@antelopejs/dms 0.18.2 → 0.19.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 (69) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +1 -1
  3. package/bin/control/backend.mjs +1 -1
  4. package/bin/control/base.mjs +24 -9
  5. package/bin/control/base.test.mjs +88 -0
  6. package/bin/control/browser-client.mjs +1 -1
  7. package/bin/control/commands-stack.mjs +3 -1
  8. package/bin/control/consumer-install.test.mjs +73 -0
  9. package/bin/control/database.mjs +66 -0
  10. package/bin/control/doctor.mjs +7 -0
  11. package/bin/control/frontend-check.mjs +2 -1
  12. package/bin/control/frontend-mode.test.mjs +24 -0
  13. package/bin/control/identity.mjs +45 -16
  14. package/bin/control/journey.mjs +31 -3
  15. package/bin/control/journey.test.mjs +207 -2
  16. package/bin/control/launch.mjs +123 -0
  17. package/bin/control/module-root.mjs +40 -0
  18. package/bin/control/module-root.test.mjs +67 -0
  19. package/bin/control/mongo-server.test.mjs +91 -0
  20. package/bin/control/mongo.mjs +125 -12
  21. package/bin/control/options.mjs +1 -0
  22. package/bin/control/pid-reuse.test.mjs +278 -0
  23. package/bin/control/processes.mjs +91 -29
  24. package/bin/control/renderer.test.mjs +1 -1
  25. package/bin/control/run-copy.mjs +6 -1
  26. package/bin/control/run-state.mjs +4 -1
  27. package/bin/control/stack.mjs +78 -165
  28. package/bin/control/verify/behaviour.test.mjs +36 -23
  29. package/bin/control/verify/decode.mjs +1 -0
  30. package/bin/control/verify/emit.mjs +11 -11
  31. package/bin/control/verify/formal.mjs +28 -14
  32. package/bin/control/verify/formal.test.mjs +15 -0
  33. package/bin/control/verify/types.mjs +1 -1
  34. package/bin/dms-control.mjs +4 -2
  35. package/dist/db/models/userNotifications.model.js +14 -8
  36. package/dist/db/models/userNotifications.model.js.map +1 -1
  37. package/dist/pages/public/auth/not-a-member.d.ts +9 -0
  38. package/dist/pages/public/auth/not-a-member.js +27 -0
  39. package/dist/pages/public/auth/not-a-member.js.map +1 -0
  40. package/dist/pages/public/index.d.ts +1 -0
  41. package/dist/pages/public/index.js +1 -0
  42. package/dist/pages/public/index.js.map +1 -1
  43. package/dist/routes/auth/oauth/identity-resolution.js +10 -0
  44. package/dist/routes/auth/oauth/identity-resolution.js.map +1 -1
  45. package/dist/routes/onboarding.js +1 -5
  46. package/dist/routes/onboarding.js.map +1 -1
  47. package/dist/utils/ensure-default-tenant.js +23 -3
  48. package/dist/utils/ensure-default-tenant.js.map +1 -1
  49. package/frontend-vue/layers/dms-auth/app/build/utils/noWorkspaceRoute.ts +19 -0
  50. package/frontend-vue/layers/dms-auth/app/custom-pages/auth/login.vue +4 -6
  51. package/frontend-vue/layers/dms-auth/app/custom-pages/auth/not-a-member.vue +21 -0
  52. package/frontend-vue/layers/dms-auth/app/custom-pages/auth/oauth-complete.vue +2 -4
  53. package/frontend-vue/layers/dms-auth/i18n/locales/auth-en-GB.json +6 -0
  54. package/frontend-vue/layers/dms-auth/i18n/locales/auth-fr-FR.json +6 -0
  55. package/frontend-vue/layers/dms-core/app/types/live.ts +2 -0
  56. package/frontend-vue/layers/dms-ui/app/build/components/containers/drawer/DynamicDrawer.vue +9 -3
  57. package/frontend-vue/layers/dms-ui/app/build/composables/live/currentPageLive.ts +7 -0
  58. package/frontend-vue/layers/dms-ui/app/build/composables/live/pageLiveController.ts +23 -3
  59. package/frontend-vue/layers/dms-ui/app/build/composables/live/usePageDataRefresh.ts +2 -1
  60. package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewRealtime.ts +21 -2
  61. package/frontend-vue/layers/dms-ui/app/build/composables/table-view/useTableLiveHold.ts +4 -3
  62. package/frontend-vue/layers/dms-ui/app/build/utils/accessibilityPreferences.ts +1 -21
  63. package/frontend-vue/layers/dms-ui/app/build/utils/blockPreview.ts +8 -4
  64. package/frontend-vue/layers/dms-ui/app/build/utils/link.ts +35 -7
  65. package/frontend-vue/layers/dms-ui/app/components/chart/ApexChartHost.vue +51 -8
  66. package/frontend-vue/layers/dms-ui/app/composables/chart/useApexChart.ts +1 -1
  67. package/frontend-vue/layers/dms-ui/app/utils/reducedMotion.ts +22 -0
  68. package/package.json +4 -4
  69. package/skills/dms-pages/REFERENCE.md +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,65 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.19.0
