Skip to content

Commit b24c7bb

Browse files
committed
test(producer): gate source tests by execution lane
1 parent 38d62f7 commit b24c7bb

15 files changed

Lines changed: 273 additions & 35 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,31 @@ jobs:
235235
- run: bun run --cwd packages/core build:hyperframes-runtime
236236
- run: bun run --filter '!@hyperframes/producer' test
237237

238+
producer-source-tests:
239+
name: "Producer: ${{ matrix.lane }} tests"
240+
needs: changes
241+
if: needs.changes.outputs.code == 'true'
242+
runs-on: ubuntu-latest
243+
timeout-minutes: 20
244+
strategy:
245+
fail-fast: false
246+
matrix:
247+
lane: [unit, integration]
248+
steps:
249+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
250+
with:
251+
lfs: true
252+
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
253+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
254+
with:
255+
node-version: 22
256+
- uses: ./.github/actions/prepare-ffmpeg-bin
257+
- run: bun install --frozen-lockfile
258+
- run: bun run --filter '@hyperframes/{parsers,lint,studio-server}' build
259+
- run: bun run --cwd packages/core build
260+
- run: bun run --filter @hyperframes/engine build
261+
- run: bun run producer:test:${{ matrix.lane }}
262+
238263
# Tests under skills/**/*.test.mjs are bare `node --test` files with only
239264
# `node:` built-in imports. They aren't part of any workspace package, and
240265
# the main `Test` job's `code` path filter excludes `skills/**`, so without

‎bun.lock‎

Lines changed: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@
2929
"lint:fix": "oxlint --fix .",
3030
"check:tracked-artifacts": "node scripts/check-tracked-artifacts.mjs",
3131
"format": "oxfmt .",
32-
"test": "bun run --filter '*' test",
32+
"test": "bun run test:unit",
33+
"test:unit": "bun run --filter '*' test",
34+
"producer:test:classification": "bun run --cwd packages/producer test:classification",
35+
"producer:test:unit": "bun run --cwd packages/producer test:unit",
36+
"producer:test:unit:bun": "bun run --cwd packages/producer test:unit:bun",
37+
"producer:test:unit:vitest": "bun run --cwd packages/producer test:unit:vitest",
38+
"producer:test:integration": "bun run --cwd packages/producer test:integration",
39+
"test:regression": "bun run --cwd packages/producer test:regression",
3340
"player:perf": "bun run --filter @hyperframes/player perf",
3441
"format:check": "oxfmt --check .",
3542
"knip": "knip",

