@kurvball/rehearse 1.13.0 → 1.13.1

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.
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import { checkoutOf, manifestOf, said } from './command.js';
3
3
  import { many, one } from '../args.js';
4
4
  import { RehearseError } from '../errors.js';
5
- import { bringDown, bringUp, liveServices, makeRoom, release, runningServices, } from '../services/index.js';
5
+ import { bringDown, bringUp, handoverSettled, liveServices, makeRoom, release, runningServices, } from '../services/index.js';
6
6
  import { baseVars } from '../run/index.js';
7
7
  import { applyWorld } from '../worlds/index.js';
8
8
  import { overlay } from '../git/index.js';
@@ -43,6 +43,7 @@ export const up = {
43
43
  });
44
44
  running = [...running, r];
45
45
  }
46
+ await Promise.all(running.filter((r) => m.services[r.name]?.drive).map(handoverSettled));
46
47
  for (const r of running)
47
48
  release(r);
48
49
  if (world && fresh.length)
@@ -7,6 +7,7 @@ import { ambiguousWords, findNamed, namedIn, notFoundWords, sameWords, } from '.
7
7
  import { noteSecretsOn, rememberSecretFields, secretsHidden, secretsHiddenInWords } from './secrets.js';
8
8
  import { SECRETS } from './watcher.js';
9
9
  export const ACT_MS = 5_000;
10
+ const LOOK_AGAIN_MS = 100;
10
11
  const CALM_MS = 120;
11
12
  const CALM_LIMIT_MS = 4_000;
12
13
  export const FIXED_TIME = new Date('2026-01-15T12:00:00.000Z');
@@ -61,8 +62,19 @@ export async function calm(page) {
61
62
  }
62
63
  return last;
63
64
  }
