@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,84 @@
|
|
|
1
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, rmSync, statSync, utimesSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { RehearseError } from '../errors.js';
|
|
4
|
+
import { sh, tail } from '../exec.js';
|
|
5
|
+
import { stateDir } from '../services/index.js';
|
|
6
|
+
import { commitOf, git, gitOr, topOf } from './git.js';
|
|
7
|
+
export const checkoutsDir = (m) => path.join(stateDir(m.dir), 'checkouts');
|
|
8
|
+
export function dirtyOf(m, checkout) {
|
|
9
|
+
const status = gitOr(checkout, ['status', '--porcelain', '--untracked-files=all']);
|
|
10
|
+
if (status === null)
|
|
11
|
+
return true;
|
|
12
|
+
const rehearsesOwnFiles = [
|
|
13
|
+
...m.overlay.map((o) => o.to.replace(/\/+$/, '')),
|
|
14
|
+
path.relative(checkout, stateDir(m.dir)).split(path.sep).join('/'),
|
|
15
|
+
];
|
|
16
|
+
return status
|
|
17
|
+
.split('\n')
|
|
18
|
+
.filter(Boolean)
|
|
19
|
+
.map((line) => line.slice(3).replace(/^"|"$/g, ''))
|
|
20
|
+
.some((file) => !rehearsesOwnFiles.some((i) => i && (file === i || file.startsWith(`${i}/`))));
|
|
21
|
+
}
|
|
22
|
+
export function infoOf(m, checkout, ref) {
|
|
23
|
+
return { path: checkout, ref, commit: commitOf(checkout), dirty: dirtyOf(m, checkout) };
|
|
24
|
+
}
|
|
25
|
+
export function overlay(m, checkout) {
|
|
26
|
+
for (const o of m.overlay) {
|
|
27
|
+
if (!existsSync(o.from))
|
|
28
|
+
throw new RehearseError('overlay', `The overlay ${o.from} isn't there.`);
|
|
29
|
+
const to = path.resolve(checkout, o.to);
|
|
30
|
+
mkdirSync(path.dirname(to), { recursive: true });
|
|
31
|
+
cpSync(o.from, to, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const preparedMark = (dir) => `${dir}.prepared`;
|
|
35
|
+
const NAMED_AS_A_FOLDER = /^(?:\.{1,2}(?:\/|$)|\/|~\/)/;
|
|
36
|
+
export async function checkoutFor(m, repo, given, progress, keep = [], cwd = process.cwd()) {
|
|
37
|
+
if (NAMED_AS_A_FOLDER.test(given)) {
|
|
38
|
+
const asPath = path.resolve(cwd, given.replace(/^~(?=\/)/, process.env.HOME ?? '~'));
|
|
39
|
+
if (!existsSync(asPath) || !statSync(asPath).isDirectory())
|
|
40
|
+
throw new RehearseError('no_checkout', `There is no checkout at ${asPath}.`);
|
|
41
|
+
return { path: topOf(asPath) ?? asPath, ref: null };
|
|
42
|
+
}
|
|
43
|
+
const commit = commitOf(repo, given);
|
|
44
|
+
if (!commit)
|
|
45
|
+
throw new RehearseError('git', `${given} isn't a commit Rehearse can find in ${repo}.${existsSync(path.resolve(cwd, given)) ? ` To mean the folder, write ./${given}.` : ''}`);
|
|
46
|
+
const dir = path.join(checkoutsDir(m), commit.slice(0, 12));
|
|
47
|
+
if (!existsSync(dir)) {
|
|
48
|
+
mkdirSync(checkoutsDir(m), { recursive: true });
|
|
49
|
+
progress(`Checking out ${given} (${commit.slice(0, 12)}) into ${dir}`);
|
|
50
|
+
gitOr(repo, ['worktree', 'prune']);
|
|
51
|
+
git(repo, ['worktree', 'add', '--detach', dir, commit]);
|
|
52
|
+
}
|
|
53
|
+
if (m.prepare && !existsSync(preparedMark(dir))) {
|
|
54
|
+
progress(`Preparing ${dir}: ${m.prepare}`);
|
|
55
|
+
const ran = await sh(m.prepare, { cwd: dir, timeoutMs: 30 * 60_000 });
|
|
56
|
+
if (ran.code !== 0)
|
|
57
|
+
throw new RehearseError('prepare', `Preparing ${given} failed (${m.prepare}): ${tail(ran.stderr || ran.stdout) || `exit ${ran.code}`}`);
|
|
58
|
+
writeFileSync(preparedMark(dir), `${new Date().toISOString()}\n`);
|
|
59
|
+
}
|
|
60
|
+
const now = new Date();
|
|
61
|
+
utimesSync(dir, now, now);
|
|
62
|
+
evict(m, repo, [dir, ...keep]);
|
|
63
|
+
return { path: dir, ref: given };
|
|
64
|
+
}
|
|
65
|
+
export function evict(m, repo, keep = []) {
|
|
66
|
+
const root = checkoutsDir(m);
|
|
67
|
+
if (!existsSync(root))
|
|
68
|
+
return [];
|
|
69
|
+
const dirs = readdirSync(root, { withFileTypes: true })
|
|
70
|
+
.filter((d) => d.isDirectory())
|
|
71
|
+
.map((d) => path.join(root, d.name))
|
|
72
|
+
.sort((a, b) => statSync(b).mtimeMs - statSync(a).mtimeMs);
|
|
73
|
+
const gone = [];
|
|
74
|
+
for (const dir of dirs.slice(m.budget.checkouts)) {
|
|
75
|
+
if (keep.some((k) => path.resolve(k) === path.resolve(dir)))
|
|
76
|
+
continue;
|
|
77
|
+
gitOr(repo, ['worktree', 'remove', '--force', dir]);
|
|
78
|
+
rmSync(dir, { recursive: true, force: true });
|
|
79
|
+
rmSync(preparedMark(dir), { force: true });
|
|
80
|
+
gone.push(dir);
|
|
81
|
+
}
|
|
82
|
+
gitOr(repo, ['worktree', 'prune']);
|
|
83
|
+
return gone;
|
|
84
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function git(dir: string, args: readonly string[], options?: {
|
|
2
|
+
input?: string;
|
|
3
|
+
}): string;
|
|
4
|
+
export declare function gitOr(dir: string, args: readonly string[]): string | null;
|
|
5
|
+
export declare const topOf: (dir: string) => string | null;
|
|
6
|
+
export declare const commitOf: (dir: string, ref?: string) => string | null;
|
|
7
|
+
export declare const isDirty: (dir: string) => boolean;
|
package/dist/git/git.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { RehearseError, errorText } from '../errors.js';
|
|
3
|
+
export function git(dir, args, options = {}) {
|
|
4
|
+
try {
|
|
5
|
+
return execFileSync('git', ['-C', dir, ...args], {
|
|
6
|
+
encoding: 'utf8',
|
|
7
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
8
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
9
|
+
...(options.input !== undefined && { input: options.input }),
|
|
10
|
+
}).trimEnd();
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
const said = error.stderr?.trim().split('\n').at(-1) ?? errorText(error);
|
|
14
|
+
throw new RehearseError('git', `git ${args.join(' ')} failed in ${dir}: ${said}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function gitOr(dir, args) {
|
|
18
|
+
try {
|
|
19
|
+
return git(dir, args);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export const topOf = (dir) => gitOr(dir, ['rev-parse', '--show-toplevel']);
|
|
26
|
+
export const commitOf = (dir, ref = 'HEAD') => gitOr(dir, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]);
|
|
27
|
+
export const isDirty = (dir) => (gitOr(dir, ['status', '--porcelain', '--untracked-files=no']) ?? '') !== '';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { main as runCli } from './cli.ts';
|
|
2
|
+
export { findManifest, loadManifest, manifestFrom, hashOf } from './manifest/index.ts';
|
|
3
|
+
export type { Manifest, Service, Person, World, Standin, Kind } from './manifest/index.ts';
|
|
4
|
+
export { fill } from './manifest/index.ts';
|
|
5
|
+
export { validate, validatorOf, SCHEMAS, SCHEMA_DIR, type SchemaName } from './schema.ts';
|
|
6
|
+
export { signedInFrom, scrub, scrubDeep } from './people/index.ts';
|
|
7
|
+
export { chainOf } from './worlds/index.ts';
|
|
8
|
+
export { readScenarios } from './scenarios/index.ts';
|
|
9
|
+
export type { Scenario, ScenarioRef } from './scenarios/index.ts';
|
|
10
|
+
export { RehearseError } from './errors.ts';
|
|
11
|
+
export { VERSION } from './version.ts';
|
|
12
|
+
export { compare, type Comparison, type CompareOptions } from './compare/index.ts';
|
|
13
|
+
export { runSide, type SideRun, type SessionOptions } from './run/index.ts';
|
|
14
|
+
export type { Observation } from './run/index.ts';
|
|
15
|
+
export { affected } from './affected/index.ts';
|
|
16
|
+
export { bringUp, bringDown } from './services/index.ts';
|
|
17
|
+
export { defineWorld, buildWorld, worldChain, worldMain, type WorldDefinition, type WorldContext, } from './worlds/index.ts';
|
|
18
|
+
export { setAsideJson, setAsideText } from './compare/index.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { main as runCli } from './cli.js';
|
|
2
|
+
export { findManifest, loadManifest, manifestFrom, hashOf } from './manifest/index.js';
|
|
3
|
+
export { fill } from './manifest/index.js';
|
|
4
|
+
export { validate, validatorOf, SCHEMAS, SCHEMA_DIR } from './schema.js';
|
|
5
|
+
export { signedInFrom, scrub, scrubDeep } from './people/index.js';
|
|
6
|
+
export { chainOf } from './worlds/index.js';
|
|
7
|
+
export { readScenarios } from './scenarios/index.js';
|
|
8
|
+
export { RehearseError } from './errors.js';
|
|
9
|
+
export { VERSION } from './version.js';
|
|
10
|
+
export { compare } from './compare/index.js';
|
|
11
|
+
export { runSide } from './run/index.js';
|
|
12
|
+
export { affected } from './affected/index.js';
|
|
13
|
+
export { bringUp, bringDown } from './services/index.js';
|
|
14
|
+
export { defineWorld, buildWorld, worldChain, worldMain, } from './worlds/index.js';
|
|
15
|
+
export { setAsideJson, setAsideText } from './compare/index.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Assert, Query } from './hurl.ts';
|
|
2
|
+
export interface Answer {
|
|
3
|
+
status: number;
|
|
4
|
+
headers: Record<string, string>;
|
|
5
|
+
text: string;
|
|
6
|
+
json: unknown;
|
|
7
|
+
ms: number;
|
|
8
|
+
}
|
|
9
|
+
export interface Found {
|
|
10
|
+
found: boolean;
|
|
11
|
+
value: unknown;
|
|
12
|
+
error?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function jsonpath(doc: unknown, path: string): Found;
|
|
15
|
+
export declare function evaluate(query: Query, answer: Answer): Found;
|
|
16
|
+
export declare class NoValue extends Error {
|
|
17
|
+
name: string;
|
|
18
|
+
readonly variable: string;
|
|
19
|
+
constructor(variable: string);
|
|
20
|
+
}
|
|
21
|
+
export declare function substitute(text: string, vars: Readonly<Record<string, unknown>>): string;
|
|
22
|
+
export declare const variablesIn: (text: string) => string[];
|
|
23
|
+
export interface Checked {
|
|
24
|
+
ok: boolean;
|
|
25
|
+
expected: string | null;
|
|
26
|
+
got: string;
|
|
27
|
+
}
|
|
28
|
+
export declare const shown: (v: unknown) => string;
|
|
29
|
+
export declare function check(assert: Assert, answer: Answer, vars: Readonly<Record<string, unknown>>): Checked;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { HURL_WORDS } from './words.js';
|
|
2
|
+
const isObject = (x) => typeof x === 'object' && x !== null;
|
|
3
|
+
function filtered(nodes, inner) {
|
|
4
|
+
const f = /^\?\(@\.([A-Za-z_][A-Za-z0-9_]*)\s*(==|!=)\s*('([^']*)'|"([^"]*)"|-?\d+(?:\.\d+)?|true|false|null)\)$/.exec(inner);
|
|
5
|
+
if (!f)
|
|
6
|
+
throw new Error(`unsupported filter ${inner}`);
|
|
7
|
+
const want = f[4] ?? f[5] ?? JSON.parse(f[3]);
|
|
8
|
+
return nodes.flatMap((x) => (Array.isArray(x) ? x : []).filter((y) => isObject(y) && (f[2] === '==') === (y[f[1]] === want)));
|
|
9
|
+
}
|
|
10
|
+
export function jsonpath(doc, path) {
|
|
11
|
+
if (!path.startsWith('$'))
|
|
12
|
+
throw new Error(`a JSON path starts with $: ${path}`);
|
|
13
|
+
let nodes = [doc];
|
|
14
|
+
let definite = true;
|
|
15
|
+
let i = 1;
|
|
16
|
+
while (i < path.length) {
|
|
17
|
+
if (path.startsWith('..', i))
|
|
18
|
+
throw new Error(`unsupported JSON path ${path}`);
|
|
19
|
+
if (path[i] === '.') {
|
|
20
|
+
const m = /^\.([A-Za-z_$][A-Za-z0-9_$-]*|\*)/.exec(path.slice(i));
|
|
21
|
+
if (!m)
|
|
22
|
+
throw new Error(`bad JSON path ${path}`);
|
|
23
|
+
i += m[0].length;
|
|
24
|
+
if (m[1] === '*') {
|
|
25
|
+
definite = false;
|
|
26
|
+
nodes = nodes.flatMap((x) => (isObject(x) ? Object.values(x) : []));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const key = m[1];
|
|
30
|
+
nodes = nodes.flatMap((x) => (isObject(x) && key in x ? [x[key]] : []));
|
|
31
|
+
}
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (path[i] === '[') {
|
|
35
|
+
const end = path.indexOf(']', i);
|
|
36
|
+
if (end < 0)
|
|
37
|
+
throw new Error(`bad JSON path ${path}`);
|
|
38
|
+
const inner = path.slice(i + 1, end).trim();
|
|
39
|
+
i = end + 1;
|
|
40
|
+
if (inner === '*') {
|
|
41
|
+
definite = false;
|
|
42
|
+
nodes = nodes.flatMap((x) => (Array.isArray(x) ? x : isObject(x) ? Object.values(x) : []));
|
|
43
|
+
}
|
|
44
|
+
else if (/^-?\d+$/.test(inner)) {
|
|
45
|
+
const k = Number(inner);
|
|
46
|
+
nodes = nodes.flatMap((x) => (Array.isArray(x) && x.at(k) !== undefined ? [x.at(k)] : []));
|
|
47
|
+
}
|
|
48
|
+
else if (/^'.*'$|^".*"$/.test(inner)) {
|
|
49
|
+
const k = inner.slice(1, -1);
|
|
50
|
+
nodes = nodes.flatMap((x) => (isObject(x) && k in x ? [x[k]] : []));
|
|
51
|
+
}
|
|
52
|
+
else if (inner.startsWith('?(')) {
|
|
53
|
+
definite = false;
|
|
54
|
+
nodes = filtered(nodes, inner);
|
|
55
|
+
}
|
|
56
|
+
else
|
|
57
|
+
throw new Error(`unsupported JSON path part [${inner}]`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`bad JSON path ${path}`);
|
|
61
|
+
}
|
|
62
|
+
if (definite)
|
|
63
|
+
return nodes.length ? { found: true, value: nodes[0] } : { found: false, value: undefined };
|
|
64
|
+
return { found: true, value: nodes };
|
|
65
|
+
}
|
|
66
|
+
export function evaluate(query, answer) {
|
|
67
|
+
let found = true;
|
|
68
|
+
let value;
|
|
69
|
+
switch (query.kind) {
|
|
70
|
+
case 'status':
|
|
71
|
+
value = answer.status;
|
|
72
|
+
break;
|
|
73
|
+
case 'duration':
|
|
74
|
+
value = answer.ms;
|
|
75
|
+
break;
|
|
76
|
+
case 'header':
|
|
77
|
+
value = answer.headers[(query.arg ?? '').toLowerCase()];
|
|
78
|
+
found = value !== undefined;
|
|
79
|
+
break;
|
|
80
|
+
case 'body':
|
|
81
|
+
value = answer.text;
|
|
82
|
+
break;
|
|
83
|
+
case 'jsonpath':
|
|
84
|
+
if (answer.json === undefined)
|
|
85
|
+
return { found: false, value: undefined, error: HURL_WORDS.notJson };
|
|
86
|
+
({ found, value } = jsonpath(answer.json, query.arg ?? '$'));
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (query.count) {
|
|
90
|
+
if (!Array.isArray(value))
|
|
91
|
+
return { found: false, value, error: HURL_WORDS.count };
|
|
92
|
+
value = value.length;
|
|
93
|
+
}
|
|
94
|
+
return { found, value };
|
|
95
|
+
}
|
|
96
|
+
const VARIABLE = /\{\{\s*([A-Za-z_][A-Za-z0-9_-]*)\s*\}\}/g;
|
|
97
|
+
export class NoValue extends Error {
|
|
98
|
+
name = 'NoValue';
|
|
99
|
+
variable;
|
|
100
|
+
constructor(variable) {
|
|
101
|
+
super(HURL_WORDS.noValue(variable));
|
|
102
|
+
this.variable = variable;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function substitute(text, vars) {
|
|
106
|
+
return text.replace(VARIABLE, (_all, name) => {
|
|
107
|
+
if (!(name in vars) || vars[name] === undefined)
|
|
108
|
+
throw new NoValue(name);
|
|
109
|
+
const v = vars[name];
|
|
110
|
+
return typeof v === 'string' ? v : JSON.stringify(v);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
export const variablesIn = (text) => [...text.matchAll(VARIABLE)].map((m) => m[1]);
|
|
114
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
115
|
+
const ISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
|
|
116
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
117
|
+
function wanted(assert, vars) {
|
|
118
|
+
const v = assert.value;
|
|
119
|
+
if (v === null)
|
|
120
|
+
return null;
|
|
121
|
+
if ('string' in v) {
|
|
122
|
+
const whole = /^\{\{\s*([A-Za-z_][A-Za-z0-9_-]*)\s*\}\}$/.exec(v.string);
|
|
123
|
+
if (whole) {
|
|
124
|
+
const name = whole[1];
|
|
125
|
+
if (!(name in vars))
|
|
126
|
+
throw new NoValue(whole[1]);
|
|
127
|
+
return vars[whole[1]];
|
|
128
|
+
}
|
|
129
|
+
return substitute(v.string, vars);
|
|
130
|
+
}
|
|
131
|
+
if ('regex' in v)
|
|
132
|
+
return new RegExp(v.regex);
|
|
133
|
+
return v.literal;
|
|
134
|
+
}
|
|
135
|
+
function holds(predicate, found, v, want) {
|
|
136
|
+
const n = (x) => (typeof x === 'number' ? x : NaN);
|
|
137
|
+
switch (predicate) {
|
|
138
|
+
case 'exists':
|
|
139
|
+
return found && v !== undefined;
|
|
140
|
+
case '==':
|
|
141
|
+
return found && same(v, want);
|
|
142
|
+
case '!=':
|
|
143
|
+
return !(found && same(v, want));
|
|
144
|
+
case '>':
|
|
145
|
+
return found && n(v) > n(want);
|
|
146
|
+
case '>=':
|
|
147
|
+
return found && n(v) >= n(want);
|
|
148
|
+
case '<':
|
|
149
|
+
return found && n(v) < n(want);
|
|
150
|
+
case '<=':
|
|
151
|
+
return found && n(v) <= n(want);
|
|
152
|
+
case 'contains':
|
|
153
|
+
return typeof v === 'string' && typeof want === 'string' && v.includes(want);
|
|
154
|
+
case 'includes':
|
|
155
|
+
return Array.isArray(v) && v.some((x) => same(x, want));
|
|
156
|
+
case 'startsWith':
|
|
157
|
+
return typeof v === 'string' && typeof want === 'string' && v.startsWith(want);
|
|
158
|
+
case 'endsWith':
|
|
159
|
+
return typeof v === 'string' && typeof want === 'string' && v.endsWith(want);
|
|
160
|
+
case 'matches':
|
|
161
|
+
return typeof v === 'string' && want instanceof RegExp && want.test(v);
|
|
162
|
+
case 'isString':
|
|
163
|
+
return typeof v === 'string';
|
|
164
|
+
case 'isInteger':
|
|
165
|
+
return Number.isInteger(v);
|
|
166
|
+
case 'isBoolean':
|
|
167
|
+
return typeof v === 'boolean';
|
|
168
|
+
case 'isCollection':
|
|
169
|
+
return Array.isArray(v) || isObject(v);
|
|
170
|
+
case 'isEmpty':
|
|
171
|
+
return (Array.isArray(v) || typeof v === 'string') && v.length === 0;
|
|
172
|
+
case 'isUuid':
|
|
173
|
+
return typeof v === 'string' && UUID.test(v);
|
|
174
|
+
case 'isIsoDate':
|
|
175
|
+
return typeof v === 'string' && ISO.test(v);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
export const shown = (v) => v instanceof RegExp ? String(v) : v === undefined ? HURL_WORDS.nothing : JSON.stringify(v);
|
|
179
|
+
export function check(assert, answer, vars) {
|
|
180
|
+
const got = evaluate(assert.query, answer);
|
|
181
|
+
const want = wanted(assert, vars);
|
|
182
|
+
const ok = holds(assert.predicate, got.found, got.value, want) !== assert.not;
|
|
183
|
+
const expected = assert.value === null ? null : shown(want);
|
|
184
|
+
if (got.error)
|
|
185
|
+
return { ok: false, expected, got: got.error };
|
|
186
|
+
return { ok, expected, got: got.found ? shown(got.value) : HURL_WORDS.nothing };
|
|
187
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ParsedCall } from './hurl.ts';
|
|
2
|
+
export declare const own: (c: ParsedCall) => {
|
|
3
|
+
method: string;
|
|
4
|
+
url: string;
|
|
5
|
+
headers: [string, string][];
|
|
6
|
+
query: [string, string][];
|
|
7
|
+
body: string | null;
|
|
8
|
+
status: number | "*" | null;
|
|
9
|
+
asserts: string[];
|
|
10
|
+
captures: (string | import("./hurl.ts").Query)[][];
|
|
11
|
+
options: {
|
|
12
|
+
retry: number;
|
|
13
|
+
interval: number;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare function callDefinition(calls: readonly ParsedCall[], index: number): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { hashOf } from '../../manifest/index.js';
|
|
2
|
+
import { variablesIn } from './check.js';
|
|
3
|
+
export const own = (c) => ({
|
|
4
|
+
method: c.method,
|
|
5
|
+
url: c.url,
|
|
6
|
+
headers: c.headers,
|
|
7
|
+
query: c.query,
|
|
8
|
+
body: c.body,
|
|
9
|
+
status: c.status?.want ?? null,
|
|
10
|
+
asserts: c.asserts.map((a) => a.text),
|
|
11
|
+
captures: c.captures.map((x) => [x.name, x.query]),
|
|
12
|
+
options: c.options,
|
|
13
|
+
});
|
|
14
|
+
const usesOf = (c) => new Set(variablesIn([
|
|
15
|
+
c.url,
|
|
16
|
+
...c.headers.map(([, v]) => v),
|
|
17
|
+
...c.query.map(([, v]) => v),
|
|
18
|
+
c.body ?? '',
|
|
19
|
+
...c.asserts.map((a) => a.text),
|
|
20
|
+
].join('\n')));
|
|
21
|
+
export function callDefinition(calls, index) {
|
|
22
|
+
const needed = new Set([index]);
|
|
23
|
+
const wanted = usesOf(calls[index]);
|
|
24
|
+
for (let i = index - 1; i >= 0; i -= 1) {
|
|
25
|
+
const c = calls[i];
|
|
26
|
+
if (c.captures.some((x) => wanted.has(x.name))) {
|
|
27
|
+
needed.add(i);
|
|
28
|
+
for (const v of usesOf(c))
|
|
29
|
+
wanted.add(v);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return hashOf([...needed].sort((a, b) => a - b).map((i) => own(calls[i])));
|
|
33
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type QueryKind = 'status' | 'header' | 'body' | 'duration' | 'jsonpath';
|
|
2
|
+
export interface Query {
|
|
3
|
+
kind: QueryKind;
|
|
4
|
+
arg: string | null;
|
|
5
|
+
count: boolean;
|
|
6
|
+
}
|
|
7
|
+
export type Value = {
|
|
8
|
+
string: string;
|
|
9
|
+
} | {
|
|
10
|
+
regex: string;
|
|
11
|
+
} | {
|
|
12
|
+
literal: number | boolean | null;
|
|
13
|
+
};
|
|
14
|
+
export declare const PREDICATES: readonly ['==', '!=', '>=', '<=', '>', '<', 'contains', 'includes', 'startsWith', 'endsWith', 'matches', 'exists', 'isString', 'isInteger', 'isBoolean', 'isCollection', 'isEmpty', 'isUuid', 'isIsoDate'];
|
|
15
|
+
export type Predicate = (typeof PREDICATES)[number];
|
|
16
|
+
export interface Assert {
|
|
17
|
+
line: number;
|
|
18
|
+
text: string;
|
|
19
|
+
query: Query;
|
|
20
|
+
not: boolean;
|
|
21
|
+
predicate: Predicate;
|
|
22
|
+
value: Value | null;
|
|
23
|
+
}
|
|
24
|
+
export interface Capture {
|
|
25
|
+
line: number;
|
|
26
|
+
name: string;
|
|
27
|
+
query: Query;
|
|
28
|
+
}
|
|
29
|
+
export interface ParsedCall {
|
|
30
|
+
file: string;
|
|
31
|
+
line: number;
|
|
32
|
+
first: number;
|
|
33
|
+
last: number;
|
|
34
|
+
name: string;
|
|
35
|
+
method: string;
|
|
36
|
+
url: string;
|
|
37
|
+
headers: [string, string][];
|
|
38
|
+
query: [string, string][];
|
|
39
|
+
options: {
|
|
40
|
+
retry: number;
|
|
41
|
+
interval: number;
|
|
42
|
+
};
|
|
43
|
+
body: string | null;
|
|
44
|
+
status: {
|
|
45
|
+
line: number;
|
|
46
|
+
want: number | '*';
|
|
47
|
+
} | null;
|
|
48
|
+
captures: Capture[];
|
|
49
|
+
asserts: Assert[];
|
|
50
|
+
lines: string[];
|
|
51
|
+
}
|
|
52
|
+
export declare class Refusal extends Error {
|
|
53
|
+
name: string;
|
|
54
|
+
readonly line: number;
|
|
55
|
+
readonly says: string;
|
|
56
|
+
constructor(line: number, says: string);
|
|
57
|
+
}
|
|
58
|
+
export interface Parsed {
|
|
59
|
+
calls: ParsedCall[];
|
|
60
|
+
}
|
|
61
|
+
export declare function parseHurl(text: string, file: string): Parsed;
|
|
62
|
+
export declare function whoOf(call: Pick<ParsedCall, 'headers'>): string;
|
|
63
|
+
export declare const pathOf: (url: string) => string;
|
|
64
|
+
export declare function requestOf(call: Pick<ParsedCall, 'method' | 'url' | 'query'>): string;
|
|
65
|
+
export declare const isVariableName: (v: string) => boolean;
|