@jskit-ai/jskit-catalog 0.2.115 → 0.2.117
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/app-guidance/AGENTS.block.md +47 -0
- package/catalog/packages.json +160 -160
- package/package.json +2 -1
- package/scripts/agents-block.mjs +121 -0
- package/scripts/browser-test-build.mjs +2 -2
- package/scripts/browser-test-servers.mjs +61 -46
- package/scripts/jskit.mjs +42 -7
- package/scripts/test-command.mjs +66 -36
- package/scripts/test-databases.mjs +6 -3
- package/scripts/test-environment.mjs +8 -4
- package/scripts/test-network-guard-preload.mjs +5 -0
- package/scripts/test-network-guard.mjs +133 -0
- package/scripts/test-runs.mjs +16 -0
- package/scripts/test-sources.mjs +256 -0
package/package.json
CHANGED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
6
|
+
const BLOCK_SOURCE = path.join(PACKAGE_ROOT, "app-guidance", "AGENTS.block.md");
|
|
7
|
+
const CATALOG = "@jskit-ai/jskit-catalog";
|
|
8
|
+
const BEGIN = "<!-- jskit:begin app guidance (written by npx jskit agents; edit outside this block) -->";
|
|
9
|
+
const END = "<!-- jskit:end app guidance -->";
|
|
10
|
+
const GUIDE = "https://mobily-enterprises.github.io/jskit-ai/guide/framework/typed-features#agent-instructions";
|
|
11
|
+
const FIX = "run `npx jskit agents` and commit AGENTS.md.";
|
|
12
|
+
|
|
13
|
+
async function readOptional(file) {
|
|
14
|
+
try {
|
|
15
|
+
return await readFile(file, "utf8");
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error?.code === "ENOENT") return null;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** This catalog's block, markers included, and its version. */
|
|
23
|
+
async function catalogBlock() {
|
|
24
|
+
const [source, manifest] = await Promise.all([
|
|
25
|
+
readFile(BLOCK_SOURCE, "utf8"),
|
|
26
|
+
readFile(path.join(PACKAGE_ROOT, "package.json"), "utf8")
|
|
27
|
+
]);
|
|
28
|
+
return { block: `${BEGIN}\n${source}${END}`, version: JSON.parse(manifest).version };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Where AGENTS.md's block lies: `start` and `stop` around one begin marker followed by one end marker, nothing when
|
|
33
|
+
* the file has neither, and `malformed` when its markers are not one such pair.
|
|
34
|
+
* @param {string} text
|
|
35
|
+
*/
|
|
36
|
+
function locateBlock(text) {
|
|
37
|
+
const begins = text.split(BEGIN).length - 1;
|
|
38
|
+
const ends = text.split(END).length - 1;
|
|
39
|
+
if (begins === 0 && ends === 0) return { found: false };
|
|
40
|
+
const start = text.indexOf(BEGIN);
|
|
41
|
+
const end = text.indexOf(END);
|
|
42
|
+
if (begins !== 1 || ends !== 1 || end < start) {
|
|
43
|
+
return {
|
|
44
|
+
found: true,
|
|
45
|
+
malformed: `AGENTS.md has ${begins} JSKIT begin marker(s) and ${ends} end marker(s)` +
|
|
46
|
+
(begins === 1 && ends === 1 ? ", the end first" : "")
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return { found: true, start, stop: end + END.length };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* `jskit agents`: writes this catalog's block into the app's AGENTS.md, between its markers, or at the top of a file
|
|
54
|
+
* without them, made if absent. Text outside the markers stays as it is.
|
|
55
|
+
* @param {{ projectRoot: string }} options
|
|
56
|
+
*/
|
|
57
|
+
async function writeAgentsBlock({ projectRoot }) {
|
|
58
|
+
const file = path.join(projectRoot, "AGENTS.md");
|
|
59
|
+
const [{ block, version }, existing] = await Promise.all([catalogBlock(), readOptional(file)]);
|
|
60
|
+
if (existing === null) {
|
|
61
|
+
await writeFile(file, `${block}\n`);
|
|
62
|
+
return { version, placed: "created", changed: true };
|
|
63
|
+
}
|
|
64
|
+
const located = locateBlock(existing);
|
|
65
|
+
if (located.malformed) {
|
|
66
|
+
throw new Error(`${located.malformed}; leave one pair, the begin marker first, or none, and run npx jskit agents again.`);
|
|
67
|
+
}
|
|
68
|
+
if (!located.found) {
|
|
69
|
+
await writeFile(file, existing.trim() ? `${block}\n\n${existing}` : `${block}\n`);
|
|
70
|
+
return { version, placed: "top", changed: true };
|
|
71
|
+
}
|
|
72
|
+
const next = `${existing.slice(0, located.start)}${block}${existing.slice(located.stop)}`;
|
|
73
|
+
if (next !== existing) await writeFile(file, next);
|
|
74
|
+
return { version, placed: "in place", changed: next !== existing };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function formatAgentsBlockWrite({ version, placed, changed }) {
|
|
78
|
+
if (!changed) return `AGENTS.md already carries the JSKIT block of ${CATALOG} ${version}.`;
|
|
79
|
+
const where = { created: "in a new AGENTS.md", top: "at the top of AGENTS.md", "in place": "in AGENTS.md, between its markers" }[placed];
|
|
80
|
+
return `Wrote the JSKIT block of ${CATALOG} ${version} ${where}. Commit AGENTS.md.`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Plain `jskit check`'s part (`agents/jskit-block`): an app that declares this catalog carries its block in AGENTS.md
|
|
85
|
+
* as `jskit agents` writes it. A project that does not declare the catalog pins no version whose block it could carry.
|
|
86
|
+
* @param {{ projectRoot: string }} options
|
|
87
|
+
*/
|
|
88
|
+
async function checkAgentsBlock({ projectRoot }) {
|
|
89
|
+
const manifest = JSON.parse(await readFile(path.join(projectRoot, "package.json"), "utf8"));
|
|
90
|
+
if (!manifest.dependencies?.[CATALOG] && !manifest.devDependencies?.[CATALOG]) {
|
|
91
|
+
return { ok: true, applies: false, findings: [] };
|
|
92
|
+
}
|
|
93
|
+
const [{ block, version }, existing] = await Promise.all([
|
|
94
|
+
catalogBlock(),
|
|
95
|
+
readOptional(path.join(projectRoot, "AGENTS.md"))
|
|
96
|
+
]);
|
|
97
|
+
const located = existing === null ? { found: false } : locateBlock(existing);
|
|
98
|
+
let message = null;
|
|
99
|
+
if (!located.found) {
|
|
100
|
+
message = `AGENTS.md lacks the JSKIT block of ${CATALOG} ${version}: ${FIX}`;
|
|
101
|
+
} else if (located.malformed || existing.slice(located.start, located.stop) !== block) {
|
|
102
|
+
message = `AGENTS.md's JSKIT block differs from ${CATALOG} ${version}'s: ${FIX}`;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
ok: message === null,
|
|
106
|
+
applies: true,
|
|
107
|
+
version,
|
|
108
|
+
findings: message === null ? [] : [{ file: "AGENTS.md", rule: "agents/jskit-block", message }]
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function formatAgentsBlockReport(result) {
|
|
113
|
+
if (!result.applies) return `JSKIT agent instructions: not checked, as package.json does not declare ${CATALOG}.`;
|
|
114
|
+
const lines = result.findings.flatMap(({ file, rule, message }) => [`${file} ${rule} ${message}`, ` ${GUIDE}`]);
|
|
115
|
+
lines.push(result.ok
|
|
116
|
+
? `JSKIT agent instructions: AGENTS.md carries the JSKIT block of ${CATALOG} ${result.version}.`
|
|
117
|
+
: "JSKIT agent instructions: 1 error.");
|
|
118
|
+
return lines.join("\n");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { checkAgentsBlock, formatAgentsBlockReport, formatAgentsBlockWrite, writeAgentsBlock };
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
// build reads; an edit to server code alone reuses the build. Those are read after the build, so a build during which
|
|
9
9
|
// one of them changed is not kept for reuse: it may hold code from before the change. A build that records no modules (a
|
|
10
10
|
// Vite config without that plugin, or a build that is not Vite's) is keyed on every source file instead, taken before it
|
|
11
|
-
// runs, as it rewrites files it generates among them (vue-router
|
|
12
|
-
// at a time: the second waits, then reuses the first one's build.
|
|
11
|
+
// runs, as it rewrites files it generates among them (a declaration file vue-router writes into src). Two runs in one
|
|
12
|
+
// tree build one at a time: the second waits, then reuses the first one's build.
|
|
13
13
|
import { spawn } from "node:child_process";
|
|
14
14
|
import { createHash } from "node:crypto";
|
|
15
15
|
import {
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
// earlier run would answer for this run's. Stopped by Playwright (SIGTERM), by Ctrl-C, by its terminal's hang-up (SIGHUP,
|
|
9
9
|
// which a host such as Vibe64 sends a target's command first), by the end of the stdin pipe Playwright gives its
|
|
10
10
|
// webServer (a Playwright that ended without stopping it) or by a write its output refused (a hung-up terminal answers
|
|
11
|
-
// EIO, a pipe without a reader EPIPE), the launcher stops its servers and waits for them,
|
|
12
|
-
//
|
|
13
|
-
//
|
|
11
|
+
// EIO, a pipe without a reader EPIPE), the launcher stops its servers and waits for them, within Playwright's grace,
|
|
12
|
+
// before it exits. The databases the prepare module gave the workers stay for the next run, which restores them
|
|
13
|
+
// (database-runtime's prepareTestDatabases()). `jskit browser-test-server` (browser-test-server.mjs) runs it
|
|
14
14
|
// for one server a host starts, with `terminal`: that server's output also reaches the launcher's own. A run takes free
|
|
15
15
|
// ports of its own, so its worker environments and signed-in states have names of their own; the launcher removes them
|
|
16
|
-
// when it stops, so they never pile up in the cache, nor outlive the sessions they hold.
|
|
16
|
+
// when it stops, so they never pile up in the cache, nor outlive the sessions they hold. Each app server, and what it
|
|
17
|
+
// starts, reaches only this machine and the test database (test-network-guard.mjs).
|
|
17
18
|
import { spawn } from "node:child_process";
|
|
18
19
|
import { once } from "node:events";
|
|
19
20
|
import { createWriteStream, fstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
@@ -24,17 +25,14 @@ import process from "node:process";
|
|
|
24
25
|
import { pathToFileURL } from "node:url";
|
|
25
26
|
import { buildFrontend } from "./browser-test-build.mjs";
|
|
26
27
|
import { useTestAppEnvironment } from "./test-environment.mjs";
|
|
28
|
+
import { networkGuardEnvironment } from "./test-network-guard.mjs";
|
|
27
29
|
|
|
28
30
|
const SETTINGS_VARIABLE = "JSKIT_BROWSER_TESTS";
|
|
29
31
|
const LOG_DIRECTORY = path.join("test-results", "browser-test-servers");
|
|
30
32
|
const READY_TIMEOUT_MS = 60_000;
|
|
31
|
-
// Within the 10 s gracefulShutdown browser-tests.mjs gives Playwright's webServer: the servers stop
|
|
32
|
-
// running then is killed
|
|
33
|
+
// Within the 10 s gracefulShutdown browser-tests.mjs gives Playwright's webServer: the servers stop, and one still
|
|
34
|
+
// running then is killed.
|
|
33
35
|
const STOP_WAIT_MS = 4_000;
|
|
34
|
-
const DROP_WAIT_MS = 5_000;
|
|
35
|
-
// Where database-runtime's prepareTestDatabases() keeps, in this process, each set of numbered copies it made with its
|
|
36
|
-
// drop: the app's prepare module loads the app's own copy of that package, so the launcher reads them here.
|
|
37
|
-
const PREPARED_COPIES = Symbol.for("@jskit-ai/database-runtime/preparedTestDatabaseCopies");
|
|
38
36
|
|
|
39
37
|
// The peak resident memory of the largest app server of a run, beside its worker environments, for the next run's
|
|
40
38
|
// worker count (browserTestWorkers()).
|
|
@@ -89,15 +87,22 @@ async function refuseBusyPorts(host, ports) {
|
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Waits until the server answers `url` with a success, and says how long it took: when it first answered at all, and
|
|
92
|
+
* (on Linux) the CPU time its processes used, which tells a start that computes from one that waits on something.
|
|
93
|
+
*/
|
|
92
94
|
async function waitUntilReady(url, server, name) {
|
|
93
95
|
const started = performance.now();
|
|
94
96
|
const deadline = Date.now() + READY_TIMEOUT_MS;
|
|
97
|
+
let answered = "";
|
|
95
98
|
while (Date.now() < deadline) {
|
|
96
99
|
if (server.exitCode !== null || server.signalCode !== null) throw new Error(`${name} stopped while starting.`);
|
|
97
100
|
try {
|
|
98
101
|
const response = await fetch(url, { signal: AbortSignal.timeout(2_000) });
|
|
102
|
+
answered ||= seconds(started);
|
|
99
103
|
if (response.ok) {
|
|
100
|
-
|
|
104
|
+
const cpu = process.platform === "linux" ? `, ${treeCpuSeconds(server.pid).toFixed(1)}s of CPU` : "";
|
|
105
|
+
console.log(`[browser-tests] ${name} started in ${seconds(started)} (first answer at ${answered}${cpu}).`);
|
|
101
106
|
return;
|
|
102
107
|
}
|
|
103
108
|
} catch {
|
|
@@ -114,12 +119,10 @@ let stopping = false;
|
|
|
114
119
|
let runFiles = [];
|
|
115
120
|
// Where this run records its servers' peak memory as they stop.
|
|
116
121
|
let serverMemoryFile = "";
|
|
117
|
-
// The prepare module's work, which a stop waits for (within DROP_WAIT_MS) so the copies it is making are dropped too.
|
|
118
|
-
let preparing = Promise.resolve();
|
|
119
122
|
const running = (server) => server.exitCode === null && server.signalCode === null;
|
|
120
123
|
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms, false));
|
|
121
|
-
/**
|
|
122
|
-
function
|
|
124
|
+
/** Process `pid` and each process under it (Linux's /proc). */
|
|
125
|
+
function processTree(pid) {
|
|
123
126
|
const children = new Map();
|
|
124
127
|
for (const entry of readdirSync("/proc").filter((name) => /^\d+$/u.test(name))) {
|
|
125
128
|
let stat;
|
|
@@ -132,18 +135,40 @@ function treePeakBytes(pid) {
|
|
|
132
135
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
133
136
|
children.set(parent, [...(children.get(parent) ?? []), Number(entry)]);
|
|
134
137
|
}
|
|
135
|
-
|
|
138
|
+
const tree = [];
|
|
136
139
|
for (const queue = [pid]; queue.length > 0;) {
|
|
137
140
|
const current = queue.pop();
|
|
141
|
+
tree.push(current);
|
|
142
|
+
queue.push(...(children.get(current) ?? []));
|
|
143
|
+
}
|
|
144
|
+
return tree;
|
|
145
|
+
}
|
|
146
|
+
/** Adds up what `read` answers for each process of `pid`'s tree, 0 for one that ended while the others were read. */
|
|
147
|
+
function treeTotal(pid, read) {
|
|
148
|
+
let total = 0;
|
|
149
|
+
for (const current of processTree(pid)) {
|
|
138
150
|
try {
|
|
139
|
-
total +=
|
|
151
|
+
total += read(current);
|
|
140
152
|
} catch {
|
|
141
153
|
// It ended while the others were read.
|
|
142
154
|
}
|
|
143
|
-
queue.push(...(children.get(current) ?? []));
|
|
144
155
|
}
|
|
145
156
|
return total;
|
|
146
157
|
}
|
|
158
|
+
/** The peak resident memory (VmHWM) of process `pid` and each process under it, added up, in bytes. */
|
|
159
|
+
function treePeakBytes(pid) {
|
|
160
|
+
return treeTotal(pid, (current) =>
|
|
161
|
+
Number(readFileSync(`/proc/${current}/status`, "utf8").match(/^VmHWM:\s+(\d+) kB$/mu)?.[1] ?? 0) * 1024);
|
|
162
|
+
}
|
|
163
|
+
/** The CPU time, user and system, process `pid` and each process under it have used, in seconds. */
|
|
164
|
+
function treeCpuSeconds(pid) {
|
|
165
|
+
return treeTotal(pid, (current) => {
|
|
166
|
+
const stat = readFileSync(`/proc/${current}/stat`, "utf8");
|
|
167
|
+
// After "pid (name) ": state is field 3, utime 14 and stime 15, in clock ticks of 1/100 s.
|
|
168
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
169
|
+
return (Number(fields[11]) + Number(fields[12])) / 100;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
147
172
|
/** Records the peak memory of the largest of the run's app servers as they stop, for the next run's worker count. */
|
|
148
173
|
function recordServerMemory() {
|
|
149
174
|
if (process.platform !== "linux" || !serverMemoryFile) return;
|
|
@@ -163,25 +188,12 @@ function stopServers() {
|
|
|
163
188
|
stopping = true;
|
|
164
189
|
for (const server of servers) if (running(server)) server.kill("SIGTERM");
|
|
165
190
|
}
|
|
166
|
-
/** Drops every set of numbered copies prepare made, once the servers have exited, and says what it did. */
|
|
167
|
-
async function dropPreparedCopies(exited) {
|
|
168
|
-
await Promise.all([preparing.catch(() => {}), exited]);
|
|
169
|
-
const drops = [...(globalThis[PREPARED_COPIES]?.values() ?? [])];
|
|
170
|
-
for (const report of await Promise.all(drops.map((drop) => drop()))) if (report) console.log(`[browser-tests] ${report}.`);
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
191
|
async function stopAndExit(code) {
|
|
174
192
|
if (stopping) return;
|
|
175
193
|
stopServers();
|
|
176
194
|
const stopped = Promise.all(servers.filter(running).map((server) => once(server, "exit")));
|
|
177
195
|
await Promise.race([stopped, delay(STOP_WAIT_MS)]);
|
|
178
|
-
const
|
|
179
|
-
for (const server of killed) server.kill("SIGKILL");
|
|
180
|
-
const exited = Promise.all(killed.map((server) => once(server, "exit")));
|
|
181
|
-
if (!(await Promise.race([dropPreparedCopies(exited), delay(DROP_WAIT_MS)]))) {
|
|
182
|
-
console.error(`[browser-tests] The prepared test database copies were not all dropped within ${DROP_WAIT_MS / 1000}s; ` +
|
|
183
|
-
"the next run makes them afresh and drops them.");
|
|
184
|
-
}
|
|
196
|
+
for (const server of servers.filter(running)) server.kill("SIGKILL");
|
|
185
197
|
for (const file of runFiles) rmSync(file, { force: true });
|
|
186
198
|
process.exit(code);
|
|
187
199
|
}
|
|
@@ -191,7 +203,7 @@ process.on("SIGINT", () => stopAndExit(130));
|
|
|
191
203
|
process.on("SIGTERM", () => stopAndExit(143));
|
|
192
204
|
process.on("SIGHUP", () => stopAndExit(129));
|
|
193
205
|
// Its servers' output passes through its own, which can go before its stop does: a write that fails there stops it like
|
|
194
|
-
// a signal, never as an uncaught error that would end it before its
|
|
206
|
+
// a signal, never as an uncaught error that would end it before its servers stop.
|
|
195
207
|
for (const output of [process.stdout, process.stderr]) output.on("error", () => stopAndExit(1));
|
|
196
208
|
// Only a pipe ends when Playwright does; a launcher started without one (stdin ignored, /dev/null) would end at once.
|
|
197
209
|
const input = fstatSync(0);
|
|
@@ -219,26 +231,29 @@ runFiles = [workerEnvironmentsFile, ...(signedInStates ? baseUrls.map((_, index)
|
|
|
219
231
|
.filter(Boolean);
|
|
220
232
|
try {
|
|
221
233
|
await refuseBusyPorts(host, baseUrls.map((_, index) => basePort + index));
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
234
|
+
// Both settle before a failure of either ends the start.
|
|
235
|
+
const [built, prepared] = await Promise.allSettled([buildFrontend({ appRoot, build }),
|
|
236
|
+
prepareWorkers(appRoot, prepare, workers, baseUrls)]);
|
|
225
237
|
for (const result of [built, prepared]) if (result.status === "rejected") throw result.reason;
|
|
226
|
-
// A stop during the start
|
|
238
|
+
// A stop during the start ends it; no server starts.
|
|
227
239
|
if (stopping) throw new Error("The run was stopped while it started.");
|
|
228
240
|
const workerEnvironments = prepared.value;
|
|
229
241
|
mkdirSync(path.join(appRoot, LOG_DIRECTORY), { recursive: true });
|
|
230
242
|
mkdirSync(path.dirname(workerEnvironmentsFile), { recursive: true });
|
|
231
243
|
writeFileSync(workerEnvironmentsFile, JSON.stringify(workerEnvironments.slice(0, workers)), { mode: 0o600 });
|
|
232
244
|
const [program, ...args] = words(server);
|
|
233
|
-
const serverEnvironments = workerEnvironments.slice(0, workers).map((workerEnvironment, index) =>
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
245
|
+
const serverEnvironments = workerEnvironments.slice(0, workers).map((workerEnvironment, index) => {
|
|
246
|
+
const serverEnvironment = {
|
|
247
|
+
...baseEnvironment,
|
|
248
|
+
...env,
|
|
249
|
+
...workerEnvironment,
|
|
250
|
+
HOST: host,
|
|
251
|
+
PORT: String(basePort + index),
|
|
252
|
+
TEST_PARALLEL_INDEX: String(index),
|
|
253
|
+
APP_ENV: "test"
|
|
254
|
+
};
|
|
255
|
+
return { ...serverEnvironment, ...networkGuardEnvironment(serverEnvironment, "jskit browser tests") };
|
|
256
|
+
});
|
|
242
257
|
await Promise.all(serverEnvironments.map((serverEnvironment, index) => {
|
|
243
258
|
const baseUrl = baseUrls[index];
|
|
244
259
|
const name = `The browser test server of worker ${index} (${baseUrl})`;
|
package/scripts/jskit.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
formatCheckReport,
|
|
12
12
|
formatExportSummary
|
|
13
13
|
} from "./i18n.mjs";
|
|
14
|
+
import { checkAgentsBlock, formatAgentsBlockReport, formatAgentsBlockWrite, writeAgentsBlock } from "./agents-block.mjs";
|
|
14
15
|
import { serveBrowserTestTarget } from "./browser-test-server.mjs";
|
|
15
16
|
import { checkDataAccess, formatDataAccessReport } from "./data-access.mjs";
|
|
16
17
|
import { checkManifestCapabilities, formatManifestCapabilitiesReport } from "./manifest-capabilities.mjs";
|
|
@@ -20,6 +21,7 @@ import { checkProject, updateProject } from "./project-packages.mjs";
|
|
|
20
21
|
import { runTests } from "./test-command.mjs";
|
|
21
22
|
import { runMigrationHistory } from "./test-databases.mjs";
|
|
22
23
|
import { checkTestRuns, formatTestRunsReport } from "./test-runs.mjs";
|
|
24
|
+
import { checkTestSources, formatTestSourcesReport } from "./test-sources.mjs";
|
|
23
25
|
|
|
24
26
|
const SCRIPT_PATH = fileURLToPath(import.meta.url);
|
|
25
27
|
const PACKAGE_ROOT = path.resolve(path.dirname(SCRIPT_PATH), "..");
|
|
@@ -32,6 +34,7 @@ function usage() {
|
|
|
32
34
|
" jskit update [--root <path>] [--no-install] [--manifest <path> ...]",
|
|
33
35
|
" jskit check [--root <path>] [--manifest <path> ...]",
|
|
34
36
|
" jskit check m3 [<path> ...] [--root <path>]",
|
|
37
|
+
" jskit agents [--root <path>]",
|
|
35
38
|
" jskit i18n export <locale> [--root <path>]",
|
|
36
39
|
" jskit i18n check <locale> [--root <path>]",
|
|
37
40
|
" jskit package nix [--root <path>]",
|
|
@@ -41,7 +44,8 @@ function usage() {
|
|
|
41
44
|
" jskit browser-test-server [host] [port] [workers]",
|
|
42
45
|
"",
|
|
43
46
|
"Commands:",
|
|
44
|
-
" update Align root and workspace @jskit-ai/* declarations to this published catalog,
|
|
47
|
+
" update Align root and workspace @jskit-ai/* declarations to this published catalog, run npm install, and",
|
|
48
|
+
" write this catalog's JSKIT block in AGENTS.md (jskit agents).",
|
|
45
49
|
" check Fail when manifests or package-lock.json contain stale, mixed, or private singleton JSKIT stacks,",
|
|
46
50
|
" or when application source breaks a rule of the JSKIT Material 3 guide: a navigation rule (nav/*),",
|
|
47
51
|
" such as history or window.location navigation, a hand-built in-app path, a back control other than",
|
|
@@ -56,8 +60,14 @@ function usage() {
|
|
|
56
60
|
" budget, as each worker drives a browser and often its own app server). A Playwright",
|
|
57
61
|
" config with a webServer uses browserTestConfig() of @jskit-ai/jskit-catalog/browser-tests (one",
|
|
58
62
|
" production-build server and database per worker), never a development server, and every one",
|
|
59
|
-
" has a globalTimeout. It fails
|
|
60
|
-
"
|
|
63
|
+
" has a globalTimeout. It fails on the app's test sources (test/*): a test file that waits a fixed",
|
|
64
|
+
" time (waitForTimeout, a setTimeout promise, an awaited sleep) without `// jskit-test: fixed-wait -",
|
|
65
|
+
" <reason>` on the line before, a test script, runner config or test file that names the test",
|
|
66
|
+
" database itself, a script that gives jskit test its files (so npm test -- <file> would run them",
|
|
67
|
+
" all), a CI workflow whose TEST_DB_NAME or BROWSER_TEST_DB_NAME is its DB_NAME, and a root Vite",
|
|
68
|
+
" config whose dts writes a generated file into src. It fails when two table resources",
|
|
69
|
+
" (defineTableResource) of the app and its installed JSKIT packages share a table or a name",
|
|
70
|
+
" (data/one-resource-per-table), or when a system",
|
|
61
71
|
" scope (a feature's systemScope, a systemContext() call) gives no literal reason (data/system-scope),",
|
|
62
72
|
" and it lists every system scope and every file the infrastructure exception lifts past the",
|
|
63
73
|
" data-access lint rules for review. It fails when an application package's manifest",
|
|
@@ -68,10 +78,14 @@ function usage() {
|
|
|
68
78
|
" that jskit package nix wrote, it fails when that file is not the one this release writes",
|
|
69
79
|
" (package/nix-current), when package.json lacks what the package needs (package/nix-manifest), or",
|
|
70
80
|
" when package-lock.json names a dependency a build with no network cannot fetch by its hash",
|
|
71
|
-
" (package/nix-offline).",
|
|
81
|
+
" (package/nix-offline). In an app whose package.json declares @jskit-ai/jskit-catalog, it fails when",
|
|
82
|
+
" AGENTS.md lacks this catalog's JSKIT block, or its block differs (agents/jskit-block).",
|
|
72
83
|
" check m3 Check application UI source against the JSKIT Material 3 guide alone, with each finding's guide",
|
|
73
84
|
" section and every exception: the whole app, or only the given files and directories (a section,",
|
|
74
85
|
" or a task's changed files). Plain jskit check applies the same rules to the whole app.",
|
|
86
|
+
" agents Write this catalog's JSKIT app guidance (the guide's links and the rules no check enforces) in",
|
|
87
|
+
" AGENTS.md: between its JSKIT markers, or at the top of a file without them, made if absent. Text",
|
|
88
|
+
" outside the markers stays as it is.",
|
|
75
89
|
" i18n export Write the English messages of the installed JSKIT packages to src/locales/<locale>/jskit.json",
|
|
76
90
|
" for translators, keeping existing translations and extra keys.",
|
|
77
91
|
" i18n check Compare src/locales/<locale>/jskit.json with the installed packages' English; fail on missing keys,",
|
|
@@ -86,7 +100,10 @@ function usage() {
|
|
|
86
100
|
" test Run node --test with these arguments, test files in parallel within the machine's test budget:",
|
|
87
101
|
" V64_TEST_CONCURRENCY when it is a positive whole number, otherwise half of the machine's CPUs",
|
|
88
102
|
" (at least 1). A file whose first line is `// jskit-test: alone - <reason>` runs after the others,",
|
|
89
|
-
" on its own.
|
|
103
|
+
" on its own. Test files, and the processes they start, connect only to loopback, unix sockets and",
|
|
104
|
+
" the database host (DB_HOST, DATABASE_URL): any other connection fails with",
|
|
105
|
+
" JSKIT_TEST_NETWORK_REFUSED, unless the file's first line is `// jskit-test: network - <reason>`.",
|
|
106
|
+
" With --databases, each file running at once gets its own copy of TEST_DB_NAME,",
|
|
90
107
|
" restored from a schema snapshot (the app's knexfile.js and @jskit-ai/database-runtime), rows",
|
|
91
108
|
" included, before each file, with the app's DB_CLIENT. With no usable TEST_DB_NAME, the files",
|
|
92
109
|
" run one at a time on the connected database; a run that gets fewer databases than its budget",
|
|
@@ -179,6 +196,15 @@ function parseArgs(argv = []) {
|
|
|
179
196
|
if (command === "check" && positionals.length > 0) {
|
|
180
197
|
return parseMaterial3Args(options, positionals);
|
|
181
198
|
}
|
|
199
|
+
if (command === "agents") {
|
|
200
|
+
if (options.additionalManifests) {
|
|
201
|
+
throw new Error("--manifest is only valid with jskit update and jskit check.");
|
|
202
|
+
}
|
|
203
|
+
if (!options.install) {
|
|
204
|
+
throw new Error("--no-install is only valid with jskit update.");
|
|
205
|
+
}
|
|
206
|
+
return { command, projectRoot: options.projectRoot };
|
|
207
|
+
}
|
|
182
208
|
if (command !== "update" && command !== "check") {
|
|
183
209
|
throw new Error(usage());
|
|
184
210
|
}
|
|
@@ -323,6 +349,10 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
323
349
|
await serveBrowserTestTarget(options.args);
|
|
324
350
|
return;
|
|
325
351
|
}
|
|
352
|
+
if (options.command === "agents") {
|
|
353
|
+
process.stdout.write(`${formatAgentsBlockWrite(await writeAgentsBlock(options))}\n`);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
326
356
|
|
|
327
357
|
const catalog = await readCatalog();
|
|
328
358
|
if (options.command === "update") {
|
|
@@ -364,6 +394,7 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
364
394
|
"before the app serves requests.\n"
|
|
365
395
|
);
|
|
366
396
|
}
|
|
397
|
+
process.stdout.write(`${formatAgentsBlockWrite(await writeAgentsBlock(options))}\n`);
|
|
367
398
|
return;
|
|
368
399
|
}
|
|
369
400
|
|
|
@@ -375,9 +406,11 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
375
406
|
});
|
|
376
407
|
const ui = await checkMaterial3({ projectRoot: options.projectRoot });
|
|
377
408
|
const tests = await checkTestRuns({ projectRoot: options.projectRoot, manifests: result.manifests });
|
|
409
|
+
const sources = await checkTestSources({ projectRoot: options.projectRoot });
|
|
378
410
|
const data = await checkDataAccess({ projectRoot: options.projectRoot });
|
|
379
411
|
const capabilities = await checkManifestCapabilities({ projectRoot: options.projectRoot, manifests: result.manifests });
|
|
380
412
|
const nixPackage = await checkPackageNix({ projectRoot: options.projectRoot });
|
|
413
|
+
const agents = await checkAgentsBlock({ projectRoot: options.projectRoot });
|
|
381
414
|
// The data rules first: a graph that fails on many pin versions would otherwise bury them.
|
|
382
415
|
const reports = [
|
|
383
416
|
formatDataAccessReport(data),
|
|
@@ -387,10 +420,12 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
387
420
|
: `JSKIT project graph is inconsistent:\n- ${result.issues.join("\n- ")}`,
|
|
388
421
|
formatMaterial3Report(ui),
|
|
389
422
|
formatTestRunsReport(tests),
|
|
423
|
+
formatTestSourcesReport(sources),
|
|
390
424
|
formatManifestCapabilitiesReport(capabilities),
|
|
391
|
-
formatPackageNixReport(nixPackage)
|
|
425
|
+
formatPackageNixReport(nixPackage),
|
|
426
|
+
formatAgentsBlockReport(agents)
|
|
392
427
|
];
|
|
393
|
-
if (!result.ok || !ui.ok || !tests.ok || !data.ok || !capabilities.ok || !nixPackage.ok) {
|
|
428
|
+
if (!result.ok || !ui.ok || !tests.ok || !sources.ok || !data.ok || !capabilities.ok || !nixPackage.ok || !agents.ok) {
|
|
394
429
|
throw new Error(reports.join("\n"));
|
|
395
430
|
}
|
|
396
431
|
process.stdout.write(`${reports.join("\n")}\n`);
|