64
- async function theOne(page, name, role) {
65
- const found = findNamed(namedIn(await treeOf(page)), name, role);
65
+ async function shownWithin(page, name, role) {
66
+ const begun = Date.now();
67
+ for (;;) {
68
+ const found = findNamed(namedIn(await treeOf(page)), name, role);
69
+ if (found.found !== 'none' || Date.now() - begun >= ACT_MS)
70
+ return found;
71
+ await new Promise((resolve) => setTimeout(resolve, LOOK_AGAIN_MS));
72
+ }
73
+ }
74
+ async function theOne(page, name, role, waits = true) {
75
+ const found = waits
76
+ ? await shownWithin(page, name, role)
77
+ : findNamed(namedIn(await treeOf(page)), name, role);
66
78
  if (found.found === 'none')
67
79
  throw new Stopped('not_found', await secretsHiddenInWords(page, notFoundWords(name, role, found.near)));
68
80
  if (found.found === 'many')
@@ -81,7 +93,7 @@ const optionsOf = (target) => target.evaluate((el) => (el instanceof HTMLSelectE
81
93
  const noOptionWords = (field, wanted, options) => `“${field}” has no option “${wanted}”. It has ${options.map((o) => `“${o}”`).join(', ') || 'none'}.`;
82
94
  export async function picks(page, name, role) {
83
95
  try {
84
- await theOne(page, name, role);
96
+ await theOne(page, name, role, false);
85
97
  return 'one';
86
98
  }
87
99
  catch (error) {
@@ -10,7 +10,7 @@ import { readScenarios, registerReader } from '../../scenarios/index.js';
10
10
  import { validate } from '../../schema.js';
11
11
  import { broken, registerRunner } from '../kind.js';
12
12
  import { startPieceServer } from '../piece/server.js';
13
- import { restart, restartable, stateDir } from '../../services/index.js';
13
+ import { handoverSettled, restart, restartable, stateDir } from '../../services/index.js';
14
14
  import { applyWorld } from '../../worlds/index.js';
15
15
  import { defaultExportOf, LiteralError } from './literal.js';
16
16
  const refuse = (says, line) => {
@@ -296,7 +296,7 @@ async function upAgainWhereTheWorldStarts(ctx, running) {
296
296
  const cantBeBroughtUpAfresh = (service, afterAnotherFlow) => `${service} can't be brought up afresh (it needs a down command, and an up that hands over to a daemon), so this flow started ${afterAnotherFlow ? 'where the last one left the app' : 'with the app as it found it'}.`;
297
297
  registerRunner({
298
298
  kind: 'flow',
299
- version: 'flow/5',
299
+ version: 'flow/6',
300
300
  services: (s) => (s.service ? [s.service] : []),
301
301
  async run(scenarios, asGiven) {
302
302
  let ctx = asGiven;
@@ -314,6 +314,7 @@ registerRunner({
314
314
  const freshAlready = !afterAnotherFlow && ctx.broughtUpAndUnused.has(svc.name);
315
315
  let shared = null;
316
316
  if (running && !freshAlready) {
317
+ await handoverSettled(running);
317
318
  if (!restartable(running))
318
319
  shared = cantBeBroughtUpAfresh(svc.name, afterAnotherFlow);
319
320
  else {
@@ -17,6 +17,7 @@ export type Seen = {
17
17
  plain: boolean;
18
18
  secret: boolean;
19
19
  value: string | null;
20
+ secretTyped?: string;
20
21
  long?: boolean;
21
22
  } | {
22
23
  kind: 'choice';
@@ -135,6 +135,7 @@ export function listenAsThePersonActs({ binding, secrets: secretsKey }) {
135
135
  plain,
136
136
  secret: looked.typed === 'password',
137
137
  value: plain ? el.value : null,
138
+ ...(looked.typed === 'password' && el.value && { secretTyped: el.value }),
138
139
  });
139
140
  }, true);
140
141
  window.addEventListener('change', (event) => {
@@ -74,8 +74,15 @@ function seenOf(v) {
74
74
  secret: s.secret,
75
75
  value: long || s.secret || !s.plain ? null : s.value,
76
76
  ...(long && { long: true }),
77
+ ...(isText(s.secretTyped) && s.secretTyped && { secretTyped: s.secretTyped }),
77
78
  };
78
79
  }
80
+ const withoutWhatWasTyped = (seen) => {
81
+ if (seen.kind !== 'text')
82
+ return seen;
83
+ const { secretTyped: _secretTyped, ...rest } = seen;
84
+ return rest;
85
+ };
79
86
  const EDITS_OR_MOVES_THE_CARET = new Set([
80
87
  'Backspace',
81
88
  'Delete',
@@ -191,10 +198,14 @@ export async function recordAPerson(m, checkout, w) {
191
198
  if (seen.kind !== 'text')
192
199
  for (const value of now)
193
200
  knownSecrets.add(value);
194
- return hiddenInWords(seen.name, [...knownSecrets, ...now]);
201
+ const typedElsewhere = [...typedSecrets]
202
+ .filter(([field]) => seen.kind !== 'text' || field !== seen.field)
203
+ .map(([, value]) => value);
204
+ return hiddenInWords(seen.name, [...knownSecrets, ...now, ...typedElsewhere]);
195
205
  };
196
206
  const keepTyped = async (seen, typed) => {
197
- const value = typed ? await typed : null;
207
+ const readAfter = typed ? await typed : null;
208
+ const value = (seen.kind === 'text' && seen.secretTyped) || readAfter;
198
209
  if (value && seen.kind === 'text')
199
210
  typedSecrets.set(seen.field, value);
200
211
  if (seen.kind === 'text' || seen.kind === 'unseen' || onlyEdits(seen))
@@ -239,7 +250,7 @@ export async function recordAPerson(m, checkout, w) {
239
250
  .then(async () => {
240
251
  await keepTyped(seen, typed);
241
252
  const hidden = read ? namesHidden(seen, read) : null;
242
- await taking.take(await namedSafely(seen, hidden), asItWas);
253
+ await taking.take(await namedSafely(withoutWhatWasTyped(seen), hidden), asItWas);
243
254
  })
244
255
  .catch(() => undefined)
245
256
  .then(lookAgainWhenIdle)
@@ -1,2 +1,2 @@
1
1
  export { alive, runningServices, stateDir, type Running } from './registry.ts';
2
- export { bringDown, bringUp, downStartedHere, freePort, inUse, liveServices, makeRoom, release, restart, restartable, standinsFor, } from './service.ts';
2
+ export { bringDown, bringUp, downStartedHere, freePort, handoverSettled, inUse, liveServices, makeRoom, release, restart, restartable, standinsFor, } from './service.ts';
@@ -1,2 +1,2 @@
1
1
  export { alive, runningServices, stateDir } from './registry.js';
2
- export { bringDown, bringUp, downStartedHere, freePort, inUse, liveServices, makeRoom, release, restart, restartable, standinsFor, } from './service.js';
2
+ export { bringDown, bringUp, downStartedHere, freePort, handoverSettled, inUse, liveServices, makeRoom, release, restart, restartable, standinsFor, } from './service.js';
@@ -18,6 +18,7 @@ export declare const stateDir: (manifestDir: string) => string;
18
18
  export declare const checkoutKey: (checkout: string) => string;
19
19
  export declare const alive: (pid: number) => boolean;
20
20
  export declare function remember(manifestDir: string, r: Running): void;
21
+ export declare function rememberIfStillUp(manifestDir: string, r: Running): void;
21
22
  export declare function forget(manifestDir: string, name: string, checkout: string): void;
22
23
  export declare function runningServices(manifestDir: string): Running[];
23
24
  export declare const runningOf: (manifestDir: string, name: string, checkout: string) => Running | null;
@@ -18,6 +18,17 @@ export function remember(manifestDir, r) {
18
18
  mkdirSync(registryDir(manifestDir), { recursive: true });
19
19
  writeFileSync(fileOf(manifestDir, r.name, r.checkout), `${JSON.stringify(r, null, 2)}\n`);
20
20
  }
21
+ export function rememberIfStillUp(manifestDir, r) {
22
+ const file = fileOf(manifestDir, r.name, r.checkout);
23
+ try {
24
+ const kept = JSON.parse(readFileSync(file, 'utf8'));
25
+ if (kept.pid === r.pid && kept.since === r.since)
26
+ remember(manifestDir, r);
27
+ }
28
+ catch {
29
+ return;
30
+ }
31
+ }
21
32
  export function forget(manifestDir, name, checkout) {
22
33
  rmSync(fileOf(manifestDir, name, checkout), { force: true });
23
34
  }
@@ -15,6 +15,7 @@ export interface UpOptions {
15
15
  export declare const logOf: (m: Manifest, name: string, checkout: string) => string;
16
16
  export declare function liveServices(m: Manifest, checkout?: string | null): Promise<Running[]>;
17
17
  export declare const restartable: (r: Running) => boolean;
18
+ export declare function handoverSettled(r: Running): Promise<void>;
18
19
  export declare function restart(m: Manifest, r: Running, whileDown?: () => Promise<void>): Promise<string | null>;
19
20
  export declare const release: (r: Running) => boolean;
20
21
  export declare function downStartedHere(): Promise<void>;
@@ -5,8 +5,9 @@ import path from 'node:path';
5
5
  import { RehearseError } from '../errors.js';
6
6
  import { sh, tail } from '../exec.js';
7
7
  import { fill, fillEnv } from '../manifest/index.js';
8
- import { alive, checkoutKey, forget, remember, runningServices, stateDir } from './registry.js';
8
+ import { alive, checkoutKey, forget, remember, rememberIfStillUp, runningServices, stateDir, } from './registry.js';
9
9
  const POLL_MS = 250;
10
+ const HANDOVER_MS = 1_000;
10
11
  const STOP_MS = 5_000;
11
12
  const TRIES_FOR_A_PORT_NOT_YET_HANDED_OUT = 20;
12
13
  const anyFreePort = () => new Promise((resolve, reject) => {
@@ -134,6 +135,17 @@ export async function liveServices(m, checkout = null) {
134
135
  return out;
135
136
  }
136
137
  export const restartable = (r) => !!(r.up && r.down && r.daemon);
138
+ const upsStillExiting = new WeakMap();
139
+ export async function handoverSettled(r) {
140
+ const still = upsStillExiting.get(r);
141
+ if (!still)
142
+ return;
143
+ let timer;
144
+ const windowCloses = new Promise((resolve) => (timer = setTimeout(resolve, still.until - Date.now())));
145
+ await Promise.race([still.exiting, windowCloses]);
146
+ clearTimeout(timer);
147
+ upsStillExiting.delete(r);
148
+ }
137
149
  function readyVarsOf(m, r) {
138
150
  return {
139
151
  checkout: r.checkout,
@@ -239,8 +251,10 @@ export async function bringUp(m, s, checkout, options) {
239
251
  });
240
252
  closeSync(out);
241
253
  let exited;
242
- child.on('exit', (code) => (exited = code));
243
- child.on('error', () => (exited = 127));
254
+ const exit = new Promise((resolve) => {
255
+ child.on('exit', (code) => resolve((exited = code)));
256
+ child.on('error', () => resolve((exited = 127)));
257
+ });
244
258
  child.unref();
245
259
  const pid = child.pid;
246
260
  if (pid === undefined) {
@@ -282,6 +296,17 @@ export async function bringUp(m, s, checkout, options) {
282
296
  running.starting = false;
283
297
  running.daemon = exited === 0;
284
298
  remember(m.dir, running);
299
+ const until = Date.now() + HANDOVER_MS;
300
+ if (exited === undefined)
301
+ upsStillExiting.set(running, {
302
+ until,
303
+ exiting: exit.then((code) => {
304
+ if (code !== 0 || Date.now() > until)
305
+ return;
306
+ running.daemon = true;
307
+ rememberIfStillUp(m.dir, running);
308
+ }),
309
+ });
285
310
  options.progress?.(`${s.name} is ready${url ? ` at ${url}` : ''} (${Date.now() - begun} ms).`);
286
311
  return running;
287
312
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kurvball/rehearse",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
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": {