@kurvball/rehearse 1.8.0 → 1.10.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/README.md +3 -2
- package/dist/commands/init.js +52 -7
- package/dist/commands/stage.js +19 -3
- package/dist/detect/detect.d.ts +6 -0
- package/dist/detect/detect.js +48 -0
- package/dist/detect/finding.d.ts +18 -0
- package/dist/detect/finding.js +4 -0
- package/dist/detect/globs.d.ts +10 -0
- package/dist/detect/globs.js +43 -0
- package/dist/detect/index.d.ts +2 -0
- package/dist/detect/index.js +2 -0
- package/dist/detect/lockfiles.d.ts +15 -0
- package/dist/detect/lockfiles.js +64 -0
- package/dist/detect/paths.d.ts +5 -0
- package/dist/detect/paths.js +39 -0
- package/dist/detect/pieces.d.ts +14 -0
- package/dist/detect/pieces.js +119 -0
- package/dist/detect/prepare.d.ts +14 -0
- package/dist/detect/prepare.js +78 -0
- package/dist/detect/repository.d.ts +33 -0
- package/dist/detect/repository.js +166 -0
- package/dist/detect/scenarios.d.ts +26 -0
- package/dist/detect/scenarios.js +170 -0
- package/dist/detect/scripts.d.ts +46 -0
- package/dist/detect/scripts.js +233 -0
- package/dist/detect/services.d.ts +16 -0
- package/dist/detect/services.js +171 -0
- package/dist/detect/write.d.ts +18 -0
- package/dist/detect/write.js +115 -0
- package/dist/manifest/index.d.ts +1 -1
- package/dist/manifest/index.js +1 -1
- package/dist/manifest/init.d.ts +47 -1
- package/dist/manifest/init.js +19 -16
- package/dist/scenarios/glob.d.ts +1 -0
- package/dist/scenarios/glob.js +10 -3
- package/dist/scenarios/index.d.ts +1 -1
- package/dist/scenarios/index.js +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +1 -0
- package/dist/stage/client/client/api.js +4 -1
- package/dist/stage/client/client/index.js +1 -0
- package/dist/stage/client/client/static.js +28 -0
- package/dist/stage/client/features/canvas/call.js +12 -3
- package/dist/stage/client/features/canvas/file.js +4 -2
- package/dist/stage/client/features/canvas/piece.js +12 -2
- package/dist/stage/client/features/list/list.js +6 -1
- package/dist/stage/client/features/scenario/heading.js +3 -2
- package/dist/stage/client/features/scenario/scenario.js +8 -4
- package/dist/stage/client/main.js +7 -3
- package/dist/stage/client/stage.css +11 -0
- package/dist/stage/compared.d.ts +7 -1
- package/dist/stage/compared.js +16 -4
- package/dist/stage/files.d.ts +1 -0
- package/dist/stage/files.js +6 -4
- package/dist/stage/index.d.ts +1 -0
- package/dist/stage/index.js +1 -0
- package/dist/stage/public.d.ts +9 -0
- package/dist/stage/public.js +107 -0
- package/dist/stage/server.js +2 -2
- package/dist/stage/static.d.ts +22 -0
- package/dist/stage/static.js +241 -0
- package/llms.txt +3 -2
- package/package.json +1 -1
- package/schema/v1/init.schema.json +69 -1
- package/schema/v1/samples/init.json +46 -1
- package/schema/v1/samples/static.json +21 -0
- package/schema/v1/static.schema.json +34 -0
- package/schema/vendor/acta/LICENSE +21 -0
- package/schema/vendor/acta/README.md +12 -0
- package/schema/vendor/acta/v1/canonical.schema.json +818 -0
- package/schema/vendor/acta/v1/check.schema.json +35 -0
- package/schema/vendor/acta/v1/record.schema.json +1443 -0
- package/schema/vendor/acta/v1/run-model.schema.json +1074 -0
- package/skill/rehearse/SKILL.md +6 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Finding } from './finding.ts';
|
|
2
|
+
import { type Package, type Repository } from './repository.ts';
|
|
3
|
+
import { type Framework } from './scripts.ts';
|
|
4
|
+
export interface Service {
|
|
5
|
+
name: string;
|
|
6
|
+
pkg: Package;
|
|
7
|
+
server: Framework | 'node';
|
|
8
|
+
up: string;
|
|
9
|
+
env: Record<string, string>;
|
|
10
|
+
ready: string;
|
|
11
|
+
built: string | null;
|
|
12
|
+
}
|
|
13
|
+
export declare function servicesOf(repo: Repository): {
|
|
14
|
+
services: Service[];
|
|
15
|
+
findings: Finding[];
|
|
16
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { isFile, joined, readText, within, } from './repository.js';
|
|
3
|
+
import { FILE_LIKE, quoted, readScript } from './scripts.js';
|
|
4
|
+
const SCRIPTS = ['dev', 'start', 'serve', 'develop'];
|
|
5
|
+
const RUN = {
|
|
6
|
+
pnpm: (s, a) => `pnpm run ${quoted(s)}${a ? ` ${a}` : ''}`,
|
|
7
|
+
npm: (s, a) => `npm run ${quoted(s)}${a ? ` -- ${a}` : ''}`,
|
|
8
|
+
yarn: (s, a) => `yarn run ${quoted(s)}${a ? ` ${a}` : ''}`,
|
|
9
|
+
bun: (s, a) => `bun run ${quoted(s)}${a ? ` ${a}` : ''}`,
|
|
10
|
+
};
|
|
11
|
+
const NAMES = { vite: 'Vite', next: 'Next', astro: 'Astro' };
|
|
12
|
+
const READS_PORT = /process\.env\.PORT\b|process\.env\[\s*['"`]PORT['"`]\s*\]|\{[^}]*\bPORT\b[^}]*\}\s*=\s*process\.env\b|(?:Bun|import\.meta)\.env\.PORT\b|Deno\.env\.get\(\s*['"`]PORT['"`]/;
|
|
13
|
+
const HEALTH = /['"`](\/(?:api\/)?(?:healthz?|livez|readyz|ping))['"`]/;
|
|
14
|
+
const RELATIVE_IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*)['"](\.{1,2}\/[^'"]+)['"]/g;
|
|
15
|
+
const EXTENSIONS = ['', '.js', '.mjs', '.cjs', '.ts', '.mts', '.cts', '/index.js', '/index.mjs', '/index.ts'];
|
|
16
|
+
const SOURCES_READ = 200;
|
|
17
|
+
const BY_HAND = 'Write its service by hand: an up command with {{port}} where the port goes, and port: auto.';
|
|
18
|
+
function resolveFile(repo, from, spec) {
|
|
19
|
+
const base = joined(from, spec);
|
|
20
|
+
const tried = [...EXTENSIONS.map((e) => base + e), base.replace(/\.([cm]?)js$/, '.$1ts')];
|
|
21
|
+
return tried.find((f) => !f.startsWith('..') && isFile(path.join(repo.root, f))) ?? null;
|
|
22
|
+
}
|
|
23
|
+
function sourcesFrom(repo, entry) {
|
|
24
|
+
const text = readText(path.join(repo.root, entry));
|
|
25
|
+
if (text === null)
|
|
26
|
+
return [];
|
|
27
|
+
const out = [{ file: entry, text }];
|
|
28
|
+
for (const m of text.matchAll(RELATIVE_IMPORT)) {
|
|
29
|
+
if (out.length > 20)
|
|
30
|
+
break;
|
|
31
|
+
const file = resolveFile(repo, path.posix.dirname(entry), m[1]);
|
|
32
|
+
const more = file && !out.some((o) => o.file === file) ? readText(path.join(repo.root, file)) : null;
|
|
33
|
+
if (file && more !== null)
|
|
34
|
+
out.push({ file, text: more });
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
function sourcesIn(repo, dir) {
|
|
39
|
+
return repo.files
|
|
40
|
+
.filter((f) => within(joined(dir, 'src'), f) && FILE_LIKE.test(f))
|
|
41
|
+
.slice(0, SOURCES_READ)
|
|
42
|
+
.flatMap((file) => {
|
|
43
|
+
const text = readText(path.join(repo.root, file));
|
|
44
|
+
return text === null ? [] : [{ file, text }];
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function nodeServer(repo, pkg, read) {
|
|
48
|
+
const its = `its ${read.script} script`;
|
|
49
|
+
if (!read.entry)
|
|
50
|
+
return { why: `${its} runs ${read.tool} without a file Rehearse can read.`, next: BY_HAND };
|
|
51
|
+
const entry = resolveFile(repo, pkg.dir, read.entry);
|
|
52
|
+
const built = entry === null || repo.ignored(entry);
|
|
53
|
+
const canBuild = pkg.scripts.build !== undefined;
|
|
54
|
+
const sources = built ? (canBuild ? sourcesIn(repo, pkg.dir) : []) : sourcesFrom(repo, entry);
|
|
55
|
+
const reading = sources.find((s) => READS_PORT.test(s.text));
|
|
56
|
+
if (!reading)
|
|
57
|
+
return {
|
|
58
|
+
why: built
|
|
59
|
+
? `${its} runs ${read.entry}, which is built, and ${canBuild ? 'no file in src/ reads PORT' : 'there is no build script'}, so Rehearse can't give it a free port.`
|
|
60
|
+
: `${its} runs ${read.entry}, which doesn't read PORT, so Rehearse can't give it a free port.`,
|
|
61
|
+
next: 'Make it listen on process.env.PORT, or write its service by hand with {{port}} where the port goes.',
|
|
62
|
+
};
|
|
63
|
+
const health = [reading, ...sources].map((s) => HEALTH.exec(s.text)?.[1]).find(Boolean) ?? '/';
|
|
64
|
+
const manager = repo.managerOf(pkg.dir);
|
|
65
|
+
return {
|
|
66
|
+
service: {
|
|
67
|
+
pkg,
|
|
68
|
+
server: 'node',
|
|
69
|
+
up: RUN[manager](read.script, ''),
|
|
70
|
+
env: { PORT: '{{port}}' },
|
|
71
|
+
ready: `http://127.0.0.1:{{port}}${health}`,
|
|
72
|
+
built: built ? joined(pkg.dir, read.entry) : null,
|
|
73
|
+
},
|
|
74
|
+
what: `a Node server that reads PORT${built ? ', built first' : ''}, on a free port`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function frameworkServer(repo, pkg, read) {
|
|
78
|
+
const { framework, script, words } = read;
|
|
79
|
+
const manager = repo.managerOf(pkg.dir);
|
|
80
|
+
const more = [
|
|
81
|
+
...(framework === 'vite' && !words.includes('--strictPort') ? ['--strictPort'] : []),
|
|
82
|
+
...(framework !== 'next' && !words.some((w) => w === '--host' || w.startsWith('--host='))
|
|
83
|
+
? ['--host', '127.0.0.1']
|
|
84
|
+
: []),
|
|
85
|
+
];
|
|
86
|
+
const up = RUN[manager](script, [framework === 'next' ? '-p' : '--port', '{{port}}', ...more].join(' '));
|
|
87
|
+
return {
|
|
88
|
+
service: { pkg, server: framework, up, env: {}, ready: 'http://127.0.0.1:{{port}}/', built: null },
|
|
89
|
+
what: `${NAMES[framework]}'s dev server, on a free port`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function left(read) {
|
|
93
|
+
const its = `its ${read.script} script`;
|
|
94
|
+
switch (read.as) {
|
|
95
|
+
case 'others':
|
|
96
|
+
return {
|
|
97
|
+
why: `${its} runs ${read.tool}, which starts other packages' scripts; Rehearse brings each app up as a service of its own.`,
|
|
98
|
+
};
|
|
99
|
+
case 'unknown':
|
|
100
|
+
return {
|
|
101
|
+
why: `${its} runs ${read.tool}, and Rehearse can't tell how that takes a port.`,
|
|
102
|
+
next: BY_HAND,
|
|
103
|
+
};
|
|
104
|
+
case 'fixed':
|
|
105
|
+
return {
|
|
106
|
+
why: `${its} fixes its port (${read.port}), so Rehearse can't give it a free one without running something else.`,
|
|
107
|
+
next: 'Take the port out of the script, since Rehearse gives it one, or write its service by hand.',
|
|
108
|
+
};
|
|
109
|
+
case 'together':
|
|
110
|
+
return {
|
|
111
|
+
why: read.how === '&'
|
|
112
|
+
? `${its} runs commands side by side (&), and a service is one server Rehearse gives one port.`
|
|
113
|
+
: `${its} pipes the server's output into another command (|), so the port Rehearse adds wouldn't reach the server.`,
|
|
114
|
+
next: BY_HAND,
|
|
115
|
+
};
|
|
116
|
+
case 'handover':
|
|
117
|
+
return {
|
|
118
|
+
why: `${its} hands over to ${read.via}, which doesn't pass on the port Rehearse adds.`,
|
|
119
|
+
next: `End that call with --, as in ${read.via} --, or write its service by hand.`,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function seen(repo, pkg) {
|
|
124
|
+
for (const script of SCRIPTS.filter((s) => s in pkg.scripts)) {
|
|
125
|
+
const read = readScript(pkg.scripts, script);
|
|
126
|
+
if (read.as === 'framework')
|
|
127
|
+
return frameworkServer(repo, pkg, read);
|
|
128
|
+
if (read.as === 'node')
|
|
129
|
+
return nodeServer(repo, pkg, read);
|
|
130
|
+
if (read.as !== 'tool')
|
|
131
|
+
return left(read);
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
const safe = (word) => (word ?? '')
|
|
136
|
+
.replace(/^@[^/]+\//, '')
|
|
137
|
+
.replace(/[^A-Za-z0-9_-]+/g, '-')
|
|
138
|
+
.replace(/^[^A-Za-z_]+|-+$/g, '');
|
|
139
|
+
function nameOf(pkg, server, taken) {
|
|
140
|
+
const byKind = server === 'node' ? 'api' : 'web';
|
|
141
|
+
const tried = (pkg.dir ? [safe(path.posix.basename(pkg.dir)), safe(pkg.name), byKind] : [byKind]).filter(Boolean);
|
|
142
|
+
const free = tried.find((name) => !taken.has(name));
|
|
143
|
+
if (free)
|
|
144
|
+
return free;
|
|
145
|
+
for (let n = 2;; n += 1)
|
|
146
|
+
if (!taken.has(`${tried[0]}-${n}`))
|
|
147
|
+
return `${tried[0]}-${n}`;
|
|
148
|
+
}
|
|
149
|
+
export function servicesOf(repo) {
|
|
150
|
+
const services = [];
|
|
151
|
+
const findings = [];
|
|
152
|
+
for (const pkg of repo.packages) {
|
|
153
|
+
const found = seen(repo, pkg);
|
|
154
|
+
if (!found)
|
|
155
|
+
continue;
|
|
156
|
+
if ('service' in found) {
|
|
157
|
+
const name = nameOf(pkg, found.service.server, new Set(services.map((s) => s.name)));
|
|
158
|
+
services.push({ name, ...found.service });
|
|
159
|
+
findings.push({ kind: 'service', name, from: pkg.file, written: true, why: found.what });
|
|
160
|
+
}
|
|
161
|
+
else
|
|
162
|
+
findings.push({
|
|
163
|
+
kind: 'service',
|
|
164
|
+
from: pkg.file,
|
|
165
|
+
written: false,
|
|
166
|
+
why: found.why,
|
|
167
|
+
...(found.next !== undefined && { next: found.next }),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return { services, findings };
|
|
171
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Blocks } from './scenarios.ts';
|
|
2
|
+
import type { Service } from './services.ts';
|
|
3
|
+
export interface Plan {
|
|
4
|
+
base: {
|
|
5
|
+
branch: string;
|
|
6
|
+
from: string;
|
|
7
|
+
} | null;
|
|
8
|
+
prepare: {
|
|
9
|
+
command: string;
|
|
10
|
+
from: string[];
|
|
11
|
+
} | null;
|
|
12
|
+
services: readonly Service[];
|
|
13
|
+
blocks: Blocks;
|
|
14
|
+
prefix: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function scalar(value: string): string;
|
|
17
|
+
export declare const commented: (block: string) => string;
|
|
18
|
+
export declare function manifestText(plan: Plan): string;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { STARTER_BLOCKS } from '../manifest/index.js';
|
|
2
|
+
import { escapeGlob } from '../scenarios/index.js';
|
|
3
|
+
import { counted, hasControl, printable } from './finding.js';
|
|
4
|
+
import { joined } from './repository.js';
|
|
5
|
+
const HEAD = `# rehearse.yaml: what this repository has, so a change can be rehearsed before it ships.
|
|
6
|
+
# rehearse init --detect wrote the blocks it found, each saying what from, and left the rest commented.
|
|
7
|
+
# Every block is optional. Reference: the docs' rehearse.yaml page.
|
|
8
|
+
version: 1
|
|
9
|
+
`;
|
|
10
|
+
const WHAT = {
|
|
11
|
+
vite: "Vite's dev server",
|
|
12
|
+
next: "Next's dev server",
|
|
13
|
+
astro: "Astro's dev server",
|
|
14
|
+
node: 'a Node server that reads PORT',
|
|
15
|
+
};
|
|
16
|
+
const SPECIAL = /^(?:true|false|yes|no|on|off|y|n|null|~)$/i;
|
|
17
|
+
const NUMBER = /^[-+]?(?:\d[\d_]*(?:\.\d*)?|\.\d+)(?:e[-+]?\d+)?$|^0x[\da-f]+$|^0o[0-7]+$|^[-+]?\.(?:inf|nan)$/i;
|
|
18
|
+
const doubleQuoted = (value) => JSON.stringify(value).replace(/[\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16)}`);
|
|
19
|
+
const singleQuoted = (value) => hasControl(value) ? doubleQuoted(value) : `'${value.replace(/'/g, "''")}'`;
|
|
20
|
+
export function scalar(value) {
|
|
21
|
+
if (hasControl(value))
|
|
22
|
+
return doubleQuoted(value);
|
|
23
|
+
const plain = /^[A-Za-z0-9_./(]/.test(value) &&
|
|
24
|
+
!/[\n\t]|: | #|:$|\s$/.test(value) &&
|
|
25
|
+
!SPECIAL.test(value) &&
|
|
26
|
+
!NUMBER.test(value);
|
|
27
|
+
return plain ? value : `'${value.replace(/'/g, "''")}'`;
|
|
28
|
+
}
|
|
29
|
+
const list = (values) => `[${values.map(singleQuoted).join(', ')}]`;
|
|
30
|
+
const and = (items) => items.length <= 1 ? (items[0] ?? '') : `${items.slice(0, -1).join(', ')} and ${items.at(-1)}`;
|
|
31
|
+
const explanation = (block) => block.split('\n')[0];
|
|
32
|
+
function commentedLine(line) {
|
|
33
|
+
if (line === '')
|
|
34
|
+
return line;
|
|
35
|
+
const indented = /^(\s+)#\s?(.*)$/.exec(line);
|
|
36
|
+
if (indented)
|
|
37
|
+
return `# ${indented[1]}${indented[2]}`;
|
|
38
|
+
return line.startsWith('#') ? line : `# ${line}`;
|
|
39
|
+
}
|
|
40
|
+
export const commented = (block) => block.split('\n').map(commentedLine).join('\n');
|
|
41
|
+
function base(plan) {
|
|
42
|
+
if (!plan.base)
|
|
43
|
+
return STARTER_BLOCKS.base;
|
|
44
|
+
return `${explanation(STARTER_BLOCKS.base)}\n# Detected from ${printable(plan.base.from)}.\nbase: ${scalar(plan.base.branch)}\n`;
|
|
45
|
+
}
|
|
46
|
+
function prepare(plan) {
|
|
47
|
+
if (!plan.prepare)
|
|
48
|
+
return STARTER_BLOCKS.prepare;
|
|
49
|
+
return `${explanation(STARTER_BLOCKS.prepare)}\n# Detected from ${printable(and(plan.prepare.from))}.\nprepare: ${scalar(plan.prepare.command)}\n`;
|
|
50
|
+
}
|
|
51
|
+
function services(plan) {
|
|
52
|
+
if (plan.services.length === 0)
|
|
53
|
+
return commented(STARTER_BLOCKS.services);
|
|
54
|
+
const lines = [explanation(STARTER_BLOCKS.services), 'services:'];
|
|
55
|
+
for (const s of plan.services) {
|
|
56
|
+
const cwd = joined(plan.prefix, s.pkg.dir);
|
|
57
|
+
const env = Object.entries(s.env);
|
|
58
|
+
lines.push(` # Detected from ${printable(s.pkg.file)}: ${WHAT[s.server]}${s.built ? ', built first' : ''}.`, ` ${s.name}:`, ` up: ${scalar(s.up)}`, ...(cwd ? [` cwd: ${scalar(cwd)}`] : []), ' port: auto', ` ready: ${scalar(s.ready)}`, ...(env.length ? [' env:', ...env.map(([k, v]) => ` ${k}: ${scalar(v)}`)] : []));
|
|
59
|
+
}
|
|
60
|
+
return `${lines.join('\n')}\n`;
|
|
61
|
+
}
|
|
62
|
+
function scenarios(plan) {
|
|
63
|
+
const b = plan.blocks;
|
|
64
|
+
if (!b.pieces && !b.flows && !b.calls && !b.files)
|
|
65
|
+
return commented(STARTER_BLOCKS.scenarios);
|
|
66
|
+
const starter = new Map(STARTER_BLOCKS.scenarios
|
|
67
|
+
.split('\n')
|
|
68
|
+
.map((line) => /^ {2}(\w+):/.exec(line))
|
|
69
|
+
.filter((m) => m !== null)
|
|
70
|
+
.map((m) => [m[1], m.input.trim()]));
|
|
71
|
+
const block = (kind, from, paths, settings) => {
|
|
72
|
+
const set = settings.filter((s) => s[1] !== null);
|
|
73
|
+
const globs = list(paths.map((p) => joined(escapeGlob(plan.prefix), p)));
|
|
74
|
+
return [
|
|
75
|
+
` # Detected from ${printable(from)}.`,
|
|
76
|
+
...(set.length
|
|
77
|
+
? [` ${kind}:`, ` paths: ${globs}`, ...set.map(([k, v]) => ` ${k}: ${scalar(v)}`)]
|
|
78
|
+
: [` ${kind}: ${globs}`]),
|
|
79
|
+
];
|
|
80
|
+
};
|
|
81
|
+
const left = (kind) => [` # ${starter.get(kind)}`];
|
|
82
|
+
const lines = [
|
|
83
|
+
explanation(STARTER_BLOCKS.scenarios),
|
|
84
|
+
'scenarios:',
|
|
85
|
+
...(b.pieces
|
|
86
|
+
? block('pieces', `${counted(b.pieces.count, 'story file', 'story files')}${b.pieces.previewFile ? ` and ${b.pieces.previewFile}` : ''}`, b.pieces.paths, [['preview', b.pieces.preview]])
|
|
87
|
+
: left('pieces')),
|
|
88
|
+
...(b.flows
|
|
89
|
+
? block('flows', counted(b.flows.count, 'flow file', 'flow files'), b.flows.paths, [
|
|
90
|
+
['service', b.flows.service],
|
|
91
|
+
])
|
|
92
|
+
: left('flows')),
|
|
93
|
+
...(b.calls
|
|
94
|
+
? block('calls', counted(b.calls.count, '.hurl file', '.hurl files'), b.calls.paths, [
|
|
95
|
+
['service', b.calls.service],
|
|
96
|
+
])
|
|
97
|
+
: left('calls')),
|
|
98
|
+
...(b.files
|
|
99
|
+
? block('files', counted(b.files.count, 'file scenario', 'file scenarios'), b.files.paths, [])
|
|
100
|
+
: left('files')),
|
|
101
|
+
];
|
|
102
|
+
return `${lines.join('\n')}\n`;
|
|
103
|
+
}
|
|
104
|
+
export function manifestText(plan) {
|
|
105
|
+
return [
|
|
106
|
+
HEAD,
|
|
107
|
+
base(plan),
|
|
108
|
+
prepare(plan),
|
|
109
|
+
services(plan),
|
|
110
|
+
commented(STARTER_BLOCKS.people),
|
|
111
|
+
commented(STARTER_BLOCKS.worlds),
|
|
112
|
+
commented(STARTER_BLOCKS.standins),
|
|
113
|
+
scenarios(plan),
|
|
114
|
+
].join('\n');
|
|
115
|
+
}
|
package/dist/manifest/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { fill, fillEnv } from './fill.ts';
|
|
2
|
-
export { STARTER } from './init.ts';
|
|
2
|
+
export { STARTER, STARTER_BLOCKS, STARTER_HEAD } from './init.ts';
|
|
3
3
|
export { findManifest, hashOf, loadManifest, MANIFEST_FILE, manifestFrom } from './load.ts';
|
|
4
4
|
export { KIND_BLOCK, KINDS, type Kind, type Manifest, type PathEntry, type Person, type Real, type Service, type Standin, type World, } from './types.ts';
|
|
5
5
|
export { readYaml } from './yaml.ts';
|
package/dist/manifest/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { fill, fillEnv } from './fill.js';
|
|
2
|
-
export { STARTER } from './init.js';
|
|
2
|
+
export { STARTER, STARTER_BLOCKS, STARTER_HEAD } from './init.js';
|
|
3
3
|
export { findManifest, hashOf, loadManifest, MANIFEST_FILE, manifestFrom } from './load.js';
|
|
4
4
|
export { KIND_BLOCK, KINDS, } from './types.js';
|
|
5
5
|
export { readYaml } from './yaml.js';
|
package/dist/manifest/init.d.ts
CHANGED
|
@@ -1 +1,47 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const STARTER_HEAD = "# rehearse.yaml: what this repository has, so a change can be rehearsed before it ships.\n# Every block is optional. Delete what you don't have. Reference: the docs' rehearse.yaml page.\nversion: 1\n";
|
|
2
|
+
export declare const STARTER_BLOCKS: {
|
|
3
|
+
readonly base: `# The branch production runs. Comparisons use it as the base.
|
|
4
|
+
base: main
|
|
5
|
+
`;
|
|
6
|
+
readonly prepare: `# Run once in a fresh checkout of a base commit, before anything else.
|
|
7
|
+
# prepare: pnpm install --frozen-lockfile --offline
|
|
8
|
+
`;
|
|
9
|
+
readonly services: `# What can come up. {{port}} is filled with the port; port: auto picks a free one.
|
|
10
|
+
services:
|
|
11
|
+
web:
|
|
12
|
+
up: pnpm dev --port {{port}}
|
|
13
|
+
port: auto
|
|
14
|
+
ready: http://127.0.0.1:{{port}}/
|
|
15
|
+
`;
|
|
16
|
+
readonly people: `# Who you can sign in as. A sign-in command prints {"people": {"name": "token"}}.
|
|
17
|
+
# signIn: node scripts/people.mjs
|
|
18
|
+
people:
|
|
19
|
+
owner:
|
|
20
|
+
describe: The organisation's owner
|
|
21
|
+
default: true
|
|
22
|
+
`;
|
|
23
|
+
readonly worlds: `# Named starting states. A world extends another and adds to it.
|
|
24
|
+
worlds:
|
|
25
|
+
empty:
|
|
26
|
+
describe: Nothing but the schema
|
|
27
|
+
default: true
|
|
28
|
+
# one-org:
|
|
29
|
+
# extends: empty
|
|
30
|
+
# add: node scripts/seed.mjs one-org --url {{web_url}}
|
|
31
|
+
`;
|
|
32
|
+
readonly standins: `# Fakes for what can't run locally, named in every result.
|
|
33
|
+
# standins:
|
|
34
|
+
# ai:
|
|
35
|
+
# replaces: The model provider
|
|
36
|
+
# by: test/fixtures/ai-fake.ts
|
|
37
|
+
# env: { AI_PROVIDER: fake }
|
|
38
|
+
`;
|
|
39
|
+
readonly scenarios: `# Where the scenarios are. A path starting with ./ is read beside this file; any other, from each checkout.
|
|
40
|
+
scenarios:
|
|
41
|
+
pieces: ['src/**/*.stories.tsx']
|
|
42
|
+
flows: ['**/*.flow.yaml']
|
|
43
|
+
calls: ['**/*.hurl']
|
|
44
|
+
files: ['**/*.rehearse.yaml']
|
|
45
|
+
`;
|
|
46
|
+
};
|
|
47
|
+
export declare const STARTER: string;
|
package/dist/manifest/init.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const STARTER_HEAD = `# rehearse.yaml: what this repository has, so a change can be rehearsed before it ships.
|
|
2
2
|
# Every block is optional. Delete what you don't have. Reference: the docs' rehearse.yaml page.
|
|
3
3
|
version: 1
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
`;
|
|
5
|
+
export const STARTER_BLOCKS = {
|
|
6
|
+
base: `# The branch production runs. Comparisons use it as the base.
|
|
6
7
|
base: main
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
`,
|
|
9
|
+
prepare: `# Run once in a fresh checkout of a base commit, before anything else.
|
|
9
10
|
# prepare: pnpm install --frozen-lockfile --offline
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
`,
|
|
12
|
+
services: `# What can come up. {{port}} is filled with the port; port: auto picks a free one.
|
|
12
13
|
services:
|
|
13
14
|
web:
|
|
14
15
|
up: pnpm dev --port {{port}}
|
|
15
16
|
port: auto
|
|
16
17
|
ready: http://127.0.0.1:{{port}}/
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
`,
|
|
19
|
+
people: `# Who you can sign in as. A sign-in command prints {"people": {"name": "token"}}.
|
|
19
20
|
# signIn: node scripts/people.mjs
|
|
20
21
|
people:
|
|
21
22
|
owner:
|
|
22
23
|
describe: The organisation's owner
|
|
23
24
|
default: true
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
`,
|
|
26
|
+
worlds: `# Named starting states. A world extends another and adds to it.
|
|
26
27
|
worlds:
|
|
27
28
|
empty:
|
|
28
29
|
describe: Nothing but the schema
|
|
@@ -30,18 +31,20 @@ worlds:
|
|
|
30
31
|
# one-org:
|
|
31
32
|
# extends: empty
|
|
32
33
|
# add: node scripts/seed.mjs one-org --url {{web_url}}
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
`,
|
|
35
|
+
standins: `# Fakes for what can't run locally, named in every result.
|
|
35
36
|
# standins:
|
|
36
37
|
# ai:
|
|
37
38
|
# replaces: The model provider
|
|
38
39
|
# by: test/fixtures/ai-fake.ts
|
|
39
40
|
# env: { AI_PROVIDER: fake }
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
`,
|
|
42
|
+
scenarios: `# Where the scenarios are. A path starting with ./ is read beside this file; any other, from each checkout.
|
|
42
43
|
scenarios:
|
|
43
44
|
pieces: ['src/**/*.stories.tsx']
|
|
44
45
|
flows: ['**/*.flow.yaml']
|
|
45
46
|
calls: ['**/*.hurl']
|
|
46
47
|
files: ['**/*.rehearse.yaml']
|
|
47
|
-
|
|
48
|
+
`,
|
|
49
|
+
};
|
|
50
|
+
export const STARTER = [STARTER_HEAD, ...Object.values(STARTER_BLOCKS)].join('\n');
|
package/dist/scenarios/glob.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const NEVER_WALKED: Set<string>;
|
|
2
|
+
export declare const escapeGlob: (text: string) => string;
|
|
2
3
|
export declare function globToRegExp(glob: string): RegExp;
|
|
3
4
|
export declare function globRoot(glob: string): string;
|
|
4
5
|
export declare const toPosix: (p: string) => string;
|
package/dist/scenarios/glob.js
CHANGED
|
@@ -16,12 +16,19 @@ export const NEVER_WALKED = new Set([
|
|
|
16
16
|
'.venv',
|
|
17
17
|
]);
|
|
18
18
|
const escape = (c) => c.replace(/[.+^$()|\\]/g, '\\$&');
|
|
19
|
+
const literal = (c) => c.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
|
|
20
|
+
export const escapeGlob = (text) => text.replace(/[*?[\]{}\\]/g, '\\$&');
|
|
19
21
|
export function globToRegExp(glob) {
|
|
20
22
|
let out = '';
|
|
21
23
|
let i = 0;
|
|
22
24
|
let braces = 0;
|
|
23
25
|
while (i < glob.length) {
|
|
24
26
|
const c = glob[i];
|
|
27
|
+
if (c === '\\' && i + 1 < glob.length) {
|
|
28
|
+
out += literal(glob[i + 1]);
|
|
29
|
+
i += 2;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
25
32
|
if (c === '*') {
|
|
26
33
|
if (glob[i + 1] === '*') {
|
|
27
34
|
const slashAfter = glob[i + 2] === '/';
|
|
@@ -59,15 +66,15 @@ export function globToRegExp(glob) {
|
|
|
59
66
|
out += escape(c);
|
|
60
67
|
i += 1;
|
|
61
68
|
}
|
|
62
|
-
return new RegExp(`^${out}
|
|
69
|
+
return new RegExp(`^${out}$`, 's');
|
|
63
70
|
}
|
|
64
71
|
export function globRoot(glob) {
|
|
65
72
|
const parts = glob.split('/');
|
|
66
73
|
const fixed = [];
|
|
67
74
|
for (const part of parts.slice(0, -1)) {
|
|
68
|
-
if (/[*?{[]/.test(part))
|
|
75
|
+
if (/[*?{[]/.test(part.replace(/\\[\s\S]/g, '')))
|
|
69
76
|
break;
|
|
70
|
-
fixed.push(part);
|
|
77
|
+
fixed.push(part.replace(/\\([\s\S])/g, '$1'));
|
|
71
78
|
}
|
|
72
79
|
return fixed.join('/');
|
|
73
80
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { packageDirOf, packageNameOf } from './area.ts';
|
|
2
|
-
export { findFiles, globRoot, globToRegExp, matches, toPosix } from './glob.ts';
|
|
2
|
+
export { escapeGlob, findFiles, globRoot, globToRegExp, matches, NEVER_WALKED, toPosix } from './glob.ts';
|
|
3
3
|
export { readScenarios, registerReader } from './read.ts';
|
|
4
4
|
export { refOf, type Refused, type Scenario, type ScenarioRef } from './scenario.ts';
|
package/dist/scenarios/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { packageDirOf, packageNameOf } from './area.js';
|
|
2
|
-
export { findFiles, globRoot, globToRegExp, matches, toPosix } from './glob.js';
|
|
2
|
+
export { escapeGlob, findFiles, globRoot, globToRegExp, matches, NEVER_WALKED, toPosix } from './glob.js';
|
|
3
3
|
export { readScenarios, registerReader } from './read.js';
|
|
4
4
|
export { refOf } from './scenario.js';
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ErrorObject, type ValidateFunction } from 'ajv/dist/2020.js';
|
|
2
2
|
export declare const SCHEMA_DIR: string;
|
|
3
|
-
export declare const SCHEMAS: readonly ['manifest', 'flow', 'file-scenario', 'announce', 'services', 'people', 'worlds', 'list', 'observation', 'comparison', 'drive', 'open', 'stage', 'try', 'error', 'dependents', 'check', 'init', 'validate', 'up', 'clean'];
|
|
3
|
+
export declare const SCHEMAS: readonly ['manifest', 'flow', 'file-scenario', 'announce', 'services', 'people', 'worlds', 'list', 'observation', 'comparison', 'drive', 'open', 'stage', 'static', 'try', 'error', 'dependents', 'check', 'init', 'validate', 'up', 'clean'];
|
|
4
4
|
export type SchemaName = (typeof SCHEMAS)[number];
|
|
5
5
|
export declare const schemaId: (name: SchemaName | 'common') => string;
|
|
6
6
|
export declare function validatorOf(name: SchemaName): ValidateFunction;
|
package/dist/schema.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { fileInTheCopy, fromTheCopy, staticCopy } from './static.js';
|
|
1
2
|
const refusedByTheStage = (answer) => answer.ok === false && answer.error !== undefined;
|
|
2
3
|
export async function api(path, body) {
|
|
4
|
+
if (staticCopy)
|
|
5
|
+
return fromTheCopy(path, body);
|
|
3
6
|
const r = await fetch(path, body === undefined
|
|
4
7
|
? {}
|
|
5
8
|
: { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
|
|
@@ -8,4 +11,4 @@ export async function api(path, body) {
|
|
|
8
11
|
throw new Error(json.error?.says ?? `The stage answered ${r.status}.`);
|
|
9
12
|
return json;
|
|
10
13
|
}
|
|
11
|
-
export const fileUrl = (file) => `/files?path=${encodeURIComponent(file)}`;
|
|
14
|
+
export const fileUrl = (file) => staticCopy ? fileInTheCopy(file) : `/files?path=${encodeURIComponent(file)}`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const staticCopy = document.documentElement.dataset.stage === 'static';
|
|
2
|
+
const NEEDS_THE_STAGE = 'This is a static copy of a comparison: rehearse stage runs it live.';
|
|
3
|
+
let copiedIndex = null;
|
|
4
|
+
async function copied(file) {
|
|
5
|
+
const r = await fetch(file);
|
|
6
|
+
if (!r.ok)
|
|
7
|
+
throw new Error(`This static copy has no ${file} (${r.status}).`);
|
|
8
|
+
return (await r.json());
|
|
9
|
+
}
|
|
10
|
+
const indexOfTheCopy = () => (copiedIndex ??= copied('data/index.json'));
|
|
11
|
+
export async function fromTheCopy(asked, body) {
|
|
12
|
+
if (body !== undefined)
|
|
13
|
+
throw new Error(NEEDS_THE_STAGE);
|
|
14
|
+
const url = new URL(asked, 'http://stage.invalid');
|
|
15
|
+
if (url.pathname === '/api/index')
|
|
16
|
+
return (await indexOfTheCopy());
|
|
17
|
+
if (url.pathname === '/api/scenario') {
|
|
18
|
+
const id = url.searchParams.get('id') ?? '';
|
|
19
|
+
const row = (await indexOfTheCopy()).scenarios.find((s) => s.id === id);
|
|
20
|
+
if (!row)
|
|
21
|
+
throw new Error(`This static copy has no scenario “${id}”.`);
|
|
22
|
+
return copied(row.data);
|
|
23
|
+
}
|
|
24
|
+
if (url.pathname === '/api/tries')
|
|
25
|
+
return { v: 1, tries: [] };
|
|
26
|
+
throw new Error(NEEDS_THE_STAGE);
|
|
27
|
+
}
|
|
28
|
+
export const fileInTheCopy = (file) => file.split('/').map(encodeURIComponent).join('/');
|
|
@@ -1,18 +1,27 @@
|
|
|
1
|
-
import { api } from '../../client/index.js';
|
|
2
|
-
import { disableKeepingFocus, enableAgain, h, say, state } from '../../primitives/index.js';
|
|
1
|
+
import { api, staticCopy } from '../../client/index.js';
|
|
2
|
+
import { disableKeepingFocus, enableAgain, h, say, state, } from '../../primitives/index.js';
|
|
3
3
|
import { differencesOrCompare, failuresOf, pretty, sideObs } from './parts.js';
|
|
4
4
|
const callEditsKeptAcrossDraws = new Map();
|
|
5
5
|
function answerOf(ctx, o, title) {
|
|
6
6
|
const seen = o?.observed;
|
|
7
7
|
if (!o || !seen)
|
|
8
|
-
return h('div', {}, h('h3', {}, title), o
|
|
8
|
+
return h('div', {}, h('h3', {}, title), o
|
|
9
|
+
? (failuresOf(o) ?? ctx.notRunYet('head'))
|
|
10
|
+
: h('p', { class: 'note' }, staticCopy ? 'Not run in this comparison.' : 'Not run yet.'));
|
|
9
11
|
const ok = typeof seen.status === 'number' && seen.status < 400;
|
|
10
12
|
return h('div', {}, h('h3', {}, title), h('div', { class: 'answer-head' }, h('span', { class: `code-badge ${ok ? 'ok' : 'bad'}` }, String(seen.status ?? '—')), h('span', {}, seen.contentType ?? ''), h('span', { class: 'note' }, seen.who ? `as ${seen.who}` : '')), h('pre', {}, pretty(seen.body)), failuresOf(o));
|
|
11
13
|
}
|
|
14
|
+
function asCompared(ctx, side) {
|
|
15
|
+
const o = sideObs(ctx, side);
|
|
16
|
+
const request = o?.observed?.request;
|
|
17
|
+
return h('div', { class: 'split' }, h('div', {}, h('h3', {}, 'Request'), h('pre', {}, request ?? '—')), answerOf(ctx, o, side === 'base' ? 'On the base' : 'On the head'));
|
|
18
|
+
}
|
|
12
19
|
export const callView = (ctx) => {
|
|
13
20
|
if (ctx.mode === 'diff')
|
|
14
21
|
return h('div', {}, differencesOrCompare(ctx), h('div', { class: 'split' }, answerOf(ctx, ctx.detail.base, 'On the base'), answerOf(ctx, ctx.detail.head, 'On the head')));
|
|
15
22
|
const side = ctx.mode;
|
|
23
|
+
if (staticCopy)
|
|
24
|
+
return asCompared(ctx, side);
|
|
16
25
|
const id = ctx.detail.scenario.id;
|
|
17
26
|
const editor = h('textarea', {
|
|
18
27
|
class: 'code',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fileUrl } from '../../client/index.js';
|
|
1
|
+
import { fileUrl, staticCopy } from '../../client/index.js';
|
|
2
2
|
import { h } from '../../primitives/index.js';
|
|
3
3
|
import { differencesOrCompare, failuresOf, markLinesNotIn, pretty, sideObs } from './parts.js';
|
|
4
4
|
function outputView(o, other) {
|
|
@@ -31,6 +31,8 @@ export const fileView = (ctx) => {
|
|
|
31
31
|
const theirs = ctx.mode === 'diff' ? outputsOf(ctx.detail.base) : null;
|
|
32
32
|
const input = o.artifacts?.find((a) => a.kind === 'input');
|
|
33
33
|
return h('div', {}, ctx.mode === 'diff' ? differencesOrCompare(ctx) : null, input
|
|
34
|
-
? h('p', { class: 'note' }, 'Input: ',
|
|
34
|
+
? h('p', { class: 'note' }, 'Input: ', staticCopy
|
|
35
|
+
? h('a', { href: fileUrl(input.path), type: 'text/plain', rel: 'noopener' }, input.name ?? input.path.split('/').at(-1) ?? input.path)
|
|
36
|
+
: h('a', { href: fileUrl(input.path), target: '_blank' }, input.path.split('/').at(-1) ?? input.path))
|
|
35
37
|
: null, failuresOf(o), outputsOf(o).map((out) => h('div', {}, h('h3', {}, ctx.mode === 'diff' ? `${out.file}, on the head, against the base` : out.file), outputView(out, theirs ? (theirs.find((x) => x.file === out.file) ?? null) : null))));
|
|
36
38
|
};
|