@jskit-ai/jskit-catalog 0.2.106 → 0.2.108
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/catalog/packages.json +281 -272
- package/package.json +1 -1
- package/scripts/browser-test-server.mjs +24 -14
- package/scripts/browser-test-servers.mjs +14 -6
- package/scripts/browser-tests.mjs +55 -7
- package/scripts/jskit.mjs +23 -16
- package/scripts/manifest-capabilities.mjs +19 -11
- package/scripts/test-budget.mjs +43 -5
- package/scripts/test-command.mjs +28 -4
- package/scripts/test-runs.mjs +15 -6
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
// `jskit browser-test-server [host] [port]`: the app as a host serves it for a browser test run, such as a
|
|
2
|
-
// target with `Data: test`. It is
|
|
3
|
-
// app's own playwright.config.mjs: the production build,
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
1
|
+
// `jskit browser-test-server [host] [port] [workers]`: the app as a host serves it for a browser test run, such as a
|
|
2
|
+
// Vibe64 Outputs target with `Data: test`. It is the servers of a local run's workers (browser-tests.mjs,
|
|
3
|
+
// browser-test-servers.mjs), read from the app's own playwright.config.mjs: the production build, built once, and for
|
|
4
|
+
// each worker i on port+i the database the app's `prepare` module gives it (its own copy of BROWSER_TEST_DB_NAME in the
|
|
5
|
+
// database patterns, prepared once for every worker), the test-only `env` and APP_ENV=test, on the host's address in
|
|
6
|
+
// place of the run's own ports. The host's suite then runs against them as a managed target (PLAYWRIGHT_BASE_URL, and
|
|
7
|
+
// PLAYWRIGHT_WORKER_TARGETS for several), signed in with the login state its host supplies, so these servers sign
|
|
8
|
+
// nothing in. The host and port come from the arguments, else HOST and PORT; workers, from 1 to 64, from the third
|
|
9
|
+
// argument, else 1. The servers' output also reaches this command's own; stopping the command stops them.
|
|
8
10
|
import { existsSync } from "node:fs";
|
|
9
11
|
import path from "node:path";
|
|
10
12
|
import process from "node:process";
|
|
@@ -12,24 +14,32 @@ import { pathToFileURL } from "node:url";
|
|
|
12
14
|
import { SETTINGS_VARIABLE } from "./browser-tests.mjs";
|
|
13
15
|
|
|
14
16
|
const CONFIG_FILES = Object.freeze(["playwright.config.mjs", "playwright.config.js"]);
|
|
17
|
+
// As many app servers as one host run asks for (Vibe64 admits a run of at most 64 workers).
|
|
18
|
+
const MAX_WORKERS = 64;
|
|
15
19
|
|
|
16
20
|
/**
|
|
17
|
-
* Serves the app in `appRoot` as
|
|
18
|
-
* @param {string[]} args `[host, port]
|
|
21
|
+
* Serves the app in `appRoot` as browser test servers, until it is stopped.
|
|
22
|
+
* @param {string[]} args `[host, port, workers]`: host and port may be left to HOST and PORT, workers to 1.
|
|
19
23
|
* @param {Record<string, string | undefined>} [environment] This process's environment, given the run's settings.
|
|
20
24
|
* @param {string} [appRoot]
|
|
21
25
|
*/
|
|
22
26
|
async function serveBrowserTestTarget(args = [], environment = process.env, appRoot = process.cwd()) {
|
|
23
|
-
if (args.length >
|
|
27
|
+
if (args.length > 3) throw new Error("Usage: jskit browser-test-server [host] [port] [workers]");
|
|
24
28
|
const host = String(args[0] || environment.HOST || "").trim() || "127.0.0.1";
|
|
25
29
|
const port = String(args[1] || environment.PORT || "").trim();
|
|
26
30
|
if (!/^[1-9]\d{0,4}$/u.test(port) || Number(port) > 65_535) {
|
|
27
31
|
throw new Error(`jskit browser-test-server needs the port to serve on, as its second argument or PORT, not ${port || "nothing"}.`);
|
|
28
32
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
const workers = String(args[2] ?? "1").trim();
|
|
34
|
+
if (!/^[1-9]\d?$/u.test(workers) || Number(workers) > MAX_WORKERS) {
|
|
35
|
+
throw new Error(`jskit browser-test-server serves 1 to ${MAX_WORKERS} app servers, not ${workers || "nothing"}.`);
|
|
36
|
+
}
|
|
37
|
+
// What a local run's config reads for its workers from this port. A suite runner's settings left in a host's
|
|
38
|
+
// environment (its managed target and servers, login state, worker count or index) are not these servers'.
|
|
39
|
+
for (const name of ["PLAYWRIGHT_BASE_URL", "PLAYWRIGHT_STORAGE_STATE", "PLAYWRIGHT_WORKER_TARGETS", "TEST_PARALLEL_INDEX"]) {
|
|
40
|
+
delete environment[name];
|
|
41
|
+
}
|
|
42
|
+
Object.assign(environment, { PLAYWRIGHT_PORT: port, PLAYWRIGHT_WORKERS: workers });
|
|
33
43
|
const config = CONFIG_FILES.map((name) => path.join(appRoot, name)).find((file) => existsSync(file));
|
|
34
44
|
const loaded = config ? (await import(pathToFileURL(config).href)).default : null;
|
|
35
45
|
const settings = loaded?.webServer?.env?.[SETTINGS_VARIABLE];
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
// (browser-tests.mjs). With the app's `signIn` module, each server is then signed in once, and its storage state left
|
|
6
6
|
// for its worker. Each server's output goes to test-results/browser-test-servers/worker-<n>.log; a server that stops
|
|
7
7
|
// ends the run. A port that already answers is refused before anything is built or started: a server left there by an
|
|
8
|
-
// earlier run would answer for this run's. Stopped by Playwright (SIGTERM), by Ctrl-C,
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
8
|
+
// earlier run would answer for this run's. Stopped by Playwright (SIGTERM), by Ctrl-C, by its terminal's hang-up (SIGHUP,
|
|
9
|
+
// which a host such as Vibe64 sends a target's command first), by the end of the stdin pipe Playwright gives its
|
|
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, then
|
|
12
|
+
// drops the numbered database copies the prepare module made, within Playwright's grace, before it exits; it drops
|
|
13
|
+
// them too when its start fails. `jskit browser-test-server` (browser-test-server.mjs) runs it
|
|
12
14
|
// for one server a host starts, with `terminal`: that server's output also reaches the launcher's own. A run takes free
|
|
13
15
|
// ports of its own, so its worker environments and signed-in states have names of their own; the launcher removes them
|
|
14
16
|
// when it stops, so they never pile up in the cache, nor outlive the sessions they hold.
|
|
@@ -136,8 +138,14 @@ async function stopAndExit(code) {
|
|
|
136
138
|
for (const file of runFiles) rmSync(file, { force: true });
|
|
137
139
|
process.exit(code);
|
|
138
140
|
}
|
|
139
|
-
|
|
140
|
-
process
|
|
141
|
+
// Kept for every signal, not once: a host's stop signals more than once (Vibe64's wrapper SIGTERM, its terminal's
|
|
142
|
+
// SIGHUP, then the process group's SIGTERM), and a signal with no handler left would kill the launcher mid-stop.
|
|
143
|
+
process.on("SIGINT", () => stopAndExit(130));
|
|
144
|
+
process.on("SIGTERM", () => stopAndExit(143));
|
|
145
|
+
process.on("SIGHUP", () => stopAndExit(129));
|
|
146
|
+
// Its servers' output passes through its own, which can go before its stop does: a write that fails there stops it like
|
|
147
|
+
// a signal, never as an uncaught error that would end it before its copies are dropped.
|
|
148
|
+
for (const output of [process.stdout, process.stderr]) output.on("error", () => stopAndExit(1));
|
|
141
149
|
// Only a pipe ends when Playwright does; a launcher started without one (stdin ignored, /dev/null) would end at once.
|
|
142
150
|
const input = fstatSync(0);
|
|
143
151
|
if (input.isFIFO() || input.isSocket()) {
|
|
@@ -11,7 +11,9 @@ import { testConcurrency } from "./test-budget.mjs";
|
|
|
11
11
|
// (browser-test-servers.mjs). With the app's `signIn` module, each worker's server is signed in once and every test of
|
|
12
12
|
// that worker starts from its signed-in state. With PLAYWRIGHT_BASE_URL set, the tests use that managed target instead,
|
|
13
13
|
// as its host serves it and with the login state its host supplies, one worker at a time unless the runner sets
|
|
14
|
-
// PLAYWRIGHT_WORKERS.
|
|
14
|
+
// PLAYWRIGHT_WORKERS. A host serving such a target several app servers (Vibe64's targets whose Run step takes
|
|
15
|
+
// {workers}) lists them in PLAYWRIGHT_WORKER_TARGETS: one Playwright worker per server, each with its own signed-in
|
|
16
|
+
// state.
|
|
15
17
|
|
|
16
18
|
const SERVERS = fileURLToPath(new URL("./browser-test-servers.mjs", import.meta.url));
|
|
17
19
|
const SLOWEST_TESTS = fileURLToPath(new URL("./browser-test-times.mjs", import.meta.url));
|
|
@@ -35,8 +37,41 @@ const WORKER_ENVIRONMENTS = path.join("node_modules", ".cache", "jskit-browser-t
|
|
|
35
37
|
|
|
36
38
|
const positiveInteger = (value) => (/^[1-9]\d*$/u.test(String(value ?? "").trim()) ? Number(String(value).trim()) : 0);
|
|
37
39
|
|
|
40
|
+
const withoutTrailingSlash = (url) => String(url || "").trim().replace(/\/+$/u, "");
|
|
41
|
+
|
|
38
42
|
function managedBaseUrl(env) {
|
|
39
|
-
return
|
|
43
|
+
return withoutTrailingSlash(env.PLAYWRIGHT_BASE_URL);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const WORKER_TARGETS_FORM = "PLAYWRIGHT_WORKER_TARGETS is a JSON list of { baseURL, storageState? }: each Playwright " +
|
|
47
|
+
"worker's app server, an HTTP URL, and its signed-in state file";
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A host's app servers for a managed run, one per Playwright worker, from PLAYWRIGHT_WORKER_TARGETS, or null without it.
|
|
51
|
+
* @param {Record<string, string | undefined>} env
|
|
52
|
+
* @returns {Array<{ baseURL: string, storageState: string }> | null}
|
|
53
|
+
*/
|
|
54
|
+
function managedWorkerTargets(env) {
|
|
55
|
+
const text = String(env.PLAYWRIGHT_WORKER_TARGETS || "").trim();
|
|
56
|
+
if (!text) return null;
|
|
57
|
+
let list;
|
|
58
|
+
try {
|
|
59
|
+
list = JSON.parse(text);
|
|
60
|
+
} catch {
|
|
61
|
+
throw new Error(`${WORKER_TARGETS_FORM}; it is not JSON.`);
|
|
62
|
+
}
|
|
63
|
+
const valid = Array.isArray(list) && list.length > 0 && list.every((entry) => {
|
|
64
|
+
let protocol = "";
|
|
65
|
+
try {
|
|
66
|
+
protocol = new URL(String(entry?.baseURL)).protocol;
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return ["http:", "https:"].includes(protocol) &&
|
|
71
|
+
(entry.storageState === undefined || (typeof entry.storageState === "string" && entry.storageState.trim() !== ""));
|
|
72
|
+
});
|
|
73
|
+
if (!valid) throw new Error(`${WORKER_TARGETS_FORM}.`);
|
|
74
|
+
return list.map(({ baseURL, storageState = "" }) => ({ baseURL: withoutTrailingSlash(baseURL), storageState }));
|
|
40
75
|
}
|
|
41
76
|
|
|
42
77
|
/**
|
|
@@ -60,12 +95,18 @@ function commandLineWorkers(argv) {
|
|
|
60
95
|
* How many workers a browser run uses: the command line's `--workers`, else PLAYWRIGHT_WORKERS, else half the machine's
|
|
61
96
|
* test budget for a local run and 1 for a managed target (one server). A local worker drives a browser and its own app
|
|
62
97
|
* server, about two threads' work: with a budget of 4, the shell foundation's 9 tests took 11.5 s on 4 workers and
|
|
63
|
-
* 7.9 s on 2.
|
|
98
|
+
* 7.9 s on 2. A managed target whose host lists several app servers (PLAYWRIGHT_WORKER_TARGETS) runs one worker per
|
|
99
|
+
* server, and refuses another count: a worker would have no server, or a server no worker.
|
|
64
100
|
* @param {{ env?: Record<string, string | undefined>, argv?: ReadonlyArray<string> }} [options]
|
|
65
101
|
*/
|
|
66
102
|
function browserTestWorkers({ env = process.env, argv = process.argv } = {}) {
|
|
67
|
-
|
|
68
|
-
|
|
103
|
+
const asked = commandLineWorkers(argv) || positiveInteger(env.PLAYWRIGHT_WORKERS);
|
|
104
|
+
const targets = managedBaseUrl(env) ? managedWorkerTargets(env) : null;
|
|
105
|
+
if (targets && asked && asked !== targets.length) {
|
|
106
|
+
throw new Error(`PLAYWRIGHT_WORKER_TARGETS lists ${targets.length} app servers, one per Playwright worker, so this run ` +
|
|
107
|
+
`cannot use ${asked} workers. Leave the count to the host that serves them.`);
|
|
108
|
+
}
|
|
109
|
+
return targets?.length || asked || (managedBaseUrl(env) ? 1 : Math.max(1, Math.floor(testConcurrency({ env }) / 2)));
|
|
69
110
|
}
|
|
70
111
|
|
|
71
112
|
// Finds `count` consecutive ports nothing listens on, at a random place below Linux's ephemeral range, and prints the
|
|
@@ -163,6 +204,13 @@ function browserTestConfig({
|
|
|
163
204
|
}
|
|
164
205
|
const managed = managedBaseUrl(environment);
|
|
165
206
|
const workers = browserTestWorkers({ env: environment });
|
|
207
|
+
// A host serving the managed target several app servers: this worker's own, and its signed-in state.
|
|
208
|
+
const workerTargets = managed ? managedWorkerTargets(environment) : null;
|
|
209
|
+
const managedIndex = Number.parseInt(String(environment.TEST_PARALLEL_INDEX || "0"), 10) || 0;
|
|
210
|
+
const workerTarget = workerTargets ? workerTargets[managedIndex] : null;
|
|
211
|
+
if (workerTargets && !workerTarget) {
|
|
212
|
+
throw new Error(`PLAYWRIGHT_WORKER_TARGETS has no app server for Playwright worker ${managedIndex}.`);
|
|
213
|
+
}
|
|
166
214
|
const runTimeout = globalTimeout ?? Math.max(MIN_GLOBAL_TIMEOUT_MS, Math.ceil(WORKER_MINUTES_MS / workers));
|
|
167
215
|
let basePort = positiveInteger(environment.PLAYWRIGHT_PORT) || port;
|
|
168
216
|
if (!basePort && !managed) {
|
|
@@ -188,7 +236,7 @@ function browserTestConfig({
|
|
|
188
236
|
Object.assign(environment, preparedWorkerEnvironment(workerEnvironments, workerIndex));
|
|
189
237
|
if (signedInStates) environment.PLAYWRIGHT_STORAGE_STATE = `${signedInStates}-${workerIndex}.json`;
|
|
190
238
|
}
|
|
191
|
-
const storageState = String(environment.PLAYWRIGHT_STORAGE_STATE || "").trim();
|
|
239
|
+
const storageState = workerTarget ? workerTarget.storageState : String(environment.PLAYWRIGHT_STORAGE_STATE || "").trim();
|
|
192
240
|
const settings = {
|
|
193
241
|
workers, host: HOST, basePort, server, build, prepare, env, health, workerEnvironments,
|
|
194
242
|
...(signedInStates ? { signIn, signedInStates } : {})
|
|
@@ -203,7 +251,7 @@ function browserTestConfig({
|
|
|
203
251
|
// Every run ends with its 10 slowest tests and their times.
|
|
204
252
|
reporter: [["list"], [SLOWEST_TESTS]],
|
|
205
253
|
use: {
|
|
206
|
-
baseURL: managed || `http://${HOST}:${basePort + workerIndex}`,
|
|
254
|
+
baseURL: workerTarget?.baseURL || managed || `http://${HOST}:${basePort + workerIndex}`,
|
|
207
255
|
headless: true,
|
|
208
256
|
actionTimeout,
|
|
209
257
|
navigationTimeout,
|
package/scripts/jskit.mjs
CHANGED
|
@@ -35,7 +35,7 @@ function usage() {
|
|
|
35
35
|
" jskit i18n check <locale> [--root <path>]",
|
|
36
36
|
" jskit package nix [--root <path>]",
|
|
37
37
|
" jskit test [node options] [files or globs]",
|
|
38
|
-
" jskit browser-test-server [host] [port]",
|
|
38
|
+
" jskit browser-test-server [host] [port] [workers]",
|
|
39
39
|
"",
|
|
40
40
|
"Commands:",
|
|
41
41
|
" update Align root and workspace @jskit-ai/* declarations to this published catalog, then run npm install.",
|
|
@@ -47,8 +47,10 @@ function usage() {
|
|
|
47
47
|
" fixed button height, or a rule for using components (ui/*), such as a prop a JSKIT component",
|
|
48
48
|
" no longer has. It also fails when",
|
|
49
49
|
" a package script runs tests outside the machine's test budget (test/*): node --test instead of",
|
|
50
|
-
" jskit test, a fixed test concurrency or worker count,
|
|
51
|
-
"
|
|
50
|
+
" jskit test, a fixed test concurrency or worker count, a Vitest config whose workers do not come",
|
|
51
|
+
" from testConcurrency() of @jskit-ai/jskit-catalog/test-budget, or a Playwright config whose",
|
|
52
|
+
" workers do not come from browserTestWorkers() of @jskit-ai/jskit-catalog/browser-tests (half the",
|
|
53
|
+
" budget, as each worker drives a browser and often its own app server). A Playwright",
|
|
52
54
|
" config with a webServer uses browserTestConfig() of @jskit-ai/jskit-catalog/browser-tests (one",
|
|
53
55
|
" production-build server and database per worker), never a development server, and every one",
|
|
54
56
|
" has a globalTimeout. It fails when two table resources (defineTableResource) of the app and its",
|
|
@@ -57,11 +59,13 @@ function usage() {
|
|
|
57
59
|
" and it lists every system scope and every file the infrastructure exception lifts past the",
|
|
58
60
|
" data-access lint rules for review. It fails when an application package's manifest",
|
|
59
61
|
" (jskit.capabilities) misses a capability its features (server providers) provide or require, or",
|
|
60
|
-
" provides one none of them does
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
62
|
+
" provides one none of them does, or its installRequires marks one they require or the manifest does",
|
|
63
|
+
" not (manifest/capabilities), and lists for review each requirement no feature has that",
|
|
64
|
+
" installRequires does not mark (only install time may need it). When the app has a package.nix",
|
|
65
|
+
" that jskit package nix wrote, it fails when that file is not the one this release writes",
|
|
66
|
+
" (package/nix-current), when package.json lacks what the package needs (package/nix-manifest), or",
|
|
67
|
+
" when package-lock.json names a dependency a build with no network cannot fetch by its hash",
|
|
68
|
+
" (package/nix-offline).",
|
|
65
69
|
" check m3 Check application UI source against the JSKIT Material 3 guide alone, with each finding's guide",
|
|
66
70
|
" section and every exception: the whole app, or only the given files and directories (a section,",
|
|
67
71
|
" or a task's changed files). Plain jskit check applies the same rules to the whole app.",
|
|
@@ -81,16 +85,19 @@ function usage() {
|
|
|
81
85
|
" (at least 1). A file whose first line is `// jskit-test: alone - <reason>` runs after the others,",
|
|
82
86
|
" on its own. With --databases, each file running at once gets its own copy of TEST_DB_NAME,",
|
|
83
87
|
" restored from a schema snapshot (the app's knexfile.js and @jskit-ai/database-runtime), rows",
|
|
84
|
-
" included, before each file
|
|
85
|
-
" connected database
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
+
" included, before each file, with the app's DB_CLIENT. With no usable TEST_DB_NAME, the files",
|
|
89
|
+
" run one at a time on the connected database; a run that gets fewer databases than its budget",
|
|
90
|
+
" asked for (no TEST_DB_NAME, or copies the database user may not create) says why at its start",
|
|
91
|
+
" and end, and fails, unless V64_TEST_CONCURRENCY is set to what the databases allow. Given no",
|
|
92
|
+
" files, it fails when a file under tests/ is named as a test (x.integration.js, x.spec.js) that",
|
|
93
|
+
" node's default pattern would leave out; a database test is named x.integration.test.js.",
|
|
88
94
|
" browser-test-server",
|
|
89
95
|
" Serve the app for a host's browser test run, such as a Vibe64 Outputs target with Data test, on",
|
|
90
|
-
" [host] [port] (else HOST and PORT):
|
|
91
|
-
" browserTestConfig(),
|
|
92
|
-
" worker, its test-only env and APP_ENV=test. The
|
|
93
|
-
"
|
|
96
|
+
" [host] [port] (else HOST and PORT): [workers] servers (1 to 64, else 1) of the app's",
|
|
97
|
+
" playwright.config.mjs browserTestConfig(), worker i on port+i, on the production build, each with",
|
|
98
|
+
" the database its prepare module gives that worker, its test-only env and APP_ENV=test. The",
|
|
99
|
+
" host's suite runs against them with PLAYWRIGHT_BASE_URL (and PLAYWRIGHT_WORKER_TARGETS for",
|
|
100
|
+
" several) and the login state the host supplies. It runs until it is stopped.",
|
|
94
101
|
"",
|
|
95
102
|
"<locale> is a BCP 47 language tag, such as fr or pt-BR."
|
|
96
103
|
].join("\n");
|
|
@@ -12,10 +12,10 @@ import { toPosixPath } from "./files.mjs";
|
|
|
12
12
|
const GUIDE = "https://mobily-enterprises.github.io/jskit-ai/guide/framework/typed-features#package-manifest";
|
|
13
13
|
const KERNEL_PLATFORM = "@jskit-ai/kernel/server/platform";
|
|
14
14
|
|
|
15
|
-
// The line naming a capability in a manifest's `capabilities` block, else the block's own line.
|
|
16
|
-
function capabilityLine(contents, capabilityId = "") {
|
|
15
|
+
// The line naming a capability in a manifest's `capabilities` block (or in its `within` list), else the block's own line.
|
|
16
|
+
function capabilityLine(contents, capabilityId = "", within = "capabilities") {
|
|
17
17
|
const text = String(contents);
|
|
18
|
-
const block = text.indexOf(
|
|
18
|
+
const block = text.indexOf(`"${within}"`);
|
|
19
19
|
if (block < 0) return 1;
|
|
20
20
|
const named = capabilityId ? text.indexOf(`"${capabilityId}"`, block) : -1;
|
|
21
21
|
return text.slice(0, named < 0 ? block : named).split("\n").length;
|
|
@@ -38,13 +38,14 @@ async function kernelPlatform(manifestPath, root) {
|
|
|
38
38
|
async function checkManifestCapabilities({ projectRoot, manifests }) {
|
|
39
39
|
const root = path.resolve(projectRoot);
|
|
40
40
|
const findings = [];
|
|
41
|
-
const
|
|
41
|
+
const extraRequires = [];
|
|
42
42
|
let packages = 0;
|
|
43
43
|
for (const manifest of manifests) {
|
|
44
44
|
const jskit = manifest.value?.jskit;
|
|
45
45
|
if (!Array.isArray(jskit?.runtime?.server?.providers) || jskit.runtime.server.providers.length < 1) continue;
|
|
46
46
|
const file = toPosixPath(path.relative(root, manifest.absolutePath)) || "package.json";
|
|
47
|
-
const at = (capabilityId, message
|
|
47
|
+
const at = (capabilityId, message, within) =>
|
|
48
|
+
findings.push({ file, line: capabilityLine(manifest.contents, capabilityId, within), rule: "manifest/capabilities", message });
|
|
48
49
|
const kernel = await kernelPlatform(manifest.absolutePath, root);
|
|
49
50
|
if (typeof kernel?.packageCapabilityDrift !== "function") {
|
|
50
51
|
at("", `declares server providers, but no installed ${KERNEL_PLATFORM} compares a manifest with them; run jskit update.`);
|
|
@@ -66,18 +67,25 @@ async function checkManifestCapabilities({ projectRoot, manifests }) {
|
|
|
66
67
|
for (const id of drift.unlistedProvides) at("", `its features provide ${id}, which jskit.capabilities.provides does not list; add it.`);
|
|
67
68
|
for (const id of drift.extraProvides) at(id, `jskit.capabilities.provides lists ${id}, which none of its features provides; remove it.`);
|
|
68
69
|
for (const id of drift.unlistedRequires) at("", `its features require ${id}, which jskit.capabilities.requires does not list; add it.`);
|
|
69
|
-
for (const id of drift.
|
|
70
|
+
for (const id of drift.requiredInstallRequires || []) {
|
|
71
|
+
at(id, `jskit.capabilities.installRequires lists ${id}, which its features require; remove it from installRequires.`, "installRequires");
|
|
72
|
+
}
|
|
73
|
+
for (const id of drift.unlistedInstallRequires || []) {
|
|
74
|
+
at(id, `jskit.capabilities.installRequires lists ${id}, which jskit.capabilities.requires does not list; add it to requires or remove it.`, "installRequires");
|
|
75
|
+
}
|
|
76
|
+
for (const id of drift.extraRequires) extraRequires.push({ file, line: capabilityLine(manifest.contents, id), capabilityId: id });
|
|
70
77
|
}
|
|
71
78
|
findings.sort((left, right) => left.file.localeCompare(right.file) || left.line - right.line);
|
|
72
|
-
return { ok: findings.length < 1, findings,
|
|
79
|
+
return { ok: findings.length < 1, findings, extraRequires, packages };
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
function formatManifestCapabilitiesReport(result) {
|
|
76
83
|
const lines = result.findings.flatMap(({ file, line, rule, message }) => [`${file}:${line} ${rule} ${message}`, ` ${GUIDE}`]);
|
|
77
|
-
if (result.
|
|
78
|
-
lines.push(`Manifest requirements no feature has (${result.
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
if (result.extraRequires.length > 0) {
|
|
85
|
+
lines.push(`Manifest requirements no feature has and installRequires does not mark (${result.extraRequires.length}): mark ` +
|
|
86
|
+
"each one only install time needs, such as the database a migration needs, in jskit.capabilities.installRequires; " +
|
|
87
|
+
`remove any other (${GUIDE}):`);
|
|
88
|
+
for (const { file, line, capabilityId } of result.extraRequires) lines.push(` ${file}:${line} ${capabilityId}`);
|
|
81
89
|
}
|
|
82
90
|
lines.push(result.ok
|
|
83
91
|
? `JSKIT package manifests name what their features provide and require in ${result.packages} package(s).`
|
package/scripts/test-budget.mjs
CHANGED
|
@@ -1,19 +1,57 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
1
2
|
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
2
4
|
import process from "node:process";
|
|
3
5
|
|
|
4
|
-
// The machine's test budget: how many test files (node --test)
|
|
5
|
-
//
|
|
6
|
-
//
|
|
6
|
+
// The machine's test budget: how many test files (node --test) or Vitest workers a run may use at once; a Playwright
|
|
7
|
+
// worker, a browser and often an app server, takes two of it (browserTestWorkers() of ./browser-tests.mjs). A test
|
|
8
|
+
// runner that hands out slots exports V64_TEST_CONCURRENCY for each run; anywhere else a run takes half of the CPUs it
|
|
9
|
+
// may use, so a test suite neither runs one file at a time nor overwhelms the machine (a 2-vCPU VPS stays at 1).
|
|
7
10
|
const BUDGET_VARIABLE = "V64_TEST_CONCURRENCY";
|
|
11
|
+
const CGROUP_ROOT = "/sys/fs/cgroup";
|
|
12
|
+
|
|
13
|
+
/** The CPUs a cgroup v2 `cpu.max` ("<quota> <period>" or "max <period>") allows, or Infinity. */
|
|
14
|
+
function quotaCpus(text) {
|
|
15
|
+
const [quota = "max", period] = String(text).trim().split(/\s+/u);
|
|
16
|
+
const cpus = Number(quota) / Number(period);
|
|
17
|
+
return quota !== "max" && Number.isFinite(cpus) && cpus > 0 ? cpus : Infinity;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The CPUs this process may use: the machine's (availableParallelism(), which follows CPU affinity), capped by the
|
|
22
|
+
* tightest cgroup v2 `cpu.max` quota from the process's own cgroup up to the root, which availableParallelism() does
|
|
23
|
+
* not read. A container or a VPS slice given 3 CPUs of a 16-thread host has 3, not 16. Without cgroup v2 (another
|
|
24
|
+
* system, or cgroup v1 alone), the machine's.
|
|
25
|
+
* @param {{ parallelism?: number, readFile?: (file: string, encoding: string) => string }} [options]
|
|
26
|
+
* @returns {number} a whole number of at least 1
|
|
27
|
+
*/
|
|
28
|
+
function availableCpus({ parallelism = os.availableParallelism(), readFile = readFileSync } = {}) {
|
|
29
|
+
const read = (file) => {
|
|
30
|
+
try {
|
|
31
|
+
return String(readFile(file, "utf8"));
|
|
32
|
+
} catch {
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const line = read("/proc/self/cgroup").split("\n").find((entry) => entry.startsWith("0::"));
|
|
37
|
+
let quota = Infinity;
|
|
38
|
+
if (line) {
|
|
39
|
+
for (let group = path.posix.join(CGROUP_ROOT, line.slice(3).trim()).replace(/\/+$/u, "");
|
|
40
|
+
group.startsWith(CGROUP_ROOT); group = path.posix.dirname(group)) {
|
|
41
|
+
quota = Math.min(quota, quotaCpus(read(path.posix.join(group, "cpu.max"))));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return Math.max(1, Math.min(parallelism, Math.floor(quota)));
|
|
45
|
+
}
|
|
8
46
|
|
|
9
47
|
/**
|
|
10
48
|
* @param {{ env?: Record<string, string | undefined>, parallelism?: number }} [options]
|
|
11
49
|
* @returns {number} a whole number of at least 1
|
|
12
50
|
*/
|
|
13
|
-
function testConcurrency({ env = process.env, parallelism =
|
|
51
|
+
function testConcurrency({ env = process.env, parallelism = availableCpus() } = {}) {
|
|
14
52
|
const configured = String(env[BUDGET_VARIABLE] ?? "").trim();
|
|
15
53
|
if (/^[1-9]\d*$/u.test(configured)) return Number(configured);
|
|
16
54
|
return Math.max(1, Math.floor(parallelism / 2));
|
|
17
55
|
}
|
|
18
56
|
|
|
19
|
-
export { BUDGET_VARIABLE, testConcurrency };
|
|
57
|
+
export { BUDGET_VARIABLE, availableCpus, testConcurrency };
|
package/scripts/test-command.mjs
CHANGED
|
@@ -18,7 +18,11 @@ import { reportTestTimes, writeFileStops } from "./test-time-report.mjs";
|
|
|
18
18
|
// --test-shard=<index>/<total> it runs only its shard's alone files, picked the way node --test picks a shard's files.
|
|
19
19
|
// Given no files, it fails instead of leaving out a file under tests/ named as a test that node's default misses.
|
|
20
20
|
// Every run also reports to test-time-report.mjs, which times the command's files against coarse bounds, and preloads
|
|
21
|
-
// test-file-stop.mjs, which stops a file still running at a generous multiple of its time.
|
|
21
|
+
// test-file-stop.mjs, which stops a file still running at a generous multiple of its time. With --databases, a run whose
|
|
22
|
+
// test databases let fewer files run at once than the budget asked for (no usable TEST_DB_NAME, or copies the database
|
|
23
|
+
// user may not create) says so, and why, at its start and its end, and fails once its tests have run: a machine that
|
|
24
|
+
// should run files in parallel never silently runs them one at a time. A budget set to what the databases allow
|
|
25
|
+
// (V64_TEST_CONCURRENCY) runs that way on purpose.
|
|
22
26
|
|
|
23
27
|
// node --test's own default (Node 26) when it is given no files.
|
|
24
28
|
const DEFAULT_PATTERN = "**/{test,test/**/*,test-*,*[._-]test}.{js,mjs,cjs,ts,mts,cts}";
|
|
@@ -179,6 +183,21 @@ function withTimeReporter(run, destination) {
|
|
|
179
183
|
];
|
|
180
184
|
}
|
|
181
185
|
|
|
186
|
+
/**
|
|
187
|
+
* What a run says, at its start and its end, when its test databases let fewer files run at once than it asked for, or
|
|
188
|
+
* "" when they gave all it asked. An installed @jskit-ai/database-runtime from before `shortfall` is read by its summary.
|
|
189
|
+
* @param {{ concurrency: number, shortfall?: string, summary: string }} databases
|
|
190
|
+
* @param {number} asked
|
|
191
|
+
*/
|
|
192
|
+
function databaseShortfall(databases, asked) {
|
|
193
|
+
if (databases.concurrency >= asked) return "";
|
|
194
|
+
const copies = asked > 2 ? `\`<TEST_DB_NAME>_1\` to \`<TEST_DB_NAME>_${asked - 1}\`` : "`<TEST_DB_NAME>_1`";
|
|
195
|
+
return `test files run ${databases.concurrency} at a time, not the ${asked} this machine's test budget allows: ` +
|
|
196
|
+
`${databases.shortfall || databases.summary}. Each file running at once needs a database of its own: TEST_DB_NAME, ` +
|
|
197
|
+
`then ${copies}, which the database user creates and drops (MySQL and MariaDB: grant it \`<TEST_DB_NAME>\\_%\`; ` +
|
|
198
|
+
`PostgreSQL: CREATEDB). To run this way on purpose, set ${BUDGET_VARIABLE}=${databases.concurrency}.`;
|
|
199
|
+
}
|
|
200
|
+
|
|
182
201
|
function runNode(args, env) {
|
|
183
202
|
return new Promise((resolve, reject) => {
|
|
184
203
|
const child = spawn(process.execPath, args, { stdio: "inherit", env: { ...process.env, ...env } });
|
|
@@ -206,11 +225,12 @@ async function runTests(args) {
|
|
|
206
225
|
let plan = planTestRuns(nodeArgs);
|
|
207
226
|
const source = process.env[BUDGET_VARIABLE] ? BUDGET_VARIABLE : "half of this machine";
|
|
208
227
|
// A database for each file that can run at once: a focused run of one file prepares one.
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
228
|
+
const asked = Math.max(1, Math.min(plan.concurrency, plan.files));
|
|
229
|
+
const databases = nodeArgs.length < args.length ? await testDatabaseRunFor(asked) : null;
|
|
230
|
+
const shortfall = databases ? databaseShortfall(databases, asked) : "";
|
|
212
231
|
if (databases) {
|
|
213
232
|
process.stderr.write(`jskit test: ${databases.summary}.\n`);
|
|
233
|
+
if (shortfall) process.stderr.write(`jskit test: ${shortfall}\n`);
|
|
214
234
|
plan = planTestRuns(nodeArgs, { concurrency: databases.concurrency });
|
|
215
235
|
}
|
|
216
236
|
process.stderr.write(`jskit test: ${plan.concurrency} test file(s) at a time (${databases ? "test databases" : source}).\n`);
|
|
@@ -241,6 +261,10 @@ async function runTests(args) {
|
|
|
241
261
|
filtered: nodeArgs.some((argument) => TEST_FILTER.test(argument)) });
|
|
242
262
|
if (times) process.stderr.write(times.report);
|
|
243
263
|
if (times?.overruns.length > 0 && exitCode === 0) exitCode = 1;
|
|
264
|
+
if (shortfall && !interrupted) {
|
|
265
|
+
process.stderr.write(`jskit test: ${shortfall}\njskit test: the run fails: its test databases cost it concurrency.\n`);
|
|
266
|
+
if (exitCode === 0) exitCode = 1;
|
|
267
|
+
}
|
|
244
268
|
} finally {
|
|
245
269
|
// However the run ended, it drops its numbered test databases, and says what it dropped.
|
|
246
270
|
const ended = await databases?.cleanup();
|
package/scripts/test-runs.mjs
CHANGED
|
@@ -4,7 +4,9 @@ import { fileExists, toPosixPath } from "./files.mjs";
|
|
|
4
4
|
|
|
5
5
|
// The test-run part of plain `jskit check`: every test run uses the machine's test budget, so a suite neither runs one
|
|
6
6
|
// file at a time nor overwhelms the machine. A package script runs node's test runner through `jskit test`, passes no
|
|
7
|
-
// fixed worker count, and the
|
|
7
|
+
// fixed worker count, and the configs its scripts use set their workers from the budget: Vitest's from
|
|
8
|
+
// testConcurrency(), Playwright's from browserTestWorkers(), half of it, since each worker drives a browser and often
|
|
9
|
+
// its own app server, about two threads (browserTestConfig() does that itself).
|
|
8
10
|
// The one exception is a test file's own first line, `// jskit-test: alone - <reason>`, which `jskit test` honours.
|
|
9
11
|
// A Playwright config those scripts use bounds its whole run (globalTimeout) and, when it starts the app (webServer),
|
|
10
12
|
// does so through browserTestConfig(): the production build, and a server, port and database for each worker.
|
|
@@ -76,12 +78,14 @@ const RUNNERS = Object.freeze({
|
|
|
76
78
|
rule: "test/playwright-workers",
|
|
77
79
|
configNames: ["playwright"],
|
|
78
80
|
setting: "workers",
|
|
81
|
+
budget: { module: BROWSER_TESTS_MODULE, call: "browserTestWorkers" },
|
|
79
82
|
fixedArgument: FIXED_PLAYWRIGHT_WORKERS
|
|
80
83
|
},
|
|
81
84
|
vitest: {
|
|
82
85
|
rule: "test/vitest-workers",
|
|
83
86
|
configNames: ["vitest", "vite"],
|
|
84
87
|
setting: "maxWorkers",
|
|
88
|
+
budget: { module: BUDGET_MODULE, call: "testConcurrency" },
|
|
85
89
|
fixedArgument: FIXED_VITEST_WORKERS
|
|
86
90
|
}
|
|
87
91
|
});
|
|
@@ -125,8 +129,8 @@ function checkPlaywrightIsolation({ file, source, report }) {
|
|
|
125
129
|
|
|
126
130
|
// A config sets the runner's workers from the budget, and Vitest's never turns file parallelism off.
|
|
127
131
|
async function checkRunnerConfig({ root, configPath, directory, runner, report }) {
|
|
128
|
-
const { rule, setting, configNames } = RUNNERS[runner];
|
|
129
|
-
const wanted = `set \`${setting}:
|
|
132
|
+
const { rule, setting, configNames, budget } = RUNNERS[runner];
|
|
133
|
+
const wanted = `set \`${setting}: ${budget.call}()\` from ${budget.module}`;
|
|
130
134
|
if (!configPath || !(await fileExists(configPath))) {
|
|
131
135
|
const missing = configPath || path.join(directory, `${configNames[0]}.config.*`);
|
|
132
136
|
report({ file: toPosixPath(path.relative(root, missing)), line: 1, rule,
|
|
@@ -141,8 +145,13 @@ async function checkRunnerConfig({ root, configPath, directory, runner, report }
|
|
|
141
145
|
report({ file, line: lineOf(source, "workers:"), rule,
|
|
142
146
|
message: "playwright's workers are set over browserTestConfig()'s; drop them, so the machine's test budget sets them." });
|
|
143
147
|
}
|
|
144
|
-
} else if (!source.includes(
|
|
145
|
-
|
|
148
|
+
} else if (!source.includes(budget.module) || !new RegExp(`\\b${setting}\\s*:\\s*${budget.call}\\(\\s*\\)`, "u").test(source)) {
|
|
149
|
+
// A Playwright worker drives a browser, and its own app server where the config starts one: two of the budget.
|
|
150
|
+
const message = runner === "playwright"
|
|
151
|
+
? "playwright's workers are not browserTestWorkers(): each worker drives a browser, and its own app server where it " +
|
|
152
|
+
`starts one, about two threads, so it takes half the test budget (1 on a managed target); ${wanted}.`
|
|
153
|
+
: `${runner} runs at a fixed or default worker count; ${wanted}.`;
|
|
154
|
+
report({ file, line: lineOf(source, `${setting}:`), rule, message });
|
|
146
155
|
}
|
|
147
156
|
if (runner === "playwright") checkPlaywrightIsolation({ file, source, report });
|
|
148
157
|
if (runner === "vitest" && /\bfileParallelism\s*:\s*false\b/u.test(source)) {
|
|
@@ -178,7 +187,7 @@ async function checkTestRuns({ projectRoot, manifests }) {
|
|
|
178
187
|
const args = runnerArguments(tokens, runner);
|
|
179
188
|
if (!args) continue;
|
|
180
189
|
if (args.some((token) => RUNNERS[runner].fixedArgument.test(token))) {
|
|
181
|
-
at(RUNNERS[runner].rule, `passes ${runner} a fixed worker count; drop it, so the config's
|
|
190
|
+
at(RUNNERS[runner].rule, `passes ${runner} a fixed worker count; drop it, so the config's ${RUNNERS[runner].budget.call}() sets it.`);
|
|
182
191
|
}
|
|
183
192
|
const configPath = await findConfig(directory, configOption(args), RUNNERS[runner].configNames);
|
|
184
193
|
configs.set(`${runner}\0${configPath || directory}`, { runner, configPath, directory });
|