test(FN-3607): harden test workflow verification and isolation checks

- Expand test-changed coverage and shard selection assertions for CI workflows
- Improve vitest worker temp-directory utilities and related core/CLI tests
- Refine test isolation guardrails and runtime ignore handling for live .fusion noise
- Update contributing guidance and root test script usage for the verified workflow

Fusion-Task-Id: FN-3607
This commit is contained in:
Fusion
2026-05-06 11:51:31 -07:00
committed by gsxdsm
parent ed7769856c
commit f6394cc22b
10 changed files with 204 additions and 48 deletions

View File

@@ -4,6 +4,10 @@ interface ComputeMaxWorkersOptions {
defaultCap?: number;
}
function computeDefaultCap(cpuCap: number): number {
return Math.max(2, Math.min(6, Math.ceil(cpuCap / 2)));
}
function parsePositiveInt(value: string | undefined): number | undefined {
const parsed = Number.parseInt(value ?? "", 10);
if (!Number.isFinite(parsed) || parsed <= 0) return undefined;
@@ -17,13 +21,12 @@ function parsePositiveInt(value: string | undefined): number | undefined {
// 2. FUSION_TEST_TOTAL_WORKERS — global budget across the workspace, divided
// by FUSION_TEST_CONCURRENCY (default 1). Lets `pnpm -r` runs cap total
// fan-out instead of multiplying per package.
// 3. defaultCap — small ceiling (2 by default) so a single package run on a
// high-core machine stays gentle.
// 3. defaultCap — CPU-aware default for local single-package runs so modern
// machines can use more parallelism without runaway fan-out.
// All paths clamp to (cpus - 1) so we never oversubscribe.
export function computeMaxWorkers(options: ComputeMaxWorkersOptions = {}): number {
const { defaultCap = 2 } = options;
const cpuCap = Math.max(1, cpus().length - 1);
const { defaultCap = computeDefaultCap(cpuCap) } = options;
const explicit = parsePositiveInt(process.env.VITEST_MAX_WORKERS);
const totalBudget = parsePositiveInt(process.env.FUSION_TEST_TOTAL_WORKERS);

View File

@@ -43,7 +43,7 @@ describe("computeMaxWorkers", () => {
expect(process.env.VITEST_MAX_WORKERS).toBe("3");
});
it("ignores invalid env values and falls back to default cap", () => {
it("ignores invalid env values and falls back to provided default cap", () => {
process.env.VITEST_MAX_WORKERS = "abc";
process.env.FUSION_TEST_TOTAL_WORKERS = "0";
process.env.FUSION_TEST_CONCURRENCY = "-1";
@@ -53,4 +53,17 @@ describe("computeMaxWorkers", () => {
expect(workers).toBe(2);
expect(process.env.VITEST_MAX_WORKERS).toBe("2");
});
it("uses a CPU-aware default cap when no overrides are provided", () => {
delete process.env.VITEST_MAX_WORKERS;
delete process.env.FUSION_TEST_TOTAL_WORKERS;
delete process.env.FUSION_TEST_CONCURRENCY;
const cpuCap = Math.max(1, cpus().length - 1);
const expected = Math.max(2, Math.min(6, Math.ceil(cpuCap / 2)));
const workers = computeMaxWorkers();
expect(workers).toBe(expected);
expect(process.env.VITEST_MAX_WORKERS).toBe(String(expected));
});
});