@kurvball/rehearse 0.0.0-stage → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -2
  3. package/dist/affected/affected.d.ts +22 -0
  4. package/dist/affected/affected.js +162 -0
  5. package/dist/affected/index.d.ts +1 -0
  6. package/dist/affected/index.js +1 -0
  7. package/dist/args.d.ts +12 -0
  8. package/dist/args.js +42 -0
  9. package/dist/cli.d.ts +4 -0
  10. package/dist/cli.js +100 -0
  11. package/dist/commands/check.d.ts +2 -0
  12. package/dist/commands/check.js +42 -0
  13. package/dist/commands/clean.d.ts +2 -0
  14. package/dist/commands/clean.js +37 -0
  15. package/dist/commands/command.d.ts +29 -0
  16. package/dist/commands/command.js +29 -0
  17. package/dist/commands/compare.d.ts +4 -0
  18. package/dist/commands/compare.js +84 -0
  19. package/dist/commands/drive.d.ts +2 -0
  20. package/dist/commands/drive.js +244 -0
  21. package/dist/commands/index.d.ts +3 -0
  22. package/dist/commands/index.js +32 -0
  23. package/dist/commands/init.d.ts +2 -0
  24. package/dist/commands/init.js +19 -0
  25. package/dist/commands/list.d.ts +2 -0
  26. package/dist/commands/list.js +69 -0
  27. package/dist/commands/open.d.ts +2 -0
  28. package/dist/commands/open.js +60 -0
  29. package/dist/commands/people.d.ts +2 -0
  30. package/dist/commands/people.js +49 -0
  31. package/dist/commands/run.d.ts +4 -0
  32. package/dist/commands/run.js +82 -0
  33. package/dist/commands/services.d.ts +28 -0
  34. package/dist/commands/services.js +51 -0
  35. package/dist/commands/stage.d.ts +7 -0
  36. package/dist/commands/stage.js +49 -0
  37. package/dist/commands/up.d.ts +3 -0
  38. package/dist/commands/up.js +77 -0
  39. package/dist/commands/validate.d.ts +2 -0
  40. package/dist/commands/validate.js +35 -0
  41. package/dist/commands/worlds.d.ts +2 -0
  42. package/dist/commands/worlds.js +15 -0
  43. package/dist/compare/announce.d.ts +6 -0
  44. package/dist/compare/announce.js +27 -0
  45. package/dist/compare/compare.d.ts +82 -0
  46. package/dist/compare/compare.js +310 -0
  47. package/dist/compare/diff.d.ts +15 -0
  48. package/dist/compare/diff.js +105 -0
  49. package/dist/compare/index.d.ts +4 -0
  50. package/dist/compare/index.js +4 -0
  51. package/dist/compare/setaside.d.ts +29 -0
  52. package/dist/compare/setaside.js +121 -0
  53. package/dist/compare/verdict.d.ts +21 -0
  54. package/dist/compare/verdict.js +30 -0
  55. package/dist/drive/aria.d.ts +8 -0
  56. package/dist/drive/aria.js +12 -0
  57. package/dist/drive/browser.d.ts +34 -0
  58. package/dist/drive/browser.js +216 -0
  59. package/dist/drive/daemon.d.ts +1 -0
  60. package/dist/drive/daemon.js +171 -0
  61. package/dist/drive/grammar.d.ts +93 -0
  62. package/dist/drive/grammar.js +303 -0
  63. package/dist/drive/index.d.ts +4 -0
  64. package/dist/drive/index.js +4 -0
  65. package/dist/drive/names.d.ts +24 -0
  66. package/dist/drive/names.js +97 -0
  67. package/dist/drive/state.d.ts +13 -0
  68. package/dist/drive/state.js +28 -0
  69. package/dist/errors.d.ts +26 -0
  70. package/dist/errors.js +32 -0
  71. package/dist/exec.d.ts +16 -0
  72. package/dist/exec.js +43 -0
  73. package/dist/git/checkout.d.ts +11 -0
  74. package/dist/git/checkout.js +84 -0
  75. package/dist/git/git.d.ts +7 -0
  76. package/dist/git/git.js +27 -0
  77. package/dist/git/index.d.ts +2 -0
  78. package/dist/git/index.js +2 -0
  79. package/dist/index.d.ts +18 -0
  80. package/dist/index.js +15 -0
  81. package/dist/kinds/all.d.ts +4 -0
  82. package/dist/kinds/all.js +4 -0
  83. package/dist/kinds/call/check.d.ts +29 -0
  84. package/dist/kinds/call/check.js +187 -0
  85. package/dist/kinds/call/definition.d.ts +16 -0
  86. package/dist/kinds/call/definition.js +33 -0
  87. package/dist/kinds/call/hurl.d.ts +65 -0
  88. package/dist/kinds/call/hurl.js +333 -0
  89. package/dist/kinds/call/kind.d.ts +8 -0
  90. package/dist/kinds/call/kind.js +122 -0
  91. package/dist/kinds/call/send.d.ts +32 -0
  92. package/dist/kinds/call/send.js +152 -0
  93. package/dist/kinds/call/words.d.ts +22 -0
  94. package/dist/kinds/call/words.js +24 -0
  95. package/dist/kinds/file/kind.d.ts +44 -0
  96. package/dist/kinds/file/kind.js +331 -0
  97. package/dist/kinds/file/layouts.d.ts +14 -0
  98. package/dist/kinds/file/layouts.js +103 -0
  99. package/dist/kinds/flow/kind.d.ts +21 -0
  100. package/dist/kinds/flow/kind.js +401 -0
  101. package/dist/kinds/flow/literal.d.ts +8 -0
  102. package/dist/kinds/flow/literal.js +148 -0
  103. package/dist/kinds/index.d.ts +10 -0
  104. package/dist/kinds/index.js +8 -0
  105. package/dist/kinds/kind.d.ts +57 -0
  106. package/dist/kinds/kind.js +21 -0
  107. package/dist/kinds/piece/canvas.d.ts +18 -0
  108. package/dist/kinds/piece/canvas.js +165 -0
  109. package/dist/kinds/piece/conventions.d.ts +12 -0
  110. package/dist/kinds/piece/conventions.js +101 -0
  111. package/dist/kinds/piece/csf.d.ts +10 -0
  112. package/dist/kinds/piece/csf.js +304 -0
  113. package/dist/kinds/piece/kind.d.ts +12 -0
  114. package/dist/kinds/piece/kind.js +297 -0
  115. package/dist/kinds/piece/server.d.ts +23 -0
  116. package/dist/kinds/piece/server.js +236 -0
  117. package/dist/manifest/fill.d.ts +4 -0
  118. package/dist/manifest/fill.js +7 -0
  119. package/dist/manifest/index.d.ts +5 -0
  120. package/dist/manifest/index.js +5 -0
  121. package/dist/manifest/init.d.ts +1 -0
  122. package/dist/manifest/init.js +47 -0
  123. package/dist/manifest/load.d.ts +7 -0
  124. package/dist/manifest/load.js +244 -0
  125. package/dist/manifest/types.d.ts +253 -0
  126. package/dist/manifest/types.js +7 -0
  127. package/dist/manifest/yaml.d.ts +5 -0
  128. package/dist/manifest/yaml.js +47 -0
  129. package/dist/people/index.d.ts +1 -0
  130. package/dist/people/index.js +1 -0
  131. package/dist/people/people.d.ts +39 -0
  132. package/dist/people/people.js +139 -0
  133. package/dist/run/cache.d.ts +20 -0
  134. package/dist/run/cache.js +98 -0
  135. package/dist/run/index.d.ts +4 -0
  136. package/dist/run/index.js +3 -0
  137. package/dist/run/observation.d.ts +27 -0
  138. package/dist/run/observation.js +1 -0
  139. package/dist/run/session.d.ts +32 -0
  140. package/dist/run/session.js +258 -0
  141. package/dist/run/vars.d.ts +3 -0
  142. package/dist/run/vars.js +13 -0
  143. package/dist/scenarios/area.d.ts +6 -0
  144. package/dist/scenarios/area.js +37 -0
  145. package/dist/scenarios/files.d.ts +9 -0
  146. package/dist/scenarios/files.js +26 -0
  147. package/dist/scenarios/glob.d.ts +6 -0
  148. package/dist/scenarios/glob.js +106 -0
  149. package/dist/scenarios/index.d.ts +4 -0
  150. package/dist/scenarios/index.js +4 -0
  151. package/dist/scenarios/read.d.ts +18 -0
  152. package/dist/scenarios/read.js +54 -0
  153. package/dist/scenarios/scenario.d.ts +34 -0
  154. package/dist/scenarios/scenario.js +10 -0
  155. package/dist/schema.d.ts +14 -0
  156. package/dist/schema.js +122 -0
  157. package/dist/services/index.d.ts +2 -0
  158. package/dist/services/index.js +2 -0
  159. package/dist/services/registry.d.ts +23 -0
  160. package/dist/services/registry.js +49 -0
  161. package/dist/services/service.d.ts +22 -0
  162. package/dist/services/service.js +284 -0
  163. package/dist/stage/api.d.ts +28 -0
  164. package/dist/stage/api.js +206 -0
  165. package/dist/stage/client/client/api.js +11 -0
  166. package/dist/stage/client/client/index.js +1 -0
  167. package/dist/stage/client/features/canvas/call.js +65 -0
  168. package/dist/stage/client/features/canvas/context.js +1 -0
  169. package/dist/stage/client/features/canvas/file.js +36 -0
  170. package/dist/stage/client/features/canvas/flow.js +59 -0
  171. package/dist/stage/client/features/canvas/index.js +1 -0
  172. package/dist/stage/client/features/canvas/observed.js +8 -0
  173. package/dist/stage/client/features/canvas/parts.js +24 -0
  174. package/dist/stage/client/features/canvas/piece.js +31 -0
  175. package/dist/stage/client/features/canvas/reach.js +6 -0
  176. package/dist/stage/client/features/canvas/views.js +16 -0
  177. package/dist/stage/client/features/list/index.js +1 -0
  178. package/dist/stage/client/features/list/list.js +53 -0
  179. package/dist/stage/client/features/list/reach.js +10 -0
  180. package/dist/stage/client/features/scenario/heading.js +14 -0
  181. package/dist/stage/client/features/scenario/index.js +1 -0
  182. package/dist/stage/client/features/scenario/reach.js +9 -0
  183. package/dist/stage/client/features/scenario/scenario.js +145 -0
  184. package/dist/stage/client/features/try/index.js +1 -0
  185. package/dist/stage/client/features/try/reach.js +12 -0
  186. package/dist/stage/client/features/try/try.js +65 -0
  187. package/dist/stage/client/index.html +16 -0
  188. package/dist/stage/client/main.js +24 -0
  189. package/dist/stage/client/primitives/busy.js +6 -0
  190. package/dist/stage/client/primitives/focus.js +21 -0
  191. package/dist/stage/client/primitives/h.js +25 -0
  192. package/dist/stage/client/primitives/index.js +6 -0
  193. package/dist/stage/client/primitives/keyed.js +16 -0
  194. package/dist/stage/client/primitives/say.js +6 -0
  195. package/dist/stage/client/primitives/state.js +21 -0
  196. package/dist/stage/client/primitives/types.js +1 -0
  197. package/dist/stage/client/primitives/verdicts.js +8 -0
  198. package/dist/stage/client/stage.css +652 -0
  199. package/dist/stage/compared.d.ts +20 -0
  200. package/dist/stage/compared.js +58 -0
  201. package/dist/stage/files.d.ts +4 -0
  202. package/dist/stage/files.js +59 -0
  203. package/dist/stage/guard.d.ts +3 -0
  204. package/dist/stage/guard.js +20 -0
  205. package/dist/stage/http.d.ts +12 -0
  206. package/dist/stage/http.js +34 -0
  207. package/dist/stage/index.d.ts +1 -0
  208. package/dist/stage/index.js +1 -0
  209. package/dist/stage/sending.d.ts +18 -0
  210. package/dist/stage/sending.js +66 -0
  211. package/dist/stage/server.d.ts +31 -0
  212. package/dist/stage/server.js +250 -0
  213. package/dist/version.d.ts +2 -0
  214. package/dist/version.js +5 -0
  215. package/dist/worlds/define.d.ts +16 -0
  216. package/dist/worlds/define.js +45 -0
  217. package/dist/worlds/index.d.ts +2 -0
  218. package/dist/worlds/index.js +2 -0
  219. package/dist/worlds/worlds.d.ts +15 -0
  220. package/dist/worlds/worlds.js +46 -0
  221. package/llms.txt +46 -0
  222. package/package.json +84 -3
  223. package/schema/v1/announce.schema.json +28 -0
  224. package/schema/v1/check.schema.json +67 -0
  225. package/schema/v1/clean.schema.json +19 -0
  226. package/schema/v1/common.schema.json +210 -0
  227. package/schema/v1/comparison.schema.json +298 -0
  228. package/schema/v1/dependents.schema.json +30 -0
  229. package/schema/v1/drive.schema.json +112 -0
  230. package/schema/v1/error.schema.json +26 -0
  231. package/schema/v1/file-scenario.schema.json +175 -0
  232. package/schema/v1/flow.schema.json +216 -0
  233. package/schema/v1/init.schema.json +20 -0
  234. package/schema/v1/list.schema.json +70 -0
  235. package/schema/v1/manifest.schema.json +430 -0
  236. package/schema/v1/observation.schema.json +388 -0
  237. package/schema/v1/open.schema.json +14 -0
  238. package/schema/v1/people.schema.json +88 -0
  239. package/schema/v1/samples/announce.yaml +5 -0
  240. package/schema/v1/samples/check.json +13 -0
  241. package/schema/v1/samples/clean.json +1 -0
  242. package/schema/v1/samples/comparison.json +83 -0
  243. package/schema/v1/samples/dependents.json +7 -0
  244. package/schema/v1/samples/drive.json +10 -0
  245. package/schema/v1/samples/error.json +10 -0
  246. package/schema/v1/samples/file-scenario.yaml +13 -0
  247. package/schema/v1/samples/flow.yaml +13 -0
  248. package/schema/v1/samples/init.json +1 -0
  249. package/schema/v1/samples/list.json +24 -0
  250. package/schema/v1/samples/manifest.yaml +55 -0
  251. package/schema/v1/samples/observation.json +49 -0
  252. package/schema/v1/samples/open.json +6 -0
  253. package/schema/v1/samples/people.json +11 -0
  254. package/schema/v1/samples/services.json +27 -0
  255. package/schema/v1/samples/stage.json +6 -0
  256. package/schema/v1/samples/try.json +13 -0
  257. package/schema/v1/samples/up.json +16 -0
  258. package/schema/v1/samples/validate.json +7 -0
  259. package/schema/v1/samples/worlds.json +21 -0
  260. package/schema/v1/services.schema.json +72 -0
  261. package/schema/v1/stage.schema.json +14 -0
  262. package/schema/v1/try.schema.json +56 -0
  263. package/schema/v1/up.schema.json +55 -0
  264. package/schema/v1/validate.schema.json +40 -0
  265. package/schema/v1/worlds.schema.json +33 -0
  266. package/skill/rehearse/SKILL.md +148 -0
