Repository navigation
Description
Problem
petry-projects/.github-private has a required duplicate-decl-gate check — added by #1520 after the #1485 trunk-corruption incident, and again after PR #1378 re-corrupted trunk on 2026-08-14. petry-projects/.github has no equivalent workflow, and its branch ruleset requires only:
SonarCloud · CodeQL · agent-shield / AgentShield · dependency-audit / Detect ecosystems
So the guard built specifically to block this corruption class protects one org-infra repo and not the other.
It just recurred, in the unguarded repo
PR #1024 (implementing #1023) reached review with duplicated content and nothing blocked it:
DUP scripts/canary-rollout.sh 2× _watched_paths()
DUP scripts/compliance-audit.sh 3× ensure_required_labels()
AGENTS.md: 23 top-level headings vs 12 on main
Intended scope was ~4 files; the PR is 15 files, +2054/-30, with the excess appearing as pure +X/-0 additions across unrelated files (AGENTS.md +611, standards/ci-standards.md +318, standards/canary-rings.json +315, scripts/compliance-audit.sh +62, …).
It also left scripts/apply-repo-settings.sh unparseable — a duplicated source-guard block produced an unmatched brace:
$ bash -n scripts/apply-repo-settings.sh
line 498: syntax error near unexpected token `}'
That script drives the fleet-wide apply-repo-settings workflow, so merging it would have broken repo-settings self-heal everywhere — the very capability #984/#985 just delivered.
What did catch it: the manual duplicate-declaration sweep (the standing session-start habit), plus CodeRabbit independently flagging the brace as 🔴 Critical. Neither is a merge gate in this repo. Existing lint checks did not catch the duplication — ShellCheck and Lint and bats failed for other reasons, and a duplicated-but-valid function definition is not a shellcheck error at all.
Why this matters more than one bad PR
#1520's own rationale was that two green-checked corruptions proved advisory detection is insufficient — hence a required gate. That reasoning applies identically to .github, which hosts the reusables the whole fleet pins: apply-repo-settings, agent-shield, dependency-audit, auto-rebase, add-to-project, canary-rollout, and the standards themselves. A corrupted reusable there propagates to every consumer on the next channel promotion.
Acceptance criteria
- Port the
duplicate-decl-gateworkflow frompetry-projects/.github-privatetopetry-projects/.github(same detection: a top-level declaration appearing more than once in a shell file). - Add it to
.github's branch ruleset as a required status check, matching.github-private. - Extend detection beyond
scripts/*.shwhere cheap — theAGENTS.mdduplication (23 vs 12 top-level headings) would not be caught by a shell-only sweep, and markdown/JSON standards files are equally load-bearing here. - Test: a PR that duplicates a function declaration fails the gate; a clean PR passes.
- Audit
.github's currentmainfor pre-existing duplication that landed while unguarded — the gate only prevents new cases. - Confirm no other org-infra repo hosting reusables lacks the gate.
Related: #1485 (original corruption), #1520 (the gate, private repo), PR #1378 (second corruption), PR #1024 (this recurrence), petry-projects/.github#1023.
Activity
don-petry commentedon Aug 31, 2026
Dev-Lead Implementation Plan
Issue: #1025 — port the
duplicate-decl-gatefrom.github-privateto.githubScope
Port the required
duplicate-decl-gateCI check (top-level duplicate-declaration detector for the #1485 corruption class) intopetry-projects/.github, extend detection cheaply to markdown top-level headings and JSON keys, and codify the required status check as a targeted ruleset scoped to the reusable-hosting meta-repos (matching therelease-channel-tagsprecedent) so it does not brick fleet repos that lack the workflow.Implementation Checklist
scripts/check-duplicate-decls.sh— pure, self-contained detector. Shell: duplicate top-level function declarations (detection logic identical to.github-private'sconflict-integrity.sh). Markdown: duplicate top-level (H1/H2) headings, fence-aware. JSON: duplicate keys / parse failure. Excludesnode_modules,.git,test,tests,.dev-lead..github/workflows/duplicate-decl-gate.yml— required gate. Runs on every PR (no paths filter, so the required check always reports) + push to main. Pinned checkout,permissions: contents: read..github/workflows/duplicate-decl-gate-tests.yml— shellcheck + bats runner (path-filtered), matching the repo's*-tests.ymlconvention.standards/rulesets/duplicate-decl-gate.json— targeted branch ruleset adding{"context": "duplicate-decl-gate"}as a required status check on~DEFAULT_BRANCH, bypass actors matchingcode-quality. Applied by name to the meta-repos only (not inFLEET_RULESETS).standards/rulesets/README.md— document the new targeted ruleset (table + scope boundary).Tests to Write
test/scripts/duplicate-decl-gate/duplicate-decl-gate.bats:name()\n{syntax)#-comments inside code fences; ignores duplicate sub-headings (H3+)Test Command
bats --print-output-on-failure test/scripts/duplicate-decl-gate/andbash .dev-lead/scripts/dev-lead-lint.shAudit result (AC: audit
main)Ran the detector's logic against current
mainunder the ship scope: shell function dups — clean; markdown top-level headings — clean; JSON keys — clean. No pre-existing corruption to remediate.don-petry commentedon Aug 31, 2026
Dev-Lead: Implementation Complete
Ported the
duplicate-decl-gatefrompetry-projects/.github-privateinto this repo, extended detection to markdown/JSON, codified the required status check, and auditedmain. All acceptance criteria addressed.Plan Execution
scripts/check-duplicate-decls.sh— pure, self-contained detector. Shell dup detection is byte-identical to.github-private'sconflict-integrity.shawk (extract_top_level_symbols, fn arms). Markdown: fence-aware duplicate top-level (H1/H2) heading detection. JSON: duplicate object keys + unparseable-file detection (fail loud). Excludes.git,node_modules,test,tests,.dev-lead..github/workflows/duplicate-decl-gate.yml— required gate; runs on every PR (no paths filter, so the required check always reports) + push tomain; pinned checkout,permissions: contents: read..github/workflows/duplicate-decl-gate-tests.yml— shellcheck + bats runner, path-filtered (matches the repo's*-tests.ymlconvention).standards/rulesets/duplicate-decl-gate.json— targeted branch ruleset adding required contextduplicate-decl-gate, bypass actors matchingcode-quality. Scoped to the reusable-hosting meta-repos only (not inFLEET_RULESETS), mirroring therelease-channel-tagsprecedent, so fleet repos lacking the workflow are not bricked.standards/rulesets/README.md— documented the new targeted ruleset (table row + scope-boundary + apply commands).test/scripts/duplicate-decl-gate/duplicate-decl-gate.bats— 17 tests.Acceptance criteria
.github-private: ✅ codified asstandards/rulesets/duplicate-decl-gate.json(contextduplicate-decl-gate). The applier (apply-rulesets.sh) needs no code change — a targeted ruleset is applied by name. Maintainer action (outside this PR's scope — I hold no admin token and don't touch live settings):GH_TOKEN=<admin> bash scripts/apply-rulesets.sh --repo petry-projects/.github duplicate-decl-gate. Verified via the compliance-audit bats that a repo carrying an extra required check beyondcode-qualityproduces no drift finding (subset semantics), so this is compatible.scripts/*.sh: ✅ markdown top-level headings + JSON keys (the AGENTS.md 23-vs-12 and unparseable-file signatures from PR feat: implement issue #1023 — canary autocut: scope bump signals to watched-path commits, paginate the range, and persist failed promotions #1024 would both fail).function-keyword forms, markdown fence-awareness + sub-heading exemption, JSON dup-key + parse-failure, scope exclusions).main: ✅ clean on all three detectors — shell functions, markdown top-level headings, JSON keys. No pre-existing corruption to remediate..githuband.github-privatehost reusable workflows (checked all non-archived org repos);.github-privatealready carries the gate,.githubnow does.Test Results
Files Changed
scripts/check-duplicate-decls.sh(new): the pure detector..github/workflows/duplicate-decl-gate.yml(new): the required gate..github/workflows/duplicate-decl-gate-tests.yml(new): the test runner.standards/rulesets/duplicate-decl-gate.json(new): the codified required check (targeted).standards/rulesets/README.md: documents the targeted ruleset.test/scripts/duplicate-decl-gate/duplicate-decl-gate.bats(new): 17 tests.Notes
scripts/; this one defaults to the repo root (minus excluded dirs) so it also coversAGENTS.mdandstandards/**per the AC. Intentional-duplicate fixtures undertest//tests/and vendored.dev-leadtooling are excluded so the gate never trips on its own fixtures.python3(present onubuntu-latest); if absent while JSON files exist, the gate exits 2 (fail-closed) rather than silently skipping.code-quality(OrganizationAdmin+ thedependabot-automerge-petryapp) for consistency; the gate still runs and passes on Dependabot PRs.feat: implement issue #1025 — petry-projects/.github has no duplicate…