This reverts commit411c9338c6. 문제: #55(b4895894)가 main run 376의 FE-GATE-030(browser file/storage 제거 드릴)을 깨서 411c9338(#64)로 통째로 되돌렸다. #55의 검사기 진단과 시험 빈틈 고침 12커밋이 main에 없다. 고른 방법: 되돌림을 되돌려 #55를 그대로 다시 넣고, 드릴을 깬 원인은 다음 커밋에서 따로 고친다. 리뷰어가 이 커밋이 #55와 같은지 트리로 볼 수 있다. 이 커밋의 트리는b4895894트리에 그 뒤 main에 들어온 #63·#65만 더한 것이다(git diffb4895894<이 커밋>: docs/ledger 두 파일, cross-context-invalidation adapter 한 파일과 시험 두 파일). 버린 대안: #55 커밋 12개 cherry-pick.71606ff1merge의 충돌 해소분을 다시 풀어야 하고 결과 트리를 b4895894와 대조하기 어렵다. 위험·한계: 이 커밋만으로는 main 단계의 FE-GATE-030이 run 376처럼 실패한다(같은 트리 내용). PR 단계 게이트는 돈다. 검증: 다음 커밋 본문에 적는다. 그 커밋의 새 단언을 이 커밋의 검사기에 돌리면 실패한다(RED). Refs: #55, #64
252 lines
11 KiB
TypeScript
252 lines
11 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 { runbookRecordArtifactSchema } from "../../scripts/contracts/release-artifacts.ts";
|
|
import { PROVIDER_EVIDENCE_MAX_AGE_MS, 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);
|
|
});
|
|
|
|
// A drill's recovery assertions are the runbook's recoveryEvidence items, named
|
|
// as config/runbooks/runbooks.json names them and in its order, so the record
|
|
// and the UNVERIFIED line name the same checks the runbook lists.
|
|
it.each(RUNBOOK_IDS)("%s names its recovery assertions after the runbook's recoveryEvidence", async (runbookId) => {
|
|
const document = JSON.parse(await readFile("config/runbooks/runbooks.json", "utf8")) as {
|
|
runbooks: Record<string, { recoveryEvidence: string[] }>;
|
|
};
|
|
const record = await runRunbookDrill(runbookId, { releaseRoot: await builtDist(), contractPackages });
|
|
expect(record.recoveryAssertions.map(({ assertion }) => assertion)).toEqual(
|
|
document.runbooks[runbookId]?.recoveryEvidence,
|
|
);
|
|
});
|
|
|
|
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);
|
|
// 0929/11-08. The drill records string verdicts now; the patterns above
|
|
// only knew the old boolean shape, so a constant "PASS" went unnoticed.
|
|
expect(source).not.toMatch(/assertion\([^;]*,\s*["']PASS["']\s*,?\s*\)/u);
|
|
expect(source).not.toMatch(/(?:Asserted|AsExpected):\s*["']PASS["']/u);
|
|
expect(source).not.toMatch(/verdict\(\s*true\s*\)/u);
|
|
});
|
|
});
|
|
|
|
// 0929/11-02. The drills with provider scope took only a runbook ID and a
|
|
// release root, so no input could ever make them PASS and the production
|
|
// stage could not close. Provider evidence now answers the items the local
|
|
// drill cannot observe, for this runbook and release only, and while recent.
|
|
describe("runbook drill with provider evidence (0929/11-02)", () => {
|
|
const NOW = new Date("2026-11-13T09:00:00.000Z");
|
|
const evidence = (overrides: Record<string, unknown> = {}) => ({
|
|
schemaVersion: 1,
|
|
artifactType: "provider-drill-evidence",
|
|
runbookId: "FE-RB-005",
|
|
releaseId: "release-a",
|
|
observedAt: "2026-11-13T08:30:00.000Z",
|
|
runId: "provider-run-41",
|
|
observations: [
|
|
{ item: "trigger", result: "PASS", evidence: "incident INC-7 declared the release-blocking defect" },
|
|
{ item: "핵심 smoke 시험", result: "PASS", evidence: "smoke against the prior release after the switch" },
|
|
{ item: "provider verification", result: "PASS", evidence: "provider serves release-a again" },
|
|
],
|
|
...overrides,
|
|
});
|
|
const drill = async (providerEvidence: unknown) =>
|
|
runRunbookDrill("FE-RB-005", { releaseRoot: await builtDist(), contractPackages, providerEvidence, now: NOW });
|
|
|
|
it("passes FE-RB-005 when the provider observed every item the local drill could not", async () => {
|
|
const record = await drill(evidence());
|
|
|
|
expect(record.result).toBe("PASS");
|
|
expect(record.triggerAsserted).toBe("PASS");
|
|
expect(record.recoveryAssertions.find(({ assertion }) => assertion === "핵심 smoke 시험")).toEqual({
|
|
assertion: "핵심 smoke 시험",
|
|
evidence: "provider evidence provider-run-41 at 2026-11-13T08:30:00.000Z: smoke against the prior release after the switch",
|
|
result: "PASS",
|
|
});
|
|
expect(record.providerEvidence).toEqual({
|
|
accepted: true,
|
|
runId: "provider-run-41",
|
|
observedAt: "2026-11-13T08:30:00.000Z",
|
|
providerVerification: "PASS",
|
|
});
|
|
const { gateId: _gateId, ...artifact } = record;
|
|
expect(runbookRecordArtifactSchema.safeParse(artifact).success).toBe(true);
|
|
});
|
|
|
|
it("fails when the provider observed a failure", async () => {
|
|
const observations = evidence().observations.map((entry) =>
|
|
entry.item === "핵심 smoke 시험" ? { ...entry, result: "FAIL" } : entry);
|
|
expect((await drill(evidence({ observations }))).result).toBe("FAIL");
|
|
});
|
|
|
|
it("stays UNVERIFIED while an item the local drill could not observe has no answer", async () => {
|
|
const record = await drill(evidence({ observations: evidence().observations.slice(0, 2) }));
|
|
expect(record.result).toBe("UNVERIFIED");
|
|
expect(record.providerEvidence?.providerVerification).toBe("UNVERIFIED");
|
|
});
|
|
|
|
it.each([
|
|
["another release", { releaseId: "release-b" }, "evidence is for release release-b, not release-a"],
|
|
["another runbook", { runbookId: "FE-RB-002" }, "evidence is for FE-RB-002, not FE-RB-005"],
|
|
[
|
|
"an expired observation",
|
|
{ observedAt: new Date(NOW.getTime() - PROVIDER_EVIDENCE_MAX_AGE_MS - 1_000).toISOString() },
|
|
"is older than 7 days",
|
|
],
|
|
["a future observation", { observedAt: "2026-11-13T10:00:00.000Z" }, "is in the future"],
|
|
[
|
|
"an answer for a check the local drill made",
|
|
{ observations: [...evidence().observations, { item: "호환성 gate", result: "PASS", evidence: "x" }] },
|
|
"evidence names items the local drill observed or does not have: 호환성 gate",
|
|
],
|
|
["a record that is not provider evidence", { artifactType: "runbook-record" }, "not provider drill evidence"],
|
|
])("does not pass on evidence for %s", async (_case, overrides, reason) => {
|
|
const record = await drill(evidence(overrides));
|
|
|
|
expect(record.result).toBe("UNVERIFIED");
|
|
expect(record.triggerAsserted).toBe("UNVERIFIED");
|
|
expect(record.providerEvidence?.accepted).toBe(false);
|
|
expect(record.providerEvidence?.reason).toContain(reason);
|
|
const { gateId: _gateId, ...artifact } = record;
|
|
expect(runbookRecordArtifactSchema.safeParse(artifact).success).toBe(true);
|
|
});
|
|
|
|
it("rejects a record that claims PASS without accepted provider evidence", () => {
|
|
const record = {
|
|
schemaVersion: 2,
|
|
runbookId: "FE-RB-005",
|
|
releaseId: "release-a",
|
|
drillTimestamp: NOW.toISOString(),
|
|
triggerInjected: "RELEASE_BLOCKING_DEFECT",
|
|
triggerAsserted: "PASS",
|
|
containmentAsserted: "PASS",
|
|
escalationPathAsserted: "PASS",
|
|
recoveryAssertions: [],
|
|
negativeFixtureFailedAsExpected: "PASS",
|
|
windowObservedBucket: "TBD",
|
|
providerVerificationRequired: true,
|
|
providerEvidence: { accepted: false, reason: "expired", providerVerification: "UNVERIFIED" },
|
|
result: "PASS",
|
|
};
|
|
expect(runbookRecordArtifactSchema.safeParse(record).success).toBe(false);
|
|
expect(runbookRecordArtifactSchema.safeParse({ ...record, result: "UNVERIFIED" }).success).toBe(true);
|
|
});
|
|
});
|