fix(ci): run every gate a non-matrix job owns and refuse profile/target mismatch (12-02, 13-01)

The generator rendered only gateIds[0] for non-matrix jobs, so
immutable_build never ran FE-GATE-027 and the snapshot test pinned that.
Each owned gate now gets its own run step, check:ci rejects a workflow in
which any contract gate has no run step, and release admission refuses
APP_PROFILE != RELEASE_TARGET. Both variables are documented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-25 21:36:27 +09:00
co-authored by Claude Opus 5.5
parent 0114b1e58b
commit 239b22ae1a
8 changed files with 134 additions and 6 deletions
+2
View File
@@ -142,6 +142,8 @@ jobs:
corepack pnpm install --frozen-lockfile --ignore-scripts
- name: Build candidate once and verify local evidence
run: corepack pnpm ci:gate -- FE-GATE-015
- name: Admit the candidate to the declared release target
run: corepack pnpm ci:gate -- FE-GATE-027
- name: Archive and validate the exact candidate file set
id: candidate
run: |
+9
View File
@@ -329,6 +329,15 @@ Repository variables required by higher tiers:
`ubuntu-latest` runner label; the workflow exposes it to gates as
`CI_RUNNER_IMAGE` (required by every tier)
- `HOSTING_BASE_URL` for live header verification
- `APP_PROFILE` for the runtime profile the release candidate is built from
(`local`, `development`, `staging`, `production`;
`scripts/generate-runtime-config.ts`). An unset value builds `local`; an empty
value fails the build.
- `RELEASE_TARGET` for the environment FE-GATE-027 admits the candidate to
(`scripts/check-release-admission.ts`). It has no default. The immutable_build
job runs FE-GATE-015 and then FE-GATE-027, and FE-GATE-027 refuses the
candidate when `APP_PROFILE` is set and differs from `RELEASE_TARGET`. Both are
repository-wide variables, so set them together for each release.
- `FIELD_WEB_VITALS_INPUT` for the privacy-approved field sample document
- `MIN_ELIGIBLE_SAMPLES` after the baseline decision
- `VULNERABILITY_PROVIDER_COMMAND` and `PROVENANCE_PROVIDER_COMMAND` for the
+6 -1
View File
@@ -10,7 +10,11 @@ import {
loadCiGateContract,
indexCiGateContract,
} from "./contracts/ci-gates.ts";
import { generateCiWorkflow, renderCiWorkflow } from "./generate-ci-workflow.ts";
import {
generateCiWorkflow,
renderCiWorkflow,
workflowGateExecutionFailures,
} from "./generate-ci-workflow.ts";
import {
ciContractReportSchema,
} from "./lib/ci-contract-report.ts";
@@ -113,6 +117,7 @@ try {
} catch (error) {
failures.push(`generated workflow is unreadable: ${error instanceof Error ? error.message : String(error)}`);
}
failures.push(...workflowGateExecutionFailures(contract, checkedWorkflowBytes.toString("utf8")));
const report = ciContractReportSchema.parse({
schemaVersion: 2,
nodeVersion,
+11
View File
@@ -40,6 +40,17 @@ async function main(): Promise<void> {
process.exitCode = 1;
return;
}
// 13-01: the build profile and the admission target are separate repository
// variables; a profile left on staging must not ship to production.
const profile = process.env["APP_PROFILE"];
if (profile !== undefined && profile !== declared) {
process.stderr.write(
`release admission refused: the artifact was built with APP_PROFILE=${profile} ` +
`but RELEASE_TARGET=${declared}. Set both to the same environment.\n`,
);
process.exitCode = 1;
return;
}
let document: unknown;
try {
+42 -4
View File
@@ -196,10 +196,16 @@ function renderStep(
" run: corepack pnpm exec playwright install --with-deps chromium firefox webkit",
];
case "run-gate": {
const gateId = job.kind === "gate-matrix" ? "${{ matrix.gate }}" : job.gateIds[0];
if (!gateId) throw new TypeError(`run-gate step lacks ownership: ${job.id}`);
const name = job.id === "documentation_gate" ? "Run documentation gate" : job.id === "immutable_build" ? "Build candidate once and verify local evidence" : "Run blocking gate";
return [` - name: ${name}`, ` run: corepack pnpm ci:gate -- ${gateId}`];
if (job.kind === "gate-matrix") {
return [" - name: Run blocking gate", " run: corepack pnpm ci:gate -- ${{ matrix.gate }}"];
}
if (job.gateIds.length === 0) throw new TypeError(`run-gate step lacks ownership: ${job.id}`);
// 12-02: every gate the job owns runs, in order. Rendering only the first
// left FE-GATE-027 (release admission) out of the workflow.
return job.gateIds.flatMap((gateId) => [
` - name: ${runGateStepName(job.id, gateId)}`,
` run: corepack pnpm ci:gate -- ${gateId}`,
]);
}
case "archive-candidate": {
const archive = shellDoubleQuoted(step.archivePath);
@@ -346,6 +352,38 @@ function shellDoubleQuoted(value: string): string {
return `"${escaped}"`;
}
function runGateStepName(jobId: string, gateId: string): string {
if (gateId === "FE-GATE-015") return "Build candidate once and verify local evidence";
if (gateId === "FE-GATE-027") return "Admit the candidate to the declared release target";
return jobId === "documentation_gate" ? "Run documentation gate" : "Run blocking gate";
}
/**
* 12-02 / D-12. Every contract gate must be executed by the workflow text: a
* literal `ci:gate -- <id>` run line, or a matrix entry of a job whose run step
* is `ci:gate -- ${{ matrix.gate }}`. Owning a gate in the contract is not
* enough; the generator once dropped all but the first.
*/
export function workflowGateExecutionFailures(
contract: CiGateContract,
workflow: string,
): string[] {
const executed = new Set<string>();
for (const job of workflow.split(/^(?= {2}[a-z_]+:$)/mu)) {
for (const match of job.matchAll(/^ +run: corepack pnpm ci:gate -- (FE-GATE-\d{3})$/gmu)) {
executed.add(match[1]!);
}
if (/^ +run: corepack pnpm ci:gate -- \$\{\{ matrix\.gate \}\}$/mu.test(job)) {
for (const match of job.matchAll(/^ +- \{ gate: (FE-GATE-\d{3}),/gmu)) {
executed.add(match[1]!);
}
}
}
return contract.gates
.filter(({ id }) => !executed.has(id))
.map(({ id }) => `gate is not executed by any workflow run step: ${id}`);
}
function humanize(value: string): string {
return value.replaceAll("-", " ");
}
@@ -145,6 +145,8 @@ jobs:
corepack pnpm install --frozen-lockfile --ignore-scripts
- name: Build candidate once and verify local evidence
run: corepack pnpm ci:gate -- FE-GATE-015
- name: Admit the candidate to the declared release target
run: corepack pnpm ci:gate -- FE-GATE-027
- name: Archive and validate the exact candidate file set
id: candidate
run: |
+28
View File
@@ -20,6 +20,7 @@ import {
createCiWorkflowGenerator,
generateCiWorkflow,
renderCiWorkflow,
workflowGateExecutionFailures,
type CiWorkflowFileSystem,
} from "../../scripts/generate-ci-workflow.ts";
import {
@@ -1411,6 +1412,33 @@ describe("CI workflow generation", () => {
expect(actionUses.every((uses) => /^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+@[0-9a-f]{40}$/u.test(uses!))).toBe(true);
});
// 12-02 / 13-01: immutable_build owns FE-GATE-015 and FE-GATE-027, but only
// the first gate of a non-matrix job was ever rendered, so release admission
// never ran in CI.
it("runs every gate a job owns, in order", async () => {
const contract = await loadCiGateContract(process.cwd());
const workflow = renderCiWorkflow(contract);
const immutable = workflow.slice(
workflow.indexOf(" immutable_build:\n"),
workflow.indexOf(" vulnerability_provider:\n"),
);
expect([...immutable.matchAll(/ci:gate -- (FE-GATE-\d{3})$/gmu)].map((match) => match[1]))
.toEqual(["FE-GATE-015", "FE-GATE-027"]);
expect(workflowGateExecutionFailures(contract, workflow)).toEqual([]);
});
it.each([
["a non-matrix gate step", " run: corepack pnpm ci:gate -- FE-GATE-027\n", "FE-GATE-027"],
["a matrix entry", " - { gate: FE-GATE-020, name: removability, browser: false }\n", "FE-GATE-020"],
])("rejects a workflow that drops %s", async (_name, line, gateId) => {
const contract = await loadCiGateContract(process.cwd());
const workflow = renderCiWorkflow(contract);
expect(workflow).toContain(line);
expect(workflowGateExecutionFailures(contract, workflow.replace(line, ""))).toEqual([
`gate is not executed by any workflow run step: ${gateId}`,
]);
});
it("derives download artifact names from the typed upload producer", async () => {
const contract = await loadCiGateContract(process.cwd());
const candidate = JSON.parse(JSON.stringify(contract)) as Record<string, any>;
+34 -1
View File
@@ -1,4 +1,6 @@
import { readFile, readdir } from "node:fs/promises";
import { spawnSync } from "node:child_process";
import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
@@ -201,4 +203,35 @@ describe("runtime config profiles", () => {
.length,
).toBeGreaterThan(0);
});
// 13-01: the build profile and the admission target are two repository
// variables. A staging profile left in place for a production release has to
// stop the release, whatever the built document happens to say.
it.each([
["staging", 1],
["production", 0],
] as const)("admits a production artifact under APP_PROFILE=%s only when it names the target", async (profile, status) => {
const root = await mkdtemp(path.join(tmpdir(), "release-admission-profile-"));
try {
const config = await generateRuntimeConfig("production", {
VITE_BUILD_ID: "20260815.42",
RELEASE_ID: "r-2026.08.15-1",
});
await mkdir(path.join(root, "dist"), { recursive: true });
await writeFile(path.join(root, "dist/config.json"), JSON.stringify(config));
const result = spawnSync(
process.execPath,
[path.resolve("scripts/check-release-admission.ts")],
{
cwd: root,
encoding: "utf8",
env: { ...process.env, APP_PROFILE: profile, RELEASE_TARGET: "production" },
},
);
expect(result.status, result.stderr).toBe(status);
if (status === 1) expect(result.stderr).toMatch(/APP_PROFILE=staging/u);
} finally {
await rm(root, { recursive: true, force: true });
}
});
});