Skip to content

feat(scripts): guard sync-policies against outdated PrGovernance pins - #72

Merged
cgl-agent-coordinator[bot] merged 1 commit into
mainfrom
feat/sync-policies-pin-guard
Dec 4, 2026
Merged

cgl-agent-coordinator[bot] merged 1 commit into
mainfrom
feat/sync-policies-pin-guard

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

AI assistance

  • Model: Antigravity (planning + implementation); verified locally with full Node test suites and dry-run.

What changed

  • Added MIN_POLICY_PIN_SHA (b540fc2eed7fa0a80c1a70b419581df2a49b0eec), extractRiskGatePin(), and isPinAtLeast() to scripts/sync-policies.mjs.
  • Before opening a chore/policy-tier PR, sync-policies.mjs checks .github/workflows/risk-gate.yml on the target repository's default branch and compares the pinned CodeGovernanceLab/PrGovernance SHA against MIN_POLICY_PIN_SHA (unless --skip-pin-check is explicitly passed), safely skipping repositories still on older evaluators so unknown policy keys never break downstream risk-gate validation.
  • Added unit tests for extractRiskGatePin and isPinAtLeast in scripts/test-sync-policies.cjs.

How verified

  • node --test pr-governance/scripts/test-*.cjs scripts/test-*.cjs: all tests passed (0 failures).
  • node scripts/sync-policies.mjs --dry-run --org Pigbibi: verified outdated repositories are safely skipped (skipped 7, failed 0).
  • /usr/local/bin/gitleaks git --config pr-governance/.gitleaks.toml --log-opts="origin/main..HEAD" --redact: no leaks found.

Why

  • Prevents rollout-ordering failures where syncing new tier fields (require_clearing_label_on_r2, require_owner_approval_on_r2) before updating PrGovernance pins breaks downstream validatePolicy (sameKeys).

Risk

  • R1 (scripts/sync-policies.mjs, scripts/test-sync-policies.cjs): operator CLI script and unit tests only; no pr-governance/ evaluator changes.

Co-authored-by: Antigravity <noreply@google.com>
@cgl-opencode-reviewer

Copy link
Copy Markdown

AI Code Review (opencode / glm-5.4)

The pin-guard helpers (extractRiskGatePin, isPinAtLeast) are correct, conservative (diverged/unknown statuses fail closed), and unit-tested, and the compare-API direction (MIN...pinned with 'ahead'/'identical') is right. However, the new guard in main() wraps all GitHub API calls in a catch-all that silently converts network, auth, rate-limit, and unexpected-response failures into a 'skipped (pin ... predates ...)' result counted under skipped with failed 0, which misreports infrastructure errors as outdated pins and can mask a totally non-functional run (e.g., bad token) behind a clean summary. Minor duplication and untested integration glue round out the findings.

Reviewed commit: 1e6f5a236e · Coverage: complete · Unresolved findings: true

Findings

  • [MEDIUM] scripts/sync-policies.mjs: The new pin-check block swallows every error from the contents/compare API calls (catch { status = ''; }) and then reports the repository as skipped (pin missing/xxxxxxxx predates ...; run sync-pins first). Transient network failures, rate limits, or an invalid/expired token (401 on every repo) are thereby indistinguishable from genuinely outdated pins: the run prints skipped N, failed 0 and exits successfully while silently doing nothing, which defeats the operator's ability to detect a broken rollout (the PR's own dry-run output skipped 7, failed 0 cannot be trusted to mean 7 repos are on old pins). Catch only the expected 'file not found' case (e.g., 404) as a skip, and surface other API failures distinctly (separate counter/reason and non-zero exit or at least a 'pin check failed: ' message) instead of conflating them with the outdated-pin skip reason.
  • [LOW] scripts/test-sync-policies.cjs: Tests cover only the pure helpers; the new main()-loop guard (skip on missing risk-gate.yml, skip on compare failure, --skip-pin-check bypass) has no coverage. Since api/retry are module-level functions, consider a small test with a stubbed api (or extracting the per-repo pin check into an exported, injectable function) so the skip-vs-proceed decision and its distinct failure reasons are regression-tested.
  • [LOW] scripts/sync-policies.mjs: Minor duplication/robustness: the 40-hex SHA regex is repeated in main() and inside isPinAtLeast (extract a shared isValidSha helper or rely on isPinAtLeast's check), and GOVERNANCE_REPO is interpolated unescaped into new RegExp(...) — harmless for the current name but latent breakage if the constant ever gains regex metacharacters; prefer escaping it or building the pattern from a literal.

@cgl-agent-coordinator cgl-agent-coordinator Bot added the agent-approved Agent-approved governance exception label Dec 4, 2026
@cgl-agent-coordinator
cgl-agent-coordinator Bot merged commit b6cbae3 into main Dec 4, 2026
11 checks passed
@cgl-agent-coordinator
cgl-agent-coordinator Bot deleted the feat/sync-policies-pin-guard branch December 4, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-approved Agent-approved governance exception

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant