From 282a842e97cbd573558e075890325cfecf322532 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Sun, 8 Nov 2026 22:03:17 -0600 Subject: [PATCH] =?UTF-8?q?feat(ci):=20ci-policy=20agreement=20checker=20?= =?UTF-8?q?=E2=80=94=20Phase=201=20of=20#7089?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tier-to-trigger mapping pinned in ci-policy.md (PR tier = pull_request, main tier = push to main or a named equivalent venue, nightly = schedule; workflow_dispatch-only and merge_group satisfy no tier after the 2026-11-08 no-merge-queue ruling), production-line guards missing tier row added, and the agreement contract section records scope, dispositions, and the waiver set. New checker .github/scripts/check-ci-policy-agreement.sh compares every in-scope workflows tier, declared triggers, and the recorded waivers (oracle: the three must agree; unwaived disagreements and stale waivers both fail), with shell contract tests, wired into workflow-lint. The Phase 2-3 disagreements land as explicit waivers naming their phase issues (#6929, #6953, #6959, #6981) so the checker is green with the set explicit: 10 workflows checked, 12 waived legs. No workflow re-armed, re-enabled, or trigger-changed. --- .github/ci-policy.md | 67 ++++++ .github/scripts/check-ci-policy-agreement.sh | 216 ++++++++++++++++++ .../scripts/check-ci-policy-agreement.test.sh | 108 +++++++++ .github/workflows/workflow-lint.yml | 7 + 4 files changed, 398 insertions(+) create mode 100755 .github/scripts/check-ci-policy-agreement.sh create mode 100755 .github/scripts/check-ci-policy-agreement.test.sh diff --git a/.github/ci-policy.md b/.github/ci-policy.md index b61f18797b..326664ea6b 100644 --- a/.github/ci-policy.md +++ b/.github/ci-policy.md @@ -175,6 +175,73 @@ main-breakage rate (issues labelled `main-broken`) proves out. | mcpx, lab-ops-hub, mod-tidy, research-workflow | unchanged path-gated PR checks (already PR-tier weight) | push to main | — | | mcpx test (#1998) | init + unit + lint + 6 static e2e shards + ci-ok (PR tier, non-draft PRs) | same full sharded suite on push to main | — (main covers it) | | mcpx fix-test guard (#1969) | fix PRs touching `pkgs/mcpx/**` must carry a test or a `No test: ` attestation (basic tier) | contract tests for the guard script only | — | +| production-line guard (#1411) | `basic: production line limit (2500)` on `pull_request` | — | — | + +## CI-policy agreement contract (#7089, Phase 1) + +For every workflow in this contract's scope, three records must +agree: the tier this policy assigns, the triggers the workflow +declares, and the Actions enablement state. A disagreement in any +leg is a defect with exactly one recorded disposition — **re-arm** +(triggers restored to the mapping + venue enabled + a completed run +on main as proof), **fold** (the check moves into a named venue that +satisfies the contract), or **retire** (workflow, policy row, and +header promises removed in the same change) — never a state that +persists by default. "Dispatch-only and nobody dispatches" is not a +disposition. + +**Tier → trigger mapping** (the checker below enforces exactly +this): + +| tier | satisfied by | +| ---------------- | ---------------------------------------------------------------------------- | +| PR (basic) tier | a `pull_request` trigger (with the workflow's path gate where one exists) | +| main tier | a `push` trigger on `branches: [main]` (path gates as before), or a named equivalent main-tier venue running the same check | +| nightly tier | a `schedule` trigger | + +A `workflow_dispatch:`-only block satisfies **no** tier, and +`merge_group` satisfies no tier either: there is no merge queue +(Drew ruling, 2026-11-08, above), which supersedes the #7089 +design's original merge_group pin for basic-tier guards — the +guards that ran only on `merge_group` now run on `pull_request`, +and this contract's mapping follows that ruling. + +**Scope.** The guard/build workflows this policy names outside the +test-suite estate (#6185's registry owns suite venues): +`workflow-lint`, `proxy-port-fallbacks`, and +`fleet-search-parity-guard` (the conforming basic-tier guards), +`opencode-config-guard`, `mcpx-fix-test-guard`, +`production-line-guard`, and the build set `go-modules-build`, +`identity-build`, `map-build`, `mcpx-nixbuild`. Phase 4 of #7089 +inventories widening this scope to every workflow this policy +names. + +**Checking.** `.github/scripts/check-ci-policy-agreement.sh` +compares each in-scope workflow's tier assignment against its +declared triggers in the tree and runs in `workflow-lint`; shell +contract tests live in +`.github/scripts/check-ci-policy-agreement.test.sh` (oracle: for +every in-scope workflow, tier, declared triggers, and the recorded +waiver set must agree). Enablement is not visible from the tree: +it is audited from the Actions API on the #6187 recurring cadence, +and a disabled in-scope venue is reported with its disposition. +At Phase 1 landing, the disabled in-scope venues are exactly the +waiver set below (opencode-config-guard and the #6981 build set +are `disabled_manually`). + +**Waivers — the recorded Phase 2–3 disagreement set.** Each waiver +names its phase issue and awaits Drew's re-arm-vs-dispatch-only +ruling on #7089; a waiver is a record, not a disposition. When a +phase lands or is ruled, the waiver is deleted in the same PR that +changes the triggers or strikes the tier — the checker fails on a +stale waiver whose leg now agrees. + +| workflow | missing leg(s) | phase issue | +| ------------------------------------------------- | ------------------------------------------------------- | ----------- | +| opencode-config-guard | main tier (`push`); venue `disabled_manually` | Phase 2 — #6953 | +| mcpx-fix-test-guard | PR tier (`pull_request`) and main tier (`push`) | Phase 2 — #6929 | +| production-line-guard | PR tier (`pull_request`) | Phase 3 — #6959 | +| go-modules-build, identity-build, map-build, mcpx-nixbuild | PR tier (`pull_request`) and main tier (`push`); venues `disabled_manually` | Phase 3 — #6981 | ## Coverage rule diff --git a/.github/scripts/check-ci-policy-agreement.sh b/.github/scripts/check-ci-policy-agreement.sh new file mode 100755 index 0000000000..2b8335fc38 --- /dev/null +++ b/.github/scripts/check-ci-policy-agreement.sh @@ -0,0 +1,216 @@ +#!/usr/bin/env bash +# CI-policy agreement checker (#7089, Phase 1 of the ci-policy +# agreement contract; design: code-ci-policy-agreement.md). +# +# The contract: for every workflow in the registry below, three +# records must agree — the tier(s) .github/ci-policy.md assigns, the +# triggers the workflow declares, and the recorded waiver set. A +# disagreement with no waiver fails, naming the workflow and the +# missing leg; a waiver whose leg now agrees is stale and also +# fails, so the waiver set cannot silently outlive the disagreement +# it records. Enablement (Actions API state, e.g. disabled_manually) +# is not visible from the tree: it is audited on the #6187 recurring +# cadence, and the currently disabled in-scope venues are exactly +# the waiver set below (recorded in ci-policy.md, #7089 section). +# +# Tier -> trigger mapping (pinned in ci-policy.md, #7089 section; +# updated for Drew's 2026-11-08 no-merge-queue ruling, which +# supersedes the design's original merge_group pin): +# pr (basic/PR tier) -> pull_request trigger +# main (main tier) -> push trigger (branches: [main]) +# nightly (nightly tier) -> schedule trigger +# A workflow_dispatch-only block satisfies NO tier. +# +# Usage: check-ci-policy-agreement.sh [ROOT] (default: repo root) +set -euo pipefail + +ROOT="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)}" +POLICY="$ROOT/.github/ci-policy.md" +WF_DIR="$ROOT/.github/workflows" + +# Registry: workflow-file|ci-policy marker|assigned tiers. +# The marker is text that must appear in ci-policy.md (the workflow's +# tier-table row or section), so a policy row cannot silently vanish. +# Scope: the guard/build workflows the #7089 contract covers — the +# Phase 2-3 set (#6929, #6953, #6959, #6981) plus the conforming +# basic-tier guards. Test-suite venues are #6185's registry, not +# this one; Phase 4 of #7089 inventories widening the scope. +REGISTRY=( + "workflow-lint.yml|workflow-lint|pr" + "proxy-port-fallbacks.yml|proxy-port-fallbacks|pr" + "fleet-search-parity-guard.yml|fleet-search-parity-guard|pr" + "opencode-config-guard.yml|opencode-config-guard|pr,main" + "mcpx-fix-test-guard.yml|mcpx fix-test guard|pr,main" + "production-line-guard.yml|production-line guard|pr" + "go-modules-build.yml|go modules build|pr,main" + "identity-build.yml|identity build|pr,main" + "map-build.yml|map build|pr,main" + "mcpx-nixbuild.yml|mcpx nix build|pr,main" +) + +# Waivers: workflow-file|tier-leg|phase issue. Each waiver records a +# Phase 2-3 disagreement of #7089 that awaits Drew's +# re-arm-vs-dispatch-only ruling; it is not a disposition. When a +# phase lands (or is ruled retire), delete the waiver in the same PR +# that changes the triggers or the policy row. +WAIVERS=( + # Phase 2 (#6953): venue disabled_manually; pull_request leg + # restored by the 2026-11-08 sweep fix, main-tier push leg missing. + "opencode-config-guard.yml|main|6953" + # Phase 2 (#6929): dispatch-only; neither tier leg declared, and + # the enforcement step is pull_request-gated so even a dispatch + # never runs the #1969 guard. + "mcpx-fix-test-guard.yml|pr|6929" + "mcpx-fix-test-guard.yml|main|6929" + # Phase 3 (#6959): dispatch-only; the guard's ci-policy row is new + # in Phase 1 and its PR leg awaits the Phase 3 disposition. + "production-line-guard.yml|pr|6959" + # Phase 3 (#6981): all four dispatch-only AND disabled_manually; + # neither tier leg declared. + "go-modules-build.yml|pr|6981" + "go-modules-build.yml|main|6981" + "identity-build.yml|pr|6981" + "identity-build.yml|main|6981" + "map-build.yml|pr|6981" + "map-build.yml|main|6981" + "mcpx-nixbuild.yml|pr|6981" + "mcpx-nixbuild.yml|main|6981" +) + +required_trigger() { + case "$1" in + pr) echo "pull_request" ;; + main) echo "push" ;; + nightly) echo "schedule" ;; + *) echo "" ;; + esac +} + +# triggers_of : print the declared trigger names of +# the workflow's on: block, one per line. Handles the block form +# (two-space-indented keys) and the single-line forms +# (on: push, on: [push, pull_request]). +triggers_of() { + local file="$1" + awk ' + /^"?on"?:[[:space:]]*\[/ { + line = $0 + sub(/^"?on"?:[[:space:]]*\[/, "", line) + sub(/\].*/, "", line) + n = split(line, parts, ",") + for (i = 1; i <= n; i++) { + gsub(/[[:space:]]/, "", parts[i]) + if (parts[i] != "") print parts[i] + } + exit + } + /^"?on"?:[[:space:]]*[a-z_]/ { + line = $0 + sub(/^"?on"?:[[:space:]]*/, "", line) + sub(/[[:space:]].*/, "", line) + print line + exit + } + /^"?on"?:[[:space:]]*$/ { inblock = 1; next } + inblock && /^ [a-z_]+:/ { + key = $0 + sub(/^ /, "", key) + sub(/:.*/, "", key) + print key + next + } + inblock && /^[^[:space:]#]/ { inblock = 0 } + ' "$file" +} + +waiver_for() { # waiver_for -> issue or empty + local entry + for entry in "${WAIVERS[@]}"; do + if [ "${entry%%|*}" = "$1" ]; then + local rest="${entry#*|}" + if [ "${rest%%|*}" = "$2" ]; then + echo "${rest#*|}" + return 0 + fi + fi + done + echo "" +} + +fail=0 +checked=0 +waived=0 +declare -A SEEN_WAIVER=() + +if [ ! -f "$POLICY" ]; then + echo "::error::ci-policy agreement: $POLICY not found" + exit 1 +fi + +for row in "${REGISTRY[@]}"; do + file="${row%%|*}" + rest="${row#*|}" + marker="${rest%%|*}" + tiers="${rest#*|}" + checked=$((checked + 1)) + wf="$WF_DIR/$file" + if [ ! -f "$wf" ]; then + echo "::error::DISAGREEMENT $file: workflow file missing (ci-policy assigns tiers: $tiers)" + fail=1 + continue + fi + if ! grep -qiF "$marker" "$POLICY"; then + echo "::error::DISAGREEMENT $file: ci-policy.md names no row/section for it (marker '$marker' absent) — every in-scope workflow needs a tier row" + fail=1 + fi + triggers="$(triggers_of "$wf")" + IFS=',' read -ra tier_list <<<"$tiers" + for tier in "${tier_list[@]}"; do + req="$(required_trigger "$tier")" + if printf '%s\n' "$triggers" | grep -qx "$req"; then + if [ -n "$(waiver_for "$file" "$tier")" ]; then + echo "::error::STALE WAIVER $file: $tier leg now agrees (trigger '$req' declared) — delete the waiver for issue #$(waiver_for "$file" "$tier") in this PR" + fail=1 + fi + else + issue="$(waiver_for "$file" "$tier")" + if [ -n "$issue" ]; then + SEEN_WAIVER["$file|$tier"]=1 + waived=$((waived + 1)) + echo "::warning::WAIVED $file: $tier tier requires trigger '$req', not declared — disagreement recorded against issue #$issue (Phase 2-3 of #7089, awaiting Drew's ruling)" + else + echo "::error::DISAGREEMENT $file: $tier tier requires trigger '$req', not declared and no waiver records it — restore the trigger, strike the tier from ci-policy.md, or record a waiver naming its phase issue (#7089)" + fail=1 + fi + fi + done +done + +# A waiver for a leg the registry never requires is a defect too: +# it would record a disagreement that cannot exist. +for entry in "${WAIVERS[@]}"; do + wfile="${entry%%|*}" + wrest="${entry#*|}" + wleg="${wrest%%|*}" + if [ -z "${SEEN_WAIVER["$wfile|$wleg"]:-}" ]; then + # Either the leg agrees (already reported stale above when the + # workflow is registered) or the workflow/leg is unknown here. + known=0 + for row in "${REGISTRY[@]}"; do + if [ "${row%%|*}" = "$wfile" ]; then + known=1 + fi + done + if [ "$known" -eq 0 ]; then + echo "::error::UNKNOWN WAIVER $entry: workflow is not in the agreement registry" + fail=1 + fi + fi +done + +echo "ci-policy-agreement: checked $checked workflows, $waived waived disagreement(s)" +if [ "$fail" -ne 0 ]; then + echo "ci-policy-agreement: FAILED - disagreement(s) without a recorded waiver listed above" + exit 1 +fi +echo "ci-policy-agreement: OK" diff --git a/.github/scripts/check-ci-policy-agreement.test.sh b/.github/scripts/check-ci-policy-agreement.test.sh new file mode 100755 index 0000000000..1bb7011005 --- /dev/null +++ b/.github/scripts/check-ci-policy-agreement.test.sh @@ -0,0 +1,108 @@ +#!/usr/bin/env bash +# Contract tests for check-ci-policy-agreement.sh (#7089 Phase 1). +# Oracle: the agreement contract — for every ci-policy-named +# workflow in the registry, tier, declared triggers and the recorded +# waiver set must agree; a disagreement without a waiver fails +# naming the workflow and the leg, and a waiver whose leg now +# agrees is stale and fails. +set -euo pipefail + +SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/check-ci-policy-agreement.sh" +TMP="$(mktemp -d)" +trap 'rm -rf "$TMP"' EXIT + +wf() { # wf + local root="$1" file="$2" + shift 2 + mkdir -p "$root/.github/workflows" + { + echo "name: $file" + echo "on:" + for t in "$@"; do echo " $t:"; done + echo "jobs: {}" + } >"$root/.github/workflows/$file" +} + +policy() { # policy : a ci-policy.md naming every registry row + local root="$1" + mkdir -p "$root/.github" + cat >"$root/.github/ci-policy.md" <<'EOF' +| workflow-lint | basic | — | — | +| proxy-port-fallbacks | basic | — | — | +| fleet-search-parity-guard | basic | — | — | +| opencode-config-guard | basic | main | — | +| mcpx fix-test guard (#1969) | basic | main | — | +| production-line guard (#1411) | basic | — | — | +| go modules build / identity build / map build / mcpx nix build | class-3 | main | — | +EOF +} + +build_tree() { # build_tree : the current-main shape + local root="$1" + policy "$root" + wf "$root" workflow-lint.yml pull_request workflow_dispatch + wf "$root" proxy-port-fallbacks.yml pull_request + wf "$root" fleet-search-parity-guard.yml pull_request workflow_dispatch + wf "$root" opencode-config-guard.yml pull_request workflow_dispatch + wf "$root" mcpx-fix-test-guard.yml workflow_dispatch + wf "$root" production-line-guard.yml workflow_dispatch + wf "$root" go-modules-build.yml workflow_dispatch + wf "$root" identity-build.yml workflow_dispatch + wf "$root" map-build.yml workflow_dispatch + wf "$root" mcpx-nixbuild.yml workflow_dispatch +} + +# Agreeing-with-waivers tree: exactly the recorded Phase 2-3 +# disagreement set, everything else in agreement — passes, and every +# waived leg is reported. +build_tree "$TMP/ok" +bash "$SCRIPT" "$TMP/ok" >"$TMP/ok.out" +grep -q "ci-policy-agreement: OK" "$TMP/ok.out" +grep -q "WAIVED mcpx-fix-test-guard.yml: pr tier" "$TMP/ok.out" +grep -q "WAIVED go-modules-build.yml: main tier" "$TMP/ok.out" +grep -q "issue #6981" "$TMP/ok.out" +echo "pass: tree with exactly the waived disagreement set passes" + +# Unwaived disagreement: workflow-lint loses its pull_request leg. +build_tree "$TMP/bad" +wf "$TMP/bad" workflow-lint.yml workflow_dispatch +if bash "$SCRIPT" "$TMP/bad" >"$TMP/bad.out" 2>&1; then + echo "FAIL: checker accepted an unwaived disagreement" >&2 + exit 1 +fi +grep -q "DISAGREEMENT workflow-lint.yml: pr tier requires trigger 'pull_request'" "$TMP/bad.out" +echo "pass: unwaived disagreement fails naming the workflow and leg" + +# Stale waiver: mcpx-nixbuild gains its main-tier push leg, so the +# #6981 main waiver for it must be deleted, not left behind. +build_tree "$TMP/stale" +wf "$TMP/stale" mcpx-nixbuild.yml workflow_dispatch push +if bash "$SCRIPT" "$TMP/stale" >"$TMP/stale.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/stale.out" +echo "pass: a waiver whose leg now agrees fails as stale" + +# Missing policy row: production-line guard's row vanishes. +build_tree "$TMP/norow" +grep -v "production-line guard" "$TMP/norow/.github/ci-policy.md" >"$TMP/norow/policy.tmp" +mv "$TMP/norow/policy.tmp" "$TMP/norow/.github/ci-policy.md" +if bash "$SCRIPT" "$TMP/norow" >"$TMP/norow.out" 2>&1; then + echo "FAIL: checker accepted a missing ci-policy row" >&2 + exit 1 +fi +grep -q "DISAGREEMENT production-line-guard.yml: ci-policy.md names no row" "$TMP/norow.out" +echo "pass: a vanished ci-policy row fails naming the workflow" + +# Missing workflow file. +build_tree "$TMP/nofile" +rm "$TMP/nofile/.github/workflows/map-build.yml" +if bash "$SCRIPT" "$TMP/nofile" >"$TMP/nofile.out" 2>&1; then + echo "FAIL: checker accepted a missing workflow file" >&2 + exit 1 +fi +grep -q "DISAGREEMENT map-build.yml: workflow file missing" "$TMP/nofile.out" +echo "pass: a missing workflow file fails naming it" + +echo "check-ci-policy-agreement.test: all contract tests passed" diff --git a/.github/workflows/workflow-lint.yml b/.github/workflows/workflow-lint.yml index 26a1427539..a9155c625a 100644 --- a/.github/workflows/workflow-lint.yml +++ b/.github/workflows/workflow-lint.yml @@ -18,6 +18,9 @@ on: - ".github/actions/**" - ".github/scripts/check-workflows.sh" - ".github/scripts/check-workflows.test.sh" + - ".github/ci-policy.md" + - ".github/scripts/check-ci-policy-agreement.sh" + - ".github/scripts/check-ci-policy-agreement.test.sh" workflow_dispatch: permissions: @@ -56,3 +59,7 @@ jobs: run: bash .github/scripts/check-workflows.test.sh - name: Validate workflows and composite actions run: bash .github/scripts/check-workflows.sh + - name: Contract tests for the ci-policy agreement checker (#7089) + run: bash .github/scripts/check-ci-policy-agreement.test.sh + - name: CI-policy agreement check (#7089) + run: bash .github/scripts/check-ci-policy-agreement.sh