ci(gates): 검사기 자기 시험과 gating 검사를 main 단계로 내리고 계약 기준선을 지운다

merge 단계(=PR)가 변경이 아니라 검사기 자신을 시험하는 명령까지 돈다.
검사기가 나쁜 입력을 거부하는지 보는 `*:fixture` 명령 15개, 모든 시험
파일과 검증 script가 게이트에 걸렸는지 보는 ungated 검사, CI 계약의
개수·해시 기준선(`config/ci/contract-baseline.json`)이다. 기준선은 게이트
명령 하나를 더하거나 빼도 OWNER·REASON을 붙여 다시 받아야 했다.
소유자 결정(2026-09-16)은 개수·배선 검사를 main 단계에 두는 것이다.

고른 방법(design-docs repo-structure/03-ci.md 7.3절 F2, README.md 3.3절,
소유자 승인 2026-11-07):
- 새 게이트 FE-GATE-029 `checker-self-tests`, 새 단계 `main`
  (`MAIN_READY`, 승격을 막지 않는다), 새 job `main_gate`. 브랜치 push와
  `workflow_dispatch`(stage=main)에서만 돈다. PR과 태그에서는 돌지 않는다.
- FE-GATE-001·005·008·010·013의 `*:fixture` 명령 15개와 그 증거
  산출물 10개를 FE-GATE-029로 옮긴다.
- `check:ci`의 ungated 검사를 `scripts/check-ci-gating.ts`
  (`check:ci:gating`)로 떼어 FE-GATE-029에 둔다. `check:ci`는 계약·
  workflow 검사만 PR에서 돈다.
- 기준선 파일, `update:ci-contract-baseline`, 그 검사를 지운다(소유자
  결정). 계약 모양은 ci-gates.ts의 의미 검사가 지킨다. 개수를 고정하던
  단위 시험의 개수 단언도 뺐다.

남긴 것: 음성 타입 fixture(`check:types:fixtures`, FE-GATE-003)는
이름이 `*:fixture`여도 merge에 둔다. 검사기가 아니라 src의 포트·계약
타입을 시험한다. `TelemetryPort.emit`을 넓히는 변경을 PR에서 막는다(정리
3단계 9.3절 변이로 확인). merge 단계 명령 참조 64 → 49.

위험: 검사기를 망가뜨린 PR은 merge를 통과하고 main에서 빨개진다. 그
대가로 PR이 검사기 자기 시험을 기다리지 않는다(설계 7.5절의 같은 교환).
FE-GATE-029의 명령이 앞 게이트 산출물 없이 새 checkout에서 도는지는
desktop에서 따로 확인했다(PR 본문).

검증(desktop): check:ci, check:ci:gating, check:types, CI 시험 통과.
merge 단계·FE-GATE-029 실행 결과는 PR 본문에 적는다.

