@antelopejs/dms 0.18.0 → 0.18.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +3 -3
  3. package/bin/control/backend-records.test.mjs +276 -0
  4. package/bin/control/backend.mjs +212 -0
  5. package/bin/control/backend.test.mjs +325 -0
  6. package/bin/control/base.mjs +3 -7
  7. package/bin/control/browser-client.mjs +6 -4
  8. package/bin/control/browser.mjs +173 -36
  9. package/bin/control/build-cache.mjs +394 -0
  10. package/bin/control/build-cache.test.mjs +270 -0
  11. package/bin/control/build-inputs.mjs +172 -0
  12. package/bin/control/build-key-refusals.test.mjs +138 -0
  13. package/bin/control/build-key.mjs +479 -0
  14. package/bin/control/build-key.test.mjs +392 -0
  15. package/bin/control/build-layout.test.mjs +314 -0
  16. package/bin/control/commands-stack.mjs +46 -6
  17. package/bin/control/commands-verify.mjs +9 -2
  18. package/bin/control/doctor.mjs +87 -16
  19. package/bin/control/forwarder.mjs +86 -0
  20. package/bin/control/forwarder.test.mjs +141 -0
  21. package/bin/control/frontend-check.mjs +54 -0
  22. package/bin/control/frontend-workspace.mjs +150 -0
  23. package/bin/control/frontend-workspace.test.mjs +133 -0
  24. package/bin/control/helpers/env.mjs +21 -0
  25. package/bin/control/helpers/evidence.mjs +13 -0
  26. package/bin/control/helpers/fake-run.mjs +290 -0
  27. package/bin/control/helpers/key-fixture.mjs +82 -0
  28. package/bin/control/helpers/pids.mjs +27 -0
  29. package/bin/control/helpers/repo.mjs +13 -0
  30. package/bin/control/helpers/tree.mjs +40 -0
  31. package/bin/control/identity.mjs +238 -0
  32. package/bin/control/identity.test.mjs +166 -0
  33. package/bin/control/journey.mjs +64 -16
  34. package/bin/control/journey.test.mjs +60 -2
  35. package/bin/control/namespaces.test.mjs +211 -0
  36. package/bin/control/options.mjs +2 -0
  37. package/bin/control/pid-guard.test.mjs +202 -0
  38. package/bin/control/prepared-workspace.mjs +20 -0
  39. package/bin/control/processes.mjs +122 -33
  40. package/bin/control/processes.test.mjs +255 -0
  41. package/bin/control/renderer.test.mjs +2 -1
  42. package/bin/control/run-copy.mjs +77 -0
  43. package/bin/control/run-state.mjs +142 -16
  44. package/bin/control/stack.mjs +259 -210
  45. package/bin/control/tab.mjs +13 -6
  46. package/bin/control/tab.test.mjs +444 -0
  47. package/bin/control/timing.mjs +244 -0
  48. package/bin/control/timing.test.mjs +197 -0
  49. package/bin/control/verify/decode.mjs +34 -21
  50. package/bin/control/verify/decode.test.mjs +39 -0
  51. package/bin/control/verify/doors.test.mjs +2 -0
  52. package/bin/control/verify/map.mjs +57 -7
  53. package/bin/control/verify/map.test.mjs +264 -0
  54. package/bin/control/verify/skill.mjs +12 -3
  55. package/bin/control/verify/types.mjs +2 -2
  56. package/bin/control/verify/verdict.mjs +37 -7
  57. package/bin/dms-control.mjs +14 -6
  58. package/frontend-vue/layers/dms-layout/app/components/layout/DashboardSearch.vue +24 -1
  59. package/package.json +1 -1
  60. package/skills/dms-project/SKILL.md +6 -3
