@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,24 @@
|
|
|
1
|
+
export const HURL_WORDS = {
|
|
2
|
+
section: (name) => `[${name}] isn’t read by Rehearse: it reads Hurl’s plain part`,
|
|
3
|
+
option: (name) => `the option ${name} isn’t read by Rehearse`,
|
|
4
|
+
query: (what) => `the query “${what}” isn’t read by Rehearse`,
|
|
5
|
+
filter: (name) => `the filter ${name} isn’t read by Rehearse`,
|
|
6
|
+
predicate: (what) => `the predicate in “${what}” isn’t read by Rehearse`,
|
|
7
|
+
value: (what) => `Rehearse can’t read the value ${what}`,
|
|
8
|
+
body: (kind) => `a ${kind} body isn’t read by Rehearse`,
|
|
9
|
+
line: 'Rehearse can’t read this line as Hurl’s plain part',
|
|
10
|
+
keyValue: 'a line here is key: value',
|
|
11
|
+
capture: 'a capture is name: query',
|
|
12
|
+
twice: (name, first) => `two calls are named “${name}” (the first at line ${first})`,
|
|
13
|
+
unclosed: 'a string or a body here is never closed',
|
|
14
|
+
noValue: (name) => `{{${name}}} has no value`,
|
|
15
|
+
noOne: (who, named) => named.length
|
|
16
|
+
? `No one to send as ${who}: the sign-in named ${named.join(', ')}.`
|
|
17
|
+
: `No one to send as ${who}: no one is signed in.`,
|
|
18
|
+
noCapture: (name) => `capture ${name}`,
|
|
19
|
+
aValue: 'a value',
|
|
20
|
+
nothing: '(nothing there)',
|
|
21
|
+
notJson: 'the body is not JSON',
|
|
22
|
+
count: 'count needs a collection',
|
|
23
|
+
unreached: (why) => `It didn’t answer: ${why}`,
|
|
24
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Column } from './layouts.ts';
|
|
2
|
+
type Layout = 'csv' | 'tsv' | 'json' | 'lines' | 'fixed' | 'zip';
|
|
3
|
+
export interface OutputSpec {
|
|
4
|
+
file: string;
|
|
5
|
+
layout: Layout;
|
|
6
|
+
header?: boolean;
|
|
7
|
+
columns?: (string | Column)[];
|
|
8
|
+
unordered?: boolean;
|
|
9
|
+
entries?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
export interface FileSpec {
|
|
12
|
+
name: string;
|
|
13
|
+
describe?: string;
|
|
14
|
+
world?: string;
|
|
15
|
+
person?: string;
|
|
16
|
+
services?: string[];
|
|
17
|
+
covers?: string[];
|
|
18
|
+
input?: {
|
|
19
|
+
file?: string;
|
|
20
|
+
command?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
};
|
|
23
|
+
run: string;
|
|
24
|
+
cwd?: string;
|
|
25
|
+
env?: Record<string, string | number | boolean>;
|
|
26
|
+
timeout?: number;
|
|
27
|
+
output: OutputSpec | OutputSpec[];
|
|
28
|
+
setAside?: {
|
|
29
|
+
columns?: string[];
|
|
30
|
+
values?: string[];
|
|
31
|
+
keep?: string[];
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export interface Output {
|
|
35
|
+
file: string;
|
|
36
|
+
layout: string;
|
|
37
|
+
columns?: string[];
|
|
38
|
+
rows?: string[][];
|
|
39
|
+
lines?: string[];
|
|
40
|
+
json?: unknown;
|
|
41
|
+
entries?: Output[];
|
|
42
|
+
}
|
|
43
|
+
export declare const outputsOf: (spec: FileSpec) => OutputSpec[];
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, statSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { clip, jsonDifferences, noCounts, setAsideJson, setAsideText, textDifferences, } from '../../compare/index.js';
|
|
5
|
+
import { sh, tail } from '../../exec.js';
|
|
6
|
+
import { fill, fillEnv, hashOf, readYaml } from '../../manifest/index.js';
|
|
7
|
+
import { scrub, scrubDeep } from '../../people/index.js';
|
|
8
|
+
import { validate } from '../../schema.js';
|
|
9
|
+
import { registerReader } from '../../scenarios/index.js';
|
|
10
|
+
import { registerRunner } from '../kind.js';
|
|
11
|
+
import { entryLayout, isUtf8WithoutNul, parseDelimited, parseFixed, readZip, } from './layouts.js';
|
|
12
|
+
export const outputsOf = (spec) => Array.isArray(spec.output) ? spec.output : [spec.output];
|
|
13
|
+
registerReader({
|
|
14
|
+
kind: 'file',
|
|
15
|
+
read(f, text, ctx) {
|
|
16
|
+
const read = readYaml(text, f.file);
|
|
17
|
+
const invalid = validate('file-scenario', read.value);
|
|
18
|
+
if (invalid.length) {
|
|
19
|
+
const first = invalid[0];
|
|
20
|
+
const line = read.lineOf(first.at, first.key);
|
|
21
|
+
throw Object.assign(new Error(first.says), { says: first.says, ...(line !== undefined && { line }) });
|
|
22
|
+
}
|
|
23
|
+
const spec = read.value;
|
|
24
|
+
let input = '';
|
|
25
|
+
if (spec.input?.file) {
|
|
26
|
+
const at = path.resolve(path.dirname(f.abs), spec.input.file);
|
|
27
|
+
if (existsSync(at) && statSync(at).isFile())
|
|
28
|
+
input = createHash('sha256').update(readFileSync(at)).digest('hex');
|
|
29
|
+
}
|
|
30
|
+
const m = ctx.manifest;
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
id: f.file,
|
|
34
|
+
kind: 'file',
|
|
35
|
+
name: spec.name,
|
|
36
|
+
file: f.file,
|
|
37
|
+
abs: f.abs,
|
|
38
|
+
line: null,
|
|
39
|
+
from: f.from,
|
|
40
|
+
area: ctx.area,
|
|
41
|
+
definition: hashOf({ spec, input }),
|
|
42
|
+
world: spec.world ?? m.defaults.world,
|
|
43
|
+
person: spec.person ?? m.defaults.person,
|
|
44
|
+
service: spec.services?.[0] ?? null,
|
|
45
|
+
covers: [...f.covers, ...(spec.covers ?? [])],
|
|
46
|
+
spec,
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
function columnsOf(o, header, width) {
|
|
52
|
+
if (header)
|
|
53
|
+
return header;
|
|
54
|
+
const given = (o.columns ?? []).map((c) => (typeof c === 'string' ? c : c.name));
|
|
55
|
+
return Array.from({ length: Math.max(width, given.length) }, (_, i) => given[i] ?? `column ${i + 1}`);
|
|
56
|
+
}
|
|
57
|
+
function readDelimited(text, o, layout, file) {
|
|
58
|
+
const rows = parseDelimited(text, layout === 'csv' ? ',' : '\t');
|
|
59
|
+
const header = o.header === false ? null : (rows.shift() ?? []);
|
|
60
|
+
const width = Math.max(0, ...rows.map((r) => r.length));
|
|
61
|
+
return { file, layout, columns: columnsOf(o, header, width), rows };
|
|
62
|
+
}
|
|
63
|
+
function readText(data, layout, o, file) {
|
|
64
|
+
if (!isUtf8WithoutNul(data))
|
|
65
|
+
return {
|
|
66
|
+
file,
|
|
67
|
+
layout: 'lines',
|
|
68
|
+
lines: [
|
|
69
|
+
`(binary: ${data.length} bytes, sha256 ${createHash('sha256').update(data).digest('hex').slice(0, 16)})`,
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
const text = data.toString('utf8');
|
|
73
|
+
switch (layout) {
|
|
74
|
+
case 'csv':
|
|
75
|
+
case 'tsv':
|
|
76
|
+
return readDelimited(text, o, layout, file);
|
|
77
|
+
case 'json':
|
|
78
|
+
try {
|
|
79
|
+
return { file, layout, json: JSON.parse(text) };
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return { file, layout: 'lines', lines: text.split(/\r?\n/) };
|
|
83
|
+
}
|
|
84
|
+
case 'fixed': {
|
|
85
|
+
const columns = (o.columns ?? []).filter((c) => typeof c === 'object');
|
|
86
|
+
return { file, layout, columns: columns.map((c) => c.name), rows: parseFixed(text, columns) };
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return { file, layout: 'lines', lines: text.replace(/\r?\n$/, '').split(/\r?\n/) };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function readEntry(name, data, layouts) {
|
|
93
|
+
const layout = entryLayout(name, layouts);
|
|
94
|
+
if (layout === 'skip')
|
|
95
|
+
return { file: name, layout: 'skip' };
|
|
96
|
+
if (layout === 'zip') {
|
|
97
|
+
try {
|
|
98
|
+
return {
|
|
99
|
+
file: name,
|
|
100
|
+
layout: 'zip',
|
|
101
|
+
entries: readZip(data).map((e) => readEntry(`${name}!${e.name}`, e.data, layouts)),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
return { file: name, layout: 'lines', lines: [`(not read as a zip: ${error.message})`] };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return readText(data, layout, { file: name, layout: 'lines' }, name);
|
|
109
|
+
}
|
|
110
|
+
function readOutput(at, o, name) {
|
|
111
|
+
if (!existsSync(at) || !statSync(at).isFile())
|
|
112
|
+
return { file: name, layout: 'missing' };
|
|
113
|
+
const data = readFileSync(at);
|
|
114
|
+
if (o.layout !== 'zip')
|
|
115
|
+
return readText(data, o.layout, o, name);
|
|
116
|
+
try {
|
|
117
|
+
const entries = readZip(data).map((e) => readEntry(e.name, e.data, o.entries ?? {}));
|
|
118
|
+
return { file: name, layout: 'zip', entries };
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
return { file: name, layout: 'lines', lines: [`(not read as a zip: ${error.message})`] };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const idOf = (id) => createHash('sha256').update(id).digest('hex').slice(0, 12);
|
|
125
|
+
async function runOne(s, ctx) {
|
|
126
|
+
const spec = s.spec;
|
|
127
|
+
const dir = path.join(ctx.keep, `file-${idOf(s.id)}`);
|
|
128
|
+
const inDir = path.join(dir, 'in');
|
|
129
|
+
const outDir = path.join(dir, 'out');
|
|
130
|
+
mkdirSync(inDir, { recursive: true });
|
|
131
|
+
mkdirSync(outDir, { recursive: true });
|
|
132
|
+
const person = ctx.as ?? s.person;
|
|
133
|
+
const token = person ? ctx.tokens[person] : undefined;
|
|
134
|
+
const here = path.dirname(s.abs);
|
|
135
|
+
const vars = {
|
|
136
|
+
...ctx.variables,
|
|
137
|
+
checkout: ctx.checkout,
|
|
138
|
+
manifest: ctx.manifest.dir,
|
|
139
|
+
here,
|
|
140
|
+
output: outDir,
|
|
141
|
+
...(ctx.world !== null && { world: ctx.world }),
|
|
142
|
+
...(person && { person }),
|
|
143
|
+
...(token && { token }),
|
|
144
|
+
};
|
|
145
|
+
const failures = [];
|
|
146
|
+
let input = '';
|
|
147
|
+
if (spec.input?.file)
|
|
148
|
+
input = path.resolve(here, fill(spec.input.file, vars));
|
|
149
|
+
else if (spec.input?.command)
|
|
150
|
+
input = path.join(inDir, spec.input.name ?? 'input');
|
|
151
|
+
vars.input = input;
|
|
152
|
+
const env = {
|
|
153
|
+
...fillEnv(Object.fromEntries(Object.entries(spec.env ?? {}).map(([k, v]) => [k, String(v)])), vars),
|
|
154
|
+
REHEARSE_INPUT: input,
|
|
155
|
+
REHEARSE_OUTPUT: outDir,
|
|
156
|
+
...(token && { REHEARSE_TOKEN: token }),
|
|
157
|
+
};
|
|
158
|
+
const cwd = spec.cwd ? path.resolve(ctx.checkout, spec.cwd) : ctx.checkout;
|
|
159
|
+
const timeoutMs = Math.round((spec.timeout ?? 120) * 1000);
|
|
160
|
+
let log = '';
|
|
161
|
+
if (spec.input?.command) {
|
|
162
|
+
const made = await sh(fill(spec.input.command, vars), { cwd, env, timeoutMs });
|
|
163
|
+
log += `${made.stdout}${made.stderr}`;
|
|
164
|
+
if (made.code !== 0)
|
|
165
|
+
failures.push({
|
|
166
|
+
text: `input: ${spec.input.command}`,
|
|
167
|
+
expected: 'exit 0',
|
|
168
|
+
got: made.timedOut ? 'timed out' : `exit ${made.code}: ${tail(made.stderr || made.stdout)}`,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
let exit = null;
|
|
172
|
+
if (failures.length === 0) {
|
|
173
|
+
const ran = await sh(fill(spec.run, vars), { cwd, env, timeoutMs });
|
|
174
|
+
exit = ran.code;
|
|
175
|
+
log += `${ran.stdout}${ran.stderr}`;
|
|
176
|
+
if (ran.code !== 0)
|
|
177
|
+
failures.push({
|
|
178
|
+
text: `run: ${spec.run}`,
|
|
179
|
+
expected: 'exit 0',
|
|
180
|
+
got: ran.timedOut ? 'timed out' : `exit ${ran.code}: ${tail(ran.stderr || ran.stdout)}`,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const outputs = outputsOf(spec).map((o) => {
|
|
184
|
+
const name = fill(o.file, vars);
|
|
185
|
+
const at = path.isAbsolute(name) ? name : path.join(outDir, name);
|
|
186
|
+
const read = readOutput(at, o, path.isAbsolute(name) ? path.relative(ctx.checkout, name) : name);
|
|
187
|
+
if (read.layout === 'missing')
|
|
188
|
+
failures.push({ text: `output: ${o.file}`, expected: 'a file', got: 'nothing was written there' });
|
|
189
|
+
else if (path.isAbsolute(name))
|
|
190
|
+
cpSync(at, path.join(outDir, path.basename(name)));
|
|
191
|
+
return read;
|
|
192
|
+
});
|
|
193
|
+
const tokens = ctx.tokens;
|
|
194
|
+
return {
|
|
195
|
+
ok: failures.length === 0,
|
|
196
|
+
failures: failures.map((f) => ({ ...f, got: f.got === null ? null : scrub(f.got, tokens) })),
|
|
197
|
+
observed: {
|
|
198
|
+
kind: 'file',
|
|
199
|
+
exit,
|
|
200
|
+
log: scrub(tail(log, 20, 4000), tokens),
|
|
201
|
+
outputs: scrubDeep(outputs, tokens),
|
|
202
|
+
},
|
|
203
|
+
artifacts: [
|
|
204
|
+
{ kind: 'output', path: outDir, label: 'Output folder' },
|
|
205
|
+
...(input ? [{ kind: 'input', path: input, label: 'Input' }] : []),
|
|
206
|
+
],
|
|
207
|
+
broke: null,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const rulesFor = (rules, spec, o, outputs) => ({
|
|
211
|
+
...rules,
|
|
212
|
+
values: [...rules.values, ...(spec.setAside?.values ?? []).map((v) => new RegExp(v))],
|
|
213
|
+
keep: [...rules.keep, ...(spec.setAside?.keep ?? [])],
|
|
214
|
+
unordered: rules.unordered || (outputs.find((x) => x.file === o.file)?.unordered ?? false),
|
|
215
|
+
});
|
|
216
|
+
function compareRows(a, b, rules, counts, skip, label) {
|
|
217
|
+
const diffs = [];
|
|
218
|
+
const ac = a.columns ?? [];
|
|
219
|
+
const bc = b.columns ?? [];
|
|
220
|
+
if (JSON.stringify(ac) !== JSON.stringify(bc))
|
|
221
|
+
diffs.push({ path: `${label} columns`, base: clip(ac), head: clip(bc), count: 1 });
|
|
222
|
+
const cell = (v, column, tally) => v === undefined
|
|
223
|
+
? undefined
|
|
224
|
+
: rules.keep.includes(column)
|
|
225
|
+
? v
|
|
226
|
+
: setAsideText(v, { ...rules, keep: [] }, tally);
|
|
227
|
+
const prepared = (o, cols, tally) => {
|
|
228
|
+
const rows = (o.rows ?? []).map((r) => cols.map((c, i) => cell(r[i], c, tally)));
|
|
229
|
+
if (!rules.unordered)
|
|
230
|
+
return rows;
|
|
231
|
+
const sorted = [...rows].sort((x, y) => (JSON.stringify(x) < JSON.stringify(y) ? -1 : 1));
|
|
232
|
+
if (sorted.some((r, i) => r !== rows[i]))
|
|
233
|
+
tally.order += 1;
|
|
234
|
+
return sorted;
|
|
235
|
+
};
|
|
236
|
+
const ar = prepared(a, ac, noCounts());
|
|
237
|
+
const br = prepared(b, bc, counts);
|
|
238
|
+
if (ar.length !== br.length)
|
|
239
|
+
diffs.push({
|
|
240
|
+
path: `${label} rows`,
|
|
241
|
+
base: String(ar.length),
|
|
242
|
+
head: String(br.length),
|
|
243
|
+
count: Math.abs(ar.length - br.length),
|
|
244
|
+
});
|
|
245
|
+
const names = [...new Set([...bc, ...ac])];
|
|
246
|
+
const byColumn = new Map();
|
|
247
|
+
for (let r = 0; r < Math.min(ar.length, br.length); r += 1)
|
|
248
|
+
for (const name of names) {
|
|
249
|
+
if (skip.has(name))
|
|
250
|
+
continue;
|
|
251
|
+
const x = ar[r][ac.indexOf(name)];
|
|
252
|
+
const y = br[r][bc.indexOf(name)];
|
|
253
|
+
if (x === y)
|
|
254
|
+
continue;
|
|
255
|
+
const n = (bc.includes(name) ? bc.indexOf(name) : ac.indexOf(name)) + 1;
|
|
256
|
+
const key = `${label} column ${n} "${name}"`;
|
|
257
|
+
const known = byColumn.get(key);
|
|
258
|
+
if (known)
|
|
259
|
+
known.count += 1;
|
|
260
|
+
else
|
|
261
|
+
byColumn.set(key, { path: key, base: clip(x), head: clip(y), count: 1 });
|
|
262
|
+
}
|
|
263
|
+
return [...diffs, ...byColumn.values()];
|
|
264
|
+
}
|
|
265
|
+
function compareOutput(a, b, rules, counts, skip, label) {
|
|
266
|
+
if (a.layout !== b.layout)
|
|
267
|
+
return [{ path: `${label} layout`, base: a.layout, head: b.layout, count: 1 }];
|
|
268
|
+
switch (a.layout) {
|
|
269
|
+
case 'missing':
|
|
270
|
+
case 'skip':
|
|
271
|
+
return [];
|
|
272
|
+
case 'csv':
|
|
273
|
+
case 'tsv':
|
|
274
|
+
case 'fixed':
|
|
275
|
+
return compareRows(a, b, rules, counts, skip, label);
|
|
276
|
+
case 'json':
|
|
277
|
+
return jsonDifferences(setAsideJson(a.json, rules, noCounts()), setAsideJson(b.json, rules, counts), `${label} $`);
|
|
278
|
+
case 'zip': {
|
|
279
|
+
const diffs = [];
|
|
280
|
+
const names = [...new Set([...(a.entries ?? []), ...(b.entries ?? [])].map((e) => e.file))].sort();
|
|
281
|
+
for (const name of names) {
|
|
282
|
+
const x = a.entries?.find((e) => e.file === name);
|
|
283
|
+
const y = b.entries?.find((e) => e.file === name);
|
|
284
|
+
const outermostArchive = label.split('!')[0];
|
|
285
|
+
const at = `${outermostArchive}!${name}`;
|
|
286
|
+
if (!x || !y)
|
|
287
|
+
diffs.push({ path: at, base: x ? 'there' : '(absent)', head: y ? 'there' : '(absent)', count: 1 });
|
|
288
|
+
else
|
|
289
|
+
diffs.push(...compareOutput(x, y, rules, counts, skip, at));
|
|
290
|
+
}
|
|
291
|
+
return diffs;
|
|
292
|
+
}
|
|
293
|
+
default:
|
|
294
|
+
return textDifferences((a.lines ?? []).map((l) => setAsideText(l, rules, noCounts())).join('\n'), (b.lines ?? []).map((l) => setAsideText(l, rules, counts)).join('\n'), label);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
registerRunner({
|
|
298
|
+
kind: 'file',
|
|
299
|
+
version: 'file/2',
|
|
300
|
+
services: (s) => s.spec.services ?? [],
|
|
301
|
+
async run(scenarios, ctx) {
|
|
302
|
+
const out = new Map();
|
|
303
|
+
for (const s of scenarios)
|
|
304
|
+
out.set(s.id, await runOne(s, ctx));
|
|
305
|
+
return out;
|
|
306
|
+
},
|
|
307
|
+
compare(base, head, rules, counts, s) {
|
|
308
|
+
const spec = s.spec;
|
|
309
|
+
const skip = new Set(spec.setAside?.columns ?? []);
|
|
310
|
+
const diffs = [];
|
|
311
|
+
if (base.exit !== head.exit)
|
|
312
|
+
diffs.push({ path: 'exit', base: String(base.exit), head: String(head.exit), count: 1 });
|
|
313
|
+
const a = (base.outputs ?? []);
|
|
314
|
+
const b = (head.outputs ?? []);
|
|
315
|
+
for (const name of new Set([...a, ...b].map((o) => o.file))) {
|
|
316
|
+
const x = a.find((o) => o.file === name);
|
|
317
|
+
const y = b.find((o) => o.file === name);
|
|
318
|
+
if (!x || !y) {
|
|
319
|
+
diffs.push({
|
|
320
|
+
path: name,
|
|
321
|
+
base: x ? x.layout : '(absent)',
|
|
322
|
+
head: y ? y.layout : '(absent)',
|
|
323
|
+
count: 1,
|
|
324
|
+
});
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
diffs.push(...compareOutput(x, y, rulesFor(rules, spec, x, outputsOf(spec)), counts, skip, name));
|
|
328
|
+
}
|
|
329
|
+
return diffs;
|
|
330
|
+
},
|
|
331
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function parseDelimited(text: string, separator: string): string[][];
|
|
2
|
+
export interface Column {
|
|
3
|
+
name: string;
|
|
4
|
+
start: number;
|
|
5
|
+
width: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const parseFixed: (text: string, columns: readonly Column[]) => string[][];
|
|
8
|
+
export interface ZipEntry {
|
|
9
|
+
name: string;
|
|
10
|
+
data: Buffer;
|
|
11
|
+
}
|
|
12
|
+
export declare function readZip(zip: Buffer): ZipEntry[];
|
|
13
|
+
export declare function entryLayout(name: string, entries: Readonly<Record<string, string>>): string;
|
|
14
|
+
export declare function isUtf8WithoutNul(data: Buffer): boolean;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { inflateRawSync } from 'node:zlib';
|
|
2
|
+
import { globToRegExp } from '../../scenarios/index.js';
|
|
3
|
+
export function parseDelimited(text, separator) {
|
|
4
|
+
const rows = [];
|
|
5
|
+
let row = [];
|
|
6
|
+
let cell = '';
|
|
7
|
+
let quoted = false;
|
|
8
|
+
const body = text.replace(/^/, '');
|
|
9
|
+
for (let i = 0; i < body.length; i += 1) {
|
|
10
|
+
const c = body[i];
|
|
11
|
+
if (quoted) {
|
|
12
|
+
if (c === '"') {
|
|
13
|
+
if (body[i + 1] === '"') {
|
|
14
|
+
cell += '"';
|
|
15
|
+
i += 1;
|
|
16
|
+
}
|
|
17
|
+
else
|
|
18
|
+
quoted = false;
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
cell += c;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (c === '"' && cell === '')
|
|
25
|
+
quoted = true;
|
|
26
|
+
else if (c === separator) {
|
|
27
|
+
row.push(cell);
|
|
28
|
+
cell = '';
|
|
29
|
+
}
|
|
30
|
+
else if (c === '\n' || c === '\r') {
|
|
31
|
+
if (c === '\r' && body[i + 1] === '\n')
|
|
32
|
+
i += 1;
|
|
33
|
+
row.push(cell);
|
|
34
|
+
rows.push(row);
|
|
35
|
+
row = [];
|
|
36
|
+
cell = '';
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
cell += c;
|
|
40
|
+
}
|
|
41
|
+
if (cell !== '' || row.length) {
|
|
42
|
+
row.push(cell);
|
|
43
|
+
rows.push(row);
|
|
44
|
+
}
|
|
45
|
+
return rows.filter((r) => !(r.length === 1 && r[0] === ''));
|
|
46
|
+
}
|
|
47
|
+
export const parseFixed = (text, columns) => text
|
|
48
|
+
.split(/\r?\n/)
|
|
49
|
+
.filter((line) => line.length > 0)
|
|
50
|
+
.map((line) => columns.map((c) => line.slice(c.start - 1, c.start - 1 + c.width).trim()));
|
|
51
|
+
const END_OF_CENTRAL_DIRECTORY = 0x06054b50;
|
|
52
|
+
const CENTRAL_DIRECTORY_ENTRY = 0x02014b50;
|
|
53
|
+
const STORED = 0;
|
|
54
|
+
const DEFLATED = 8;
|
|
55
|
+
export function readZip(zip) {
|
|
56
|
+
let end = -1;
|
|
57
|
+
for (let i = zip.length - 22; i >= Math.max(0, zip.length - 65_557); i -= 1)
|
|
58
|
+
if (zip.readUInt32LE(i) === END_OF_CENTRAL_DIRECTORY) {
|
|
59
|
+
end = i;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
if (end < 0)
|
|
63
|
+
throw new Error('it is not a zip archive: no end of central directory');
|
|
64
|
+
const count = zip.readUInt16LE(end + 10);
|
|
65
|
+
let at = zip.readUInt32LE(end + 16);
|
|
66
|
+
const out = [];
|
|
67
|
+
for (let n = 0; n < count; n += 1) {
|
|
68
|
+
if (zip.readUInt32LE(at) !== CENTRAL_DIRECTORY_ENTRY)
|
|
69
|
+
throw new Error('its central directory is broken');
|
|
70
|
+
const method = zip.readUInt16LE(at + 10);
|
|
71
|
+
const compressed = zip.readUInt32LE(at + 20);
|
|
72
|
+
const nameLength = zip.readUInt16LE(at + 28);
|
|
73
|
+
const extra = zip.readUInt16LE(at + 30);
|
|
74
|
+
const comment = zip.readUInt16LE(at + 32);
|
|
75
|
+
const local = zip.readUInt32LE(at + 42);
|
|
76
|
+
const name = zip.subarray(at + 46, at + 46 + nameLength).toString('utf8');
|
|
77
|
+
at += 46 + nameLength + extra + comment;
|
|
78
|
+
if (name.endsWith('/'))
|
|
79
|
+
continue;
|
|
80
|
+
const localName = zip.readUInt16LE(local + 26);
|
|
81
|
+
const localExtra = zip.readUInt16LE(local + 28);
|
|
82
|
+
const start = local + 30 + localName + localExtra;
|
|
83
|
+
const raw = zip.subarray(start, start + compressed);
|
|
84
|
+
if (method === STORED)
|
|
85
|
+
out.push({ name, data: Buffer.from(raw) });
|
|
86
|
+
else if (method === DEFLATED)
|
|
87
|
+
out.push({ name, data: inflateRawSync(raw) });
|
|
88
|
+
else
|
|
89
|
+
throw new Error(`its entry ${name} uses compression method ${method}, which Rehearse can't read`);
|
|
90
|
+
}
|
|
91
|
+
return out.sort((a, b) => a.name.localeCompare(b.name));
|
|
92
|
+
}
|
|
93
|
+
export function entryLayout(name, entries) {
|
|
94
|
+
for (const [glob, layout] of Object.entries(entries))
|
|
95
|
+
if (globToRegExp(glob).test(name))
|
|
96
|
+
return layout;
|
|
97
|
+
return 'lines';
|
|
98
|
+
}
|
|
99
|
+
export function isUtf8WithoutNul(data) {
|
|
100
|
+
if (data.includes(0))
|
|
101
|
+
return false;
|
|
102
|
+
return !new TextDecoder('utf-8', { fatal: false }).decode(data).includes('�');
|
|
103
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Step } from '../../drive/index.ts';
|
|
2
|
+
export interface FlowSpec {
|
|
3
|
+
name: string;
|
|
4
|
+
service?: string;
|
|
5
|
+
piece?: string;
|
|
6
|
+
start?: string;
|
|
7
|
+
world?: string;
|
|
8
|
+
person?: string;
|
|
9
|
+
covers?: string[];
|
|
10
|
+
steps: Step[];
|
|
11
|
+
}
|
|
12
|
+
export interface StepSeen {
|
|
13
|
+
n: number;
|
|
14
|
+
step: Step | {
|
|
15
|
+
open: string;
|
|
16
|
+
};
|
|
17
|
+
ok: boolean;
|
|
18
|
+
says: string | null;
|
|
19
|
+
tree: string | null;
|
|
20
|
+
screenshot: string | null;
|
|
21
|
+
}
|