@kurvball/rehearse 1.13.3 → 1.15.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.
Files changed (82) hide show
  1. package/dist/cli.js +5 -0
  2. package/dist/commands/announce.js +2 -2
  3. package/dist/commands/clean.js +6 -3
  4. package/dist/commands/compare.js +6 -1
  5. package/dist/commands/drive.js +12 -3
  6. package/dist/commands/index.js +2 -0
  7. package/dist/commands/init.js +1 -1
  8. package/dist/commands/keys.d.ts +2 -0
  9. package/dist/commands/keys.js +67 -0
  10. package/dist/commands/run.js +8 -4
  11. package/dist/commands/services.d.ts +3 -0
  12. package/dist/commands/services.js +10 -1
  13. package/dist/commands/stage.js +18 -2
  14. package/dist/commands/up.js +11 -3
  15. package/dist/compare/compare.d.ts +2 -0
  16. package/dist/compare/compare.js +19 -10
  17. package/dist/detect/detect.js +4 -0
  18. package/dist/detect/index.d.ts +1 -0
  19. package/dist/detect/index.js +1 -0
  20. package/dist/detect/keys.d.ts +16 -0
  21. package/dist/detect/keys.js +141 -0
  22. package/dist/detect/write.d.ts +2 -0
  23. package/dist/detect/write.js +20 -1
  24. package/dist/drive/daemon.js +2 -1
  25. package/dist/drive/open.js +6 -1
  26. package/dist/errors.js +2 -1
  27. package/dist/git/checkout.d.ts +6 -0
  28. package/dist/git/checkout.js +28 -19
  29. package/dist/git/index.d.ts +3 -2
  30. package/dist/git/index.js +3 -2
  31. package/dist/index.d.ts +1 -0
  32. package/dist/index.js +1 -0
  33. package/dist/keys/index.d.ts +3 -0
  34. package/dist/keys/index.js +3 -0
  35. package/dist/keys/keys.d.ts +16 -0
  36. package/dist/keys/keys.js +139 -0
  37. package/dist/keys/report.d.ts +23 -0
  38. package/dist/keys/report.js +31 -0
  39. package/dist/keys/store.d.ts +7 -0
  40. package/dist/keys/store.js +133 -0
  41. package/dist/keys/tool.d.ts +11 -0
  42. package/dist/keys/tool.js +27 -0
  43. package/dist/kinds/flow/kind.js +2 -2
  44. package/dist/manifest/index.d.ts +1 -1
  45. package/dist/manifest/load.js +33 -0
  46. package/dist/manifest/types.d.ts +28 -0
  47. package/dist/repositories/copies.d.ts +16 -0
  48. package/dist/repositories/copies.js +132 -0
  49. package/dist/repositories/index.d.ts +1 -0
  50. package/dist/repositories/index.js +1 -0
  51. package/dist/run/cache.d.ts +2 -1
  52. package/dist/run/cache.js +3 -1
  53. package/dist/run/index.d.ts +1 -1
  54. package/dist/run/index.js +1 -0
  55. package/dist/run/observation.d.ts +4 -0
  56. package/dist/run/observation.js +5 -1
  57. package/dist/run/session.d.ts +3 -1
  58. package/dist/run/session.js +27 -13
  59. package/dist/schema.d.ts +1 -1
  60. package/dist/schema.js +1 -0
  61. package/dist/services/index.d.ts +2 -2
  62. package/dist/services/index.js +2 -2
  63. package/dist/services/registry.d.ts +1 -0
  64. package/dist/services/service.d.ts +4 -0
  65. package/dist/services/service.js +46 -14
  66. package/dist/stage/api.d.ts +2 -0
  67. package/dist/stage/api.js +4 -0
  68. package/dist/stage/http.js +2 -1
  69. package/dist/stage/sending.d.ts +2 -1
  70. package/dist/stage/sending.js +8 -2
  71. package/dist/stage/server.d.ts +2 -0
  72. package/dist/stage/server.js +14 -1
  73. package/llms.txt +7 -6
  74. package/package.json +2 -2
  75. package/schema/v1/common.schema.json +22 -0
  76. package/schema/v1/init.schema.json +2 -1
  77. package/schema/v1/keys.schema.json +51 -0
  78. package/schema/v1/manifest.schema.json +66 -0
  79. package/schema/v1/samples/keys.json +22 -0
  80. package/schema/v1/samples/manifest.yaml +12 -0
  81. package/schema/v1/services.schema.json +13 -0
  82. package/skill/rehearse/SKILL.md +8 -0
@@ -4,13 +4,16 @@ import { infoOf, overlay, topOf } from '../git/index.js';
4
4
  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
+ import { knowKeys, withoutKeysDeep } from '../keys/index.js';
7
8
  import { fill } from '../manifest/index.js';
8
9
  import { signIn } from '../people/index.js';
