@antelopejs/dms 0.18.2 → 0.19.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.
- package/CHANGELOG.md +86 -0
- package/README.md +1 -1
- package/bin/control/backend.mjs +1 -1
- package/bin/control/base.mjs +24 -9
- package/bin/control/base.test.mjs +88 -0
- package/bin/control/browser-client.mjs +1 -1
- package/bin/control/commands-stack.mjs +8 -6
- package/bin/control/commands-verify.mjs +2 -2
- package/bin/control/consumer-install.test.mjs +86 -0
- package/bin/control/database.mjs +66 -0
- package/bin/control/doctor.mjs +7 -0
- package/bin/control/frontend-check.mjs +2 -1
- package/bin/control/frontend-mode.test.mjs +24 -0
- package/bin/control/identity.mjs +45 -16
- package/bin/control/journey.mjs +31 -3
- package/bin/control/journey.test.mjs +207 -2
- package/bin/control/launch.mjs +123 -0
- package/bin/control/module-root.mjs +40 -0
- package/bin/control/module-root.test.mjs +67 -0
- package/bin/control/mongo-server.test.mjs +91 -0
- package/bin/control/mongo.mjs +125 -12
- package/bin/control/namespaces.test.mjs +33 -0
- package/bin/control/options.mjs +1 -0
- package/bin/control/pid-reuse.test.mjs +278 -0
- package/bin/control/processes.mjs +91 -29
- package/bin/control/renderer.test.mjs +1 -1
- package/bin/control/run-copy.mjs +6 -1
- package/bin/control/run-state.mjs +31 -12
- package/bin/control/stack.mjs +86 -173
- package/bin/control/verify/behaviour.test.mjs +36 -23
- package/bin/control/verify/decode.mjs +1 -0
- package/bin/control/verify/emit.mjs +11 -11
- package/bin/control/verify/formal.mjs +29 -15
- package/bin/control/verify/formal.test.mjs +15 -0
- package/bin/control/verify/map.test.mjs +2 -6
- package/bin/control/verify/types.mjs +1 -1
- package/bin/control/verify/verdict.mjs +4 -4
- package/bin/dms-control.mjs +4 -2
- package/dist/attachments/save.js +2 -1
- package/dist/attachments/save.js.map +1 -1
- package/dist/db/models/userNotifications.model.js +14 -8
- package/dist/db/models/userNotifications.model.js.map +1 -1
- package/dist/pages/public/auth/not-a-member.d.ts +9 -0
- package/dist/pages/public/auth/not-a-member.js +27 -0
- package/dist/pages/public/auth/not-a-member.js.map +1 -0
- package/dist/pages/public/index.d.ts +1 -0
- package/dist/pages/public/index.js +1 -0
- package/dist/pages/public/index.js.map +1 -1
- package/dist/routes/auth/oauth/identity-resolution.js +10 -0
- package/dist/routes/auth/oauth/identity-resolution.js.map +1 -1
- package/dist/routes/onboarding.js +1 -5
- package/dist/routes/onboarding.js.map +1 -1
- package/dist/utils/ensure-default-tenant.js +23 -3
- package/dist/utils/ensure-default-tenant.js.map +1 -1
- package/frontend-vue/layers/dms-auth/app/build/utils/noWorkspaceRoute.ts +19 -0
- package/frontend-vue/layers/dms-auth/app/custom-pages/auth/login.vue +4 -6
- package/frontend-vue/layers/dms-auth/app/custom-pages/auth/not-a-member.vue +21 -0
- package/frontend-vue/layers/dms-auth/app/custom-pages/auth/oauth-complete.vue +2 -4
- package/frontend-vue/layers/dms-auth/i18n/locales/auth-en-GB.json +6 -0
- package/frontend-vue/layers/dms-auth/i18n/locales/auth-fr-FR.json +6 -0
- package/frontend-vue/layers/dms-core/app/types/live.ts +2 -0
- package/frontend-vue/layers/dms-ui/app/build/components/containers/drawer/DynamicDrawer.vue +9 -3
- package/frontend-vue/layers/dms-ui/app/build/composables/live/currentPageLive.ts +7 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/live/pageLiveController.ts +23 -3
- package/frontend-vue/layers/dms-ui/app/build/composables/live/usePageDataRefresh.ts +2 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewRealtime.ts +21 -2
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/useTableLiveHold.ts +4 -3
- package/frontend-vue/layers/dms-ui/app/build/utils/accessibilityPreferences.ts +1 -21
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreview.ts +8 -4
- package/frontend-vue/layers/dms-ui/app/build/utils/link.ts +35 -7
- package/frontend-vue/layers/dms-ui/app/components/chart/ApexChartHost.vue +51 -8
- package/frontend-vue/layers/dms-ui/app/components/kpi/KpiCard.vue +3 -0
- package/frontend-vue/layers/dms-ui/app/composables/chart/types.ts +2 -0
- package/frontend-vue/layers/dms-ui/app/composables/chart/useApexChart.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/utils/reducedMotion.ts +22 -0
- package/package.json +6 -6
- package/skills/dms-pages/REFERENCE.md +1 -1
package/bin/control/identity.mjs
CHANGED
|
@@ -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
|
-
*
|
|
88
|
-
* `/proc/<pid>/stat`),
|
|
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
|
|
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)
|
|
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
|
|
218
|
-
* pid the system has since given to another
|
|
219
|
-
*
|
|
220
|
-
*
|
|
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
|
-
|
|
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
|
}
|
package/bin/control/journey.mjs
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
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 =
|
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
chmodSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
mkdtempSync,
|
|
7
|
+
rmSync,
|
|
8
|
+
writeFileSync,
|
|
9
|
+
} from "node:fs";
|
|
10
|
+
import { createConnection } from "node:net";
|
|
4
11
|
import { tmpdir } from "node:os";
|
|
5
12
|
import { join } from "node:path";
|
|
6
13
|
import test from "node:test";
|
|
7
|
-
import {
|
|
14
|
+
import { isSameProcess } from "./identity.mjs";
|
|
15
|
+
import {
|
|
16
|
+
JourneyContext,
|
|
17
|
+
loadJourneys,
|
|
18
|
+
runJourney,
|
|
19
|
+
runJourneyFile,
|
|
20
|
+
} from "./journey.mjs";
|
|
21
|
+
import { apiTargetFile, writeTarget } from "./forwarder.mjs";
|
|
22
|
+
import { startMongod } from "./mongo.mjs";
|
|
23
|
+
import { startDetached, stopRecorded, waitForPort } from "./processes.mjs";
|
|
24
|
+
import { recordBackend } from "./run-state.mjs";
|
|
25
|
+
import { liveBackends } from "./stack.mjs";
|
|
8
26
|
import { readTimings } from "./timing.mjs";
|
|
9
27
|
|
|
10
28
|
const JOURNEY = '{ id: "smoke", title: "t", entryPoint: "e", async run() {} }';
|
|
@@ -117,3 +135,190 @@ await test("a run whose backend holds the API port itself is refused before its
|
|
|
117
135
|
{ message: "this run was started by an older dms-control; run `up` again" },
|
|
118
136
|
);
|
|
119
137
|
});
|
|
138
|
+
|
|
139
|
+
const FAKE_MONGOD = `#!/usr/bin/env node
|
|
140
|
+
const { existsSync, readFileSync, writeFileSync } = require("node:fs");
|
|
141
|
+
const option = (name) => process.argv[process.argv.indexOf(name) + 1];
|
|
142
|
+
const starts = require("node:path").join(option("--dbpath"), "starts");
|
|
143
|
+
const before = existsSync(starts) ? Number(readFileSync(starts, "utf8")) : 0;
|
|
144
|
+
writeFileSync(starts, String(before + 1));
|
|
145
|
+
require("node:net").createServer((socket) => socket.end(String(before + 1))).listen(Number(option("--port")), "127.0.0.1");
|
|
146
|
+
`;
|
|
147
|
+
|
|
148
|
+
/** A driver whose server takes the replica-set setup the run's mongod gets and answers that it accepts writes. */
|
|
149
|
+
const FAKE_DRIVER = `
|
|
150
|
+
class MongoClient {
|
|
151
|
+
async connect() {}
|
|
152
|
+
async close() {}
|
|
153
|
+
db() {
|
|
154
|
+
return {
|
|
155
|
+
admin: () => ({ command: async () => ({ ok: 1, isWritablePrimary: true }) }),
|
|
156
|
+
dropDatabase: async () => {},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
module.exports = { MongoClient };
|
|
161
|
+
`;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @param {number} port The port
|
|
165
|
+
* @returns {Promise<boolean>} Whether something accepts a connection on it
|
|
166
|
+
*/
|
|
167
|
+
function accepts(port) {
|
|
168
|
+
return new Promise((resolve) => {
|
|
169
|
+
const socket = createConnection({ host: "127.0.0.1", port });
|
|
170
|
+
socket.once("connect", () => {
|
|
171
|
+
socket.end();
|
|
172
|
+
resolve(true);
|
|
173
|
+
});
|
|
174
|
+
socket.once("error", () => resolve(false));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @param {number} port The port of a fake mongod
|
|
180
|
+
* @returns {Promise<string>} What it says on a connection: how many times it started on its data folder
|
|
181
|
+
*/
|
|
182
|
+
function starts(port) {
|
|
183
|
+
return new Promise((resolve, reject) => {
|
|
184
|
+
const socket = createConnection({ host: "127.0.0.1", port });
|
|
185
|
+
let text = "";
|
|
186
|
+
socket.on("data", (chunk) => {
|
|
187
|
+
text += String(chunk);
|
|
188
|
+
});
|
|
189
|
+
socket.once("end", () => resolve(text));
|
|
190
|
+
socket.once("error", reject);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* A run that owns a mongod, a fake one that listens on the port it is given.
|
|
196
|
+
*
|
|
197
|
+
* @param {import("node:test").TestContext} t The test
|
|
198
|
+
* @returns {Promise<{ state: { dir: string, logs: string, mongo: string, processes: import("./run-state.mjs").ProcessRecord[], ownsMongo: boolean }, context: JourneyContext, port: number }>} The run, a journey's context and the mongod's port
|
|
199
|
+
*/
|
|
200
|
+
async function runOwningMongod(t) {
|
|
201
|
+
const dir = mkdtempSync(join(tmpdir(), "dms-control-journey-mongod-"));
|
|
202
|
+
const binary = join(dir, "mongod");
|
|
203
|
+
writeFileSync(binary, FAKE_MONGOD);
|
|
204
|
+
chmodSync(binary, 0o755);
|
|
205
|
+
for (const [name, source] of [
|
|
206
|
+
["mongodb", FAKE_DRIVER],
|
|
207
|
+
["mongodb-memory-server-core", "module.exports = {};"],
|
|
208
|
+
]) {
|
|
209
|
+
const root = join(dir, "node_modules", name);
|
|
210
|
+
mkdirSync(root, { recursive: true });
|
|
211
|
+
writeFileSync(join(root, "package.json"), `{"name":"${name}"}`);
|
|
212
|
+
writeFileSync(join(root, "index.js"), source);
|
|
213
|
+
}
|
|
214
|
+
const previous = process.env.DMS_CONTROL_MONGOD;
|
|
215
|
+
process.env.DMS_CONTROL_MONGOD = binary;
|
|
216
|
+
const paths = { mongo: join(dir, "mongo"), logs: dir };
|
|
217
|
+
const mongod = await startMongod(paths, [dir]);
|
|
218
|
+
const state = {
|
|
219
|
+
...paths,
|
|
220
|
+
dir,
|
|
221
|
+
evidence: join(dir, "evidence"),
|
|
222
|
+
playground: dir,
|
|
223
|
+
moduleRoot: dir,
|
|
224
|
+
mongoUrl: mongod.url,
|
|
225
|
+
ownsMongo: true,
|
|
226
|
+
processes: [mongod.record],
|
|
227
|
+
};
|
|
228
|
+
t.after(async () => {
|
|
229
|
+
await stopRecorded(state.processes);
|
|
230
|
+
if (previous === undefined) delete process.env.DMS_CONTROL_MONGOD;
|
|
231
|
+
else process.env.DMS_CONTROL_MONGOD = previous;
|
|
232
|
+
rmSync(dir, { recursive: true, force: true });
|
|
233
|
+
});
|
|
234
|
+
const context = new JourneyContext(state, "feat", "j1", undefined, undefined);
|
|
235
|
+
return { state, context, port: mongod.record.port };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
await test("a journey stops the run's mongod and starts it again on the same port and data folder; a mongod left running, or started on a new port or folder, fails it", async (t) => {
|
|
239
|
+
const { state, context, port } = await runOwningMongod(t);
|
|
240
|
+
await context.stopDatabase();
|
|
241
|
+
assert.equal(await accepts(port), false, "nothing listens once stopped");
|
|
242
|
+
await context.startDatabase();
|
|
243
|
+
assert.equal(await accepts(port), true, "mongod listens again");
|
|
244
|
+
assert.equal(await starts(port), "2");
|
|
245
|
+
assert.ok(
|
|
246
|
+
state.processes.some(
|
|
247
|
+
(entry) => entry.name === "mongod" && isSameProcess(entry),
|
|
248
|
+
),
|
|
249
|
+
"the run records the mongod that runs now",
|
|
250
|
+
);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
await test("starting a mongod that runs keeps it; spawning another fails on its taken port", async (t) => {
|
|
254
|
+
const { state, context } = await runOwningMongod(t);
|
|
255
|
+
const [before] = state.processes;
|
|
256
|
+
await context.startDatabase();
|
|
257
|
+
assert.deepEqual(state.processes, [before]);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
await test("a journey that ends with mongod stopped leaves it running for the next one, which a fresh database needs", async (t) => {
|
|
261
|
+
const { context, port } = await runOwningMongod(t);
|
|
262
|
+
await context.stopDatabase();
|
|
263
|
+
await context.close();
|
|
264
|
+
assert.equal(await accepts(port), true);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
await test("a run on --mongo-url refuses to stop a mongod it does not own, the server keeps answering, and the journey still closes without trying to start it", async (t) => {
|
|
268
|
+
const { state, context, port } = await runOwningMongod(t);
|
|
269
|
+
state.ownsMongo = false;
|
|
270
|
+
await assert.rejects(context.stopDatabase(), /--mongo-url/);
|
|
271
|
+
await context.close();
|
|
272
|
+
assert.equal(await accepts(port), true);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @param {{ dir: string, logs: string }} state The run
|
|
277
|
+
* @param {number} port The port it is recorded on
|
|
278
|
+
* @returns {import("./run-state.mjs").BackendRecord} A backend the run recorded, a process that waits
|
|
279
|
+
*/
|
|
280
|
+
function recordedBackend(state, port) {
|
|
281
|
+
const started = startDetached({
|
|
282
|
+
name: `backend-${port}`,
|
|
283
|
+
program: process.execPath,
|
|
284
|
+
args: ["-e", "setInterval(() => {}, 1000)"],
|
|
285
|
+
cwd: state.dir,
|
|
286
|
+
env: process.env,
|
|
287
|
+
logs: state.logs,
|
|
288
|
+
});
|
|
289
|
+
const backend = { ...started, port, database: `verify_x_${port}` };
|
|
290
|
+
recordBackend(state.dir, backend);
|
|
291
|
+
return backend;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
await test("stopping the database kills the standby, which would boot without its database and be promoted, and keeps the backend the API forwards to", async (t) => {
|
|
295
|
+
const { state, context } = await runOwningMongod(t);
|
|
296
|
+
const serving = recordedBackend(state, 41001);
|
|
297
|
+
const standby = recordedBackend(state, 41002);
|
|
298
|
+
t.after(() => stopRecorded([serving, standby]));
|
|
299
|
+
writeTarget(apiTargetFile(state.dir), serving.port);
|
|
300
|
+
await context.stopDatabase();
|
|
301
|
+
assert.deepEqual(
|
|
302
|
+
liveBackends(state).map((backend) => backend.port),
|
|
303
|
+
[serving.port],
|
|
304
|
+
);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
await test("a mongod that cannot take its port while another program holds it fails to start, instead of the run trusting that program", async (t) => {
|
|
308
|
+
const { state, context, port } = await runOwningMongod(t);
|
|
309
|
+
await context.stopDatabase();
|
|
310
|
+
const squatter = startDetached({
|
|
311
|
+
name: "squatter",
|
|
312
|
+
program: process.execPath,
|
|
313
|
+
args: [
|
|
314
|
+
"-e",
|
|
315
|
+
`require("node:net").createServer((s) => s.end()).listen(${port}, "127.0.0.1")`,
|
|
316
|
+
],
|
|
317
|
+
cwd: state.dir,
|
|
318
|
+
env: process.env,
|
|
319
|
+
logs: state.logs,
|
|
320
|
+
});
|
|
321
|
+
t.after(() => stopRecorded([squatter]));
|
|
322
|
+
await waitForPort(port, squatter, 5_000);
|
|
323
|
+
await assert.rejects(context.startDatabase(), /does not listen on/);
|
|
324
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { RENDERER_CLI } from "./renderer.mjs";
|
|
5
|
+
|
|
6
|
+
const DROPPED_PREFIXES = ["ANTELOPEJS_", "npm_", "PNPM_", "DMS_", "MONGO_"];
|
|
7
|
+
|
|
8
|
+
/** This package's root, which resolves dms-control's own dependencies. */
|
|
9
|
+
export const PACKAGE_ROOT = resolve(import.meta.dirname, "..", "..");
|
|
10
|
+
|
|
11
|
+
/** The dms-control entry, which also serves the mail sink and the browser. */
|
|
12
|
+
export const CONTROL_BIN = join(PACKAGE_ROOT, "bin", "dms-control.mjs");
|
|
13
|
+
|
|
14
|
+
/** The AntelopeJS environment every run builds and starts. */
|
|
15
|
+
export const ENVIRONMENT = "docs";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The folders the project's dependencies resolve from: the playground, the
|
|
19
|
+
* module it belongs to, then this package.
|
|
20
|
+
*
|
|
21
|
+
* @param {{ playground: string, moduleRoot: string }} state The run
|
|
22
|
+
* @returns {string[]} The folders, in order
|
|
23
|
+
*/
|
|
24
|
+
export function resolutionFolders(state) {
|
|
25
|
+
return [state.playground, state.moduleRoot, PACKAGE_ROOT];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The `ajs` and `ajs dms` entry points the playground installs, `ajs dms`
|
|
30
|
+
* being the renderer checkout's when the run serves one.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} playground The playground folder
|
|
33
|
+
* @param {string} [renderer] The renderer checkout the run serves
|
|
34
|
+
* @returns {{ ajs: string, dms: string }} Their scripts
|
|
35
|
+
*/
|
|
36
|
+
export function cliPaths(playground, renderer) {
|
|
37
|
+
const require = createRequire(join(playground, "package.json"));
|
|
38
|
+
const core = dirname(require.resolve("@antelopejs/core/package.json"));
|
|
39
|
+
return {
|
|
40
|
+
ajs: join(core, "dist", "core", "cli", "index.js"),
|
|
41
|
+
dms: join(frontendPackage(playground, renderer), RENDERER_CLI),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The `@antelopejs/dms-frontend` that builds and serves the run's dashboard:
|
|
47
|
+
* the renderer checkout, else the one the playground installs.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} playground The playground folder
|
|
50
|
+
* @param {string} [renderer] The renderer checkout the run serves
|
|
51
|
+
* @returns {string} Its folder
|
|
52
|
+
*/
|
|
53
|
+
export function frontendPackage(playground, renderer) {
|
|
54
|
+
const require = createRequire(join(playground, "package.json"));
|
|
55
|
+
return (
|
|
56
|
+
renderer ??
|
|
57
|
+
dirname(require.resolve("@antelopejs/dms-frontend/package.json"))
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function inheritedEnv() {
|
|
62
|
+
return Object.fromEntries(
|
|
63
|
+
Object.entries(process.env).filter(
|
|
64
|
+
([key]) => !DROPPED_PREFIXES.some((prefix) => key.startsWith(prefix)),
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The environment of every process a run starts: its own HOME, ports,
|
|
71
|
+
* database, origin and secrets, an npm cache and a pnpm store shared by
|
|
72
|
+
* every run, no update checks and no colors. Extra `KEY=VALUE` pairs from `--env` come last.
|
|
73
|
+
*
|
|
74
|
+
* @param {import("./run-state.mjs").RunState} state The run
|
|
75
|
+
* @returns {NodeJS.ProcessEnv} The environment
|
|
76
|
+
*/
|
|
77
|
+
export function runEnv(state) {
|
|
78
|
+
const cacheHome = process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache");
|
|
79
|
+
return {
|
|
80
|
+
...inheritedEnv(),
|
|
81
|
+
HOME: state.home,
|
|
82
|
+
USERPROFILE: state.home,
|
|
83
|
+
CI: "1",
|
|
84
|
+
NO_COLOR: "1",
|
|
85
|
+
AJS_NO_UPDATE_CHECK: "1",
|
|
86
|
+
NO_UPDATE_NOTIFIER: "1",
|
|
87
|
+
COREPACK_HOME:
|
|
88
|
+
process.env.COREPACK_HOME ?? join(cacheHome, "node", "corepack"),
|
|
89
|
+
npm_config_cache: join(cacheHome, "dms-control", "npm"),
|
|
90
|
+
npm_config_store_dir: join(cacheHome, "dms-control", "pnpm-store"),
|
|
91
|
+
PORT: String(state.apiPort),
|
|
92
|
+
DMS_CLIENT_BASE_URL: state.webUrl,
|
|
93
|
+
DMS_API_BASE_URL: state.apiUrl,
|
|
94
|
+
DMS_PREBUILT: "1",
|
|
95
|
+
DMS_SMTP_PORT: String(state.smtpPort),
|
|
96
|
+
MONGO_URL: state.mongoUrl,
|
|
97
|
+
MONGO_DATABASE: state.database,
|
|
98
|
+
...state.secrets,
|
|
99
|
+
...state.extraEnv,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* How to run one of the playground's CLIs for the run: its own log, the
|
|
105
|
+
* run's environment, from the run's playground copy or `cwd`.
|
|
106
|
+
*
|
|
107
|
+
* @param {import("./run-state.mjs").RunState} state The run
|
|
108
|
+
* @param {string} name The log name
|
|
109
|
+
* @param {string} script The CLI script
|
|
110
|
+
* @param {string[]} args Its arguments
|
|
111
|
+
* @param {string} [cwd] Where to run it
|
|
112
|
+
* @returns {{ name: string, program: string, args: string[], cwd: string, env: NodeJS.ProcessEnv, logs: string }} The process spec
|
|
113
|
+
*/
|
|
114
|
+
export function spec(state, name, script, args, cwd = state.runPlayground) {
|
|
115
|
+
return {
|
|
116
|
+
name,
|
|
117
|
+
program: process.execPath,
|
|
118
|
+
args: [script, ...args],
|
|
119
|
+
cwd,
|
|
120
|
+
env: runEnv(state),
|
|
121
|
+
logs: state.logs,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { isRecord } from "./json.mjs";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} folder
|
|
7
|
+
* @returns {boolean} Whether its `package.json` declares an AntelopeJS manifest
|
|
8
|
+
*/
|
|
9
|
+
function isAntelopeModule(folder) {
|
|
10
|
+
try {
|
|
11
|
+
/** @type {unknown} */
|
|
12
|
+
const manifest = JSON.parse(
|
|
13
|
+
readFileSync(join(folder, "package.json"), "utf8"),
|
|
14
|
+
);
|
|
15
|
+
return isRecord(manifest) && Object.hasOwn(manifest, "antelopeJs");
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The module a playground verifies: the nearest folder above it whose
|
|
23
|
+
* `package.json` declares `antelopeJs`, so a playground in a verification
|
|
24
|
+
* skill (`.agents/skills/<skill>/playground`) verifies the repository's
|
|
25
|
+
* module, not the skill folder. Its parent when no folder above declares
|
|
26
|
+
* one.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} playground The playground folder
|
|
29
|
+
* @returns {string} The module's folder
|
|
30
|
+
*/
|
|
31
|
+
export function moduleRootOf(playground) {
|
|
32
|
+
for (
|
|
33
|
+
let folder = dirname(playground);
|
|
34
|
+
folder !== dirname(folder);
|
|
35
|
+
folder = dirname(folder)
|
|
36
|
+
) {
|
|
37
|
+
if (isAntelopeModule(folder)) return folder;
|
|
38
|
+
}
|
|
39
|
+
return dirname(playground);
|
|
40
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import {
|
|
3
|
+
mkdirSync,
|
|
4
|
+
mkdtempSync,
|
|
5
|
+
realpathSync,
|
|
6
|
+
rmSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
} from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import test from "node:test";
|
|
12
|
+
import { moduleRootOf } from "./module-root.mjs";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {import("node:test").TestContext} t The test
|
|
16
|
+
* @returns {string} A real scratch folder removed when the test ends
|
|
17
|
+
*/
|
|
18
|
+
function scratch(t) {
|
|
19
|
+
const dir = realpathSync(
|
|
20
|
+
mkdtempSync(join(tmpdir(), "dms-control-module-root-test-")),
|
|
21
|
+
);
|
|
22
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
23
|
+
return dir;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} folder The folder
|
|
28
|
+
* @param {Record<string, unknown>} manifest Its `package.json`
|
|
29
|
+
* @returns {string} The folder
|
|
30
|
+
*/
|
|
31
|
+
function writePackage(folder, manifest) {
|
|
32
|
+
mkdirSync(folder, { recursive: true });
|
|
33
|
+
writeFileSync(join(folder, "package.json"), JSON.stringify(manifest));
|
|
34
|
+
return folder;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const MODULE = {
|
|
38
|
+
name: "@antelopejs/dms-x",
|
|
39
|
+
version: "1.2.3",
|
|
40
|
+
antelopeJs: { baseUrl: "dist" },
|
|
41
|
+
};
|
|
42
|
+
const PLAYGROUND = { name: "playground", antelopeJs: { baseUrl: "dist" } };
|
|
43
|
+
|
|
44
|
+
await test("the module of a playground in a verification skill is the repository's module, not the skill folder", (t) => {
|
|
45
|
+
const repo = writePackage(scratch(t), MODULE);
|
|
46
|
+
const skill = writePackage(join(repo, ".agents", "skills", "verify-dms-x"), {
|
|
47
|
+
type: "module",
|
|
48
|
+
});
|
|
49
|
+
const playground = writePackage(join(skill, "playground"), PLAYGROUND);
|
|
50
|
+
assert.equal(moduleRootOf(playground), repo);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
await test("the module of a playground inside the module is its parent", (t) => {
|
|
54
|
+
const workspace = writePackage(scratch(t), {
|
|
55
|
+
name: "workspace",
|
|
56
|
+
antelopeJs: {},
|
|
57
|
+
});
|
|
58
|
+
const module = writePackage(join(workspace, "packages", "dms"), MODULE);
|
|
59
|
+
const playground = writePackage(join(module, "playground"), PLAYGROUND);
|
|
60
|
+
assert.equal(moduleRootOf(playground), module);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await test("a playground with no module above it keeps its parent as the module", (t) => {
|
|
64
|
+
const parent = scratch(t);
|
|
65
|
+
const playground = writePackage(join(parent, "playground"), PLAYGROUND);
|
|
66
|
+
assert.equal(moduleRootOf(playground), parent);
|
|
67
|
+
});
|