@kurvball/rehearse 0.0.0-stage → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +107 -2
- package/dist/affected/affected.d.ts +22 -0
- package/dist/affected/affected.js +162 -0
- package/dist/affected/index.d.ts +1 -0
- package/dist/affected/index.js +1 -0
- package/dist/args.d.ts +12 -0
- package/dist/args.js +42 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +100 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +42 -0
- package/dist/commands/clean.d.ts +2 -0
- package/dist/commands/clean.js +37 -0
- package/dist/commands/command.d.ts +30 -0
- package/dist/commands/command.js +38 -0
- package/dist/commands/compare.d.ts +4 -0
- package/dist/commands/compare.js +89 -0
- package/dist/commands/drive.d.ts +2 -0
- package/dist/commands/drive.js +244 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +32 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +19 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.js +69 -0
- package/dist/commands/open.d.ts +2 -0
- package/dist/commands/open.js +60 -0
- package/dist/commands/people.d.ts +2 -0
- package/dist/commands/people.js +49 -0
- package/dist/commands/run.d.ts +4 -0
- package/dist/commands/run.js +84 -0
- package/dist/commands/services.d.ts +28 -0
- package/dist/commands/services.js +51 -0
- package/dist/commands/stage.d.ts +7 -0
- package/dist/commands/stage.js +53 -0
- package/dist/commands/up.d.ts +3 -0
- package/dist/commands/up.js +77 -0
- package/dist/commands/validate.d.ts +2 -0
- package/dist/commands/validate.js +35 -0
- package/dist/commands/worlds.d.ts +2 -0
- package/dist/commands/worlds.js +15 -0
- package/dist/compare/announce.d.ts +6 -0
- package/dist/compare/announce.js +27 -0
- package/dist/compare/compare.d.ts +83 -0
- package/dist/compare/compare.js +335 -0
- package/dist/compare/diff.d.ts +15 -0
- package/dist/compare/diff.js +105 -0
- package/dist/compare/index.d.ts +5 -0
- package/dist/compare/index.js +5 -0
- package/dist/compare/setaside.d.ts +29 -0
- package/dist/compare/setaside.js +121 -0
- package/dist/compare/verdict.d.ts +21 -0
- package/dist/compare/verdict.js +30 -0
- package/dist/drive/aria.d.ts +8 -0
- package/dist/drive/aria.js +12 -0
- package/dist/drive/browser.d.ts +34 -0
- package/dist/drive/browser.js +216 -0
- package/dist/drive/daemon.d.ts +1 -0
- package/dist/drive/daemon.js +171 -0
- package/dist/drive/grammar.d.ts +93 -0
- package/dist/drive/grammar.js +303 -0
- package/dist/drive/index.d.ts +4 -0
- package/dist/drive/index.js +4 -0
- package/dist/drive/names.d.ts +24 -0
- package/dist/drive/names.js +97 -0
- package/dist/drive/state.d.ts +13 -0
- package/dist/drive/state.js +28 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.js +32 -0
- package/dist/exec.d.ts +16 -0
- package/dist/exec.js +43 -0
- package/dist/git/checkout.d.ts +11 -0
- package/dist/git/checkout.js +90 -0
- package/dist/git/git.d.ts +7 -0
- package/dist/git/git.js +27 -0
- package/dist/git/index.d.ts +2 -0
- package/dist/git/index.js +2 -0
- package/dist/git/seed.d.ts +3 -0
- package/dist/git/seed.js +115 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +15 -0
- package/dist/kinds/all.d.ts +4 -0
- package/dist/kinds/all.js +4 -0
- package/dist/kinds/call/check.d.ts +29 -0
- package/dist/kinds/call/check.js +187 -0
- package/dist/kinds/call/definition.d.ts +16 -0
- package/dist/kinds/call/definition.js +33 -0
- package/dist/kinds/call/hurl.d.ts +65 -0
- package/dist/kinds/call/hurl.js +333 -0
- package/dist/kinds/call/kind.d.ts +8 -0
- package/dist/kinds/call/kind.js +122 -0
- package/dist/kinds/call/send.d.ts +32 -0
- package/dist/kinds/call/send.js +152 -0
- package/dist/kinds/call/words.d.ts +22 -0
- package/dist/kinds/call/words.js +24 -0
- package/dist/kinds/file/kind.d.ts +44 -0
- package/dist/kinds/file/kind.js +331 -0
- package/dist/kinds/file/layouts.d.ts +14 -0
- package/dist/kinds/file/layouts.js +103 -0
- package/dist/kinds/flow/kind.d.ts +21 -0
- package/dist/kinds/flow/kind.js +412 -0
- package/dist/kinds/flow/literal.d.ts +8 -0
- package/dist/kinds/flow/literal.js +148 -0
- package/dist/kinds/index.d.ts +10 -0
- package/dist/kinds/index.js +8 -0
- package/dist/kinds/kind.d.ts +63 -0
- package/dist/kinds/kind.js +21 -0
- package/dist/kinds/piece/canvas.d.ts +18 -0
- package/dist/kinds/piece/canvas.js +165 -0
- package/dist/kinds/piece/conventions.d.ts +12 -0
- package/dist/kinds/piece/conventions.js +101 -0
- package/dist/kinds/piece/csf.d.ts +10 -0
- package/dist/kinds/piece/csf.js +304 -0
- package/dist/kinds/piece/kind.d.ts +12 -0
- package/dist/kinds/piece/kind.js +297 -0
- package/dist/kinds/piece/server.d.ts +23 -0
- package/dist/kinds/piece/server.js +236 -0
- package/dist/manifest/fill.d.ts +4 -0
- package/dist/manifest/fill.js +7 -0
- package/dist/manifest/index.d.ts +5 -0
- package/dist/manifest/index.js +5 -0
- package/dist/manifest/init.d.ts +1 -0
- package/dist/manifest/init.js +47 -0
- package/dist/manifest/load.d.ts +7 -0
- package/dist/manifest/load.js +245 -0
- package/dist/manifest/types.d.ts +255 -0
- package/dist/manifest/types.js +7 -0
- package/dist/manifest/yaml.d.ts +5 -0
- package/dist/manifest/yaml.js +47 -0
- package/dist/people/index.d.ts +1 -0
- package/dist/people/index.js +1 -0
- package/dist/people/people.d.ts +39 -0
- package/dist/people/people.js +139 -0
- package/dist/run/cache.d.ts +20 -0
- package/dist/run/cache.js +98 -0
- package/dist/run/index.d.ts +5 -0
- package/dist/run/index.js +4 -0
- package/dist/run/observation.d.ts +27 -0
- package/dist/run/observation.js +1 -0
- package/dist/run/parallel.d.ts +28 -0
- package/dist/run/parallel.js +140 -0
- package/dist/run/session.d.ts +35 -0
- package/dist/run/session.js +399 -0
- package/dist/run/vars.d.ts +3 -0
- package/dist/run/vars.js +13 -0
- package/dist/scenarios/area.d.ts +6 -0
- package/dist/scenarios/area.js +37 -0
- package/dist/scenarios/files.d.ts +9 -0
- package/dist/scenarios/files.js +26 -0
- package/dist/scenarios/glob.d.ts +6 -0
- package/dist/scenarios/glob.js +106 -0
- package/dist/scenarios/index.d.ts +4 -0
- package/dist/scenarios/index.js +4 -0
- package/dist/scenarios/read.d.ts +18 -0
- package/dist/scenarios/read.js +54 -0
- package/dist/scenarios/scenario.d.ts +34 -0
- package/dist/scenarios/scenario.js +10 -0
- package/dist/schema.d.ts +14 -0
- package/dist/schema.js +122 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/services/registry.d.ts +23 -0
- package/dist/services/registry.js +49 -0
- package/dist/services/service.d.ts +23 -0
- package/dist/services/service.js +313 -0
- package/dist/stage/api.d.ts +30 -0
- package/dist/stage/api.js +206 -0
- package/dist/stage/client/client/api.js +11 -0
- package/dist/stage/client/client/index.js +1 -0
- package/dist/stage/client/features/canvas/call.js +65 -0
- package/dist/stage/client/features/canvas/context.js +1 -0
- package/dist/stage/client/features/canvas/file.js +36 -0
- package/dist/stage/client/features/canvas/flow.js +59 -0
- package/dist/stage/client/features/canvas/index.js +1 -0
- package/dist/stage/client/features/canvas/observed.js +8 -0
- package/dist/stage/client/features/canvas/parts.js +24 -0
- package/dist/stage/client/features/canvas/piece.js +31 -0
- package/dist/stage/client/features/canvas/reach.js +6 -0
- package/dist/stage/client/features/canvas/views.js +16 -0
- package/dist/stage/client/features/list/index.js +1 -0
- package/dist/stage/client/features/list/list.js +53 -0
- package/dist/stage/client/features/list/reach.js +10 -0
- package/dist/stage/client/features/scenario/heading.js +14 -0
- package/dist/stage/client/features/scenario/index.js +1 -0
- package/dist/stage/client/features/scenario/reach.js +9 -0
- package/dist/stage/client/features/scenario/scenario.js +145 -0
- package/dist/stage/client/features/try/index.js +1 -0
- package/dist/stage/client/features/try/reach.js +12 -0
- package/dist/stage/client/features/try/try.js +65 -0
- package/dist/stage/client/index.html +16 -0
- package/dist/stage/client/main.js +24 -0
- package/dist/stage/client/primitives/busy.js +6 -0
- package/dist/stage/client/primitives/focus.js +21 -0
- package/dist/stage/client/primitives/h.js +25 -0
- package/dist/stage/client/primitives/index.js +6 -0
- package/dist/stage/client/primitives/keyed.js +16 -0
- package/dist/stage/client/primitives/say.js +6 -0
- package/dist/stage/client/primitives/state.js +21 -0
- package/dist/stage/client/primitives/types.js +1 -0
- package/dist/stage/client/primitives/verdicts.js +8 -0
- package/dist/stage/client/stage.css +652 -0
- package/dist/stage/compared.d.ts +20 -0
- package/dist/stage/compared.js +58 -0
- package/dist/stage/files.d.ts +4 -0
- package/dist/stage/files.js +59 -0
- package/dist/stage/guard.d.ts +3 -0
- package/dist/stage/guard.js +20 -0
- package/dist/stage/http.d.ts +12 -0
- package/dist/stage/http.js +34 -0
- package/dist/stage/index.d.ts +1 -0
- package/dist/stage/index.js +1 -0
- package/dist/stage/sending.d.ts +18 -0
- package/dist/stage/sending.js +66 -0
- package/dist/stage/server.d.ts +33 -0
- package/dist/stage/server.js +253 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +5 -0
- package/dist/worlds/define.d.ts +16 -0
- package/dist/worlds/define.js +45 -0
- package/dist/worlds/index.d.ts +2 -0
- package/dist/worlds/index.js +2 -0
- package/dist/worlds/worlds.d.ts +15 -0
- package/dist/worlds/worlds.js +46 -0
- package/llms.txt +46 -0
- package/package.json +84 -3
- package/schema/v1/announce.schema.json +28 -0
- package/schema/v1/check.schema.json +67 -0
- package/schema/v1/clean.schema.json +19 -0
- package/schema/v1/common.schema.json +210 -0
- package/schema/v1/comparison.schema.json +298 -0
- package/schema/v1/dependents.schema.json +30 -0
- package/schema/v1/drive.schema.json +112 -0
- package/schema/v1/error.schema.json +26 -0
- package/schema/v1/file-scenario.schema.json +175 -0
- package/schema/v1/flow.schema.json +216 -0
- package/schema/v1/init.schema.json +20 -0
- package/schema/v1/list.schema.json +70 -0
- package/schema/v1/manifest.schema.json +434 -0
- package/schema/v1/observation.schema.json +388 -0
- package/schema/v1/open.schema.json +14 -0
- package/schema/v1/people.schema.json +88 -0
- package/schema/v1/samples/announce.yaml +5 -0
- package/schema/v1/samples/check.json +13 -0
- package/schema/v1/samples/clean.json +1 -0
- package/schema/v1/samples/comparison.json +83 -0
- package/schema/v1/samples/dependents.json +7 -0
- package/schema/v1/samples/drive.json +10 -0
- package/schema/v1/samples/error.json +10 -0
- package/schema/v1/samples/file-scenario.yaml +13 -0
- package/schema/v1/samples/flow.yaml +13 -0
- package/schema/v1/samples/init.json +1 -0
- package/schema/v1/samples/list.json +24 -0
- package/schema/v1/samples/manifest.yaml +55 -0
- package/schema/v1/samples/observation.json +49 -0
- package/schema/v1/samples/open.json +6 -0
- package/schema/v1/samples/people.json +11 -0
- package/schema/v1/samples/services.json +27 -0
- package/schema/v1/samples/stage.json +6 -0
- package/schema/v1/samples/try.json +13 -0
- package/schema/v1/samples/up.json +16 -0
- package/schema/v1/samples/validate.json +7 -0
- package/schema/v1/samples/worlds.json +21 -0
- package/schema/v1/services.schema.json +72 -0
- package/schema/v1/stage.schema.json +14 -0
- package/schema/v1/try.schema.json +56 -0
- package/schema/v1/up.schema.json +55 -0
- package/schema/v1/validate.schema.json +40 -0
- package/schema/v1/worlds.schema.json +33 -0
- package/skill/rehearse/SKILL.md +148 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { affected } from '../affected/index.js';
|
|
5
|
+
import { RehearseError, errorText } from '../errors.js';
|
|
6
|
+
import { checkoutFor, infoOf, commitOf, gitOr } from '../git/index.js';
|
|
7
|
+
import { runnerOf } from '../kinds/index.js';
|
|
8
|
+
import { cached, cacheKeyOf, groupsOf, keep, runSideSharing, slotsFor, } from '../run/index.js';
|
|
9
|
+
import { readScenarios, refOf, globToRegExp, } from '../scenarios/index.js';
|
|
10
|
+
import { runningServices, stateDir } from '../services/index.js';
|
|
11
|
+
import { announcementFor, readAnnouncement } from './announce.js';
|
|
12
|
+
import { nonZeroCounts, noCounts, rulesOf } from './setaside.js';
|
|
13
|
+
import { lineOf, verdictOf } from './verdict.js';
|
|
14
|
+
const emptyCounts = () => ({
|
|
15
|
+
same: 0,
|
|
16
|
+
said: 0,
|
|
17
|
+
announced: 0,
|
|
18
|
+
edited: 0,
|
|
19
|
+
unsaid: 0,
|
|
20
|
+
new: 0,
|
|
21
|
+
fails: 0,
|
|
22
|
+
failsOnBoth: 0,
|
|
23
|
+
gone: 0,
|
|
24
|
+
notRun: 0,
|
|
25
|
+
});
|
|
26
|
+
const hashId = (id) => createHash('sha256').update(id).digest('hex').slice(0, 16);
|
|
27
|
+
function sideOf(info, broke, cachedCount = 0) {
|
|
28
|
+
return {
|
|
29
|
+
checkout: info,
|
|
30
|
+
ok: broke === null,
|
|
31
|
+
step: broke?.step ?? null,
|
|
32
|
+
says: broke?.says ?? null,
|
|
33
|
+
cached: cachedCount,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function changedFiles(head, baseCommit) {
|
|
37
|
+
const diff = gitOr(head, ['diff', '--name-only', baseCommit]) ?? '';
|
|
38
|
+
const untracked = gitOr(head, ['ls-files', '--others', '--exclude-standard']) ?? '';
|
|
39
|
+
return [...new Set([...diff.split('\n'), ...untracked.split('\n')].filter(Boolean))].sort();
|
|
40
|
+
}
|
|
41
|
+
function select(all, ids) {
|
|
42
|
+
if (ids.length === 0)
|
|
43
|
+
return [...all];
|
|
44
|
+
return all.filter((s) => ids.some((id) => id === s.id || (/[*?{[]/.test(id) && globToRegExp(id).test(s.id))));
|
|
45
|
+
}
|
|
46
|
+
function cachedWholeGroupsOnly(found, scenarios, groups) {
|
|
47
|
+
const missesAMember = (group) => scenarios.some((x) => groups.get(x.id) === group && !found.has(x.id));
|
|
48
|
+
for (const s of scenarios) {
|
|
49
|
+
const group = groups.get(s.id);
|
|
50
|
+
if (group && missesAMember(group))
|
|
51
|
+
for (const x of scenarios)
|
|
52
|
+
if (groups.get(x.id) === group)
|
|
53
|
+
found.delete(x.id);
|
|
54
|
+
}
|
|
55
|
+
return found;
|
|
56
|
+
}
|
|
57
|
+
async function fromCache(m, info, scenarios, o, groups) {
|
|
58
|
+
const found = new Map();
|
|
59
|
+
if (o.fresh || !info.commit || info.dirty)
|
|
60
|
+
return found;
|
|
61
|
+
for (const s of scenarios) {
|
|
62
|
+
const runner = await runnerOf(s.kind);
|
|
63
|
+
const key = cacheKeyOf({
|
|
64
|
+
group: groups.get(s.id) ?? null,
|
|
65
|
+
commit: info.commit,
|
|
66
|
+
scenario: s,
|
|
67
|
+
world: o.world ?? s.world,
|
|
68
|
+
person: o.as ?? s.person,
|
|
69
|
+
real: [...o.real],
|
|
70
|
+
runner,
|
|
71
|
+
manifest: m,
|
|
72
|
+
});
|
|
73
|
+
const hit = cached(m, info.commit, key);
|
|
74
|
+
if (hit)
|
|
75
|
+
found.set(s.id, hit);
|
|
76
|
+
}
|
|
77
|
+
return cachedWholeGroupsOnly(found, scenarios, groups);
|
|
78
|
+
}
|
|
79
|
+
function bothSidesMayRunAtOnce(m, base, head) {
|
|
80
|
+
const onlyTheseTwo = new Set([path.resolve(base.path), path.resolve(head.path)]);
|
|
81
|
+
const headCouldReadWhatTheBaseKeeps = !head.dirty && head.commit === base.commit;
|
|
82
|
+
return (m.budget.services >= 2 &&
|
|
83
|
+
!headCouldReadWhatTheBaseKeeps &&
|
|
84
|
+
runningServices(m.dir).every((r) => onlyTheseTwo.has(path.resolve(r.checkout))));
|
|
85
|
+
}
|
|
86
|
+
const latestComparisonFile = (m, everyScenario) => path.join(stateDir(m.dir), 'compare', everyScenario ? 'latest.json' : 'latest-partial.json');
|
|
87
|
+
export async function compare(m, o) {
|
|
88
|
+
const begun = Date.now();
|
|
89
|
+
const parallel = o.parallel ?? 1;
|
|
90
|
+
const slots = slotsFor(parallel);
|
|
91
|
+
const session = (ref) => ({
|
|
92
|
+
world: o.world,
|
|
93
|
+
as: o.as,
|
|
94
|
+
real: o.real,
|
|
95
|
+
keepUp: false,
|
|
96
|
+
progress: o.progress,
|
|
97
|
+
ref,
|
|
98
|
+
parallel,
|
|
99
|
+
});
|
|
100
|
+
const head = o.head
|
|
101
|
+
? await checkoutFor(m, o.repo, o.head, o.progress, [], o.cwd)
|
|
102
|
+
: { path: o.repo, ref: null };
|
|
103
|
+
const baseRef = o.base ?? m.base;
|
|
104
|
+
const everyScenario = o.ids.length === 0 && !o.affected;
|
|
105
|
+
let base;
|
|
106
|
+
try {
|
|
107
|
+
base = await checkoutFor(m, head.path, baseRef, o.progress, [head.path], o.cwd);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
const info = { path: '', ref: baseRef, commit: commitOf(head.path, baseRef), dirty: false };
|
|
111
|
+
return failedBase(m, info, infoOf(m, head.path, head.ref), error instanceof RehearseError && ['git', 'no_checkout'].includes(error.code) ? 'checkout' : 'prepare', errorText(error), begun, everyScenario);
|
|
112
|
+
}
|
|
113
|
+
if (path.resolve(base.path) === path.resolve(head.path))
|
|
114
|
+
throw new RehearseError('usage', `The base and the head are the same checkout (${head.path}): name a base ref, or another folder.`, { exit: 2 });
|
|
115
|
+
const announced = [];
|
|
116
|
+
const announceFile = o.announce ??
|
|
117
|
+
(existsSync(path.join(stateDir(m.dir), 'announce.yaml'))
|
|
118
|
+
? path.join(stateDir(m.dir), 'announce.yaml')
|
|
119
|
+
: null);
|
|
120
|
+
if (announceFile)
|
|
121
|
+
announced.push(...readAnnouncement(path.resolve(o.repo, announceFile)));
|
|
122
|
+
for (const id of o.said)
|
|
123
|
+
announced.push({ scenario: id, why: 'Said on the command line.' });
|
|
124
|
+
const headRead = await readScenarios(m, head.path);
|
|
125
|
+
const baseRead = await readScenarios(m, base.path);
|
|
126
|
+
let headScenarios = select(headRead.scenarios, o.ids);
|
|
127
|
+
const headIds = new Set(headRead.scenarios.map((s) => s.id));
|
|
128
|
+
let baseScenarios = select(baseRead.scenarios, o.ids);
|
|
129
|
+
if (o.affected) {
|
|
130
|
+
const baseCommit = commitOf(base.path);
|
|
131
|
+
const files = baseCommit ? changedFiles(head.path, baseCommit) : [];
|
|
132
|
+
const reach = await affected(m, head.path, files, headScenarios);
|
|
133
|
+
const ids = new Set(reach.reached.map((r) => r.scenario.id));
|
|
134
|
+
headScenarios = headScenarios.filter((s) => ids.has(s.id));
|
|
135
|
+
const baseReach = await affected(m, base.path, files, baseScenarios);
|
|
136
|
+
const baseIds = new Set([...ids, ...baseReach.reached.map((r) => r.scenario.id)]);
|
|
137
|
+
baseScenarios = baseScenarios.filter((s) => baseIds.has(s.id));
|
|
138
|
+
}
|
|
139
|
+
const baseInfo = infoOf(m, base.path, base.ref);
|
|
140
|
+
const baseRunsOnlyWhatTheHeadStillHas = baseScenarios.filter((s) => headIds.has(s.id) && headScenarios.some((h) => h.id === s.id));
|
|
141
|
+
const baseGroups = await groupsOf(m, baseRunsOnlyWhatTheHeadStillHas, o.world);
|
|
142
|
+
const hits = await fromCache(m, baseInfo, baseRunsOnlyWhatTheHeadStillHas, o, baseGroups);
|
|
143
|
+
if (hits.size)
|
|
144
|
+
o.progress(`${hits.size} base observation${hits.size === 1 ? '' : 's'} read from the cache (${baseInfo.commit?.slice(0, 12)}).`);
|
|
145
|
+
const runHead = async (info) => {
|
|
146
|
+
const groups = await groupsOf(m, headScenarios, o.world);
|
|
147
|
+
const headHits = await fromCache(m, info, headScenarios, o, groups);
|
|
148
|
+
const run = await runSideSharing(m, head.path, headScenarios.filter((s) => !headHits.has(s.id)), { ...session(head.ref), groups }, slots);
|
|
149
|
+
return { info, hits: headHits, run };
|
|
150
|
+
};
|
|
151
|
+
let headAlongside = null;
|
|
152
|
+
if (parallel >= 2) {
|
|
153
|
+
const headAsItIs = infoOf(m, head.path, head.ref);
|
|
154
|
+
if (bothSidesMayRunAtOnce(m, baseInfo, headAsItIs))
|
|
155
|
+
headAlongside = runHead(headAsItIs);
|
|
156
|
+
}
|
|
157
|
+
const headDone = headAlongside?.then(() => undefined, () => undefined);
|
|
158
|
+
const baseRun = await runSideSharing(m, base.path, baseRunsOnlyWhatTheHeadStillHas.filter((s) => !hits.has(s.id)), { ...session(base.ref), groups: baseGroups }, slots).catch(async (error) => {
|
|
159
|
+
await headDone;
|
|
160
|
+
throw error;
|
|
161
|
+
});
|
|
162
|
+
if (baseRun.broke) {
|
|
163
|
+
await headDone;
|
|
164
|
+
return failedBase(m, baseRun.checkout, infoOf(m, head.path, head.ref), baseRun.broke.step, baseRun.broke.says, begun, everyScenario, [
|
|
165
|
+
...baseRead.refused.map((r) => ({ side: 'base', ...r })),
|
|
166
|
+
...headRead.refused.map((r) => ({ side: 'head', ...r })),
|
|
167
|
+
]);
|
|
168
|
+
}
|
|
169
|
+
const baseObs = new Map([...hits, ...baseRun.observations]);
|
|
170
|
+
for (const ob of baseRun.observations.values())
|
|
171
|
+
keep(m, ob);
|
|
172
|
+
const { info: headInfo, hits: headHits, run: headRun, } = await (headAlongside ?? runHead(infoOf(m, head.path, head.ref)));
|
|
173
|
+
const headObs = new Map([...headHits, ...headRun.observations]);
|
|
174
|
+
for (const ob of headRun.observations.values())
|
|
175
|
+
keep(m, ob);
|
|
176
|
+
const out = {
|
|
177
|
+
v: 1,
|
|
178
|
+
ok: false,
|
|
179
|
+
base: sideOf(baseRun.checkout.commit ? baseRun.checkout : baseInfo, null, hits.size),
|
|
180
|
+
head: sideOf(headRun.checkout.commit ? headRun.checkout : headInfo, headRun.broke, headHits.size),
|
|
181
|
+
line: '',
|
|
182
|
+
counts: emptyCounts(),
|
|
183
|
+
scenarios: [],
|
|
184
|
+
notRun: [],
|
|
185
|
+
gone: [],
|
|
186
|
+
announcedUnchanged: [],
|
|
187
|
+
byChange: [],
|
|
188
|
+
standins: [],
|
|
189
|
+
refused: [
|
|
190
|
+
...baseRead.refused.map((r) => ({ side: 'base', ...r })),
|
|
191
|
+
...headRead.refused.map((r) => ({ side: 'head', ...r })),
|
|
192
|
+
],
|
|
193
|
+
ms: 0,
|
|
194
|
+
};
|
|
195
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
196
|
+
const dir = path.join(stateDir(m.dir), 'compare', stamp);
|
|
197
|
+
const store = (side, ob) => {
|
|
198
|
+
const file = path.join(dir, side, `${hashId(ob.scenario.id)}.json`);
|
|
199
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
200
|
+
writeFileSync(file, `${JSON.stringify(ob)}\n`);
|
|
201
|
+
return file;
|
|
202
|
+
};
|
|
203
|
+
const notRunOf = (side, list) => list.forEach((n) => out.notRun.push({ scenario: refOf(n.scenario), side, step: n.step, says: n.says }));
|
|
204
|
+
if (headRun.broke) {
|
|
205
|
+
out.counts.notRun = headScenarios.length;
|
|
206
|
+
for (const s of headScenarios)
|
|
207
|
+
out.notRun.push({
|
|
208
|
+
scenario: refOf(s),
|
|
209
|
+
side: 'head',
|
|
210
|
+
step: headRun.broke.step,
|
|
211
|
+
says: headRun.broke.says,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
notRunOf('base', baseRun.notRun);
|
|
215
|
+
notRunOf('head', headRun.notRun);
|
|
216
|
+
const notRunIds = new Set(out.notRun.map((n) => n.scenario.id));
|
|
217
|
+
const baseById = new Map(baseScenarios.map((s) => [s.id, s]));
|
|
218
|
+
const allBase = new Map(baseRead.scenarios.map((s) => [s.id, s]));
|
|
219
|
+
const standins = new Map();
|
|
220
|
+
for (const s of headRun.broke ? [] : headScenarios) {
|
|
221
|
+
if (notRunIds.has(s.id))
|
|
222
|
+
continue;
|
|
223
|
+
const h = headObs.get(s.id);
|
|
224
|
+
if (!h)
|
|
225
|
+
continue;
|
|
226
|
+
for (const x of h.standins)
|
|
227
|
+
standins.set(x.name, x);
|
|
228
|
+
const b = baseObs.get(s.id);
|
|
229
|
+
const onBase = s.from === 'manifest' || allBase.has(s.id);
|
|
230
|
+
const runner = await runnerOf(s.kind);
|
|
231
|
+
const aside = noCounts();
|
|
232
|
+
let differences = [];
|
|
233
|
+
if (b && b.observed && h.observed)
|
|
234
|
+
differences = runner.compare(b.observed, h.observed, rulesOf(m.setAside, runner.unordered?.(s, m) ?? false), aside, s, m);
|
|
235
|
+
else if (b && (b.observed === null) !== (h.observed === null))
|
|
236
|
+
differences = [
|
|
237
|
+
{
|
|
238
|
+
path: 'observed',
|
|
239
|
+
base: b.observed ? 'something' : 'nothing',
|
|
240
|
+
head: h.observed ? 'something' : 'nothing',
|
|
241
|
+
count: 1,
|
|
242
|
+
},
|
|
243
|
+
];
|
|
244
|
+
const baseScenario = baseById.get(s.id) ?? allBase.get(s.id);
|
|
245
|
+
const edited = s.from === 'checkout' && baseScenario !== undefined && baseScenario.definition !== s.definition;
|
|
246
|
+
const announcement = announcementFor(s.id, announced);
|
|
247
|
+
const said = announcement ? 'announced' : edited ? 'edited' : null;
|
|
248
|
+
const changed = differences.length > 0;
|
|
249
|
+
const failsOnHead = !h.ok;
|
|
250
|
+
const failsOnBase = b ? !b.ok : false;
|
|
251
|
+
const verdict = verdictOf({ onBase: onBase && b !== undefined, failsOnHead, changed, said });
|
|
252
|
+
out.scenarios.push({
|
|
253
|
+
scenario: h.scenario,
|
|
254
|
+
verdict,
|
|
255
|
+
changed,
|
|
256
|
+
said,
|
|
257
|
+
edited,
|
|
258
|
+
why: announcement?.why ?? null,
|
|
259
|
+
failsOnBase,
|
|
260
|
+
failsOnHead,
|
|
261
|
+
differences,
|
|
262
|
+
setAside: nonZeroCounts(aside),
|
|
263
|
+
failures: h.failures,
|
|
264
|
+
baseFailures: b?.failures ?? [],
|
|
265
|
+
cached: b?.cached ?? false,
|
|
266
|
+
observations: { base: b ? store('base', b) : null, head: store('head', h) },
|
|
267
|
+
});
|
|
268
|
+
out.counts[verdict] += 1;
|
|
269
|
+
if (verdict === 'said')
|
|
270
|
+
out.counts[said === 'announced' ? 'announced' : 'edited'] += 1;
|
|
271
|
+
if (verdict === 'fails' && failsOnBase)
|
|
272
|
+
out.counts.failsOnBoth += 1;
|
|
273
|
+
}
|
|
274
|
+
out.gone = baseScenarios.filter((s) => !headIds.has(s.id)).map(refOf);
|
|
275
|
+
out.counts.gone = out.gone.length;
|
|
276
|
+
out.counts.notRun = new Set(out.notRun.map((n) => n.scenario.id)).size;
|
|
277
|
+
for (const a of announced) {
|
|
278
|
+
const named = out.scenarios.filter((c) => announcementFor(c.scenario.id, [a]));
|
|
279
|
+
const comparedGoneOrNotRun = [
|
|
280
|
+
...out.scenarios.map((c) => c.scenario.id),
|
|
281
|
+
...out.gone.map((g) => g.id),
|
|
282
|
+
...out.notRun.map((n) => n.scenario.id),
|
|
283
|
+
];
|
|
284
|
+
const mayBeATypo = everyScenario && out.head.ok && !comparedGoneOrNotRun.some((id) => announcementFor(id, [a]));
|
|
285
|
+
if (mayBeATypo)
|
|
286
|
+
out.refused.push({
|
|
287
|
+
side: 'head',
|
|
288
|
+
file: announceFile ?? '--said',
|
|
289
|
+
says: `The announcement names ${a.scenario}, which matches no scenario compared.`,
|
|
290
|
+
});
|
|
291
|
+
if (named.length > 0 && named.every((c) => !c.changed))
|
|
292
|
+
out.announcedUnchanged.push({ scenario: a.scenario, why: a.why });
|
|
293
|
+
}
|
|
294
|
+
const byPath = new Map();
|
|
295
|
+
for (const c of out.scenarios.filter((x) => x.verdict === 'unsaid'))
|
|
296
|
+
for (const d of c.differences)
|
|
297
|
+
byPath.set(d.path, (byPath.get(d.path) ?? new Set()).add(c.scenario.id));
|
|
298
|
+
out.byChange = [...byPath]
|
|
299
|
+
.map(([p, ids]) => ({ path: p, scenarios: [...ids] }))
|
|
300
|
+
.sort((a, b) => b.scenarios.length - a.scenarios.length);
|
|
301
|
+
out.standins = [...standins.values()];
|
|
302
|
+
out.line = lineOf(out.counts);
|
|
303
|
+
out.ok =
|
|
304
|
+
out.base.ok &&
|
|
305
|
+
out.head.ok &&
|
|
306
|
+
out.counts.notRun === 0 &&
|
|
307
|
+
out.counts.fails === 0 &&
|
|
308
|
+
out.counts.unsaid === 0;
|
|
309
|
+
out.ms = Date.now() - begun;
|
|
310
|
+
mkdirSync(dir, { recursive: true });
|
|
311
|
+
writeFileSync(path.join(dir, 'comparison.json'), `${JSON.stringify(out, null, 2)}\n`);
|
|
312
|
+
writeFileSync(latestComparisonFile(m, everyScenario), `${JSON.stringify(out, null, 2)}\n`);
|
|
313
|
+
return out;
|
|
314
|
+
}
|
|
315
|
+
function failedBase(m, base, head, step, says, begun, everyScenario, refused = []) {
|
|
316
|
+
const out = {
|
|
317
|
+
v: 1,
|
|
318
|
+
ok: false,
|
|
319
|
+
base: { checkout: base, ok: false, step, says, cached: 0 },
|
|
320
|
+
head: { checkout: head, ok: true, step: null, says: null, cached: 0 },
|
|
321
|
+
line: `The base didn't come up (${step}): ${says}`,
|
|
322
|
+
counts: emptyCounts(),
|
|
323
|
+
scenarios: [],
|
|
324
|
+
notRun: [],
|
|
325
|
+
gone: [],
|
|
326
|
+
announcedUnchanged: [],
|
|
327
|
+
byChange: [],
|
|
328
|
+
standins: [],
|
|
329
|
+
refused,
|
|
330
|
+
ms: Date.now() - begun,
|
|
331
|
+
};
|
|
332
|
+
mkdirSync(path.join(stateDir(m.dir), 'compare'), { recursive: true });
|
|
333
|
+
writeFileSync(latestComparisonFile(m, everyScenario), `${JSON.stringify(out, null, 2)}\n`);
|
|
334
|
+
return out;
|
|
335
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface Difference {
|
|
2
|
+
path: string;
|
|
3
|
+
base: string;
|
|
4
|
+
head: string;
|
|
5
|
+
count: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function clip(v: unknown, n?: number): string;
|
|
8
|
+
export declare function jsonDifferences(a: unknown, b: unknown, root?: string): Difference[];
|
|
9
|
+
export interface Hunk {
|
|
10
|
+
at: number;
|
|
11
|
+
removed: string[];
|
|
12
|
+
added: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare function lineHunks(a: readonly string[], b: readonly string[]): Hunk[];
|
|
15
|
+
export declare function textDifferences(a: string, b: string, label: string, limit?: number): Difference[];
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const CLIP = 80;
|
|
2
|
+
export function clip(v, n = CLIP) {
|
|
3
|
+
if (v === undefined)
|
|
4
|
+
return '(absent)';
|
|
5
|
+
const s = typeof v === 'string' ? JSON.stringify(v) : JSON.stringify(v);
|
|
6
|
+
return s.length > n ? `${s.slice(0, n - 1)}…` : s;
|
|
7
|
+
}
|
|
8
|
+
const plain = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
9
|
+
function walk(a, b, at, out) {
|
|
10
|
+
if (JSON.stringify(a) === JSON.stringify(b))
|
|
11
|
+
return;
|
|
12
|
+
if (plain(a) && plain(b)) {
|
|
13
|
+
for (const k of new Set([...Object.keys(a), ...Object.keys(b)]))
|
|
14
|
+
walk(a[k], b[k], `${at}.${k}`, out);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(a) && Array.isArray(b) && a.length === b.length) {
|
|
18
|
+
a.forEach((x, i) => walk(x, b[i], `${at}[${i}]`, out));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
out.push({ at, base: a, head: b });
|
|
22
|
+
}
|
|
23
|
+
export function jsonDifferences(a, b, root = '$') {
|
|
24
|
+
const raw = [];
|
|
25
|
+
walk(a, b, root, raw);
|
|
26
|
+
const grouped = new Map();
|
|
27
|
+
for (const d of raw) {
|
|
28
|
+
const path = d.at.replace(/\[\d+\]/g, '[*]');
|
|
29
|
+
const known = grouped.get(path);
|
|
30
|
+
if (known)
|
|
31
|
+
known.count += 1;
|
|
32
|
+
else
|
|
33
|
+
grouped.set(path, { path, base: clip(d.base), head: clip(d.head), count: 1 });
|
|
34
|
+
}
|
|
35
|
+
return [...grouped.values()];
|
|
36
|
+
}
|
|
37
|
+
const MOST_LINE_PAIRS_TO_ALIGN = 4_000_000;
|
|
38
|
+
function hunksLineByLineWithoutAligning(a, b) {
|
|
39
|
+
const hunks = [];
|
|
40
|
+
for (let i = 0; i < Math.max(a.length, b.length); i += 1)
|
|
41
|
+
if (a[i] !== b[i])
|
|
42
|
+
hunks.push({
|
|
43
|
+
at: i + 1,
|
|
44
|
+
removed: a[i] === undefined ? [] : [a[i]],
|
|
45
|
+
added: b[i] === undefined ? [] : [b[i]],
|
|
46
|
+
});
|
|
47
|
+
return hunks;
|
|
48
|
+
}
|
|
49
|
+
export function lineHunks(a, b) {
|
|
50
|
+
const n = a.length;
|
|
51
|
+
const m = b.length;
|
|
52
|
+
if (n * m > MOST_LINE_PAIRS_TO_ALIGN)
|
|
53
|
+
return hunksLineByLineWithoutAligning(a, b);
|
|
54
|
+
const lcs = Array.from({ length: n + 1 }, () => new Uint32Array(m + 1));
|
|
55
|
+
for (let i = n - 1; i >= 0; i -= 1)
|
|
56
|
+
for (let j = m - 1; j >= 0; j -= 1)
|
|
57
|
+
lcs[i][j] = a[i] === b[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
|
|
58
|
+
const hunks = [];
|
|
59
|
+
let i = 0;
|
|
60
|
+
let j = 0;
|
|
61
|
+
let open = null;
|
|
62
|
+
const close = () => {
|
|
63
|
+
if (open && (open.removed.length || open.added.length))
|
|
64
|
+
hunks.push(open);
|
|
65
|
+
open = null;
|
|
66
|
+
};
|
|
67
|
+
while (i < n || j < m) {
|
|
68
|
+
if (i < n && j < m && a[i] === b[j]) {
|
|
69
|
+
close();
|
|
70
|
+
i += 1;
|
|
71
|
+
j += 1;
|
|
72
|
+
}
|
|
73
|
+
else if (j < m && (i >= n || lcs[i][j + 1] >= lcs[i + 1][j])) {
|
|
74
|
+
open ??= { at: j + 1, removed: [], added: [] };
|
|
75
|
+
open.added.push(b[j]);
|
|
76
|
+
j += 1;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
open ??= { at: j + 1, removed: [], added: [] };
|
|
80
|
+
open.removed.push(a[i]);
|
|
81
|
+
i += 1;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
close();
|
|
85
|
+
return hunks;
|
|
86
|
+
}
|
|
87
|
+
export function textDifferences(a, b, label, limit = 20) {
|
|
88
|
+
if (a === b)
|
|
89
|
+
return [];
|
|
90
|
+
const hunks = lineHunks(a.split('\n'), b.split('\n'));
|
|
91
|
+
const out = hunks.slice(0, limit).map((h) => ({
|
|
92
|
+
path: `${label} line ${h.at}`,
|
|
93
|
+
base: clip(h.removed.join('\n').trim() || '(nothing)'),
|
|
94
|
+
head: clip(h.added.join('\n').trim() || '(nothing)'),
|
|
95
|
+
count: Math.max(h.removed.length, h.added.length, 1),
|
|
96
|
+
}));
|
|
97
|
+
if (hunks.length > limit)
|
|
98
|
+
out.push({
|
|
99
|
+
path: `${label} (more)`,
|
|
100
|
+
base: '',
|
|
101
|
+
head: `${hunks.length - limit} more changes`,
|
|
102
|
+
count: hunks.length - limit,
|
|
103
|
+
});
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { readAnnouncement } from './announce.ts';
|
|
2
|
+
export { changedFiles, compare, type CompareOptions, type Compared, type Comparison } from './compare.ts';
|
|
3
|
+
export { clip, jsonDifferences, lineHunks, textDifferences, type Difference } from './diff.ts';
|
|
4
|
+
export { noCounts, noRules, setAsideJson, setAsideText, type Counts as AsideCounts, type Rules, } from './setaside.ts';
|
|
5
|
+
export { lineOf, verdictOf, type Counts } from './verdict.ts';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { readAnnouncement } from './announce.js';
|
|
2
|
+
export { changedFiles, compare } from './compare.js';
|
|
3
|
+
export { clip, jsonDifferences, lineHunks, textDifferences } from './diff.js';
|
|
4
|
+
export { noCounts, noRules, setAsideJson, setAsideText, } from './setaside.js';
|
|
5
|
+
export { lineOf, verdictOf } from './verdict.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface Rules {
|
|
2
|
+
keys: RegExp[];
|
|
3
|
+
values: RegExp[];
|
|
4
|
+
keep: string[];
|
|
5
|
+
unordered: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const noRules: () => Rules;
|
|
8
|
+
export interface Counts {
|
|
9
|
+
ids: number;
|
|
10
|
+
times: number;
|
|
11
|
+
opaque: number;
|
|
12
|
+
order: number;
|
|
13
|
+
custom: number;
|
|
14
|
+
}
|
|
15
|
+
export declare const noCounts: () => Counts;
|
|
16
|
+
export declare const ID = "\u2039id\u203A";
|
|
17
|
+
export declare const TIME = "\u2039time\u203A";
|
|
18
|
+
export declare const OPAQUE = "\u2039opaque\u203A";
|
|
19
|
+
export declare const ASIDE = "\u2039set aside\u203A";
|
|
20
|
+
export declare function looksGenerated(v: string): boolean;
|
|
21
|
+
export declare const fold: (at: string) => string;
|
|
22
|
+
export declare function setAsideText(text: string, rules: Rules, counts: Counts): string;
|
|
23
|
+
export declare function setAsideJson(v: unknown, rules: Rules, counts: Counts, at?: string, key?: string): unknown;
|
|
24
|
+
export declare const nonZeroCounts: (c: Counts) => Partial<Counts>;
|
|
25
|
+
export declare function rulesOf(manifest: {
|
|
26
|
+
keys: string[];
|
|
27
|
+
values: string[];
|
|
28
|
+
keep: string[];
|
|
29
|
+
}, unordered?: boolean): Rules;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export const noRules = () => ({ keys: [], values: [], keep: [], unordered: false });
|
|
2
|
+
export const noCounts = () => ({ ids: 0, times: 0, opaque: 0, order: 0, custom: 0 });
|
|
3
|
+
export const ID = '‹id›';
|
|
4
|
+
export const TIME = '‹time›';
|
|
5
|
+
export const OPAQUE = '‹opaque›';
|
|
6
|
+
export const ASIDE = '‹set aside›';
|
|
7
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
8
|
+
const UUID_IN = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
|
|
9
|
+
const ULID = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
10
|
+
const ISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?$/;
|
|
11
|
+
const ISO_IN = /\b\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?/g;
|
|
12
|
+
const RELATIVE_IN = /\b(?:(?:about|almost|over|under)\s+)?(?:\d+|an?|one|a few)\s+(?:second|minute|hour|day|week|month|year)s?\s+ago\b|\bin\s+(?:\d+|an?)\s+(?:second|minute|hour)s?\b|\bjust now\b/gi;
|
|
13
|
+
const ID_KEY = /(^id$|Id$|_id$|^correlation|^requestId$|^traceId$)/;
|
|
14
|
+
const TIME_KEY = /(At$|_at$|^at$|Time$|_time$|^timestamp$|^ts$)/;
|
|
15
|
+
const OPAQUE_KEY = /(cursor|token|etag|nonce)$/i;
|
|
16
|
+
const BASE64URL = /^[A-Za-z0-9_-]{32,}={0,2}$/;
|
|
17
|
+
export function looksGenerated(v) {
|
|
18
|
+
if (UUID.test(v) || ULID.test(v))
|
|
19
|
+
return true;
|
|
20
|
+
if (v.length < 16 || /\s/.test(v))
|
|
21
|
+
return false;
|
|
22
|
+
if (!/^[A-Za-z0-9_-]+$/.test(v))
|
|
23
|
+
return false;
|
|
24
|
+
return /[0-9]/.test(v) && /[A-Za-z]/.test(v) && !/^[a-z]+(?:[-_][a-z]+)*$/.test(v);
|
|
25
|
+
}
|
|
26
|
+
const looksOpaque = (v) => BASE64URL.test(v) && /[A-Z]/.test(v) && /[a-z]/.test(v) && /[0-9]/.test(v);
|
|
27
|
+
export const fold = (at) => at.replace(/\[\d+\]/g, '[*]');
|
|
28
|
+
const kept = (at, rules) => rules.keep.some((k) => k === at || k === fold(at));
|
|
29
|
+
export function setAsideText(text, rules, counts) {
|
|
30
|
+
let out = text;
|
|
31
|
+
for (const re of rules.values) {
|
|
32
|
+
const global = new RegExp(re.source, re.flags.includes('g') ? re.flags : `${re.flags}g`);
|
|
33
|
+
out = out.replace(global, () => {
|
|
34
|
+
counts.custom += 1;
|
|
35
|
+
return ASIDE;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
out = out.replace(UUID_IN, () => {
|
|
39
|
+
counts.ids += 1;
|
|
40
|
+
return ID;
|
|
41
|
+
});
|
|
42
|
+
out = out.replace(ISO_IN, () => {
|
|
43
|
+
counts.times += 1;
|
|
44
|
+
return TIME;
|
|
45
|
+
});
|
|
46
|
+
out = out.replace(RELATIVE_IN, () => {
|
|
47
|
+
counts.times += 1;
|
|
48
|
+
return TIME;
|
|
49
|
+
});
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
function setAsideString(v, key, at, rules, counts) {
|
|
53
|
+
if (kept(at, rules))
|
|
54
|
+
return v;
|
|
55
|
+
if (rules.keys.some((re) => re.test(key))) {
|
|
56
|
+
counts.custom += 1;
|
|
57
|
+
return ASIDE;
|
|
58
|
+
}
|
|
59
|
+
if (rules.values.some((re) => re.test(v))) {
|
|
60
|
+
counts.custom += 1;
|
|
61
|
+
return ASIDE;
|
|
62
|
+
}
|
|
63
|
+
if (UUID.test(v) || ULID.test(v) || (ID_KEY.test(key) && looksGenerated(v))) {
|
|
64
|
+
counts.ids += 1;
|
|
65
|
+
return ID;
|
|
66
|
+
}
|
|
67
|
+
if (ISO.test(v)) {
|
|
68
|
+
counts.times += 1;
|
|
69
|
+
return TIME;
|
|
70
|
+
}
|
|
71
|
+
if ((OPAQUE_KEY.test(key) && v.length > 0) || looksOpaque(v)) {
|
|
72
|
+
counts.opaque += 1;
|
|
73
|
+
return OPAQUE;
|
|
74
|
+
}
|
|
75
|
+
return setAsideText(v, { ...rules, values: [] }, counts);
|
|
76
|
+
}
|
|
77
|
+
const stable = (v) => JSON.stringify(v);
|
|
78
|
+
export function setAsideJson(v, rules, counts, at = '$', key = '') {
|
|
79
|
+
if (typeof v === 'string')
|
|
80
|
+
return setAsideString(v, key, at, rules, counts);
|
|
81
|
+
if (typeof v === 'number') {
|
|
82
|
+
if (kept(at, rules))
|
|
83
|
+
return v;
|
|
84
|
+
if (rules.keys.some((re) => re.test(key))) {
|
|
85
|
+
counts.custom += 1;
|
|
86
|
+
return ASIDE;
|
|
87
|
+
}
|
|
88
|
+
if (ID_KEY.test(key) && Number.isInteger(v)) {
|
|
89
|
+
counts.ids += 1;
|
|
90
|
+
return ID;
|
|
91
|
+
}
|
|
92
|
+
if (TIME_KEY.test(key) && Number.isInteger(v) && v > 1_000_000_000) {
|
|
93
|
+
counts.times += 1;
|
|
94
|
+
return TIME;
|
|
95
|
+
}
|
|
96
|
+
return v;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(v)) {
|
|
99
|
+
const items = v.map((x, i) => setAsideJson(x, rules, counts, `${at}[${i}]`, key));
|
|
100
|
+
if (!rules.unordered)
|
|
101
|
+
return items;
|
|
102
|
+
const sorted = [...items].sort((a, b) => (stable(a) < stable(b) ? -1 : stable(a) > stable(b) ? 1 : 0));
|
|
103
|
+
if (sorted.some((x, i) => x !== items[i]))
|
|
104
|
+
counts.order += 1;
|
|
105
|
+
return sorted;
|
|
106
|
+
}
|
|
107
|
+
if (v && typeof v === 'object')
|
|
108
|
+
return Object.fromEntries(Object.keys(v)
|
|
109
|
+
.sort()
|
|
110
|
+
.map((k) => [k, setAsideJson(v[k], rules, counts, `${at}.${k}`, k)]));
|
|
111
|
+
return v;
|
|
112
|
+
}
|
|
113
|
+
export const nonZeroCounts = (c) => Object.fromEntries(Object.entries(c).filter(([, n]) => n > 0));
|
|
114
|
+
export function rulesOf(manifest, unordered = false) {
|
|
115
|
+
return {
|
|
116
|
+
keys: manifest.keys.map((r) => new RegExp(r)),
|
|
117
|
+
values: manifest.values.map((r) => new RegExp(r)),
|
|
118
|
+
keep: manifest.keep,
|
|
119
|
+
unordered,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type Verdict = 'same' | 'said' | 'unsaid' | 'new' | 'fails';
|
|
2
|
+
export interface VerdictParts {
|
|
3
|
+
onBase: boolean;
|
|
4
|
+
failsOnHead: boolean;
|
|
5
|
+
changed: boolean;
|
|
6
|
+
said: 'announced' | 'edited' | null;
|
|
7
|
+
}
|
|
8
|
+
export declare function verdictOf(p: VerdictParts): Verdict;
|
|
9
|
+
export interface Counts {
|
|
10
|
+
same: number;
|
|
11
|
+
said: number;
|
|
12
|
+
announced: number;
|
|
13
|
+
edited: number;
|
|
14
|
+
unsaid: number;
|
|
15
|
+
new: number;
|
|
16
|
+
fails: number;
|
|
17
|
+
failsOnBoth: number;
|
|
18
|
+
gone: number;
|
|
19
|
+
notRun: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function lineOf(c: Counts): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function verdictOf(p) {
|
|
2
|
+
if (p.failsOnHead)
|
|
3
|
+
return 'fails';
|
|
4
|
+
if (!p.onBase)
|
|
5
|
+
return 'new';
|
|
6
|
+
if (!p.changed)
|
|
7
|
+
return 'same';
|
|
8
|
+
return p.said ? 'said' : 'unsaid';
|
|
9
|
+
}
|
|
10
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
11
|
+
export function lineOf(c) {
|
|
12
|
+
const parts = [`${c.same} as on the base`];
|
|
13
|
+
if (c.new)
|
|
14
|
+
parts.push(`${c.new} new`);
|
|
15
|
+
if (c.said) {
|
|
16
|
+
const how = [c.announced ? `${c.announced} announced` : '', c.edited ? `${c.edited} edited` : '']
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
.join(', ');
|
|
19
|
+
parts.push(`${c.said} changed and said so${how ? ` (${how})` : ''}`);
|
|
20
|
+
}
|
|
21
|
+
if (c.unsaid)
|
|
22
|
+
parts.push(`${c.unsaid} changed without saying so`);
|
|
23
|
+
if (c.fails)
|
|
24
|
+
parts.push(`${plural(c.fails, 'fails', 'fail')} on the head${c.failsOnBoth ? ` (${c.failsOnBoth} on the base too)` : ''}`);
|
|
25
|
+
if (c.gone)
|
|
26
|
+
parts.push(`${c.gone} gone`);
|
|
27
|
+
if (c.notRun)
|
|
28
|
+
parts.push(`${c.notRun} not run`);
|
|
29
|
+
return parts.join(' · ');
|
|
30
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface AriaLine {
|
|
2
|
+
depth: number;
|
|
3
|
+
role: string;
|
|
4
|
+
name: string | null;
|
|
5
|
+
}
|
|
6
|
+
export declare const spacedName: (name: string) => string;
|
|
7
|
+
export declare const tidyName: (name: string) => string;
|
|
8
|
+
export declare function ariaLine(raw: string): AriaLine | null;
|