diff --git a/scripts/test-feature-scaffold.ts b/scripts/test-feature-scaffold.ts index 59df1162..92f4a267 100644 --- a/scripts/test-feature-scaffold.ts +++ b/scripts/test-feature-scaffold.ts @@ -1,3 +1,4 @@ +import { spawnSync } from "node:child_process"; import { mkdir, rm, writeFile } from "node:fs/promises"; import { loadCiGateContract } from "./contracts/ci-gates.ts"; @@ -39,6 +40,12 @@ const REPORT = "artifacts/tests/feature-scaffold.xml"; const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath"); const fixtureRoot = await createRemovalFixtureRoot("feature-scaffold"); +function fixtureCommit(root: string): string { + const head = spawnSync("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8" }); + if (head.status !== 0) throw new Error(`feature scaffold fixture has no commit: ${head.stderr}`); + return head.stdout.trim(); +} + function check(name: string, script: string, extra: readonly string[] = []): RemovalCheck { return runRemovalFixtureCheck(name, fixtureRoot, pnpmCli, script, extra); } @@ -55,6 +62,12 @@ try { // Commits the copy with the feature, as a project would: git-based // checks (git grep, git ls-files) then see the feature's files. sealRemovalFixtureRepository(fixtureRoot); + // build:release-candidate records the build's commit and refuses one that + // is not a commit ID. CI sets VITE_COMMIT_SHA for the whole workflow; a + // local run gets the copy's own sealed commit instead of "local". + if (!process.env["VITE_COMMIT_SHA"]?.trim()) { + process.env["VITE_COMMIT_SHA"] = fixtureCommit(fixtureRoot); + } for (const command of scaffoldDrillCommands(await loadCiGateContract(fixtureRoot))) { checks.push(runScaffoldDrillCommand(command, fixtureRoot, pnpmCli)); }