Prepare verified laboratory 7 implementation and evidence

This commit is contained in:
rey
2026-11-17 17:32:06 +03:00
parent 20afc2c790
commit eb1b5c7b84
677 changed files with 208256 additions and 64 deletions
+68
View File
@@ -0,0 +1,68 @@
import { expect, test } from "bun:test";
import {
createRuntimePreparation,
type RuntimeMode,
} from "../scripts/runtime-preparation";
test("canonical runtime invokes its build exactly once", async () => {
const calls: string[] = [];
await createRuntimePreparation({
build: async () => {
calls.push("build");
},
verifyCache: async () => {
calls.push("cache");
},
})("canonical");
expect(calls).toEqual(["build"]);
});
test("checked cache verifies existing runtime without an implicit build", async () => {
const calls: string[] = [];
await createRuntimePreparation({
build: async () => {
calls.push("build");
},
verifyCache: async () => {
calls.push("cache");
},
})("checked-cache");
expect(calls).toEqual(["cache"]);
});
test("failed cache verification preserves its error and never falls back to a build", async () => {
const error = new Error("FIXTURE_WRONG_BINARY"),
calls: string[] = [];
let observed: unknown;
try {
await createRuntimePreparation({
build: async () => {
calls.push("build");
},
verifyCache: async () => {
calls.push("cache");
throw error;
},
})("checked-cache");
} catch (e) {
observed = e;
}
expect(observed).toBe(error);
expect(calls).toEqual(["cache"]);
});
test("unknown runtime mode fails before either operational port", async () => {
const calls: string[] = [];
await expect(
createRuntimePreparation({
build: async () => {
calls.push("build");
},
verifyCache: async () => {
calls.push("cache");
},
})("foreign" as RuntimeMode),
).rejects.toThrow("INVALID_RUNTIME_MODE");
expect(calls).toEqual([]);
});
test("constructor requires both explicit ports", () => {
expect(() =>
createRuntimePreparation({ build: async () => {} } as never),
).toThrow("RUNTIME_PREPARATION_PORTS_REQUIRED");
});