@kurvball/rehearse 0.0.0-stage → 1.3.0
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.
- package/LICENSE +21 -0
- package/README.md +107 -2
- package/dist/affected/affected.d.ts +22 -0
- package/dist/affected/affected.js +162 -0
- package/dist/affected/index.d.ts +1 -0
- package/dist/affected/index.js +1 -0
- package/dist/args.d.ts +12 -0
- package/dist/args.js +42 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +100 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +42 -0
- package/dist/commands/clean.d.ts +2 -0
- package/dist/commands/clean.js +37 -0
- package/dist/commands/command.d.ts +30 -0
- package/dist/commands/command.js +38 -0
- package/dist/commands/compare.d.ts +4 -0
- package/dist/commands/compare.js +89 -0
- package/dist/commands/drive.d.ts +2 -0
- package/dist/commands/drive.js +244 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +32 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +19 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.js +69 -0
- package/dist/commands/open.d.ts +2 -0
- package/dist/commands/open.js +60 -0
- package/dist/commands/people.d.ts +2 -0
- package/dist/commands/people.js +49 -0
- package/dist/commands/run.d.ts +4 -0
- package/dist/commands/run.js +84 -0
- package/dist/commands/services.d.ts +28 -0
- package/dist/commands/services.js +51 -0
- package/dist/commands/stage.d.ts +7 -0
- package/dist/commands/stage.js +53 -0
- package/dist/commands/up.d.ts +3 -0
- package/dist/commands/up.js +77 -0
- package/dist/commands/validate.d.ts +2 -0
- package/dist/commands/validate.js +35 -0
- package/dist/commands/worlds.d.ts +2 -0
- package/dist/commands/worlds.js +15 -0
- package/dist/compare/announce.d.ts +6 -0
- package/dist/compare/announce.js +27 -0
- package/dist/compare/compare.d.ts +83 -0
- package/dist/compare/compare.js +335 -0
- package/dist/compare/diff.d.ts +15 -0
- package/dist/compare/diff.js +105 -0
- package/dist/compare/index.d.ts +5 -0
- package/dist/compare/index.js +5 -0
- package/dist/compare/setaside.d.ts +29 -0
- package/dist/compare/setaside.js +121 -0
- package/dist/compare/verdict.d.ts +21 -0
- package/dist/compare/verdict.js +30 -0
- package/dist/drive/aria.d.ts +8 -0
- package/dist/drive/aria.js +12 -0
- package/dist/drive/browser.d.ts +34 -0
- package/dist/drive/browser.js +216 -0
- package/dist/drive/daemon.d.ts +1 -0
- package/dist/drive/daemon.js +171 -0
- package/dist/drive/grammar.d.ts +93 -0
- package/dist/drive/grammar.js +303 -0
- package/dist/drive/index.d.ts +4 -0
- package/dist/drive/index.js +4 -0
- package/dist/drive/names.d.ts +24 -0
- package/dist/drive/names.js +97 -0
- package/dist/drive/state.d.ts +13 -0
- package/dist/drive/state.js +28 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.js +32 -0
- package/dist/exec.d.ts +16 -0
- package/dist/exec.js +43 -0
- package/dist/git/checkout.d.ts +11 -0
- package/dist/git/checkout.js +90 -0
- package/dist/git/git.d.ts +7 -0
- package/dist/git/git.js +27 -0
- package/dist/git/index.d.ts +2 -0
- package/dist/git/index.js +2 -0
- package/dist/git/seed.d.ts +3 -0
- package/dist/git/seed.js +115 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +15 -0
- package/dist/kinds/all.d.ts +4 -0
- package/dist/kinds/all.js +4 -0
- package/dist/kinds/call/check.d.ts +29 -0
- package/dist/kinds/call/check.js +187 -0
- package/dist/kinds/call/definition.d.ts +16 -0
- package/dist/kinds/call/definition.js +33 -0
- package/dist/kinds/call/hurl.d.ts +65 -0
- package/dist/kinds/call/hurl.js +333 -0
- package/dist/kinds/call/kind.d.ts +8 -0
- package/dist/kinds/call/kind.js +122 -0
- package/dist/kinds/call/send.d.ts +32 -0
- package/dist/kinds/call/send.js +152 -0
- package/dist/kinds/call/words.d.ts +22 -0
- package/dist/kinds/call/words.js +24 -0
- package/dist/kinds/file/kind.d.ts +44 -0
- package/dist/kinds/file/kind.js +331 -0
- package/dist/kinds/file/layouts.d.ts +14 -0
- package/dist/kinds/file/layouts.js +103 -0
- package/dist/kinds/flow/kind.d.ts +21 -0
- package/dist/kinds/flow/kind.js +412 -0
- package/dist/kinds/flow/literal.d.ts +8 -0
- package/dist/kinds/flow/literal.js +148 -0
- package/dist/kinds/index.d.ts +10 -0
- package/dist/kinds/index.js +8 -0
- package/dist/kinds/kind.d.ts +63 -0
- package/dist/kinds/kind.js +21 -0
- package/dist/kinds/piece/canvas.d.ts +18 -0
- package/dist/kinds/piece/canvas.js +165 -0
- package/dist/kinds/piece/conventions.d.ts +12 -0
- package/dist/kinds/piece/conventions.js +101 -0
- package/dist/kinds/piece/csf.d.ts +10 -0
- package/dist/kinds/piece/csf.js +304 -0
- package/dist/kinds/piece/kind.d.ts +12 -0
- package/dist/kinds/piece/kind.js +297 -0
- package/dist/kinds/piece/server.d.ts +23 -0
- package/dist/kinds/piece/server.js +236 -0
- package/dist/manifest/fill.d.ts +4 -0
- package/dist/manifest/fill.js +7 -0
- package/dist/manifest/index.d.ts +5 -0
- package/dist/manifest/index.js +5 -0
- package/dist/manifest/init.d.ts +1 -0
- package/dist/manifest/init.js +47 -0
- package/dist/manifest/load.d.ts +7 -0
- package/dist/manifest/load.js +245 -0
- package/dist/manifest/types.d.ts +255 -0
- package/dist/manifest/types.js +7 -0
- package/dist/manifest/yaml.d.ts +5 -0
- package/dist/manifest/yaml.js +47 -0
- package/dist/people/index.d.ts +1 -0
- package/dist/people/index.js +1 -0
- package/dist/people/people.d.ts +39 -0
- package/dist/people/people.js +139 -0
- package/dist/run/cache.d.ts +20 -0
- package/dist/run/cache.js +98 -0
- package/dist/run/index.d.ts +5 -0
- package/dist/run/index.js +4 -0
- package/dist/run/observation.d.ts +27 -0
- package/dist/run/observation.js +1 -0
- package/dist/run/parallel.d.ts +28 -0
- package/dist/run/parallel.js +140 -0
- package/dist/run/session.d.ts +35 -0
- package/dist/run/session.js +399 -0
- package/dist/run/vars.d.ts +3 -0
- package/dist/run/vars.js +13 -0
- package/dist/scenarios/area.d.ts +6 -0
- package/dist/scenarios/area.js +37 -0
- package/dist/scenarios/files.d.ts +9 -0
- package/dist/scenarios/files.js +26 -0
- package/dist/scenarios/glob.d.ts +6 -0
- package/dist/scenarios/glob.js +106 -0
- package/dist/scenarios/index.d.ts +4 -0
- package/dist/scenarios/index.js +4 -0
- package/dist/scenarios/read.d.ts +18 -0
- package/dist/scenarios/read.js +54 -0
- package/dist/scenarios/scenario.d.ts +34 -0
- package/dist/scenarios/scenario.js +10 -0
- package/dist/schema.d.ts +14 -0
- package/dist/schema.js +122 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/services/registry.d.ts +23 -0
- package/dist/services/registry.js +49 -0
- package/dist/services/service.d.ts +23 -0
- package/dist/services/service.js +313 -0
- package/dist/stage/api.d.ts +30 -0
- package/dist/stage/api.js +206 -0
- package/dist/stage/client/client/api.js +11 -0
- package/dist/stage/client/client/index.js +1 -0
- package/dist/stage/client/features/canvas/call.js +65 -0
- package/dist/stage/client/features/canvas/context.js +1 -0
- package/dist/stage/client/features/canvas/file.js +36 -0
- package/dist/stage/client/features/canvas/flow.js +59 -0
- package/dist/stage/client/features/canvas/index.js +1 -0
- package/dist/stage/client/features/canvas/observed.js +8 -0
- package/dist/stage/client/features/canvas/parts.js +24 -0
- package/dist/stage/client/features/canvas/piece.js +31 -0
- package/dist/stage/client/features/canvas/reach.js +6 -0
- package/dist/stage/client/features/canvas/views.js +16 -0
- package/dist/stage/client/features/list/index.js +1 -0
- package/dist/stage/client/features/list/list.js +53 -0
- package/dist/stage/client/features/list/reach.js +10 -0
- package/dist/stage/client/features/scenario/heading.js +14 -0
- package/dist/stage/client/features/scenario/index.js +1 -0
- package/dist/stage/client/features/scenario/reach.js +9 -0
- package/dist/stage/client/features/scenario/scenario.js +145 -0
- package/dist/stage/client/features/try/index.js +1 -0
- package/dist/stage/client/features/try/reach.js +12 -0
- package/dist/stage/client/features/try/try.js +65 -0
- package/dist/stage/client/index.html +16 -0
- package/dist/stage/client/main.js +24 -0
- package/dist/stage/client/primitives/busy.js +6 -0
- package/dist/stage/client/primitives/focus.js +21 -0
- package/dist/stage/client/primitives/h.js +25 -0
- package/dist/stage/client/primitives/index.js +6 -0
- package/dist/stage/client/primitives/keyed.js +16 -0
- package/dist/stage/client/primitives/say.js +6 -0
- package/dist/stage/client/primitives/state.js +21 -0
- package/dist/stage/client/primitives/types.js +1 -0
- package/dist/stage/client/primitives/verdicts.js +8 -0
- package/dist/stage/client/stage.css +652 -0
- package/dist/stage/compared.d.ts +20 -0
- package/dist/stage/compared.js +58 -0
- package/dist/stage/files.d.ts +4 -0
- package/dist/stage/files.js +59 -0
- package/dist/stage/guard.d.ts +3 -0
- package/dist/stage/guard.js +20 -0
- package/dist/stage/http.d.ts +12 -0
- package/dist/stage/http.js +34 -0
- package/dist/stage/index.d.ts +1 -0
- package/dist/stage/index.js +1 -0
- package/dist/stage/sending.d.ts +18 -0
- package/dist/stage/sending.js +66 -0
- package/dist/stage/server.d.ts +33 -0
- package/dist/stage/server.js +253 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +5 -0
- package/dist/worlds/define.d.ts +16 -0
- package/dist/worlds/define.js +45 -0
- package/dist/worlds/index.d.ts +2 -0
- package/dist/worlds/index.js +2 -0
- package/dist/worlds/worlds.d.ts +15 -0
- package/dist/worlds/worlds.js +46 -0
- package/llms.txt +46 -0
- package/package.json +84 -3
- package/schema/v1/announce.schema.json +28 -0
- package/schema/v1/check.schema.json +67 -0
- package/schema/v1/clean.schema.json +19 -0
- package/schema/v1/common.schema.json +210 -0
- package/schema/v1/comparison.schema.json +298 -0
- package/schema/v1/dependents.schema.json +30 -0
- package/schema/v1/drive.schema.json +112 -0
- package/schema/v1/error.schema.json +26 -0
- package/schema/v1/file-scenario.schema.json +175 -0
- package/schema/v1/flow.schema.json +216 -0
- package/schema/v1/init.schema.json +20 -0
- package/schema/v1/list.schema.json +70 -0
- package/schema/v1/manifest.schema.json +434 -0
- package/schema/v1/observation.schema.json +388 -0
- package/schema/v1/open.schema.json +14 -0
- package/schema/v1/people.schema.json +88 -0
- package/schema/v1/samples/announce.yaml +5 -0
- package/schema/v1/samples/check.json +13 -0
- package/schema/v1/samples/clean.json +1 -0
- package/schema/v1/samples/comparison.json +83 -0
- package/schema/v1/samples/dependents.json +7 -0
- package/schema/v1/samples/drive.json +10 -0
- package/schema/v1/samples/error.json +10 -0
- package/schema/v1/samples/file-scenario.yaml +13 -0
- package/schema/v1/samples/flow.yaml +13 -0
- package/schema/v1/samples/init.json +1 -0
- package/schema/v1/samples/list.json +24 -0
- package/schema/v1/samples/manifest.yaml +55 -0
- package/schema/v1/samples/observation.json +49 -0
- package/schema/v1/samples/open.json +6 -0
- package/schema/v1/samples/people.json +11 -0
- package/schema/v1/samples/services.json +27 -0
- package/schema/v1/samples/stage.json +6 -0
- package/schema/v1/samples/try.json +13 -0
- package/schema/v1/samples/up.json +16 -0
- package/schema/v1/samples/validate.json +7 -0
- package/schema/v1/samples/worlds.json +21 -0
- package/schema/v1/services.schema.json +72 -0
- package/schema/v1/stage.schema.json +14 -0
- package/schema/v1/try.schema.json +56 -0
- package/schema/v1/up.schema.json +55 -0
- package/schema/v1/validate.schema.json +40 -0
- package/schema/v1/worlds.schema.json +33 -0
- package/skill/rehearse/SKILL.md +148 -0
|
@@ -0,0 +1,245 @@
|
|
|
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
|
+
seed: raw.seed ?? true,
|
|
199
|
+
overlay: (raw.overlay ?? []).map((o) => ({ from: path.resolve(dir, o.from), to: o.to })),
|
|
200
|
+
services,
|
|
201
|
+
signIn,
|
|
202
|
+
people,
|
|
203
|
+
worlds,
|
|
204
|
+
standins,
|
|
205
|
+
scenarios: scenariosOf(raw.scenarios),
|
|
206
|
+
defaults: {
|
|
207
|
+
service: raw.defaults?.service ?? ('api' in services ? 'api' : firstService),
|
|
208
|
+
world: raw.defaults?.world ?? Object.values(worlds).find((w) => w.default)?.name ?? null,
|
|
209
|
+
person: raw.defaults?.person ?? Object.values(people).find((p) => p.default)?.name ?? null,
|
|
210
|
+
},
|
|
211
|
+
setAside: {
|
|
212
|
+
keys: raw.setAside?.keys ?? [],
|
|
213
|
+
values: raw.setAside?.values ?? [],
|
|
214
|
+
keep: raw.setAside?.keep ?? [],
|
|
215
|
+
},
|
|
216
|
+
affected: { graph: raw.affected?.graph ?? null },
|
|
217
|
+
budget: { services: raw.budget?.services ?? 1, checkouts: raw.budget?.checkouts ?? 3 },
|
|
218
|
+
lineOf: (at, key) => read.lineOf(at, key),
|
|
219
|
+
};
|
|
220
|
+
checkWhatTheSchemaCant(m);
|
|
221
|
+
return m;
|
|
222
|
+
}
|
|
223
|
+
export function loadManifest(file) {
|
|
224
|
+
let text;
|
|
225
|
+
try {
|
|
226
|
+
text = readFileSync(file, 'utf8');
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
throw new RehearseError('no_manifest', `Rehearse can't read ${file}: ${error.message}`);
|
|
230
|
+
}
|
|
231
|
+
return manifestFrom(text, file);
|
|
232
|
+
}
|
|
233
|
+
export function hashOf(value) {
|
|
234
|
+
const withKeysSorted = (v) => Array.isArray(v)
|
|
235
|
+
? v.map(withKeysSorted)
|
|
236
|
+
: v && typeof v === 'object'
|
|
237
|
+
? Object.fromEntries(Object.keys(v)
|
|
238
|
+
.sort()
|
|
239
|
+
.map((k) => [k, withKeysSorted(v[k])]))
|
|
240
|
+
: v;
|
|
241
|
+
return createHash('sha256')
|
|
242
|
+
.update(JSON.stringify(withKeysSorted(value) ?? null))
|
|
243
|
+
.digest('hex')
|
|
244
|
+
.slice(0, 16);
|
|
245
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
export interface RawManifest {
|
|
2
|
+
version?: 1;
|
|
3
|
+
base?: string;
|
|
4
|
+
checkout?: string;
|
|
5
|
+
prepare?: string;
|
|
6
|
+
seed?: boolean;
|
|
7
|
+
overlay?: {
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
}[];
|
|
11
|
+
services?: Record<string, RawService>;
|
|
12
|
+
signIn?: string | {
|
|
13
|
+
command: string;
|
|
14
|
+
service?: string;
|
|
15
|
+
cwd?: string;
|
|
16
|
+
};
|
|
17
|
+
people?: Record<string, RawPerson>;
|
|
18
|
+
worlds?: Record<string, RawWorld>;
|
|
19
|
+
standins?: Record<string, RawStandin>;
|
|
20
|
+
scenarios?: {
|
|
21
|
+
pieces?: RawPaths | ({
|
|
22
|
+
paths: RawPaths;
|
|
23
|
+
} & PieceSettings);
|
|
24
|
+
flows?: RawPaths | {
|
|
25
|
+
paths: RawPaths;
|
|
26
|
+
service?: string;
|
|
27
|
+
};
|
|
28
|
+
calls?: RawPaths | ({
|
|
29
|
+
paths: RawPaths;
|
|
30
|
+
} & CallSettings);
|
|
31
|
+
files?: RawPaths | {
|
|
32
|
+
paths: RawPaths;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
defaults?: {
|
|
36
|
+
service?: string;
|
|
37
|
+
world?: string;
|
|
38
|
+
person?: string;
|
|
39
|
+
};
|
|
40
|
+
setAside?: SetAsideRules;
|
|
41
|
+
affected?: {
|
|
42
|
+
graph?: string;
|
|
43
|
+
};
|
|
44
|
+
budget?: {
|
|
45
|
+
services?: number;
|
|
46
|
+
checkouts?: number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export type Env = Record<string, string | number | boolean>;
|
|
50
|
+
export type RawReady = string | {
|
|
51
|
+
http?: string;
|
|
52
|
+
command?: string;
|
|
53
|
+
log?: string;
|
|
54
|
+
};
|
|
55
|
+
export interface RawService {
|
|
56
|
+
describe?: string;
|
|
57
|
+
up: string;
|
|
58
|
+
cwd?: string;
|
|
59
|
+
port?: number | 'auto';
|
|
60
|
+
url?: string;
|
|
61
|
+
ready?: RawReady;
|
|
62
|
+
timeout?: number;
|
|
63
|
+
down?: string;
|
|
64
|
+
env?: Env;
|
|
65
|
+
isolate?: {
|
|
66
|
+
env: string;
|
|
67
|
+
};
|
|
68
|
+
drive?: string;
|
|
69
|
+
}
|
|
70
|
+
export type Ready = {
|
|
71
|
+
http: string;
|
|
72
|
+
} | {
|
|
73
|
+
command: string;
|
|
74
|
+
} | {
|
|
75
|
+
log: string;
|
|
76
|
+
} | null;
|
|
77
|
+
export interface Service {
|
|
78
|
+
name: string;
|
|
79
|
+
describe: string | null;
|
|
80
|
+
up: string;
|
|
81
|
+
cwd: string | null;
|
|
82
|
+
port: number | 'auto' | null;
|
|
83
|
+
url: string | null;
|
|
84
|
+
ready: Ready;
|
|
85
|
+
timeoutMs: number;
|
|
86
|
+
down: string | null;
|
|
87
|
+
env: Record<string, string>;
|
|
88
|
+
isolate: {
|
|
89
|
+
env: string;
|
|
90
|
+
} | null;
|
|
91
|
+
drive: string | null;
|
|
92
|
+
}
|
|
93
|
+
export type Real = 'local' | 'stand-in' | 'real';
|
|
94
|
+
export interface Step {
|
|
95
|
+
click?: string;
|
|
96
|
+
type?: string;
|
|
97
|
+
key?: string;
|
|
98
|
+
snapshot?: string;
|
|
99
|
+
fill?: string;
|
|
100
|
+
with?: string;
|
|
101
|
+
role?: string;
|
|
102
|
+
}
|
|
103
|
+
export interface RawPerson {
|
|
104
|
+
describe?: string;
|
|
105
|
+
real?: Real;
|
|
106
|
+
default?: boolean;
|
|
107
|
+
token?: {
|
|
108
|
+
command?: string;
|
|
109
|
+
env?: string;
|
|
110
|
+
};
|
|
111
|
+
browser?: {
|
|
112
|
+
headers?: Record<string, string>;
|
|
113
|
+
storage?: Record<string, string>;
|
|
114
|
+
cookies?: {
|
|
115
|
+
name: string;
|
|
116
|
+
value: string;
|
|
117
|
+
path?: string;
|
|
118
|
+
}[];
|
|
119
|
+
steps?: Step[];
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export interface Person {
|
|
123
|
+
name: string;
|
|
124
|
+
describe: string | null;
|
|
125
|
+
real: Real;
|
|
126
|
+
default: boolean;
|
|
127
|
+
token: {
|
|
128
|
+
command: string;
|
|
129
|
+
} | {
|
|
130
|
+
env: string;
|
|
131
|
+
} | null;
|
|
132
|
+
browser: NonNullable<RawPerson['browser']> | null;
|
|
133
|
+
}
|
|
134
|
+
export interface RawWorld {
|
|
135
|
+
describe?: string;
|
|
136
|
+
extends?: string;
|
|
137
|
+
add?: string;
|
|
138
|
+
before?: string;
|
|
139
|
+
default?: boolean;
|
|
140
|
+
}
|
|
141
|
+
export interface World {
|
|
142
|
+
name: string;
|
|
143
|
+
describe: string | null;
|
|
144
|
+
extends: string | null;
|
|
145
|
+
add: string | null;
|
|
146
|
+
before: string | null;
|
|
147
|
+
default: boolean;
|
|
148
|
+
}
|
|
149
|
+
export type Fidelity = 'fake' | 'recorded' | 'local';
|
|
150
|
+
export interface RawStandin {
|
|
151
|
+
replaces: string;
|
|
152
|
+
by?: string;
|
|
153
|
+
fidelity?: Fidelity;
|
|
154
|
+
services?: string[];
|
|
155
|
+
env?: Env;
|
|
156
|
+
real?: {
|
|
157
|
+
env?: Env;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export interface Standin {
|
|
161
|
+
name: string;
|
|
162
|
+
replaces: string;
|
|
163
|
+
by: string | null;
|
|
164
|
+
fidelity: Fidelity;
|
|
165
|
+
services: string[] | null;
|
|
166
|
+
env: Record<string, string>;
|
|
167
|
+
real: {
|
|
168
|
+
env: Record<string, string>;
|
|
169
|
+
} | null;
|
|
170
|
+
}
|
|
171
|
+
export type RawPaths = (string | {
|
|
172
|
+
path: string;
|
|
173
|
+
covers?: string[];
|
|
174
|
+
})[];
|
|
175
|
+
export interface PathEntry {
|
|
176
|
+
glob: string;
|
|
177
|
+
from: 'manifest' | 'checkout';
|
|
178
|
+
covers: string[];
|
|
179
|
+
}
|
|
180
|
+
export interface PieceSettings {
|
|
181
|
+
preview?: string;
|
|
182
|
+
styles?: string;
|
|
183
|
+
config?: string;
|
|
184
|
+
schemes?: ('light' | 'dark')[];
|
|
185
|
+
compare?: ('tree' | 'errors' | 'violations' | 'screenshot')[];
|
|
186
|
+
viewport?: {
|
|
187
|
+
width: number;
|
|
188
|
+
height: number;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export interface CallSettings {
|
|
192
|
+
service?: string;
|
|
193
|
+
variables?: Record<string, string>;
|
|
194
|
+
unordered?: boolean;
|
|
195
|
+
}
|
|
196
|
+
export interface SetAsideRules {
|
|
197
|
+
keys?: string[];
|
|
198
|
+
values?: string[];
|
|
199
|
+
keep?: string[];
|
|
200
|
+
}
|
|
201
|
+
export declare const KINDS: readonly ['piece', 'flow', 'call', 'file'];
|
|
202
|
+
export type Kind = (typeof KINDS)[number];
|
|
203
|
+
export declare const KIND_BLOCK: Readonly<Record<Kind, 'pieces' | 'flows' | 'calls' | 'files'>>;
|
|
204
|
+
export interface Scenarios {
|
|
205
|
+
pieces: {
|
|
206
|
+
paths: PathEntry[];
|
|
207
|
+
} & PieceSettings;
|
|
208
|
+
flows: {
|
|
209
|
+
paths: PathEntry[];
|
|
210
|
+
service?: string;
|
|
211
|
+
};
|
|
212
|
+
calls: {
|
|
213
|
+
paths: PathEntry[];
|
|
214
|
+
} & CallSettings;
|
|
215
|
+
files: {
|
|
216
|
+
paths: PathEntry[];
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
export interface Manifest {
|
|
220
|
+
file: string;
|
|
221
|
+
dir: string;
|
|
222
|
+
raw: RawManifest;
|
|
223
|
+
base: string;
|
|
224
|
+
checkout: string | null;
|
|
225
|
+
prepare: string | null;
|
|
226
|
+
seed: boolean;
|
|
227
|
+
overlay: {
|
|
228
|
+
from: string;
|
|
229
|
+
to: string;
|
|
230
|
+
}[];
|
|
231
|
+
services: Record<string, Service>;
|
|
232
|
+
signIn: {
|
|
233
|
+
command: string;
|
|
234
|
+
service: string | null;
|
|
235
|
+
cwd: string | null;
|
|
236
|
+
} | null;
|
|
237
|
+
people: Record<string, Person>;
|
|
238
|
+
worlds: Record<string, World>;
|
|
239
|
+
standins: Record<string, Standin>;
|
|
240
|
+
scenarios: Scenarios;
|
|
241
|
+
defaults: {
|
|
242
|
+
service: string | null;
|
|
243
|
+
world: string | null;
|
|
244
|
+
person: string | null;
|
|
245
|
+
};
|
|
246
|
+
setAside: Required<SetAsideRules>;
|
|
247
|
+
affected: {
|
|
248
|
+
graph: string | null;
|
|
249
|
+
};
|
|
250
|
+
budget: {
|
|
251
|
+
services: number;
|
|
252
|
+
checkouts: number;
|
|
253
|
+
};
|
|
254
|
+
lineOf(at: readonly string[], key?: string): number | undefined;
|
|
255
|
+
}
|
|
@@ -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 {};
|