@@ -0,0 +1,166 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawnSync } from "node:child_process";
3
+ import { join } from "node:path";
4
+ import test from "node:test";
5
+ import {
6
+ decode,
7
+ isBoolean,
8
+ isNumber,
9
+ isString,
10
+ nullable,
11
+ objectOf,
12
+ } from "./json.mjs";
13
+ import { newRun } from "./helpers/fake-run.mjs";
14
+
15
+ const CONTROL_BIN = join(import.meta.dirname, "..", "dms-control.mjs");
16
+ const INSIDE_TIMEOUT_MS = 60_000;
17
+
18
+ /**
19
+ * Runs in a PID namespace that mounted no /proc of its own, so /proc shows
20
+ * the processes of the namespace around it. It records a process of its own
21
+ * with the start time /proc gives for its pid, as a run started there
22
+ * would, runs `dms-control down` on the run, then tries to start a process,
23
+ * and prints what happened.
24
+ */
25
+ const INSIDE = `
26
+ import { spawn, spawnSync } from "node:child_process";
27
+ import { readFileSync } from "node:fs";
28
+ import { setTimeout as sleep } from "node:timers/promises";
29
+ const [bin, dir] = process.argv.slice(1);
30
+ const control = new URL("./control/", "file://" + bin);
31
+ const { startDetached } = await import(new URL("processes.mjs", control));
32
+ const { loadRun, saveRun } = await import(new URL("run-state.mjs", control));
33
+ const other = spawn(process.execPath, ["-e", "setInterval(() => {}, 1000)"], { stdio: "ignore" });
34
+ let startTime = null;
35
+ try {
36
+ const stat = readFileSync("/proc/" + other.pid + "/stat", "utf8");
37
+ startTime = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19]);
38
+ } catch {}
39
+ const state = loadRun(dir);
40
+ state.processes = [{ name: "frontend", pid: other.pid, startTime, command: "x", cwd: dir, log: "/dev/null", startedAt: new Date().toISOString() }];
41
+ saveRun(state);
42
+ const down = spawnSync(process.execPath, [bin, "down", dir], { encoding: "utf8" });
43
+ await sleep(200);
44
+ let start = "started";
45
+ try {
46
+ startDetached({ name: "inside", program: process.execPath, args: ["-e", ""], cwd: dir, env: process.env, logs: dir });
47
+ } catch (error) {
48
+ start = error.message;
49
+ }
50
+ console.log(JSON.stringify({ down: down.status, stderr: down.stderr, signal: other.signalCode, start }));
51
+ process.exit(0);
52
+ `;
53
+
54
+ const isReport = objectOf({
55
+ down: nullable(isNumber),
56
+ stderr: isString,
57
+ signal: nullable(isString),
58
+ start: isString,
59
+ });
60
+
61
+ /** @returns {boolean} True where the test may make a user and PID namespace */
62
+ function canUnshare() {
63
+ return spawnSync("unshare", ["-Ur", "--fork", "--pid", "true"]).status === 0;
64
+ }
65
+
66
+ await test(
67
+ "where /proc is not this PID namespace's, down and a start refuse and say why, and the process a record names is not signalled; a version that trusts that /proc signals it",
68
+ {
69
+ skip:
70
+ !canUnshare() &&
71
+ "this host does not let the test make a user and PID namespace",
72
+ },
73
+ async (t) => {
74
+ const state = await newRun(t);
75
+ const inside = spawnSync(
76
+ "unshare",
77
+ [
78
+ "-Ur",
79
+ "--fork",
80
+ "--pid",
81
+ process.execPath,
82
+ "--input-type=module",
83
+ "-e",
84
+ INSIDE,
85
+ CONTROL_BIN,
86
+ state.dir,
87
+ ],
88
+ { encoding: "utf8", timeout: INSIDE_TIMEOUT_MS },
89
+ );
90
+ /** @type {unknown} */
91
+ const parsed = JSON.parse(inside.stdout);
92
+ const report = decode(isReport, parsed, inside.stderr, "a report");
93
+ assert.equal(report.signal, null);
94
+ assert.equal(report.down, 1);
95
+ assert.match(report.stderr, /is not this PID namespace's/);
96
+ assert.equal(report.stderr.split("\n").filter(Boolean).length, 1);
97
+ assert.match(report.start, /is not this PID namespace's/);
98
+ },
99
+ );
100
+
101
+ /**
102
+ * Runs where /proc is hidden behind an empty mount, as on a system with no
103
+ * /proc: it starts a process the way a run does, records it, and runs
104
+ * `dms-control down` on the run.
105
+ */
106
+ const WITHOUT_PROC = `
107
+ import { spawnSync } from "node:child_process";
108
+ import { setTimeout as sleep } from "node:timers/promises";
109
+ const [bin, dir] = process.argv.slice(1);
110
+ const control = new URL("./control/", "file://" + bin);
111
+ const { startDetached } = await import(new URL("processes.mjs", control));
112
+ const { loadRun, saveRun } = await import(new URL("run-state.mjs", control));
113
+ const own = startDetached({ name: "own", program: "sleep", args: ["60"], cwd: dir, env: process.env, logs: dir });
114
+ const state = loadRun(dir);
115
+ state.processes = [own];
116
+ saveRun(state);
117
+ const down = spawnSync(process.execPath, [bin, "down", dir], { encoding: "utf8" });
118
+ await sleep(300);
119
+ let alive = true;
120
+ try { process.kill(own.pid, 0); } catch { alive = false; }
121
+ console.log(JSON.stringify({ down: down.status, stderr: down.stderr, alive }));
122
+ process.exit(0);
123
+ `;
124
+
125
+ const isBareReport = objectOf({
126
+ down: nullable(isNumber),
127
+ stderr: isString,
128
+ alive: isBoolean,
129
+ });
130
+
131
+ await test(
132
+ "on a system with no /proc, a run's own process is still stopped by its pid, as before; refusing whenever /proc is missing leaves every run running on such systems",
133
+ {
134
+ skip:
135
+ !canUnshare() &&
136
+ "this host does not let the test make a user and PID namespace",
137
+ },
138
+ async (t) => {
139
+ const state = await newRun(t);
140
+ const inside = spawnSync(
141
+ "unshare",
142
+ [
143
+ "-Ur",
144
+ "--fork",
145
+ "--pid",
146
+ "--mount",
147
+ "sh",
148
+ "-c",
149
+ 'mount -t tmpfs none /proc && exec "$@"',
150
+ "sh",
151
+ process.execPath,
152
+ "--input-type=module",
153
+ "-e",
154
+ WITHOUT_PROC,
155
+ CONTROL_BIN,
156
+ state.dir,
157
+ ],
158
+ { encoding: "utf8", timeout: INSIDE_TIMEOUT_MS },
159
+ );
160
+ /** @type {unknown} */
161
+ const parsed = JSON.parse(inside.stdout.trim().split("\n").at(-1) ?? "{}");
162
+ const report = decode(isBareReport, parsed, inside.stderr, "a report");
163
+ assert.equal(report.down, 0, report.stderr);
164
+ assert.equal(report.alive, false, report.stderr);
165
+ },
166
+ );
@@ -3,7 +3,7 @@ import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { join, relative } from "node:path";
4
4
  import { pathToFileURL } from "node:url";
5
5
  import { withBaseBackend } from "./base.mjs";
6
- import { launchBrowser, newContext } from "./browser.mjs";
6
+ import { launchBrowser, newContext, screenshot } from "./browser.mjs";
7
7
  import { capturedMail } from "./mail.mjs";
8
8
  import { isRecord, isString, readRecordList } from "./json.mjs";
9
9
  import { saveRun } from "./run-state.mjs";
@@ -14,13 +14,14 @@ import {
14
14
  onboard,
15
15
  recordedRequest,
16
16
  } from "./session.mjs";
17
+ import { ensureMail, resolutionFolders } from "./stack.mjs";
17
18
  import {
18
- ensureMail,
19
+ assertForwardedRun,
19
20
  freshDatabase,
20
- resolutionFolders,
21
21
  restartBackend,
22
- } from "./stack.mjs";
22
+ } from "./backend.mjs";
23
23
  import { Tab } from "./tab.mjs";
24
+ import { recordTiming, stopwatch, timed } from "./timing.mjs";
24
25
 
25
26
  /**
26
27
  * @typedef {{ name: string, pass: boolean, detail: string }} Check
@@ -127,6 +128,8 @@ export class JourneyContext {
127
128
  /** @type {Map<string, import("playwright-core").BrowserContext>} */
128
129
  this.contexts = new Map();
129
130
  this.index = 0;
131
+ /** @type {Tab | undefined} */
132
+ this.lastTab = undefined;
130
133
  this.startedAt = new Date().toISOString();
131
134
  this.equal = equal;
132
135
  this.status = status;
@@ -175,7 +178,9 @@ export class JourneyContext {
175
178
 
176
179
  /**
177
180
  * Records a step of checks, which may be promises (`tab.visible(...)`).
178
- * With `{ critical: true }` a failure ends the journey.
181
+ * With `{ critical: true }` a failure ends the journey. Writes one
182
+ * `screenshot.png` of the tab driven last into the step folder, whatever
183
+ * the checks' outcome; before any tab was driven it writes none.
179
184
  *
180
185
  * @param {string} label What the step verifies
181
186
  * @param {(Check | Promise<Check>)[]} checks The checks, or promises of them
@@ -183,11 +188,12 @@ export class JourneyContext {
183
188
  * @returns {Promise<boolean>} Whether every check passed
184
189
  */
185
190
  async verify(label, checks, options = {}) {
186
- return this.record(
187
- this.step(label),
188
- await Promise.all(checks.map((check) => Promise.resolve(check))),
189
- options,
191
+ const folder = this.step(label);
192
+ const settled = await Promise.all(
193
+ checks.map((check) => Promise.resolve(check)),
190
194
  );
195
+ if (this.lastTab) await screenshot(this.lastTab.page, folder, this.state);
196
+ return this.record(folder, settled, options);
191
197
  }
192
198
 
193
199
  /**
@@ -352,18 +358,29 @@ export class JourneyContext {
352
358
  * @param {JourneyContext} context The journey's context
353
359
  */
354
360
  async function prepare(state, feature, journey, context) {
361
+ const detail = { feature, journey: journey.id };
355
362
  await ensureMail(state);
356
363
  if (journey.database !== "shared") {
357
364
  const index = String((state.journeyCount ?? 0) + 1).padStart(3, "0");
358
365
  state.journeyCount = Number(index);
359
- await freshDatabase(state, `j${index}`);
366
+ await timed(
367
+ state,
368
+ "fresh-database",
369
+ () => freshDatabase(state, `j${index}`),
370
+ detail,
371
+ );
360
372
  writeJson(join(context.step("fresh database"), "database.json"), {
361
373
  database: state.database,
362
374
  });
363
375
  }
364
376
  if (journey.onboard === false || state.accounts?.admin) return;
365
377
  const folder = context.step("onboard the administrator");
366
- const answer = await onboard(state, {});
378
+ const answer = await timed(
379
+ state,
380
+ "onboard",
381
+ () => onboard(state, {}),
382
+ detail,
383
+ );
367
384
  context.record(
368
385
  folder,
369
386
  [
@@ -395,7 +412,39 @@ async function prepare(state, feature, journey, context) {
395
412
  * @returns {Promise<FeatureResult>} The result
396
413
  */
397
414
  export async function runJourney(state, feature, journey, skill) {
398
- const browser = await launchBrowser(resolutionFolders(state));
415
+ const stop = stopwatch();
416
+ const detail = { feature, journey: journey.id };
417
+ /** @type {Omit<FeatureResult, "ms"> | undefined} */
418
+ let result;
419
+ let lap = { ms: 0, startedAt: "" };
420
+ try {
421
+ result = await driveJourney(state, feature, journey, skill);
422
+ } finally {
423
+ lap = stop();
424
+ recordTiming(state, "journey", lap, result?.status === "PASS", detail);
425
+ }
426
+ const timedResult = { ...result, ms: lap.ms };
427
+ writeJson(join(state.evidence, result.folder, "result.json"), timedResult);
428
+ return timedResult;
429
+ }
430
+
431
+ /**
432
+ * Drives one journey from its browser launch to its closed contexts.
433
+ *
434
+ * @param {import("./run-state.mjs").RunState} state The run
435
+ * @param {string} feature The feature it belongs to
436
+ * @param {Journey} journey The journey
437
+ * @param {import("./verify/skill.mjs").Skill} skill The skill the journey belongs to
438
+ * @returns {Promise<Omit<FeatureResult, "ms">>} The result, without its duration
439
+ */
440
+ async function driveJourney(state, feature, journey, skill) {
441
+ const detail = { feature, journey: journey.id };
442
+ const browser = await timed(
443
+ state,
444
+ "browser-launch",
445
+ () => launchBrowser(resolutionFolders(state)),
446
+ detail,
447
+ );
399
448
  const context = new JourneyContext(
400
449
  state,
401
450
  feature,
@@ -406,7 +455,7 @@ export async function runJourney(state, feature, journey, skill) {
406
455
  let error = null;
407
456
  try {
408
457
  await prepare(state, feature, journey, context);
409
- await journey.run(context);
458
+ await timed(state, "journey-run", () => journey.run(context), detail);
410
459
  } catch (failure) {
411
460
  error =
412
461
  failure instanceof JourneyAbort
@@ -419,7 +468,7 @@ export async function runJourney(state, feature, journey, skill) {
419
468
  const failed =
420
469
  error !== null ||
421
470
  context.steps.some((step) => step.checks.some((check) => !check.pass));
422
- const result = {
471
+ return {
423
472
  feature,
424
473
  journey: journey.id,
425
474
  title: journey.title,
@@ -430,8 +479,6 @@ export async function runJourney(state, feature, journey, skill) {
430
479
  error,
431
480
  folder: relative(state.evidence, context.folder),
432
481
  };
433
- writeJson(join(context.folder, "result.json"), result);
434
- return result;
435
482
  }
436
483
 
437
484
  /**
@@ -480,6 +527,7 @@ export async function loadJourneys(file) {
480
527
  * @returns {Promise<FeatureResult[]>} The results of this run
481
528
  */
482
529
  export async function runJourneyFile(state, request) {
530
+ assertForwardedRun(state);
483
531
  const journeys = await loadJourneys(request.file);
484
532
  const unknown = request.ids.filter(
485
533
  (id) => !journeys.some((journey) => journey.id === id),
@@ -1,9 +1,11 @@
1
1
  import assert from "node:assert/strict";
2
- import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
2
+ import { spawn } from "node:child_process";
3
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
4
  import { tmpdir } from "node:os";
4
5
  import { join } from "node:path";
5
6
  import test from "node:test";
6
- import { loadJourneys } from "./journey.mjs";
7
+ import { loadJourneys, runJourney, runJourneyFile } from "./journey.mjs";
8
+ import { readTimings } from "./timing.mjs";
7
9
 
8
10
  const JOURNEY = '{ id: "smoke", title: "t", entryPoint: "e", async run() {} }';
9
11
 
@@ -59,3 +61,59 @@ await test("a journey missing a field a run reads is refused", async (t) => {
59
61
  );
60
62
  }
61
63
  });
64
+
65
+ await test("a journey whose browser fails to launch still records its journey entry, failed; recording it only after a normal return leaves the run's total blind to it", async (t) => {
66
+ const dir = mkdtempSync(join(tmpdir(), "dms-control-journey-timing-"));
67
+ t.after(() => rmSync(dir, { recursive: true, force: true }));
68
+ const evidence = join(dir, "evidence");
69
+ mkdirSync(evidence);
70
+ const previous = process.env.PLAYWRIGHT_BROWSERS_PATH;
71
+ process.env.PLAYWRIGHT_BROWSERS_PATH = join(dir, "no-browsers");
72
+ t.after(() => {
73
+ if (previous === undefined) delete process.env.PLAYWRIGHT_BROWSERS_PATH;
74
+ else process.env.PLAYWRIGHT_BROWSERS_PATH = previous;
75
+ });
76
+ const state = {
77
+ dir,
78
+ evidence,
79
+ playground: dir,
80
+ moduleRoot: dir,
81
+ accounts: {},
82
+ };
83
+ const journey = {
84
+ id: "j1",
85
+ title: "t",
86
+ entryPoint: "e",
87
+ database: "shared",
88
+ onboard: false,
89
+ async run() {},
90
+ };
91
+ await assert.rejects(runJourney(state, "feat", journey, {}));
92
+ const entry = readTimings(evidence).find((line) => line.phase === "journey");
93
+ assert.deepEqual(entry && [entry.ok, entry.feature, entry.journey], [
94
+ false,
95
+ "feat",
96
+ "j1",
97
+ ]);
98
+ });
99
+
100
+ await test("a run whose backend holds the API port itself is refused before its journeys load", async (t) => {
101
+ const old = spawn(process.execPath, ["-e", "setInterval(() => {}, 1000)"], {
102
+ stdio: "ignore",
103
+ });
104
+ t.after(() => old.kill());
105
+ assert.ok(old.pid !== undefined && old.pid > 1, "the old backend started");
106
+ const state = {
107
+ apiPort: 5010,
108
+ processes: [{ name: "backend", pid: old.pid, port: 5010 }],
109
+ };
110
+ await assert.rejects(
111
+ runJourneyFile(state, {
112
+ file: journeysModule(t, `export const journeys = [${JOURNEY}];`),
113
+ feature: "smoke",
114
+ ids: [],
115
+ skill: { config: {} },
116
+ }),
117
+ { message: "this run was started by an older dms-control; run `up` again" },
118
+ );
119
+ });
@@ -0,0 +1,211 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawn, spawnSync } from "node:child_process";
3
+ import { existsSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { createInterface } from "node:readline";
6
+ import test from "node:test";
7
+ import { bystander, newRun, storedRun } from "./helpers/fake-run.mjs";
8
+ import { currentNamespaces, isRunning, startTimeOf } from "./identity.mjs";
9
+ import {
10
+ decode,
11
+ isBoolean,
12
+ isNumber,
13
+ isString,
14
+ nullable,
15
+ objectOf,
16
+ } from "./json.mjs";
17
+ import { saveRun } from "./run-state.mjs";
18
+
19
+ const CONTROL_BIN = join(import.meta.dirname, "..", "dms-control.mjs");
20
+ const NESTED_TIMEOUT_MS = 60_000;
21
+ const BOOTTIME_OFFSET_S = "1000";
22
+
23
+ /**
24
+ * Runs in a PID namespace of its own, as `up` would there: it starts a
25
+ * process the way a run does, records it with the namespaces it runs in,
26
+ * says `ready`, waits for a line on stdin, then runs `dms-control down` on
27
+ * the run from inside and reports whether its process ran before and after.
28
+ */
29
+ const NESTED = `
30
+ import { spawnSync } from "node:child_process";
31
+ import { createInterface } from "node:readline";
32
+ import { setTimeout as sleep } from "node:timers/promises";
33
+ const [bin, dir] = process.argv.slice(1);
34
+ const control = new URL("./control/", "file://" + bin);
35
+ const { startDetached } = await import(new URL("processes.mjs", control));
36
+ const { currentNamespaces, isRunning } = await import(new URL("identity.mjs", control));
37
+ const { loadRun, saveRun } = await import(new URL("run-state.mjs", control));
38
+ const own = startDetached({ name: "own", program: "sleep", args: ["60"], cwd: dir, env: process.env, logs: dir });
39
+ const state = loadRun(dir);
40
+ state.namespaces = currentNamespaces();
41
+ state.processes = [own];
42
+ saveRun(state);
43
+ const lines = createInterface({ input: process.stdin })[Symbol.asyncIterator]();
44
+ console.log("ready");
45
+ await lines.next();
46
+ const before = isRunning(own.pid);
47
+ const down = spawnSync(process.execPath, [bin, "down", dir], { encoding: "utf8" });
48
+ await sleep(200);
49
+ console.log(JSON.stringify({ before, down: down.status, stderr: down.stderr, after: isRunning(own.pid) }));
50
+ process.exit(0);
51
+ `;
52
+
53
+ const isNestedReport = objectOf({
54
+ before: isBoolean,
55
+ down: nullable(isNumber),
56
+ stderr: isString,
57
+ after: isBoolean,
58
+ });
59
+
60
+ /** @returns {boolean} True where the test may make a user and PID namespace */
61
+ function canUnshare() {
62
+ return (
63
+ spawnSync("unshare", ["-Ur", "--fork", "--pid", "--mount-proc", "true"])
64
+ .status === 0
65
+ );
66
+ }
67
+
68
+ /** @returns {boolean} True where the test may make a user and time namespace */
69
+ function canUnshareTime() {
70
+ return (
71
+ spawnSync("unshare", ["-Ur", "--time", "--boottime", "1", "true"])
72
+ .status === 0
73
+ );
74
+ }
75
+
76
+ await test(
77
+ "down run outside the PID namespace the run was started in refuses and changes nothing; inside it, down stops the run's process; a version without the check exits 0, forgets the process and leaves it running",
78
+ {
79
+ skip:
80
+ !canUnshare() && "this host does not let the test make a PID namespace",
81
+ timeout: NESTED_TIMEOUT_MS,
82
+ },
83
+ async (t) => {
84
+ const state = await newRun(t);
85
+ const nested = spawn(
86
+ "unshare",
87
+ [
88
+ "-Ur",
89
+ "--fork",
90
+ "--pid",
91
+ "--mount-proc",
92
+ process.execPath,
93
+ "--input-type=module",
94
+ "-e",
95
+ NESTED,
96
+ CONTROL_BIN,
97
+ state.dir,
98
+ ],
99
+ { stdio: ["pipe", "pipe", "inherit"] },
100
+ );
101
+ t.after(() => nested.kill("SIGKILL"));
102
+ const lines = createInterface({ input: nested.stdout })[
103
+ Symbol.asyncIterator
104
+ ]();
105
+ assert.equal((await lines.next()).value, "ready");
106
+ const recorded = storedRun(state.dir);
107
+
108
+ const outside = spawnSync(
109
+ process.execPath,
110
+ [CONTROL_BIN, "down", state.dir],
111
+ {
112
+ encoding: "utf8",
113
+ },
114
+ );
115
+ assert.equal(outside.status, 1, outside.stderr);
116
+ assert.match(
117
+ outside.stderr,
118
+ /this run was started in another PID namespace \(run: pid:\[\d+\]; here: pid:\[\d+\]\); run this command there/,
119
+ );
120
+ assert.equal(storedRun(state.dir), recorded);
121
+ assert.ok(
122
+ existsSync(state.home),
123
+ "down from outside keeps the run's folders",
124
+ );
125
+
126
+ nested.stdin.write("go\n");
127
+ /** @type {unknown} */
128
+ const parsed = JSON.parse(String((await lines.next()).value));
129
+ const report = decode(isNestedReport, parsed, "the nested run", "a report");
130
+ assert.equal(
131
+ report.before,
132
+ true,
133
+ "the run's process outlives the refused down",
134
+ );
135
+ assert.equal(report.down, 0, report.stderr);
136
+ assert.equal(report.after, false, "down inside stops the run's process");
137
+ },
138
+ );
139
+
140
+ await test(
141
+ "down run in another time namespace refuses and changes nothing; a version without the check reads every start time shifted, exits 0 and forgets the process while it runs",
142
+ {
143
+ skip:
144
+ !canUnshareTime() &&
145
+ "this host does not let the test make a time namespace",
146
+ },
147
+ async (t) => {
148
+ const state = await newRun(t);
149
+ const pid = bystander(t);
150
+ Object.assign(state, {
151
+ namespaces: currentNamespaces(),
152
+ processes: [
153
+ {
154
+ name: "frontend",
155
+ pid,
156
+ startTime: startTimeOf(pid),
157
+ command: "node",
158
+ cwd: state.dir,
159
+ log: join(state.logs, "frontend.log"),
160
+ startedAt: new Date().toISOString(),
161
+ },
162
+ ],
163
+ });
164
+ saveRun(state);
165
+ const recorded = storedRun(state.dir);
166
+
167
+ const shifted = spawnSync(
168
+ "unshare",
169
+ [
170
+ "-Ur",
171
+ "--time",
172
+ "--boottime",
173
+ BOOTTIME_OFFSET_S,
174
+ process.execPath,
175
+ CONTROL_BIN,
176
+ "down",
177
+ state.dir,
178
+ ],
179
+ { encoding: "utf8" },
180
+ );
181
+ assert.equal(shifted.status, 1, shifted.stderr);
182
+ assert.match(
183
+ shifted.stderr,
184
+ /this run was started in another time namespace \(run: time:\[\d+\]; here: time:\[\d+\]\); run this command there/,
185
+ );
186
+ assert.equal(storedRun(state.dir), recorded);
187
+ assert.equal(isRunning(pid), true);
188
+ },
189
+ );
190
+
191
+ await test("a run that recorded no namespaces, as an earlier dms-control wrote it, is still stopped by down", async (t) => {
192
+ const state = await newRun(t);
193
+ const pid = bystander(t);
194
+ state.processes = [
195
+ {
196
+ name: "frontend",
197
+ pid,
198
+ startTime: startTimeOf(pid),
199
+ command: "node",
200
+ cwd: state.dir,
201
+ log: join(state.logs, "frontend.log"),
202
+ startedAt: new Date().toISOString(),
203
+ },
204
+ ];
205
+ saveRun(state);
206
+ const down = spawnSync(process.execPath, [CONTROL_BIN, "down", state.dir], {
207
+ encoding: "utf8",
208
+ });
209
+ assert.equal(down.status, 0, down.stderr);
210
+ assert.equal(isRunning(pid), false);
211
+ });
@@ -3,6 +3,8 @@
3
3
  */
4
4
  export const OPTIONS = /** @type {const} */ ({
5
5
  prepare: { type: "boolean" },
6
+ "no-standby": { type: "boolean" },
7
+ "no-build-cache": { type: "boolean" },
6
8
  playground: { type: "string" },
7
9
  renderer: { type: "string" },
8
10
  runs: { type: "string" },