4
+
5
+ [compare changes](https://github.com/AntelopeJS/dms/compare/v0.18.2...v0.19.0)
6
+
7
+ ### 🚀 Enhancements
8
+
9
+ - **dms-control:** Serve the dashboard with ajs dms dev under up --dev-frontend ([#829](https://github.com/AntelopeJS/dms/pull/829))
10
+ - **table-view:** Add liveHold.whileOnScreen to let a live table follow its feed on screen ([#808](https://github.com/AntelopeJS/dms/pull/808))
11
+
12
+ ### 🩹 Fixes
13
+
14
+ - **verify-dms:** Expect the assistant ask item in the palette no-match journey ([#799](https://github.com/AntelopeJS/dms/pull/799))
15
+ - **notifications:** Undo mark-all-read in one bulk update ([#826](https://github.com/AntelopeJS/dms/pull/826))
16
+ - **dms:** Auto-import isReducedMotionActive for frontend modules ([#823](https://github.com/AntelopeJS/dms/pull/823))
17
+ - **dms-control:** Resolve moduleRoot to the module above a skill playground ([#827](https://github.com/AntelopeJS/dms/pull/827))
18
+ - **preview:** Draw a serialized resource form that reads any path of the site ([#820](https://github.com/AntelopeJS/dms/pull/820))
19
+ - **dms-control:** Key a non-literal module specifier by its structure in the emit fingerprint ([#816](https://github.com/AntelopeJS/dms/pull/816))
20
+ - **dms:** Keep the newest row read when two table row updates answer out of order ([#812](https://github.com/AntelopeJS/dms/pull/812))
21
+ - **dms-ui:** Keep query-only block action links in the browser ([#832](https://github.com/AntelopeJS/dms/pull/832))
22
+ - **chart:** Stop a donut redrawing itself through its parent resize observer ([#835](https://github.com/AntelopeJS/dms/pull/835))
23
+ - **release:** Decide the interface range check as semver does ([#813](https://github.com/AntelopeJS/dms/pull/813))
24
+ - **dms-control:** Let journeys stop and restart the run's mongod ([#831](https://github.com/AntelopeJS/dms/pull/831))
25
+ - **dms-control:** Start the base backend when the base ref has no playground ([#818](https://github.com/AntelopeJS/dms/pull/818))
26
+ - **dms-control:** Start the run's mongod as a single-node replica set ([#830](https://github.com/AntelopeJS/dms/pull/830))
27
+ - **realtime:** Read a page's data again once its subscription is in place ([#810](https://github.com/AntelopeJS/dms/pull/810))
28
+ - **dms-control:** Ship playwright-core as an optional dependency of @antelopejs/dms ([#817](https://github.com/AntelopeJS/dms/pull/817))
29
+ - **auth:** Show a no-workspace screen when no module serves /auth/no-workspace ([#800](https://github.com/AntelopeJS/dms/pull/800))
30
+ - **dms-control:** Fail a formal finding dropped by a check edit instead of counting it fixed ([#821](https://github.com/AntelopeJS/dms/pull/821))
31
+ - **playground:** Load an api that reads RouteHandler.controller ([#819](https://github.com/AntelopeJS/dms/pull/819))
32
+ - **dms-ui:** Build a module drawer's provides from the raw caller provides ([#809](https://github.com/AntelopeJS/dms/pull/809))
33
+ - **dms-control:** Identify each process from the read that finds it, and check it again before each signal ([#801](https://github.com/AntelopeJS/dms/pull/801))
34
+ - **interface-dms:** Answer 400 to a guarded confirmation body that is not a JSON object ([#828](https://github.com/AntelopeJS/dms/pull/828))
35
+ - **interface-dms:** Accept a model row or a PromiseLike from PageRecordLoader ([#815](https://github.com/AntelopeJS/dms/pull/815))
36
+ - **interface-dms:** Refuse upload field options that are not an object ([#825](https://github.com/AntelopeJS/dms/pull/825))
37
+ - **oauth:** Create no account before the platform has its owner ([#807](https://github.com/AntelopeJS/dms/pull/807))
38
+ - **dms:** Stop without waiting for a default tenant provisioning run in progress ([#804](https://github.com/AntelopeJS/dms/pull/804))
39
+ - **tenant-lifecycle:** Name a blocked release and give operators a way to retire it ([#822](https://github.com/AntelopeJS/dms/pull/822))
40
+ - **onboarding:** Keep the register as the one writer of has_onboarded ([#806](https://github.com/AntelopeJS/dms/pull/806))
41
+
42
+ ### 💅 Refactors
43
+
44
+ - **iface:** Drop the shape-name suppressions in block-registry describe ([#803](https://github.com/AntelopeJS/dms/pull/803))
45
+
46
+ ### 📖 Documentation
47
+
48
+ - Refresh the stale block screenshots ([#802](https://github.com/AntelopeJS/dms/pull/802))
49
+
50
+ ### 🏡 Chore
51
+
52
+ - **release:** @antelopejs/interface-dms v0.13.0 ([187e2598](https://github.com/AntelopeJS/dms/commit/187e2598))
53
+ - **dms:** Depend on @antelopejs/interface-dms 0.13 ([#839](https://github.com/AntelopeJS/dms/pull/839))
54
+
55
+ ### ✅ Tests
56
+
57
+ - **frontend:** Import the table row actions subject at file load ([#805](https://github.com/AntelopeJS/dms/pull/805))
58
+
59
+ ### ❤️ Contributors
60
+
61
+ - Antony Rizzitelli ([@Upd4ting](http://github.com/Upd4ting))
62
+
3
63
  ## v0.18.2
4
64
 
5
65
  [compare changes](https://github.com/AntelopeJS/dms/compare/v0.18.1...v0.18.2)
package/README.md CHANGED
@@ -86,7 +86,7 @@ export class SalesPage extends PageController("sales", {
86
86
  | `@antelopejs/interface-data-api` | `>=0.6.0 <1.0.0` | `0.6.0` |
87
87
  | `@antelopejs/interface-database` | `>=0.3.0 <1.0.0` | `0.3.1` |
88
88
  | `@antelopejs/interface-database-decorators` | `>=0.2.0 <1.0.0` | `0.2.1` |
89
- | `@antelopejs/interface-dms` | `>=0.12.0 <0.13.0` | `0.12.0` |
89
+ | `@antelopejs/interface-dms` | `>=0.13.0 <0.14.0` | `0.13.0` |
90
90
  | `@antelopejs/interface-dms-automation` | `>=0.6.0 <1.0.0` | `0.6.1` |
91
91
  | `@antelopejs/interface-email` | `>=0.0.6 <1.0.0` | `0.0.6` |
92
92
  | `@antelopejs/interface-file-storage` | `>=0.1.4 <1.0.0` | `0.1.4` |
@@ -1,13 +1,13 @@
1
1
  import { buildChangedSince, missingBuildRoot } from "./build-inputs.mjs";
2
2
  import { apiTargetFile, readTarget, writeTarget } from "./forwarder.mjs";
3
3
  import { dropDatabase } from "./mongo.mjs";
4
+ import { resolutionFolders } from "./launch.mjs";
4
5
  import { killRecorded, stopRecorded } from "./processes.mjs";
5
6
  import {
6
7
  ensureApi,
7
8
  launchBackend,
8
9
  liveBackends,
9
10
  record,
10
- resolutionFolders,
11
11
  startBackend,
12
12
  waitForBackend,
13
13
  } from "./stack.mjs";
@@ -1,12 +1,12 @@
1
- import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
1
+ import { cpSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
- import { join, relative } from "node:path";
3
+ import { basename, join, relative } from "node:path";
4
4
  import { git } from "./git.mjs";
5
5
  import { runToEnd } from "./processes.mjs";
6
6
  import { saveRun } from "./run-state.mjs";
7
7
  import { runPrepare } from "./verify/skill.mjs";
8
- import { layOutCopy } from "./run-copy.mjs";
9
- import { cliPaths, ENVIRONMENT, spec } from "./stack.mjs";
8
+ import { COPY_SKIPPED, layOutCopy } from "./run-copy.mjs";
9
+ import { cliPaths, ENVIRONMENT, spec } from "./launch.mjs";
10
10
  import { restartBackend } from "./backend.mjs";
11
11
 
12
12
  const READY_MARK = ".dms-control-ready";
@@ -19,22 +19,37 @@ function baseCache() {
19
19
  /**
20
20
  * A prepared worktree of the run's base ref, built once per commit under
21
21
  * `~/.cache/dms-control/base/<sha>` with the skill's `prepare` commands.
22
+ * When the base ref has no playground folder, as in the change that adds
23
+ * it, the worktree gets a copy of the run's playground before `prepare`,
24
+ * and is built again on every call so the copy follows the run's.
22
25
  *
23
26
  * @param {import("./run-state.mjs").RunState} state The run
24
27
  * @param {import("./verify/skill.mjs").Skill} skill The skill
25
- * @returns {{ sha: string, dir: string }} The base commit and its worktree
28
+ * @returns {{ sha: string, dir: string, playground: string }} The base commit, its worktree and its playground
26
29
  */
27
- function baseCheckout(state, skill) {
30
+ export function baseCheckout(state, skill) {
28
31
  const sha = git(["rev-parse", `${state.baseRef}^{commit}`], state.repo);
29
32
  const dir = join(baseCache(), sha);
30
- if (existsSync(join(dir, READY_MARK))) return { sha, dir };
33
+ const path = relative(state.repo, state.playground);
34
+ const playground = join(dir, path);
35
+ const copied =
36
+ git(["ls-tree", "-d", "--name-only", sha, "--", path], state.repo) === "";
37
+ if (!copied && existsSync(join(dir, READY_MARK))) {
38
+ return { sha, dir, playground };
39
+ }
31
40
  rmSync(dir, { recursive: true, force: true });
32
41
  mkdirSync(baseCache(), { recursive: true });
33
42
  git(["worktree", "prune"], state.repo);
34
43
  git(["worktree", "add", "--detach", "--force", dir, sha], state.repo);
44
+ if (copied) {
45
+ cpSync(state.playground, playground, {
46
+ recursive: true,
47
+ filter: (source) => !COPY_SKIPPED.has(basename(source)),
48
+ });
49
+ }
35
50
  runPrepare(skill, dir);
36
51
  writeFileSync(join(dir, READY_MARK), `${sha}\n`);
37
- return { sha, dir };
52
+ return { sha, dir, playground };
38
53
  }
39
54
 
40
55
  /**
@@ -55,7 +70,7 @@ export async function withBaseBackend(state, skill, action) {
55
70
  );
56
71
  }
57
72
  const base = baseCheckout(state, skill);
58
- const playground = join(base.dir, relative(state.repo, state.playground));
73
+ const { playground } = base;
59
74
  state.baseRoot = join(state.dir, "base-root");
60
75
  rmSync(state.baseRoot, { recursive: true, force: true });
61
76
  const cwd = layOutCopy(playground, base.dir, state.baseRoot);
@@ -0,0 +1,88 @@
1
+ import assert from "node:assert/strict";
2
+ import {
3
+ existsSync,
4
+ mkdirSync,
5
+ mkdtempSync,
6
+ realpathSync,
7
+ rmSync,
8
+ } from "node:fs";
9
+ import { tmpdir } from "node:os";
10
+ import { join } from "node:path";
11
+ import test from "node:test";
12
+ import { baseCheckout } from "./base.mjs";
13
+ import { git } from "./git.mjs";
14
+ import { setEnv } from "./helpers/env.mjs";
15
+ import { write } from "./helpers/repo.mjs";
16
+
17
+ const PLAYGROUND = join(".agents", "skills", "verify", "playground");
18
+
19
+ /**
20
+ * A repository whose commit `base` has no playground and whose HEAD adds
21
+ * one, with installed modules left untracked. The base cache is scratch.
22
+ *
23
+ * @param {import("node:test").TestContext} t The test
24
+ * @returns {{ repo: string, playground: string }} Its paths
25
+ */
26
+ function repoWithNewPlayground(t) {
27
+ const root = realpathSync(
28
+ mkdtempSync(join(tmpdir(), "dms-control-base-test-")),
29
+ );
30
+ t.after(() => rmSync(root, { recursive: true, force: true }));
31
+ setEnv(t, { XDG_CACHE_HOME: join(root, "cache") });
32
+ const repo = join(root, "repo");
33
+ mkdirSync(repo);
34
+ git(["init", "-q", "-b", "main"], repo);
35
+ git(["config", "user.email", "test@example.com"], repo);
36
+ git(["config", "user.name", "test"], repo);
37
+ write(join(repo, "README.md"), "base\n");
38
+ git(["add", "."], repo);
39
+ git(["commit", "-q", "-m", "base"], repo);
40
+ git(["tag", "base"], repo);
41
+ const playground = join(repo, PLAYGROUND);
42
+ write(join(playground, "antelope.config.ts"), "head\n");
43
+ write(join(playground, ".gitignore"), "node_modules\n");
44
+ write(join(playground, "node_modules", "zod", "package.json"), "{}");
45
+ git(["add", "."], repo);
46
+ git(["commit", "-q", "-m", "add the playground"], repo);
47
+ return { repo, playground };
48
+ }
49
+
50
+ await test("a base ref without the playground prepares a copy of the run's playground", (t) => {
51
+ const { repo, playground } = repoWithNewPlayground(t);
52
+ const prepare = [
53
+ ["grep", "-qx", "head", join(PLAYGROUND, "antelope.config.ts")],
54
+ ["grep", "-qx", "base", "README.md"],
55
+ ];
56
+ const base = baseCheckout(
57
+ { repo, playground, baseRef: "base" },
58
+ { config: { prepare } },
59
+ );
60
+ assert.equal(base.sha, git(["rev-parse", "base"], repo));
61
+ assert.equal(base.playground, join(base.dir, PLAYGROUND));
62
+ assert.equal(existsSync(join(base.playground, "node_modules")), false);
63
+ });
64
+
65
+ await test("a copied base playground follows the run's playground from one run to the next", (t) => {
66
+ const { repo, playground } = repoWithNewPlayground(t);
67
+ const state = { repo, playground, baseRef: "base" };
68
+ baseCheckout(state, { config: { prepare: [] } });
69
+ write(join(playground, "antelope.config.ts"), "edited\n");
70
+ const base = baseCheckout(state, {
71
+ config: {
72
+ prepare: [
73
+ ["grep", "-qx", "edited", join(PLAYGROUND, "antelope.config.ts")],
74
+ ["touch", "prepared"],
75
+ ],
76
+ },
77
+ });
78
+ assert.equal(existsSync(join(base.dir, "prepared")), true);
79
+ });
80
+
81
+ await test("a base ref that has the playground is built once", (t) => {
82
+ const { repo, playground } = repoWithNewPlayground(t);
83
+ const state = { repo, playground, baseRef: "HEAD" };
84
+ const first = baseCheckout(state, { config: { prepare: [] } });
85
+ write(join(first.playground, "prepared"), "");
86
+ const second = baseCheckout(state, { config: { prepare: [["false"]] } });
87
+ assert.equal(existsSync(join(second.playground, "prepared")), true);
88
+ });
@@ -1,6 +1,6 @@
1
1
  import { isOutcome } from "./browser-wire.mjs";
2
2
  import { decode } from "./json.mjs";
3
- import { CONTROL_BIN } from "./stack.mjs";
3
+ import { CONTROL_BIN } from "./launch.mjs";
4
4
  import { isSameProcess } from "./identity.mjs";
5
5
  import { freePort, startDetached, waitForOk } from "./processes.mjs";
6
6
  import { saveRun } from "./run-state.mjs";
@@ -7,7 +7,8 @@ import { setUpFrontendWorkspace } from "./frontend-workspace.mjs";
7
7
  import { capturedMail, serveMail } from "./mail.mjs";
8
8
  import { loadRun } from "./run-state.mjs";
9
9
  import { apiRequest, isOk, onboard } from "./session.mjs";
10
- import { down, resolutionFolders, up } from "./stack.mjs";
10
+ import { resolutionFolders } from "./launch.mjs";
11
+ import { down, up } from "./stack.mjs";
11
12
  import { freshDatabase } from "./backend.mjs";
12
13
  import { apiTargetFile, serveForwarder } from "./forwarder.mjs";
13
14
  import { formatTimings, readTimings, summarize, timed } from "./timing.mjs";
@@ -72,6 +73,7 @@ async function commandUp(values) {
72
73
  values["no-standby"] === true ||
73
74
  process.env.DMS_CONTROL_NO_STANDBY === "1",
74
75
  buildCache: !values["no-build-cache"],
76
+ frontendMode: values["dev-frontend"] ? "dev" : "build",
75
77
  });
76
78
  if (state.frontendBuild?.reason) {
77
79
  process.stderr.write(
@@ -0,0 +1,73 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawnSync } from "node:child_process";
3
+ import { cpSync, mkdirSync, mkdtempSync, rmSync, symlinkSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import test from "node:test";
7
+ import { pathToFileURL } from "node:url";
8
+ import manifest from "../../package.json" with { type: "json" };
9
+ import { PACKAGE_ROOT } from "./launch.mjs";
10
+
11
+ /**
12
+ * A module repository that depends on `@antelopejs/dms` and declares nothing
13
+ * else: the installed copy gets the `bin` folder it publishes and, beside it,
14
+ * the dependencies an install of that kind gives a dependency.
15
+ *
16
+ * @param {import("node:test").TestContext} t
17
+ * @param {Record<string, string>[]} installed Each dependency list of the manifest the install honours
18
+ * @returns {string} The output of resolving playwright-core the way dms-control does, or its error
19
+ */
20
+ function resolveFromConsumer(t, installed) {
21
+ const moduleRoot = mkdtempSync(join(tmpdir(), "dms-control-consumer-"));
22
+ t.after(() => rmSync(moduleRoot, { recursive: true, force: true }));
23
+ const dms = join(moduleRoot, "node_modules", "@antelopejs", "dms");
24
+ mkdirSync(dms, { recursive: true });
25
+ cpSync(join(PACKAGE_ROOT, "bin"), join(dms, "bin"), { recursive: true });
26
+ cpSync(join(PACKAGE_ROOT, "package.json"), join(dms, "package.json"));
27
+ for (const name of installed.flatMap((list) => Object.keys(list))) {
28
+ const link = join(dms, "node_modules", name);
29
+ mkdirSync(join(link, ".."), { recursive: true });
30
+ symlinkSync(join(PACKAGE_ROOT, "node_modules", name), link, "dir");
31
+ }
32
+ const mongo = pathToFileURL(join(dms, "bin", "control", "mongo.mjs"));
33
+ const from = [join(moduleRoot, ".agents", "playground"), moduleRoot, dms];
34
+ const run = spawnSync(
35
+ process.execPath,
36
+ [
37
+ "--input-type=module",
38
+ "--eval",
39
+ `const { importFrom } = await import(${JSON.stringify(mongo.href)});
40
+ try {
41
+ const { chromium } = await importFrom("playwright-core", ${JSON.stringify(from)});
42
+ process.stdout.write(chromium.name());
43
+ } catch (error) {
44
+ process.stdout.write(error.message);
45
+ }`,
46
+ ],
47
+ { cwd: moduleRoot, encoding: "utf8" },
48
+ );
49
+ return run.stdout;
50
+ }
51
+
52
+ await test("dms-control resolves playwright-core for a module whose install of @antelopejs/dms keeps optional dependencies", (t) => {
53
+ assert.equal(
54
+ resolveFromConsumer(t, [
55
+ manifest.dependencies,
56
+ manifest.optionalDependencies,
57
+ ]),
58
+ "chromium",
59
+ );
60
+ });
61
+
62
+ await test("dms-control names the install command when the install of @antelopejs/dms omitted optional dependencies", (t) => {
63
+ const spec = `playwright-core@${manifest.optionalDependencies["playwright-core"]}`;
64
+ const message = resolveFromConsumer(t, [manifest.dependencies]);
65
+ assert.ok(
66
+ message.includes(`npm install --save-dev ${spec}`),
67
+ `the error names the npm command: ${message}`,
68
+ );
69
+ assert.ok(
70
+ message.includes(`pnpm add --save-dev ${spec}`),
71
+ `the error names the pnpm command: ${message}`,
72
+ );
73
+ });
@@ -0,0 +1,66 @@
1
+ import { apiTargetFile, readTarget } from "./forwarder.mjs";
2
+ import { isSameProcess } from "./identity.mjs";
3
+ import { startMongod } from "./mongo.mjs";
4
+ import { killRecorded, stopRecorded } from "./processes.mjs";
5
+ import { resolutionFolders } from "./launch.mjs";
6
+ import { liveBackends, record } from "./stack.mjs";
7
+
8
+ /** @typedef {import("./run-state.mjs").RunState} RunState */
9
+
10
+ /**
11
+ * @param {RunState} state The run
12
+ * @returns {import("./run-state.mjs").ServerRecord} The mongod the run started
13
+ * @throws When the run uses a server it does not own (`--mongo-url`) or recorded no mongod
14
+ */
15
+ function ownedMongod(state) {
16
+ if (!state.ownsMongo) {
17
+ throw new Error(
18
+ "this run uses --mongo-url: it does not own the server, so it neither stops nor starts it",
19
+ );
20
+ }
21
+ const mongod = state.processes.find((entry) => entry.name === "mongod");
22
+ if (mongod?.port === undefined) {
23
+ throw new Error("this run recorded no mongod");
24
+ }
25
+ return { ...mongod, port: mongod.port };
26
+ }
27
+
28
+ /**
29
+ * Stops the run's mongod, as a crash of the database would: the backend the
30
+ * API forwards to loses its connection until {@link startDatabase}. Every
31
+ * other backend, such as the next database's standby, is killed first, so
32
+ * none that booted without its database is ever promoted. The mongod's
33
+ * record stays, and stopping a mongod that no longer runs signals nothing.
34
+ *
35
+ * @param {RunState} state The run
36
+ * @returns {Promise<void>} Resolves once mongod no longer runs
37
+ * @throws When the run does not own its server, before it stops anything
38
+ */
39
+ export async function stopDatabase(state) {
40
+ const mongod = ownedMongod(state);
41
+ const target = readTarget(apiTargetFile(state.dir));
42
+ await killRecorded(
43
+ liveBackends(state).filter((backend) => backend.port !== target),
44
+ );
45
+ await stopRecorded([mongod]);
46
+ }
47
+
48
+ /**
49
+ * Starts the run's mongod again on its port and data folder, so the URL the
50
+ * backend holds reaches it and the data written before is still there. A
51
+ * mongod that still runs is kept.
52
+ *
53
+ * @param {RunState} state The run
54
+ * @returns {Promise<void>} Resolves once mongod listens
55
+ * @throws When the run does not own its server
56
+ */
57
+ export async function startDatabase(state) {
58
+ const mongod = ownedMongod(state);
59
+ if (isSameProcess(mongod)) return;
60
+ const started = await startMongod(
61
+ state,
62
+ resolutionFolders(state),
63
+ mongod.port,
64
+ );
65
+ record(state, started.record);
66
+ }
@@ -203,6 +203,13 @@ async function freshnessLines(state) {
203
203
  * @param {number} frontendSources
204
204
  */
205
205
  async function frontendBuildLine(state, frontendBuild, frontendSources) {
206
+ if (state.frontendMode === "dev") {
207
+ return line(
208
+ "frontend serves the sources with ajs dms dev",
209
+ true,
210
+ "no build to compare",
211
+ );
212
+ }
206
213
  const recorded = state.frontendBuild;
207
214
  if (!recorded?.key) {
208
215
  return line(
@@ -8,7 +8,8 @@ import {
8
8
  WORKSPACE_FOLDER,
9
9
  } from "./build-key.mjs";
10
10
  import { layOutCopy } from "./run-copy.mjs";
11
- import { frontendPackage, workspaceSetup } from "./stack.mjs";
11
+ import { frontendPackage } from "./launch.mjs";
12
+ import { workspaceSetup } from "./stack.mjs";
12
13
 
13
14
  const SUFFIX_BYTES = 4;
14
15
 
@@ -0,0 +1,24 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { newRun } from "./helpers/fake-run.mjs";
4
+ import { loadRun, saveRun } from "./run-state.mjs";
5
+ import { cliPaths } from "./launch.mjs";
6
+ import { frontendSpec } from "./stack.mjs";
7
+
8
+ await test("a run in dev mode serves its dashboard with ajs dms dev on its web port against its API, after a reload of run.json", async (t) => {
9
+ const state = await newRun(t);
10
+ state.frontendMode = "dev";
11
+ state.webPort = 4321;
12
+ saveRun(state);
13
+ const loaded = loadRun(state.dir);
14
+ assert.deepEqual(frontendSpec(loaded).args, [
15
+ cliPaths(state.playground).dms,
16
+ "dev",
17
+ "-e",
18
+ "docs",
19
+ "-b",
20
+ state.apiUrl,
21
+ "-p",
22
+ "4321",
23
+ ]);
24
+ });
@@ -10,6 +10,9 @@ const NAMESPACE_KINDS = ["pid", "time"];
10
10
  /** The index of the start time, field 22 of `/proc/<pid>/stat`, among the fields after the command name, which start at field 3. */
11
11
  const START_TIME_FIELD = 19;
12
12
 
13
+ /** The index of the parent pid, field 4 of `/proc/<pid>/stat`, among the fields after the command name. */
14
+ const PARENT_FIELD = 1;
15
+
13
16
  /** The length of a clock tick in /proc: USER_HZ is 100 on every architecture Node runs on. */
14
17
  const MS_PER_TICK = 10;
15
18
 
@@ -84,23 +87,37 @@ export function isRunning(pid) {
84
87
  }
85
88
 
86
89
  /**
87
- * When the kernel started `pid`, in clock ticks since boot (field 22 of
88
- * `/proc/<pid>/stat`), or `null` when no such process exists.
90
+ * The parent of `pid` and when the kernel started it, in clock ticks since
91
+ * boot (fields 4 and 22 of `/proc/<pid>/stat`), both from one read, or
92
+ * `null` when no such process exists.
89
93
  *
90
94
  * @param {number} pid The process id
91
- * @returns {number | null} Its start time
95
+ * @returns {{ parent: number, startTime: number } | null} Its parent and start time
92
96
  */
93
- export function startTimeOf(pid) {
97
+ export function statOf(pid) {
94
98
  try {
95
99
  const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
96
100
  const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
97
101
  const ticks = Number(fields[START_TIME_FIELD]);
98
- return Number.isSafeInteger(ticks) ? ticks : null;
102
+ return Number.isSafeInteger(ticks)
103
+ ? { parent: Number(fields[PARENT_FIELD]), startTime: ticks }
104
+ : null;
99
105
  } catch {
100
106
  return null;
101
107
  }
102
108
  }
103
109
 
110
+ /**
111
+ * When the kernel started `pid`, in clock ticks since boot (field 22 of
112
+ * `/proc/<pid>/stat`), or `null` when no such process exists.
113
+ *
114
+ * @param {number} pid The process id
115
+ * @returns {number | null} Its start time
116
+ */
117
+ export function startTimeOf(pid) {
118
+ return statOf(pid)?.startTime ?? null;
119
+ }
120
+
104
121
  /** @returns {number | null} The pid `/proc/self/stat` gives this process, or `null` without one */
105
122
  function pidInProc() {
106
123
  try {
@@ -118,7 +135,7 @@ function pidInProc() {
118
135
  *
119
136
  * @returns {boolean} True when `/proc/self` exists
120
137
  */
121
- function hasProc() {
138
+ export function hasProc() {
122
139
  return existsSync("/proc/self");
123
140
  }
124
141
 
@@ -212,13 +229,29 @@ function startedAround(ticks, startedAt) {
212
229
  }
213
230
  }
214
231
 
232
+ /**
233
+ * Whether a process the kernel started `ticks` after boot is the one
234
+ * `record` names: the start time recorded with it, or, for a record with no
235
+ * start time, as an earlier dms-control wrote, a start within a few seconds
236
+ * of the record's `startedAt`.
237
+ *
238
+ * @param {{ startTime?: number | null, startedAt?: string }} record A process the run recorded
239
+ * @param {number} ticks The kernel start time of the process its pid names
240
+ * @returns {boolean} True when they are the same process
241
+ */
242
+ export function startedAs(record, ticks) {
243
+ const recorded = record.startTime ?? null;
244
+ return recorded === null
245
+ ? startedAround(ticks, record.startedAt)
246
+ : ticks === recorded;
247
+ }
248
+
215
249
  /**
216
250
  * Whether `record` still names the process the run started: its pid runs,
217
- * and the kernel started that process at the time recorded with it, so a
218
- * pid the system has since given to another process is not taken for it. A
219
- * record with no start time, as an earlier dms-control wrote, names the
220
- * process only while the kernel started it within a few seconds of the
221
- * record's `startedAt`. On a system with no /proc, a running pid names it.
251
+ * and the kernel started that process at the time recorded with it (see
252
+ * {@link startedAs}), so a pid the system has since given to another
253
+ * process is not taken for it. On a system with no /proc, a running pid
254
+ * names it.
222
255
  *
223
256
  * @param {{ pid: number, startTime?: number | null, startedAt?: string }} record A process the run recorded
224
257
  * @returns {boolean} True while that process runs
@@ -230,9 +263,5 @@ export function isSameProcess(record) {
230
263
  if (!hasProc()) return isAlive(record.pid);
231
264
  if (!isRunning(record.pid)) return false;
232
265
  const ticks = startTimeOf(record.pid);
233
- const recorded = record.startTime ?? null;
234
- if (ticks === null) return false;
235
- return recorded === null
236
- ? startedAround(ticks, record.startedAt)
237
- : ticks === recorded;
266
+ return ticks !== null && startedAs(record, ticks);
238
267
  }
@@ -4,6 +4,7 @@ import { join, relative } from "node:path";
4
4
  import { pathToFileURL } from "node:url";
5
5
  import { withBaseBackend } from "./base.mjs";
6
6
  import { launchBrowser, newContext, screenshot } from "./browser.mjs";
7
+ import { startDatabase, stopDatabase } from "./database.mjs";
7
8
  import { capturedMail } from "./mail.mjs";
8
9
  import { isRecord, isString, readRecordList } from "./json.mjs";
9
10
  import { saveRun } from "./run-state.mjs";
@@ -14,7 +15,8 @@ import {
14
15
  onboard,
15
16
  recordedRequest,
16
17
  } from "./session.mjs";
17
- import { ensureMail, resolutionFolders } from "./stack.mjs";
18
+ import { resolutionFolders } from "./launch.mjs";
19
+ import { ensureMail } from "./stack.mjs";
18
20
  import {
19
21
  assertForwardedRun,
20
22
  freshDatabase,
@@ -130,6 +132,7 @@ export class JourneyContext {
130
132
  this.index = 0;
131
133
  /** @type {Tab | undefined} */
132
134
  this.lastTab = undefined;
135
+ this.databaseStopped = false;
133
136
  this.startedAt = new Date().toISOString();
134
137
  this.equal = equal;
135
138
  this.status = status;
@@ -304,7 +307,8 @@ export class JourneyContext {
304
307
  /**
305
308
  * Runs `action` against the base version's backend on the same database,
306
309
  * then the run's own backend again: data written inside `action` is data
307
- * the previous release wrote. Records the base commit as a step.
310
+ * the previous release wrote. Records the base commit as a step. A base
311
+ * that has no playground yet runs on a copy of the run's playground.
308
312
  *
309
313
  * @param {(sha: string) => Promise<void>} action What to do against the base backend
310
314
  * @returns {Promise<string>} The base commit
@@ -323,6 +327,24 @@ export class JourneyContext {
323
327
  return restartBackend(this.state);
324
328
  }
325
329
 
330
+ /**
331
+ * Stops the run's mongod, so the backend loses its database until
332
+ * {@link JourneyContext.startDatabase}. When the journey ends with it
333
+ * stopped, it starts again before the next journey.
334
+ *
335
+ * @throws When the run uses `--mongo-url`, whose server it does not own
336
+ */
337
+ async stopDatabase() {
338
+ await stopDatabase(this.state);
339
+ this.databaseStopped = true;
340
+ }
341
+
342
+ /** Starts the run's mongod again, at the same URL and with the same data. */
343
+ async startDatabase() {
344
+ await startDatabase(this.state);
345
+ this.databaseStopped = false;
346
+ }
347
+
326
348
  /**
327
349
  * The mail the sink captured since the journey started, waiting until
328
350
  * `accept` matches one or the timeout passes; `match` is the latest match.
@@ -348,6 +370,7 @@ export class JourneyContext {
348
370
  for (const context of this.contexts.values()) {
349
371
  await context.close().catch(() => undefined);
350
372
  }
373
+ if (this.databaseStopped) await this.startDatabase();
351
374
  }
352
375
  }
353
376
 
@@ -462,7 +485,12 @@ async function driveJourney(state, feature, journey, skill) {
462
485
  ? failure.message
463
486
  : String(failure?.stack ?? failure);
464
487
  } finally {
465
- await context.close();
488
+ try {
489
+ await context.close();
490
+ } catch (failure) {
491
+ const closing = `closing the journey failed: ${String(failure?.stack ?? failure)}`;
492
+ error = error === null ? closing : `${error}\n${closing}`;
493
+ }
466
494
  await browser.close();
467
495
  }
468
496
  const failed =