Fork Horse repository, listed by its owner. Publisher snapshot.
packages/forkhorse-dashboard/test/race-contract.test.ts
Snapshot at 34e3175
1import assert from "node:assert/strict";
2import { spawnSync } from "node:child_process";
3import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4import { createRequire } from "node:module";
5import { tmpdir } from "node:os";
6import { dirname, join } from "node:path";
7import { fileURLToPath } from "node:url";
8import test from "node:test";
9
10const require = createRequire(import.meta.url);
11test("offline race fixture slices satisfy the merged core public contract", () => {
12 const source = readFileSync(new URL("../../forkhorse-core/src/workflow-types.ts", import.meta.url), "utf8");
13 // StateSnapshot imports Worker internals for project/activity. Check the public
14 // records before it in isolation, using the installed compiler and actual source.
15 const boundary = source.indexOf("export interface StateSnapshot");
16 assert.ok(boundary > 0, "Core public record declarations must precede StateSnapshot");
17 const fixturePath = fileURLToPath(new URL("race-fixtures.ts", import.meta.url));
18 const scratch = mkdtempSync(join(tmpdir(), "fh-race-contract-"));
19 try {
20 const contractPath = join(scratch, "contract.ts");
21 writeFileSync(contractPath, `${source.slice(0, boundary)}
22 import type { RaceFixture } from ${JSON.stringify(fixturePath)};
23 declare const fixture: RaceFixture;
24 const races: RaceState[] = fixture.races;
25 const ledger: LedgerEntry[] = fixture.ledger;
26 const reviews: (Review & { receipt: ReceiptSummary | null })[] = fixture.reviews;
27 `);
28 const compiler = join(dirname(require.resolve("typescript/package.json")), "bin/tsc");
29 const typeRoots = fileURLToPath(new URL("../../../node_modules/@types", import.meta.url));
30 const result = spawnSync(process.execPath, [compiler, "--ignoreConfig", "--noEmit",
31 "--strict", "--skipLibCheck", "--allowImportingTsExtensions", "--module", "ESNext",
32 "--moduleResolution", "bundler", "--target", "ESNext", "--types", "node",
33 "--typeRoots", typeRoots, contractPath], { encoding: "utf8", timeout: 30000 });
34 assert.equal(result.status, 0, result.error?.message ?? result.stdout + result.stderr);
35 } finally {
36 rmSync(scratch, { recursive: true, force: true });
37 }
38});
39