@gadicc/loom 2.2.1 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.loom-source-manifest.json +6 -1
- package/README.md +6 -4
- package/db/testing.d.ts +38 -1
- package/db/testing.js +66 -18
- package/db/testingTiming.js +45 -0
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +46 -0
- package/esm/src/cli/mod.js.map +1 -1
- package/esm/src/cli/testResourceCommand.d.ts +9 -0
- package/esm/src/cli/testResourceCommand.d.ts.map +1 -0
- package/esm/src/cli/testResourceCommand.js +33 -0
- package/esm/src/cli/testResourceCommand.js.map +1 -0
- package/esm/src/cli/testResourceHost.d.ts +36 -0
- package/esm/src/cli/testResourceHost.d.ts.map +1 -0
- package/esm/src/cli/testResourceHost.js +207 -0
- package/esm/src/cli/testResourceHost.js.map +1 -0
- package/esm/src/cli/testResourceLaunch.d.ts +22 -0
- package/esm/src/cli/testResourceLaunch.d.ts.map +1 -0
- package/esm/src/cli/testResourceLaunch.js +189 -0
- package/esm/src/cli/testResourceLaunch.js.map +1 -0
- package/esm/src/cli/testResourcePolicy.d.ts +24 -0
- package/esm/src/cli/testResourcePolicy.d.ts.map +1 -0
- package/esm/src/cli/testResourcePolicy.js +103 -0
- package/esm/src/cli/testResourcePolicy.js.map +1 -0
- package/esm/src/cli/testVitestRunner.d.ts +28 -0
- package/esm/src/cli/testVitestRunner.d.ts.map +1 -0
- package/esm/src/cli/testVitestRunner.js +159 -0
- package/esm/src/cli/testVitestRunner.js.map +1 -0
- package/package.json +2 -2
- package/skills/loom/SKILL.md +10 -0
- package/skills/loom-db/SKILL.md +8 -2
- package/skills/loom-db/references/test-boundaries.md +93 -0
- package/source/src/cli/mod.ts +70 -0
- package/source/src/cli/testResourceCommand.ts +49 -0
- package/source/src/cli/testResourceHost.ts +299 -0
- package/source/src/cli/testResourceLaunch.ts +257 -0
- package/source/src/cli/testResourcePolicy.ts +135 -0
- package/source/src/cli/testVitestRunner.ts +222 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
/** Parses Linux CPU lists strictly and returns normalized ascending indices. */
|
|
3
|
+
export function parseCpuList(text) {
|
|
4
|
+
const result = new Set();
|
|
5
|
+
for (const part of text.trim().split(",")) {
|
|
6
|
+
const match = /^(\d+)(?:-(\d+))?$/.exec(part);
|
|
7
|
+
if (!match)
|
|
8
|
+
throw new Error("Invalid CPU list");
|
|
9
|
+
const start = Number(match[1]);
|
|
10
|
+
const end = Number(match[2] ?? match[1]);
|
|
11
|
+
if (end < start || end > 1_000_000)
|
|
12
|
+
throw new Error("Invalid CPU range");
|
|
13
|
+
for (let cpu = start; cpu <= end; cpu++)
|
|
14
|
+
result.add(cpu);
|
|
15
|
+
}
|
|
16
|
+
return [...result].sort((a, b) => a - b);
|
|
17
|
+
}
|
|
18
|
+
/** Stable selection shared by projects; private masks never choose substitute cores. */
|
|
19
|
+
export function selectTestCpus(online, inherited, physical, reserve) {
|
|
20
|
+
const normalized = parseCpuList(online.join(","));
|
|
21
|
+
const onlineSet = new Set(normalized);
|
|
22
|
+
const cores = physical
|
|
23
|
+
? physical.map((item) => ({
|
|
24
|
+
socket: item.socket,
|
|
25
|
+
core: item.core,
|
|
26
|
+
cpus: [...item.cpus].sort((a, b) => a - b),
|
|
27
|
+
}))
|
|
28
|
+
: normalized.map((cpu) => ({ socket: 0, core: cpu, cpus: [cpu] }));
|
|
29
|
+
cores.sort((a, b) => a.socket - b.socket || a.core - b.core || a.cpus[0] - b.cpus[0]);
|
|
30
|
+
const covered = cores.flatMap((item) => item.cpus);
|
|
31
|
+
if (cores.some((item) => !Number.isInteger(item.socket) ||
|
|
32
|
+
!Number.isInteger(item.core) ||
|
|
33
|
+
item.cpus.length === 0) ||
|
|
34
|
+
covered.length !== normalized.length ||
|
|
35
|
+
new Set(covered).size !== covered.length ||
|
|
36
|
+
covered.some((cpu) => !onlineSet.has(cpu))) {
|
|
37
|
+
throw new Error("Physical topology must partition the online CPU set");
|
|
38
|
+
}
|
|
39
|
+
const count = reserve ?? (cores.length <= 2 ? 0 : cores.length < 8 ? 1 : 2);
|
|
40
|
+
if (!Number.isSafeInteger(count) || count < 0 || count >= cores.length) {
|
|
41
|
+
throw new Error("Reservation must leave at least one online core");
|
|
42
|
+
}
|
|
43
|
+
const reservedCpus = cores
|
|
44
|
+
.slice(0, count)
|
|
45
|
+
.flatMap((item) => item.cpus)
|
|
46
|
+
.sort((a, b) => a - b);
|
|
47
|
+
const reserved = new Set(reservedCpus);
|
|
48
|
+
const testCpus = [...new Set(inherited)]
|
|
49
|
+
.filter((cpu) => onlineSet.has(cpu) && !reserved.has(cpu))
|
|
50
|
+
.sort((a, b) => a - b);
|
|
51
|
+
if (testCpus.length === 0) {
|
|
52
|
+
throw new Error("Inherited CPU restrictions leave no test CPUs after exclusion");
|
|
53
|
+
}
|
|
54
|
+
const spec = "loom-cpu-selection-v1";
|
|
55
|
+
// No inherited mask, dynamic frequency, memory, or worker choice in the epoch.
|
|
56
|
+
const epoch = createHash("sha256")
|
|
57
|
+
.update(JSON.stringify({
|
|
58
|
+
spec,
|
|
59
|
+
online: normalized,
|
|
60
|
+
cores,
|
|
61
|
+
reserve: reserve ?? null,
|
|
62
|
+
}))
|
|
63
|
+
.digest("hex");
|
|
64
|
+
return {
|
|
65
|
+
spec,
|
|
66
|
+
epoch,
|
|
67
|
+
reservedCpus,
|
|
68
|
+
testCpus,
|
|
69
|
+
reservedCores: count,
|
|
70
|
+
topology: physical ? "physical" : "logical-fallback",
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** A cgroup quota ceiling, or undefined when any applicable limit is unknown. */
|
|
74
|
+
export function testCpuQuota(texts) {
|
|
75
|
+
let capacity = Infinity;
|
|
76
|
+
for (const text of texts) {
|
|
77
|
+
if (text === undefined)
|
|
78
|
+
return undefined;
|
|
79
|
+
const fields = text.trim().split(/\s+/);
|
|
80
|
+
if (fields.length !== 2 || !/^\d+$/.test(fields[1]))
|
|
81
|
+
return undefined;
|
|
82
|
+
const period = Number(fields[1]);
|
|
83
|
+
if (!Number.isSafeInteger(period) || period <= 0)
|
|
84
|
+
return undefined;
|
|
85
|
+
if (fields[0] === "max")
|
|
86
|
+
continue;
|
|
87
|
+
if (!/^\d+$/.test(fields[0]))
|
|
88
|
+
return undefined;
|
|
89
|
+
const quota = Number(fields[0]);
|
|
90
|
+
if (!Number.isSafeInteger(quota) || quota <= 0)
|
|
91
|
+
return undefined;
|
|
92
|
+
capacity = Math.min(capacity, quota / period);
|
|
93
|
+
}
|
|
94
|
+
return texts.length ? capacity : undefined;
|
|
95
|
+
}
|
|
96
|
+
/** Local desktop reserve; CI does not use this floor. */
|
|
97
|
+
export function testMemoryHeadroom(capacityBytes) {
|
|
98
|
+
if (!Number.isFinite(capacityBytes) || capacityBytes <= 0) {
|
|
99
|
+
throw new Error("Memory capacity must be positive and finite");
|
|
100
|
+
}
|
|
101
|
+
return Math.min(2 * 1024 ** 3, Math.max(256 * 1024 ** 2, capacityBytes * 0.1));
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=testResourcePolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testResourcePolicy.js","sourceRoot":"","sources":["../../../source/src/cli/testResourcePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAmBzC,gFAAgF;AAChF,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,kBAAk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AAyD;AACzD,MAAM,UAAU,kBAAkB,CAAC,aAAqB;IACtD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CACb,CAAC,GAAG,IAAI,IAAI,CAAC,EACb,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,EAAE,aAAa,GAAG,GAAG,CAAC,CAC/C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Minimal supported resolved config; Vitest stays an optional consumer dependency. */
|
|
2
|
+
interface ManagedConfig {
|
|
3
|
+
maxWorkers?: number;
|
|
4
|
+
pool?: unknown;
|
|
5
|
+
watch?: boolean;
|
|
6
|
+
projects?: unknown;
|
|
7
|
+
browser?: {
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
};
|
|
10
|
+
typecheck?: {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
};
|
|
13
|
+
passWithNoTests?: boolean;
|
|
14
|
+
standalone?: boolean;
|
|
15
|
+
ui?: boolean;
|
|
16
|
+
api?: unknown;
|
|
17
|
+
mergeReports?: unknown;
|
|
18
|
+
inspect?: unknown;
|
|
19
|
+
inspectBrk?: unknown;
|
|
20
|
+
}
|
|
21
|
+
/** Location used by the CLI to launch the same source or emitted runner module. */
|
|
22
|
+
export declare const managedVitestModuleURL: string;
|
|
23
|
+
/** Restrict a single, already resolved config before Vitest creates its pool. */
|
|
24
|
+
export declare function clampResolvedTestWorkers(config: ManagedConfig, ceiling: number): number;
|
|
25
|
+
/** Load the installed runner once, clamp final config, then execute that same instance. */
|
|
26
|
+
export declare function runManagedVitest(cwd: string, args: string[], ceiling: number, report?: (workers: number, pool: string) => void): Promise<number>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=testVitestRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testVitestRunner.d.ts","sourceRoot":"","sources":["../../../source/src/cli/testVitestRunner.ts"],"names":[],"mappings":"AAMA,uFAAuF;AACvF,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAChC,SAAS,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAClC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAsBD,mFAAmF;AACnF,eAAO,MAAM,sBAAsB,QAAkB,CAAC;AAEtD,iFAAiF;AACjF,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,GACd,MAAM,CAgDR;AAED,2FAA2F;AAC3F,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAe,GACzD,OAAO,CAAC,MAAM,CAAC,CAmHjB"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { createRequire } from "node:module";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import process from "node:process";
|
|
13
|
+
import { pathToFileURL } from "node:url";
|
|
14
|
+
/** Location used by the CLI to launch the same source or emitted runner module. */
|
|
15
|
+
export const managedVitestModuleURL = import.meta.url;
|
|
16
|
+
/** Restrict a single, already resolved config before Vitest creates its pool. */
|
|
17
|
+
export function clampResolvedTestWorkers(config, ceiling) {
|
|
18
|
+
if (!Number.isSafeInteger(ceiling) || ceiling < 1)
|
|
19
|
+
throw new Error("Invalid worker ceiling");
|
|
20
|
+
if (config.pool !== "threads" && config.pool !== "forks")
|
|
21
|
+
throw new Error("Managed tests support only threads and forks pools");
|
|
22
|
+
const api = config.api;
|
|
23
|
+
// Vitest resolves its disabled API to internal middleware metadata. Only
|
|
24
|
+
// a listening/unknown API mode is unsupported, not that ordinary default.
|
|
25
|
+
const listeningApi = api !== undefined &&
|
|
26
|
+
api !== false &&
|
|
27
|
+
api !== null &&
|
|
28
|
+
(typeof api !== "object" ||
|
|
29
|
+
!("middlewareMode" in api) ||
|
|
30
|
+
api.middlewareMode !== true ||
|
|
31
|
+
("port" in api && api.port !== undefined));
|
|
32
|
+
if (config.watch ||
|
|
33
|
+
config.standalone ||
|
|
34
|
+
config.ui ||
|
|
35
|
+
listeningApi ||
|
|
36
|
+
config.mergeReports ||
|
|
37
|
+
config.inspect ||
|
|
38
|
+
config.inspectBrk ||
|
|
39
|
+
config.projects ||
|
|
40
|
+
config.browser?.enabled ||
|
|
41
|
+
config.typecheck?.enabled) {
|
|
42
|
+
throw new Error("Managed tests currently require a single Node test project without watch, UI/API, standalone, merging, inspectors, browser or typecheck pools");
|
|
43
|
+
}
|
|
44
|
+
const existing = config.maxWorkers;
|
|
45
|
+
if (existing !== undefined &&
|
|
46
|
+
(!Number.isSafeInteger(existing) || existing < 1)) {
|
|
47
|
+
throw new Error("Unsupported resolved Vitest worker limit");
|
|
48
|
+
}
|
|
49
|
+
const selected = Math.min(ceiling, existing ?? ceiling);
|
|
50
|
+
// Later reporter hooks cannot raise a validated value before pool creation.
|
|
51
|
+
Object.defineProperty(config, "maxWorkers", {
|
|
52
|
+
value: selected,
|
|
53
|
+
enumerable: true,
|
|
54
|
+
writable: false,
|
|
55
|
+
configurable: false,
|
|
56
|
+
});
|
|
57
|
+
return selected;
|
|
58
|
+
}
|
|
59
|
+
/** Load the installed runner once, clamp final config, then execute that same instance. */
|
|
60
|
+
export async function runManagedVitest(cwd, args, ceiling, report = () => { }) {
|
|
61
|
+
let context;
|
|
62
|
+
let started = false;
|
|
63
|
+
let outcome = 120;
|
|
64
|
+
let api;
|
|
65
|
+
try {
|
|
66
|
+
if (args[0] !== "run")
|
|
67
|
+
throw new Error("Managed Vitest requires the run command; watch is not yet supported");
|
|
68
|
+
const require = createRequire(join(cwd, "package.json"));
|
|
69
|
+
const packagePath = require.resolve("vitest/package.json");
|
|
70
|
+
const pkg = JSON.parse(await readFile(packagePath, "utf8"));
|
|
71
|
+
const major = Number(pkg.version.split(".")[0]);
|
|
72
|
+
if (major !== 4 && major !== 5)
|
|
73
|
+
throw new Error(`Unsupported managed Vitest major ${major}`);
|
|
74
|
+
api = (await import(__rewriteRelativeImportExtension(pathToFileURL(require.resolve("vitest/node")).href)));
|
|
75
|
+
const parsed = api.parseCLI(["vitest", ...args]);
|
|
76
|
+
const options = parsed.options;
|
|
77
|
+
if (options.watch ||
|
|
78
|
+
options.standalone ||
|
|
79
|
+
options.ui ||
|
|
80
|
+
options.api ||
|
|
81
|
+
options.mergeReports ||
|
|
82
|
+
options.help ||
|
|
83
|
+
options.version ||
|
|
84
|
+
options.inspect ||
|
|
85
|
+
options.inspectBrk) {
|
|
86
|
+
throw new Error("Managed Vitest supports a finite run, without watch, UI, API or report merging");
|
|
87
|
+
}
|
|
88
|
+
const requested = options.maxWorkers;
|
|
89
|
+
let requestedCeiling = ceiling;
|
|
90
|
+
if (requested !== undefined) {
|
|
91
|
+
if (!/^\d+$/.test(String(requested)) ||
|
|
92
|
+
!Number.isSafeInteger(Number(requested)) ||
|
|
93
|
+
Number(requested) < 1 ||
|
|
94
|
+
Number(requested) > ceiling) {
|
|
95
|
+
throw new Error("Managed --maxWorkers must be a positive integer no higher than the launcher ceiling");
|
|
96
|
+
}
|
|
97
|
+
requestedCeiling = Number(requested);
|
|
98
|
+
// A CLI flag must not override the app's lower computed cap. Resolve
|
|
99
|
+
// the app once without this override, then take the minimum below.
|
|
100
|
+
delete options.maxWorkers;
|
|
101
|
+
}
|
|
102
|
+
process.env.TEST = "true";
|
|
103
|
+
process.env.VITEST = "true";
|
|
104
|
+
process.env.NODE_ENV ??= "test";
|
|
105
|
+
Object.assign(options, {
|
|
106
|
+
root: options.root ?? cwd,
|
|
107
|
+
run: true,
|
|
108
|
+
watch: false,
|
|
109
|
+
});
|
|
110
|
+
context =
|
|
111
|
+
major === 4
|
|
112
|
+
? await api.createVitest("test", options)
|
|
113
|
+
: await api.createVitest(options);
|
|
114
|
+
if (context.projects.length !== 1)
|
|
115
|
+
throw new Error("Managed Vitest requires exactly one resolved project");
|
|
116
|
+
const rootWorkers = clampResolvedTestWorkers(context.config, requestedCeiling);
|
|
117
|
+
for (const project of context.projects)
|
|
118
|
+
clampResolvedTestWorkers(project.config, rootWorkers);
|
|
119
|
+
// No new unchecked project may appear in an onInit reporter hook.
|
|
120
|
+
Object.freeze(context.projects);
|
|
121
|
+
Object.defineProperty(context, "projects", {
|
|
122
|
+
value: context.projects,
|
|
123
|
+
writable: false,
|
|
124
|
+
configurable: false,
|
|
125
|
+
});
|
|
126
|
+
report(rootWorkers, String(context.config.pool));
|
|
127
|
+
started = true;
|
|
128
|
+
const result = await context.start(parsed.filter);
|
|
129
|
+
outcome =
|
|
130
|
+
result.unhandledErrors.length ||
|
|
131
|
+
result.testModules.some((module) => module.state() === "failed")
|
|
132
|
+
? 1
|
|
133
|
+
: Number(process.exitCode ?? 0);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const Missing = api?.TestsNotFoundError ?? api?.FilesNotFoundError;
|
|
137
|
+
if (started &&
|
|
138
|
+
context?.config.passWithNoTests &&
|
|
139
|
+
Missing &&
|
|
140
|
+
error instanceof Missing)
|
|
141
|
+
outcome = 0;
|
|
142
|
+
else {
|
|
143
|
+
console.error(`Loom ${started ? "test runner" : "test preflight"}: ${error instanceof Error ? error.message : String(error)}`);
|
|
144
|
+
outcome = started ? 1 : 120;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
try {
|
|
149
|
+
await context?.close();
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
console.error("Loom test cleanup:", error);
|
|
153
|
+
if (outcome === 0)
|
|
154
|
+
outcome = 1;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return outcome;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=testVitestRunner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testVitestRunner.js","sourceRoot":"","sources":["../../../source/src/cli/testVitestRunner.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAuCzC,mFA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C,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,QAAQ,CAAC;gBAC9D,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,GAAG,EAAE,kBAAkB,IAAI,GAAG,EAAE,kBAAkB,CAAC;QACnE,IACE,OAAO;YACP,OAAO,EAAE,MAAM,CAAC,eAAe;YAC/B,OAAO;YACP,KAAK,YAAY,OAAO;YAExB,OAAO,GAAG,CAAC,CAAC;aACT,CAAC;YACJ,OAAO,CAAC,KAAK,CACX,QAAQ,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAChH,CAAC;YACF,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QAC9B,CAAC;IACH,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;YAC3C,IAAI,OAAO,KAAK,CAAC;gBAAE,OAAO,GAAG,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gadicc/loom",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Shared helpers and verification tooling for Next.js applications.",
|
|
5
5
|
"homepage": "https://github.com/gadicc/loom#readme",
|
|
6
6
|
"repository": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://github.com/gadicc/loom/issues"
|
|
12
12
|
},
|
|
13
13
|
"loom": {
|
|
14
|
-
"gitCommit": "
|
|
14
|
+
"gitCommit": "aefcdc95762cffdae8af715ce57f6344f7abc45f"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
|
17
17
|
"main": "./esm/mod.js",
|
package/skills/loom/SKILL.md
CHANGED
|
@@ -85,6 +85,16 @@ from the consumer's working directory.
|
|
|
85
85
|
|
|
86
86
|
## High-value code improvements
|
|
87
87
|
|
|
88
|
+
When adding or changing tests, choose the lightest tier that proves their
|
|
89
|
+
assertions. For database-related tests, use `loom-db` and its
|
|
90
|
+
[test boundaries](../loom-db/references/test-boundaries.md) guidance. Inspect
|
|
91
|
+
tests touched by ordinary feature work for avoidable database initialization;
|
|
92
|
+
the user does not need to request a separate performance review. Implement
|
|
93
|
+
small, behavior-preserving splits that fit the task and verify the retained
|
|
94
|
+
integration coverage. Record broader opportunities with their scope and
|
|
95
|
+
evidence instead of starting a fleet rewrite or changing runner/backends as a
|
|
96
|
+
side effect.
|
|
97
|
+
|
|
88
98
|
While doing requested work, look for high-value improvements in code you
|
|
89
99
|
inspect, including existing code that works but is unnecessarily verbose or
|
|
90
100
|
difficult to maintain. Behavior-preserving cleanup is valuable when it makes
|
package/skills/loom-db/SKILL.md
CHANGED
|
@@ -82,13 +82,19 @@ Use this skill when working on the shared DB stack from a consuming app.
|
|
|
82
82
|
|
|
83
83
|
## Validation and tests
|
|
84
84
|
|
|
85
|
+
Read [test boundaries and local resources](references/test-boundaries.md) before
|
|
86
|
+
adding or changing database-related tests, retargeting existing tests, changing
|
|
87
|
+
test backends or adopting resource controls. Apply the criteria during normal
|
|
88
|
+
feature work, including small opportunities to remove unnecessary DB startup
|
|
89
|
+
from tests already being touched; do not wait for a separate optimization request.
|
|
90
|
+
|
|
85
91
|
- Use `loom db schema-gen` after schema changes that affect generated Valibot
|
|
86
92
|
output.
|
|
87
93
|
- Use `loom db schemas sync` to refresh active Loom-managed schema blueprints,
|
|
88
94
|
then review diffs and run the normal migration generation flow deliberately.
|
|
89
95
|
- Keep `src/db/valibot/generated/*` generated and committed, never hand-edited.
|
|
90
|
-
-
|
|
91
|
-
|
|
96
|
+
- For SQL assertions, prefer `tests/memory-pglite.ts` plus a mock of `@/db/neon`
|
|
97
|
+
or `@/db/neonFull`; pure decisions should not initialize a database.
|
|
92
98
|
- If fixtures are used, keep them under `tests/fixtures/db/` and serialize them
|
|
93
99
|
with `superjson`.
|
|
94
100
|
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Database test boundaries and local resources
|
|
2
|
+
|
|
3
|
+
Apply these criteria while adding or editing tests during ordinary feature work.
|
|
4
|
+
Inspect the touched tests' runtime imports and assertion claims; make a small
|
|
5
|
+
verified boundary improvement when it fits the task. Propose broader work with
|
|
6
|
+
concrete candidates and evidence. No periodic agent, automatic fleet sweep or
|
|
7
|
+
target percentage is implied.
|
|
8
|
+
|
|
9
|
+
Retarget tests by what their assertions prove. Pure decisions use plain values
|
|
10
|
+
and a module with no runtime DB/schema import. Feature orchestration may use a
|
|
11
|
+
small repository fake only when the fake and real implementation share a
|
|
12
|
+
contract suite. SQL predicates, joins, mapping, constraints and persistence stay
|
|
13
|
+
on PGlite. Independent transactions, locking/isolation, RLS/roles, production
|
|
14
|
+
extensions and version-specific behavior need native PostgreSQL with the
|
|
15
|
+
relevant independent connections. Provider transport needs its own adapter gate.
|
|
16
|
+
PGlite remains appropriate for SQL; a JS PostgreSQL emulator is not the default.
|
|
17
|
+
|
|
18
|
+
Preserve the original business assertions when splitting a test. Add actual
|
|
19
|
+
production-loader coverage before removing test-local SQL setup. Seed targeted
|
|
20
|
+
query faults (for example a missing owner/building predicate or wrong join) and
|
|
21
|
+
confirm the retained SQL tests fail. Keep useful service/repository end-to-end
|
|
22
|
+
paths. Do not convert tests based only on filenames or a target percentage.
|
|
23
|
+
Required integration commands fail when their backend or expected discovery is
|
|
24
|
+
missing; a silently skipped native suite does not prove that coverage exists.
|
|
25
|
+
|
|
26
|
+
For investigation, the shared harness has optional synchronous `onTiming`
|
|
27
|
+
events with phase, duration and status only. Keep collectors short, omit them
|
|
28
|
+
normally, and use `harness.close()` for observed owned cleanup. Existing
|
|
29
|
+
`client.close()` remains valid. Do not log fixtures, SQL, paths or credentials.
|
|
30
|
+
|
|
31
|
+
On a Loom version that provides the resource commands:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
loom test resources doctor
|
|
35
|
+
loom test run --workers auto --cpu-mode exclude --dry-run -- vitest run
|
|
36
|
+
loom test run --workers auto --cpu-mode exclude -- vitest run
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`auto` selects the visible CPU/quota ceiling; it is not a measured optimum.
|
|
40
|
+
Existing lower app caps remain authoritative. An explicit numeric count may
|
|
41
|
+
lower demand. Local Linux exclusion reserves all SMT siblings of the same
|
|
42
|
+
stable machine cores across projects; it never chooses replacement cores from
|
|
43
|
+
an inherited private mask. One or two physical cores are reserved according to
|
|
44
|
+
small-device thresholds. There is no persistent machine policy or aggregate
|
|
45
|
+
worker/memory admission. Identical stateless v1 clients need the same visible
|
|
46
|
+
online topology; inspect their epochs when diagnosing differences.
|
|
47
|
+
|
|
48
|
+
CI ignores the local worker request, exclusion and desktop memory floor, while
|
|
49
|
+
retaining container limits and deliberate app/runner caps. `--test-profile local`
|
|
50
|
+
explicitly overrides CI detection; `ci` explicitly selects CI behavior. On
|
|
51
|
+
unknown local quota the pilot degrades to one worker. Unknown or insufficient
|
|
52
|
+
local memory headroom refuses the run; there is no calibrated per-worker memory
|
|
53
|
+
estimate or hard memory isolation.
|
|
54
|
+
|
|
55
|
+
Only finite, single-project Vitest 4/5 Node pools (`threads`/`forks`) are
|
|
56
|
+
supported. Existing environments such as jsdom remain app-configured. Watch, UI/API, standalone/report merging, inspectors,
|
|
57
|
+
browser/VM/custom pools, multi-project runs and percentage CLI worker overrides
|
|
58
|
+
are unavailable. Config loads once; lowering CLI counts work, while escalation
|
|
59
|
+
and late attempts to raise the resolved bound fail before test execution.
|
|
60
|
+
The CLI runs Vitest in Node, including when Loom itself starts in Bun or Deno.
|
|
61
|
+
Keep any explicitly Bun-executed Vitest task on its existing path until that
|
|
62
|
+
runner runtime has its own verified adapter.
|
|
63
|
+
|
|
64
|
+
Preserve the app's pool, config, filters, environment wrapper and prerequisites.
|
|
65
|
+
For example, keep an existing `loom env --` outside the resource command and
|
|
66
|
+
keep generated-data/i18n steps before it. Read recorded `project.tooling` before
|
|
67
|
+
editing a task; do not assume npm scripts or pnpm. Resource controls apply to
|
|
68
|
+
the runner child, after those prerequisites and normal Loom sync. Progress goes
|
|
69
|
+
to stderr; reporter stdout is retained. `--quiet-test-resources` suppresses
|
|
70
|
+
Loom's resource summary.
|
|
71
|
+
|
|
72
|
+
Normal terminal job control is retained. Nonterminal POSIX termination is
|
|
73
|
+
forwarded to the owned process group; no daemon, SIGKILL/orphan containment or
|
|
74
|
+
active-run drain guarantee is provided. Use verified disposable scopes for
|
|
75
|
+
unattended performance experiments. Other users and unwrapped jobs remain
|
|
76
|
+
outside this policy. Do not promise OS responsiveness or speed from affinity.
|
|
77
|
+
|
|
78
|
+
Keep new controls opt-in until representative comparisons justify adoption.
|
|
79
|
+
|
|
80
|
+
A smaller dedicated local PGlite worker budget is a separate experiment from engine
|
|
81
|
+
reuse. Restricting workers can reduce simultaneous engines but still creates a
|
|
82
|
+
fresh harness per isolated file. Reusing an engine requires independent proof
|
|
83
|
+
of reset correctness, fixture/schema ownership, transaction behavior and leaked
|
|
84
|
+
state/resource cleanup. Pure and SQL jobs must share an explicit total budget
|
|
85
|
+
when run together; independent per-job caps do not provide aggregate admission.
|
|
86
|
+
The current launcher supports one finite single-project run, not a composed
|
|
87
|
+
multi-project scheduler. Do not disable isolation or share mutable databases
|
|
88
|
+
merely to make worker processes longer-lived.
|
|
89
|
+
|
|
90
|
+
The initial busy-desktop pilot found two workers slower than the unchanged
|
|
91
|
+
three-file selection, and per-run prepared SQL was slower after preparation.
|
|
92
|
+
Neither result determines the best setting for another app/device. No worker
|
|
93
|
+
count, DB backend replacement or cross-run cache is selected fleet-wide.
|
package/source/src/cli/mod.ts
CHANGED
|
@@ -57,6 +57,8 @@ import {
|
|
|
57
57
|
syncSourceDev,
|
|
58
58
|
watchSourceDev,
|
|
59
59
|
} from "./sourceDev.ts";
|
|
60
|
+
import { runTestResourceDoctor } from "./testResourceCommand.ts";
|
|
61
|
+
import { runManagedTestCommand } from "./testResourceLaunch.ts";
|
|
60
62
|
|
|
61
63
|
import {
|
|
62
64
|
type FilesR2DirectUploadPolicy,
|
|
@@ -23779,6 +23781,12 @@ function printHelp({ out }: CliOutput) {
|
|
|
23779
23781
|
out("loom <command>");
|
|
23780
23782
|
out("");
|
|
23781
23783
|
out("Commands:");
|
|
23784
|
+
out(
|
|
23785
|
+
" test run --workers <count|auto> -- vitest run [args] Opt in to verified finite worker controls (--cpu-mode inherit|exclude, --dry-run).",
|
|
23786
|
+
);
|
|
23787
|
+
out(
|
|
23788
|
+
" test resources doctor Inspect local/CI resource limits without changing policy (--json, --test-profile local|ci).",
|
|
23789
|
+
);
|
|
23782
23790
|
out(
|
|
23783
23791
|
" init Set up package/Deno config, loom.json, managed AGENTS.md guidance, first-party links, and package skills.",
|
|
23784
23792
|
);
|
|
@@ -25194,6 +25202,12 @@ function printSkillsHelp({ out }: CliOutput) {
|
|
|
25194
25202
|
out("loom skills <command> [skill]");
|
|
25195
25203
|
out("");
|
|
25196
25204
|
out("Commands:");
|
|
25205
|
+
out(
|
|
25206
|
+
" test run --workers <count|auto> -- vitest run [args] Opt in to verified finite worker controls (--cpu-mode inherit|exclude, --dry-run).",
|
|
25207
|
+
);
|
|
25208
|
+
out(
|
|
25209
|
+
" test resources doctor Inspect local/CI resource limits without changing policy (--json, --test-profile local|ci).",
|
|
25210
|
+
);
|
|
25197
25211
|
out(" list Show discovered, adopted, disabled, and recommended skills.");
|
|
25198
25212
|
out(" add Adopt selected external or installed npm skills.");
|
|
25199
25213
|
out(" sync Restore recorded skill content and links.");
|
|
@@ -26620,6 +26634,12 @@ export async function runCli(
|
|
|
26620
26634
|
force: { type: "boolean" },
|
|
26621
26635
|
help: { short: "h", type: "boolean" },
|
|
26622
26636
|
jurisdiction: { type: "string" },
|
|
26637
|
+
json: { type: "boolean" },
|
|
26638
|
+
"test-profile": { type: "string" },
|
|
26639
|
+
"cpu-mode": { type: "string" },
|
|
26640
|
+
workers: { type: "string" },
|
|
26641
|
+
"quiet-test-resources": { type: "boolean" },
|
|
26642
|
+
"dry-run": { type: "boolean" },
|
|
26623
26643
|
"local-bucket": { type: "string" },
|
|
26624
26644
|
"local-db-host": { type: "string" },
|
|
26625
26645
|
"local-db-port": { type: "string" },
|
|
@@ -26663,6 +26683,28 @@ export async function runCli(
|
|
|
26663
26683
|
}
|
|
26664
26684
|
|
|
26665
26685
|
const [command, arg1, arg2, ...rest] = parsed.positionals;
|
|
26686
|
+
const resourceRun = command === "test" && arg1 === "run";
|
|
26687
|
+
const resourceDoctor =
|
|
26688
|
+
command === "test" && arg1 === "resources" && arg2 === "doctor";
|
|
26689
|
+
// A generic dry-run flag must never be silently ignored by another command
|
|
26690
|
+
// that could provision resources. Refuse before automatic local-dev sync.
|
|
26691
|
+
if (
|
|
26692
|
+
(parsed.values["dry-run"] && !resourceRun) ||
|
|
26693
|
+
(parsed.values.json && !resourceDoctor) ||
|
|
26694
|
+
(!resourceRun &&
|
|
26695
|
+
(parsed.values.workers !== undefined ||
|
|
26696
|
+
parsed.values["cpu-mode"] !== undefined ||
|
|
26697
|
+
parsed.values["quiet-test-resources"])) ||
|
|
26698
|
+
(!resourceRun &&
|
|
26699
|
+
!resourceDoctor &&
|
|
26700
|
+
parsed.values["test-profile"] !== undefined)
|
|
26701
|
+
) {
|
|
26702
|
+
io.err(
|
|
26703
|
+
"Test-resource flags apply only to their documented loom test command; no command ran.",
|
|
26704
|
+
);
|
|
26705
|
+
return 1;
|
|
26706
|
+
}
|
|
26707
|
+
|
|
26666
26708
|
const cwd = parsed.values.cwd
|
|
26667
26709
|
? resolve(process.cwd(), parsed.values.cwd)
|
|
26668
26710
|
: process.cwd();
|
|
@@ -26670,6 +26712,8 @@ export async function runCli(
|
|
|
26670
26712
|
const productionCheck =
|
|
26671
26713
|
command === "check" && (parsed.values.production ?? false);
|
|
26672
26714
|
const addListOnly = command === "add" && arg1 === undefined;
|
|
26715
|
+
const testResourceDoctor =
|
|
26716
|
+
command === "test" && arg1 === "resources" && arg2 === "doctor";
|
|
26673
26717
|
|
|
26674
26718
|
if (
|
|
26675
26719
|
command !== undefined &&
|
|
@@ -26680,6 +26724,8 @@ export async function runCli(
|
|
|
26680
26724
|
command !== "skills" &&
|
|
26681
26725
|
command !== "status" &&
|
|
26682
26726
|
!addListOnly &&
|
|
26727
|
+
!testResourceDoctor &&
|
|
26728
|
+
!(command === "test" && arg1 === "run" && parsed.values["dry-run"]) &&
|
|
26683
26729
|
!productionCheck &&
|
|
26684
26730
|
!parsed.values["no-sync"]
|
|
26685
26731
|
) {
|
|
@@ -26815,6 +26861,30 @@ export async function runCli(
|
|
|
26815
26861
|
return await runSkills(cwd, arg1, [arg2, ...rest].filter(Boolean), io, {
|
|
26816
26862
|
acceptUnknownLicense: parsed.values["accept-unknown-license"],
|
|
26817
26863
|
});
|
|
26864
|
+
case "test":
|
|
26865
|
+
if (arg1 === "run") {
|
|
26866
|
+
if (!args.includes("--")) {
|
|
26867
|
+
io.err("Use -- before the Vitest command.");
|
|
26868
|
+
return 1;
|
|
26869
|
+
}
|
|
26870
|
+
return await runManagedTestCommand(
|
|
26871
|
+
cwd,
|
|
26872
|
+
args.slice(args.indexOf("--") + 1),
|
|
26873
|
+
{
|
|
26874
|
+
workers: parsed.values.workers,
|
|
26875
|
+
cpuMode: parsed.values["cpu-mode"],
|
|
26876
|
+
profile: parsed.values["test-profile"],
|
|
26877
|
+
quiet: parsed.values["quiet-test-resources"],
|
|
26878
|
+
dryRun: parsed.values["dry-run"],
|
|
26879
|
+
},
|
|
26880
|
+
io,
|
|
26881
|
+
);
|
|
26882
|
+
}
|
|
26883
|
+
return await runTestResourceDoctor(
|
|
26884
|
+
[arg1, arg2, ...rest],
|
|
26885
|
+
{ profile: parsed.values["test-profile"], json: parsed.values.json },
|
|
26886
|
+
io,
|
|
26887
|
+
);
|
|
26818
26888
|
case "env":
|
|
26819
26889
|
return await runEnvCommand(
|
|
26820
26890
|
cwd,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { inspectTestResources } from "./testResourceHost.ts";
|
|
2
|
+
|
|
3
|
+
/** Read-only diagnostic command; policy selection and runner enforcement are separate gates. */
|
|
4
|
+
export async function runTestResourceDoctor(
|
|
5
|
+
args: readonly (string | undefined)[],
|
|
6
|
+
options: { profile?: string; json?: boolean },
|
|
7
|
+
io: { out: (line: string) => void; err: (line: string) => void },
|
|
8
|
+
): Promise<number> {
|
|
9
|
+
if (
|
|
10
|
+
args[0] !== "resources" ||
|
|
11
|
+
args[1] !== "doctor" ||
|
|
12
|
+
args.slice(2).some((arg) => arg !== undefined)
|
|
13
|
+
) {
|
|
14
|
+
io.err(
|
|
15
|
+
"Usage: loom test resources doctor [--test-profile local|ci] [--json]",
|
|
16
|
+
);
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
if (
|
|
20
|
+
options.profile !== undefined &&
|
|
21
|
+
options.profile !== "local" &&
|
|
22
|
+
options.profile !== "ci"
|
|
23
|
+
) {
|
|
24
|
+
io.err("Test resource profile must be local or ci (exit 120).");
|
|
25
|
+
return 120;
|
|
26
|
+
}
|
|
27
|
+
const report = await inspectTestResources({ profile: options.profile });
|
|
28
|
+
if (options.json) io.out(JSON.stringify(report));
|
|
29
|
+
else {
|
|
30
|
+
io.out(`Test resources: ${report.profile} profile, ${report.platform}`);
|
|
31
|
+
io.out(
|
|
32
|
+
`Inherited logical CPUs: ${report.cpu.inherited.length || "unknown"}; visible quota: ${report.cpu.quota.status === "known" ? report.cpu.quota.cpus : report.cpu.quota.status}.`,
|
|
33
|
+
);
|
|
34
|
+
const selection = report.cpu.exclusion;
|
|
35
|
+
if (selection) {
|
|
36
|
+
io.out(
|
|
37
|
+
`Hypothetical exclusion: ${selection.spec}, ${selection.reservedCores} ${selection.topology === "physical" ? "physical cores" : "logical CPUs"}, epoch ${selection.epoch}.`,
|
|
38
|
+
);
|
|
39
|
+
io.out(
|
|
40
|
+
`Test CPU intersection: ${selection.testCpus.join(",")}. No affinity was changed.`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
io.out(
|
|
44
|
+
`Diagnostic CPU ceiling: ${report.cpu.diagnosticCeiling ?? "unknown"}; this is not an app worker setting.`,
|
|
45
|
+
);
|
|
46
|
+
for (const warning of report.warnings) io.err(`Note: ${warning}`);
|
|
47
|
+
}
|
|
48
|
+
return 0;
|
|
49
|
+
}
|