@@ -0,0 +1,244 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { existsSync, readFileSync, statSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { RehearseError } from '../errors.js';
5
+ import { validate } from '../schema.js';
6
+ import { readYaml } from './yaml.js';
7
+ export const MANIFEST_FILE = 'rehearse.yaml';
8
+ export const MANIFEST_VARIABLE = 'REHEARSE_MANIFEST';
9
+ const isFile = (file) => {
10
+ try {
11
+ return statSync(file).isFile();
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ };
17
+ export function findManifest(cwd, given, env = process.env) {
18
+ const named = given ?? (env[MANIFEST_VARIABLE]?.trim() || null);
19
+ if (named) {
20
+ const file = path.resolve(cwd, named);
21
+ const inside = existsSync(file) && statSync(file).isDirectory() ? path.join(file, MANIFEST_FILE) : file;
22
+ if (!isFile(inside))
23
+ throw new RehearseError('no_manifest', `There is no manifest at ${inside}.`);
24
+ return inside;
25
+ }
26
+ for (let at = path.resolve(cwd);; at = path.dirname(at)) {
27
+ const file = path.join(at, MANIFEST_FILE);
28
+ if (isFile(file))
29
+ return file;
30
+ if (path.dirname(at) === at)
31
+ break;
32
+ }
33
+ throw new RehearseError('no_manifest', `No ${MANIFEST_FILE} here or in a folder above ${cwd}. Write one with \`rehearse init\`, or name one with --manifest.`);
34
+ }
35
+ const strings = (env) => Object.fromEntries(Object.entries(env ?? {}).map(([k, v]) => [k, String(v)]));
36
+ function readyOf(ready) {
37
+ if (ready === undefined)
38
+ return null;
39
+ if (typeof ready === 'string')
40
+ return /^https?:\/\//.test(ready) ? { http: ready } : { command: ready };
41
+ if (ready.http !== undefined)
42
+ return { http: ready.http };
43
+ if (ready.command !== undefined)
44
+ return { command: ready.command };
45
+ if (ready.log !== undefined)
46
+ return { log: ready.log };
47
+ return null;
48
+ }
49
+ function serviceOf(name, s) {
50
+ const port = s.port ?? null;
51
+ return {
52
+ name,
53
+ describe: s.describe ?? null,
54
+ up: s.up,
55
+ cwd: s.cwd ?? null,
56
+ port,
57
+ url: s.url ?? (port !== null ? 'http://127.0.0.1:{{port}}' : null),
58
+ ready: readyOf(s.ready),
59
+ timeoutMs: Math.round((s.timeout ?? 60) * 1000),
60
+ down: s.down ?? null,
61
+ env: strings(s.env),
62
+ isolate: s.isolate ?? null,
63
+ drive: s.drive ?? null,
64
+ };
65
+ }
66
+ const fromOf = (glob) => glob.startsWith('./') || glob.startsWith('../') ? 'manifest' : 'checkout';
67
+ function pathsOf(raw) {
68
+ return (raw ?? []).map((p) => typeof p === 'string'
69
+ ? { glob: p, from: fromOf(p), covers: [] }
70
+ : { glob: p.path, from: fromOf(p.path), covers: p.covers ?? [] });
71
+ }
72
+ function block(raw) {
73
+ if (raw === undefined)
74
+ return { paths: [] };
75
+ if (Array.isArray(raw))
76
+ return { paths: pathsOf(raw) };
77
+ const { paths, ...rest } = raw;
78
+ return { ...rest, paths: pathsOf(paths) };
79
+ }
80
+ function scenariosOf(raw) {
81
+ return {
82
+ pieces: block(raw?.pieces),
83
+ flows: block(raw?.flows),
84
+ calls: block(raw?.calls),
85
+ files: block(raw?.files),
86
+ };
87
+ }
88
+ function refuse(file, line, says) {
89
+ const where = line ? `${path.basename(file)}:${line}` : path.basename(file);
90
+ throw new RehearseError('manifest', `${where}: ${says}`, { file, ...(line !== undefined && { line }) });
91
+ }
92
+ function checkWhatTheSchemaCant(m) {
93
+ const at = (where, key) => m.lineOf(where, key);
94
+ const services = Object.keys(m.services);
95
+ const named = (kind, name, known, where) => {
96
+ if (!known.includes(name))
97
+ refuse(m.file, at(where), `${kind} “${name}” isn't declared${known.length ? `: there is ${known.map((k) => `“${k}”`).join(', ')}` : ''}.`);
98
+ };
99
+ for (const w of Object.values(m.worlds)) {
100
+ if (w.extends !== null)
101
+ named('The world', w.extends, Object.keys(m.worlds), ['worlds', w.name, 'extends']);
102
+ const seen = [w.name];
103
+ for (let next = w.extends; next !== null; next = m.worlds[next]?.extends ?? null) {
104
+ if (seen.includes(next))
105
+ refuse(m.file, at(['worlds', w.name]), `the worlds extend in a circle: ${[...seen, next].join(' → ')}.`);
106
+ seen.push(next);
107
+ }
108
+ }
109
+ for (const s of Object.values(m.standins))
110
+ for (const [i, svc] of (s.services ?? []).entries())
111
+ named('The service', svc, services, ['standins', s.name, 'services', String(i)]);
112
+ if (m.signIn?.service)
113
+ named('The service', m.signIn.service, services, ['signIn', 'service']);
114
+ const d = m.raw.defaults ?? {};
115
+ if (d.service)
116
+ named('The service', d.service, services, ['defaults', 'service']);
117
+ if (d.world)
118
+ named('The world', d.world, Object.keys(m.worlds), ['defaults', 'world']);
119
+ if (d.person)
120
+ named('The person', d.person, Object.keys(m.people), ['defaults', 'person']);
121
+ if (m.scenarios.flows.service)
122
+ named('The service', m.scenarios.flows.service, services, ['scenarios', 'flows', 'service']);
123
+ if (m.scenarios.calls.service)
124
+ named('The service', m.scenarios.calls.service, services, ['scenarios', 'calls', 'service']);
125
+ const defaults = (kind, all, where) => {
126
+ const marked = all.filter((x) => x.default);
127
+ if (marked.length > 1)
128
+ refuse(m.file, at([where, marked[1].name]), `only one ${kind} can be the default; ${marked.map((x) => x.name).join(' and ')} both are.`);
129
+ };
130
+ defaults('person', Object.values(m.people), 'people');
131
+ defaults('world', Object.values(m.worlds), 'worlds');
132
+ for (const [i, rule] of [...m.setAside.keys, ...m.setAside.values].entries()) {
133
+ try {
134
+ void new RegExp(rule);
135
+ }
136
+ catch {
137
+ refuse(m.file, at(['setAside']), `the rule “${rule}” (number ${i + 1}) isn't a regular expression.`);
138
+ }
139
+ }
140
+ }
141
+ export function manifestFrom(text, file) {
142
+ const read = readYaml(text, file);
143
+ const raw = (read.value ?? {});
144
+ const invalid = validate('manifest', raw);
145
+ if (invalid.length) {
146
+ const first = invalid[0];
147
+ refuse(file, read.lineOf(first.at, first.key), first.says);
148
+ }
149
+ const dir = path.dirname(file);
150
+ const services = Object.fromEntries(Object.entries(raw.services ?? {}).map(([n, s]) => [n, serviceOf(n, s)]));
151
+ const people = Object.fromEntries(Object.entries(raw.people ?? {}).map(([name, p]) => [
152
+ name,
153
+ {
154
+ name,
155
+ describe: p.describe ?? null,
156
+ real: p.real ?? 'local',
157
+ default: p.default ?? false,
158
+ token: p.token?.command ? { command: p.token.command } : p.token?.env ? { env: p.token.env } : null,
159
+ browser: p.browser ?? null,
160
+ },
161
+ ]));
162
+ const worlds = Object.fromEntries(Object.entries(raw.worlds ?? {}).map(([name, w]) => [
163
+ name,
164
+ {
165
+ name,
166
+ describe: w.describe ?? null,
167
+ extends: w.extends ?? null,
168
+ add: w.add ?? null,
169
+ before: w.before ?? null,
170
+ default: w.default ?? false,
171
+ },
172
+ ]));
173
+ const standins = Object.fromEntries(Object.entries(raw.standins ?? {}).map(([name, s]) => [
174
+ name,
175
+ {
176
+ name,
177
+ replaces: s.replaces,
178
+ by: s.by ?? null,
179
+ fidelity: s.fidelity ?? 'fake',
180
+ services: s.services ?? null,
181
+ env: strings(s.env),
182
+ real: s.real ? { env: strings(s.real.env) } : null,
183
+ },
184
+ ]));
185
+ const signIn = raw.signIn === undefined
186
+ ? null
187
+ : typeof raw.signIn === 'string'
188
+ ? { command: raw.signIn, service: null, cwd: null }
189
+ : { command: raw.signIn.command, service: raw.signIn.service ?? null, cwd: raw.signIn.cwd ?? null };
190
+ const firstService = Object.values(services).find((s) => s.url !== null)?.name ?? Object.keys(services)[0] ?? null;
191
+ const m = {
192
+ file,
193
+ dir,
194
+ raw,
195
+ base: raw.base ?? 'main',
196
+ checkout: raw.checkout ? path.resolve(dir, raw.checkout) : null,
197
+ prepare: raw.prepare ?? null,
198
+ overlay: (raw.overlay ?? []).map((o) => ({ from: path.resolve(dir, o.from), to: o.to })),
199
+ services,
200
+ signIn,
201
+ people,
202
+ worlds,
203
+ standins,
204
+ scenarios: scenariosOf(raw.scenarios),
205
+ defaults: {
206
+ service: raw.defaults?.service ?? ('api' in services ? 'api' : firstService),
207
+ world: raw.defaults?.world ?? Object.values(worlds).find((w) => w.default)?.name ?? null,
208
+ person: raw.defaults?.person ?? Object.values(people).find((p) => p.default)?.name ?? null,
209
+ },
210
+ setAside: {
211
+ keys: raw.setAside?.keys ?? [],
212
+ values: raw.setAside?.values ?? [],
213
+ keep: raw.setAside?.keep ?? [],
214
+ },
215
+ affected: { graph: raw.affected?.graph ?? null },
216
+ budget: { services: raw.budget?.services ?? 1, checkouts: raw.budget?.checkouts ?? 3 },
217
+ lineOf: (at, key) => read.lineOf(at, key),
218
+ };
219
+ checkWhatTheSchemaCant(m);
220
+ return m;
221
+ }
222
+ export function loadManifest(file) {
223
+ let text;
224
+ try {
225
+ text = readFileSync(file, 'utf8');
226
+ }
227
+ catch (error) {
228
+ throw new RehearseError('no_manifest', `Rehearse can't read ${file}: ${error.message}`);
229
+ }
230
+ return manifestFrom(text, file);
231
+ }
232
+ export function hashOf(value) {
233
+ const withKeysSorted = (v) => Array.isArray(v)
234
+ ? v.map(withKeysSorted)
235
+ : v && typeof v === 'object'
236
+ ? Object.fromEntries(Object.keys(v)
237
+ .sort()
238
+ .map((k) => [k, withKeysSorted(v[k])]))
239
+ : v;
240
+ return createHash('sha256')
241
+ .update(JSON.stringify(withKeysSorted(value) ?? null))
242
+ .digest('hex')
243
+ .slice(0, 16);
244
+ }
@@ -0,0 +1,253 @@
1
+ export interface RawManifest {
2
+ version?: 1;
3
+ base?: string;
4
+ checkout?: string;
5
+ prepare?: string;
6
+ overlay?: {
7
+ from: string;
8
+ to: string;
9
+ }[];
10
+ services?: Record<string, RawService>;
11
+ signIn?: string | {
12
+ command: string;
13
+ service?: string;
14
+ cwd?: string;
15
+ };
16
+ people?: Record<string, RawPerson>;
17
+ worlds?: Record<string, RawWorld>;
18
+ standins?: Record<string, RawStandin>;
19
+ scenarios?: {
20
+ pieces?: RawPaths | ({
21
+ paths: RawPaths;
22
+ } & PieceSettings);
23
+ flows?: RawPaths | {
24
+ paths: RawPaths;
25
+ service?: string;
26
+ };
27
+ calls?: RawPaths | ({
28
+ paths: RawPaths;
29
+ } & CallSettings);
30
+ files?: RawPaths | {
31
+ paths: RawPaths;
32
+ };
33
+ };
34
+ defaults?: {
35
+ service?: string;
36
+ world?: string;
37
+ person?: string;
38
+ };
39
+ setAside?: SetAsideRules;
40
+ affected?: {
41
+ graph?: string;
42
+ };
43
+ budget?: {
44
+ services?: number;
45
+ checkouts?: number;
46
+ };
47
+ }
48
+ export type Env = Record<string, string | number | boolean>;
49
+ export type RawReady = string | {
50
+ http?: string;
51
+ command?: string;
52
+ log?: string;
53
+ };
54
+ export interface RawService {
55
+ describe?: string;
56
+ up: string;
57
+ cwd?: string;
58
+ port?: number | 'auto';
59
+ url?: string;
60
+ ready?: RawReady;
61
+ timeout?: number;
62
+ down?: string;
63
+ env?: Env;
64
+ isolate?: {
65
+ env: string;
66
+ };
67
+ drive?: string;
68
+ }
69
+ export type Ready = {
70
+ http: string;
71
+ } | {
72
+ command: string;
73
+ } | {
74
+ log: string;
75
+ } | null;
76
+ export interface Service {
77
+ name: string;
78
+ describe: string | null;
79
+ up: string;
80
+ cwd: string | null;
81
+ port: number | 'auto' | null;
82
+ url: string | null;
83
+ ready: Ready;
84
+ timeoutMs: number;
85
+ down: string | null;
86
+ env: Record<string, string>;
87
+ isolate: {
88
+ env: string;
89
+ } | null;
90
+ drive: string | null;
91
+ }
92
+ export type Real = 'local' | 'stand-in' | 'real';
93
+ export interface Step {
94
+ click?: string;
95
+ type?: string;
96
+ key?: string;
97
+ snapshot?: string;
98
+ fill?: string;
99
+ with?: string;
100
+ role?: string;
101
+ }
102
+ export interface RawPerson {
103
+ describe?: string;
104
+ real?: Real;
105
+ default?: boolean;
106
+ token?: {
107
+ command?: string;
108
+ env?: string;
109
+ };
110
+ browser?: {
111
+ headers?: Record<string, string>;
112
+ storage?: Record<string, string>;
113
+ cookies?: {
114
+ name: string;
115
+ value: string;
116
+ path?: string;
117
+ }[];
118
+ steps?: Step[];
119
+ };
120
+ }
121
+ export interface Person {
122
+ name: string;
123
+ describe: string | null;
124
+ real: Real;
125
+ default: boolean;
126
+ token: {
127
+ command: string;
128
+ } | {
129
+ env: string;
130
+ } | null;
131
+ browser: NonNullable<RawPerson['browser']> | null;
132
+ }
133
+ export interface RawWorld {
134
+ describe?: string;
135
+ extends?: string;
136
+ add?: string;
137
+ before?: string;
138
+ default?: boolean;
139
+ }
140
+ export interface World {
141
+ name: string;
142
+ describe: string | null;
143
+ extends: string | null;
144
+ add: string | null;
145
+ before: string | null;
146
+ default: boolean;
147
+ }
148
+ export type Fidelity = 'fake' | 'recorded' | 'local';
149
+ export interface RawStandin {
150
+ replaces: string;
151
+ by?: string;
152
+ fidelity?: Fidelity;
153
+ services?: string[];
154
+ env?: Env;
155
+ real?: {
156
+ env?: Env;
157
+ };
158
+ }
159
+ export interface Standin {
160
+ name: string;
161
+ replaces: string;
162
+ by: string | null;
163
+ fidelity: Fidelity;
164
+ services: string[] | null;
165
+ env: Record<string, string>;
166
+ real: {
167
+ env: Record<string, string>;
168
+ } | null;
169
+ }
170
+ export type RawPaths = (string | {
171
+ path: string;
172
+ covers?: string[];
173
+ })[];
174
+ export interface PathEntry {
175
+ glob: string;
176
+ from: 'manifest' | 'checkout';
177
+ covers: string[];
178
+ }
179
+ export interface PieceSettings {
180
+ preview?: string;
181
+ styles?: string;
182
+ config?: string;
183
+ schemes?: ('light' | 'dark')[];
184
+ compare?: ('tree' | 'errors' | 'violations' | 'screenshot')[];
185
+ viewport?: {
186
+ width: number;
187
+ height: number;
188
+ };
189
+ }
190
+ export interface CallSettings {
191
+ service?: string;
192
+ variables?: Record<string, string>;
193
+ unordered?: boolean;
194
+ }
195
+ export interface SetAsideRules {
196
+ keys?: string[];
197
+ values?: string[];
198
+ keep?: string[];
199
+ }
200
+ export declare const KINDS: readonly ['piece', 'flow', 'call', 'file'];
201
+ export type Kind = (typeof KINDS)[number];
202
+ export declare const KIND_BLOCK: Readonly<Record<Kind, 'pieces' | 'flows' | 'calls' | 'files'>>;
203
+ export interface Scenarios {
204
+ pieces: {
205
+ paths: PathEntry[];
206
+ } & PieceSettings;
207
+ flows: {
208
+ paths: PathEntry[];
209
+ service?: string;
210
+ };
211
+ calls: {
212
+ paths: PathEntry[];
213
+ } & CallSettings;
214
+ files: {
215
+ paths: PathEntry[];
216
+ };
217
+ }
218
+ export interface Manifest {
219
+ file: string;
220
+ dir: string;
221
+ raw: RawManifest;
222
+ base: string;
223
+ checkout: string | null;
224
+ prepare: string | null;
225
+ overlay: {
226
+ from: string;
227
+ to: string;
228
+ }[];
229
+ services: Record<string, Service>;
230
+ signIn: {
231
+ command: string;
232
+ service: string | null;
233
+ cwd: string | null;
234
+ } | null;
235
+ people: Record<string, Person>;
236
+ worlds: Record<string, World>;
237
+ standins: Record<string, Standin>;
238
+ scenarios: Scenarios;
239
+ defaults: {
240
+ service: string | null;
241
+ world: string | null;
242
+ person: string | null;
243
+ };
244
+ setAside: Required<SetAsideRules>;
245
+ affected: {
246
+ graph: string | null;
247
+ };
248
+ budget: {
249
+ services: number;
250
+ checkouts: number;
251
+ };
252
+ lineOf(at: readonly string[], key?: string): number | undefined;
253
+ }
@@ -0,0 +1,7 @@
1
+ export const KINDS = ['piece', 'flow', 'call', 'file'];
2
+ export const KIND_BLOCK = {
3
+ piece: 'pieces',
4
+ flow: 'flows',
5
+ call: 'calls',
6
+ file: 'files',
7
+ };
@@ -0,0 +1,5 @@
1
+ export interface ReadYaml {
2
+ value: unknown;
3
+ lineOf(at: readonly string[], key?: string): number | undefined;
4
+ }
5
+ export declare function readYaml(text: string, file: string): ReadYaml;
@@ -0,0 +1,47 @@
1
+ import { isMap, isPair, isScalar, LineCounter, parseDocument } from 'yaml';
2
+ import path from 'node:path';
3
+ import { RehearseError } from '../errors.js';
4
+ function nodeAt(doc, at) {
5
+ let node = doc.contents;
6
+ for (const segment of at) {
7
+ if (isMap(node)) {
8
+ const pair = node.items.find((p) => isScalar(p.key) && String(p.key.value) === segment);
9
+ node = pair?.value ?? null;
10
+ }
11
+ else if (node && typeof node === 'object' && 'items' in node && Array.isArray(node.items)) {
12
+ node = node.items[Number(segment)] ?? null;
13
+ }
14
+ else
15
+ return null;
16
+ }
17
+ return node ?? null;
18
+ }
19
+ export function readYaml(text, file) {
20
+ const lines = new LineCounter();
21
+ const doc = parseDocument(text, { lineCounter: lines, prettyErrors: false, uniqueKeys: true });
22
+ const first = doc.errors[0];
23
+ if (first) {
24
+ const line = lines.linePos(first.pos[0]).line;
25
+ throw new RehearseError('yaml', `${path.basename(file)}:${line}: ${first.message.split('\n')[0]}`, {
26
+ file,
27
+ line,
28
+ });
29
+ }
30
+ const lineAtOffset = (offset) => offset === undefined ? undefined : lines.linePos(offset).line;
31
+ return {
32
+ value: doc.toJS(),
33
+ lineOf(at, key) {
34
+ const node = nodeAt(doc, at);
35
+ if (key !== undefined && isMap(node)) {
36
+ const pair = node.items.find((p) => isPair(p) && isScalar(p.key) && String(p.key.value) === key);
37
+ if (pair && isScalar(pair.key))
38
+ return lineAtOffset(pair.key.range?.[0]);
39
+ }
40
+ if (node && 'range' in node && Array.isArray(node.range))
41
+ return lineAtOffset(node.range[0]);
42
+ if (at.length > 0)
43
+ return this.lineOf(at.slice(0, -1));
44
+ return undefined;
45
+ },
46
+ };
47
+ }
@@ -0,0 +1 @@
1
+ export { NO_ONE, NOBODY, peopleOut, scrub, scrubDeep, signedInFrom, signIn } from './people.ts';
@@ -0,0 +1 @@
1
+ export { NO_ONE, NOBODY, peopleOut, scrub, scrubDeep, signedInFrom, signIn } from './people.js';
@@ -0,0 +1,39 @@
1
+ import type { Manifest, Real } from '../manifest/index.ts';
2
+ export declare const NOBODY = "nobody";
3
+ export declare const NO_ONE = "a token for no one";
4
+ export declare const NAMES_A_PERSON_CANT_TAKE: Set<string>;
5
+ export declare const isVariableName: (v: string) => boolean;
6
+ export interface AboutOut {
7
+ real: Real;
8
+ default: boolean;
9
+ describe: string | null;
10
+ signedIn: boolean;
11
+ }
12
+ type InTheSignInShape = Record<string, {
13
+ token: string;
14
+ [field: string]: string;
15
+ }>;
16
+ export interface PeopleOut {
17
+ v: 1;
18
+ people: InTheSignInShape;
19
+ variables: Record<string, string>;
20
+ about: Record<string, AboutOut>;
21
+ signedIn: boolean;
22
+ said: string | null;
23
+ }
24
+ export interface SignedIn {
25
+ tokens: Record<string, string>;
26
+ fields: Record<string, Record<string, string>>;
27
+ variables: Record<string, string>;
28
+ }
29
+ export declare function signedInFrom(stdout: string): SignedIn | null;
30
+ export interface SignInPlace {
31
+ cwd: string;
32
+ env: Record<string, string>;
33
+ fill(text: string): string;
34
+ }
35
+ export declare function signIn(m: Manifest, place: SignInPlace): Promise<SignedIn>;
36
+ export declare function peopleOut(m: Manifest, signed: SignedIn | null, withTokens: boolean, said: string | null): PeopleOut;
37
+ export declare function scrub(text: string, tokens: Readonly<Record<string, string>>): string;
38
+ export declare function scrubDeep<T>(value: T, tokens: Readonly<Record<string, string>>): T;
39
+ export {};