@antelopejs/dms 0.18.0 → 0.18.2

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 (61) hide show
  1. package/CHANGELOG.md +49 -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 +14 -25
  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 -36
  50. package/bin/control/verify/decode.test.mjs +40 -14
  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 +34 -37
  57. package/bin/dms-control.mjs +13 -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
  61. package/bin/control/verify/publish.mjs +0 -186
@@ -0,0 +1,314 @@
1
+ import assert from "node:assert/strict";
2
+ import { cpSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import test from "node:test";
6
+ import { layOutFrontendBuild } from "./build-cache.mjs";
7
+ import { buildInputs, buildKey, sourceNames } from "./build-key.mjs";
8
+ import { PREPARED_WORKSPACE_REFUSED } from "./frontend-workspace.mjs";
9
+ import { setEnv } from "./helpers/env.mjs";
10
+ import { write } from "./helpers/repo.mjs";
11
+ import { namesIn, treeOf } from "./helpers/tree.mjs";
12
+ import { ExitError } from "./processes.mjs";
13
+
14
+ const PAGE = join("frontend-vue", "page.vue");
15
+ const SOURCE = join("frontend-modules", "page");
16
+ const REGISTRY = "generated-frontend-modules.json";
17
+
18
+ /**
19
+ * A checkout holding a module's page, an installed dms-frontend and a build
20
+ * cache. Each run copies the page into its workspace, as the dms-frontend
21
+ * setup does, with a registry naming its own folder and URL; its build
22
+ * serves the page its workspace holds.
23
+ *
24
+ * @param {import("node:test").TestContext} t The test
25
+ */
26
+ function fixture(t) {
27
+ const dir = mkdtempSync(join(tmpdir(), "dms-control-build-layout-test-"));
28
+ t.after(() => rmSync(dir, { recursive: true, force: true }));
29
+ setEnv(t, { XDG_CACHE_HOME: join(dir, "xdg") });
30
+ const checkout = join(dir, "checkout");
31
+ write(join(checkout, PAGE), "clean");
32
+ const frontend = join(dir, "dms-frontend");
33
+ write(join(frontend, "package.json"), '{"version":"0.10.0"}');
34
+ /** @param {string} workspace */
35
+ const copySources = (workspace) => {
36
+ cpSync(join(checkout, "frontend-vue"), join(workspace, SOURCE), {
37
+ recursive: true,
38
+ });
39
+ };
40
+ let port = 1000;
41
+ /**
42
+ * @param {{ runs?: string, prepare?: (workspace: string) => void, build?: (workspace: string, prepared: boolean) => void, useCache?: boolean }} [options]
43
+ */
44
+ const up = async (options = {}) => {
45
+ port += 1;
46
+ const runDir = join(options.runs ?? join(dir, "runs"), String(port));
47
+ const webUrl = `http://127.0.0.1:${port}`;
48
+ /** @type {Parameters<typeof layOutFrontendBuild>[0]} */
49
+ const state = {
50
+ environment: "docs",
51
+ extraEnv: {},
52
+ webUrl,
53
+ runPlayground: join(runDir, "playground"),
54
+ };
55
+ const workspace = join(state.runPlayground ?? "", ".dms-frontend");
56
+ /** @param {string} log */
57
+ const log = (log) => write(join(runDir, "logs", `${log}.log`), "ran\n");
58
+ /**
59
+ * @param {string} into
60
+ * @param {(workspace: string) => void} copy
61
+ */
62
+ const setUp = (into, copy) => {
63
+ copy(into);
64
+ write(join(into, REGISTRY), JSON.stringify({ into, webUrl }));
65
+ write(join(into, ".deps-hash"), "a\n");
66
+ write(join(into, "pnpm-lock.yaml"), "vue: 3.5.0\n");
67
+ };
68
+ /** @type {boolean[]} */
69
+ const builds = [];
70
+ await layOutFrontendBuild(
71
+ state,
72
+ frontend,
73
+ {
74
+ prepare: (into) => {
75
+ log("frontend-prepare");
76
+ setUp(into, options.prepare ?? copySources);
77
+ return Promise.resolve();
78
+ },
79
+ build: (prepared) => {
80
+ builds.push(prepared);
81
+ log("frontend-build");
82
+ if (!prepared) setUp(workspace, copySources);
83
+ options.build?.(workspace, prepared);
84
+ const page = treeOf(workspace)?.[join(SOURCE, "page.vue")] ?? "";
85
+ write(join(workspace, "dist", "index.html"), page);
86
+ return Promise.resolve();
87
+ },
88
+ },
89
+ options.useCache ?? true,
90
+ );
91
+ const laidOut = treeOf(workspace) ?? {};
92
+ return {
93
+ state,
94
+ workspace,
95
+ builds,
96
+ frontendBuild: state.frontendBuild,
97
+ served: laidOut[join("dist", "index.html")],
98
+ registry: laidOut[REGISTRY],
99
+ };
100
+ };
101
+ return { dir, checkout, frontend, up };
102
+ }
103
+
104
+ await test("a run restores the build of the sources it set up into its own workspace, and builds when they changed", async (t) => {
105
+ const { checkout, up } = fixture(t);
106
+ const first = await up();
107
+ assert.deepEqual(
108
+ first.builds,
109
+ [true],
110
+ "a miss builds in the workspace the key was read from",
111
+ );
112
+ const second = await up();
113
+ assert.equal(
114
+ second.frontendBuild?.cached,
115
+ true,
116
+ "a cache never read saves nothing",
117
+ );
118
+ assert.deepEqual(second.builds, []);
119
+ assert.equal(second.served, "clean");
120
+ assert.match(
121
+ second.registry,
122
+ /"webUrl":"http:\/\/127.0.0.1:1002"/u,
123
+ "restoring the builder's sources over the run's serves the builder's registry",
124
+ );
125
+ write(join(checkout, PAGE), "edited");
126
+ const edited = await up();
127
+ assert.equal(edited.frontendBuild?.cached, false);
128
+ assert.equal(
129
+ edited.served,
130
+ "edited",
131
+ "a key that missed the edit serves the old page",
132
+ );
133
+ });
134
+
135
+ await test("an edit present only while a run copies its sources is keyed with them, so a clean run never serves it", async (t) => {
136
+ const { checkout, up } = fixture(t);
137
+ const edited = await up({
138
+ prepare: (workspace) => {
139
+ write(join(checkout, PAGE), "RV787-STALE");
140
+ cpSync(join(checkout, "frontend-vue"), join(workspace, SOURCE), {
141
+ recursive: true,
142
+ });
143
+ write(join(checkout, PAGE), "clean");
144
+ },
145
+ });
146
+ assert.equal(edited.served, "RV787-STALE");
147
+ const clean = await up();
148
+ assert.notEqual(clean.frontendBuild?.key, edited.frontendBuild?.key);
149
+ assert.equal(
150
+ clean.served,
151
+ "clean",
152
+ "a key read off the checkout before and after the build stores the edited build as the clean one",
153
+ );
154
+ assert.equal((await up()).served, "clean");
155
+ });
156
+
157
+ await test("a build whose workspace sources change while it builds is not stored", async (t) => {
158
+ const { up } = fixture(t);
159
+ const changed = await up({
160
+ build: (workspace) => write(join(workspace, SOURCE, "page.vue"), "late"),
161
+ });
162
+ assert.match(
163
+ changed.frontendBuild?.reason ?? "",
164
+ /changed while it built/u,
165
+ "storing under the key read before the build caches a build of other sources",
166
+ );
167
+ const next = await up();
168
+ assert.equal(next.frontendBuild?.cached, false);
169
+ assert.equal(next.served, "clean");
170
+ });
171
+
172
+ await test("a cache that cannot be written leaves the run built and says why", async (t) => {
173
+ const { dir, up } = fixture(t);
174
+ writeFileSync(join(dir, "xdg"), "");
175
+ const run = await up();
176
+ assert.equal(
177
+ run.served,
178
+ "clean",
179
+ "a store that throws fails up after its build",
180
+ );
181
+ assert.match(run.frontendBuild?.reason ?? "", /refused it/u);
182
+ });
183
+
184
+ await test("runs inside the checkout keep the cache", async (t) => {
185
+ const { checkout, up } = fixture(t);
186
+ const runs = join(checkout, "runs");
187
+ await up({ runs });
188
+ const second = await up({ runs });
189
+ assert.equal(
190
+ second.frontendBuild?.cached,
191
+ true,
192
+ "a key on the checkout's untracked files changes with the run's own folder and logs",
193
+ );
194
+ });
195
+
196
+ await test("without the cache, or when the workspace cannot be prepared, the run builds as ajs dms build does and says why", async (t) => {
197
+ const { dir, checkout, up } = fixture(t);
198
+ await up();
199
+ write(join(checkout, PAGE), "edited");
200
+ const forced = await up({ useCache: false });
201
+ assert.deepEqual(
202
+ forced.builds,
203
+ [false],
204
+ "--no-build-cache must build as it is",
205
+ );
206
+ assert.equal(forced.frontendBuild?.key, null);
207
+ assert.equal(
208
+ namesIn(join(dir, "xdg", "dms-control", "frontend")).length,
209
+ 1,
210
+ "--no-build-cache stores what it built",
211
+ );
212
+ const unprepared = await up({
213
+ prepare: () => {
214
+ throw new Error("no setupWorkspace");
215
+ },
216
+ });
217
+ assert.deepEqual(unprepared.builds, [false]);
218
+ assert.match(
219
+ unprepared.frontendBuild?.reason ?? "",
220
+ /could not be prepared \(no setupWorkspace\)/u,
221
+ "a run that skips the cache without saying why looks like a cache that never hits",
222
+ );
223
+ assert.equal(unprepared.served, "edited");
224
+ });
225
+
226
+ await test("an install record the key cannot read is a miss that builds as ajs dms build does, stores nothing and says why", async (t) => {
227
+ const { dir, up } = fixture(t);
228
+ const record = join(dir, "node_modules", ".modules.yaml");
229
+ write(record, "hoistPattern:\n - '*'\nlayoutVersion: 5\n");
230
+ await up();
231
+ assert.equal((await up()).frontendBuild?.cached, true);
232
+ write(record, `${JSON.stringify({ hoistPattern: [], layoutVersion: 5 })}\n`);
233
+ const unread = await up();
234
+ assert.deepEqual(
235
+ unread.builds,
236
+ [false],
237
+ "a key that skips a record it cannot read restores the build of another layout",
238
+ );
239
+ assert.deepEqual(unread.frontendBuild, {
240
+ key: null,
241
+ cached: false,
242
+ reason: `its inputs could not be keyed (${record} is not the YAML layout the build cache reads (line 1))`,
243
+ });
244
+ assert.equal(
245
+ namesIn(join(dir, "xdg", "dms-control", "frontend")).length,
246
+ 1,
247
+ "a build whose inputs were not all keyed is stored under no key",
248
+ );
249
+ });
250
+
251
+ await test("a build that refuses its prepared workspace builds again as ajs dms build does; a failing build fails the run once", async (t) => {
252
+ const { dir, up } = fixture(t);
253
+ const refused = await up({
254
+ build: (_workspace, prepared) => {
255
+ if (!prepared) return;
256
+ throw new ExitError(
257
+ "frontend-build exited with 75",
258
+ PREPARED_WORKSPACE_REFUSED,
259
+ );
260
+ },
261
+ });
262
+ assert.deepEqual(
263
+ refused.builds,
264
+ [true, false],
265
+ "a preload that cannot take hold fails up instead of building",
266
+ );
267
+ assert.equal(refused.served, "clean");
268
+ assert.equal(refused.frontendBuild?.key, null);
269
+ assert.match(
270
+ refused.frontendBuild?.reason ?? "",
271
+ /refused its prepared workspace \(frontend-build exited with 75\)/u,
272
+ );
273
+ assert.equal(
274
+ treeOf(join(dir, "xdg", "dms-control", "frontend")),
275
+ null,
276
+ "a build outside the prepared workspace is stored under the key of sources it did not read",
277
+ );
278
+ /** @type {boolean[]} */
279
+ const builds = [];
280
+ await assert.rejects(
281
+ up({
282
+ build: (_workspace, prepared) => {
283
+ builds.push(prepared);
284
+ throw new ExitError("frontend-build exited with 1", 1);
285
+ },
286
+ }),
287
+ /exited with 1/u,
288
+ );
289
+ assert.deepEqual(
290
+ builds,
291
+ [true],
292
+ "a build that fails on its own sources builds a second time",
293
+ );
294
+ });
295
+
296
+ await test("a run records the VITE_ and NODE_ENV variables it keyed on, so another shell keys its sources the same", async (t) => {
297
+ const { frontend, up } = fixture(t);
298
+ setEnv(t, { VITE_PROBE: "on" });
299
+ const run = await up();
300
+ delete process.env.VITE_PROBE;
301
+ assert.deepEqual(run.state.bakedEnv, { VITE_PROBE: "on" });
302
+ const sources = sourceNames(run.workspace).filter((name) => name !== "dist");
303
+ const again = buildInputs(run.state, frontend, {
304
+ project: run.state.runPlayground ?? "",
305
+ workspace: run.workspace,
306
+ names: sources,
307
+ installed: run.workspace,
308
+ });
309
+ assert.equal(
310
+ buildKey(again),
311
+ run.frontendBuild?.key,
312
+ "doctor keys with its own shell's variables and fails a fresh build",
313
+ );
314
+ });
@@ -3,10 +3,14 @@ import { join, resolve } from "node:path";
3
3
  import { browserCommand } from "./browser-client.mjs";
4
4
  import { ACTION_NAMES, describeTarget, serveBrowser } from "./browser.mjs";
5
5
  import { doctor } from "./doctor.mjs";
6
+ import { setUpFrontendWorkspace } from "./frontend-workspace.mjs";
6
7
  import { capturedMail, serveMail } from "./mail.mjs";
7
8
  import { loadRun } from "./run-state.mjs";
8
9
  import { apiRequest, isOk, onboard } from "./session.mjs";
9
- import { down, freshDatabase, resolutionFolders, up } from "./stack.mjs";
10
+ import { down, resolutionFolders, up } from "./stack.mjs";
11
+ import { freshDatabase } from "./backend.mjs";
12
+ import { apiTargetFile, serveForwarder } from "./forwarder.mjs";
13
+ import { formatTimings, readTimings, summarize, timed } from "./timing.mjs";
10
14
  import { loadSkill, runPrepare } from "./verify/skill.mjs";
11
15
 
12
16
  /** @typedef {import("./options.mjs").Values} Values */
@@ -50,9 +54,11 @@ export async function targetOf(values, cwd) {
50
54
  */
51
55
  async function commandUp(values) {
52
56
  const skill = values.skill ? resolve(values.skill) : undefined;
57
+ /** @type {import("./timing.mjs").TimingEntry[]} */
58
+ let prepared = [];
53
59
  if (values.prepare) {
54
60
  const loaded = await loadSkill(skill, process.cwd());
55
- runPrepare(loaded, loaded.repo);
61
+ prepared = runPrepare(loaded, loaded.repo);
56
62
  }
57
63
  const state = await up({
58
64
  ...(await targetOf(values, process.cwd())),
@@ -61,7 +67,17 @@ async function commandUp(values) {
61
67
  env: values.env,
62
68
  base: values.base,
63
69
  skill,
70
+ prepared,
71
+ noStandby:
72
+ values["no-standby"] === true ||
73
+ process.env.DMS_CONTROL_NO_STANDBY === "1",
74
+ buildCache: !values["no-build-cache"],
64
75
  });
76
+ if (state.frontendBuild?.reason) {
77
+ process.stderr.write(
78
+ `dms-control: the frontend build was not cached: ${state.frontendBuild.reason}\n`,
79
+ );
80
+ }
65
81
  print(state.dir);
66
82
  return 0;
67
83
  }
@@ -144,7 +160,12 @@ async function commandBrowser(dir, action, values) {
144
160
  path: values.path,
145
161
  };
146
162
  const label = `${values.tab ?? "main"} ${action} ${target ? describeTarget(target) : (values.path ?? "")}`;
147
- const outcome = await browserCommand(state, request, label);
163
+ const outcome = await timed(
164
+ state,
165
+ "browser-command",
166
+ () => browserCommand(state, request, label),
167
+ { action },
168
+ );
148
169
  if (!outcome.ok) {
149
170
  print(
150
171
  `FAIL ${label}: ${outcome.error} (at ${outcome.url}; evidence ${outcome.folder})`,
@@ -185,7 +206,9 @@ async function commandApi(dir, method, path, values) {
185
206
  async function commandDown(dir) {
186
207
  const state = loadRun(dir);
187
208
  const lines = await down(state);
188
- for (const line of lines.filter((entry) => entry.startsWith("could not")))
209
+ for (const line of lines.filter(
210
+ (entry) => entry.startsWith("could not") || entry.startsWith("skipped"),
211
+ ))
189
212
  print(line);
190
213
  print(state.evidence);
191
214
  return 0;
@@ -193,12 +216,13 @@ async function commandDown(dir) {
193
216
 
194
217
  /**
195
218
  * Runs a command that drives the product: `up`, `doctor`, `onboard`,
196
- * `browser`, `api`, `mail`, `down`, and the two services `up` starts.
219
+ * `browser`, `api`, `mail`, `down`, `timings`, the three services `up`
220
+ * starts, and the frontend workspace setup it runs (`prepare-frontend`).
197
221
  *
198
222
  * @param {string | undefined} command The command
199
223
  * @param {string[]} rest Its positional arguments
200
224
  * @param {Values} values Its options
201
- * @returns {Promise<number | undefined>} The exit code, or undefined for a command it does not own; the two services keep the process alive
225
+ * @returns {Promise<number | undefined>} The exit code, or undefined for a command it does not own; the three services keep the process alive
202
226
  */
203
227
  export async function runStackCommand(command, rest, values) {
204
228
  switch (command) {
@@ -217,17 +241,33 @@ export async function runStackCommand(command, rest, values) {
217
241
  return 0;
218
242
  case "down":
219
243
  return commandDown(rest[0]);
244
+ case "timings":
245
+ print(formatTimings(summarize(readTimings(loadRun(rest[0]).evidence))));
246
+ return 0;
220
247
  case "reset": {
221
248
  const state = loadRun(rest[0]);
222
249
  state.resetCount = (state.resetCount ?? 0) + 1;
223
250
  print(await freshDatabase(state, `r${state.resetCount}`));
224
251
  return 0;
225
252
  }
253
+ case "prepare-frontend":
254
+ await setUpFrontendWorkspace(
255
+ rest[0] ?? "",
256
+ rest[1] ?? "",
257
+ rest[2] ?? "",
258
+ rest[3] === "install",
259
+ );
260
+ return 0;
226
261
  case "serve-mail": {
227
262
  const state = loadRun(rest[0]);
228
263
  await serveMail(state.mail, state.smtpPort);
229
264
  return 0;
230
265
  }
266
+ case "serve-api": {
267
+ const state = loadRun(rest[0]);
268
+ await serveForwarder(state.apiPort, apiTargetFile(state.dir));
269
+ return 0;
270
+ }
231
271
  case "serve-browser":
232
272
  await serveBrowser(
233
273
  rest[0],
@@ -2,6 +2,7 @@ import { join } from "node:path";
2
2
  import { print } from "./commands-stack.mjs";
3
3
  import { runJourneyFile } from "./journey.mjs";
4
4
  import { loadRun } from "./run-state.mjs";
5
+ import { timed } from "./timing.mjs";
5
6
  import { doorLine, flaggedDoors, patchFiles } from "./verify/doors.mjs";
6
7
  import {
7
8
  formalGate,
@@ -10,12 +11,6 @@ import {
10
11
  } from "./verify/formal.mjs";
11
12
  import { readJudgement } from "./verify/judgement.mjs";
12
13
  import { checkMap, planFor } from "./verify/map.mjs";
13
- import {
14
- postComment,
15
- pushEvidence,
16
- readStatus,
17
- setStatus,
18
- } from "./verify/publish.mjs";
19
14
  import { journeysFile, loadSkill } from "./verify/skill.mjs";
20
15
  import { renderVerdict } from "./verify/verdict.mjs";
21
16
 
@@ -51,7 +46,7 @@ async function commandMap(values) {
51
46
  * @returns {Promise<number>} The exit code
52
47
  */
53
48
  async function commandPlan(values) {
54
- const plan = planFor(await skillOf(values), values.base);
49
+ const plan = planFor(await skillOf(values), values.base, values.all);
55
50
  print(JSON.stringify(plan, null, 2));
56
51
  return plan.unmapped.length === 0 ? 0 : 1;
57
52
  }
@@ -120,7 +115,12 @@ async function commandFormal(dir, values) {
120
115
  };
121
116
  for (const check of checks) {
122
117
  const gate = touched.includes(check);
123
- const result = runFormalCheck(skill, state, check, gate ? diff : null);
118
+ const result = await timed(
119
+ state,
120
+ "formal",
121
+ () => runFormalCheck(skill, state, check, gate ? diff : null),
122
+ { check: check.name },
123
+ );
124
124
  const weight = formalGate(result);
125
125
  const outcome = gate
126
126
  ? weight.fails
@@ -140,15 +140,14 @@ async function commandFormal(dir, values) {
140
140
  }
141
141
 
142
142
  /**
143
- * @param {string} command `verdict` or `publish`
144
143
  * @param {string} dir The run root
145
144
  * @param {Values} values The options of the command line
146
145
  * @returns {Promise<number>} The exit code
147
146
  */
148
- async function commandJudge(command, dir, values) {
147
+ async function commandVerdict(dir, values) {
149
148
  const pr = Number(values.pr);
150
149
  if (!Number.isInteger(pr) || pr <= 0) {
151
- print(`${command} needs --pr <number>`);
150
+ print("verdict needs --pr <number>");
152
151
  return 2;
153
152
  }
154
153
  const state = loadRun(dir);
@@ -158,24 +157,15 @@ async function commandJudge(command, dir, values) {
158
157
  state,
159
158
  pr,
160
159
  readJudgement(skill, join(state.evidence, "judgement.json")),
160
+ values.all,
161
161
  );
162
162
  print(verdict.markdown);
163
- if (command !== "publish") return verdict.result === "FAIL" ? 1 : 0;
164
- print(`evidence commit ${pushEvidence(skill, state, verdict)}`);
165
- const comment = postComment(skill, verdict);
166
- print(`comment ${comment}`);
167
- const error = setStatus(skill, verdict, comment);
168
- if (error)
169
- print(`FAIL status verify on ${verdict.headSha} not set: ${error}`);
170
- print(
171
- `status verify on ${verdict.headSha}: ${readStatus(skill, verdict.headSha)}`,
172
- );
173
- return error || verdict.result === "FAIL" ? 1 : 0;
163
+ return verdict.result === "FAIL" ? 1 : 0;
174
164
  }
175
165
 
176
166
  /**
177
167
  * Runs a command of the verification harness: `map`, `plan`, `journey`,
178
- * `doors`, `formal`, `verdict` and `publish`.
168
+ * `doors`, `formal` and `verdict`.
179
169
  *
180
170
  * @param {string} command The command
181
171
  * @param {string[]} rest Its positional arguments
@@ -195,8 +185,7 @@ export function runVerifyCommand(command, rest, values) {
195
185
  case "formal":
196
186
  return commandFormal(rest[0], values);
197
187
  case "verdict":
198
- case "publish":
199
- return commandJudge(command, rest[0], values);
188
+ return commandVerdict(rest[0], values);
200
189
  default:
201
190
  return Promise.resolve(undefined);
202
191
  }
@@ -1,14 +1,34 @@
1
1
  import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
2
  import { createRequire } from "node:module";
3
3
  import { dirname, join } from "node:path";
4
- import { descendantsOf, isAlive, listenersOf, probe } from "./processes.mjs";
4
+ import { isSameProcess } from "./identity.mjs";
5
+ import { descendantsOf, listenersOf, probe } from "./processes.mjs";
6
+ import { buildChangedSince } from "./build-inputs.mjs";
7
+ import { apiTargetFile, readTarget } from "./forwarder.mjs";
5
8
  import { checkoutOf } from "./git.mjs";
6
9
  import { stringField } from "./json.mjs";
7
10
  import { apiRequest } from "./session.mjs";
8
- import { packageVersion } from "./stack.mjs";
11
+ import { describeFailure } from "./failure.mjs";
12
+ import { currentFrontendBuildKey } from "./frontend-check.mjs";
9
13
 
10
14
  /** @typedef {import("./run-state.mjs").RunState} RunState */
11
15
 
16
+ /**
17
+ * The version a package.json declares, or `missing`.
18
+ *
19
+ * @param {string} file The package.json
20
+ * @returns {string} The version
21
+ */
22
+ function packageVersion(file) {
23
+ try {
24
+ /** @type {unknown} */
25
+ const manifest = JSON.parse(readFileSync(file, "utf8"));
26
+ return stringField(manifest, "version") ?? "missing";
27
+ } catch {
28
+ return "missing";
29
+ }
30
+ }
31
+
12
32
  const SKIPPED = new Set([
13
33
  "node_modules",
14
34
  ".antelope",
@@ -57,15 +77,14 @@ function line(check, ok, detail) {
57
77
 
58
78
  /** @param {RunState} state */
59
79
  function processLines(state) {
60
- const family = new Set([
61
- ...state.processes.map((record) => record.pid),
62
- ...descendantsOf(state.processes.map((record) => record.pid)),
63
- ]);
80
+ const own = state.processes.filter(isSameProcess);
81
+ const pids = own.map((record) => record.pid);
82
+ const family = new Set([...pids, ...descendantsOf(pids)]);
64
83
  return state.processes.flatMap((record) => {
65
84
  const lines = [
66
85
  line(
67
86
  `${record.name} pid ${record.pid} alive`,
68
- isAlive(record.pid),
87
+ own.includes(record),
69
88
  record.command,
70
89
  ),
71
90
  ];
@@ -133,8 +152,11 @@ function versions(state) {
133
152
  };
134
153
  }
135
154
 
136
- /** @param {RunState} state */
137
- function freshnessLines(state) {
155
+ /**
156
+ * @param {RunState} state
157
+ * @returns {Promise<{ check: string, ok: boolean, detail: string }[]>}
158
+ */
159
+ async function freshnessLines(state) {
138
160
  const moduleDist = join(state.moduleRoot, "dist");
139
161
  const playgroundDist = join(state.playground, "dist");
140
162
  const frontendBuild = join(
@@ -171,12 +193,56 @@ function freshnessLines(state) {
171
193
  newestMtime(join(state.playground, "src")),
172
194
  playgroundDist,
173
195
  ),
174
- line(
196
+ await frontendBuildLine(state, frontendBuild, frontendSources),
197
+ ];
198
+ }
199
+
200
+ /**
201
+ * @param {RunState} state
202
+ * @param {string} frontendBuild
203
+ * @param {number} frontendSources
204
+ */
205
+ async function frontendBuildLine(state, frontendBuild, frontendSources) {
206
+ const recorded = state.frontendBuild;
207
+ if (!recorded?.key) {
208
+ return line(
175
209
  "frontend build newer than frontend-vue",
176
210
  mtime(frontendBuild) >= frontendSources,
177
211
  frontendBuild,
178
- ),
179
- ];
212
+ );
213
+ }
214
+ const now = await currentFrontendBuildKey(state).catch(
215
+ (/** @type {unknown} */ error) => `unreadable (${describeFailure(error)})`,
216
+ );
217
+ return line(
218
+ "frontend build is of the current sources",
219
+ now === recorded.key,
220
+ `${recorded.cached ? "from the build cache" : "built by up"}, inputs ${recorded.key.slice(0, 12)} at up, ${now.slice(0, 12)} now`,
221
+ );
222
+ }
223
+
224
+ /** @param {RunState} state */
225
+ function forwardLine(state) {
226
+ const target = readTarget(apiTargetFile(state.dir));
227
+ const backend = state.processes.find((record) => record.name === "backend");
228
+ return line(
229
+ "API port forwards to the backend",
230
+ target !== null && target === backend?.port,
231
+ `${state.apiUrl} to port ${target ?? "none"}, backend on ${backend?.port ?? "none"}`,
232
+ );
233
+ }
234
+
235
+ /** @param {RunState} state */
236
+ function buildLine(state) {
237
+ const backend = state.processes.find((record) => record.name === "backend");
238
+ const changed = backend ? buildChangedSince(state, backend.startedAt) : null;
239
+ return line(
240
+ "backend started after the last build",
241
+ backend !== undefined && changed === null,
242
+ changed === null
243
+ ? `backend started ${backend?.startedAt ?? "never"}`
244
+ : `${changed} since the backend started at ${backend?.startedAt}; once the build is done, reset or run a journey to start one from it`,
245
+ );
180
246
  }
181
247
 
182
248
  /** @param {RunState} state */
@@ -210,9 +276,12 @@ async function sessionLine(state) {
210
276
 
211
277
  /**
212
278
  * Answers whether a run is worth driving: every recorded process is alive
213
- * and holds its port, both servers answer, the frontend serves this run's
214
- * backend, the builds are newer than their sources, the database is the
215
- * run's own, and the admin session (once onboarded) is valid.
279
+ * and holds its port, both servers answer, the API port forwards to the
280
+ * run's backend, the frontend serves this run's backend, the builds are
281
+ * newer than their sources (the frontend build is keyed as a fresh `up`
282
+ * would key it now, when it recorded a key), the backend started after the
283
+ * last build, the database is the run's own, and the admin session (once
284
+ * onboarded) is valid.
216
285
  *
217
286
  * @param {import("./run-state.mjs").RunState} state The run
218
287
  * @returns {Promise<{ check: string, ok: boolean, detail: string }[]>} One line per check
@@ -228,6 +297,7 @@ export async function doctor(state) {
228
297
  (await probe(`${state.apiUrl}/api/onboarding/informations`)) === 200,
229
298
  `${state.apiUrl}/api/onboarding/informations`,
230
299
  ),
300
+ forwardLine(state),
231
301
  line(
232
302
  "frontend answers",
233
303
  (await probe(`${state.webUrl}/dms-preview`)) === 200,
@@ -243,7 +313,8 @@ export async function doctor(state) {
243
313
  found.core !== "missing" && found.dmsFrontend !== "missing",
244
314
  `module ${found.module}, @antelopejs/core ${found.core}, @antelopejs/dms-frontend ${found.dmsFrontend}`,
245
315
  ),
246
- ...freshnessLines(state),
316
+ ...(await freshnessLines(state)),
317
+ buildLine(state),
247
318
  line(
248
319
  "database is the run's",
249
320
  state.database.startsWith(state.databasePrefix),