Files
clean-architecture-frontend…/scripts/update-ci-contract-baseline.ts
DongHyeonkaandClaude Opus 5.5 0114b1e58b fix(ci): move CI contract counts and gate hash to an owned baseline file (14-02)
Gate/command/artifact counts and the gate-shape SHA-256 were code
constants, so any real removal or addition failed check:ci and removal
fixtures passed only in a relaxed mode. They now live in
config/ci/contract-baseline.json (owner, reason) with
update:ci-contract-baseline; update:registry-baseline wraps the existing
registry script. Removal fixtures re-baseline and run canonical check:ci
and check:registries; CI_CONTRACT_MODE, --reduced-removal-fixture and
check:registries:structure are gone. ci-quality-gates.md lists the
baselines a new project resets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 21:34:12 +09:00

53 lines
1.8 KiB
TypeScript

import { readFile, writeFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import {
CI_CONTRACT_BASELINE_PATH,
measureCiContractBaseline,
parseCiGateContract,
type CiContractBaseline,
} from "./contracts/ci-gates.ts";
/**
* D-13. Records the current `config/ci/gates.json` size and gate shape as the
* reviewed baseline. Run it after an intended contract change; the diff of
* `config/ci/contract-baseline.json` is what review approves.
*/
export async function updateCiContractBaseline(
root: string,
approval: Readonly<{ owner: string; reason: string }>,
): Promise<CiContractBaseline> {
const contract = parseCiGateContract(
JSON.parse(await readFile(path.join(root, "config/ci/gates.json"), "utf8")),
);
const baseline: CiContractBaseline = {
schemaVersion: 1,
owner: approval.owner,
reason: approval.reason,
...measureCiContractBaseline(contract),
};
await writeFile(
path.join(root, CI_CONTRACT_BASELINE_PATH),
`${JSON.stringify(baseline, null, 2)}\n`,
);
return baseline;
}
const isCli = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
if (isCli) {
const owner = process.env.CI_CONTRACT_BASELINE_OWNER;
const reason = process.env.CI_CONTRACT_BASELINE_REASON;
if (!owner || !reason) {
process.stderr.write(
"CI_CONTRACT_BASELINE_OWNER and CI_CONTRACT_BASELINE_REASON are required.\n",
);
process.exit(1);
}
const baseline = await updateCiContractBaseline(process.cwd(), { owner, reason });
process.stdout.write(
`CI contract baseline updated: ${baseline.gates} gates, ${baseline.commands} commands, ` +
`${baseline.commandReferences} command references, ${baseline.artifacts} artifacts\n`,
);
}