@kurvball/rehearse 1.15.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/drive.js +42 -12
- package/dist/commands/up.js +4 -2
- package/dist/drive/open.js +19 -10
- package/dist/drive/state.d.ts +1 -0
- package/dist/manifest/index.d.ts +1 -0
- package/dist/manifest/index.js +1 -0
- package/dist/manifest/load.js +9 -0
- package/dist/manifest/order.d.ts +8 -0
- package/dist/manifest/order.js +53 -0
- package/dist/run/cache.js +3 -2
- package/dist/run/session.js +10 -8
- package/dist/stage/sending.js +4 -3
- package/package.json +1 -1
package/dist/commands/drive.js
CHANGED
|
@@ -6,7 +6,7 @@ import { checkoutOf, manifestOf, said } from './command.js';
|
|
|
6
6
|
import { addToWalk, beginWalk, failed, driveArgv, exitOf, parseDrive, resultText, VERBS, forgetDriving, readDriving, walked, writeDriving, } from '../drive/index.js';
|
|
7
7
|
import { sh, tail } from '../exec.js';
|
|
8
8
|
import { knowKeys } from '../keys/index.js';
|
|
9
|
-
import { fillEnv } from '../manifest/index.js';
|
|
9
|
+
import { fillEnv, withWhatTheyName } from '../manifest/index.js';
|
|
10
10
|
import { applyWorld, baseVars } from '../run/index.js';
|
|
11
11
|
import { alive, runningServices, stateDir, bringDown, bringUp, cwdOf, envOf, handoverSettled, release, } from '../services/index.js';
|
|
12
12
|
import { copiesFor, rootsOf } from '../repositories/index.js';
|
|
@@ -70,26 +70,51 @@ Each answers in the drive result shape (schema/v1/drive.schema.json): 0 done, 1
|
|
|
70
70
|
const world = options.world ?? m.defaults.world;
|
|
71
71
|
let running = runningServices(m.dir).filter((r) => path.resolve(r.checkout) === path.resolve(checkout));
|
|
72
72
|
const already = running.some((r) => r.name === svc.name);
|
|
73
|
+
const alsoStarted = [];
|
|
73
74
|
if (already)
|
|
74
75
|
await knowKeys(m, svc);
|
|
75
76
|
else {
|
|
76
77
|
if (world)
|
|
77
78
|
await applyWorld(m, world, 'before', checkout, baseVars(m, checkout, running));
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
const roots = rootsOf(await copiesFor(m, {}, checkout, ctx.progress, ctx.cwd));
|
|
80
|
+
const startedHere = [];
|
|
81
|
+
try {
|
|
82
|
+
for (const named of withWhatTheyName(m, [svc.name])) {
|
|
83
|
+
if (running.some((r) => r.name === named))
|
|
84
|
+
continue;
|
|
85
|
+
const r = await bringUp(m, m.services[named], checkout, {
|
|
86
|
+
world,
|
|
87
|
+
real: new Set(),
|
|
88
|
+
vars: baseVars(m, checkout, running),
|
|
89
|
+
roots,
|
|
90
|
+
progress: ctx.progress,
|
|
91
|
+
});
|
|
92
|
+
startedHere.push(r);
|
|
93
|
+
if (named === svc.name)
|
|
94
|
+
await handoverSettled(r);
|
|
95
|
+
else
|
|
96
|
+
alsoStarted.push(named);
|
|
97
|
+
release(r);
|
|
98
|
+
running = [...running, r];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
for (const r of startedHere.toReversed())
|
|
103
|
+
await bringDown(m, r, ctx.progress);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
88
106
|
if (world)
|
|
89
107
|
await applyWorld(m, world, 'add', checkout, baseVars(m, checkout, running));
|
|
90
108
|
}
|
|
91
109
|
const since = new Date().toISOString();
|
|
92
|
-
writeDriving(m.dir, {
|
|
110
|
+
writeDriving(m.dir, {
|
|
111
|
+
driver: 'service',
|
|
112
|
+
service: svc.name,
|
|
113
|
+
checkout,
|
|
114
|
+
started: !already,
|
|
115
|
+
...(alsoStarted.length && { alsoStarted }),
|
|
116
|
+
since,
|
|
117
|
+
});
|
|
93
118
|
beginWalk(m.dir, {
|
|
94
119
|
driver: 'service',
|
|
95
120
|
service: svc.name,
|
|
@@ -187,6 +212,11 @@ Each answers in the drive result shape (schema/v1/drive.schema.json): 0 done, 1
|
|
|
187
212
|
if (command.command === 'stop') {
|
|
188
213
|
if (running && driving.started)
|
|
189
214
|
await bringDown(m, running, ctx.progress);
|
|
215
|
+
for (const named of (driving.alsoStarted ?? []).toReversed()) {
|
|
216
|
+
const up = runningServices(m.dir).find((r) => r.name === named && path.resolve(r.checkout) === path.resolve(driving.checkout));
|
|
217
|
+
if (up)
|
|
218
|
+
await bringDown(m, up, ctx.progress);
|
|
219
|
+
}
|
|
190
220
|
forgetDriving(m.dir);
|
|
191
221
|
return answer({
|
|
192
222
|
v: 1,
|
package/dist/commands/up.js
CHANGED
|
@@ -7,6 +7,7 @@ import { copiesFor, refsOf, rootsOf } from '../repositories/index.js';
|
|
|
7
7
|
import { baseVars } from '../run/index.js';
|
|
8
8
|
import { applyWorld } from '../worlds/index.js';
|
|
9
9
|
import { overlay } from '../git/index.js';
|
|
10
|
+
import { withWhatTheyName } from '../manifest/index.js';
|
|
10
11
|
const rowOf = (r) => ({
|
|
11
12
|
name: r.name,
|
|
12
13
|
checkout: r.checkout,
|
|
@@ -24,10 +25,11 @@ export const up = {
|
|
|
24
25
|
async run(args, ctx) {
|
|
25
26
|
const m = manifestOf(ctx);
|
|
26
27
|
const checkout = checkoutOf(m, one(args, 'on'), ctx.cwd);
|
|
27
|
-
const
|
|
28
|
-
for (const n of
|
|
28
|
+
const asked = args.positional.length ? args.positional : Object.keys(m.services);
|
|
29
|
+
for (const n of asked)
|
|
29
30
|
if (!m.services[n])
|
|
30
31
|
throw new RehearseError('no_service', `There is no service “${n}”: there is ${Object.keys(m.services).join(', ') || 'none'}.`);
|
|
32
|
+
const names = withWhatTheyName(m, asked);
|
|
31
33
|
const world = one(args, 'world') ?? m.defaults.world;
|
|
32
34
|
overlay(m, checkout);
|
|
33
35
|
await makeRoom(m, checkout, ctx.progress);
|
package/dist/drive/open.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { knowKeys } from '../keys/index.js';
|
|
3
|
-
import { fill } from '../manifest/index.js';
|
|
3
|
+
import { fill, withWhatTheyName } from '../manifest/index.js';
|
|
4
4
|
import { scrub, signIn } from '../people/index.js';
|
|
5
5
|
import { startPieceServer } from '../kinds/index.js';
|
|
6
6
|
import { applyWorld, baseVars } from '../run/index.js';
|
|
@@ -54,18 +54,27 @@ export async function openPage(m, checkout, o, showing = {}) {
|
|
|
54
54
|
else {
|
|
55
55
|
if (o.world)
|
|
56
56
|
await applyWorld(m, o.world, 'before', checkout, baseVars(m, checkout, running));
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
const roots = rootsOf(await copiesFor(m, {}, checkout, showing.progress ?? (() => undefined)));
|
|
58
|
+
for (const named of withWhatTheyName(m, [svc.name])) {
|
|
59
|
+
if (running.some((r) => r.name === named))
|
|
60
|
+
continue;
|
|
61
|
+
const r = await bringUp(m, m.services[named], checkout, {
|
|
62
|
+
world: o.world,
|
|
63
|
+
real: new Set(),
|
|
64
|
+
vars: baseVars(m, checkout, running),
|
|
65
|
+
roots,
|
|
66
|
+
...(showing.progress && { progress: showing.progress }),
|
|
67
|
+
});
|
|
68
|
+
started.push(r);
|
|
69
|
+
running = [...running, r];
|
|
70
|
+
if (named === svc.name)
|
|
71
|
+
mine = r;
|
|
72
|
+
}
|
|
66
73
|
if (o.world)
|
|
67
74
|
await applyWorld(m, o.world, 'add', checkout, baseVars(m, checkout, running));
|
|
68
75
|
}
|
|
76
|
+
if (!mine)
|
|
77
|
+
throw new Error(`${svc.name} didn't come up.`);
|
|
69
78
|
if (!mine.url)
|
|
70
79
|
throw new Error(`${svc.name} has no URL to open.`);
|
|
71
80
|
url = new URL(o.start ?? '/', mine.url).href;
|
package/dist/drive/state.d.ts
CHANGED
package/dist/manifest/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { fill, fillEnv, placeholdersIn } from './fill.ts';
|
|
2
2
|
export { STARTER, STARTER_BLOCKS, STARTER_HEAD } from './init.ts';
|
|
3
|
+
export { servicesNamedBy, upOrder, withWhatTheyName } from './order.ts';
|
|
3
4
|
export { findManifest, hashOf, INERT_BY_DEFAULT, loadManifest, MANIFEST_FILE, manifestFrom } from './load.ts';
|
|
4
5
|
export { KIND_BLOCK, KINDS, type Key, type Kind, type Manifest, type PathEntry, type Person, type Real, type Repository, type Service, type Standin, type World, } from './types.ts';
|
|
5
6
|
export { readYaml } from './yaml.ts';
|
package/dist/manifest/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { fill, fillEnv, placeholdersIn } from './fill.js';
|
|
2
2
|
export { STARTER, STARTER_BLOCKS, STARTER_HEAD } from './init.js';
|
|
3
|
+
export { servicesNamedBy, upOrder, withWhatTheyName } from './order.js';
|
|
3
4
|
export { findManifest, hashOf, INERT_BY_DEFAULT, loadManifest, MANIFEST_FILE, manifestFrom } from './load.js';
|
|
4
5
|
export { KIND_BLOCK, KINDS, } from './types.js';
|
|
5
6
|
export { readYaml } from './yaml.js';
|
package/dist/manifest/load.js
CHANGED
|
@@ -3,6 +3,7 @@ import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { RehearseError } from '../errors.js';
|
|
5
5
|
import { validate } from '../schema.js';
|
|
6
|
+
import { NamedInACircle, upOrder } from './order.js';
|
|
6
7
|
import { readYaml } from './yaml.js';
|
|
7
8
|
export const INERT_BY_DEFAULT = [
|
|
8
9
|
'.changeset/*.md',
|
|
@@ -173,6 +174,14 @@ function checkWhatTheSchemaCant(m) {
|
|
|
173
174
|
if (alsoFrom)
|
|
174
175
|
refuse(m.file, at(['services', s.name, 'keys', env]), `${s.name} gets ${env} from both ${alsoFrom.includes(' ') || alsoFrom === 'Rehearse' ? alsoFrom : `the stand-in ${alsoFrom}`} and its keys: give it one of them.`);
|
|
175
176
|
}
|
|
177
|
+
try {
|
|
178
|
+
upOrder(m);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
if (!(error instanceof NamedInACircle))
|
|
182
|
+
throw error;
|
|
183
|
+
refuse(m.file, at(['services', error.circle[0]]), error.message);
|
|
184
|
+
}
|
|
176
185
|
for (const [i, rule] of [...m.setAside.keys, ...m.setAside.values].entries()) {
|
|
177
186
|
try {
|
|
178
187
|
void new RegExp(rule);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Manifest, Service } from './types.ts';
|
|
2
|
+
export declare function servicesNamedBy(m: Manifest, s: Service): string[];
|
|
3
|
+
export declare class NamedInACircle extends Error {
|
|
4
|
+
readonly circle: readonly string[];
|
|
5
|
+
constructor(circle: readonly string[]);
|
|
6
|
+
}
|
|
7
|
+
export declare const upOrder: (m: Manifest) => string[];
|
|
8
|
+
export declare const withWhatTheyName: (m: Manifest, names: Iterable<string>) => string[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { placeholdersIn } from './fill.js';
|
|
2
|
+
const ANOTHERS_ADDRESS = /^([A-Za-z_][A-Za-z0-9_-]*)_(?:url|port)$/;
|
|
3
|
+
const serviceNamed = (m, name) => Object.hasOwn(m.services, name) ? m.services[name] : undefined;
|
|
4
|
+
function textsOf(m, s) {
|
|
5
|
+
const standins = Object.values(m.standins).filter((x) => x.services === null || x.services.includes(s.name));
|
|
6
|
+
return [
|
|
7
|
+
s.up,
|
|
8
|
+
s.url,
|
|
9
|
+
s.down,
|
|
10
|
+
...(s.ready === null ? [] : Object.values(s.ready)),
|
|
11
|
+
...Object.values(s.env),
|
|
12
|
+
...standins.flatMap((x) => [...Object.values(x.env), ...Object.values(x.real?.env ?? {})]),
|
|
13
|
+
].filter((t) => typeof t === 'string');
|
|
14
|
+
}
|
|
15
|
+
export function servicesNamedBy(m, s) {
|
|
16
|
+
const named = new Set();
|
|
17
|
+
for (const text of textsOf(m, s))
|
|
18
|
+
for (const placeholder of placeholdersIn(text)) {
|
|
19
|
+
const name = ANOTHERS_ADDRESS.exec(placeholder)?.[1];
|
|
20
|
+
if (name !== undefined && name !== s.name && serviceNamed(m, name))
|
|
21
|
+
named.add(name);
|
|
22
|
+
}
|
|
23
|
+
return Object.keys(m.services).filter((name) => named.has(name));
|
|
24
|
+
}
|
|
25
|
+
export class NamedInACircle extends Error {
|
|
26
|
+
circle;
|
|
27
|
+
constructor(circle) {
|
|
28
|
+
super(`${circle
|
|
29
|
+
.slice(0, -1)
|
|
30
|
+
.map((name, i) => `${name} names ${circle[i + 1]}'s address`)
|
|
31
|
+
.join(', ')}, so none of them can come up first.`);
|
|
32
|
+
this.circle = circle;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function dependenciesFirst(m, names) {
|
|
36
|
+
const order = [];
|
|
37
|
+
const visit = (name, path) => {
|
|
38
|
+
if (order.includes(name))
|
|
39
|
+
return;
|
|
40
|
+
if (path.includes(name))
|
|
41
|
+
throw new NamedInACircle([...path.slice(path.indexOf(name)), name]);
|
|
42
|
+
const s = serviceNamed(m, name);
|
|
43
|
+
if (s)
|
|
44
|
+
for (const named of servicesNamedBy(m, s))
|
|
45
|
+
visit(named, [...path, name]);
|
|
46
|
+
order.push(name);
|
|
47
|
+
};
|
|
48
|
+
for (const name of names)
|
|
49
|
+
visit(name, []);
|
|
50
|
+
return order;
|
|
51
|
+
}
|
|
52
|
+
export const upOrder = (m) => dependenciesFirst(m, Object.keys(m.services));
|
|
53
|
+
export const withWhatTheyName = (m, names) => dependenciesFirst(m, names);
|
package/dist/run/cache.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
7
|
import { dirtyAnywhere } from './observation.js';
|
|
@@ -60,7 +60,8 @@ export async function groupsOf(m, scenarios, world) {
|
|
|
60
60
|
return out;
|
|
61
61
|
}
|
|
62
62
|
export function cacheKeyOf(p) {
|
|
63
|
-
const
|
|
63
|
+
const own = p.runner.services(p.scenario, p.manifest);
|
|
64
|
+
const services = [...own, ...withWhatTheyName(p.manifest, own).filter((name) => !own.includes(name))];
|
|
64
65
|
return hashOf({
|
|
65
66
|
commit: p.commit,
|
|
66
67
|
...(p.copies && { copies: p.copies }),
|
package/dist/run/session.js
CHANGED
|
@@ -5,7 +5,7 @@ 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
10
|
import { rootsOf } from '../repositories/index.js';
|
|
11
11
|
import { stateDir, bringDown, bringUp, handoverSettled, inUse, liveServices, makeRoom, release, standinsFor, upFromAnotherCopy, } from '../services/index.js';
|
|
@@ -79,18 +79,20 @@ async function planOf(m, world, group) {
|
|
|
79
79
|
...everyServiceWhenTheWorldAdds(m, world),
|
|
80
80
|
...(m.signIn?.service ? [m.signIn.service] : []),
|
|
81
81
|
];
|
|
82
|
-
const needed = new Set([
|
|
82
|
+
const needed = new Set(withWhatTheyName(m, [
|
|
83
83
|
...group.flatMap((s) => runners.get(s.kind).services(s, m)),
|
|
84
84
|
...everyServiceWhenTheWorldAdds(m, world),
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
needed.add(m.signIn.service);
|
|
85
|
+
...(m.signIn?.service ? [m.signIn.service] : []),
|
|
86
|
+
]));
|
|
88
87
|
return {
|
|
89
88
|
world,
|
|
90
89
|
group,
|
|
91
90
|
runners,
|
|
92
91
|
needed,
|
|
93
|
-
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
|
+
},
|
|
94
96
|
};
|
|
95
97
|
}
|
|
96
98
|
function undeclaredIn(m, needed) {
|
|
@@ -130,7 +132,7 @@ async function runGroup(side, world, group, runners, needed, upAlready, rehearse
|
|
|
130
132
|
await makeRoom(m, checkout, o.progress);
|
|
131
133
|
if (world && fresh.length)
|
|
132
134
|
await applyWorld(m, world, 'before', checkout, vars());
|
|
133
|
-
for (const name of
|
|
135
|
+
for (const name of upOrder(m).filter((n) => fresh.includes(n))) {
|
|
134
136
|
bringingUp = name;
|
|
135
137
|
const r = await bringUp(m, m.services[name], checkout, {
|
|
136
138
|
world,
|
|
@@ -144,7 +146,7 @@ async function runGroup(side, world, group, runners, needed, upAlready, rehearse
|
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
catch (error) {
|
|
147
|
-
for (const r of started)
|
|
149
|
+
for (const r of started.toReversed())
|
|
148
150
|
await bringDown(m, r, o.progress);
|
|
149
151
|
out.broke = {
|
|
150
152
|
step: error instanceof RehearseError && error.code === 'world' ? 'world' : 'up',
|
package/dist/stage/sending.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
5
|
import { rootsOf } from '../repositories/index.js';
|
|
@@ -29,10 +29,11 @@ export function servicesForSending(m, checkoutOf, copiesOn, progress) {
|
|
|
29
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'}.`);
|
|
30
30
|
const started = [];
|
|
31
31
|
try {
|
|
32
|
-
const
|
|
32
|
+
const inOrder = upOrder(m).map((name) => m.services[name]);
|
|
33
|
+
const fresh = inOrder.some((s) => !running.some((r) => r.name === s.name));
|
|
33
34
|
if (world && fresh)
|
|
34
35
|
await applyWorld(m, world, 'before', checkout, baseVars(m, checkout, running));
|
|
35
|
-
for (const s of
|
|
36
|
+
for (const s of inOrder) {
|
|
36
37
|
if (running.some((r) => r.name === s.name))
|
|
37
38
|
continue;
|
|
38
39
|
const r = await bringUp(m, s, checkout, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kurvball/rehearse",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "Rehearse a change before it ships: bring the product up, sign in as named people, start from named worlds, and compare any scenario on the base and on the head.",
|
|
5
5
|
"homepage": "https://rehearse.kurvball.ca/",
|
|
6
6
|
"repository": {
|