@tokenoftrust/storefront-runner 3.1.0 → 3.1.2
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.
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
const { defineWorkersConfig } = require("@cloudflare/vitest-pool-workers/config");
|
|
12
12
|
const esbuild = require("esbuild");
|
|
13
13
|
const path = require("node:path");
|
|
14
|
+
// The check step's CPU budget sizes the worker pool (scripts/lib/step-cpus.cjs). Concurrent cells
|
|
15
|
+
// are not held to it: they interleave on the one workerd isolate thread and wait on alarms, so 24
|
|
16
|
+
// at once keep under one CPU busy (measured 2026-10-22: 11.5 CPU-s over 16.8s at 24; 87s at 3).
|
|
17
|
+
const { stepWorkers } = require("../../../../scripts/lib/step-cpus.cjs");
|
|
14
18
|
|
|
15
19
|
const compatibilityDate = "2024-11-01";
|
|
16
20
|
const compatibilityFlags = ["nodejs_compat"];
|
|
@@ -20,6 +24,7 @@ const HOST = "pipeline-host";
|
|
|
20
24
|
* @param {{ root: string; name: string; include: string[]; maxConcurrency?: number; testTimeout?: number }} options
|
|
21
25
|
*/
|
|
22
26
|
function pipelinePoolConfig({ root, name, include, maxConcurrency, testTimeout = 60_000 }) {
|
|
27
|
+
const workers = stepWorkers();
|
|
23
28
|
const hostModule = esbuild.buildSync({
|
|
24
29
|
entryPoints: [path.join(root, "test/pipeline/pipeline-host.ts")],
|
|
25
30
|
bundle: true,
|
|
@@ -42,6 +47,8 @@ function pipelinePoolConfig({ root, name, include, maxConcurrency, testTimeout =
|
|
|
42
47
|
testTimeout,
|
|
43
48
|
hookTimeout: 60_000,
|
|
44
49
|
...(maxConcurrency ? { maxConcurrency } : {}),
|
|
50
|
+
maxWorkers: workers.maxWorkers,
|
|
51
|
+
minWorkers: workers.minWorkers,
|
|
45
52
|
poolOptions: {
|
|
46
53
|
workers: {
|
|
47
54
|
isolatedStorage: false,
|
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
// node_modules/.vite/vitest.
|
|
4
4
|
process.env.VITE_CJS_IGNORE_WARNING = "1";
|
|
5
5
|
const { defineConfig } = require("vitest/config");
|
|
6
|
+
// The check step's CPU budget sizes the worker pool (scripts/lib/step-cpus.cjs).
|
|
7
|
+
const { stepWorkers } = require("../../scripts/lib/step-cpus.cjs");
|
|
6
8
|
const path = require("node:path");
|
|
7
9
|
|
|
10
|
+
const workers = stepWorkers();
|
|
11
|
+
|
|
8
12
|
// Storefront unit tests — pure TS logic (tenant routing, search, query engine,
|
|
9
13
|
// image-attr resolution, edge cache, etc.). We deliberately do NOT render .astro
|
|
10
14
|
// components here: the Astro Container API needs Astro's Vite pipeline, whose
|
|
@@ -34,5 +38,7 @@ module.exports = defineConfig({
|
|
|
34
38
|
// Folds and CI run many suites at once; a fixture-heavy test that takes 2s alone can pass 5s
|
|
35
39
|
// under that load. A genuinely hung test still fails, only later.
|
|
36
40
|
testTimeout: 30_000,
|
|
41
|
+
maxWorkers: workers.maxWorkers,
|
|
42
|
+
minWorkers: workers.minWorkers,
|
|
37
43
|
},
|
|
38
44
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
|
|
6
6
|
"packageManager": "pnpm@11.9.0",
|
|
@@ -3,11 +3,20 @@
|
|
|
3
3
|
// node_modules/.vite/vitest.
|
|
4
4
|
process.env.VITE_CJS_IGNORE_WARNING = "1";
|
|
5
5
|
const { defineConfig } = require("vitest/config");
|
|
6
|
+
// The check step's CPU budget sizes the worker pool (scripts/lib/step-cpus.cjs).
|
|
7
|
+
const { stepWorkers } = require("../../scripts/lib/step-cpus.cjs");
|
|
8
|
+
|
|
9
|
+
const workers = stepWorkers();
|
|
6
10
|
|
|
7
11
|
module.exports = defineConfig({
|
|
8
12
|
test: {
|
|
9
13
|
include: ["tests/**/*.test.ts"],
|
|
10
14
|
environment: "node",
|
|
11
15
|
cache: false,
|
|
16
|
+
// Folds and CI run many suites at once; a fixture-heavy test that takes 0.5s alone can pass 5s
|
|
17
|
+
// under that load. A genuinely hung test still fails, only later.
|
|
18
|
+
testTimeout: 30_000,
|
|
19
|
+
maxWorkers: workers.maxWorkers,
|
|
20
|
+
minWorkers: workers.minWorkers,
|
|
12
21
|
},
|
|
13
22
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// The CPU budget of the check step this process runs in. The check runner
|
|
2
|
+
// (scripts/lib/check-runner.mjs) reserves slots for each step and exports the count as
|
|
3
|
+
// TOT_STEP_CPUS; every pool a step starts (vitest workers, `node --test`
|
|
4
|
+
// files, `pnpm -r` packages) sizes itself from it, so a step never uses more CPUs than it reserved.
|
|
5
|
+
// With TOT_STEP_CPUS unset (a suite run by hand) every pool keeps its own default.
|
|
6
|
+
//
|
|
7
|
+
// CommonJS so the in-memory `.cts` vitest configs can require it as well as ESM can import it.
|
|
8
|
+
"use strict";
|
|
9
|
+
|
|
10
|
+
const STEP_CPUS_ENV = "TOT_STEP_CPUS";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The step's CPU budget, or null outside a budgeted step.
|
|
14
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
15
|
+
* @returns {number | null}
|
|
16
|
+
*/
|
|
17
|
+
function stepCpus(env = process.env) {
|
|
18
|
+
const raw = env[STEP_CPUS_ENV];
|
|
19
|
+
if (raw === undefined || raw === "") return null;
|
|
20
|
+
const cpus = Number(raw);
|
|
21
|
+
if (!Number.isInteger(cpus) || cpus < 1) throw new Error(`${STEP_CPUS_ENV} must be a positive integer, got "${raw}"`);
|
|
22
|
+
return cpus;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* vitest's worker pool for this step: at most the budget. Both are undefined outside a budgeted
|
|
27
|
+
* step, which leaves vitest's defaults.
|
|
28
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
29
|
+
* @returns {{ maxWorkers: number | undefined, minWorkers: number | undefined }}
|
|
30
|
+
*/
|
|
31
|
+
function stepWorkers(env = process.env) {
|
|
32
|
+
const cpus = stepCpus(env);
|
|
33
|
+
return { maxWorkers: cpus ?? undefined, minWorkers: cpus === null ? undefined : 1 };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* `node --test` flags with the run's file concurrency held to the budget. A flag list that already
|
|
38
|
+
* sets --test-concurrency keeps it.
|
|
39
|
+
* @param {string[]} flags
|
|
40
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
41
|
+
*/
|
|
42
|
+
function nodeTestFlags(flags, env = process.env) {
|
|
43
|
+
const cpus = stepCpus(env);
|
|
44
|
+
if (cpus === null || flags.some((flag) => flag.startsWith("--test-concurrency"))) return flags;
|
|
45
|
+
return [...flags, `--test-concurrency=${cpus}`];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = { STEP_CPUS_ENV, stepCpus, stepWorkers, nodeTestFlags };
|