@kurvball/rehearse 1.14.0 → 1.16.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/dist/commands/announce.js +2 -2
- package/dist/commands/clean.js +6 -3
- package/dist/commands/compare.js +6 -1
- package/dist/commands/drive.js +49 -13
- package/dist/commands/init.js +1 -1
- package/dist/commands/run.js +8 -4
- package/dist/commands/services.d.ts +2 -0
- package/dist/commands/services.js +9 -1
- package/dist/commands/stage.js +18 -2
- package/dist/commands/up.js +15 -5
- package/dist/compare/compare.d.ts +2 -0
- package/dist/compare/compare.js +19 -10
- package/dist/detect/detect.js +4 -0
- package/dist/detect/index.d.ts +1 -0
- package/dist/detect/index.js +1 -0
- package/dist/detect/keys.d.ts +16 -0
- package/dist/detect/keys.js +141 -0
- package/dist/detect/write.d.ts +2 -0
- package/dist/detect/write.js +20 -1
- package/dist/drive/open.js +20 -9
- package/dist/drive/state.d.ts +1 -0
- package/dist/git/checkout.d.ts +6 -0
- package/dist/git/checkout.js +28 -19
- package/dist/git/index.d.ts +3 -2
- package/dist/git/index.js +3 -2
- package/dist/kinds/flow/kind.js +2 -2
- package/dist/manifest/index.d.ts +2 -1
- package/dist/manifest/index.js +1 -0
- package/dist/manifest/load.js +21 -0
- package/dist/manifest/order.d.ts +8 -0
- package/dist/manifest/order.js +53 -0
- package/dist/manifest/types.d.ts +15 -0
- package/dist/repositories/copies.d.ts +16 -0
- package/dist/repositories/copies.js +132 -0
- package/dist/repositories/index.d.ts +1 -0
- package/dist/repositories/index.js +1 -0
- package/dist/run/cache.d.ts +2 -1
- package/dist/run/cache.js +6 -3
- package/dist/run/index.d.ts +1 -1
- package/dist/run/index.js +1 -0
- package/dist/run/observation.d.ts +4 -0
- package/dist/run/observation.js +5 -1
- package/dist/run/session.d.ts +3 -1
- package/dist/run/session.js +32 -20
- package/dist/services/index.d.ts +2 -2
- package/dist/services/index.js +2 -2
- package/dist/services/registry.d.ts +1 -0
- package/dist/services/service.d.ts +4 -0
- package/dist/services/service.js +24 -8
- package/dist/stage/api.d.ts +2 -0
- package/dist/stage/api.js +4 -0
- package/dist/stage/sending.d.ts +2 -1
- package/dist/stage/sending.js +12 -5
- package/dist/stage/server.d.ts +2 -0
- package/dist/stage/server.js +14 -1
- package/llms.txt +5 -5
- package/package.json +2 -2
- package/schema/v1/common.schema.json +22 -0
- package/schema/v1/init.schema.json +2 -1
- package/schema/v1/manifest.schema.json +30 -0
- package/schema/v1/samples/manifest.yaml +8 -0
- package/schema/v1/services.schema.json +8 -0
- package/skill/rehearse/SKILL.md +4 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, renameSync, rmSync, statSync, utimesSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { RehearseError, errorText, usage } from '../errors.js';
|
|
4
|
+
import { commitOf, folderNamed, git, gitOr, isDirty, preparedMark, preparedOnce, topOf, } from '../git/index.js';
|
|
5
|
+
import { checkoutKey, runningServices, stateDir } from '../services/index.js';
|
|
6
|
+
export const repositoriesDir = (m) => path.join(stateDir(m.dir), 'repositories');
|
|
7
|
+
const cloneOf = (m, name) => path.join(repositoriesDir(m), `${name}.git`);
|
|
8
|
+
const copiesOf = (m, name) => path.join(repositoriesDir(m), name);
|
|
9
|
+
const WITH_CREDENTIALS = /(?<=:\/\/)[^/@\s]+@/g;
|
|
10
|
+
const withoutCredentials = (text) => text.replace(WITH_CREDENTIALS, '');
|
|
11
|
+
const usedHere = new Set();
|
|
12
|
+
function cloned(m, r, progress) {
|
|
13
|
+
const clone = cloneOf(m, r.name);
|
|
14
|
+
const from = withoutCredentials(r.from);
|
|
15
|
+
if (existsSync(clone)) {
|
|
16
|
+
if (gitOr(clone, ['config', '--get', 'remote.origin.url']) !== r.from) {
|
|
17
|
+
progress(`${r.name} now comes from ${from}.`);
|
|
18
|
+
git(clone, ['remote', 'set-url', 'origin', r.from]);
|
|
19
|
+
}
|
|
20
|
+
const fetched = gitOr(clone, [
|
|
21
|
+
'fetch',
|
|
22
|
+
'--quiet',
|
|
23
|
+
'--prune',
|
|
24
|
+
'origin',
|
|
25
|
+
'+refs/heads/*:refs/heads/*',
|
|
26
|
+
'+refs/tags/*:refs/tags/*',
|
|
27
|
+
]);
|
|
28
|
+
if (fetched === null)
|
|
29
|
+
progress(`Rehearse couldn't fetch ${r.name} from ${from}, so it uses what it fetched before.`);
|
|
30
|
+
return clone;
|
|
31
|
+
}
|
|
32
|
+
mkdirSync(repositoriesDir(m), { recursive: true });
|
|
33
|
+
progress(`Cloning ${r.name} from ${from}`);
|
|
34
|
+
const into = `${clone}.${process.pid}.cloning`;
|
|
35
|
+
rmSync(into, { recursive: true, force: true });
|
|
36
|
+
try {
|
|
37
|
+
git(repositoriesDir(m), ['clone', '--bare', '--quiet', r.from, into]);
|
|
38
|
+
renameSync(into, clone);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
rmSync(into, { recursive: true, force: true });
|
|
42
|
+
if (!existsSync(clone))
|
|
43
|
+
throw new RehearseError('git', withoutCredentials(`Rehearse can't clone ${r.name} from ${r.from}: ${errorText(error)}`));
|
|
44
|
+
}
|
|
45
|
+
return clone;
|
|
46
|
+
}
|
|
47
|
+
const baseOf = (clone, r) => r.base ?? gitOr(clone, ['symbolic-ref', '--short', 'HEAD']) ?? 'main';
|
|
48
|
+
const dirtyIn = (folder) => {
|
|
49
|
+
const status = gitOr(folder, ['status', '--porcelain', '--untracked-files=all']);
|
|
50
|
+
return status === null || status !== '';
|
|
51
|
+
};
|
|
52
|
+
export async function copyOf(m, name, given, forSet, progress, cwd = process.cwd()) {
|
|
53
|
+
const r = m.repositories[name];
|
|
54
|
+
if (!r)
|
|
55
|
+
throw new RehearseError('usage', `There is no repository “${name}” in the manifest.`, { exit: 2 });
|
|
56
|
+
const folder = given === null ? null : folderNamed(given, cwd);
|
|
57
|
+
if (folder !== null)
|
|
58
|
+
return { path: folder, ref: null, commit: commitOf(folder), dirty: dirtyIn(folder) };
|
|
59
|
+
const clone = cloned(m, r, progress);
|
|
60
|
+
const ref = given ?? baseOf(clone, r);
|
|
61
|
+
const commit = commitOf(clone, ref);
|
|
62
|
+
if (commit === null)
|
|
63
|
+
throw new RehearseError('git', `${ref} isn't a branch, tag or commit of ${name} (${withoutCredentials(r.from)}).${r.base === null && given === null ? ' Say its base in rehearse.yaml.' : ''}`);
|
|
64
|
+
const dir = path.join(copiesOf(m, name), `${commit.slice(0, 12)}@${checkoutKey(forSet)}`);
|
|
65
|
+
if (!existsSync(dir)) {
|
|
66
|
+
mkdirSync(copiesOf(m, name), { recursive: true });
|
|
67
|
+
progress(`Checking out ${name} at ${ref} (${commit.slice(0, 12)}) into ${dir}`);
|
|
68
|
+
gitOr(clone, ['worktree', 'prune']);
|
|
69
|
+
git(clone, ['worktree', 'add', '--detach', dir, commit]);
|
|
70
|
+
}
|
|
71
|
+
await preparedOnce(dir, { prepare: r.prepare, seed: m.seed, given: `${name} at ${ref}` }, progress);
|
|
72
|
+
const now = new Date();
|
|
73
|
+
utimesSync(dir, now, now);
|
|
74
|
+
usedHere.add(path.resolve(dir));
|
|
75
|
+
evictCopies(m, name);
|
|
76
|
+
return { path: dir, ref, commit, dirty: isDirty(dir) };
|
|
77
|
+
}
|
|
78
|
+
export function evictCopies(m, name) {
|
|
79
|
+
const root = copiesOf(m, name);
|
|
80
|
+
if (!existsSync(root))
|
|
81
|
+
return [];
|
|
82
|
+
const dirs = readdirSync(root, { withFileTypes: true })
|
|
83
|
+
.filter((d) => d.isDirectory())
|
|
84
|
+
.map((d) => path.join(root, d.name))
|
|
85
|
+
.sort((a, b) => statSync(b).mtimeMs - statSync(a).mtimeMs);
|
|
86
|
+
const gone = [];
|
|
87
|
+
const clone = cloneOf(m, name);
|
|
88
|
+
const inUse = [
|
|
89
|
+
...usedHere,
|
|
90
|
+
...runningServices(m.dir).flatMap((r) => (r.root === undefined ? [] : [r.root])),
|
|
91
|
+
];
|
|
92
|
+
for (const dir of dirs.slice(m.budget.checkouts * 2)) {
|
|
93
|
+
if (inUse.some((k) => path.resolve(k) === path.resolve(dir)))
|
|
94
|
+
continue;
|
|
95
|
+
if (existsSync(clone))
|
|
96
|
+
gitOr(clone, ['worktree', 'remove', '--force', dir]);
|
|
97
|
+
rmSync(dir, { recursive: true, force: true });
|
|
98
|
+
rmSync(preparedMark(dir), { force: true });
|
|
99
|
+
gone.push(dir);
|
|
100
|
+
}
|
|
101
|
+
if (existsSync(clone))
|
|
102
|
+
gitOr(clone, ['worktree', 'prune']);
|
|
103
|
+
return gone;
|
|
104
|
+
}
|
|
105
|
+
const A_REPOSITORY_NAMED = /^([A-Za-z_][A-Za-z0-9_-]*)=(.+)$/;
|
|
106
|
+
export function refsOf(given, flag) {
|
|
107
|
+
const refs = {};
|
|
108
|
+
for (const value of given) {
|
|
109
|
+
const named = A_REPOSITORY_NAMED.exec(value);
|
|
110
|
+
if (!named)
|
|
111
|
+
throw usage(`--${flag} takes a repository's name, = and a ref or folder, as in api=feature-x: not “${value}”.`);
|
|
112
|
+
const [, name = '', ref = ''] = named;
|
|
113
|
+
if (name in refs)
|
|
114
|
+
throw usage(`--${flag} names ${name} twice.`);
|
|
115
|
+
refs[name] = ref;
|
|
116
|
+
}
|
|
117
|
+
return refs;
|
|
118
|
+
}
|
|
119
|
+
export function refuseUnknownRepositories(m, given) {
|
|
120
|
+
for (const name of Object.keys(given))
|
|
121
|
+
if (!(name in m.repositories))
|
|
122
|
+
throw usage(`There is no repository “${name}”${Object.keys(m.repositories).length ? `: the manifest names ${Object.keys(m.repositories).join(', ')}` : ' in the manifest'}.`);
|
|
123
|
+
}
|
|
124
|
+
export async function copiesFor(m, given, forSet, progress, cwd = process.cwd()) {
|
|
125
|
+
refuseUnknownRepositories(m, given);
|
|
126
|
+
const out = {};
|
|
127
|
+
for (const name of Object.keys(m.repositories))
|
|
128
|
+
out[name] = await copyOf(m, name, given[name] ?? null, topOf(forSet) ?? forSet, progress, cwd);
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
export const pinnedOf = (copies) => Object.fromEntries(Object.entries(copies).map(([name, c]) => [name, c.ref === null ? c.path : (c.commit ?? c.path)]));
|
|
132
|
+
export const rootsOf = (copies) => Object.fromEntries(Object.entries(copies ?? {}).map(([name, c]) => [name, c.path]));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { copiesFor, copyOf, evictCopies, pinnedOf, refsOf, refuseUnknownRepositories, repositoriesDir, rootsOf, type Copies, type Copy, } from './copies.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { copiesFor, copyOf, evictCopies, pinnedOf, refsOf, refuseUnknownRepositories, repositoriesDir, rootsOf, } from './copies.js';
|
package/dist/run/cache.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { KindRunner } from '../kinds/index.ts';
|
|
2
2
|
import { type Manifest } from '../manifest/index.ts';
|
|
3
3
|
import type { Scenario } from '../scenarios/index.ts';
|
|
4
|
-
import type
|
|
4
|
+
import { type Observation } from './observation.ts';
|
|
5
5
|
export declare function hashOfContents(at: string): string;
|
|
6
6
|
export declare function manifestPartsUsedBy(m: Manifest, services: readonly string[], world: string | null, kind: string): unknown;
|
|
7
7
|
export declare function groupsOf(m: Manifest, scenarios: readonly Scenario[], world: string | null): Promise<Map<string, string>>;
|
|
8
8
|
export interface KeyParts {
|
|
9
9
|
group?: string | null;
|
|
10
10
|
commit: string;
|
|
11
|
+
copies?: Readonly<Record<string, string>> | undefined;
|
|
11
12
|
scenario: Scenario;
|
|
12
13
|
world: string | null;
|
|
13
14
|
person: string | null;
|
package/dist/run/cache.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { hashOf } from '../manifest/index.js';
|
|
4
|
+
import { hashOf, withWhatTheyName } from '../manifest/index.js';
|
|
5
5
|
import { stateDir } from '../services/index.js';
|
|
6
6
|
import { chainOf } from '../worlds/index.js';
|
|
7
|
+
import { dirtyAnywhere } from './observation.js';
|
|
7
8
|
export function hashOfContents(at) {
|
|
8
9
|
const hash = createHash('sha256');
|
|
9
10
|
const walk = (p, rel) => {
|
|
@@ -59,9 +60,11 @@ export async function groupsOf(m, scenarios, world) {
|
|
|
59
60
|
return out;
|
|
60
61
|
}
|
|
61
62
|
export function cacheKeyOf(p) {
|
|
62
|
-
const
|
|
63
|
+
const own = p.runner.services(p.scenario, p.manifest);
|
|
64
|
+
const services = [...own, ...withWhatTheyName(p.manifest, own).filter((name) => !own.includes(name))];
|
|
63
65
|
return hashOf({
|
|
64
66
|
commit: p.commit,
|
|
67
|
+
...(p.copies && { copies: p.copies }),
|
|
65
68
|
id: p.scenario.id,
|
|
66
69
|
definition: p.scenario.definition,
|
|
67
70
|
context: p.scenario.context ?? null,
|
|
@@ -87,7 +90,7 @@ export function cached(m, commit, key) {
|
|
|
87
90
|
}
|
|
88
91
|
const didntAnswer = (o) => o.failures.some((f) => typeof f.got === 'string' && /^It didn’t answer|timed out/.test(f.got));
|
|
89
92
|
export function keep(m, o) {
|
|
90
|
-
if (!o.cacheKey || !o.checkout.commit || o.checkout
|
|
93
|
+
if (!o.cacheKey || !o.checkout.commit || dirtyAnywhere(o.checkout) || o.broke)
|
|
91
94
|
return false;
|
|
92
95
|
if (didntAnswer(o))
|
|
93
96
|
return false;
|
package/dist/run/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { cached, cacheKeyOf, groupsOf, keep, type KeyParts } from './cache.ts';
|
|
2
|
-
export type
|
|
2
|
+
export { commitsOf, dirtyAnywhere, withCopies, type CheckoutInfo, type Observation } from './observation.ts';
|
|
3
3
|
export { slotsFor, type Slots } from './parallel.ts';
|
|
4
4
|
export { applyWorld, placedIn, runSide, runSideSharing, type NotRun, type SessionOptions, type SideRun, } from './session.ts';
|
|
5
5
|
export { baseVars } from './vars.ts';
|
package/dist/run/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { cached, cacheKeyOf, groupsOf, keep } from './cache.js';
|
|
2
|
+
export { commitsOf, dirtyAnywhere, withCopies } from './observation.js';
|
|
2
3
|
export { slotsFor } from './parallel.js';
|
|
3
4
|
export { applyWorld, placedIn, runSide, runSideSharing, } from './session.js';
|
|
4
5
|
export { baseVars } from './vars.js';
|
|
@@ -5,7 +5,11 @@ export interface CheckoutInfo {
|
|
|
5
5
|
ref: string | null;
|
|
6
6
|
commit: string | null;
|
|
7
7
|
dirty: boolean;
|
|
8
|
+
repositories?: Record<string, CheckoutInfo>;
|
|
8
9
|
}
|
|
10
|
+
export declare const withCopies: (info: CheckoutInfo, copies: Readonly<Record<string, CheckoutInfo>> | undefined) => CheckoutInfo;
|
|
11
|
+
export declare const dirtyAnywhere: (info: CheckoutInfo) => boolean;
|
|
12
|
+
export declare const commitsOf: (info: CheckoutInfo) => Record<string, string> | undefined;
|
|
9
13
|
export interface Observation {
|
|
10
14
|
v: 1;
|
|
11
15
|
ok: boolean;
|
package/dist/run/observation.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export const withCopies = (info, copies) => (copies && Object.keys(copies).length ? { ...info, repositories: { ...copies } } : info);
|
|
2
|
+
export const dirtyAnywhere = (info) => info.dirty || Object.values(info.repositories ?? {}).some((c) => c.dirty || c.commit === null);
|
|
3
|
+
export const commitsOf = (info) => info.repositories
|
|
4
|
+
? Object.fromEntries(Object.entries(info.repositories).map(([name, c]) => [name, c.commit ?? '']))
|
|
5
|
+
: undefined;
|
package/dist/run/session.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type Scenario } from '../scenarios/index.ts';
|
|
2
2
|
import { type StandinUse } from '../kinds/index.ts';
|
|
3
3
|
import { type Manifest } from '../manifest/index.ts';
|
|
4
|
+
import { type Copies } from '../repositories/index.ts';
|
|
4
5
|
import { applyWorld } from '../worlds/index.ts';
|
|
5
6
|
export { applyWorld };
|
|
6
|
-
import type
|
|
7
|
+
import { type CheckoutInfo, type Observation } from './observation.ts';
|
|
7
8
|
import { type Slots } from './parallel.ts';
|
|
8
9
|
export interface SessionOptions {
|
|
9
10
|
world: string | null;
|
|
@@ -14,6 +15,7 @@ export interface SessionOptions {
|
|
|
14
15
|
ref: string | null;
|
|
15
16
|
groups?: ReadonlyMap<string, string>;
|
|
16
17
|
parallel?: number;
|
|
18
|
+
copies?: Copies;
|
|
17
19
|
}
|
|
18
20
|
export interface NotRun {
|
|
19
21
|
scenario: Scenario;
|
package/dist/run/session.js
CHANGED
|
@@ -5,13 +5,15 @@ import { toPosix, refOf } from '../scenarios/index.js';
|
|
|
5
5
|
import { RehearseError, errorText } from '../errors.js';
|
|
6
6
|
import { broken, runnerOf, } from '../kinds/index.js';
|
|
7
7
|
import { knowKeys, withoutKeysDeep } from '../keys/index.js';
|
|
8
|
-
import { fill } from '../manifest/index.js';
|
|
8
|
+
import { fill, upOrder, withWhatTheyName } from '../manifest/index.js';
|
|
9
9
|
import { signIn } from '../people/index.js';
|
|
10
|
-
import {
|
|
10
|
+
import { rootsOf } from '../repositories/index.js';
|
|
11
|
+
import { stateDir, bringDown, bringUp, handoverSettled, inUse, liveServices, makeRoom, release, standinsFor, upFromAnotherCopy, } from '../services/index.js';
|
|
11
12
|
import { VERSION } from '../version.js';
|
|
12
13
|
import { applyWorld, chainOf } from '../worlds/index.js';
|
|
13
14
|
export { applyWorld };
|
|
14
15
|
import { cacheKeyOf, groupsOf } from './cache.js';
|
|
16
|
+
import { commitsOf, dirtyAnywhere, withCopies } from './observation.js';
|
|
15
17
|
import { inTurn, slotsFor, unitsOf } from './parallel.js';
|
|
16
18
|
import { baseVars } from './vars.js';
|
|
17
19
|
const worldOf = (s, o) => o.world ?? s.world;
|
|
@@ -77,18 +79,20 @@ async function planOf(m, world, group) {
|
|
|
77
79
|
...everyServiceWhenTheWorldAdds(m, world),
|
|
78
80
|
...(m.signIn?.service ? [m.signIn.service] : []),
|
|
79
81
|
];
|
|
80
|
-
const needed = new Set([
|
|
82
|
+
const needed = new Set(withWhatTheyName(m, [
|
|
81
83
|
...group.flatMap((s) => runners.get(s.kind).services(s, m)),
|
|
82
84
|
...everyServiceWhenTheWorldAdds(m, world),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
needed.add(m.signIn.service);
|
|
85
|
+
...(m.signIn?.service ? [m.signIn.service] : []),
|
|
86
|
+
]));
|
|
86
87
|
return {
|
|
87
88
|
world,
|
|
88
89
|
group,
|
|
89
90
|
runners,
|
|
90
91
|
needed,
|
|
91
|
-
servicesOf: (s) =>
|
|
92
|
+
servicesOf: (s) => {
|
|
93
|
+
const own = [...new Set([...runners.get(s.kind).services(s, m), ...forEveryScenario])];
|
|
94
|
+
return [...own, ...withWhatTheyName(m, own).filter((name) => !own.includes(name))];
|
|
95
|
+
},
|
|
92
96
|
};
|
|
93
97
|
}
|
|
94
98
|
function undeclaredIn(m, needed) {
|
|
@@ -100,14 +104,16 @@ function undeclaredIn(m, needed) {
|
|
|
100
104
|
}
|
|
101
105
|
: null;
|
|
102
106
|
}
|
|
103
|
-
function
|
|
107
|
+
function leftUpOtherwise(scope, world, leftUp) {
|
|
104
108
|
const other = leftUp.find((r) => (r.world ?? null) !== world);
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
if (other)
|
|
110
|
+
return {
|
|
107
111
|
step: 'world',
|
|
108
|
-
says: `${other.name} is already up in ${checkout} with ${other.world ? `the world ${other.world}` : 'no world Rehearse built'}, not ${world ?? 'no world'}: run with --world ${other.world ?? '…'}, or stop it with \`rehearse down\`.`,
|
|
109
|
-
}
|
|
110
|
-
|
|
112
|
+
says: `${other.name} is already up in ${scope.checkout} with ${other.world ? `the world ${other.world}` : 'no world Rehearse built'}, not ${world ?? 'no world'}: run with --world ${other.world ?? '…'}, or stop it with \`rehearse down\`.`,
|
|
113
|
+
};
|
|
114
|
+
const roots = rootsOf(scope.o.copies);
|
|
115
|
+
const fromAnotherCopy = leftUp.map((r) => upFromAnotherCopy(scope.m, r, roots)).find(Boolean);
|
|
116
|
+
return fromAnotherCopy ? { step: 'up', says: fromAnotherCopy } : null;
|
|
111
117
|
}
|
|
112
118
|
const everyOneOf = (group, why) => group.map((s) => ({ scenario: s, ...why, byItsRunner: false }));
|
|
113
119
|
async function runGroup(side, world, group, runners, needed, upAlready, rehearseCanVouchForTheirState) {
|
|
@@ -126,12 +132,13 @@ async function runGroup(side, world, group, runners, needed, upAlready, rehearse
|
|
|
126
132
|
await makeRoom(m, checkout, o.progress);
|
|
127
133
|
if (world && fresh.length)
|
|
128
134
|
await applyWorld(m, world, 'before', checkout, vars());
|
|
129
|
-
for (const name of
|
|
135
|
+
for (const name of upOrder(m).filter((n) => fresh.includes(n))) {
|
|
130
136
|
bringingUp = name;
|
|
131
137
|
const r = await bringUp(m, m.services[name], checkout, {
|
|
132
138
|
world,
|
|
133
139
|
real: o.real,
|
|
134
140
|
vars: vars(),
|
|
141
|
+
roots: rootsOf(o.copies),
|
|
135
142
|
progress: o.progress,
|
|
136
143
|
});
|
|
137
144
|
started.push(r);
|
|
@@ -139,7 +146,7 @@ async function runGroup(side, world, group, runners, needed, upAlready, rehearse
|
|
|
139
146
|
}
|
|
140
147
|
}
|
|
141
148
|
catch (error) {
|
|
142
|
-
for (const r of started)
|
|
149
|
+
for (const r of started.toReversed())
|
|
143
150
|
await bringDown(m, r, o.progress);
|
|
144
151
|
out.broke = {
|
|
145
152
|
step: error instanceof RehearseError && error.code === 'world' ? 'world' : 'up',
|
|
@@ -224,10 +231,11 @@ async function runGroup(side, world, group, runners, needed, upAlready, rehearse
|
|
|
224
231
|
at: new Date().toISOString(),
|
|
225
232
|
rehearse: VERSION,
|
|
226
233
|
runner: runner.version,
|
|
227
|
-
cacheKey: side.info.commit && !side.info
|
|
234
|
+
cacheKey: side.info.commit && !dirtyAnywhere(side.info) && rehearseCanVouchForTheirState
|
|
228
235
|
? cacheKeyOf({
|
|
229
236
|
group: side.groups.get(s.id) ?? null,
|
|
230
237
|
commit: side.info.commit,
|
|
238
|
+
copies: commitsOf(side.info),
|
|
231
239
|
scenario: s,
|
|
232
240
|
world,
|
|
233
241
|
person,
|
|
@@ -280,7 +288,7 @@ async function oneWorldAfterAnother(scope, worlds, side) {
|
|
|
280
288
|
}
|
|
281
289
|
const running = await liveServices(m, checkout);
|
|
282
290
|
const leftUp = running.filter((r) => plan.needed.has(r.name));
|
|
283
|
-
const elsewhere =
|
|
291
|
+
const elsewhere = leftUpOtherwise(scope, world, leftUp);
|
|
284
292
|
if (elsewhere) {
|
|
285
293
|
side.notRun.push(...everyOneOf(group, elsewhere).map(asNotRun));
|
|
286
294
|
continue;
|
|
@@ -327,7 +335,7 @@ async function inTurns(scope, worlds, side, slots) {
|
|
|
327
335
|
for (const [world, group] of worlds) {
|
|
328
336
|
const plan = await planOf(m, world, group);
|
|
329
337
|
const leftUp = upAtFirst.filter((r) => plan.needed.has(r.name));
|
|
330
|
-
const refused = undeclaredIn(m, plan.needed) ??
|
|
338
|
+
const refused = undeclaredIn(m, plan.needed) ?? leftUpOtherwise(scope, world, leftUp);
|
|
331
339
|
if (refused) {
|
|
332
340
|
planned.push({ refused: everyOneOf(group, refused) });
|
|
333
341
|
continue;
|
|
@@ -365,7 +373,7 @@ export function runSide(m, checkout, scenarios, o) {
|
|
|
365
373
|
export function runSideSharing(m, checkout, scenarios, o, slots) {
|
|
366
374
|
return inUse(checkout, async () => {
|
|
367
375
|
const side = {
|
|
368
|
-
checkout: infoOf(m, checkout, o.ref),
|
|
376
|
+
checkout: withCopies(infoOf(m, checkout, o.ref), o.copies),
|
|
369
377
|
observations: new Map(),
|
|
370
378
|
broke: null,
|
|
371
379
|
notRun: [],
|
|
@@ -379,7 +387,7 @@ export function runSideSharing(m, checkout, scenarios, o, slots) {
|
|
|
379
387
|
side.broke = { step: 'overlay', says: errorText(error) };
|
|
380
388
|
return side;
|
|
381
389
|
}
|
|
382
|
-
side.checkout = infoOf(m, checkout, o.ref);
|
|
390
|
+
side.checkout = withCopies(infoOf(m, checkout, o.ref), o.copies);
|
|
383
391
|
const manifestAs = manifestFolderAsOnBothSides(m);
|
|
384
392
|
const keepDir = path.join(stateDir(m.dir), 'runs', `${Date.now().toString(36)}-${path.basename(checkout)}`);
|
|
385
393
|
mkdirSync(keepDir, { recursive: true });
|
|
@@ -393,6 +401,10 @@ export function runSideSharing(m, checkout, scenarios, o, slots) {
|
|
|
393
401
|
placed: (v) => placedIn(v, [
|
|
394
402
|
[path.resolve(checkout), '{{checkout}}'],
|
|
395
403
|
[path.resolve(m.dir), manifestAs],
|
|
404
|
+
...Object.entries(o.copies ?? {}).map(([name, c]) => [
|
|
405
|
+
path.resolve(c.path),
|
|
406
|
+
`{{${name}_checkout}}`,
|
|
407
|
+
]),
|
|
396
408
|
]),
|
|
397
409
|
};
|
|
398
410
|
const worlds = new Map();
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { alive, runningServices, stateDir, type Running } from './registry.ts';
|
|
2
|
-
export { bringDown, bringUp, downStartedHere, envOf, freePort, handoverSettled, inUse, liveServices, makeRoom, release, restart, restartable, standinsFor, } from './service.ts';
|
|
1
|
+
export { alive, checkoutKey, runningServices, stateDir, type Running } from './registry.ts';
|
|
2
|
+
export { bringDown, bringUp, cwdOf, downStartedHere, envOf, freePort, handoverSettled, inUse, liveServices, makeRoom, release, restart, restartable, rootOf, standinsFor, upFromAnotherCopy, } from './service.ts';
|
package/dist/services/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { alive, runningServices, stateDir } from './registry.js';
|
|
2
|
-
export { bringDown, bringUp, downStartedHere, envOf, freePort, handoverSettled, inUse, liveServices, makeRoom, release, restart, restartable, standinsFor, } from './service.js';
|
|
1
|
+
export { alive, checkoutKey, runningServices, stateDir } from './registry.js';
|
|
2
|
+
export { bringDown, bringUp, cwdOf, downStartedHere, envOf, freePort, handoverSettled, inUse, liveServices, makeRoom, release, restart, restartable, rootOf, standinsFor, upFromAnotherCopy, } from './service.js';
|
|
@@ -10,8 +10,12 @@ export interface UpOptions {
|
|
|
10
10
|
world: string | null;
|
|
11
11
|
real: ReadonlySet<string>;
|
|
12
12
|
vars: Record<string, string>;
|
|
13
|
+
roots?: Readonly<Record<string, string>>;
|
|
13
14
|
progress?: (line: string) => void;
|
|
14
15
|
}
|
|
16
|
+
export declare const rootOf: (r: Running) => string;
|
|
17
|
+
export declare const cwdOf: (s: Service | undefined, r: Running) => string;
|
|
18
|
+
export declare function upFromAnotherCopy(m: Manifest, r: Running, roots: Readonly<Record<string, string>>): string | null;
|
|
15
19
|
export declare const logOf: (m: Manifest, name: string, checkout: string) => string;
|
|
16
20
|
export declare function liveServices(m: Manifest, checkout?: string | null): Promise<Running[]>;
|
|
17
21
|
export declare const restartable: (r: Running) => boolean;
|
package/dist/services/service.js
CHANGED
|
@@ -72,6 +72,15 @@ export function standinsFor(m, service, real) {
|
|
|
72
72
|
return { standin, real: isReal };
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
+
export const rootOf = (r) => r.root ?? r.checkout;
|
|
76
|
+
export const cwdOf = (s, r) => s?.cwd ? path.resolve(rootOf(r), s.cwd) : rootOf(r);
|
|
77
|
+
export function upFromAnotherCopy(m, r, roots) {
|
|
78
|
+
const repository = m.services[r.name]?.repository;
|
|
79
|
+
const wanted = repository ? roots[repository] : undefined;
|
|
80
|
+
if (!wanted || path.resolve(rootOf(r)) === path.resolve(wanted))
|
|
81
|
+
return null;
|
|
82
|
+
return `${r.name} is already up from ${rootOf(r)}, and this needs it from ${wanted}: stop it with \`rehearse down ${r.name}\`.`;
|
|
83
|
+
}
|
|
75
84
|
const logDir = (m) => path.join(stateDir(m.dir), 'logs');
|
|
76
85
|
export const logOf = (m, name, checkout) => path.join(logDir(m), `${name}@${checkoutKey(checkout)}.log`);
|
|
77
86
|
function signalledIfStillThere(pid, signal) {
|
|
@@ -123,7 +132,7 @@ export async function liveServices(m, checkout = null) {
|
|
|
123
132
|
}
|
|
124
133
|
const s = m.services[r.name];
|
|
125
134
|
const answers = s?.ready
|
|
126
|
-
? await readyNow(s.ready, varsOf(m, r), envOf(m, r), s
|
|
135
|
+
? await readyNow(s.ready, varsOf(m, r), envOf(m, r), cwdOf(s, r), '', r.port)
|
|
127
136
|
: r.port !== null
|
|
128
137
|
? await portTaken(r.port)
|
|
129
138
|
: false;
|
|
@@ -151,7 +160,7 @@ export async function handoverSettled(r) {
|
|
|
151
160
|
}
|
|
152
161
|
function varsOf(m, r) {
|
|
153
162
|
return (r.vars ?? {
|
|
154
|
-
checkout: r
|
|
163
|
+
checkout: rootOf(r),
|
|
155
164
|
manifest: m.dir,
|
|
156
165
|
...(r.scratch && { scratch: r.scratch }),
|
|
157
166
|
...(r.world && { world: r.world }),
|
|
@@ -189,7 +198,7 @@ export async function restart(m, r, whileDown = async () => undefined) {
|
|
|
189
198
|
const s = m.services[r.name];
|
|
190
199
|
if (!s || !restartable(r))
|
|
191
200
|
return null;
|
|
192
|
-
const cwd = s
|
|
201
|
+
const cwd = cwdOf(s, r);
|
|
193
202
|
const env = envOf(m, r);
|
|
194
203
|
let keys;
|
|
195
204
|
try {
|
|
@@ -227,16 +236,22 @@ export async function downStartedHere() {
|
|
|
227
236
|
}
|
|
228
237
|
}
|
|
229
238
|
export async function bringUp(m, s, checkout, options) {
|
|
239
|
+
const root = s.repository === null ? checkout : options.roots?.[s.repository];
|
|
240
|
+
if (root === undefined)
|
|
241
|
+
throw new RehearseError('service', `${s.name} runs in the repository ${s.repository}, and Rehearse has no copy of it for ${checkout}.`);
|
|
230
242
|
const upThere = () => runningServices(m.dir).find((r) => r.name === s.name && path.resolve(r.checkout) === path.resolve(checkout));
|
|
231
243
|
const already = upThere();
|
|
232
244
|
if (already) {
|
|
245
|
+
const another = upFromAnotherCopy(m, already, options.roots ?? {});
|
|
246
|
+
if (another)
|
|
247
|
+
throw new RehearseError('service', another);
|
|
233
248
|
await knowKeys(m, s);
|
|
234
249
|
if (alive(already.pid) || !s.ready)
|
|
235
250
|
return already;
|
|
236
251
|
if (await readyNow(s.ready, {
|
|
237
252
|
...(already.url && { url: already.url }),
|
|
238
253
|
...(already.port !== null && { port: String(already.port) }),
|
|
239
|
-
}, envOf(m, already), s
|
|
254
|
+
}, envOf(m, already), cwdOf(s, already), '', already.port))
|
|
240
255
|
return already;
|
|
241
256
|
forget(m.dir, already.name, already.checkout);
|
|
242
257
|
}
|
|
@@ -253,14 +268,14 @@ export async function bringUp(m, s, checkout, options) {
|
|
|
253
268
|
throw new RehearseError('service', `${s.name} listens on port ${port}, and something already answers there. Stop it, or give the service port: auto.`);
|
|
254
269
|
}
|
|
255
270
|
const standins = standinsFor(m, s.name, options.real);
|
|
256
|
-
const cwd = s.cwd ? path.resolve(
|
|
271
|
+
const cwd = s.cwd ? path.resolve(root, s.cwd) : root;
|
|
257
272
|
if (!existsSync(cwd))
|
|
258
273
|
throw new RehearseError('service', `${s.name} runs in ${cwd}, which isn't there.`);
|
|
259
274
|
mkdirSync(path.join(stateDir(m.dir), 'scratch'), { recursive: true });
|
|
260
275
|
const scratch = mkdtempSync(path.join(stateDir(m.dir), 'scratch', `${s.name}-${checkoutKey(checkout)}-`));
|
|
261
276
|
const vars = {
|
|
262
277
|
...options.vars,
|
|
263
|
-
checkout,
|
|
278
|
+
checkout: root,
|
|
264
279
|
manifest: m.dir,
|
|
265
280
|
scratch,
|
|
266
281
|
...(options.world !== null && { world: options.world }),
|
|
@@ -278,7 +293,7 @@ export async function bringUp(m, s, checkout, options) {
|
|
|
278
293
|
const log = logOf(m, s.name, checkout);
|
|
279
294
|
const out = openSync(log, 'w');
|
|
280
295
|
const command = fill(s.up, vars);
|
|
281
|
-
options.progress?.(`Bringing ${s.name} up in ${
|
|
296
|
+
options.progress?.(`Bringing ${s.name} up in ${root}: ${command}`);
|
|
282
297
|
const child = spawn('/bin/sh', ['-c', command], {
|
|
283
298
|
cwd,
|
|
284
299
|
env: { ...process.env, ...env, ...keys },
|
|
@@ -300,6 +315,7 @@ export async function bringUp(m, s, checkout, options) {
|
|
|
300
315
|
const running = {
|
|
301
316
|
name: s.name,
|
|
302
317
|
checkout,
|
|
318
|
+
...(s.repository !== null && { root }),
|
|
303
319
|
pid,
|
|
304
320
|
port,
|
|
305
321
|
url,
|
|
@@ -352,7 +368,7 @@ export async function bringUp(m, s, checkout, options) {
|
|
|
352
368
|
export async function bringDown(m, r, progress) {
|
|
353
369
|
if (r.down) {
|
|
354
370
|
const s = m.services[r.name];
|
|
355
|
-
const cwd = s
|
|
371
|
+
const cwd = cwdOf(s, r);
|
|
356
372
|
await sh(r.down, {
|
|
357
373
|
cwd,
|
|
358
374
|
timeoutMs: 30_000,
|
package/dist/stage/api.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Manifest } from '../manifest/index.ts';
|
|
2
|
+
import { type Copies } from '../repositories/index.ts';
|
|
2
3
|
import { type Observation } from '../run/index.ts';
|
|
3
4
|
import { type Scenario } from '../scenarios/index.ts';
|
|
4
5
|
import type { LastCompared } from './compared.ts';
|
|
@@ -22,6 +23,7 @@ export interface StageScope {
|
|
|
22
23
|
};
|
|
23
24
|
baseRef: string;
|
|
24
25
|
checkoutOf(side: Side): Promise<string>;
|
|
26
|
+
copiesOn(side: Side): Promise<Copies>;
|
|
25
27
|
scenarioOn(side: Side, id: string): Promise<Scenario | null>;
|
|
26
28
|
runs: Map<string, Observation>;
|
|
27
29
|
compared: LastCompared;
|
package/dist/stage/api.js
CHANGED
|
@@ -3,6 +3,7 @@ import { compare, lineOf } from '../compare/index.js';
|
|
|
3
3
|
import { RehearseError } from '../errors.js';
|
|
4
4
|
import { infoOf } from '../git/index.js';
|
|
5
5
|
import { scrub } from '../people/index.js';
|
|
6
|
+
import { pinnedOf } from '../repositories/index.js';
|
|
6
7
|
import { runSide } from '../run/index.js';
|
|
7
8
|
import { readScenarios, refOf } from '../scenarios/index.js';
|
|
8
9
|
import { validate } from '../schema.js';
|
|
@@ -131,6 +132,7 @@ export function apiOf(s) {
|
|
|
131
132
|
keepUp: false,
|
|
132
133
|
progress: s.asked.progress,
|
|
133
134
|
ref: side === 'base' ? baseRef : head.ref,
|
|
135
|
+
copies: await s.copiesOn(side),
|
|
134
136
|
});
|
|
135
137
|
const ob = run.observations.get(id);
|
|
136
138
|
if (!ob) {
|
|
@@ -153,6 +155,8 @@ export function apiOf(s) {
|
|
|
153
155
|
cwd: s.asked.cwd,
|
|
154
156
|
head: s.asked.head,
|
|
155
157
|
base: s.asked.base,
|
|
158
|
+
headRepositories: pinnedOf(await s.copiesOn('head')),
|
|
159
|
+
baseRepositories: pinnedOf(await s.copiesOn('base')),
|
|
156
160
|
ids: [id],
|
|
157
161
|
affected: false,
|
|
158
162
|
announce: s.asked.announce,
|
package/dist/stage/sending.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Manifest } from '../manifest/index.ts';
|
|
2
|
+
import { type Copies } from '../repositories/index.ts';
|
|
2
3
|
import { type Running } from '../services/index.ts';
|
|
3
4
|
import type { Side } from './http.ts';
|
|
4
5
|
export interface SideSession {
|
|
@@ -15,4 +16,4 @@ export interface ServicesForSending {
|
|
|
15
16
|
takeDown(): Promise<void>;
|
|
16
17
|
tokens(): Record<string, string>;
|
|
17
18
|
}
|
|
18
|
-
export declare function servicesForSending(m: Manifest, checkoutOf: (side: Side) => Promise<string>, progress: (line: string) => void): ServicesForSending;
|
|
19
|
+
export declare function servicesForSending(m: Manifest, checkoutOf: (side: Side) => Promise<string>, copiesOn: (side: Side) => Promise<Copies>, progress: (line: string) => void): ServicesForSending;
|
package/dist/stage/sending.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { RehearseError } from '../errors.js';
|
|
2
|
-
import { fill } from '../manifest/index.js';
|
|
2
|
+
import { fill, upOrder } from '../manifest/index.js';
|
|
3
3
|
import { signIn } from '../people/index.js';
|
|
4
4
|
import { applyWorld, baseVars } from '../run/index.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { rootsOf } from '../repositories/index.js';
|
|
6
|
+
import { bringDown, bringUp, liveServices, makeRoom, upFromAnotherCopy, } from '../services/index.js';
|
|
7
|
+
export function servicesForSending(m, checkoutOf, copiesOn, progress) {
|
|
7
8
|
let session = null;
|
|
8
9
|
const takeDown = async () => {
|
|
9
10
|
const s = session;
|
|
@@ -18,22 +19,28 @@ export function servicesForSending(m, checkoutOf, progress) {
|
|
|
18
19
|
return session;
|
|
19
20
|
await takeDown();
|
|
20
21
|
await makeRoom(m, checkout, progress);
|
|
22
|
+
const roots = rootsOf(await copiesOn(side));
|
|
21
23
|
let running = await liveServices(m, checkout);
|
|
24
|
+
const fromAnotherCopy = running.map((r) => upFromAnotherCopy(m, r, roots)).find(Boolean);
|
|
25
|
+
if (fromAnotherCopy)
|
|
26
|
+
throw new RehearseError('service', fromAnotherCopy);
|
|
22
27
|
const already = running.find((r) => (r.world ?? null) !== world);
|
|
23
28
|
if (already)
|
|
24
29
|
throw new RehearseError('service', `${already.name} is already up on the ${side} with ${already.world ? `the world ${already.world}` : 'no world'}: bring it down with rehearse down to send in ${world ? `the world ${world}` : 'no world'}.`);
|
|
25
30
|
const started = [];
|
|
26
31
|
try {
|
|
27
|
-
const
|
|
32
|
+
const inOrder = upOrder(m).map((name) => m.services[name]);
|
|
33
|
+
const fresh = inOrder.some((s) => !running.some((r) => r.name === s.name));
|
|
28
34
|
if (world && fresh)
|
|
29
35
|
await applyWorld(m, world, 'before', checkout, baseVars(m, checkout, running));
|
|
30
|
-
for (const s of
|
|
36
|
+
for (const s of inOrder) {
|
|
31
37
|
if (running.some((r) => r.name === s.name))
|
|
32
38
|
continue;
|
|
33
39
|
const r = await bringUp(m, s, checkout, {
|
|
34
40
|
world,
|
|
35
41
|
real: new Set(),
|
|
36
42
|
vars: baseVars(m, checkout, running),
|
|
43
|
+
roots,
|
|
37
44
|
progress,
|
|
38
45
|
});
|
|
39
46
|
started.push(r);
|
package/dist/stage/server.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface StageOptions {
|
|
|
17
17
|
announceFrom?: 'changesets' | null;
|
|
18
18
|
said?: readonly string[];
|
|
19
19
|
progress: (line: string) => void;
|
|
20
|
+
baseRepositories?: Readonly<Record<string, string>>;
|
|
21
|
+
headRepositories?: Readonly<Record<string, string>>;
|
|
20
22
|
}
|
|
21
23
|
export interface Stage {
|
|
22
24
|
url: string;
|