9
- import { stateDir, bringDown, bringUp, handoverSettled, inUse, liveServices, makeRoom, release, standinsFor, } from '../services/index.js';
10
+ import { rootsOf } from '../repositories/index.js';
11
+ import { stateDir, bringDown, bringUp, handoverSettled, inUse, liveServices, makeRoom, release, standinsFor, upFromAnotherCopy, } from '../services/index.js';
10
12
  import { VERSION } from '../version.js';
11
13
  import { applyWorld, chainOf } from '../worlds/index.js';
12
14
  export { applyWorld };
13
15
  import { cacheKeyOf, groupsOf } from './cache.js';
16
+ import { commitsOf, dirtyAnywhere, withCopies } from './observation.js';
14
17
  import { inTurn, slotsFor, unitsOf } from './parallel.js';
15
18
  import { baseVars } from './vars.js';
16
19
  const worldOf = (s, o) => o.world ?? s.world;
@@ -99,14 +102,16 @@ function undeclaredIn(m, needed) {
99
102
  }
100
103
  : null;
101
104
  }
102
- function upInAnotherWorld(checkout, world, leftUp) {
105
+ function leftUpOtherwise(scope, world, leftUp) {
103
106
  const other = leftUp.find((r) => (r.world ?? null) !== world);
104
- return other
105
- ? {
107
+ if (other)
108
+ return {
106
109
  step: 'world',
107
- 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\`.`,
108
- }
109
- : null;
110
+ 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\`.`,
111
+ };
112
+ const roots = rootsOf(scope.o.copies);
113
+ const fromAnotherCopy = leftUp.map((r) => upFromAnotherCopy(scope.m, r, roots)).find(Boolean);
114
+ return fromAnotherCopy ? { step: 'up', says: fromAnotherCopy } : null;
110
115
  }
111
116
  const everyOneOf = (group, why) => group.map((s) => ({ scenario: s, ...why, byItsRunner: false }));
112
117
  async function runGroup(side, world, group, runners, needed, upAlready, rehearseCanVouchForTheirState) {
@@ -114,6 +119,9 @@ async function runGroup(side, world, group, runners, needed, upAlready, rehearse
114
119
  const out = { observations: new Map(), notRun: [], broke: null };
115
120
  const started = [];
116
121
  let running = upAlready;
122
+ for (const r of upAlready)
123
+ if (needed.has(r.name) && m.services[r.name])
124
+ await knowKeys(m, m.services[r.name]);
117
125
  const vars = () => baseVars(m, checkout, running);
118
126
  let bringingUp = null;
119
127
  try {
@@ -128,6 +136,7 @@ async function runGroup(side, world, group, runners, needed, upAlready, rehearse
128
136
  world,
129
137
  real: o.real,
130
138
  vars: vars(),
139
+ roots: rootsOf(o.copies),
131
140
  progress: o.progress,
132
141
  });
133
142
  started.push(r);
@@ -193,7 +202,7 @@ async function runGroup(side, world, group, runners, needed, upAlready, rehearse
193
202
  broughtUpAndUnused.delete(name);
194
203
  const ms = Math.round((Date.now() - begun) / Math.max(1, these.length));
195
204
  for (const s of these) {
196
- const r = ran.get(s.id);
205
+ const r = withoutKeysDeep(ran.get(s.id));
197
206
  if (!r)
198
207
  continue;
199
208
  if (r.broke &&
@@ -220,10 +229,11 @@ async function runGroup(side, world, group, runners, needed, upAlready, rehearse
220
229
  at: new Date().toISOString(),
221
230
  rehearse: VERSION,
222
231
  runner: runner.version,
223
- cacheKey: side.info.commit && !side.info.dirty && rehearseCanVouchForTheirState
232
+ cacheKey: side.info.commit && !dirtyAnywhere(side.info) && rehearseCanVouchForTheirState
224
233
  ? cacheKeyOf({
225
234
  group: side.groups.get(s.id) ?? null,
226
235
  commit: side.info.commit,
236
+ copies: commitsOf(side.info),
227
237
  scenario: s,
228
238
  world,
229
239
  person,
@@ -276,7 +286,7 @@ async function oneWorldAfterAnother(scope, worlds, side) {
276
286
  }
277
287
  const running = await liveServices(m, checkout);
278
288
  const leftUp = running.filter((r) => plan.needed.has(r.name));
279
- const elsewhere = upInAnotherWorld(checkout, world, leftUp);
289
+ const elsewhere = leftUpOtherwise(scope, world, leftUp);
280
290
  if (elsewhere) {
281
291
  side.notRun.push(...everyOneOf(group, elsewhere).map(asNotRun));
282
292
  continue;
@@ -323,7 +333,7 @@ async function inTurns(scope, worlds, side, slots) {
323
333
  for (const [world, group] of worlds) {
324
334
  const plan = await planOf(m, world, group);
325
335
  const leftUp = upAtFirst.filter((r) => plan.needed.has(r.name));
326
- const refused = undeclaredIn(m, plan.needed) ?? upInAnotherWorld(checkout, world, leftUp);
336
+ const refused = undeclaredIn(m, plan.needed) ?? leftUpOtherwise(scope, world, leftUp);
327
337
  if (refused) {
328
338
  planned.push({ refused: everyOneOf(group, refused) });
329
339
  continue;
@@ -361,7 +371,7 @@ export function runSide(m, checkout, scenarios, o) {
361
371
  export function runSideSharing(m, checkout, scenarios, o, slots) {
362
372
  return inUse(checkout, async () => {
363
373
  const side = {
364
- checkout: infoOf(m, checkout, o.ref),
374
+ checkout: withCopies(infoOf(m, checkout, o.ref), o.copies),
365
375
  observations: new Map(),
366
376
  broke: null,
367
377
  notRun: [],
@@ -375,7 +385,7 @@ export function runSideSharing(m, checkout, scenarios, o, slots) {
375
385
  side.broke = { step: 'overlay', says: errorText(error) };
376
386
  return side;
377
387
  }
378
- side.checkout = infoOf(m, checkout, o.ref);
388
+ side.checkout = withCopies(infoOf(m, checkout, o.ref), o.copies);
379
389
  const manifestAs = manifestFolderAsOnBothSides(m);
380
390
  const keepDir = path.join(stateDir(m.dir), 'runs', `${Date.now().toString(36)}-${path.basename(checkout)}`);
381
391
  mkdirSync(keepDir, { recursive: true });
@@ -389,6 +399,10 @@ export function runSideSharing(m, checkout, scenarios, o, slots) {
389
399
  placed: (v) => placedIn(v, [
390
400
  [path.resolve(checkout), '{{checkout}}'],
391
401
  [path.resolve(m.dir), manifestAs],
402
+ ...Object.entries(o.copies ?? {}).map(([name, c]) => [
403
+ path.resolve(c.path),
404
+ `{{${name}_checkout}}`,
405
+ ]),
392
406
  ]),
393
407
  };
394
408
  const worlds = new Map();
package/dist/schema.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type ErrorObject, type ValidateFunction } from 'ajv/dist/2020.js';
2
2
  export declare const SCHEMA_DIR: string;
3
- export declare const SCHEMAS: readonly ['manifest', 'flow', 'file-scenario', 'announce', 'services', 'people', 'worlds', 'list', 'observation', 'comparison', 'drive', 'open', 'stage', 'static', 'try', 'error', 'dependents', 'check', 'init', 'validate', 'up', 'clean', 'record'];
3
+ export declare const SCHEMAS: readonly ['manifest', 'flow', 'file-scenario', 'announce', 'services', 'keys', 'people', 'worlds', 'list', 'observation', 'comparison', 'drive', 'open', 'stage', 'static', 'try', 'error', 'dependents', 'check', 'init', 'validate', 'up', 'clean', 'record'];
4
4
  export type SchemaName = (typeof SCHEMAS)[number];
5
5
  export declare const schemaId: (name: SchemaName | 'common') => string;
6
6
  export declare function validatorOf(name: SchemaName): ValidateFunction;
package/dist/schema.js CHANGED
@@ -9,6 +9,7 @@ export const SCHEMAS = [
9
9
  'file-scenario',
10
10
  'announce',
11
11
  'services',
12
+ 'keys',
12
13
  'people',
13
14
  'worlds',
14
15
  'list',
@@ -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';
@@ -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';
@@ -1,6 +1,7 @@
1
1
  export interface Running {
2
2
  name: string;
3
3
  checkout: string;
4
+ root?: string;
4
5
  pid: number;
5
6
  port: number | null;
6
7
  url: string | null;
@@ -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;
@@ -4,6 +4,7 @@ import { connect, createServer } from 'node:net';
4
4
  import path from 'node:path';
5
5
  import { RehearseError } from '../errors.js';
6
6
  import { sh, tail } from '../exec.js';
7
+ import { keysFor, knowKeys, maskKeysIn, withoutKeys } from '../keys/index.js';
7
8
  import { fill, fillEnv } from '../manifest/index.js';
8
9
  import { alive, checkoutKey, forget, remember, rememberIfStillUp, runningServices, stateDir, } from './registry.js';
9
10
  const POLL_MS = 250;
@@ -71,6 +72,15 @@ export function standinsFor(m, service, real) {
71
72
  return { standin, real: isReal };
72
73
  });
73
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
+ }
74
84
  const logDir = (m) => path.join(stateDir(m.dir), 'logs');
75
85
  export const logOf = (m, name, checkout) => path.join(logDir(m), `${name}@${checkoutKey(checkout)}.log`);
76
86
  function signalledIfStillThere(pid, signal) {
@@ -122,7 +132,7 @@ export async function liveServices(m, checkout = null) {
122
132
  }
123
133
  const s = m.services[r.name];
124
134
  const answers = s?.ready
125
- ? await readyNow(s.ready, varsOf(m, r), envOf(m, r), s.cwd ? path.resolve(r.checkout, s.cwd) : r.checkout, '', r.port)
135
+ ? await readyNow(s.ready, varsOf(m, r), envOf(m, r), cwdOf(s, r), '', r.port)
126
136
  : r.port !== null
127
137
  ? await portTaken(r.port)
128
138
  : false;
@@ -150,7 +160,7 @@ export async function handoverSettled(r) {
150
160
  }
151
161
  function varsOf(m, r) {
152
162
  return (r.vars ?? {
153
- checkout: r.checkout,
163
+ checkout: rootOf(r),
154
164
  manifest: m.dir,
155
165
  ...(r.scratch && { scratch: r.scratch }),
156
166
  ...(r.world && { world: r.world }),
@@ -188,15 +198,22 @@ export async function restart(m, r, whileDown = async () => undefined) {
188
198
  const s = m.services[r.name];
189
199
  if (!s || !restartable(r))
190
200
  return null;
191
- const cwd = s.cwd ? path.resolve(r.checkout, s.cwd) : r.checkout;
201
+ const cwd = cwdOf(s, r);
192
202
  const env = envOf(m, r);
203
+ let keys;
204
+ try {
205
+ keys = await keysFor(m, s);
206
+ }
207
+ catch (error) {
208
+ return error.message;
209
+ }
193
210
  await sh(r.down, { cwd, env, timeoutMs: 60_000 });
194
211
  await whileDown();
195
- const up = await sh(r.up, { cwd, env, timeoutMs: s.timeoutMs });
212
+ const up = await sh(r.up, { cwd, env: { ...env, ...keys }, timeoutMs: s.timeoutMs });
196
213
  const upSaidThisTime = logOf(m, s.name, r.checkout);
197
- writeFileSync(upSaidThisTime, `${up.stdout}${up.stderr}`);
214
+ writeFileSync(upSaidThisTime, withoutKeys(`${up.stdout}${up.stderr}`));
198
215
  if (up.code !== 0)
199
- return `${s.name} didn't come up again (exit ${up.code}): ${tail(up.stderr || up.stdout)}`;
216
+ return `${s.name} didn't come up again (exit ${up.code}): ${tail(withoutKeys(up.stderr || up.stdout))}`;
200
217
  const vars = varsOf(m, r);
201
218
  const begun = Date.now();
202
219
  while (!(await readyNow(s.ready, vars, env, cwd, upSaidThisTime, r.port))) {
@@ -219,17 +236,29 @@ export async function downStartedHere() {
219
236
  }
220
237
  }
221
238
  export async function bringUp(m, s, checkout, options) {
222
- const already = runningServices(m.dir).find((r) => r.name === s.name && path.resolve(r.checkout) === path.resolve(checkout));
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}.`);
242
+ const upThere = () => runningServices(m.dir).find((r) => r.name === s.name && path.resolve(r.checkout) === path.resolve(checkout));
243
+ const already = upThere();
223
244
  if (already) {
245
+ const another = upFromAnotherCopy(m, already, options.roots ?? {});
246
+ if (another)
247
+ throw new RehearseError('service', another);
248
+ await knowKeys(m, s);
224
249
  if (alive(already.pid) || !s.ready)
225
250
  return already;
226
251
  if (await readyNow(s.ready, {
227
252
  ...(already.url && { url: already.url }),
228
253
  ...(already.port !== null && { port: String(already.port) }),
229
- }, envOf(m, already), s.cwd ? path.resolve(checkout, s.cwd) : checkout, '', already.port))
254
+ }, envOf(m, already), cwdOf(s, already), '', already.port))
230
255
  return already;
231
256
  forget(m.dir, already.name, already.checkout);
232
257
  }
258
+ const keys = await keysFor(m, s);
259
+ const startedMeanwhile = upThere();
260
+ if (startedMeanwhile && alive(startedMeanwhile.pid))
261
+ return startedMeanwhile;
233
262
  let port = null;
234
263
  if (s.port === 'auto')
235
264
  port = await freePort();
@@ -239,14 +268,14 @@ export async function bringUp(m, s, checkout, options) {
239
268
  throw new RehearseError('service', `${s.name} listens on port ${port}, and something already answers there. Stop it, or give the service port: auto.`);
240
269
  }
241
270
  const standins = standinsFor(m, s.name, options.real);
242
- const cwd = s.cwd ? path.resolve(checkout, s.cwd) : checkout;
271
+ const cwd = s.cwd ? path.resolve(root, s.cwd) : root;
243
272
  if (!existsSync(cwd))
244
273
  throw new RehearseError('service', `${s.name} runs in ${cwd}, which isn't there.`);
245
274
  mkdirSync(path.join(stateDir(m.dir), 'scratch'), { recursive: true });
246
275
  const scratch = mkdtempSync(path.join(stateDir(m.dir), 'scratch', `${s.name}-${checkoutKey(checkout)}-`));
247
276
  const vars = {
248
277
  ...options.vars,
249
- checkout,
278
+ checkout: root,
250
279
  manifest: m.dir,
251
280
  scratch,
252
281
  ...(options.world !== null && { world: options.world }),
@@ -264,10 +293,10 @@ export async function bringUp(m, s, checkout, options) {
264
293
  const log = logOf(m, s.name, checkout);
265
294
  const out = openSync(log, 'w');
266
295
  const command = fill(s.up, vars);
267
- options.progress?.(`Bringing ${s.name} up in ${checkout}: ${command}`);
296
+ options.progress?.(`Bringing ${s.name} up in ${root}: ${command}`);
268
297
  const child = spawn('/bin/sh', ['-c', command], {
269
298
  cwd,
270
- env: { ...process.env, ...env },
299
+ env: { ...process.env, ...env, ...keys },
271
300
  stdio: ['ignore', out, out],
272
301
  detached: true,
273
302
  });
@@ -286,6 +315,7 @@ export async function bringUp(m, s, checkout, options) {
286
315
  const running = {
287
316
  name: s.name,
288
317
  checkout,
318
+ ...(s.repository !== null && { root }),
289
319
  pid,
290
320
  port,
291
321
  url,
@@ -302,8 +332,9 @@ export async function bringUp(m, s, checkout, options) {
302
332
  remember(m.dir, running);
303
333
  startedHereNotHandedOver.set(keyOf(running), { m, r: running });
304
334
  const begun = Date.now();
305
- const said = () => tail(readFileSync(log, 'utf8'), 4);
335
+ const said = () => tail(withoutKeys(readFileSync(log, 'utf8')), 4);
306
336
  const giveUp = async (why) => {
337
+ maskKeysIn(log);
307
338
  await bringDown(m, running);
308
339
  throw new RehearseError('service', why);
309
340
  };
@@ -316,6 +347,7 @@ export async function bringUp(m, s, checkout, options) {
316
347
  return giveUp(`${s.name} wasn't ready after ${Math.round(s.timeoutMs / 1000)} seconds. ${said() ? `It last said: ${said()}. ` : ''}Its log: ${log}`);
317
348
  await new Promise((resolve) => setTimeout(resolve, POLL_MS));
318
349
  }
350
+ maskKeysIn(log);
319
351
  running.starting = false;
320
352
  running.daemon = exited === 0;
321
353
  remember(m.dir, running);
@@ -336,7 +368,7 @@ export async function bringUp(m, s, checkout, options) {
336
368
  export async function bringDown(m, r, progress) {
337
369
  if (r.down) {
338
370
  const s = m.services[r.name];
339
- const cwd = s?.cwd ? path.resolve(r.checkout, s.cwd) : r.checkout;
371
+ const cwd = cwdOf(s, r);
340
372
  await sh(r.down, {
341
373
  cwd,
342
374
  timeoutMs: 30_000,
@@ -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,
@@ -1,7 +1,8 @@
1
1
  import { RehearseError, errorText } from '../errors.js';
2
+ import { withoutKeysDeep } from '../keys/index.js';
2
3
  export const json = (res, status, body) => {
3
4
  res.writeHead(status, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
4
- res.end(JSON.stringify(body));
5
+ res.end(JSON.stringify(withoutKeysDeep(body)));
5
6
  };
6
7
  export const fail = (res, status, code, says) => json(res, status, { v: 1, ok: false, error: { code, says } });
7
8
  export function answer(res, work) {
@@ -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;
@@ -2,8 +2,9 @@ import { RehearseError } from '../errors.js';
2
2
  import { fill } from '../manifest/index.js';
3
3
  import { signIn } from '../people/index.js';
4
4
  import { applyWorld, baseVars } from '../run/index.js';
5
- import { bringDown, bringUp, liveServices, makeRoom } from '../services/index.js';
6
- export function servicesForSending(m, checkoutOf, progress) {
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,7 +19,11 @@ 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'}.`);
@@ -34,6 +39,7 @@ export function servicesForSending(m, checkoutOf, progress) {
34
39
  world,
35
40
  real: new Set(),
36
41
  vars: baseVars(m, checkout, running),
42
+ roots,
37
43
  progress,
38
44
  });
39
45
  started.push(r);
@@ -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;
@@ -4,6 +4,7 @@ import path from 'node:path';
4
4
  import { readAnnouncement } from '../compare/index.js';
5
5
  import { RehearseError, errorText } from '../errors.js';
6
6
  import { checkoutFor } from '../git/index.js';
7
+ import { copiesFor } from '../repositories/index.js';
7
8
  import { parseHurl, Refusal, sendFile, startPieceServer, } from '../kinds/index.js';
8
9
  import { scrubDeep } from '../people/index.js';
9
10
  import { readScenarios } from '../scenarios/index.js';
@@ -72,8 +73,19 @@ export async function startStage(o) {
72
73
  const baseRef = o.base ?? m.base;
73
74
  const baseCheckout = async () => (base ??= await checkoutFor(m, head.path, baseRef, o.progress, [head.path], o.cwd));
74
75
  const checkoutOf = async (side) => (side === 'head' ? head.path : (await baseCheckout()).path);
76
+ const copies = new Map();
77
+ const copiesOn = (side) => {
78
+ const known = copies.get(side);
79
+ if (known)
80
+ return known;
81
+ const given = (side === 'head' ? o.headRepositories : o.baseRepositories) ?? {};
82
+ const resolving = checkoutOf(side).then((dir) => copiesFor(m, given, dir, o.progress, o.cwd));
83
+ resolving.catch(() => copies.delete(side));
84
+ copies.set(side, resolving);
85
+ return resolving;
86
+ };
75
87
  const scenarioOn = async (side, id) => (await readScenarios(m, await checkoutOf(side))).scenarios.find((s) => s.id === id) ?? null;
76
- const sending = servicesForSending(m, checkoutOf, o.progress);
88
+ const sending = servicesForSending(m, checkoutOf, copiesOn, o.progress);
77
89
  const pieces = new Map();
78
90
  const api = {
79
91
  ...apiOf({
@@ -82,6 +94,7 @@ export async function startStage(o) {
82
94
  head,
83
95
  baseRef,
84
96
  checkoutOf,
97
+ copiesOn,
85
98
  scenarioOn,
86
99
  runs: new Map(),
87
100
  compared: lastCompared(path.join(stateDir(m.dir), 'compare'), head.path, baseAsked(head.path, baseRef, o.cwd)),
package/llms.txt CHANGED
@@ -7,14 +7,15 @@
7
7
  - `rehearse init [--detect] [--force] [--json]`: writes a starter rehearse.yaml, every block commented. With --detect it fills in what the repository has (base from origin/HEAD, prepare from the lockfile, a service per app whose dev script runs Vite, Next, Astro or a Node server reading PORT, and globs for stories, flows, .hurl and *.rehearse.yaml), each block commented with what it was detected from; --json adds `detected` {base, findings: [{kind, name?, from, count?, written, why, next?}], next} (schema init), naming what it found but couldn't write (OpenAPI, Playwright, a dev server it can't give a port). It writes only rehearse.yaml.
8
8
  - `rehearse check [--json]`: reads the manifest and every scenario file; says what it can't read and where (schema check).
9
9
  - `rehearse services | people | worlds [--json]`: what can come up; who you can sign in as (people: the sign-in shape {name: {token, …}}, everyone described in about; tokens only with --json); the named starting states.
10
+ - `rehearse keys [--check] [--json]` and `rehearse keys add <key>`: the keys services need (manifest `keys`: an op:// reference, or this computer's key store), where each comes from and who gets it as which variable; --check looks each up (found, missing, live, short, unreadable; exit 1 when one isn't there); add keeps one on this computer from stdin. Never prints a key (schema keys).
10
11
  - `rehearse list [--affected <file>… | --since <ref>] [--json]`: the scenarios, or those a change reaches, each with reachedBy (schema list).
11
- - `rehearse up [<service>…] [--world] [--real <stand-in>]` and `rehearse down [--all]`: services left running with a world built on them (schema up).
12
- - `rehearse run <scenario> [--on <checkout|ref>] [--world] [--as <person>] [--real <stand-in>] [--keep] [--parallel <n>] --json`: one observation (schema observation).
13
- - `rehearse compare [<id or glob>…] [--affected] [--base <ref|./folder>] [--head <ref|./folder>] [--announce <file>] [--announce-from changesets] [--said <id>]… [--world] [--as] [--real] [--fresh] [--parallel <n>] [--gate [--preview <url>]] --json`: a verdict per scenario (schema comparison). --gate prints a gate answer instead ({v, ok, summary, details, annotations, links, tool}; exit 0 ok, 1 not, 2 can't compare). --announce-from changesets also reads the `announce` blocks of the changesets the change adds. Exit 0 when both sides came up and nothing fails on the head or changed without saying so. --parallel runs groups that share no service at once, and the base beside the head when budget.services allows two; the result is the same as one at a time.
12
+ - `rehearse up [<service>…] [--on <checkout>] [--repository <name=ref|folder>]… [--world] [--real <stand-in>]` and `rehearse down [--all]`: services left running with a world built on them (schema up).
13
+ - `rehearse run <scenario> [--on <checkout|ref>] [--repository <name=ref|folder>]… [--world] [--as <person>] [--real <stand-in>] [--keep] [--parallel <n>] --json`: one observation (schema observation). A service whose manifest entry names a `repository` (top-level `repositories: {name: {from, base?, prepare?}}`) runs in a fresh, prepared copy of that repository at its base, or at what --repository names; checkout.repositories gives each copy's {path, ref, commit, dirty}.
14
+ - `rehearse compare [<id or glob>…] [--affected] [--base <ref|./folder>] [--head <ref|./folder>] [--base-repository <name=ref|folder>]… [--head-repository <name=ref|folder>]… [--announce <file>] [--announce-from changesets] [--said <id>]… [--world] [--as] [--real] [--fresh] [--parallel <n>] [--gate [--preview <url>]] --json`: a verdict per scenario (schema comparison). --gate prints a gate answer instead ({v, ok, summary, details, annotations, links, tool}; exit 0 ok, 1 not, 2 can't compare). --announce-from changesets also reads the `announce` blocks of the changesets the change adds. Exit 0 when both sides came up and nothing fails on the head or changed without saying so. --parallel runs groups that share no service at once, and the base beside the head when budget.services allows two; the result is the same as one at a time.
14
15
  - `rehearse announce [<id or glob>…] [--draft] [--base] [--head] [--announce <file>] [--announce-from changesets] [--said <id>]… [--format yaml|changeset] --json`: what a comparison would read as announced (schema announce); with --draft (and compare's own options) it compares and proposes {scenario, why} for each scenario whose verdict is unsaid, its why the first difference, for you to rewrite as the reason. --format changeset prints an `announce` block for a changeset. It writes no file; refuses with code not_compared when the base or head doesn't come up.
15
16
  - `rehearse drive start [--service <name> | --piece <id>] [--world] [--as <person>] [--scheme light|dark]` (or DRIVE_SCHEME), then `rehearse drive click --name <name> [--role <role>] | fill --name <name> --with <text> | type <text> | key <key> | snapshot [--name <name> [--role <role>]] | screenshot <file.png> | stop`, each with --json: the drive result shape {ok, command, ms, file, tree} plus v and driver (schema drive). Exit 0 done, 1 failed, 2 usage.
16
17
  - `rehearse record <file.flow.yaml> --from-drive [--name <words>] [--force] --json`: writes the steps the current or latest drive took as a flow, every step by accessible name, then `rehearse run <file>` runs it (schema record: {file, from, replaced, steps, warnings}, each warning with the line it points to). It keeps each click, fill, type and key that worked, and each `snapshot --name` as a check the element is there; it leaves out failed steps and looks. The drive's steps are kept in .rehearse/drive-steps.jsonl until the next drive start. Without --from-drive, `rehearse record <file> [--service] [--world] [--as] [--start]` opens a Chromium window and records what a person clicks, fills, chooses and presses until the window closes or Ctrl-C. Rehearse keeps typed text only for plain fields it can see (native text, email, search, url, tel and number inputs and textareas, not secret, checked again when the step is written): a secret field (ever a password, a secret autocomplete, -webkit-text-security, or a name, label, placeholder or title saying pass, secret, token, key, pin, otp…) is written as `<password>`, anything else (custom elements, role=textbox, contenteditable, closed shadow roots, a service's own driver) as `<not recorded>`, each with a warning at its line that never quotes the text; text holding `{{` gets `literal: true`, the person's own token is written as `{{token}}`, and any other form of a token is kept out. A role and name more than one element has keeps its step with a warning. Refuses with code exists when the file is there (--force replaces it), and no_steps when there is nothing to write.
17
- - `rehearse stage [--base] [--head] [--port] [--announce <file>] [--announce-from changesets] [--said <id>]…`: the stage on 127.0.0.1 (default port 4400): every scenario in Base, Head and Diff, with Works, Doesn't and a note (kept in .rehearse/tries.jsonl, schema try).
18
+ - `rehearse stage [--base] [--head] [--base-repository]… [--head-repository]… [--port] [--announce <file>] [--announce-from changesets] [--said <id>]…`: the stage on 127.0.0.1 (default port 4400): every scenario in Base, Head and Diff, with Works, Doesn't and a note (kept in .rehearse/tries.jsonl, schema try).
18
19
  - `rehearse stage --static <dir> [--base <ref>] [--json]`: writes the stage of the latest comparison of this checkout with the base (the newer of .rehearse/compare/latest.json and latest-partial.json; --base as compare was given it) into <dir> as plain files with relative addresses, for any static host, such as a pull request's preview, then exits (schema static). It runs nothing; Run, Compare, Send, Works and a piece's live canvas aren't there. For a public preview it turns local paths (the checkouts, the home folder, and any /home/<name>, /Users/<name>, /root or C:\Users\<name>, also JSON-escaped or percent-encoded) into {{checkout}} and ~, copies an input only when git tracks it unchanged, copies from .rehearse only what runs made, and copies anything but a PNG, JPEG, WebP or GIF as scrubbed plain text; a home with a space in its name can slip through, so read a copy made on your own machine before publishing it. --base matches a ref by name and a folder by path; the newer comparison is the one written later. Refuses with code no_comparison when there is no comparison of this checkout with the base it can read, and exists when <dir> holds files an earlier copy didn't write.
19
20
  - `rehearse open <scenario> [--json]`: the stage's address for a scenario (schema open), starting the stage if none runs.
20
21
  - `rehearse clean [--all]`: removes old base checkouts, runs and comparisons (schema clean).
@@ -33,12 +34,12 @@
33
34
  - same: as on the base. said: changed and said so (announced, or its own definition edited, unless it is a file scenario with contract: true; announced wins). unsaid: changed without saying so. new: not on the base. fails: fails on the head (failsOnBase: it fails on the base too, so not this change's doing).
34
35
  - Ids, times and opaque tokens are set aside before comparing; arrays keep their order unless a scenario says unordered; a comparison counts what it set aside.
35
36
  - A change announces what it expects to change in .rehearse/announce.yaml beside rehearse.yaml (schema announce): changes: [{scenario: <id or glob>, why: <one line>}].
36
- - The base's observations are cached by commit under .rehearse/cache, so each base commit runs once; scenarios that share services in a world are cached and run as a group; --fresh runs again.
37
+ - The base's observations are cached by commit (and by the commit of each other repository's copy) under .rehearse/cache, so each base commit runs once; scenarios that share services in a world are cached and run as a group; --fresh runs again.
37
38
 
38
39
  ## Schemas (schema/v1/)
39
40
 
40
41
  - manifest.schema.json: rehearse.yaml. flow.schema.json: *.flow.yaml. file-scenario.schema.json: *.rehearse.yaml. announce.schema.json: announcements, and what `rehearse announce --json` prints.
41
- - check, init, services, people, worlds, list, up, observation, comparison, drive, record, open, static, try, clean, validate, error: one per command's --json output, each with a sample in schema/v1/samples/.
42
+ - check, init, services, keys, people, worlds, list, up, observation, comparison, drive, record, open, static, try, clean, validate, error: one per command's --json output, each with a sample in schema/v1/samples/.
42
43
  - dependents.schema.json: what Rehearse reads from an import graph (`ashlar dependents <files> --json`, or the manifest's affected.graph).
43
44
  - Within v1 an output only gains optional fields, and open string fields may gain values: readers ignore what they don't know.
44
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kurvball/rehearse",
3
- "version": "1.13.3",
3
+ "version": "1.15.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": {
@@ -83,7 +83,7 @@
83
83
  "docs:dev": "pnpm --filter rehearse-docs dev",
84
84
  "rehearse": "node dist/cli.js",
85
85
  "changeset": "changeset",
86
- "release:version": "changeset version && node scripts/changelog.ts && node docs/scripts/since.ts && prettier --write CHANGELOG.md package.json",
86
+ "release:version": "changeset version && node scripts/changelog.ts && node docs/scripts/since.ts && prettier --write CHANGELOG.md package.json docs/reference docs/src/content/docs",
87
87
  "release:publish": "node scripts/release.ts"
88
88
  }
89
89
  }
@@ -61,6 +61,23 @@
61
61
  }
62
62
  }
63
63
  },
64
+ "copy": {
65
+ "description": "A copy of one of the manifest's other repositories.",
66
+ "type": "object",
67
+ "required": ["path"],
68
+ "properties": {
69
+ "path": { "description": "The copy's folder, or the folder given as it is.", "type": "string" },
70
+ "ref": {
71
+ "description": "The ref it was asked for, or null for a folder given.",
72
+ "type": ["string", "null"]
73
+ },
74
+ "commit": { "description": "The commit it holds.", "type": ["string", "null"] },
75
+ "dirty": {
76
+ "description": "Whether it holds uncommitted changes to tracked files. A run with one is never cached.",
77
+ "type": "boolean"
78
+ }
79
+ }
80
+ },
64
81
  "checkout": {
65
82
  "type": "object",
66
83
  "required": ["path"],
@@ -80,6 +97,11 @@
80
97
  "dirty": {
81
98
  "description": "Whether it holds uncommitted changes. A dirty checkout is never cached.",
82
99
  "type": "boolean"
100
+ },
101
+ "repositories": {
102
+ "description": "The copy of each of the manifest's other repositories that its services ran in, by name: its folder, the ref asked for, its commit and whether it holds changes.",
103
+ "type": "object",
104
+ "additionalProperties": { "$ref": "#/$defs/copy" }
83
105
  }
84
106
  }
85
107
  },
@@ -40,6 +40,7 @@
40
40
  "prepare",
41
41
  "build",
42
42
  "service",
43
+ "key",
43
44
  "pieces",
44
45
  "flows",
45
46
  "calls",
@@ -50,7 +51,7 @@
50
51
  ]
51
52
  },
52
53
  "name": {
53
- "description": "The service's name in the manifest, for a service it wrote.",
54
+ "description": "The name it wrote in the manifest, for a service or a key.",
54
55
  "type": "string"
55
56
  },
56
57
  "from": {