@kurvball/rehearse 1.2.1 → 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/README.md +6 -1
- package/dist/commands/command.d.ts +2 -1
- package/dist/commands/command.js +10 -1
- package/dist/commands/compare.js +8 -3
- package/dist/commands/run.js +5 -3
- package/dist/commands/stage.js +7 -3
- package/dist/compare/compare.d.ts +1 -0
- package/dist/compare/compare.js +33 -8
- package/dist/compare/index.d.ts +1 -0
- package/dist/compare/index.js +1 -0
- package/dist/git/checkout.js +8 -2
- package/dist/git/seed.d.ts +3 -0
- package/dist/git/seed.js +115 -0
- package/dist/kinds/flow/kind.js +25 -14
- package/dist/kinds/index.d.ts +1 -1
- package/dist/kinds/kind.d.ts +6 -0
- package/dist/manifest/load.js +1 -0
- package/dist/manifest/types.d.ts +2 -0
- package/dist/run/index.d.ts +2 -1
- package/dist/run/index.js +2 -1
- package/dist/run/parallel.d.ts +28 -0
- package/dist/run/parallel.js +140 -0
- package/dist/run/session.d.ts +3 -0
- package/dist/run/session.js +312 -171
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/service.d.ts +2 -1
- package/dist/services/service.js +41 -12
- package/dist/stage/api.d.ts +2 -0
- package/dist/stage/api.js +2 -2
- package/dist/stage/server.d.ts +2 -0
- package/dist/stage/server.js +4 -1
- package/llms.txt +3 -3
- package/package.json +1 -1
- package/schema/v1/manifest.schema.json +4 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Args, type ArgSpec } from '../args.ts';
|
|
2
2
|
import { type Manifest } from '../manifest/index.ts';
|
|
3
3
|
export interface Context {
|
|
4
4
|
cwd: string;
|
|
@@ -27,3 +27,4 @@ export declare const said: (json: unknown, text: string, code?: number) => Said;
|
|
|
27
27
|
export declare function manifestOf(ctx: Context): Manifest;
|
|
28
28
|
export declare function checkoutOf(m: Manifest, given: string | null, cwd: string): string;
|
|
29
29
|
export declare function columns(rows: readonly (readonly [string, string])[], indent?: string): string;
|
|
30
|
+
export declare function parallelOf(args: Args): number;
|
package/dist/commands/command.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { one } from '../args.js';
|
|
2
3
|
import { findManifest, loadManifest } from '../manifest/index.js';
|
|
3
4
|
import { topOf } from '../git/index.js';
|
|
4
|
-
import { RehearseError } from '../errors.js';
|
|
5
|
+
import { RehearseError, usage } from '../errors.js';
|
|
5
6
|
import { existsSync, statSync } from 'node:fs';
|
|
6
7
|
export const GLOBAL_VALUED = ['manifest'];
|
|
7
8
|
export const GLOBAL_BARE = ['json', 'help'];
|
|
@@ -27,3 +28,11 @@ export function columns(rows, indent = ' ') {
|
|
|
27
28
|
const width = Math.min(32, Math.max(0, ...rows.map(([a]) => a.length)));
|
|
28
29
|
return rows.map(([a, b]) => `${indent}${a.padEnd(width)} ${b}`.trimEnd()).join('\n');
|
|
29
30
|
}
|
|
31
|
+
export function parallelOf(args) {
|
|
32
|
+
const given = one(args, 'parallel');
|
|
33
|
+
if (given === null)
|
|
34
|
+
return 1;
|
|
35
|
+
if (!/^[1-9]\d*$/.test(given))
|
|
36
|
+
throw usage(`--parallel takes a whole number, 1 or more, not “${given}”.`);
|
|
37
|
+
return Number(given);
|
|
38
|
+
}
|
package/dist/commands/compare.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { checkoutOf, manifestOf, said } from './command.js';
|
|
2
|
+
import { checkoutOf, manifestOf, parallelOf, said } from './command.js';
|
|
3
3
|
import { many, one } from '../args.js';
|
|
4
4
|
import { compare as compareSides } from '../compare/index.js';
|
|
5
5
|
const VERDICT_WORDS = {
|
|
@@ -58,12 +58,16 @@ export function comparisonText(c) {
|
|
|
58
58
|
export const compare = {
|
|
59
59
|
name: 'compare',
|
|
60
60
|
summary: 'Runs scenarios on the base and on the head, compares them, and sorts each into a verdict.',
|
|
61
|
-
usage: "rehearse compare [<scenario>…] [--affected] [--base <ref|checkout>] [--head <ref|checkout>] [--announce <file>] [--said <scenario>]… [--world <name>] [--as <person>] [--real <stand-in>]… [--fresh] [--json]\n\nThe base defaults to the manifest's base branch; the head to this checkout as it is now.\nScenario ids may be globs: 'apps/api/**'. It exits 0 when nothing fails on the head or changed without saying so.",
|
|
62
|
-
spec: {
|
|
61
|
+
usage: "rehearse compare [<scenario>…] [--affected] [--base <ref|checkout>] [--head <ref|checkout>] [--announce <file>] [--said <scenario>]… [--world <name>] [--as <person>] [--real <stand-in>]… [--fresh] [--parallel <n>] [--json]\n\nThe base defaults to the manifest's base branch; the head to this checkout as it is now.\nScenario ids may be globs: 'apps/api/**'. It exits 0 when nothing fails on the head or changed without saying so.",
|
|
62
|
+
spec: {
|
|
63
|
+
valued: ['base', 'head', 'announce', 'said', 'world', 'as', 'real', 'parallel'],
|
|
64
|
+
bare: ['affected', 'fresh'],
|
|
65
|
+
},
|
|
63
66
|
async run(args, ctx) {
|
|
64
67
|
const m = manifestOf(ctx);
|
|
65
68
|
const repo = checkoutOf(m, null, ctx.cwd);
|
|
66
69
|
const announce = one(args, 'announce');
|
|
70
|
+
const parallel = parallelOf(args);
|
|
67
71
|
const c = await compareSides(m, {
|
|
68
72
|
repo,
|
|
69
73
|
cwd: ctx.cwd,
|
|
@@ -78,6 +82,7 @@ export const compare = {
|
|
|
78
82
|
as: one(args, 'as'),
|
|
79
83
|
real: new Set(many(args, 'real')),
|
|
80
84
|
progress: ctx.progress,
|
|
85
|
+
parallel,
|
|
81
86
|
});
|
|
82
87
|
return said(c, comparisonText(c), c.ok ? 0 : 1);
|
|
83
88
|
},
|
package/dist/commands/run.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { runnerOf } from '../kinds/index.js';
|
|
2
|
-
import { checkoutOf, manifestOf, said } from './command.js';
|
|
2
|
+
import { checkoutOf, manifestOf, parallelOf, said } from './command.js';
|
|
3
3
|
import { many, one } from '../args.js';
|
|
4
4
|
import { RehearseError, usage } from '../errors.js';
|
|
5
5
|
import { readScenarios, refOf } from '../scenarios/index.js';
|
|
@@ -25,12 +25,13 @@ export function observationText(o) {
|
|
|
25
25
|
export const run = {
|
|
26
26
|
name: 'run',
|
|
27
27
|
summary: 'Runs one scenario on a checkout and prints what it observed.',
|
|
28
|
-
usage: 'rehearse run <scenario> [--on <checkout|ref>] [--world <name>] [--as <person>] [--real <stand-in>]… [--keep] [--json]',
|
|
29
|
-
spec: { valued: ['on', 'world', 'as', 'real'], bare: ['keep'] },
|
|
28
|
+
usage: 'rehearse run <scenario> [--on <checkout|ref>] [--world <name>] [--as <person>] [--real <stand-in>]… [--keep] [--parallel <n>] [--json]',
|
|
29
|
+
spec: { valued: ['on', 'world', 'as', 'real', 'parallel'], bare: ['keep'] },
|
|
30
30
|
async run(args, ctx) {
|
|
31
31
|
const id = args.positional[0];
|
|
32
32
|
if (!id)
|
|
33
33
|
throw usage('Name the scenario to run: rehearse list shows their ids.');
|
|
34
|
+
const parallel = parallelOf(args);
|
|
34
35
|
const m = manifestOf(ctx);
|
|
35
36
|
const repo = checkoutOf(m, null, ctx.cwd);
|
|
36
37
|
const on = one(args, 'on');
|
|
@@ -51,6 +52,7 @@ export const run = {
|
|
|
51
52
|
keepUp: args.flags.has('keep'),
|
|
52
53
|
progress: ctx.progress,
|
|
53
54
|
ref: target.ref,
|
|
55
|
+
parallel,
|
|
54
56
|
});
|
|
55
57
|
let o = side.observations.get(s.id);
|
|
56
58
|
if (!o) {
|
package/dist/commands/stage.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
1
2
|
import { checkoutOf, manifestOf, said } from './command.js';
|
|
2
|
-
import { one } from '../args.js';
|
|
3
|
+
import { many, one } from '../args.js';
|
|
3
4
|
import { errorText, usage } from '../errors.js';
|
|
4
5
|
import { startStage } from '../stage/index.js';
|
|
5
6
|
export const DEFAULT_STAGE_PORT = 4400;
|
|
@@ -14,11 +15,12 @@ export function portOf(given) {
|
|
|
14
15
|
export const stage = {
|
|
15
16
|
name: 'stage',
|
|
16
17
|
summary: "Serves the stage: every scenario on one page, in Base, Head and Diff, with Works, Doesn't and a note.",
|
|
17
|
-
usage: 'rehearse stage [--base <ref|checkout>] [--head <ref|checkout>] [--port <port>]
|
|
18
|
-
spec: { valued: ['base', 'head', 'port'], bare: [] },
|
|
18
|
+
usage: 'rehearse stage [--base <ref|checkout>] [--head <ref|checkout>] [--port <port>] [--announce <file>] [--said <scenario>]…\n\nIt runs until you stop it (Ctrl-C), and stops the services it brought up.\nCompare on the stage reads the announcement as rehearse compare does.',
|
|
19
|
+
spec: { valued: ['base', 'head', 'port', 'announce', 'said'], bare: [] },
|
|
19
20
|
async run(args, ctx) {
|
|
20
21
|
const m = manifestOf(ctx);
|
|
21
22
|
const { port, anyPort } = portOf(one(args, 'port'));
|
|
23
|
+
const announce = one(args, 'announce');
|
|
22
24
|
const s = await startStage({
|
|
23
25
|
manifest: m,
|
|
24
26
|
repo: checkoutOf(m, null, ctx.cwd),
|
|
@@ -27,6 +29,8 @@ export const stage = {
|
|
|
27
29
|
base: one(args, 'base'),
|
|
28
30
|
port,
|
|
29
31
|
anyPort,
|
|
32
|
+
announce: announce ? path.resolve(ctx.cwd, announce) : null,
|
|
33
|
+
said: many(args, 'said'),
|
|
30
34
|
progress: ctx.progress,
|
|
31
35
|
});
|
|
32
36
|
process.stdout.write(ctx.json
|
package/dist/compare/compare.js
CHANGED
|
@@ -5,9 +5,9 @@ import { affected } from '../affected/index.js';
|
|
|
5
5
|
import { RehearseError, errorText } from '../errors.js';
|
|
6
6
|
import { checkoutFor, infoOf, commitOf, gitOr } from '../git/index.js';
|
|
7
7
|
import { runnerOf } from '../kinds/index.js';
|
|
8
|
-
import { cached, cacheKeyOf, groupsOf, keep,
|
|
8
|
+
import { cached, cacheKeyOf, groupsOf, keep, runSideSharing, slotsFor, } from '../run/index.js';
|
|
9
9
|
import { readScenarios, refOf, globToRegExp, } from '../scenarios/index.js';
|
|
10
|
-
import { stateDir } from '../services/index.js';
|
|
10
|
+
import { runningServices, stateDir } from '../services/index.js';
|
|
11
11
|
import { announcementFor, readAnnouncement } from './announce.js';
|
|
12
12
|
import { nonZeroCounts, noCounts, rulesOf } from './setaside.js';
|
|
13
13
|
import { lineOf, verdictOf } from './verdict.js';
|
|
@@ -76,9 +76,18 @@ async function fromCache(m, info, scenarios, o, groups) {
|
|
|
76
76
|
}
|
|
77
77
|
return cachedWholeGroupsOnly(found, scenarios, groups);
|
|
78
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
|
+
}
|
|
79
86
|
const latestComparisonFile = (m, everyScenario) => path.join(stateDir(m.dir), 'compare', everyScenario ? 'latest.json' : 'latest-partial.json');
|
|
80
87
|
export async function compare(m, o) {
|
|
81
88
|
const begun = Date.now();
|
|
89
|
+
const parallel = o.parallel ?? 1;
|
|
90
|
+
const slots = slotsFor(parallel);
|
|
82
91
|
const session = (ref) => ({
|
|
83
92
|
world: o.world,
|
|
84
93
|
as: o.as,
|
|
@@ -86,6 +95,7 @@ export async function compare(m, o) {
|
|
|
86
95
|
keepUp: false,
|
|
87
96
|
progress: o.progress,
|
|
88
97
|
ref,
|
|
98
|
+
parallel,
|
|
89
99
|
});
|
|
90
100
|
const head = o.head
|
|
91
101
|
? await checkoutFor(m, o.repo, o.head, o.progress, [], o.cwd)
|
|
@@ -132,19 +142,34 @@ export async function compare(m, o) {
|
|
|
132
142
|
const hits = await fromCache(m, baseInfo, baseRunsOnlyWhatTheHeadStillHas, o, baseGroups);
|
|
133
143
|
if (hits.size)
|
|
134
144
|
o.progress(`${hits.size} base observation${hits.size === 1 ? '' : 's'} read from the cache (${baseInfo.commit?.slice(0, 12)}).`);
|
|
135
|
-
const
|
|
136
|
-
|
|
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;
|
|
137
164
|
return failedBase(m, baseRun.checkout, infoOf(m, head.path, head.ref), baseRun.broke.step, baseRun.broke.says, begun, everyScenario, [
|
|
138
165
|
...baseRead.refused.map((r) => ({ side: 'base', ...r })),
|
|
139
166
|
...headRead.refused.map((r) => ({ side: 'head', ...r })),
|
|
140
167
|
]);
|
|
168
|
+
}
|
|
141
169
|
const baseObs = new Map([...hits, ...baseRun.observations]);
|
|
142
170
|
for (const ob of baseRun.observations.values())
|
|
143
171
|
keep(m, ob);
|
|
144
|
-
const headInfo = infoOf(m, head.path, head.ref);
|
|
145
|
-
const headGroups = await groupsOf(m, headScenarios, o.world);
|
|
146
|
-
const headHits = await fromCache(m, headInfo, headScenarios, o, headGroups);
|
|
147
|
-
const headRun = await runSide(m, head.path, headScenarios.filter((s) => !headHits.has(s.id)), { ...session(head.ref), groups: headGroups });
|
|
172
|
+
const { info: headInfo, hits: headHits, run: headRun, } = await (headAlongside ?? runHead(infoOf(m, head.path, head.ref)));
|
|
148
173
|
const headObs = new Map([...headHits, ...headRun.observations]);
|
|
149
174
|
for (const ob of headRun.observations.values())
|
|
150
175
|
keep(m, ob);
|
package/dist/compare/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { readAnnouncement } from './announce.ts';
|
|
1
2
|
export { changedFiles, compare, type CompareOptions, type Compared, type Comparison } from './compare.ts';
|
|
2
3
|
export { clip, jsonDifferences, lineHunks, textDifferences, type Difference } from './diff.ts';
|
|
3
4
|
export { noCounts, noRules, setAsideJson, setAsideText, type Counts as AsideCounts, type Rules, } from './setaside.ts';
|
package/dist/compare/index.js
CHANGED
package/dist/git/checkout.js
CHANGED
|
@@ -4,6 +4,7 @@ import { RehearseError } from '../errors.js';
|
|
|
4
4
|
import { sh, tail } from '../exec.js';
|
|
5
5
|
import { stateDir } from '../services/index.js';
|
|
6
6
|
import { commitOf, git, gitOr, topOf } from './git.js';
|
|
7
|
+
import { preparedMark, seedDependencies, unseed } from './seed.js';
|
|
7
8
|
export const checkoutsDir = (m) => path.join(stateDir(m.dir), 'checkouts');
|
|
8
9
|
export function dirtyOf(m, checkout) {
|
|
9
10
|
const status = gitOr(checkout, ['status', '--porcelain', '--untracked-files=all']);
|
|
@@ -31,7 +32,6 @@ export function overlay(m, checkout) {
|
|
|
31
32
|
cpSync(o.from, to, { recursive: true });
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
const preparedMark = (dir) => `${dir}.prepared`;
|
|
35
35
|
const NAMED_AS_A_FOLDER = /^(?:\.{1,2}(?:\/|$)|\/|~\/)/;
|
|
36
36
|
export async function checkoutFor(m, repo, given, progress, keep = [], cwd = process.cwd()) {
|
|
37
37
|
if (NAMED_AS_A_FOLDER.test(given)) {
|
|
@@ -51,8 +51,14 @@ export async function checkoutFor(m, repo, given, progress, keep = [], cwd = pro
|
|
|
51
51
|
git(repo, ['worktree', 'add', '--detach', dir, commit]);
|
|
52
52
|
}
|
|
53
53
|
if (m.prepare && !existsSync(preparedMark(dir))) {
|
|
54
|
+
const seeded = m.seed ? seedDependencies(dir, progress) : [];
|
|
54
55
|
progress(`Preparing ${dir}: ${m.prepare}`);
|
|
55
|
-
|
|
56
|
+
let ran = await sh(m.prepare, { cwd: dir, timeoutMs: 30 * 60_000 });
|
|
57
|
+
if (ran.code !== 0 && seeded.length > 0) {
|
|
58
|
+
progress(`Preparing ${dir} again, without the seeded dependencies: ${m.prepare}`);
|
|
59
|
+
unseed(seeded);
|
|
60
|
+
ran = await sh(m.prepare, { cwd: dir, timeoutMs: 30 * 60_000 });
|
|
61
|
+
}
|
|
56
62
|
if (ran.code !== 0)
|
|
57
63
|
throw new RehearseError('prepare', `Preparing ${given} failed (${m.prepare}): ${tail(ran.stderr || ran.stdout) || `exit ${ran.code}`}`);
|
|
58
64
|
writeFileSync(preparedMark(dir), `${new Date().toISOString()}\n`);
|
package/dist/git/seed.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { constants, copyFileSync, existsSync, linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, rmSync, statSync, symlinkSync, writeFileSync, } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { gitOr } from './git.js';
|
|
5
|
+
const LOCKFILES = [
|
|
6
|
+
'pnpm-lock.yaml',
|
|
7
|
+
'package-lock.json',
|
|
8
|
+
'npm-shrinkwrap.json',
|
|
9
|
+
'yarn.lock',
|
|
10
|
+
'bun.lock',
|
|
11
|
+
'bun.lockb',
|
|
12
|
+
];
|
|
13
|
+
const CACHES_REBUILT_ON_DEMAND = new Set(['.cache', '.vite']);
|
|
14
|
+
const SMALL_ENOUGH_TO_REWRITE = 1_000_000;
|
|
15
|
+
export const preparedMark = (dir) => `${dir}.prepared`;
|
|
16
|
+
function lockfilesOf(dir) {
|
|
17
|
+
const hash = createHash('sha256');
|
|
18
|
+
let found = false;
|
|
19
|
+
for (const name of LOCKFILES) {
|
|
20
|
+
const file = path.join(dir, name);
|
|
21
|
+
if (!existsSync(file))
|
|
22
|
+
continue;
|
|
23
|
+
found = true;
|
|
24
|
+
hash.update(`${name}\n`).update(readFileSync(file));
|
|
25
|
+
}
|
|
26
|
+
return found ? hash.digest('hex') : null;
|
|
27
|
+
}
|
|
28
|
+
function newestPreparedWithTheSameLockfile(dir) {
|
|
29
|
+
const wanted = lockfilesOf(dir);
|
|
30
|
+
if (wanted === null)
|
|
31
|
+
return null;
|
|
32
|
+
const root = path.dirname(dir);
|
|
33
|
+
const prepared = readdirSync(root, { withFileTypes: true })
|
|
34
|
+
.filter((d) => d.isDirectory() && path.join(root, d.name) !== dir)
|
|
35
|
+
.map((d) => path.join(root, d.name))
|
|
36
|
+
.filter((other) => existsSync(preparedMark(other)))
|
|
37
|
+
.sort((a, b) => statSync(b).mtimeMs - statSync(a).mtimeMs);
|
|
38
|
+
return prepared.find((other) => lockfilesOf(other) === wanted) ?? null;
|
|
39
|
+
}
|
|
40
|
+
function packageFolders(dir) {
|
|
41
|
+
const listed = gitOr(dir, ['ls-files', '-z', '--', 'package.json', '*/package.json']) ?? '';
|
|
42
|
+
return [
|
|
43
|
+
...new Set(listed
|
|
44
|
+
.split('\0')
|
|
45
|
+
.filter((f) => f && !f.split('/').includes('node_modules'))
|
|
46
|
+
.map((f) => path.posix.dirname(f))),
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
const placedAgain = (text, from, to) => text.split(from).join(to);
|
|
50
|
+
function copyLink(from, to, roots) {
|
|
51
|
+
const target = readlinkSync(from);
|
|
52
|
+
const inside = path.isAbsolute(target) && target.startsWith(`${roots.from}${path.sep}`);
|
|
53
|
+
symlinkSync(inside ? path.join(roots.to, path.relative(roots.from, target)) : target, to);
|
|
54
|
+
}
|
|
55
|
+
function copyFileOver(from, to, roots, mayNameTheCheckout) {
|
|
56
|
+
const seen = lstatSync(from);
|
|
57
|
+
if (mayNameTheCheckout && seen.size <= SMALL_ENOUGH_TO_REWRITE) {
|
|
58
|
+
const text = readFileSync(from, 'utf8');
|
|
59
|
+
if (text.includes(roots.from)) {
|
|
60
|
+
writeFileSync(to, placedAgain(text, roots.from, roots.to), { mode: seen.mode & 0o7777 });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (seen.nlink > 1)
|
|
65
|
+
try {
|
|
66
|
+
linkSync(from, to);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
rmSync(to, { force: true });
|
|
71
|
+
}
|
|
72
|
+
copyFileSync(from, to, constants.COPYFILE_FICLONE);
|
|
73
|
+
}
|
|
74
|
+
function copyTree(from, to, roots) {
|
|
75
|
+
mkdirSync(to);
|
|
76
|
+
const isBin = path.basename(from) === '.bin';
|
|
77
|
+
const isModules = path.basename(from) === 'node_modules';
|
|
78
|
+
for (const entry of readdirSync(from, { withFileTypes: true })) {
|
|
79
|
+
if (isModules && CACHES_REBUILT_ON_DEMAND.has(entry.name))
|
|
80
|
+
continue;
|
|
81
|
+
const [a, b] = [path.join(from, entry.name), path.join(to, entry.name)];
|
|
82
|
+
if (entry.isSymbolicLink())
|
|
83
|
+
copyLink(a, b, roots);
|
|
84
|
+
else if (entry.isDirectory())
|
|
85
|
+
copyTree(a, b, roots);
|
|
86
|
+
else if (entry.isFile())
|
|
87
|
+
copyFileOver(a, b, roots, isBin || (isModules && entry.name.startsWith('.')));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export function seedDependencies(dir, progress) {
|
|
91
|
+
const from = newestPreparedWithTheSameLockfile(dir);
|
|
92
|
+
if (from === null)
|
|
93
|
+
return [];
|
|
94
|
+
const seeded = [];
|
|
95
|
+
for (const folder of packageFolders(dir)) {
|
|
96
|
+
const source = path.join(from, folder, 'node_modules');
|
|
97
|
+
const target = path.join(dir, folder, 'node_modules');
|
|
98
|
+
if (!existsSync(source) || existsSync(target) || !existsSync(path.dirname(target)))
|
|
99
|
+
continue;
|
|
100
|
+
try {
|
|
101
|
+
copyTree(source, target, { from, to: dir });
|
|
102
|
+
seeded.push(target);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
rmSync(target, { recursive: true, force: true });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (seeded.length > 0)
|
|
109
|
+
progress(`Seeded ${seeded.length} node_modules folder${seeded.length === 1 ? '' : 's'} from ${from}, prepared with the same lockfile.`);
|
|
110
|
+
return seeded;
|
|
111
|
+
}
|
|
112
|
+
export function unseed(seeded) {
|
|
113
|
+
for (const dir of seeded)
|
|
114
|
+
rmSync(dir, { recursive: true, force: true });
|
|
115
|
+
}
|
package/dist/kinds/flow/kind.js
CHANGED
|
@@ -271,27 +271,35 @@ async function throughBrowser(s, ctx, browser, url) {
|
|
|
271
271
|
await context.close();
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
|
-
async function
|
|
274
|
+
async function upAgainWhereTheWorldStarts(ctx, running) {
|
|
275
275
|
const vars = { ...ctx.variables, ...(ctx.world && { world: ctx.world }) };
|
|
276
276
|
try {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
277
|
+
const why = await restart(ctx.manifest, running, async () => {
|
|
278
|
+
if (ctx.world)
|
|
279
|
+
await applyWorld(ctx.manifest, ctx.world, 'before', ctx.checkout, vars);
|
|
280
|
+
});
|
|
280
281
|
if (why)
|
|
281
|
-
return broken('driver', why);
|
|
282
|
+
return { stopped: broken('driver', why) };
|
|
282
283
|
if (ctx.world)
|
|
283
284
|
await applyWorld(ctx.manifest, ctx.world, 'add', ctx.checkout, vars);
|
|
284
|
-
return null;
|
|
285
285
|
}
|
|
286
286
|
catch (error) {
|
|
287
|
-
return broken('world', errorText(error));
|
|
287
|
+
return { stopped: broken('world', errorText(error)) };
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
return { signedInAgain: { ...ctx, ...(await ctx.signInAgain()) } };
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
return { stopped: broken('signIn', scrub(errorText(error), ctx.tokens)) };
|
|
288
294
|
}
|
|
289
295
|
}
|
|
296
|
+
const cantBeBroughtUpAfresh = (service, afterAnotherFlow) => `${service} can't be brought up afresh (it needs a down command, and an up that hands over to a daemon), so this flow started ${afterAnotherFlow ? 'where the last one left the app' : 'with the app as it found it'}.`;
|
|
290
297
|
registerRunner({
|
|
291
298
|
kind: 'flow',
|
|
292
|
-
version: 'flow/
|
|
299
|
+
version: 'flow/3',
|
|
293
300
|
services: (s) => (s.service ? [s.service] : []),
|
|
294
|
-
async run(scenarios,
|
|
301
|
+
async run(scenarios, asGiven) {
|
|
302
|
+
let ctx = asGiven;
|
|
295
303
|
const out = new Map();
|
|
296
304
|
let browser = null;
|
|
297
305
|
const pieces = new Map();
|
|
@@ -302,16 +310,19 @@ registerRunner({
|
|
|
302
310
|
const svc = s.service ? ctx.manifest.services[s.service] : undefined;
|
|
303
311
|
if (svc?.drive) {
|
|
304
312
|
const running = ctx.running.find((r) => r.name === svc.name);
|
|
313
|
+
const afterAnotherFlow = driven.has(svc.name);
|
|
314
|
+
const freshAlready = !afterAnotherFlow && ctx.broughtUpAndUnused.has(svc.name);
|
|
305
315
|
let shared = null;
|
|
306
|
-
if (
|
|
316
|
+
if (running && !freshAlready) {
|
|
307
317
|
if (!restartable(running))
|
|
308
|
-
shared =
|
|
318
|
+
shared = cantBeBroughtUpAfresh(svc.name, afterAnotherFlow);
|
|
309
319
|
else {
|
|
310
|
-
const
|
|
311
|
-
if (stopped) {
|
|
312
|
-
out.set(s.id, stopped);
|
|
320
|
+
const again = await upAgainWhereTheWorldStarts(ctx, running);
|
|
321
|
+
if ('stopped' in again) {
|
|
322
|
+
out.set(s.id, again.stopped);
|
|
313
323
|
continue;
|
|
314
324
|
}
|
|
325
|
+
ctx = again.signedInAgain;
|
|
315
326
|
}
|
|
316
327
|
}
|
|
317
328
|
driven.add(svc.name);
|
package/dist/kinds/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { broken, loadKinds, runnerOf, type Artifact, type Broke, type Failure, type KindRunner, type Ran, type StandinUse, } from './kind.ts';
|
|
1
|
+
export { broken, loadKinds, runnerOf, type Artifact, type Broke, type Failure, type KindRunner, type Ran, type RunContext, type SignedInAgain, type StandinUse, } from './kind.ts';
|
|
2
2
|
export { callDefinition } from './call/definition.ts';
|
|
3
3
|
export { parseHurl, Refusal } from './call/hurl.ts';
|
|
4
4
|
export { sendFile, type Fetcher } from './call/send.ts';
|
package/dist/kinds/kind.d.ts
CHANGED
|
@@ -32,6 +32,10 @@ export interface StandinUse {
|
|
|
32
32
|
fidelity: string;
|
|
33
33
|
real: boolean;
|
|
34
34
|
}
|
|
35
|
+
export interface SignedInAgain {
|
|
36
|
+
tokens: Record<string, string>;
|
|
37
|
+
variables: Record<string, string>;
|
|
38
|
+
}
|
|
35
39
|
export interface RunContext {
|
|
36
40
|
manifest: Manifest;
|
|
37
41
|
checkout: string;
|
|
@@ -40,6 +44,8 @@ export interface RunContext {
|
|
|
40
44
|
tokens: Record<string, string>;
|
|
41
45
|
variables: Record<string, string>;
|
|
42
46
|
running: Running[];
|
|
47
|
+
broughtUpAndUnused: ReadonlySet<string>;
|
|
48
|
+
signInAgain(): Promise<SignedInAgain>;
|
|
43
49
|
keep: string;
|
|
44
50
|
progress(line: string): void;
|
|
45
51
|
}
|
package/dist/manifest/load.js
CHANGED
|
@@ -195,6 +195,7 @@ export function manifestFrom(text, file) {
|
|
|
195
195
|
base: raw.base ?? 'main',
|
|
196
196
|
checkout: raw.checkout ? path.resolve(dir, raw.checkout) : null,
|
|
197
197
|
prepare: raw.prepare ?? null,
|
|
198
|
+
seed: raw.seed ?? true,
|
|
198
199
|
overlay: (raw.overlay ?? []).map((o) => ({ from: path.resolve(dir, o.from), to: o.to })),
|
|
199
200
|
services,
|
|
200
201
|
signIn,
|
package/dist/manifest/types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export interface RawManifest {
|
|
|
3
3
|
base?: string;
|
|
4
4
|
checkout?: string;
|
|
5
5
|
prepare?: string;
|
|
6
|
+
seed?: boolean;
|
|
6
7
|
overlay?: {
|
|
7
8
|
from: string;
|
|
8
9
|
to: string;
|
|
@@ -222,6 +223,7 @@ export interface Manifest {
|
|
|
222
223
|
base: string;
|
|
223
224
|
checkout: string | null;
|
|
224
225
|
prepare: string | null;
|
|
226
|
+
seed: boolean;
|
|
225
227
|
overlay: {
|
|
226
228
|
from: string;
|
|
227
229
|
to: string;
|
package/dist/run/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { cached, cacheKeyOf, groupsOf, keep, type KeyParts } from './cache.ts';
|
|
2
2
|
export type { CheckoutInfo, Observation } from './observation.ts';
|
|
3
|
-
export {
|
|
3
|
+
export { slotsFor, type Slots } from './parallel.ts';
|
|
4
|
+
export { applyWorld, placedIn, runSide, runSideSharing, type NotRun, type SessionOptions, type SideRun, } from './session.ts';
|
|
4
5
|
export { baseVars } from './vars.ts';
|
package/dist/run/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { cached, cacheKeyOf, groupsOf, keep } from './cache.js';
|
|
2
|
-
export {
|
|
2
|
+
export { slotsFor } from './parallel.js';
|
|
3
|
+
export { applyWorld, placedIn, runSide, runSideSharing, } from './session.js';
|
|
3
4
|
export { baseVars } from './vars.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { KindRunner } from '../kinds/index.ts';
|
|
2
|
+
import type { Kind, Manifest } from '../manifest/index.ts';
|
|
3
|
+
import type { Scenario } from '../scenarios/index.ts';
|
|
4
|
+
export interface Slots {
|
|
5
|
+
take(): Promise<() => void>;
|
|
6
|
+
}
|
|
7
|
+
export declare function slotsFor(n: number): Slots;
|
|
8
|
+
export interface Unit {
|
|
9
|
+
at: number;
|
|
10
|
+
world: string | null;
|
|
11
|
+
members: Scenario[];
|
|
12
|
+
runners: Map<Kind, KindRunner>;
|
|
13
|
+
needed: Set<string>;
|
|
14
|
+
vouched: boolean;
|
|
15
|
+
holds: ReadonlySet<string>;
|
|
16
|
+
holdsTheWholeCheckout: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface WorldToSplit {
|
|
19
|
+
at: number;
|
|
20
|
+
world: string | null;
|
|
21
|
+
group: readonly Scenario[];
|
|
22
|
+
runners: ReadonlyMap<Kind, KindRunner>;
|
|
23
|
+
needed: ReadonlySet<string>;
|
|
24
|
+
vouched: boolean;
|
|
25
|
+
servicesOf(s: Scenario): string[];
|
|
26
|
+
}
|
|
27
|
+
export declare function unitsOf(m: Manifest, w: WorldToSplit): Unit[];
|
|
28
|
+
export declare function inTurn<T>(units: readonly Unit[], slots: Slots, work: (u: Unit) => Promise<T>, skip: (u: Unit) => boolean): Promise<(T | null)[]>;
|