Refs: design-docs repo-structure/03-ci.md 7.3·7.4절, README.md 3.3절
This commit is contained in:
2026-11-08 21:56:37 +09:00
parent 0739f26b80
commit f6b2b96c53
22 changed files with 325 additions and 426 deletions
+31 -3
View File
@@ -15,6 +15,7 @@ on:
type: choice
options:
- merge
- main
- release
- production
- field
@@ -33,7 +34,7 @@ env:
jobs:
merge_static:
name: "merge / static checks"
if: ${{ gitea.event_name != 'workflow_dispatch' || inputs.stage != 'documentation' }}
if: ${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }}
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
@@ -75,7 +76,7 @@ jobs:
merge_test:
name: "merge / tests"
if: ${{ gitea.event_name != 'workflow_dispatch' || inputs.stage != 'documentation' }}
if: ${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }}
# FE-GATE-013 runner requirement: Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers
# FE-GATE-013 runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs
runs-on: ubuntu-latest
@@ -119,7 +120,7 @@ jobs:
merge_browser:
name: "merge / browser tests"
if: ${{ gitea.event_name != 'workflow_dispatch' || inputs.stage != 'documentation' }}
if: ${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }}
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
@@ -571,3 +572,30 @@ jobs:
name: "FE-GATE-017-${{ gitea.run_id }}"
path: artifacts/
if-no-files-found: error
main_gate:
name: "main / checker self-tests"
if: ${{ (gitea.event_name == 'push' && startsWith(gitea.ref, 'refs/heads/')) || (gitea.event_name == 'workflow_dispatch' && inputs.stage == 'main') }}
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
with:
persist-credentials: false
- uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
with:
node-version-file: .nvmrc
- name: Frozen install
run: |
corepack enable
corepack pnpm install --frozen-lockfile --ignore-scripts
- name: "FE-GATE-029 / checker-self-tests"
if: ${{ !cancelled() }}
run: corepack pnpm ci:gate -- FE-GATE-029
- name: Upload main gate evidence
if: always()
uses: https://github.com/ChristopherHX/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7
with:
name: "main-gate-${{ gitea.run_id }}"
path: artifacts/
if-no-files-found: error
-11
View File
@@ -1,11 +0,0 @@
{
"schemaVersion": 1,
"owner": "DongHyeonka",
"reason": "2026-11-07 소유자 결정: 정리 3단계(design-docs repo-structure/README.md 3.4절). 음성 타입 fixture 명령 23개를 실행기 하나로 합치고, 수동 a11y 기록을 docs/accessibility/route-reviews로, JSON Schema를 config/schemas로 옮긴다",
"gates": 27,
"commands": 76,
"commandReferences": 80,
"artifacts": 105,
"stages": 5,
"gateShapeSha256": "5b2ded190e5c1cbfc31f0d8c90fa358defe87850d99dc4db5439426b9ed72a90"
}
+98 -32
View File
@@ -427,6 +427,11 @@
"script": "check:ci",
"expect": "pass"
},
{
"id": "check-ci-gating",
"script": "check:ci:gating",
"expect": "pass"
},
{
"id": "check-release-admission",
"script": "check:release-admission",
@@ -1563,6 +1568,12 @@
"path": "artifacts/quality/gates/FE-GATE-028.txt",
"schemaId": "text",
"production": "runner-generated"
},
{
"id": "artifact-artifacts-quality-gates-FE-GATE-029-txt",
"path": "artifacts/quality/gates/FE-GATE-029.txt",
"schemaId": "text",
"production": "runner-generated"
}
],
"gates": [
@@ -1570,8 +1581,7 @@
"id": "FE-GATE-001",
"name": "manifest-lockfile",
"commandIds": [
"verify-lockfile",
"check-frozen-lockfile-fixture"
"verify-lockfile"
],
"logArtifactId": "artifact-artifacts-quality-install-txt",
"evidenceArtifactIds": [
@@ -1623,7 +1633,6 @@
"test-unit",
"test-contract",
"test-coverage",
"check-coverage-fixture",
"check-scale-pr"
],
"logArtifactId": "artifact-artifacts-quality-gates-FE-GATE-005-txt",
@@ -1632,8 +1641,7 @@
"artifact-artifacts-tests-contract-xml",
"artifact-artifacts-tests-coverage-xml",
"artifact-artifacts-tests-coverage-coverage-summary-json",
"artifact-artifacts-quality-risk-coverage-json",
"artifact-artifacts-quality-risk-coverage-fixture-json"
"artifact-artifacts-quality-risk-coverage-json"
],
"retentionClassId": "merge-cycle"
},
@@ -1676,8 +1684,7 @@
"verify-browser-capability-evidence",
"test-storybook",
"test-visual",
"check-test-evidence-browser",
"check-test-evidence-fixture"
"check-test-evidence-browser"
],
"logArtifactId": "artifact-artifacts-quality-gates-FE-GATE-008-txt",
"evidenceArtifactIds": [
@@ -1689,8 +1696,7 @@
"artifact-artifacts-tests-storybook-results-xml",
"artifact-artifacts-tests-visual-report-index-html",
"artifact-artifacts-tests-visual-results-xml",
"artifact-artifacts-quality-test-evidence-json",
"artifact-artifacts-quality-test-evidence-fixture-json"
"artifact-artifacts-quality-test-evidence-json"
],
"retentionClassId": "merge-cycle"
},
@@ -1715,21 +1721,12 @@
"check-request-fanout",
"check-app-build-input",
"check-design-system",
"check-design-system-fixture",
"check-i18n",
"check-i18n-fixture",
"check-diagnostics",
"check-diagnostics-fixture",
"check-browser-file-storage-boundaries",
"check-realtime-boundaries",
"check-realtime-boundaries-fixture",
"check-optional-recipes-source",
"check-optional-recipe-fixtures",
"check-registries",
"check-registries-compatibility-fixtures",
"check-registries-baseline-fixture",
"check-registries-fixture",
"check-routes-fixture",
"check-adapter-inventory",
"check-ci"
],
@@ -1737,19 +1734,11 @@
"evidenceArtifactIds": [
"artifact-artifacts-quality-dependency-report-json",
"artifact-artifacts-quality-design-system-json",
"artifact-artifacts-quality-design-system-fixture-json",
"artifact-artifacts-quality-i18n-json",
"artifact-artifacts-quality-i18n-fixture-json",
"artifact-artifacts-quality-diagnostics-json",
"artifact-artifacts-quality-diagnostics-fixture-json",
"artifact-artifacts-quality-realtime-boundaries-json",
"artifact-artifacts-quality-optional-recipes-json",
"artifact-artifacts-quality-optional-recipe-fixtures-json",
"artifact-artifacts-quality-registries-json",
"artifact-artifacts-quality-registry-compatibility-fixtures-json",
"artifact-artifacts-quality-registry-baseline-fixture-json",
"artifact-artifacts-quality-registry-fixture-json",
"artifact-artifacts-quality-route-registry-fixture-json",
"artifact-artifacts-quality-ci-contract-json"
],
"retentionClassId": "merge-cycle"
@@ -1793,9 +1782,6 @@
"verify-reproducible-build",
"build-release-candidate",
"verify-local-evidence",
"check-supply-chain-fixtures",
"check-supply-chain-provider-fixtures",
"check-security-fixtures",
"check-browser-security"
],
"logArtifactId": "artifact-artifacts-quality-gates-FE-GATE-013-txt",
@@ -1810,9 +1796,7 @@
"artifact-artifacts-security-license-report-json",
"artifact-artifacts-security-vulnerability-report-json",
"artifact-artifacts-security-supply-chain-verification-json",
"artifact-artifacts-security-supply-chain-coherence-json",
"artifact-artifacts-security-supply-chain-fixtures-json",
"artifact-artifacts-security-supply-chain-provider-fixtures-json"
"artifact-artifacts-security-supply-chain-coherence-json"
],
"retentionClassId": "release-coherence",
"hostRequirements": [
@@ -2009,6 +1993,44 @@
"artifact-artifacts-tests-a11y-manual-report-json"
],
"retentionClassId": "release-coherence"
},
{
"id": "FE-GATE-029",
"name": "checker-self-tests",
"commandIds": [
"check-frozen-lockfile-fixture",
"check-coverage-fixture",
"check-test-evidence-fixture",
"check-design-system-fixture",
"check-i18n-fixture",
"check-diagnostics-fixture",
"check-realtime-boundaries-fixture",
"check-optional-recipe-fixtures",
"check-registries-compatibility-fixtures",
"check-registries-baseline-fixture",
"check-registries-fixture",
"check-routes-fixture",
"check-supply-chain-fixtures",
"check-supply-chain-provider-fixtures",
"check-security-fixtures",
"check-ci-gating"
],
"logArtifactId": "artifact-artifacts-quality-gates-FE-GATE-029-txt",
"evidenceArtifactIds": [
"artifact-artifacts-quality-risk-coverage-fixture-json",
"artifact-artifacts-quality-test-evidence-fixture-json",
"artifact-artifacts-quality-design-system-fixture-json",
"artifact-artifacts-quality-i18n-fixture-json",
"artifact-artifacts-quality-diagnostics-fixture-json",
"artifact-artifacts-quality-optional-recipe-fixtures-json",
"artifact-artifacts-quality-registry-compatibility-fixtures-json",
"artifact-artifacts-quality-registry-baseline-fixture-json",
"artifact-artifacts-quality-registry-fixture-json",
"artifact-artifacts-quality-route-registry-fixture-json",
"artifact-artifacts-security-supply-chain-fixtures-json",
"artifact-artifacts-security-supply-chain-provider-fixtures-json"
],
"retentionClassId": "merge-cycle"
}
],
"stages": [
@@ -2079,6 +2101,14 @@
"gateIds": [
"FE-GATE-017"
]
},
{
"id": "main",
"readiness": "MAIN_READY",
"needs": [],
"gateIds": [
"FE-GATE-029"
]
}
],
"jobs": [
@@ -2825,6 +2855,42 @@
"always": true
}
]
},
{
"id": "main_gate",
"displayName": "main / checker self-tests",
"kind": "gate-sequence",
"needs": [],
"condition": "main",
"timeoutMinutes": 45,
"gateIds": [
"FE-GATE-029"
],
"browserGateIds": [],
"environment": [],
"steps": [
{
"kind": "checkout"
},
{
"kind": "setup-node"
},
{
"kind": "frozen-install"
},
{
"kind": "run-gate"
},
{
"kind": "upload",
"transferId": "main-gate-evidence",
"name": "main-gate-${{ gitea.run_id }}",
"paths": [
"artifacts/"
],
"always": true
}
]
}
],
"retention": {
+12 -24
View File
@@ -9,33 +9,22 @@ or otherwise byte-different output. `corepack pnpm check:ci` runs artifact-schem
checking, the typed contract checker, and this workflow drift check. The merge
stage runs as three jobs (`merge_static`, `merge_test`, `merge_browser`), one
install each; every gate is a step named by its ID, and a failed gate does not
skip the next. Release and production gates stay matrix checks. There is no
soft-fail wiring.
skip the next. The checkers' own negative fixtures and the gating check run in
the main stage (`main_gate`, FE-GATE-029) after a push to a branch. Release and
production gates stay matrix checks. There is no soft-fail wiring.
## 기준선 갱신과 새 프로젝트 시작 시 초기화할 기준선
게이트 계약의 크기와 모양은 코드 상수가 아니라 `config/ci/contract-baseline.json`에
있다. 이 파일에는 게이트 수, 명령 정의 수, 명령 참조 수, 산출물 수, stage 수,
게이트 모양 SHA-256과 함께 `owner`·`reason`이 들어 있다. 계약을 불러올 때 현재
`gates.json`과 이 파일이 다르면 실패한다(`scripts/contracts/ci-gates.ts`의
`assertCiContractBaseline`). 그래서 게이트·명령·산출물을 추가하거나 지운 뒤에는
다음 순서로 커밋한다.
게이트·명령·산출물 수와 게이트 모양 해시를 따로 기록하던 기준선 파일은 2026-11-08에
지웠다(소유자 결정, design-docs `repo-structure/README.md` 3.3절). 계약의 모양은
`scripts/contracts/ci-gates.ts`의 의미 검사(게이트·job·stage 소유와 순서)가 지킨다.
게이트·명령·산출물을 바꾼 뒤에는 `corepack pnpm generate:ci-workflow`와
`corepack pnpm check:ci`를 돌리고 생성된 workflow를 함께 커밋한다. 제거 검증
(`test:*-removal`)은 줄인 계약을 그대로 불러 canonical `check:ci`를 돌린다
(`scripts/lib/removal-fixture.ts`의 `pruneRemovalFixtureCiContract`).
```
# 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`). 완화 모드는 없다.
`check:ci`는 `tests/` 아래 테스트 파일(`tests/fixtures` 제외)이 모두 CI 게이트
명령에서 실행되는지도 확인한다. 게이트 명령이 닿는 package script의 Vitest 경로와
`check:ci:gating`(main 단계 FE-GATE-029)은 `tests/` 아래 테스트 파일(`tests/fixtures` 제외)이 모두 CI 게이트
명령에서 실행되는지 확인한다. 게이트 명령이 닿는 package script의 Vitest 경로와
Playwright 설정의 `testDir`를 모아 비교한다(`scripts/lib/ungated-tests.ts`).
`run-scale-profile.ts <tier>`를 부르는 명령은 그 tier의 Vitest 경로로 센다.
게이트가 돌리지 않는 테스트는 `config/ci/ungated-tests.json`에 이유와 함께 적어야
@@ -65,7 +54,6 @@ package script 그래프로 닿거나, 게이트가 이미 돌리는 Vitest 경
| 기준선 | 파일 | 갱신 방법 | 검사 위치 |
|---|---|---|---|
| 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`에 항목을 추가(`changeId`, 그 변경 뒤 값 `after`(삭제는 생략, 값은 JSON 그대로이고 키·원시값 배열 순서는 상관없다), `versionBump`·`migration`·`compatibilityWindow`·`rollback`·`owner`). 같은 칸을 다시 바꾸면 `after`가 달라 새 항목이 필요하다. 지금 diff의 breaking 변경과 changeId가 맞지 않는 항목이 있으면 게이트가 그 항목을 나열하며 실패한다. `update:registry-baseline`은 새 기준선이 설명하는 항목을 모두 지운다(지운 항목은 git 이력에 남는다) | `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`가 같은 일을 한다) | 실패하는 검사는 없다. 남은 키는 아무것도 끄지 않고, `check:release-admission`(FE-GATE-027)이 `release admission warning: FEATURE_OVERRIDES.<id> … the override does nothing`을, 부팅이 진단 `feature.override.unknown`(warn)을 남긴다(리뷰 09-09) |
+1 -1
View File
@@ -104,7 +104,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",
"check:ci:gating": "node scripts/check-ci-gating.ts",
"verify:documentation": "node scripts/generate-product-feature-index.ts && node scripts/verify-documentation-readiness.ts",
"check:types:service-worker": "tsc --project tsconfig.service-worker.json",
"generate:feature-index": "node scripts/generate-product-feature-index.ts",
+5 -51
View File
@@ -1,5 +1,4 @@
import { createHash } from "node:crypto";
import { readFileSync } from "node:fs";
import { readFile } from "node:fs/promises";
import {
@@ -25,25 +24,12 @@ import {
validateInstallScriptPolicy,
validatePackageScriptGraph,
} from "./lib/package-script-graph.ts";
import {
gatedTestPaths,
listTestFiles,
parseUngatedTestExclusions,
ungatedTestFailures,
UNGATED_TESTS_PATH,
} from "./lib/ungated-tests.ts";
import {
parseUngatedScriptExclusions,
ungatedScriptFailures,
UNGATED_SCRIPTS_PATH,
} from "./lib/ungated-scripts.ts";
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
const contract = await loadCiGateContract(process.cwd());
const index = indexCiGateContract(contract);
// 1103/12-07. The product's merge gates are entry scripts of CI as well.
// 1103/12-07. The product's merge gates run in the generated workflow too.
const { mergeGates: productGates } = await loadProductCiOverlay(process.cwd());
const productGateScripts = productGates.map(({ script }) => script);
const [packageDocument, nodeVersion] = await Promise.all([
readFile("package.json", "utf8").then((value) => JSON.parse(value) as { scripts?: Record<string, string> }),
readFile(".nvmrc", "utf8").then((value) => value.trim()),
@@ -82,42 +68,10 @@ failures.push(
),
);
// 12-04: every test file runs in a gate, or config/ci/ungated-tests.json says why not.
try {
failures.push(
...ungatedTestFailures({
testFiles: await listTestFiles(process.cwd()),
gatedPaths: gatedTestPaths(
packageScripts,
[...contract.commands.map(({ script }) => script), ...productGateScripts],
(file) => readFileSync(file, "utf8"),
),
exclusions: parseUngatedTestExclusions(
JSON.parse(await readFile(UNGATED_TESTS_PATH, "utf8")),
),
}),
);
} catch (error) {
failures.push(`ungated test check could not run: ${error instanceof Error ? error.message : String(error)}`);
}
// 12-04: every verification package script is reached by a gate, or
// config/ci/ungated-scripts.json says why not.
try {
const entryScripts = [...contract.commands.map(({ script }) => script), ...productGateScripts];
failures.push(
...ungatedScriptFailures({
scripts: packageScripts,
entryScripts,
gatedTestPaths: gatedTestPaths(packageScripts, entryScripts, (file) => readFileSync(file, "utf8")),
exclusions: parseUngatedScriptExclusions(
JSON.parse(await readFile(UNGATED_SCRIPTS_PATH, "utf8")),
),
}),
);
} catch (error) {
failures.push(`ungated script check could not run: ${error instanceof Error ? error.message : String(error)}`);
}
// 12-04. Whether every test file and verification script is reached by a
// gate is checked by check:ci:gating (scripts/check-ci-gating.ts) in the main
// stage (FE-GATE-029), not on every pull request (design-docs
// repo-structure/03-ci.md F2).
const immutable = index.gates.get("FE-GATE-015");
const immutableCommands = immutable?.commandIds.map((id) => index.commands.get(id)?.script);
+77
View File
@@ -0,0 +1,77 @@
import { readFileSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { loadCiGateContract } from "./contracts/ci-gates.ts";
import { loadProductCiOverlay } from "./contracts/product-ci-overlay.ts";
import {
gatedTestPaths,
listTestFiles,
parseUngatedTestExclusions,
ungatedTestFailures,
UNGATED_TESTS_PATH,
} from "./lib/ungated-tests.ts";
import {
parseUngatedScriptExclusions,
ungatedScriptFailures,
UNGATED_SCRIPTS_PATH,
} from "./lib/ungated-scripts.ts";
/**
* 12-04. Every test file and every verification package script is reached by
* a gate command of any stage, or config/ci/ungated-tests.json and
* config/ci/ungated-scripts.json say why not. It checks how the gates are
* wired, not the change, so it runs in the main stage (FE-GATE-029) after a
* merge (design-docs repo-structure/03-ci.md F2); check:ci keeps the contract
* and workflow checks on every pull request.
*/
const contract = await loadCiGateContract(process.cwd());
// 1103/12-07. The product's merge gates are entry scripts of CI as well.
const { mergeGates: productGates } = await loadProductCiOverlay(process.cwd());
const productGateScripts = productGates.map(({ script }) => script);
const packageScripts =
(JSON.parse(await readFile("package.json", "utf8")) as { scripts?: Record<string, string> }).scripts ?? {};
const failures: string[] = [];
// 12-04: every test file runs in a gate, or config/ci/ungated-tests.json says why not.
try {
failures.push(
...ungatedTestFailures({
testFiles: await listTestFiles(process.cwd()),
gatedPaths: gatedTestPaths(
packageScripts,
[...contract.commands.map(({ script }) => script), ...productGateScripts],
(file) => readFileSync(file, "utf8"),
),
exclusions: parseUngatedTestExclusions(
JSON.parse(await readFile(UNGATED_TESTS_PATH, "utf8")),
),
}),
);
} catch (error) {
failures.push(`ungated test check could not run: ${error instanceof Error ? error.message : String(error)}`);
}
// 12-04: every verification package script is reached by a gate, or
// config/ci/ungated-scripts.json says why not.
try {
const entryScripts = [...contract.commands.map(({ script }) => script), ...productGateScripts];
failures.push(
...ungatedScriptFailures({
scripts: packageScripts,
entryScripts,
gatedTestPaths: gatedTestPaths(packageScripts, entryScripts, (file) => readFileSync(file, "utf8")),
exclusions: parseUngatedScriptExclusions(
JSON.parse(await readFile(UNGATED_SCRIPTS_PATH, "utf8")),
),
}),
);
} catch (error) {
failures.push(`ungated script check could not run: ${error instanceof Error ? error.message : String(error)}`);
}
if (failures.length > 0) {
process.stderr.write(`CI gating failed:\n${failures.join("\n")}\n`);
process.exit(1);
}
process.stdout.write("CI gating: every test file and verification script is gated or excluded with a reason PASS\n");
+12 -103
View File
@@ -1,5 +1,4 @@
import { readFile } from "node:fs/promises";
import { createHash } from "node:crypto";
import path from "node:path";
import { z } from "zod";
@@ -312,6 +311,7 @@ const stageSchema = z
"PROD_PROMOTION_READY",
"FIELD_SLO_READY",
"DOCUMENTATION_READY",
"MAIN_READY",
]),
needs: z.array(id).max(16),
gateIds: z.array(id).min(1).max(64),
@@ -407,7 +407,7 @@ const jobSchema = z
displayName: workflowValue,
kind: z.enum(["gate-matrix", "gate-sequence", "gate-single", "immutable", "provider", "promotion", "deployment"]),
needs: z.array(id).max(32),
condition: z.enum(["always", "needs-success", "merge", "release", "production", "field", "documentation"]),
condition: z.enum(["always", "needs-success", "merge", "main", "release", "production", "field", "documentation"]),
timeoutMinutes: z.number().int().positive(),
gateIds: z.array(id).max(64),
browserGateIds: z.array(id).max(64),
@@ -467,106 +467,10 @@ export type CiGateContractIndex = Readonly<{
export const RETIRED_GATE_IDS: readonly string[] = Object.freeze(["FE-GATE-016"]);
export const CANONICAL_GATE_IDS: readonly string[] = Object.freeze(
Array.from({ length: 28 }, (_, index) => `FE-GATE-${String(index + 1).padStart(3, "0")}`)
Array.from({ length: 29 }, (_, index) => `FE-GATE-${String(index + 1).padStart(3, "0")}`)
.filter((gateId) => !RETIRED_GATE_IDS.includes(gateId)),
);
/**
* 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 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(
({
id,
name,
commandIds,
logArtifactId,
evidenceArtifactIds,
retentionClassId,
requiresEnvironment,
hostRequirements,
}) => ({
id,
name,
commandIds,
logArtifactId,
evidenceArtifactIds,
retentionClassId,
requiresEnvironment: requiresEnvironment ?? [],
// Only gates that declare runner requirements carry the key, so the
// digest of every other gate stays what it was.
...(hostRequirements === undefined ? {} : { hostRequirements }),
}),
);
return createHash("sha256").update(JSON.stringify(normalized)).digest("hex");
}
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 (!parsed.success) {
throw new TypeError(
`${CI_CONTRACT_BASELINE_PATH} invalid:\n${parsed.error.issues
.map((issue) => `${issue.path.join(".") || "root"}: ${issue.message}`)
.join("\n")}`,
);
}
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" },
@@ -668,8 +572,6 @@ export async function loadCiGateContract(
`CI package script install policy invalid:\n${installPolicyFailures.join("\n")}`,
);
}
// The baseline describes the template contract; the overlay is the product's.
await assertCiContractBaseline(root, template);
return contract;
}
@@ -843,7 +745,7 @@ function validateContractSemantics(
const expectedGateIds = CANONICAL_GATE_IDS;
if (JSON.stringify(contract.gates.map(({ id }) => id)) !== JSON.stringify(expectedGateIds)) {
issue(`gate registry must contain FE-GATE-001..028 without retired ${RETIRED_GATE_IDS.join(", ")} in canonical order`);
issue(`gate registry must contain FE-GATE-001..029 without retired ${RETIRED_GATE_IDS.join(", ")} in canonical order`);
}
const expectedStages: ReadonlyArray<readonly [string, string, readonly string[], readonly string[]]> = [
["merge", "MERGE_READY", [], PROMOTION_FORMULA.MERGE_READY],
@@ -851,6 +753,7 @@ function validateContractSemantics(
["production", "PROD_PROMOTION_READY", ["release"], PROMOTION_FORMULA.PROD_PROMOTION_READY],
["field", "FIELD_SLO_READY", ["production"], PROMOTION_FORMULA.FIELD_SLO_READY],
["documentation", "DOCUMENTATION_READY", [], PROMOTION_FORMULA.DOCUMENTATION_READY],
["main", "MAIN_READY", [], PROMOTION_FORMULA.MAIN_READY],
];
const stageShape = contract.stages.map(({ id, readiness, needs, gateIds }) => [id, readiness, needs, gateIds]);
if (JSON.stringify(stageShape) !== JSON.stringify(expectedStages)) {
@@ -933,9 +836,12 @@ function validateContractSemantics(
production_gate: ["FE-GATE-019", "FE-GATE-021", "FE-GATE-022", "FE-GATE-023", "FE-GATE-024", "FE-GATE-025"],
field_gate: ["FE-GATE-018"],
documentation_gate: ["FE-GATE-017"],
// F2. The checkers' own negative fixtures and the gating coverage check
// run after a merge to main, not on every pull request.
main_gate: ["FE-GATE-029"],
};
if (JSON.stringify(contract.jobs.map(({ id }) => id)) !== JSON.stringify(Object.keys(expectedJobOwnership))) {
issue("job registry must contain the exact twelve canonical jobs in semantic order");
issue("job registry must contain the exact thirteen canonical jobs in semantic order");
}
for (const [jobId, gateIds] of Object.entries(expectedJobOwnership)) {
const job = contract.jobs.find(({ id }) => id === jobId);
@@ -956,6 +862,7 @@ function validateContractSemantics(
production_gate: ["gate-matrix", ["immutable_build", "promotion", "deployment"], "production"],
field_gate: ["gate-single", ["production_gate"], "field"],
documentation_gate: ["gate-single", [], "documentation"],
main_gate: ["gate-sequence", [], "main"],
};
for (const [jobId, [kind, needs, condition]] of Object.entries(expectedJobGraph)) {
const job = contract.jobs.find(({ id }) => id === jobId);
@@ -976,6 +883,7 @@ function validateContractSemantics(
production_gate: ["checkout", "setup-node", "frozen-install", "download", "extract", "run-gate", "upload"],
field_gate: ["checkout", "setup-node", "frozen-install", "run-gate", "upload"],
documentation_gate: ["checkout", "setup-node", "frozen-install", "run-gate", "upload"],
main_gate: ["checkout", "setup-node", "frozen-install", "run-gate", "upload"],
};
for (const [jobId, expected] of Object.entries(expectedStepKinds)) {
const actual = contract.jobs.find(({ id }) => id === jobId)?.steps.map(({ kind }) => kind);
@@ -1049,6 +957,7 @@ function validateContractSemantics(
{ name: "MIN_ELIGIBLE_SAMPLES", value: "${{ vars.MIN_ELIGIBLE_SAMPLES }}" },
],
documentation_gate: [],
main_gate: [],
};
for (const job of contract.jobs) {
const environmentNames = job.environment.map(({ name }) => name);
+8 -4
View File
@@ -108,6 +108,7 @@ export function renderCiWorkflow(
" type: choice",
" options:",
" - merge",
" - main",
" - release",
" - production",
" - field",
@@ -295,9 +296,9 @@ function renderStep(
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}`);
// F1 (design-docs repo-structure/03-ci.md). A job of several gates shares
// one install; each gate is a step named by its id, and a failed gate
// does not skip the ones after it, as the matrix entries did not.
// F2·F1 (design-docs repo-structure/03-ci.md). A job of several gates
// shares one install; each gate is a step named by its id, and a failed
// gate does not skip the ones after it, as the matrix entries did not.
if (job.kind === "gate-sequence") {
return job.gateIds.flatMap((gateId) => [
` - name: ${yamlScalar(`${gateId} / ${index.gates.get(gateId)?.name ?? ""}`)}`,
@@ -437,7 +438,10 @@ function renderCondition(condition: CiWorkflowJob["condition"]): string | null {
const expressions: Record<CiWorkflowJob["condition"], string | null> = {
always: null,
"needs-success": null,
merge: "${{ gitea.event_name != 'workflow_dispatch' || inputs.stage != 'documentation' }}",
merge: "${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }}",
// A push to a branch (main, develop) or a dispatch that asks for it; never
// a pull request or a tag.
main: "${{ (gitea.event_name == 'push' && startsWith(gitea.ref, 'refs/heads/')) || (gitea.event_name == 'workflow_dispatch' && inputs.stage == 'main') }}",
release: "${{ startsWith(gitea.ref, 'refs/tags/v') || (gitea.event_name == 'workflow_dispatch' && (inputs.stage == 'release' || inputs.stage == 'production' || inputs.stage == 'field')) }}",
production: "${{ gitea.event_name == 'workflow_dispatch' && (inputs.stage == 'production' || inputs.stage == 'field') }}",
field: "${{ gitea.event_name == 'workflow_dispatch' && inputs.stage == 'field' }}",
+4 -3
View File
@@ -4,11 +4,11 @@ export const ciContractReportSchema = z
.object({
schemaVersion: z.literal(2),
nodeVersion: z.string().regex(/^\d+\.\d+\.\d+$/u),
gateCount: z.literal(27),
gateCount: z.literal(28),
commandDefinitionCount: z.number().int().positive(),
commandReferenceCount: z.number().int().positive(),
artifactCount: z.number().int().positive(),
jobCount: z.literal(12),
jobCount: z.literal(13),
workflowSha256: z.string().regex(/^[a-f0-9]{64}$/u),
durationStatus: z.string().min(1),
negativeFixtures: z.array(
@@ -20,6 +20,7 @@ export const ciContractReportSchema = z
"PROD_PROMOTION_READY",
"FIELD_SLO_READY",
"DOCUMENTATION_READY",
"MAIN_READY",
]),
failedGate: z.string().regex(/^FE-GATE-\d{3}$/u),
passed: z.boolean(),
@@ -37,7 +38,7 @@ export const ciContractReportSchema = z
fail(["passed"], "passed must agree with failures");
}
if (
report.negativeFixtures.length !== 5 ||
report.negativeFixtures.length !== 6 ||
report.negativeFixtures.some((fixture) => !fixture.passed)
) {
fail(["negativeFixtures"], "every readiness negative fixture must pass");
+6
View File
@@ -40,6 +40,10 @@ export const PROMOTION_FORMULA = Object.freeze({
]),
FIELD_SLO_READY: Object.freeze(["FE-GATE-018"]),
DOCUMENTATION_READY: Object.freeze(["FE-GATE-017"]),
// F2 (design-docs repo-structure/03-ci.md 7.3). The checkers' negative
// fixtures and the gating coverage check run after a merge to main. They
// test the checkers, not the change, so they hold no promotion.
MAIN_READY: Object.freeze(["FE-GATE-029"]),
});
export type GateResult = "PASS" | "FAIL" | "UNVERIFIED";
@@ -58,6 +62,7 @@ export function evaluatePromotionReadiness(
const fieldReady =
productionReady && allPass(PROMOTION_FORMULA.FIELD_SLO_READY);
const documentationReady = allPass(PROMOTION_FORMULA.DOCUMENTATION_READY);
const mainReady = allPass(PROMOTION_FORMULA.MAIN_READY);
return Object.freeze({
MERGE_READY: mergeReady,
@@ -65,5 +70,6 @@ export function evaluatePromotionReadiness(
PROD_PROMOTION_READY: productionReady,
FIELD_SLO_READY: fieldReady,
DOCUMENTATION_READY: documentationReady,
MAIN_READY: mainReady,
});
}
-13
View File
@@ -21,7 +21,6 @@ import {
} from "./fixture-node-modules.ts";
import { generateCiWorkflow } from "../generate-ci-workflow.ts";
import { selectRepositoryPaths } from "./repository-layout.ts";
import { updateCiContractBaseline } from "../update-ci-contract-baseline.ts";
/**
* The fixture-copy set of config/repository-layout.json (R2). It includes the
@@ -510,16 +509,4 @@ export async function pruneRemovalFixtureCiContract(options: Readonly<{
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.
// 1103/16-02. A product feature owns no CI script; an empty list used to
// leave a trailing blank that the baseline schema refuses.
await updateCiContractBaseline(options.root, {
owner: "removal-fixture",
reason: `removal fixture pruned ${
options.removedScripts.size === 0
? "no CI scripts"
: [...options.removedScripts].join(", ")
}`,
});
}
-52
View File
@@ -1,52 +0,0 @@
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`,
);
}
@@ -49,10 +49,6 @@ 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`,
@@ -106,10 +102,6 @@ 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`,
@@ -158,10 +150,6 @@ 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`,
@@ -218,10 +206,6 @@ describe("CI-runner FE-GATE-027 advisory record", () => {
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`,
@@ -18,6 +18,7 @@ on:
type: choice
options:
- merge
- main
- release
- production
- field
@@ -36,7 +37,7 @@ env:
jobs:
merge_static:
name: "merge / static checks"
if: \${{ gitea.event_name != 'workflow_dispatch' || inputs.stage != 'documentation' }}
if: \${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }}
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
@@ -78,7 +79,7 @@ jobs:
merge_test:
name: "merge / tests"
if: \${{ gitea.event_name != 'workflow_dispatch' || inputs.stage != 'documentation' }}
if: \${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }}
# FE-GATE-013 runner requirement: Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers
# FE-GATE-013 runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs
runs-on: ubuntu-latest
@@ -122,7 +123,7 @@ jobs:
merge_browser:
name: "merge / browser tests"
if: \${{ gitea.event_name != 'workflow_dispatch' || inputs.stage != 'documentation' }}
if: \${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }}
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
@@ -574,5 +575,32 @@ jobs:
name: "FE-GATE-017-\${{ gitea.run_id }}"
path: artifacts/
if-no-files-found: error
main_gate:
name: "main / checker self-tests"
if: \${{ (gitea.event_name == 'push' && startsWith(gitea.ref, 'refs/heads/')) || (gitea.event_name == 'workflow_dispatch' && inputs.stage == 'main') }}
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
with:
persist-credentials: false
- uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
with:
node-version-file: .nvmrc
- name: Frozen install
run: |
corepack enable
corepack pnpm install --frozen-lockfile --ignore-scripts
- name: "FE-GATE-029 / checker-self-tests"
if: \${{ !cancelled() }}
run: corepack pnpm ci:gate -- FE-GATE-029
- name: Upload main gate evidence
if: always()
uses: https://github.com/ChristopherHX/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7
with:
name: "main-gate-\${{ gitea.run_id }}"
path: artifacts/
if-no-files-found: error
"
`;
+9 -62
View File
@@ -138,10 +138,6 @@ 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;
}
@@ -186,22 +182,20 @@ describe("CI gate contract", () => {
expect(() => parseCiGateContract(candidate)).toThrow(diagnostic);
});
it("loads the strict v2 registry and preserves the reviewed baseline", async () => {
// The command and artifact counts are not pinned here: the count and shape
// baseline was deleted on 2026-11-08 (design-docs repo-structure/README.md
// 3.3), and the contract's semantic checks hold gate, job and stage shape.
it("loads the strict v2 registry", async () => {
const contract = await loadCiGateContract(process.cwd());
const index = indexCiGateContract(contract);
expect(contract.schemaVersion).toBe(2);
expect(contract.gates.map(({ id }) => id)).toEqual(
Array.from({ length: 28 }, (_, index) =>
Array.from({ length: 29 }, (_, index) =>
`FE-GATE-${String(index + 1).padStart(3, "0")}`,
).filter((gateId) => gateId !== "FE-GATE-016"),
);
expect(contract.jobs).toHaveLength(12);
expect(contract.commands).toHaveLength(76);
expect(contract.gates.reduce((total, gate) => total + gate.commandIds.length, 0)).toBe(80);
expect(contract.commands.filter(({ expect }) => expect === "fail")).toHaveLength(8);
expect(contract.gates.reduce((total, gate) => total + gate.evidenceArtifactIds.length, 0)).toBe(83);
expect(contract.artifacts).toHaveLength(105);
expect(contract.stages).toHaveLength(5);
expect(contract.jobs).toHaveLength(13);
expect(contract.stages).toHaveLength(6);
expect(contract.retention.classes).toHaveLength(5);
expect(index.gates.get("FE-GATE-015")?.commandIds).toHaveLength(2);
expect(index.gates.get("FE-GATE-020")?.name).toBe("removability");
@@ -558,49 +552,6 @@ describe("CI gate contract", () => {
);
});
it("rejects canonical gate name drift through the semantic-shape digest", async () => {
const root = await mkdtemp(path.join(tmpdir(), "ci-contract-gate-name-shape-"));
temporaryRoots.push(root);
await mkdir(path.join(root, "config/ci"), { recursive: true });
const contract = JSON.parse(
JSON.stringify(await loadCiGateContract(process.cwd())),
) as Record<string, any>;
const gate = contract.gates.find(
(candidate: Record<string, any>) => candidate.id === "FE-GATE-013",
);
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 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("rejects runner requirement drift through the semantic-shape digest (1105/12-01)", async () => {
const root = await mkdtemp(path.join(tmpdir(), "ci-contract-host-shape-"));
temporaryRoots.push(root);
await mkdir(path.join(root, "config/ci"), { recursive: true });
const contract = JSON.parse(
JSON.stringify(await loadCiGateContract(process.cwd())),
) as Record<string, any>;
const gate = contract.gates.find(
(candidate: Record<string, any>) => candidate.id === "FE-GATE-013",
);
expect(gate.hostRequirements?.length).toBeGreaterThan(0);
gate.hostRequirements = gate.hostRequirements.slice(1);
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, "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"])(
"rejects a missing nested check:ci dependency: %s",
async (removedScript) => {
@@ -1598,10 +1549,6 @@ 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")], {
@@ -1640,7 +1587,7 @@ describe("CI workflow generation", () => {
expect(first).toContain("persist-credentials: false");
expect(
first.match(/corepack pnpm install --frozen-lockfile --ignore-scripts/gu),
).toHaveLength(11);
).toHaveLength(12);
expect(first).not.toMatch(/corepack pnpm install --frozen-lockfile$/mu);
expect(first).toContain("verify-ci-candidate-archive.ts --archive");
// Providers and promotion read the archive without extracting it; only the
@@ -1676,7 +1623,7 @@ describe("CI workflow generation", () => {
'if [ -n "$PROMOTION_STAGING_ROOT" ] && [ -n "$PROMOTION_CLEANUP_TOKEN" ] && [ -n "$PROMOTION_RUNNER_TEMP_DEV" ] && [ -n "$PROMOTION_RUNNER_TEMP_INO" ] && [ -n "$PROMOTION_STAGING_DEV" ] && [ -n "$PROMOTION_STAGING_INO" ]; then',
);
const actionUses = [...first.matchAll(/^\s+-?\s*uses: (.+)$/gmu)].map((match) => match[1]);
expect(actionUses).toHaveLength(40);
expect(actionUses).toHaveLength(43);
expect(new Set(actionUses)).toEqual(
new Set([
"https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5",
+13 -3
View File
@@ -36,10 +36,20 @@ describe("feature scaffold drill commands", () => {
}
});
// 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 = await loadCiGateContract(process.cwd());
expect(scaffoldDrillCommands(contract).find(({ script }) => script === "check:coverage:fixture"))
.toMatchObject({ expectation: { kind: "fail", expectedExitCode: 1, expectedDiagnosticId: "Risk coverage failed:" } });
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 () => {
+4 -5
View File
@@ -32,9 +32,7 @@ async function productRoot(
const root = await mkdtemp(path.join(tmpdir(), "product-ci-overlay-"));
roots.push(root);
await mkdir(path.join(root, "config/ci"), { recursive: true });
for (const file of ["config/ci/gates.json", "config/ci/contract-baseline.json"]) {
await writeFile(path.join(root, file), await readFile(file));
}
await writeFile(path.join(root, "config/ci/gates.json"), await readFile("config/ci/gates.json"));
const packageDocument = JSON.parse(await readFile("package.json", "utf8")) as {
scripts: Record<string, string>;
};
@@ -72,7 +70,6 @@ describe("product CI overlay (1103/12-07)", () => {
DEPLOY_SCRIPTS,
);
// The template baseline (config/ci/contract-baseline.json) is unchanged.
const contract = await loadCiGateContract(root);
const slot = contract.jobs.find(({ id }) => id === "deployment");
expect(slot?.steps.map(({ kind }) => kind)).toEqual([
@@ -143,7 +140,9 @@ describe("product CI overlay (1103/12-07)", () => {
const job = workflow.slice(workflow.indexOf(" product_merge_gate:\n"));
expect(job).toContain(' - { gate: PRODUCT-GATE-001, name: backend-contract, script: "check:backend-contract" }');
expect(job).toContain(" run: corepack pnpm ${{ matrix.script }}");
expect(job).toContain(` if: ${"${{ gitea.event_name != 'workflow_dispatch' || inputs.stage != 'documentation' }}"}`);
expect(job).toContain(
` if: ${"${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }}"}`,
);
expect(workflowGateExecutionFailures(contract, workflow, mergeGates)).toEqual([]);
// The template part of the workflow is the same bytes with or without the
// overlay, except that the release stage waits for the product job (1105/13-02).
+2
View File
@@ -19,6 +19,7 @@ describe("promotion readiness formula", () => {
PROD_PROMOTION_READY: true,
FIELD_SLO_READY: true,
DOCUMENTATION_READY: true,
MAIN_READY: true,
});
});
@@ -30,6 +31,7 @@ describe("promotion readiness formula", () => {
["FE-GATE-021", "PROD_PROMOTION_READY"],
["FE-GATE-018", "FIELD_SLO_READY"],
["FE-GATE-017", "DOCUMENTATION_READY"],
["FE-GATE-029", "MAIN_READY"],
] as const)("fails closed when %s fails", (failedGate, readiness) => {
const result = evaluatePromotionReadiness({
...passing,
+4 -26
View File
@@ -64,15 +64,13 @@ 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 });
for (const file of ["config/ci/gates.json", "config/ci/contract-baseline.json", "package.json"]) {
for (const file of ["config/ci/gates.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 () => {
it("prunes removed command and evidence references and loads the reduced contract", async () => {
const root = await copyCiContract("removal-fixture-contract-");
// A command with evidence of its own, as a removed sample's tests had. Not
@@ -91,10 +89,6 @@ it("prunes removed command and evidence references and re-baselines the contract
expect(contract.gates.some(({ evidenceArtifactIds }) =>
evidenceArtifactIds.includes("artifact-artifacts-tests-integration-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>;
};
@@ -102,9 +96,8 @@ it("prunes removed command and evidence references and re-baselines the contract
});
// 1103/16-02. A product feature owns no CI script, so its removal prunes
// nothing. The baseline reason then ended in a blank ("removal fixture pruned
// ") and the baseline schema refused it before any gate ran.
it("re-baselines a removal that prunes no CI script", async () => {
// nothing, and the contract still loads.
it("loads a removal that prunes no CI script", async () => {
const root = await copyCiContract("removal-fixture-no-scripts-");
await pruneRemovalFixtureCiContract({
@@ -113,24 +106,9 @@ it("re-baselines a removal that prunes no CI script", async () => {
removedEvidencePathFragments: [],
});
const baseline = JSON.parse(
await readFile(path.join(root, "config/ci/contract-baseline.json"), "utf8"),
) as Record<string, unknown>;
expect(baseline["reason"]).toBe("removal fixture pruned no CI scripts");
await expect(loadCiGateContract(root)).resolves.toBeDefined();
});
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 copyCiContract("removal-fixture-empty-gate-");
+3 -1
View File
@@ -454,10 +454,12 @@ describe("supply-chain policy", () => {
).rejects.toThrow(/did not fail exactly/u);
});
// The checkers' own negative fixtures run in the main stage (FE-GATE-029)
// since 2026-11-08 (design-docs repo-structure/03-ci.md F2).
it("wires the exact security fixture checker as a passing CI gate", async () => {
const contract = await loadCiGateContract(process.cwd());
const index = indexCiGateContract(contract);
const securityGate = index.gates.get("FE-GATE-013");
const securityGate = index.gates.get("FE-GATE-029");
expect(securityGate).toBeDefined();
const commands = securityGate!.commandIds.map((commandId) =>
index.commands.get(commandId),
+5 -13
View File
@@ -7,12 +7,7 @@ import { pathToFileURL } from "node:url";
import { afterEach, describe, expect, it } from "vitest";
import {
CI_CONTRACT_BASELINE_PATH,
loadCiGateContract,
measureCiContractBaseline,
parseCiGateContract,
} from "../../scripts/contracts/ci-gates.ts";
import { loadCiGateContract, parseCiGateContract } from "../../scripts/contracts/ci-gates.ts";
import { generateCiWorkflow } from "../../scripts/generate-ci-workflow.ts";
import { validatePackageScriptGraph } from "../../scripts/lib/package-script-graph.ts";
@@ -188,14 +183,11 @@ describe("selective Task 3 contract closure", () => {
.toContain("package script missing: root -> missing");
});
// 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 () => {
// The count and gate-shape baseline (D-13, config/ci/contract-baseline.json)
// was deleted on 2026-11-08 (owner decision, design-docs repo-structure/
// README.md 3.3): the contract's own semantic checks hold its shape.
it("rejects orphan retention", async () => {
const canonical = await loadCiGateContract(process.cwd());
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>;