@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.
- package/CHANGELOG.md +60 -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 +3 -1
- package/bin/control/consumer-install.test.mjs +73 -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/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 +4 -1
- package/bin/control/stack.mjs +78 -165
- 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 +28 -14
- package/bin/control/verify/formal.test.mjs +15 -0
- package/bin/control/verify/types.mjs +1 -1
- package/bin/dms-control.mjs +4 -2
- 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/composables/chart/useApexChart.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/utils/reducedMotion.ts +22 -0
- package/package.json +4 -4
- package/skills/dms-pages/REFERENCE.md +1 -1
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import {
|
|
4
|
+
chmodSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
mkdtempSync,
|
|
7
|
+
rmSync,
|
|
8
|
+
writeFileSync,
|
|
9
|
+
} from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import test from "node:test";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { MongoClient } from "mongodb";
|
|
15
|
+
import { mongodBinary, startMongod } from "./mongo.mjs";
|
|
16
|
+
import { stopRecorded } from "./processes.mjs";
|
|
17
|
+
|
|
18
|
+
const PACKAGE_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {import("node:test").TestContext} t
|
|
22
|
+
* @returns {{ root: string, mongo: string, logs: string }} A run's folders, removed after the test
|
|
23
|
+
*/
|
|
24
|
+
function runFolders(t) {
|
|
25
|
+
const root = mkdtempSync(join(tmpdir(), "dms-control-mongod-test-"));
|
|
26
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
27
|
+
const paths = { root, mongo: join(root, "mongo"), logs: join(root, "logs") };
|
|
28
|
+
mkdirSync(paths.logs);
|
|
29
|
+
return paths;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
await test("the run's mongod serves a change stream", async (t) => {
|
|
33
|
+
const paths = runFolders(t);
|
|
34
|
+
const server = await startMongod(paths, [PACKAGE_ROOT]);
|
|
35
|
+
const client = new MongoClient(server.url);
|
|
36
|
+
t.after(async () => {
|
|
37
|
+
await client.close();
|
|
38
|
+
await stopRecorded([server.record]);
|
|
39
|
+
});
|
|
40
|
+
const items = client.db("verify_test").collection("items");
|
|
41
|
+
const stream = items.watch();
|
|
42
|
+
assert.equal(await stream.tryNext(), null);
|
|
43
|
+
await items.insertOne({ name: "watched" });
|
|
44
|
+
const change = await stream.next();
|
|
45
|
+
assert.equal(
|
|
46
|
+
change.operationType === "insert" ? change.fullDocument.name : undefined,
|
|
47
|
+
"watched",
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
await test("a mongod that cannot join the replica set is stopped", async (t) => {
|
|
52
|
+
const paths = runFolders(t);
|
|
53
|
+
const binary = await mongodBinary([PACKAGE_ROOT]);
|
|
54
|
+
const wrapper = join(paths.root, "mongod-standalone");
|
|
55
|
+
writeFileSync(
|
|
56
|
+
wrapper,
|
|
57
|
+
`#!/bin/sh\nexec "${binary}" --dbpath "$2" --port "$4" --bind_ip 127.0.0.1\n`,
|
|
58
|
+
);
|
|
59
|
+
chmodSync(wrapper, 0o755);
|
|
60
|
+
const saved = process.env.DMS_CONTROL_MONGOD;
|
|
61
|
+
process.env.DMS_CONTROL_MONGOD = wrapper;
|
|
62
|
+
t.after(() => {
|
|
63
|
+
if (saved === undefined) delete process.env.DMS_CONTROL_MONGOD;
|
|
64
|
+
else process.env.DMS_CONTROL_MONGOD = saved;
|
|
65
|
+
});
|
|
66
|
+
await assert.rejects(startMongod(paths, [PACKAGE_ROOT]), {
|
|
67
|
+
message: "This node was not started with replication enabled.",
|
|
68
|
+
});
|
|
69
|
+
assert.equal(spawnSync("pgrep", ["-f", paths.mongo]).status, 1);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
await test("a mongod restarted on its port and data folder serves a change stream again", async (t) => {
|
|
73
|
+
const paths = runFolders(t);
|
|
74
|
+
const first = await startMongod(paths, [PACKAGE_ROOT]);
|
|
75
|
+
await stopRecorded([first.record]);
|
|
76
|
+
const again = await startMongod(paths, [PACKAGE_ROOT], first.record.port);
|
|
77
|
+
const client = new MongoClient(again.url);
|
|
78
|
+
t.after(async () => {
|
|
79
|
+
await client.close();
|
|
80
|
+
await stopRecorded([again.record]);
|
|
81
|
+
});
|
|
82
|
+
const items = client.db("verify_test").collection("items");
|
|
83
|
+
const stream = items.watch();
|
|
84
|
+
assert.equal(await stream.tryNext(), null);
|
|
85
|
+
await items.insertOne({ name: "after restart" });
|
|
86
|
+
const change = await stream.next();
|
|
87
|
+
assert.equal(
|
|
88
|
+
change.operationType === "insert" ? change.fullDocument.name : undefined,
|
|
89
|
+
"after restart",
|
|
90
|
+
);
|
|
91
|
+
});
|