@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.
- package/LICENSE +21 -0
- package/README.md +102 -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 +29 -0
- package/dist/commands/command.js +29 -0
- package/dist/commands/compare.d.ts +4 -0
- package/dist/commands/compare.js +84 -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 +82 -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 +49 -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 +82 -0
- package/dist/compare/compare.js +310 -0
- package/dist/compare/diff.d.ts +15 -0
- package/dist/compare/diff.js +105 -0
- package/dist/compare/index.d.ts +4 -0
- package/dist/compare/index.js +4 -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 +84 -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/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 +401 -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 +57 -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 +244 -0
- package/dist/manifest/types.d.ts +253 -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 +4 -0
- package/dist/run/index.js +3 -0
- package/dist/run/observation.d.ts +27 -0
- package/dist/run/observation.js +1 -0
- package/dist/run/session.d.ts +32 -0
- package/dist/run/session.js +258 -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 +22 -0
- package/dist/services/service.js +284 -0
- package/dist/stage/api.d.ts +28 -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 +31 -0
- package/dist/stage/server.js +250 -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 +430 -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,82 @@
|
|
|
1
|
+
import { runnerOf } from '../kinds/index.js';
|
|
2
|
+
import { checkoutOf, manifestOf, said } from './command.js';
|
|
3
|
+
import { many, one } from '../args.js';
|
|
4
|
+
import { RehearseError, usage } from '../errors.js';
|
|
5
|
+
import { readScenarios, refOf } from '../scenarios/index.js';
|
|
6
|
+
import { runSide, keep } from '../run/index.js';
|
|
7
|
+
import { infoOf, checkoutFor } from '../git/index.js';
|
|
8
|
+
import { VERSION } from '../version.js';
|
|
9
|
+
export function observationText(o) {
|
|
10
|
+
const head = `${o.ok ? '✓' : '✗'} ${o.scenario.name} (${o.scenario.id})`;
|
|
11
|
+
const where = ` on ${o.checkout.path}${o.checkout.commit ? ` at ${o.checkout.commit.slice(0, 12)}${o.checkout.dirty ? ' with changes' : ''}` : ''}${o.world ? ` · world ${o.world}` : ''}${o.person ? ` · as ${o.person}` : ''}`;
|
|
12
|
+
const standins = o.standins.length
|
|
13
|
+
? ` stand-ins: ${o.standins.map((s) => `${s.name}${s.real ? ' (real)' : ` (${s.fidelity})`}`).join(', ')}`
|
|
14
|
+
: '';
|
|
15
|
+
const broke = o.broke ? ` broke at ${o.broke.step}: ${o.broke.says}` : '';
|
|
16
|
+
const failures = o.failures.map((f) => ` ${f.line ? `line ${f.line}: ` : f.step ? `step ${f.step}: ` : ''}${f.text}${f.expected !== null || f.got !== null ? `\n expected ${f.expected ?? '—'}, got ${f.got ?? '—'}` : ''}`);
|
|
17
|
+
const observed = o.observed;
|
|
18
|
+
const summary = observed?.kind === 'call'
|
|
19
|
+
? ` ${String(observed.request)} as ${String(observed.who)} → ${String(observed.status)}`
|
|
20
|
+
: observed?.kind === 'file'
|
|
21
|
+
? ` exit ${String(observed.exit)} · ${(observed.outputs ?? []).map((x) => `${x.file} (${x.layout}${x.rows ? `, ${x.rows.length} rows` : ''})`).join(', ')}`
|
|
22
|
+
: '';
|
|
23
|
+
return [head, where, summary, standins, broke, ...failures].filter(Boolean).join('\n');
|
|
24
|
+
}
|
|
25
|
+
export const run = {
|
|
26
|
+
name: 'run',
|
|
27
|
+
summary: 'Runs one scenario on a checkout and prints what it observed.',
|
|
28
|
+
usage: 'rehearse run <scenario> [--on <checkout|ref>] [--world <name>] [--as <person>] [--real <stand-in>]… [--keep] [--json]',
|
|
29
|
+
spec: { valued: ['on', 'world', 'as', 'real'], bare: ['keep'] },
|
|
30
|
+
async run(args, ctx) {
|
|
31
|
+
const id = args.positional[0];
|
|
32
|
+
if (!id)
|
|
33
|
+
throw usage('Name the scenario to run: rehearse list shows their ids.');
|
|
34
|
+
const m = manifestOf(ctx);
|
|
35
|
+
const repo = checkoutOf(m, null, ctx.cwd);
|
|
36
|
+
const on = one(args, 'on');
|
|
37
|
+
const target = on ? await checkoutFor(m, repo, on, ctx.progress, [], ctx.cwd) : { path: repo, ref: null };
|
|
38
|
+
const read = await readScenarios(m, target.path);
|
|
39
|
+
const s = read.scenarios.find((x) => x.id === id) ??
|
|
40
|
+
read.scenarios.find((x) => x.id.endsWith(id) || x.name === id);
|
|
41
|
+
if (!s) {
|
|
42
|
+
const refused = read.refused.find((r) => id.startsWith(r.file));
|
|
43
|
+
throw new RehearseError('no_scenario', refused
|
|
44
|
+
? `${refused.file}${refused.line ? `:${refused.line}` : ''}: ${refused.says}`
|
|
45
|
+
: `There is no scenario “${id}” in ${target.path}. rehearse list shows them.`);
|
|
46
|
+
}
|
|
47
|
+
const side = await runSide(m, target.path, [s], {
|
|
48
|
+
world: one(args, 'world'),
|
|
49
|
+
as: one(args, 'as'),
|
|
50
|
+
real: new Set(many(args, 'real')),
|
|
51
|
+
keepUp: args.flags.has('keep'),
|
|
52
|
+
progress: ctx.progress,
|
|
53
|
+
ref: target.ref,
|
|
54
|
+
});
|
|
55
|
+
let o = side.observations.get(s.id);
|
|
56
|
+
if (!o) {
|
|
57
|
+
const why = side.broke ?? side.notRun[0] ?? { step: 'runner', says: "It wasn't run." };
|
|
58
|
+
o = {
|
|
59
|
+
v: 1,
|
|
60
|
+
ok: false,
|
|
61
|
+
scenario: refOf(s),
|
|
62
|
+
checkout: infoOf(m, target.path, target.ref),
|
|
63
|
+
world: one(args, 'world') ?? s.world,
|
|
64
|
+
person: one(args, 'as') ?? s.person,
|
|
65
|
+
standins: [],
|
|
66
|
+
failures: [],
|
|
67
|
+
broke: { step: why.step, says: why.says },
|
|
68
|
+
observed: null,
|
|
69
|
+
artifacts: [],
|
|
70
|
+
ms: 0,
|
|
71
|
+
at: new Date().toISOString(),
|
|
72
|
+
rehearse: VERSION,
|
|
73
|
+
runner: (await runnerOf(s.kind)).version,
|
|
74
|
+
cacheKey: null,
|
|
75
|
+
cached: false,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
else
|
|
79
|
+
keep(m, o);
|
|
80
|
+
return said(o, `${observationText(o)}\n`, o.ok ? 0 : 1);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Command } from './command.ts';
|
|
2
|
+
import type { Manifest } from '../manifest/index.ts';
|
|
3
|
+
export declare function servicesOut(m: Manifest): Promise<{
|
|
4
|
+
v: 1;
|
|
5
|
+
services: {
|
|
6
|
+
name: string;
|
|
7
|
+
describe: string | null;
|
|
8
|
+
up: string;
|
|
9
|
+
cwd: string | null;
|
|
10
|
+
url: string | null;
|
|
11
|
+
port: number | "auto" | null;
|
|
12
|
+
ready: import("../manifest/types.ts").Ready;
|
|
13
|
+
down: string | null;
|
|
14
|
+
isolate: {
|
|
15
|
+
env: string;
|
|
16
|
+
} | null;
|
|
17
|
+
drive: string | null;
|
|
18
|
+
standins: string[];
|
|
19
|
+
running: {
|
|
20
|
+
checkout: string;
|
|
21
|
+
url: string | null;
|
|
22
|
+
port: number | null;
|
|
23
|
+
pid: number;
|
|
24
|
+
since: string;
|
|
25
|
+
}[];
|
|
26
|
+
}[];
|
|
27
|
+
}>;
|
|
28
|
+
export declare const services: Command;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { manifestOf, said } from './command.js';
|
|
2
|
+
import { liveServices } from '../services/index.js';
|
|
3
|
+
export async function servicesOut(m) {
|
|
4
|
+
const running = await liveServices(m);
|
|
5
|
+
return {
|
|
6
|
+
v: 1,
|
|
7
|
+
services: Object.values(m.services).map((s) => ({
|
|
8
|
+
name: s.name,
|
|
9
|
+
describe: s.describe,
|
|
10
|
+
up: s.up,
|
|
11
|
+
cwd: s.cwd,
|
|
12
|
+
url: s.url,
|
|
13
|
+
port: s.port,
|
|
14
|
+
ready: s.ready,
|
|
15
|
+
down: s.down,
|
|
16
|
+
isolate: s.isolate,
|
|
17
|
+
drive: s.drive,
|
|
18
|
+
standins: Object.values(m.standins)
|
|
19
|
+
.filter((x) => x.services === null || x.services.includes(s.name))
|
|
20
|
+
.map((x) => x.name),
|
|
21
|
+
running: running
|
|
22
|
+
.filter((r) => r.name === s.name)
|
|
23
|
+
.map((r) => ({ checkout: r.checkout, url: r.url, port: r.port, pid: r.pid, since: r.since })),
|
|
24
|
+
})),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export const services = {
|
|
28
|
+
name: 'services',
|
|
29
|
+
summary: 'What can come up, how Rehearse knows it is ready, and what is up now.',
|
|
30
|
+
usage: 'rehearse services [--json]',
|
|
31
|
+
spec: { valued: [], bare: [] },
|
|
32
|
+
async run(_args, ctx) {
|
|
33
|
+
const m = manifestOf(ctx);
|
|
34
|
+
const out = await servicesOut(m);
|
|
35
|
+
if (out.services.length === 0)
|
|
36
|
+
return said(out, 'This manifest declares no services.\n');
|
|
37
|
+
const lines = out.services.map((s) => {
|
|
38
|
+
const up = s.running.length
|
|
39
|
+
? `up: ${s.running.map((r) => `${r.url ?? `pid ${r.pid}`} (${r.checkout})`).join(', ')}`
|
|
40
|
+
: 'not up';
|
|
41
|
+
const extra = [
|
|
42
|
+
s.drive ? `driven by \`${s.drive}\`` : null,
|
|
43
|
+
s.standins.length ? `stand-ins: ${s.standins.join(', ')}` : null,
|
|
44
|
+
]
|
|
45
|
+
.filter(Boolean)
|
|
46
|
+
.join(' · ');
|
|
47
|
+
return `${s.name}${s.describe ? ` — ${s.describe}` : ''}\n \`${s.up}\`${s.url ? ` at ${s.url}` : ''}\n ${up}${extra ? `\n ${extra}` : ''}`;
|
|
48
|
+
});
|
|
49
|
+
return said(out, `${lines.join('\n')}\n`);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { checkoutOf, manifestOf, said } from './command.js';
|
|
2
|
+
import { one } from '../args.js';
|
|
3
|
+
import { errorText, usage } from '../errors.js';
|
|
4
|
+
import { startStage } from '../stage/index.js';
|
|
5
|
+
export const DEFAULT_STAGE_PORT = 4400;
|
|
6
|
+
export function portOf(given) {
|
|
7
|
+
if (given === null)
|
|
8
|
+
return { port: DEFAULT_STAGE_PORT, anyPort: true };
|
|
9
|
+
const port = /^\d+$/.test(given) ? Number(given) : NaN;
|
|
10
|
+
if (!Number.isInteger(port) || port < 1 || port > 65_535)
|
|
11
|
+
throw usage(`--port takes a port from 1 to 65535, not “${given}”.`);
|
|
12
|
+
return { port, anyPort: false };
|
|
13
|
+
}
|
|
14
|
+
export const stage = {
|
|
15
|
+
name: 'stage',
|
|
16
|
+
summary: "Serves the stage: every scenario on one page, in Base, Head and Diff, with Works, Doesn't and a note.",
|
|
17
|
+
usage: 'rehearse stage [--base <ref|checkout>] [--head <ref|checkout>] [--port <port>]\n\nIt runs until you stop it (Ctrl-C), and stops the services it brought up.',
|
|
18
|
+
spec: { valued: ['base', 'head', 'port'], bare: [] },
|
|
19
|
+
async run(args, ctx) {
|
|
20
|
+
const m = manifestOf(ctx);
|
|
21
|
+
const { port, anyPort } = portOf(one(args, 'port'));
|
|
22
|
+
const s = await startStage({
|
|
23
|
+
manifest: m,
|
|
24
|
+
repo: checkoutOf(m, null, ctx.cwd),
|
|
25
|
+
cwd: ctx.cwd,
|
|
26
|
+
head: one(args, 'head'),
|
|
27
|
+
base: one(args, 'base'),
|
|
28
|
+
port,
|
|
29
|
+
anyPort,
|
|
30
|
+
progress: ctx.progress,
|
|
31
|
+
});
|
|
32
|
+
process.stdout.write(ctx.json
|
|
33
|
+
? `${JSON.stringify({ v: 1, url: s.url, port: s.port, pid: process.pid })}\n`
|
|
34
|
+
: `The stage is at ${s.url}\nStop it with Ctrl-C, or kill ${process.pid}.\n`);
|
|
35
|
+
const code = await new Promise((resolve) => {
|
|
36
|
+
const stopWithTheServicesItBroughtUp = (exit) => () => {
|
|
37
|
+
s.forget();
|
|
38
|
+
void s.close().finally(() => resolve(exit));
|
|
39
|
+
};
|
|
40
|
+
process.once('SIGINT', stopWithTheServicesItBroughtUp(0));
|
|
41
|
+
process.once('SIGTERM', stopWithTheServicesItBroughtUp(0));
|
|
42
|
+
process.once('uncaughtException', (error) => {
|
|
43
|
+
process.stderr.write(`The stage stopped: ${errorText(error)}\n`);
|
|
44
|
+
stopWithTheServicesItBroughtUp(1)();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
return said(null, '', code);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { checkoutOf, manifestOf, said } from './command.js';
|
|
3
|
+
import { many, one } from '../args.js';
|
|
4
|
+
import { RehearseError } from '../errors.js';
|
|
5
|
+
import { bringDown, bringUp, liveServices, makeRoom, release, runningServices, } from '../services/index.js';
|
|
6
|
+
import { baseVars } from '../run/index.js';
|
|
7
|
+
import { applyWorld } from '../worlds/index.js';
|
|
8
|
+
import { overlay } from '../git/index.js';
|
|
9
|
+
const rowOf = (r) => ({
|
|
10
|
+
name: r.name,
|
|
11
|
+
checkout: r.checkout,
|
|
12
|
+
url: r.url,
|
|
13
|
+
port: r.port,
|
|
14
|
+
pid: r.pid,
|
|
15
|
+
since: r.since,
|
|
16
|
+
standins: r.standins,
|
|
17
|
+
});
|
|
18
|
+
export const up = {
|
|
19
|
+
name: 'up',
|
|
20
|
+
summary: 'Brings services up and leaves them running, with a world built on them.',
|
|
21
|
+
usage: 'rehearse up [<service>…] [--on <checkout>] [--world <name>] [--real <stand-in>]… [--json]',
|
|
22
|
+
spec: { valued: ['on', 'world', 'real'], bare: [] },
|
|
23
|
+
async run(args, ctx) {
|
|
24
|
+
const m = manifestOf(ctx);
|
|
25
|
+
const checkout = checkoutOf(m, one(args, 'on'), ctx.cwd);
|
|
26
|
+
const names = args.positional.length ? args.positional : Object.keys(m.services);
|
|
27
|
+
for (const n of names)
|
|
28
|
+
if (!m.services[n])
|
|
29
|
+
throw new RehearseError('no_service', `There is no service “${n}”: there is ${Object.keys(m.services).join(', ') || 'none'}.`);
|
|
30
|
+
const world = one(args, 'world') ?? m.defaults.world;
|
|
31
|
+
overlay(m, checkout);
|
|
32
|
+
await makeRoom(m, checkout, ctx.progress);
|
|
33
|
+
let running = await liveServices(m, checkout);
|
|
34
|
+
const fresh = names.filter((n) => !running.some((r) => r.name === n));
|
|
35
|
+
if (world && fresh.length)
|
|
36
|
+
await applyWorld(m, world, 'before', checkout, baseVars(m, checkout, running));
|
|
37
|
+
for (const n of fresh) {
|
|
38
|
+
const r = await bringUp(m, m.services[n], checkout, {
|
|
39
|
+
world,
|
|
40
|
+
real: new Set(many(args, 'real')),
|
|
41
|
+
vars: baseVars(m, checkout, running),
|
|
42
|
+
progress: ctx.progress,
|
|
43
|
+
});
|
|
44
|
+
running = [...running, r];
|
|
45
|
+
}
|
|
46
|
+
for (const r of running)
|
|
47
|
+
release(r);
|
|
48
|
+
if (world && fresh.length)
|
|
49
|
+
await applyWorld(m, world, 'add', checkout, baseVars(m, checkout, running));
|
|
50
|
+
const out = {
|
|
51
|
+
v: 1,
|
|
52
|
+
checkout,
|
|
53
|
+
world,
|
|
54
|
+
services: running.filter((r) => names.includes(r.name)).map(rowOf),
|
|
55
|
+
};
|
|
56
|
+
return said(out, `${out.services.map((s) => `${s.name} is up${s.url ? ` at ${s.url}` : ''} (pid ${s.pid})`).join('\n')}\n${world ? `World: ${world}.\n` : ''}Stop with \`rehearse down\`.\n`);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
export const down = {
|
|
60
|
+
name: 'down',
|
|
61
|
+
summary: 'Stops services Rehearse brought up: in one checkout, or everywhere with --all.',
|
|
62
|
+
usage: 'rehearse down [<service>…] [--on <checkout>] [--all] [--json]',
|
|
63
|
+
spec: { valued: ['on'], bare: ['all'] },
|
|
64
|
+
async run(args, ctx) {
|
|
65
|
+
const m = manifestOf(ctx);
|
|
66
|
+
const all = args.flags.has('all');
|
|
67
|
+
const checkout = all ? null : checkoutOf(m, one(args, 'on'), ctx.cwd);
|
|
68
|
+
const these = runningServices(m.dir).filter((r) => (checkout === null || path.resolve(r.checkout) === path.resolve(checkout)) &&
|
|
69
|
+
(args.positional.length === 0 || args.positional.includes(r.name)));
|
|
70
|
+
for (const r of these)
|
|
71
|
+
await bringDown(m, r, ctx.progress);
|
|
72
|
+
const out = { v: 1, checkout, world: null, services: these.map(rowOf) };
|
|
73
|
+
return said(out, these.length
|
|
74
|
+
? `${these.map((r) => `${r.name} is down (${r.checkout})`).join('\n')}\n`
|
|
75
|
+
: 'Nothing Rehearse brought up is running.\n');
|
|
76
|
+
},
|
|
77
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { said } from './command.js';
|
|
4
|
+
import { usage } from '../errors.js';
|
|
5
|
+
import { placeOf, SCHEMAS, validate as check } from '../schema.js';
|
|
6
|
+
import { readYaml } from '../manifest/index.js';
|
|
7
|
+
const readStdin = async () => {
|
|
8
|
+
const chunks = [];
|
|
9
|
+
for await (const chunk of process.stdin)
|
|
10
|
+
chunks.push(chunk);
|
|
11
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
12
|
+
};
|
|
13
|
+
export const validate = {
|
|
14
|
+
name: 'validate',
|
|
15
|
+
summary: "Checks a JSON or YAML file (or stdin) against one of Rehearse's schemas, and says what is wrong where.",
|
|
16
|
+
usage: `rehearse validate <schema> [<file>] [--json]\n\nSchemas: ${SCHEMAS.join(', ')}.\nWith no file, it reads stdin: rehearse services --json | rehearse validate services`,
|
|
17
|
+
spec: { valued: [], bare: [] },
|
|
18
|
+
async run(args, ctx) {
|
|
19
|
+
const [name, file] = args.positional;
|
|
20
|
+
if (!name || !SCHEMAS.includes(name))
|
|
21
|
+
throw usage(`Name a schema: ${SCHEMAS.join(', ')}.`);
|
|
22
|
+
const text = file ? readFileSync(path.resolve(ctx.cwd, file), 'utf8') : await readStdin();
|
|
23
|
+
const read = readYaml(text, file ?? 'stdin');
|
|
24
|
+
const oneLine = !text.trim().includes('\n');
|
|
25
|
+
const errors = check(name, read.value).map((e) => {
|
|
26
|
+
const line = oneLine ? undefined : read.lineOf(e.at, e.key);
|
|
27
|
+
return { at: placeOf(e.at), ...(line !== undefined && { line }), says: e.says };
|
|
28
|
+
});
|
|
29
|
+
const out = { v: 1, ok: errors.length === 0, schema: name, file: file ?? null, errors };
|
|
30
|
+
const text2 = out.ok
|
|
31
|
+
? `${file ?? 'It'} meets the ${name} schema.\n`
|
|
32
|
+
: `${errors.map((e) => `✗ ${e.line ? `line ${e.line}: ` : ''}${e.says}`).join('\n')}\n`;
|
|
33
|
+
return said(out, text2, out.ok ? 0 : 1);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { manifestOf, said } from './command.js';
|
|
2
|
+
import { worldsOut } from '../worlds/index.js';
|
|
3
|
+
export const worlds = {
|
|
4
|
+
name: 'worlds',
|
|
5
|
+
summary: 'The named starting states, each with the chain it is built from.',
|
|
6
|
+
usage: 'rehearse worlds [--json]',
|
|
7
|
+
spec: { valued: [], bare: [] },
|
|
8
|
+
async run(_args, ctx) {
|
|
9
|
+
const out = worldsOut(manifestOf(ctx));
|
|
10
|
+
if (out.worlds.length === 0)
|
|
11
|
+
return said(out, 'This manifest declares no worlds: scenarios start from what the services hold.\n');
|
|
12
|
+
const lines = out.worlds.map((w) => `${w.name}${w.default ? ' (default)' : ''}${w.describe ? ` — ${w.describe}` : ''}${w.chain.length > 1 ? `\n built from ${w.chain.join(' → ')}` : ''}`);
|
|
13
|
+
return said(out, `${lines.join('\n')}\n`);
|
|
14
|
+
},
|
|
15
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { RehearseError } from '../errors.js';
|
|
3
|
+
import { readYaml } from '../manifest/index.js';
|
|
4
|
+
import { globToRegExp } from '../scenarios/index.js';
|
|
5
|
+
import { validate } from '../schema.js';
|
|
6
|
+
export function readAnnouncement(file) {
|
|
7
|
+
let text;
|
|
8
|
+
try {
|
|
9
|
+
text = readFileSync(file, 'utf8');
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
throw new RehearseError('announce', `Rehearse can't read the announcement ${file}: ${error.message}`);
|
|
13
|
+
}
|
|
14
|
+
const read = readYaml(text, file);
|
|
15
|
+
const invalid = validate('announce', read.value);
|
|
16
|
+
if (invalid.length) {
|
|
17
|
+
const line = read.lineOf(invalid[0].at, invalid[0].key);
|
|
18
|
+
throw new RehearseError('announce', `${file}${line ? `:${line}` : ''}: ${invalid[0].says}`, {
|
|
19
|
+
file,
|
|
20
|
+
...(line !== undefined && { line }),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return read.value.changes;
|
|
24
|
+
}
|
|
25
|
+
export function announcementFor(id, announced) {
|
|
26
|
+
return (announced.find((a) => a.scenario === id || (/[*?{[]/.test(a.scenario) && globToRegExp(a.scenario).test(id))) ?? null);
|
|
27
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type Failure } from '../kinds/index.ts';
|
|
2
|
+
import type { Manifest } from '../manifest/index.ts';
|
|
3
|
+
import { type CheckoutInfo, type Observation } from '../run/index.ts';
|
|
4
|
+
import { type ScenarioRef } from '../scenarios/index.ts';
|
|
5
|
+
import type { Difference } from './diff.ts';
|
|
6
|
+
import { type Counts as AsideCounts } from './setaside.ts';
|
|
7
|
+
import { type Counts, type Verdict } from './verdict.ts';
|
|
8
|
+
export interface CompareOptions {
|
|
9
|
+
repo: string;
|
|
10
|
+
cwd: string;
|
|
11
|
+
head: string | null;
|
|
12
|
+
base: string | null;
|
|
13
|
+
ids: string[];
|
|
14
|
+
affected: boolean;
|
|
15
|
+
announce: string | null;
|
|
16
|
+
said: string[];
|
|
17
|
+
fresh: boolean;
|
|
18
|
+
world: string | null;
|
|
19
|
+
as: string | null;
|
|
20
|
+
real: ReadonlySet<string>;
|
|
21
|
+
progress: (line: string) => void;
|
|
22
|
+
}
|
|
23
|
+
export interface Side {
|
|
24
|
+
checkout: CheckoutInfo;
|
|
25
|
+
ok: boolean;
|
|
26
|
+
step: string | null;
|
|
27
|
+
says: string | null;
|
|
28
|
+
cached: number;
|
|
29
|
+
}
|
|
30
|
+
export interface Compared {
|
|
31
|
+
scenario: ScenarioRef;
|
|
32
|
+
verdict: Verdict;
|
|
33
|
+
changed: boolean;
|
|
34
|
+
said: 'announced' | 'edited' | null;
|
|
35
|
+
edited: boolean;
|
|
36
|
+
why: string | null;
|
|
37
|
+
failsOnBase: boolean;
|
|
38
|
+
failsOnHead: boolean;
|
|
39
|
+
differences: Difference[];
|
|
40
|
+
setAside: Partial<AsideCounts>;
|
|
41
|
+
failures: Failure[];
|
|
42
|
+
baseFailures: Failure[];
|
|
43
|
+
cached: boolean;
|
|
44
|
+
observations: {
|
|
45
|
+
base: string | null;
|
|
46
|
+
head: string | null;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export interface Comparison {
|
|
50
|
+
v: 1;
|
|
51
|
+
ok: boolean;
|
|
52
|
+
base: Side;
|
|
53
|
+
head: Side;
|
|
54
|
+
line: string;
|
|
55
|
+
counts: Counts;
|
|
56
|
+
scenarios: Compared[];
|
|
57
|
+
notRun: {
|
|
58
|
+
scenario: ScenarioRef;
|
|
59
|
+
side: 'base' | 'head';
|
|
60
|
+
step: string;
|
|
61
|
+
says: string;
|
|
62
|
+
}[];
|
|
63
|
+
gone: ScenarioRef[];
|
|
64
|
+
announcedUnchanged: {
|
|
65
|
+
scenario: string;
|
|
66
|
+
why: string;
|
|
67
|
+
}[];
|
|
68
|
+
byChange: {
|
|
69
|
+
path: string;
|
|
70
|
+
scenarios: string[];
|
|
71
|
+
}[];
|
|
72
|
+
standins: Observation['standins'];
|
|
73
|
+
refused: {
|
|
74
|
+
side: 'base' | 'head';
|
|
75
|
+
file: string;
|
|
76
|
+
line?: number;
|
|
77
|
+
says: string;
|
|
78
|
+
}[];
|
|
79
|
+
ms: number;
|
|
80
|
+
}
|
|
81
|
+
export declare function changedFiles(head: string, baseCommit: string): string[];
|
|
82
|
+
export declare function compare(m: Manifest, o: CompareOptions): Promise<Comparison>;
|