import { readFile } from "node:fs/promises"; import { describe, expect, it } from "vitest"; import { loadCiGateContract } from "../../scripts/contracts/ci-gates.ts"; import { SCAFFOLD_DRILL_EXCLUDED_SCRIPTS, scaffoldDrillCommands, } from "../../scripts/lib/feature-scaffold-drill.ts"; // 1103/12-02. The scaffold drill claimed "every merge gate" and ran 15 // hand-picked commands of the 88 in the merge stage. describe("feature scaffold drill commands", () => { it("are the merge stage minus the named exclusions, each command once", async () => { const contract = await loadCiGateContract(process.cwd()); const merge = contract.stages.find(({ id }) => id === "merge")!; const mergeCommandIds = new Set( merge.gateIds.flatMap((gateId) => contract.gates.find(({ id }) => id === gateId)!.commandIds), ); const commands = scaffoldDrillCommands(contract); const runCommandIds = commands.map(({ name }) => name.split(":").slice(1).join(":")); expect(new Set(runCommandIds).size).toBe(runCommandIds.length); for (const commandId of mergeCommandIds) { const command = contract.commands.find(({ id }) => id === commandId)!; expect( runCommandIds.includes(commandId) || Object.hasOwn(SCAFFOLD_DRILL_EXCLUDED_SCRIPTS, command.script), commandId, ).toBe(true); } expect(commands.map(({ script }) => script)).toEqual(expect.arrayContaining([ "check:types", "lint", "test:unit", "test:coverage", "build", "check:bundle", "test:contract", "test:runtime-schema", "check:request-fanout", "build:release-candidate", ])); for (const reason of Object.values(SCAFFOLD_DRILL_EXCLUDED_SCRIPTS)) { expect(reason.length).toBeGreaterThan(10); } }); // The checkers' negative fixtures moved to the main stage (FE-GATE-029) on // 2026-11-08, so the merge stage has none; a probe stands in for one. it("keeps a negative fixture's registered exit and diagnostic", async () => { const contract = structuredClone(await loadCiGateContract(process.cwd())); contract.commands.push({ id: "check-probe-fixture", script: "check:probe:fixture", expect: "fail", expectedExitCode: 1, expectedDiagnosticId: "probe failed:", } as never); contract.gates.find(({ id }) => id === "FE-GATE-010")!.commandIds.push("check-probe-fixture"); expect(scaffoldDrillCommands(contract).find(({ script }) => script === "check:probe:fixture")) .toMatchObject({ expectation: { kind: "fail", expectedExitCode: 1, expectedDiagnosticId: "probe failed:" } }); }); it("runs a command added to the merge stage without an edit to the drill", async () => { const contract = structuredClone(await loadCiGateContract(process.cwd())); contract.commands.push({ id: "check-probe", script: "check:probe", expect: "pass" } as never); contract.gates.find(({ id }) => id === "FE-GATE-010")!.commandIds.push("check-probe"); expect(scaffoldDrillCommands(contract).map(({ name }) => name)).toContain("FE-GATE-010:check-probe"); }); it("refuses an exclusion for a command the contract runs outside the merge stage", async () => { const contract = await loadCiGateContract(process.cwd()); const merge = new Set(contract.stages.find(({ id }) => id === "merge")!.gateIds); const mergeCommandIds = new Set( contract.gates.filter(({ id }) => merge.has(id)).flatMap(({ commandIds }) => commandIds), ); const mergeScripts = new Set( contract.commands.filter(({ id }) => mergeCommandIds.has(id)).map(({ script }) => script), ); const outside = contract.commands.find(({ script }) => !mergeScripts.has(script))!; expect(() => scaffoldDrillCommands(contract, { ...SCAFFOLD_DRILL_EXCLUDED_SCRIPTS, [outside.script]: "not in the merge stage", })).toThrow(`outside the merge stage: ${outside.script}`); }); // A removal drill prunes its capability's commands from the contract, and // this file runs inside that fixture too. it("accepts an exclusion whose command the contract no longer has", async () => { const contract = structuredClone(await loadCiGateContract(process.cwd())); const removed = contract.commands.find(({ script }) => Object.hasOwn(SCAFFOLD_DRILL_EXCLUDED_SCRIPTS, script) )!; contract.commands = contract.commands.filter(({ id }) => id !== removed.id); for (const gate of contract.gates) { gate.commandIds = gate.commandIds.filter((id) => id !== removed.id); } expect(() => scaffoldDrillCommands(contract)).not.toThrow(); }); it("is what test:feature-scaffold runs", async () => { const drill = await readFile("scripts/test-feature-scaffold.ts", "utf8"); expect(drill).toContain("scaffoldDrillCommands("); expect(drill).toContain("loadCiGateContract(fixtureRoot)"); }); });