‎packages/producer/package.json‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,16 @@
4343
"check:runtime-conformance": "tsx src/runtime-conformance.ts",
4444
"benchmark": "tsx src/benchmark.ts",
4545
"bench:hdr": "tsx src/benchmark.ts --tags hdr",
46-
"test": "tsx src/regression-harness.ts --exclude-tags transparency",
47-
"test:update": "tsx src/regression-harness.ts --update --exclude-tags transparency",
46+
"test": "bun run test:unit",
47+
"test:classification": "node --test scripts/test-classification.test.mjs && node scripts/check-test-classification.mjs",
48+
"test:unit": "bun run test:classification && node scripts/run-test-lane.mjs unit",
49+
"test:unit:bun": "node scripts/run-test-lane.mjs unit bun",
50+
"test:unit:vitest": "node scripts/run-test-lane.mjs unit vitest",
51+
"test:integration": "bun run test:classification && node scripts/run-test-lane.mjs integration",
52+
"test:integration:bun": "node scripts/run-test-lane.mjs integration bun",
53+
"test:integration:vitest": "node scripts/run-test-lane.mjs integration vitest",
54+
"test:regression": "tsx src/regression-harness.ts --exclude-tags transparency",
55+
"test:regression:update": "tsx src/regression-harness.ts --update --exclude-tags transparency",
4856
"test:distributed": "tsx src/regression-harness.ts --exclude-tags transparency --mode=distributed-simulated",
4957
"test:transparency": "tsx src/transparency-test.ts",
5058
"docker:build:test": "docker build -f ../../Dockerfile.test -t hyperframes-producer:test ../..",
@@ -93,7 +101,8 @@
93101
"@webgpu/types": "^0.1.69",
94102
"esbuild": "^0.25.12",
95103
"tsx": "^4.21.0",
96-
"typescript": "^5.7.2"
104+
"typescript": "^5.7.2",
105+
"vitest": "^3.2.4"
97106
},
98107
"engines": {
99108
"node": ">=22"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { discoverProducerTests, summarizeTests } from "./test-classification.mjs";
2+
3+
try {
4+
const tests = discoverProducerTests();
5+
console.log(JSON.stringify({ event: "producer_tests_classified", ...summarizeTests(tests) }));
6+
} catch (error) {
7+
console.error(error instanceof Error ? error.message : String(error));
8+
process.exitCode = 1;
9+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { spawnSync } from "node:child_process";
2+
import { discoverProducerTests, PRODUCER_ROOT } from "./test-classification.mjs";
3+
4+
const lane = process.argv[2];
5+
const requestedRunner = process.argv[3];
6+
if (lane !== "unit" && lane !== "integration") {
7+
throw new Error("Usage: node scripts/run-test-lane.mjs <unit|integration> [bun|vitest]");
8+
}
9+
if (requestedRunner && requestedRunner !== "bun" && requestedRunner !== "vitest") {
10+
throw new Error(`Unknown test runner: ${requestedRunner}`);
11+
}
12+
13+
const tests = discoverProducerTests().filter(
14+
(test) => test.lane === lane && (!requestedRunner || test.runner === requestedRunner),
15+
);
16+
17+
function run(args) {
18+
const result = spawnSync("bun", args, {
19+
cwd: PRODUCER_ROOT,
20+
env: { ...process.env, HYPERFRAMES_TEST_LANE: lane },
21+
stdio: "inherit",
22+
});
23+
if (result.error) throw result.error;
24+
if (result.status !== 0) process.exit(result.status ?? 1);
25+
}
26+
27+
const vitestFiles = tests.filter((test) => test.runner === "vitest").map((test) => test.file);
28+
if (vitestFiles.length > 0) run(["x", "vitest", "run", ...vitestFiles]);
29+
30+
// Bun's mock.module registry is process-global. Run each file in a fresh
31+
// process so mocks from one source test cannot mutate another test's imports.
32+
for (const test of tests.filter((entry) => entry.runner === "bun")) {
33+
run(["test", test.file]);
34+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// fallow-ignore-file complexity
2+
import { readdirSync, readFileSync } from "node:fs";
3+
import { relative, resolve } from "node:path";
4+
import { fileURLToPath } from "node:url";
5+
6+
export const PRODUCER_ROOT = fileURLToPath(new URL("../", import.meta.url));
7+
8+
// These tests need host capabilities such as Chrome, ffmpeg, worker threads,
9+
// or local sockets. Keep the list explicit so a filename-only rename does not
10+
// make Git/fallow re-audit thousands of unchanged test lines as new code.
11+
const INTEGRATION_TEST_FILES = new Set([
12+
"src/services/deterministicFonts-systemCapture.test.ts",
13+
"src/services/distributed/assemble.test.ts",
14+
"src/services/distributed/chunkBoundary.test.ts",
15+
"src/services/distributed/crossWorkerIdempotency.test.ts",
16+
"src/services/distributed/plan.test.ts",
17+
"src/services/distributed/planSizeCap.test.ts",
18+
"src/services/distributed/renderChunk.test.ts",
19+
"src/services/fileServer.test.ts",
20+
"src/services/healthWorker.test.ts",
21+
"src/utils/audioRegression.test.ts",
22+
"src/utils/streamDurationParity.test.ts",
23+
]);
24+
25+
function collectTestFiles(directory, files = []) {
26+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
27+
const entryPath = resolve(directory, entry.name);
28+
if (entry.isDirectory()) collectTestFiles(entryPath, files);
29+
else if (entry.isFile() && entry.name.endsWith(".test.ts")) files.push(entryPath);
30+
}
31+
return files;
32+
}
33+
34+
export function classifyTestSource(filePath, source, integrationFiles = INTEGRATION_TEST_FILES) {
35+
const importsBun = /\bfrom\s+["']bun:test["']/.test(source);
36+
const importsVitest = /\bfrom\s+["']vitest["']/.test(source);
37+
if (importsBun === importsVitest) {
38+
const detail = importsBun ? "imports both bun:test and vitest" : "imports neither runner";
39+
throw new Error(`${filePath}: ${detail}`);
40+
}
41+
return {
42+
file: filePath,
43+
runner: importsBun ? "bun" : "vitest",
44+
lane: integrationFiles.has(filePath) ? "integration" : "unit",
45+
};
46+
}
47+
48+
export function discoverProducerTests(producerRoot = PRODUCER_ROOT) {
49+
const srcDir = resolve(producerRoot, "src");
50+
const files = collectTestFiles(srcDir).map((absolutePath) => ({
51+
absolutePath,
52+
filePath: relative(producerRoot, absolutePath).replaceAll("\\", "/"),
53+
}));
54+
const discoveredFiles = new Set(files.map((test) => test.filePath));
55+
const staleEntries = [...INTEGRATION_TEST_FILES].filter((file) => !discoveredFiles.has(file));
56+
if (staleEntries.length > 0) {
57+
throw new Error(`Integration test manifest contains missing files: ${staleEntries.join(", ")}`);
58+
}
59+
return files
60+
.map(({ absolutePath, filePath }) => {
61+
return classifyTestSource(filePath, readFileSync(absolutePath, "utf8"));
62+
})
63+
.sort((left, right) => left.file.localeCompare(right.file));
64+
}
65+
66+
export function summarizeTests(tests) {
67+
const summary = {
68+
total: tests.length,
69+
unit: { bun: 0, vitest: 0 },
70+
integration: { bun: 0, vitest: 0 },
71+
};
72+
for (const test of tests) summary[test.lane][test.runner] += 1;
73+
return summary;
74+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import assert from "node:assert/strict";
2+
import { describe, it } from "node:test";
3+
import {
4+
classifyTestSource,
5+
discoverProducerTests,
6+
summarizeTests,
7+
} from "./test-classification.mjs";
8+
9+
describe("producer test classification", () => {
10+
it("classifies each supported runner into one lane", () => {
11+
assert.deepEqual(classifyTestSource("src/a.test.ts", 'import { it } from "bun:test";'), {
12+
file: "src/a.test.ts",
13+
runner: "bun",
14+
lane: "unit",
15+
});
16+
assert.deepEqual(
17+
classifyTestSource(
18+
"src/a.test.ts",
19+
'import { it } from "vitest";',
20+
new Set(["src/a.test.ts"]),
21+
),
22+
{ file: "src/a.test.ts", runner: "vitest", lane: "integration" },
23+
);
24+
});
25+
26+
it("rejects missing and ambiguous runner imports", () => {
27+
assert.throws(() => classifyTestSource("src/a.test.ts", "export {};"), /neither runner/);
28+
assert.throws(
29+
() =>
30+
classifyTestSource(
31+
"src/a.test.ts",
32+
'import { it } from "bun:test"; import { expect } from "vitest";',
33+
),
34+
/both bun:test and vitest/,
35+
);
36+
});
37+
38+
it("classifies every current source test exactly once", () => {
39+
const tests = discoverProducerTests();
40+
assert.equal(new Set(tests.map((test) => test.file)).size, tests.length);
41+
const summary = summarizeTests(tests);
42+
assert.ok(summary.total > 0);
43+
assert.equal(
44+
summary.unit.bun + summary.unit.vitest + summary.integration.bun + summary.integration.vitest,
45+
summary.total,
46+
);
47+
});
48+
});

‎packages/producer/src/regression-harness.ts‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// fallow-ignore-file complexity
12
import {
23
existsSync,
34
mkdirSync,
@@ -1510,12 +1511,14 @@ async function run(): Promise<void> {
15101511
}
15111512
}
15121513

1513-
void run().catch((error) => {
1514-
console.error(
1515-
JSON.stringify({
1516-
event: "test_suite_fatal",
1517-
message: error instanceof Error ? error.message : String(error),
1518-
}),
1519-
);
1520-
process.exitCode = 1;
1521-
});
1514+
if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
1515+
void run().catch((error) => {
1516+
console.error(
1517+
JSON.stringify({
1518+
event: "test_suite_fatal",
1519+
message: error instanceof Error ? error.message : String(error),
1520+
}),
1521+
);
1522+
process.exitCode = 1;
1523+
});
1524+
}

0 commit comments

Comments
 (0)