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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
991da882e2
commit
0114b1e58b
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"owner": "frontend-platform",
|
||||
"reason": "Template contract as of the 2026-09-25 maturity review (D-13): counts and gate shape moved out of scripts/contracts/ci-gates.ts",
|
||||
"gates": 27,
|
||||
"commands": 91,
|
||||
"commandReferences": 103,
|
||||
"artifacts": 109,
|
||||
"stages": 5,
|
||||
"gateShapeSha256": "43dc4ed1cdaf21a674bd069d42eb2c32276afd8f763d72e52c9f7c3adccbeb58"
|
||||
}
|
||||
@@ -10,6 +10,39 @@ checking, the typed contract checker, and this workflow drift check. The Gitea
|
||||
adapter runs each gate as an independent matrix check with full fan-out and no
|
||||
soft-fail wiring.
|
||||
|
||||
## 기준선 갱신과 새 프로젝트 시작 시 초기화할 기준선
|
||||
|
||||
게이트 계약의 크기와 모양은 코드 상수가 아니라 `config/ci/contract-baseline.json`에
|
||||
있다. 이 파일에는 게이트 수, 명령 정의 수, 명령 참조 수, 산출물 수, stage 수,
|
||||
게이트 모양 SHA-256과 함께 `owner`·`reason`이 들어 있다. 계약을 불러올 때 현재
|
||||
`gates.json`과 이 파일이 다르면 실패한다(`scripts/contracts/ci-gates.ts`의
|
||||
`assertCiContractBaseline`). 그래서 게이트·명령·산출물을 추가하거나 지운 뒤에는
|
||||
다음 순서로 커밋한다.
|
||||
|
||||
```
|
||||
# 1. config/ci/gates.json 수정
|
||||
CI_CONTRACT_BASELINE_OWNER=<팀> CI_CONTRACT_BASELINE_REASON=<이유> corepack pnpm update:ci-contract-baseline
|
||||
corepack pnpm generate:ci-workflow
|
||||
corepack pnpm check:ci
|
||||
```
|
||||
|
||||
`update:ci-contract-baseline`은 `scripts/update-ci-contract-baseline.ts`를 실행한다.
|
||||
리뷰는 `contract-baseline.json`의 diff로 변경을 승인한다. 샘플·recipe·런타임 제거
|
||||
검증(`test:*-removal`)도 같은 절차를 쓴다. 줄인 계약을 기준선으로 기록한 뒤
|
||||
canonical `check:ci`를 돌린다(`scripts/lib/removal-fixture.ts`의
|
||||
`pruneRemovalFixtureCiContract`). 완화 모드는 없다.
|
||||
|
||||
템플릿을 복사해 새 프로젝트를 시작하면 아래 기준선은 템플릿의 값이다. 샘플을
|
||||
지우거나 구조를 바꾸면 프로젝트 값으로 다시 찍는다.
|
||||
|
||||
| 기준선 | 파일 | 갱신 방법 | 검사 위치 |
|
||||
|---|---|---|---|
|
||||
| CI 계약 크기·게이트 모양 | `config/ci/contract-baseline.json` | `update:ci-contract-baseline` (`CI_CONTRACT_BASELINE_OWNER`·`_REASON` 필수) | `scripts/contracts/ci-gates.ts` `assertCiContractBaseline` |
|
||||
| registry 스냅샷과 승인 | `config/contracts/registry-baseline.json`, `registry-baseline.approval.json` | `update:registry-baseline` (`REGISTRY_BASELINE_OWNER`·`_REASON` 필수). 기준선을 새로 찍지 않고 breaking 변경을 유지하려면 `config/contracts/registry-change-evidence.json`에 항목을 추가 | `scripts/check-registries.ts`의 baseline 비교 |
|
||||
| 커버리지 모듈 수 하한 | `config/testing/risk-coverage.json`의 `repositoryBaseline` | 직접 수정. 지운 production 모듈 수만큼 줄인다(`scripts/test-sample-removal.ts`가 같은 계산을 한다) | `scripts/lib/risk-coverage.ts` "repository module baseline" |
|
||||
| 기능 끄기 설정 | `config/runtime/<profile>.json`의 `FEATURE_OVERRIDES` | 직접 수정. 지운 기능의 키를 뺀다(`scripts/test-sample-removal.ts`가 같은 일을 한다) | 없음. 남은 키는 조용히 무시된다(리뷰 09-09) |
|
||||
| 의존성 목록 | `config/security/dependency-baseline.json`, `dependency-baseline.approval.json` | `update:dependency-baseline` (`DEPENDENCY_BASELINE_OWNER`·`_REASON` 필수) | `scripts/generate-supply-chain.ts` |
|
||||
|
||||
Contract loading validates every registered command entry against the
|
||||
authoritative root package-script graph and lifecycle/install policy before the
|
||||
runner enters its execution callback. Foreign cwd/workspace script dispatch,
|
||||
|
||||
+2
-1
@@ -103,7 +103,7 @@
|
||||
"check:optional-recipes:source": "node scripts/generate-product-feature-index.ts && node scripts/check-optional-recipes.ts",
|
||||
"check:optional-recipe-fixtures": "node scripts/generate-product-feature-index.ts && node scripts/check-optional-recipe-fixtures.ts",
|
||||
"check:registries": "node scripts/generate-product-feature-index.ts && node scripts/check-registries.ts",
|
||||
"check:registries:structure": "node scripts/generate-product-feature-index.ts && node scripts/check-registries.ts --no-baseline",
|
||||
"update:registry-baseline": "node scripts/generate-product-feature-index.ts && node scripts/check-registries.ts --no-baseline --artifact artifacts/quality/registry-current-snapshot.json && node scripts/update-registry-baseline.ts",
|
||||
"check:registries:compatibility-fixtures": "node scripts/generate-product-feature-index.ts && node scripts/check-registry-compatibility-fixtures.ts",
|
||||
"check:registries:baseline-fixture": "node scripts/generate-product-feature-index.ts && node scripts/check-registries.ts --approval tests/fixtures/registry/compatibility/tampered-approval.json --artifact artifacts/quality/registry-baseline-fixture.json",
|
||||
"check:registries:fixture": "node scripts/generate-product-feature-index.ts && node scripts/check-registries.ts --governance tests/fixtures/registry/forbidden/governance.json --artifact artifacts/quality/registry-fixture.json",
|
||||
@@ -120,6 +120,7 @@
|
||||
"generate:ci-workflow": "node scripts/generate-ci-workflow.ts",
|
||||
"check:ci-workflow": "node scripts/generate-ci-workflow.ts --check",
|
||||
"check:ci": "corepack pnpm check:artifact-schemas && node scripts/check-ci-contract.ts && corepack pnpm check:ci-workflow",
|
||||
"update:ci-contract-baseline": "node scripts/update-ci-contract-baseline.ts",
|
||||
"verify:documentation": "node scripts/generate-product-feature-index.ts && node scripts/verify-documentation-readiness.ts",
|
||||
"build:app-only": "node scripts/generate-product-feature-index.ts && vite build && node scripts/generate-build-manifest.ts",
|
||||
"generate:contract-set": "node scripts/generate-product-feature-index.ts && node scripts/generate-contract-set.ts",
|
||||
|
||||
@@ -20,10 +20,7 @@ import {
|
||||
} from "./lib/package-script-graph.ts";
|
||||
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
||||
|
||||
const removalFixtureMode = process.argv.includes("--reduced-removal-fixture");
|
||||
const contract = await loadCiGateContract(process.cwd(), {
|
||||
mode: removalFixtureMode ? "removal-fixture" : "canonical",
|
||||
});
|
||||
const contract = await loadCiGateContract(process.cwd());
|
||||
const index = indexCiGateContract(contract);
|
||||
const [packageDocument, nodeVersion] = await Promise.all([
|
||||
readFile("package.json", "utf8").then((value) => JSON.parse(value) as { scripts?: Record<string, string> }),
|
||||
|
||||
@@ -438,12 +438,29 @@ export type CiGateContractIndex = Readonly<{
|
||||
jobs: ReadonlyMap<string, CiWorkflowJob>;
|
||||
retentionClasses: ReadonlyMap<string, CiGateContract["retention"]["classes"][number]>;
|
||||
}>;
|
||||
export type LoadCiGateContractOptions = Readonly<{
|
||||
mode?: "canonical" | "removal-fixture";
|
||||
}>;
|
||||
/**
|
||||
* D-13. The contract's size and gate shape are a reviewed baseline, not code
|
||||
* constants: a project that removes a sample or adds a gate records the new
|
||||
* shape with `update:ci-contract-baseline` (owner and reason required) and the
|
||||
* diff of this file is what review sees.
|
||||
*/
|
||||
export const CI_CONTRACT_BASELINE_PATH = "config/ci/contract-baseline.json";
|
||||
|
||||
const CANONICAL_GATE_SHAPE_SHA256 =
|
||||
"43dc4ed1cdaf21a674bd069d42eb2c32276afd8f763d72e52c9f7c3adccbeb58";
|
||||
const ciContractBaselineSchema = z
|
||||
.object({
|
||||
schemaVersion: z.literal(1),
|
||||
owner: nonEmpty,
|
||||
reason: nonEmpty,
|
||||
gates: z.number().int().nonnegative(),
|
||||
commands: z.number().int().nonnegative(),
|
||||
commandReferences: z.number().int().nonnegative(),
|
||||
artifacts: z.number().int().nonnegative(),
|
||||
stages: z.number().int().nonnegative(),
|
||||
gateShapeSha256: z.string().regex(/^[0-9a-f]{64}$/u),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export type CiContractBaseline = z.infer<typeof ciContractBaselineSchema>;
|
||||
|
||||
function canonicalGateShapeSha256(gates: CiGateContract["gates"]): string {
|
||||
const normalized = gates.map(
|
||||
@@ -468,26 +485,52 @@ function canonicalGateShapeSha256(gates: CiGateContract["gates"]): string {
|
||||
return createHash("sha256").update(JSON.stringify(normalized)).digest("hex");
|
||||
}
|
||||
|
||||
function canonicalAuthorityBaselineFailures(contract: CiGateContract): string[] {
|
||||
const failures: string[] = [];
|
||||
const commandReferenceCount = contract.gates.reduce(
|
||||
(total, gate) => total + gate.commandIds.length,
|
||||
0,
|
||||
export function measureCiContractBaseline(
|
||||
contract: CiGateContract,
|
||||
): Omit<CiContractBaseline, "schemaVersion" | "owner" | "reason"> {
|
||||
return {
|
||||
gates: contract.gates.length,
|
||||
commands: contract.commands.length,
|
||||
commandReferences: contract.gates.reduce(
|
||||
(total, gate) => total + gate.commandIds.length,
|
||||
0,
|
||||
),
|
||||
artifacts: contract.artifacts.length,
|
||||
stages: contract.stages.length,
|
||||
gateShapeSha256: canonicalGateShapeSha256(contract.gates),
|
||||
};
|
||||
}
|
||||
|
||||
async function assertCiContractBaseline(
|
||||
root: string,
|
||||
contract: CiGateContract,
|
||||
): Promise<void> {
|
||||
const parsed = ciContractBaselineSchema.safeParse(
|
||||
JSON.parse(await readFile(path.join(root, CI_CONTRACT_BASELINE_PATH), "utf8")),
|
||||
);
|
||||
if (contract.gates.length !== 27) {
|
||||
failures.push(`gate authority baseline must contain exactly 27 gates; received ${contract.gates.length}`);
|
||||
}
|
||||
if (contract.commands.length !== 91 || commandReferenceCount !== 103) {
|
||||
failures.push(
|
||||
`command authority baseline must contain exactly 91 definitions and 103 references; received ${contract.commands.length} definitions and ${commandReferenceCount} references`,
|
||||
if (!parsed.success) {
|
||||
throw new TypeError(
|
||||
`${CI_CONTRACT_BASELINE_PATH} invalid:\n${parsed.error.issues
|
||||
.map((issue) => `${issue.path.join(".") || "root"}: ${issue.message}`)
|
||||
.join("\n")}`,
|
||||
);
|
||||
}
|
||||
if (contract.artifacts.length !== 109) {
|
||||
failures.push(`artifact authority baseline must contain exactly 109 artifacts; received ${contract.artifacts.length}`);
|
||||
}
|
||||
if (contract.stages.length !== 5) {
|
||||
failures.push(`stage authority baseline must contain exactly 5 stages; received ${contract.stages.length}`);
|
||||
const baseline = parsed.data;
|
||||
const drift = Object.entries(measureCiContractBaseline(contract))
|
||||
.filter(([key, value]) => baseline[key as keyof CiContractBaseline] !== value)
|
||||
.map(([key, value]) =>
|
||||
`${key}: baseline ${String(baseline[key as keyof CiContractBaseline])}, contract ${String(value)}`
|
||||
);
|
||||
if (drift.length > 0) {
|
||||
throw new TypeError(
|
||||
`CI gate contract does not match ${CI_CONTRACT_BASELINE_PATH}:\n${drift.join("\n")}\n` +
|
||||
"If the change is intended, review it and run " +
|
||||
"CI_CONTRACT_BASELINE_OWNER=<team> CI_CONTRACT_BASELINE_REASON=<why> corepack pnpm update:ci-contract-baseline",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function retentionRegistryFailures(contract: CiGateContract): string[] {
|
||||
const expectedRetentionClasses = [
|
||||
{ id: "merge-cycle", policy: "at least through pull-request readiness decision" },
|
||||
{ id: "release-coherence", policy: "at least until the next release is promoted" },
|
||||
@@ -495,16 +538,12 @@ function canonicalAuthorityBaselineFailures(contract: CiGateContract): string[]
|
||||
{ id: "field", policy: "through the 28-day window and aggregation" },
|
||||
{ id: "documentation", policy: "through documentation readiness review" },
|
||||
];
|
||||
if (JSON.stringify(contract.retention.classes) !== JSON.stringify(expectedRetentionClasses)) {
|
||||
failures.push("retention registry must contain exactly the five canonical retention classes");
|
||||
}
|
||||
return failures;
|
||||
return JSON.stringify(contract.retention.classes) === JSON.stringify(expectedRetentionClasses)
|
||||
? []
|
||||
: ["retention registry must contain exactly the five canonical retention classes"];
|
||||
}
|
||||
|
||||
export function parseCiGateContract(
|
||||
value: unknown,
|
||||
options: LoadCiGateContractOptions = {},
|
||||
): CiGateContract {
|
||||
export function parseCiGateContract(value: unknown): CiGateContract {
|
||||
const result = ciGateContractSchema.safeParse(value);
|
||||
if (!result.success) {
|
||||
const diagnostic = result.error.issues
|
||||
@@ -512,49 +551,21 @@ export function parseCiGateContract(
|
||||
.join("\n");
|
||||
throw new TypeError(`CI gate contract invalid:\n${diagnostic}`);
|
||||
}
|
||||
if ((options.mode ?? defaultCiContractMode()) === "canonical") {
|
||||
const failures = canonicalAuthorityBaselineFailures(result.data);
|
||||
if (failures.length > 0) {
|
||||
throw new TypeError(`CI gate contract invalid:\n${failures.map((failure) => `root: ${failure}`).join("\n")}`);
|
||||
}
|
||||
const failures = retentionRegistryFailures(result.data);
|
||||
if (failures.length > 0) {
|
||||
throw new TypeError(`CI gate contract invalid:\n${failures.map((failure) => `root: ${failure}`).join("\n")}`);
|
||||
}
|
||||
return result.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* A removal fixture runs the whole suite against a deliberately *reduced* CI
|
||||
* contract: the removed capability's gates, commands and artifacts are pruned.
|
||||
* Loading that contract in canonical mode re-imposes the full exact-count
|
||||
* authority on it, so the fixture failed on the very reduction it exists to
|
||||
* prove. `runRemovalFixturePnpm` marks those runs, and this is where the mark
|
||||
* is honoured.
|
||||
*/
|
||||
export function defaultCiContractMode(): "canonical" | "removal-fixture" {
|
||||
return process.env.CI_CONTRACT_MODE === "removal-fixture"
|
||||
? "removal-fixture"
|
||||
: "canonical";
|
||||
}
|
||||
|
||||
export function isReducedCiContractRun(): boolean {
|
||||
return defaultCiContractMode() === "removal-fixture";
|
||||
}
|
||||
|
||||
export async function loadCiGateContract(
|
||||
root = process.cwd(),
|
||||
options: LoadCiGateContractOptions = {},
|
||||
): Promise<CiGateContract> {
|
||||
const mode = options.mode ?? defaultCiContractMode();
|
||||
const [rawContract, rawPackage] = await Promise.all([
|
||||
readFile(path.join(root, "config/ci/gates.json"), "utf8"),
|
||||
readFile(path.join(root, "package.json"), "utf8"),
|
||||
]);
|
||||
const contract = parseCiGateContract(JSON.parse(rawContract), { mode });
|
||||
if (
|
||||
mode === "canonical" &&
|
||||
canonicalGateShapeSha256(contract.gates) !== CANONICAL_GATE_SHAPE_SHA256
|
||||
) {
|
||||
throw new TypeError("CI gate contract canonical gate semantic shape drift");
|
||||
}
|
||||
const contract = parseCiGateContract(JSON.parse(rawContract));
|
||||
const packageDocument = z
|
||||
.object({ scripts: z.record(z.string(), z.string()).default({}) })
|
||||
.passthrough()
|
||||
@@ -566,9 +577,8 @@ export async function loadCiGateContract(
|
||||
if (missing.length > 0) {
|
||||
throw new TypeError(`CI gate contract missing package scripts: ${missing.join(", ")}`);
|
||||
}
|
||||
const expectedCheckCi = mode === "canonical"
|
||||
? "corepack pnpm check:artifact-schemas && node scripts/check-ci-contract.ts && corepack pnpm check:ci-workflow"
|
||||
: "corepack pnpm check:artifact-schemas && node scripts/check-ci-contract.ts --reduced-removal-fixture && corepack pnpm check:ci-workflow";
|
||||
const expectedCheckCi =
|
||||
"corepack pnpm check:artifact-schemas && node scripts/check-ci-contract.ts && corepack pnpm check:ci-workflow";
|
||||
if (packageDocument.scripts["check:ci"] !== expectedCheckCi) {
|
||||
throw new TypeError("check:ci must use the exact canonical non-recursive orchestration");
|
||||
}
|
||||
@@ -577,9 +587,7 @@ export async function loadCiGateContract(
|
||||
// product index, so the index is rendered first.
|
||||
"check:artifact-schemas":
|
||||
"node scripts/generate-product-feature-index.ts && node scripts/generate-artifact-schemas.ts --check",
|
||||
"check:ci-workflow": mode === "canonical"
|
||||
? "node scripts/generate-ci-workflow.ts --check"
|
||||
: "node scripts/generate-ci-workflow.ts --check --reduced-removal-fixture",
|
||||
"check:ci-workflow": "node scripts/generate-ci-workflow.ts --check",
|
||||
} as const;
|
||||
for (const [script, expected] of Object.entries(canonicalCheckCiDependencies)) {
|
||||
if (packageDocument.scripts[script] !== expected) {
|
||||
@@ -609,6 +617,7 @@ export async function loadCiGateContract(
|
||||
`CI package script install policy invalid:\n${installPolicyFailures.join("\n")}`,
|
||||
);
|
||||
}
|
||||
await assertCiContractBaseline(root, contract);
|
||||
return contract;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ export type GenerateCiWorkflowOptions = Readonly<{
|
||||
root: string;
|
||||
contract?: CiGateContract;
|
||||
check: boolean;
|
||||
contractMode?: "canonical" | "removal-fixture";
|
||||
}>;
|
||||
|
||||
export type GenerateCiWorkflowResult = Readonly<{
|
||||
@@ -361,9 +360,7 @@ export function createCiWorkflowGenerator(
|
||||
const createNonce = dependencies.createNonce ?? randomUUID;
|
||||
return async function generate(options: GenerateCiWorkflowOptions): Promise<GenerateCiWorkflowResult> {
|
||||
const root = path.resolve(options.root);
|
||||
const contract = options.contract ?? (await loadCiGateContract(root, {
|
||||
mode: options.contractMode ?? "canonical",
|
||||
}));
|
||||
const contract = options.contract ?? (await loadCiGateContract(root));
|
||||
const target = path.resolve(root, contract.providerAdapter);
|
||||
if (path.relative(root, target).startsWith("..") || path.relative(root, target) === "") {
|
||||
throw new TypeError(`workflow target escapes repository root: ${contract.providerAdapter}`);
|
||||
@@ -478,11 +475,8 @@ function hasErrorCode(error: unknown, code: string): boolean {
|
||||
const isCli = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
||||
if (isCli) {
|
||||
const check = process.argv.includes("--check");
|
||||
const contractMode = process.argv.includes("--reduced-removal-fixture")
|
||||
? "removal-fixture" as const
|
||||
: "canonical" as const;
|
||||
try {
|
||||
const result = await generateCiWorkflow({ root: process.cwd(), check, contractMode });
|
||||
const result = await generateCiWorkflow({ root: process.cwd(), check });
|
||||
if (!result.matches) {
|
||||
process.stderr.write(
|
||||
`CI workflow drift: ${result.target} differs at byte ${result.firstDifferenceByte ?? 0}, line ${result.firstDifferenceLine ?? 1}\n`,
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
} from "../contracts/ci-gates.ts";
|
||||
import { linkFixtureNodeModules } from "./fixture-node-modules.ts";
|
||||
import { generateCiWorkflow } from "../generate-ci-workflow.ts";
|
||||
import { updateCiContractBaseline } from "../update-ci-contract-baseline.ts";
|
||||
|
||||
export const REMOVAL_FIXTURE_COPY_TARGETS = Object.freeze([
|
||||
"src", "tests", "recipes", "scripts", "schemas", "config", "public",
|
||||
@@ -164,11 +165,12 @@ export function runRemovalFixturePnpm(
|
||||
pnpmCli: string,
|
||||
script: string,
|
||||
extra: readonly string[] = [],
|
||||
env: Readonly<Record<string, string>> = {},
|
||||
): boolean {
|
||||
return spawnSync(process.execPath, [pnpmCli, script, ...extra], {
|
||||
cwd: root,
|
||||
stdio: "inherit",
|
||||
env: { ...process.env, CI_CONTRACT_MODE: "removal-fixture" },
|
||||
env: { ...process.env, ...env },
|
||||
}).status === 0;
|
||||
}
|
||||
|
||||
@@ -274,7 +276,7 @@ export function pruneScriptOrchestration(
|
||||
}
|
||||
|
||||
export async function regenerateRemovalFixtureWorkflow(root: string): Promise<void> {
|
||||
const contract = await loadCiGateContract(root, { mode: "removal-fixture" });
|
||||
const contract = await loadCiGateContract(root);
|
||||
await generateCiWorkflow({ root, contract, check: false });
|
||||
// Every removal script calls this once, after it has finished mutating the
|
||||
// tree, so it is the one place where the fixture's contents are final.
|
||||
@@ -328,10 +330,6 @@ export async function pruneRemovalFixtureCiContract(options: Readonly<{
|
||||
scripts: Record<string, string>;
|
||||
};
|
||||
for (const script of options.removedScripts) delete packageDocument.scripts[script];
|
||||
packageDocument.scripts["check:ci-workflow"] =
|
||||
"node scripts/generate-ci-workflow.ts --check --reduced-removal-fixture";
|
||||
packageDocument.scripts["check:ci"] =
|
||||
"corepack pnpm check:artifact-schemas && node scripts/check-ci-contract.ts --reduced-removal-fixture && corepack pnpm check:ci-workflow";
|
||||
|
||||
const contract = structuredClone(
|
||||
parseCiGateContract(JSON.parse(await readFile(gatesPath, "utf8"))),
|
||||
@@ -384,9 +382,15 @@ export async function pruneRemovalFixtureCiContract(options: Readonly<{
|
||||
contract.artifactSchemas = contract.artifactSchemas.filter(({ id }) =>
|
||||
referencedSchemaIds.has(id)
|
||||
);
|
||||
const validated = parseCiGateContract(contract, { mode: "removal-fixture" });
|
||||
const validated = parseCiGateContract(contract);
|
||||
await Promise.all([
|
||||
writeFile(packagePath, `${JSON.stringify(packageDocument, null, 2)}\n`),
|
||||
writeFile(gatesPath, `${JSON.stringify(validated, null, 2)}\n`),
|
||||
]);
|
||||
// D-13: the reduced contract is a new baseline, recorded the way a project
|
||||
// that removes the capability records it; canonical check:ci then applies.
|
||||
await updateCiContractBaseline(options.root, {
|
||||
owner: "removal-fixture",
|
||||
reason: `removal fixture pruned ${[...options.removedScripts].join(", ")}`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -282,6 +282,15 @@ try {
|
||||
"http-scenario-evidence",
|
||||
],
|
||||
});
|
||||
// D-13: removing the sample is a breaking registry change. The fixture
|
||||
// records the new registry baseline the way a downstream project does, and
|
||||
// the canonical check:registries then runs against it.
|
||||
if (!runRemovalFixturePnpm(fixtureRoot, pnpmCli, "update:registry-baseline", [], {
|
||||
REGISTRY_BASELINE_OWNER: "removal-fixture",
|
||||
REGISTRY_BASELINE_REASON: "reference feature removed",
|
||||
})) {
|
||||
throw new Error("Registry baseline failed to update after sample removal");
|
||||
}
|
||||
await regenerateRemovalFixtureWorkflow(fixtureRoot);
|
||||
|
||||
const residue: string[] = [];
|
||||
@@ -317,7 +326,7 @@ try {
|
||||
],
|
||||
["typecheck", runPnpm("check:types")],
|
||||
["architecture", runPnpm("check:architecture")],
|
||||
["registry-structure", runPnpm("check:registries:structure")],
|
||||
["registries", runPnpm("check:registries")],
|
||||
["unit-integration", runPnpm("test:all")],
|
||||
["coverage", runPnpm("test:coverage")],
|
||||
["test-evidence-source", runPnpm("check:test-evidence:source")],
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
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`,
|
||||
);
|
||||
}
|
||||
@@ -42,6 +42,10 @@ describe("CI-runner command-generated evidence freshness", () => {
|
||||
path.join(root, "config/ci/gates.json"),
|
||||
`${JSON.stringify(contract)}\n`,
|
||||
);
|
||||
await writeFile(
|
||||
path.join(root, "config/ci/contract-baseline.json"),
|
||||
await readFile("config/ci/contract-baseline.json"),
|
||||
);
|
||||
await writeFile(
|
||||
path.join(root, "package.json"),
|
||||
`${JSON.stringify(packageDocument)}\n`,
|
||||
@@ -95,6 +99,10 @@ describe("CI-runner command-generated evidence freshness", () => {
|
||||
path.join(root, "config/ci/gates.json"),
|
||||
`${JSON.stringify(contract)}\n`,
|
||||
);
|
||||
await writeFile(
|
||||
path.join(root, "config/ci/contract-baseline.json"),
|
||||
await readFile("config/ci/contract-baseline.json"),
|
||||
);
|
||||
await writeFile(
|
||||
path.join(root, "package.json"),
|
||||
`${JSON.stringify(packageDocument)}\n`,
|
||||
@@ -143,6 +151,10 @@ describe("CI-runner gate output budget", () => {
|
||||
path.join(root, "config/ci/gates.json"),
|
||||
`${JSON.stringify(contract)}\n`,
|
||||
);
|
||||
await writeFile(
|
||||
path.join(root, "config/ci/contract-baseline.json"),
|
||||
await readFile("config/ci/contract-baseline.json"),
|
||||
);
|
||||
await writeFile(
|
||||
path.join(root, "package.json"),
|
||||
`${JSON.stringify(packageDocument)}\n`,
|
||||
|
||||
@@ -135,6 +135,10 @@ async function createUnsafeCiGateFixture(
|
||||
Object.assign(packageDocument.scripts, additionalScripts);
|
||||
await writeFile(path.join(root, "config/ci/gates.json"), `${JSON.stringify(contract)}\n`);
|
||||
await writeFile(path.join(root, "package.json"), `${JSON.stringify(packageDocument)}\n`);
|
||||
await writeFile(
|
||||
path.join(root, "config/ci/contract-baseline.json"),
|
||||
await readFile("config/ci/contract-baseline.json"),
|
||||
);
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -323,10 +327,12 @@ describe("CI gate contract", () => {
|
||||
gate.name = `${gate.name}-renamed`;
|
||||
await writeFile(path.join(root, "config/ci/gates.json"), `${JSON.stringify(contract)}\n`);
|
||||
await writeFile(path.join(root, "package.json"), await readFile("package.json"));
|
||||
|
||||
await expect(loadCiGateContract(root)).rejects.toThrow(
|
||||
/canonical gate semantic shape/i,
|
||||
await writeFile(
|
||||
path.join(root, "config/ci/contract-baseline.json"),
|
||||
await readFile("config/ci/contract-baseline.json"),
|
||||
);
|
||||
|
||||
await expect(loadCiGateContract(root)).rejects.toThrow(/gateShapeSha256: baseline/i);
|
||||
});
|
||||
|
||||
it.each(["check:artifact-schemas", "check:ci-workflow"])(
|
||||
@@ -1318,6 +1324,10 @@ describe("CI gate contract", () => {
|
||||
await writeFile(path.join(root, "config/ci/gates.json"), `${JSON.stringify(contract)}\n`);
|
||||
await writeFile(path.join(root, "package.json"), await readFile("package.json"));
|
||||
await writeFile(path.join(root, ".nvmrc"), await readFile(".nvmrc"));
|
||||
await writeFile(
|
||||
path.join(root, "config/ci/contract-baseline.json"),
|
||||
await readFile("config/ci/contract-baseline.json"),
|
||||
);
|
||||
const drift = Buffer.from("drifted workflow\n", "utf8");
|
||||
await writeFile(path.join(root, ".gitea/workflows/quality-gates.yml"), drift);
|
||||
const result = spawnSync(process.execPath, [path.resolve("scripts/check-ci-contract.ts")], {
|
||||
|
||||
@@ -334,10 +334,11 @@ describe("registry governance manifest", () => {
|
||||
edges: expect.any(Array),
|
||||
});
|
||||
expect(versions?.rows).toBeDefined();
|
||||
// Who approved and why, not this template's wording: a project that
|
||||
// re-baselines with update:registry-baseline writes its own (D-13).
|
||||
expect(approval).toMatchObject({
|
||||
owner: "frontend-platform",
|
||||
reason:
|
||||
"Baseline canonical invalidation graph and topic-version contracts after FE-REG-QUERY retirement",
|
||||
owner: expect.stringMatching(/\S/u),
|
||||
reason: expect.stringMatching(/\S/u),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -53,12 +53,20 @@ it("allows zero runtime imports after the runtime has been removed", async () =>
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("prunes removed command and evidence references from a reduced CI contract", async () => {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "removal-fixture-contract-"));
|
||||
async function copyCiContract(prefix: string): Promise<string> {
|
||||
const root = await mkdtemp(path.join(tmpdir(), prefix));
|
||||
temporaryRoots.push(root);
|
||||
await mkdir(path.join(root, "config/ci"), { recursive: true });
|
||||
await writeFile(path.join(root, "config/ci/gates.json"), await readFile("config/ci/gates.json"));
|
||||
await writeFile(path.join(root, "package.json"), await readFile("package.json"));
|
||||
for (const file of ["config/ci/gates.json", "config/ci/contract-baseline.json", "package.json"]) {
|
||||
await writeFile(path.join(root, file), await readFile(file));
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
// D-13: a removal takes the same step a downstream project takes — it records
|
||||
// the reduced contract as the new baseline — and then loads canonically.
|
||||
it("prunes removed command and evidence references and re-baselines the contract", async () => {
|
||||
const root = await copyCiContract("removal-fixture-contract-");
|
||||
|
||||
await pruneRemovalFixtureCiContract({
|
||||
root,
|
||||
@@ -66,21 +74,36 @@ it("prunes removed command and evidence references from a reduced CI contract",
|
||||
removedEvidencePathFragments: ["reference-feature.xml"],
|
||||
});
|
||||
|
||||
const contract = await loadCiGateContract(root, { mode: "removal-fixture" });
|
||||
const contract = await loadCiGateContract(root);
|
||||
expect(contract.commands.some(({ script }) => script === "test:reference-feature")).toBe(false);
|
||||
expect(contract.artifacts.some(({ path }) => path.includes("reference-feature.xml"))).toBe(false);
|
||||
expect(contract.gates.some(({ commandIds }) => commandIds.includes("test-reference-feature"))).toBe(false);
|
||||
expect(contract.gates.some(({ evidenceArtifactIds }) =>
|
||||
evidenceArtifactIds.includes("artifact-artifacts-tests-reference-feature-xml")
|
||||
)).toBe(false);
|
||||
const baseline = JSON.parse(
|
||||
await readFile(path.join(root, "config/ci/contract-baseline.json"), "utf8"),
|
||||
) as Record<string, unknown>;
|
||||
expect(baseline).toMatchObject({ commands: contract.commands.length, owner: "removal-fixture" });
|
||||
const packageDocument = JSON.parse(await readFile(path.join(root, "package.json"), "utf8")) as {
|
||||
scripts: Record<string, string>;
|
||||
};
|
||||
expect(packageDocument.scripts["check:ci"]).not.toMatch(/reduced/u);
|
||||
});
|
||||
|
||||
it("rejects a contract that no longer matches its committed baseline", async () => {
|
||||
const root = await copyCiContract("removal-fixture-baseline-drift-");
|
||||
const baselinePath = path.join(root, "config/ci/contract-baseline.json");
|
||||
const baseline = JSON.parse(await readFile(baselinePath, "utf8")) as Record<string, number>;
|
||||
await writeFile(baselinePath, JSON.stringify({ ...baseline, commands: baseline.commands! + 1 }));
|
||||
|
||||
await expect(loadCiGateContract(root)).rejects.toThrow(
|
||||
/contract-baseline\.json[\s\S]*commands[\s\S]*update:ci-contract-baseline/u,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects pruning that leaves a reduced gate without commands", async () => {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "removal-fixture-empty-gate-"));
|
||||
temporaryRoots.push(root);
|
||||
await mkdir(path.join(root, "config/ci"), { recursive: true });
|
||||
await writeFile(path.join(root, "config/ci/gates.json"), await readFile("config/ci/gates.json"));
|
||||
await writeFile(path.join(root, "package.json"), await readFile("package.json"));
|
||||
const root = await copyCiContract("removal-fixture-empty-gate-");
|
||||
|
||||
await expect(pruneRemovalFixtureCiContract({
|
||||
root,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createHash, generateKeyPairSync, sign } from "node:crypto";
|
||||
import { existsSync } from "node:fs";
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -14,7 +15,6 @@ import {
|
||||
validateLicensePolicy,
|
||||
} from "../../scripts/lib/supply-chain.ts";
|
||||
import { digestReleaseInputFiles } from "../../scripts/lib/release-input-evidence.ts";
|
||||
import { isReducedCiContractRun } from "../../scripts/contracts/ci-gates.ts";
|
||||
import { findSecretMatches } from "../../scripts/lib/secret-scan.ts";
|
||||
import {
|
||||
parseSecretScanIncludedPaths,
|
||||
@@ -456,11 +456,7 @@ describe("supply-chain policy", () => {
|
||||
});
|
||||
|
||||
it("wires the exact security fixture checker as a passing CI gate", async () => {
|
||||
const contract = await loadCiGateContract(process.cwd(), {
|
||||
mode: process.env.CI_CONTRACT_MODE === "removal-fixture"
|
||||
? "removal-fixture"
|
||||
: "canonical",
|
||||
});
|
||||
const contract = await loadCiGateContract(process.cwd());
|
||||
const index = indexCiGateContract(contract);
|
||||
const securityGate = index.gates.get("FE-GATE-013");
|
||||
expect(securityGate).toBeDefined();
|
||||
@@ -538,43 +534,43 @@ describe("supply-chain policy", () => {
|
||||
|
||||
// A removal fixture deletes some of these inputs on purpose — removing the
|
||||
// browser file/storage capability takes the whole browser-capability harness
|
||||
// with it — and prunes them from its own policy. This is a claim about the
|
||||
// full repository, so it does not describe a deliberately reduced one.
|
||||
it.skipIf(isReducedCiContractRun())("covers every mandatory release input in the secret scan policy", async () => {
|
||||
// with it. The claim is about the inputs this checkout has.
|
||||
it("covers every mandatory release input in the secret scan policy", async () => {
|
||||
const policy = JSON.parse(
|
||||
await readFile("config/security/secret-scan-policy.json", "utf8"),
|
||||
) as { trackedRoots: string[] };
|
||||
const mandatory = [
|
||||
"index.html",
|
||||
".dependency-cruiser.json",
|
||||
".nvmrc",
|
||||
".npmrc",
|
||||
"eslint.config.ts",
|
||||
"package.json",
|
||||
"pnpm-lock.yaml",
|
||||
"pnpm-workspace.yaml",
|
||||
"scripts",
|
||||
"schemas",
|
||||
"config",
|
||||
".gitea/workflows/quality-gates.yml",
|
||||
"vite.config.ts",
|
||||
"vite.service-worker.config.ts",
|
||||
"vitest.config.ts",
|
||||
"playwright.config.ts",
|
||||
"playwright.capabilities.config.ts",
|
||||
"playwright.dev.config.ts",
|
||||
"playwright.storybook.config.ts",
|
||||
"playwright.visual.config.ts",
|
||||
"tsconfig.json",
|
||||
"tsconfig.app.json",
|
||||
"tsconfig.base.json",
|
||||
"tsconfig.node.json",
|
||||
"tsconfig.recipes.json",
|
||||
"tsconfig.service-worker.json",
|
||||
"tsconfig.test.json",
|
||||
"tsconfig.web-worker.json",
|
||||
];
|
||||
expect(policy.trackedRoots).toEqual(
|
||||
expect.arrayContaining([
|
||||
"index.html",
|
||||
".dependency-cruiser.json",
|
||||
".nvmrc",
|
||||
".npmrc",
|
||||
"eslint.config.ts",
|
||||
"package.json",
|
||||
"pnpm-lock.yaml",
|
||||
"pnpm-workspace.yaml",
|
||||
"scripts",
|
||||
"schemas",
|
||||
"config",
|
||||
".gitea/workflows/quality-gates.yml",
|
||||
"vite.config.ts",
|
||||
"vite.service-worker.config.ts",
|
||||
"vitest.config.ts",
|
||||
"playwright.config.ts",
|
||||
"playwright.capabilities.config.ts",
|
||||
"playwright.dev.config.ts",
|
||||
"playwright.storybook.config.ts",
|
||||
"playwright.visual.config.ts",
|
||||
"tsconfig.json",
|
||||
"tsconfig.app.json",
|
||||
"tsconfig.base.json",
|
||||
"tsconfig.node.json",
|
||||
"tsconfig.recipes.json",
|
||||
"tsconfig.service-worker.json",
|
||||
"tsconfig.test.json",
|
||||
"tsconfig.web-worker.json",
|
||||
]),
|
||||
expect.arrayContaining(mandatory.filter((input) => existsSync(input))),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@ import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
isReducedCiContractRun,
|
||||
CI_CONTRACT_BASELINE_PATH,
|
||||
loadCiGateContract,
|
||||
measureCiContractBaseline,
|
||||
parseCiGateContract,
|
||||
} from "../../scripts/contracts/ci-gates.ts";
|
||||
import { generateCiWorkflow } from "../../scripts/generate-ci-workflow.ts";
|
||||
@@ -176,16 +177,14 @@ describe("selective Task 3 contract closure", () => {
|
||||
.toContain("package script missing: root -> missing");
|
||||
});
|
||||
|
||||
// A removal fixture runs against a pruned contract on purpose, so the
|
||||
// canonical counts do not describe it. Asserting them there failed the
|
||||
// fixture for the reduction it exists to demonstrate.
|
||||
it.skipIf(isReducedCiContractRun())("accepts only the canonical exact-count authority and rejects orphan retention", async () => {
|
||||
// D-13: the counts and gate shape come from the reviewed baseline file, so a
|
||||
// removal fixture that re-baselines its reduced contract passes here too.
|
||||
it("matches the owned contract baseline and rejects orphan retention", async () => {
|
||||
const canonical = await loadCiGateContract(process.cwd());
|
||||
expect(canonical.gates).toHaveLength(27);
|
||||
expect(canonical.commands).toHaveLength(91);
|
||||
expect(canonical.gates.reduce((sum, gate) => sum + gate.commandIds.length, 0)).toBe(103);
|
||||
expect(canonical.artifacts).toHaveLength(109);
|
||||
expect(canonical.stages).toHaveLength(5);
|
||||
const baseline = JSON.parse(await readFile(CI_CONTRACT_BASELINE_PATH, "utf8")) as Record<string, unknown>;
|
||||
expect(baseline).toMatchObject(measureCiContractBaseline(canonical));
|
||||
expect(baseline["owner"]).toEqual(expect.any(String));
|
||||
expect(baseline["reason"]).toEqual(expect.any(String));
|
||||
expect(canonical.retention.classes).toHaveLength(5);
|
||||
|
||||
const orphan = JSON.parse(JSON.stringify(canonical)) as Record<string, any>;
|
||||
@@ -193,7 +192,7 @@ describe("selective Task 3 contract closure", () => {
|
||||
expect(() => parseCiGateContract(orphan)).toThrow(/five canonical retention|orphan retention/u);
|
||||
});
|
||||
|
||||
it.skipIf(isReducedCiContractRun())("rejects the retired validate-candidate-archive grammar", async () => {
|
||||
it("rejects the retired validate-candidate-archive grammar", async () => {
|
||||
const canonical = JSON.parse(
|
||||
JSON.stringify(await loadCiGateContract(process.cwd())),
|
||||
) as Record<string, any>;
|
||||
|
||||
Reference in New Issue
Block a user