Fork Horse repository, listed by its owner. Publisher snapshot.

packages/forkhorse-dashboard/test/archive-contract.test.ts

Snapshot at 34e3175

Containing directory

2,656 bytes · typescriptView raw
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 archive 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("archive-fixtures.ts", import.meta.url));
18  const scratch = mkdtempSync(join(tmpdir(), "fh-archive-contract-"));
19  try {
20    const contractPath = join(scratch, "contract.ts");
21    writeFileSync(contractPath, `${source.slice(0, boundary)}
22      import { archiveFixtureState, archiveRace } from ${JSON.stringify(fixturePath)};
23      const fixture = archiveFixtureState();
24      const packets: Packet[] = fixture.packets.map(packet => ({ ...packet, tokenBudget: packet.tokenBudget ?? undefined, archived: packet.archived ?? null }));
25      const blockers: Pick<Blocker, "packet" | "pushingPacket" | "resolved">[] = fixture.blockers.map(blocker => ({ ...blocker,
26        pushingPacket: blocker.pushingPacket ?? null, resolved: blocker.resolved ?? null }));
27      const race: RaceState = archiveRace();
28      const reviews: Pick<Review, "packet" | "promoted" | "stale" | "returned">[] =
29        fixture.reviews.map(review => ({ ...review, returned: review.returned ?? null }));
30    `);
31    const compiler = join(dirname(require.resolve("typescript/package.json")), "bin/tsc");
32    const typeRoots = fileURLToPath(new URL("../../../node_modules/@types", import.meta.url));
33    const result = spawnSync(process.execPath, [compiler, "--ignoreConfig", "--noEmit",
34      "--strict", "--skipLibCheck", "--allowImportingTsExtensions", "--module", "ESNext",
35      "--moduleResolution", "bundler", "--target", "ESNext", "--types", "node",
36      "--typeRoots", typeRoots, contractPath], { encoding: "utf8", timeout: 30000 });
37    assert.equal(result.status, 0, result.error?.message ?? result.stdout + result.stderr);
38  } finally {
39    rmSync(scratch, { recursive: true, force: true });
40  }
41});
42