Files
clean-architecture-frontend…/tests/unit/runbook-drill.test.ts
T
DongHyeonkaandClaude Opus 5.5 839205c134 feat(release): re-verify a promoted release in archived mode (13-04)
Provider evidence expires two hours after issue, so no repo tool could
re-verify a release before deploying it later or rolling back to it.
verify:promotion --archived keeps every signature, digest and member check and
judges freshness at the recorded promotion time; the FE-RB-005 drill takes the
extracted release with --release-root.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:58:37 +09:00

130 lines
4.7 KiB
TypeScript

import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { runRunbookDrill } from "../../scripts/drill-runbook.ts";
import { computeContractSetDigest } from "../../src/contracts/contract-set-canonical.ts";
import type { InstalledContractPackageIdentity } from "../../src/contracts/external-contract-runtime.ts";
// 11-01 / 13-03 (D-14). A drill reports PASS only for what it observed on the
// local build. Boot, live traffic, smoke and the provider switch are not
// observable here, so a drill with provider scope ends UNVERIFIED, never PASS.
const contractPackages = [
{
packageId: "@example/accounts",
version: "1.2.3",
digest: `sha256:${"1".repeat(64)}`,
runtimeProtocolVersion: 1,
sourceRevision: "a".repeat(40),
},
] as const satisfies readonly InstalledContractPackageIdentity[];
const RUNBOOK_IDS = ["FE-RB-001", "FE-RB-002", "FE-RB-003", "FE-RB-004", "FE-RB-005"] as const;
const roots: string[] = [];
afterEach(async () => {
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
});
async function builtDist(options: Readonly<{ withoutJs?: boolean; withoutDist?: boolean }> = {}) {
const root = await mkdtemp(path.join(tmpdir(), "runbook-drill-"));
roots.push(root);
if (options.withoutDist) return root;
const write = async (file: string, content: string) => {
await mkdir(path.dirname(path.join(root, file)), { recursive: true });
await writeFile(path.join(root, file), content);
};
await write("dist/index.html", "<!doctype html><script type=module src=/assets/index-a.js></script>");
await write(
"dist/.vite/manifest.json",
JSON.stringify({
"index.html": { file: "assets/index-a.js", isEntry: true, css: ["assets/index-a.css"], imports: ["_shared-b.js"] },
"_shared-b.js": { file: "assets/shared-b.js" },
"src/pages/lazy.tsx": { file: "assets/lazy-c.js", isDynamicEntry: true },
}),
);
await write("dist/assets/index-a.css", "body{}");
if (!options.withoutJs) {
for (const file of ["assets/index-a.js", "assets/shared-b.js", "assets/lazy-c.js"]) {
await write(`dist/${file}`, "export {};");
}
}
await write(
"dist/release-manifest.json",
JSON.stringify({
schemaVersion: 2,
appVersion: "1.0.0",
buildId: "build-a",
commitSha: "abc1234",
configSchemaVersion: "2.0",
assetManifestHash: "assets-a",
releaseId: "release-a",
builtAt: "2026-08-01T00:00:00.000Z",
routeChunks: {},
contractSet: {
setAlgorithm: "CA_CONTRACT_SET_V1",
setDigest: await computeContractSetDigest(contractPackages),
packages: [...contractPackages],
},
}),
);
await write(
"dist/config.json",
JSON.stringify({
APP_ENV: "local",
API_BASE_URL: "http://localhost:8080/",
REQUEST_TIMEOUT_MS: 10_000,
MAX_RETRY_ATTEMPTS: 2,
TELEMETRY_ENABLED: false,
AUTH_MODE: "external",
CONFIG_SCHEMA_VERSION: "2.0",
RELEASE_MANIFEST_URL: "/release-manifest.json",
BUILD_ID: "build-a",
RELEASE_ID: "release-a",
CAPABILITY_OVERRIDES: {
REALTIME: "DEFAULT",
WEB_WORKER: "DEFAULT",
SERVICE_WORKER: "DEFAULT",
OFFLINE_COMMANDS: "DEFAULT",
},
FEATURE_OVERRIDES: {},
}),
);
return root;
}
describe("runbook drill verdicts", () => {
it.each(RUNBOOK_IDS)("%s on a complete local build is UNVERIFIED, not PASS", async (runbookId) => {
const record = await runRunbookDrill(runbookId, { releaseRoot: await builtDist(), contractPackages });
expect(record.result).toBe("UNVERIFIED");
expect(record.recoveryAssertions.some(({ result }) => result === "FAIL")).toBe(false);
});
it.each(["FE-RB-002", "FE-RB-005"] as const)(
"%s fails when the build lost its JavaScript assets",
async (runbookId) => {
const record = await runRunbookDrill(runbookId, {
releaseRoot: await builtDist({ withoutJs: true }),
contractPackages,
});
expect(record.result).toBe("FAIL");
},
);
it("FE-RB-005 fails without a build instead of reading public/ placeholders", async () => {
await expect(
runRunbookDrill("FE-RB-005", { releaseRoot: await builtDist({ withoutDist: true }), contractPackages }),
).rejects.toThrow(/dist\/release-manifest\.json/u);
});
it("keeps no constant recovery verdict in the drill source", async () => {
const source = await readFile("scripts/drill-runbook.ts", "utf8");
expect(source).not.toMatch(/assertion\([^;]*,\s*true\s*\)/u);
expect(source).not.toMatch(/Asserted:\s*true\b/u);
expect(source).not.toMatch(/injectedMountFailure\s*=\s*true/u);
});
});