From 30c4788e7909e25973aeead78d18a96fead1b4cb Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sat, 12 Sep 2026 17:54:40 +0000 Subject: [PATCH 1/3] ci: fail PRs whose merge commits introduce docs/adr files present in neither parent ADR governance content smuggled inside a merge commit is invisible to every per-commit review tool (gh pr diff --patch, incremental bot reviews), so it takes zero review. Discovered on PR #16768 where AGENT-SESSION-0028-compose-turn-origin-and-account-generation.md landed only inside the 'merge main' commit; it now lives on main as its own commit (#17483). The new guard scans every merge commit in the PR range and fails when one introduces a docs/adr/*.md file absent from all of its parents. --- .../workflows/ci-adr-evil-merge-guard.yaml | 25 ++++ scripts/cicd/check-adr-evil-merge.sh | 58 ++++++++ scripts/cicd/check-adr-evil-merge.test.ts | 133 ++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 .github/workflows/ci-adr-evil-merge-guard.yaml create mode 100755 scripts/cicd/check-adr-evil-merge.sh create mode 100644 scripts/cicd/check-adr-evil-merge.test.ts diff --git a/.github/workflows/ci-adr-evil-merge-guard.yaml b/.github/workflows/ci-adr-evil-merge-guard.yaml new file mode 100644 index 00000000000..c7fdc9a65db --- /dev/null +++ b/.github/workflows/ci-adr-evil-merge-guard.yaml @@ -0,0 +1,25 @@ +# Description: Fails when a merge commit in the PR's history introduces a +# docs/adr/*.md file present in neither of its parents ("evil merge" of +# governance content — invisible to per-commit review tooling). +name: 'CI: ADR Evil Merge Guard' + +on: + push: + branches: + - main + pull_request: + +jobs: + adr-evil-merge: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + - name: Check for ADR files introduced inside merge commits + run: | + base="${{ github.event.pull_request.base.sha }}" + if [ -z "$base" ]; then + base="${{ github.event.before }}" + fi + ./scripts/cicd/check-adr-evil-merge.sh "$base" HEAD diff --git a/scripts/cicd/check-adr-evil-merge.sh b/scripts/cicd/check-adr-evil-merge.sh new file mode 100755 index 00000000000..820b645c9e1 --- /dev/null +++ b/scripts/cicd/check-adr-evil-merge.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# Description: Fails when a merge commit in the scanned range introduces a +# `docs/adr/*.md` file that is present in NEITHER of its parents ("evil merge" +# of governance content). Per-commit review tooling (`gh pr diff --patch`, +# incremental bot reviews) cannot see content that only exists inside a merge +# commit, so governance artifacts smuggled in that way take zero review. +# Added by phs-48 after AGENT-SESSION-0028 landed inside PR #16768's +# "merge main" commit (own commit on main: #17483). +# +# Usage: check-adr-evil-merge.sh [head-rev] +# exclusive range start (e.g. PR base sha, or `github.event.before`) +# [head-rev] inclusive range end, defaults to HEAD +# An all-zero base (new-branch push) is a no-op success. The range scan needs +# merge-commit history: run the workflow with `fetch-depth: 0`. +set -euo pipefail + +base="${1:?usage: check-adr-evil-merge.sh [head-rev]}" +head="${2:-HEAD}" +path='docs/adr/' + +if [[ "$base" =~ ^0+$ ]]; then + exit 0 +fi + +merges="$(git rev-list --merges "$base..$head" 2>/dev/null || true)" +if [ -z "$merges" ]; then + exit 0 +fi + +fail=0 +for merge in $merges; do + # `rev-list --parents -n 1` prints " ..." + parents="$(git rev-list --parents -n 1 "$merge")" + read -r _ first_parent other_parents <<< "$parents" + # Files ADDED relative to parent 1 under docs/adr/; then reject when no + # other parent contains the file either, i.e. it exists only in the merge. + while IFS= read -r file; do + [ -n "$file" ] || continue + in_some_parent=0 + for parent in $other_parents; do + if git cat-file -e "${parent}:${file}" 2>/dev/null; then + in_some_parent=1 + break + fi + done + if [ "$in_some_parent" -eq 0 ]; then + echo "ERROR: merge $(git rev-parse --short "$merge") introduces ${file}" >&2 + echo " present in neither of its parents — ADR governance content must land" >&2 + echo " on its own commit so per-commit review tools can see it." >&2 + fail=1 + fi + done < <(git diff-tree -r --name-only --diff-filter=A --no-commit-id "$first_parent" "$merge" -- "$path") +done + +if [ "$fail" -ne 0 ]; then + echo "One or more merge commits evil-merged files under ${path}." >&2 +fi +exit "$fail" diff --git a/scripts/cicd/check-adr-evil-merge.test.ts b/scripts/cicd/check-adr-evil-merge.test.ts new file mode 100644 index 00000000000..0ead8eeed98 --- /dev/null +++ b/scripts/cicd/check-adr-evil-merge.test.ts @@ -0,0 +1,133 @@ +import { execFileSync, spawnSync } from 'node:child_process' +import fs from 'node:fs' +import os from 'node:os' +import path from 'node:path' +import { afterEach, describe, expect, it } from 'vitest' + +const SCRIPT = path.join(import.meta.dirname, 'check-adr-evil-merge.sh') +const temporaryDirectories: string[] = [] + +const GIT_ENV = { + GIT_CONFIG_GLOBAL: '/dev/null', + GIT_CONFIG_SYSTEM: '/dev/null' +} + +// The script walks merge-commit history, so fixtures need a hermetic throwaway +// repo with real (non-shallow) history. +function tempGitRepo(): { dir: string; git: (...args: string[]) => string } { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'adr-evil-merge-')) + temporaryDirectories.push(dir) + const env = { ...process.env, ...GIT_ENV } + const git = (...args: string[]) => + execFileSync('git', args, { cwd: dir, encoding: 'utf8', env }) + git('init', '--initial-branch=main') + git('config', 'user.email', 'ci@example.com') + git('config', 'user.name', 'CI') + return { dir, git } +} + +function write(dir: string, rel: string, contents: string): void { + const filePath = path.join(dir, rel) + fs.mkdirSync(path.dirname(filePath), { recursive: true }) + fs.writeFileSync(filePath, contents) +} + +function commitAll( + dir: string, + git: (...args: string[]) => string, + message: string +): string { + git('add', '.') + git('commit', '-m', message) + return git('rev-parse', 'HEAD').trim() +} + +function runScript(dir: string, base: string, head = 'HEAD') { + return spawnSync('bash', [SCRIPT, base, head], { + cwd: dir, + encoding: 'utf8', + env: { ...process.env, ...GIT_ENV } + }) +} + +afterEach(() => { + for (const directory of temporaryDirectories.splice(0)) { + fs.rmSync(directory, { recursive: true, force: true }) + } +}) + +describe('check-adr-evil-merge', () => { + it('passes when the range has no merge commits', () => { + const { dir, git } = tempGitRepo() + write(dir, 'docs/adr/TOPIC-0001.md', '# adr\n') + const base = commitAll(dir, git, 'base') + write(dir, 'src/index.ts', 'export {}\n') + commitAll(dir, git, 'ordinary commit adds an unrelated file') + + const result = runScript(dir, base) + expect(result.status).toBe(0) + }) + + it('passes when the ADR arrived on a branch commit and the merge only integrates it', () => { + const { dir, git } = tempGitRepo() + write(dir, 'src/index.ts', 'export {}\n') + const base = commitAll(dir, git, 'base') + git('checkout', '-b', 'feature') + write(dir, 'docs/adr/TOPIC-0002.md', '# adr\n') + commitAll(dir, git, 'branch commit adds the ADR') + git('checkout', 'main') + git('merge', '--no-ff', '--no-edit', 'feature') + + const result = runScript(dir, base) + expect(result.status).toBe(0) + }) + + it('fails when a merge commit introduces a docs/adr file present in neither parent', () => { + const { dir, git } = tempGitRepo() + write(dir, 'src/index.ts', 'export {}\n') + commitAll(dir, git, 'base') + git('checkout', '-b', 'feature') + write(dir, 'src/feature.ts', 'export {}\n') + commitAll(dir, git, 'branch commit') + git('checkout', 'main') + write(dir, 'src/main-drift.ts', 'export {}\n') + const mainDrift = commitAll(dir, git, 'main drifts independently') + git('merge', '--no-ff', '--no-commit', 'feature') + // Smuggle governance content into the merge itself: present in NEITHER parent. + write(dir, 'docs/adr/TOPIC-0003-evil.md', '# smuggled\n') + git('add', '.') + git('commit', '-m', 'merge main and smuggle an ADR') + + const result = runScript(dir, mainDrift) + expect(result.status).toBe(1) + expect(result.stderr).toContain('docs/adr/TOPIC-0003-evil.md') + }) + + it('does not flag a merge that only resolves conflicts in files both parents already have', () => { + const { dir, git } = tempGitRepo() + write(dir, 'docs/adr/TOPIC-0004.md', '# adr\n') + commitAll(dir, git, 'base') + git('checkout', '-b', 'feature') + write(dir, 'docs/adr/TOPIC-0004.md', '# adr with branch edit\n') + commitAll(dir, git, 'branch edits the ADR') + git('checkout', 'main') + write(dir, 'docs/adr/TOPIC-0004.md', '# adr with main edit\n') + const mainEdit = commitAll(dir, git, 'main edits the ADR') + expect(() => git('merge', '--no-ff', '--no-edit', 'feature')).toThrow() + write(dir, 'docs/adr/TOPIC-0004.md', '# adr resolved\n') + git('add', '.') + git('commit', '--no-edit') + + const result = runScript(dir, mainEdit) + expect(result.status).toBe(0) + }) + + it('is a no-op when the base is the all-zero new-branch sentinel', () => { + const { dir, git } = tempGitRepo() + write(dir, 'docs/adr/TOPIC-0005.md', '# adr\n') + commitAll(dir, git, 'base') + + const result = runScript(dir, '0'.repeat(40)) + expect(result.status).toBe(0) + }) +}) From 6efeaa01831e831e56f572231ec511a36ab7c9fe Mon Sep 17 00:00:00 2001 From: christian-byrne Date: Sat, 19 Sep 2026 20:49:09 -0700 Subject: [PATCH 2/3] ci: stop the evil-merge fixtures from tripping the ADR link guard Two red checks at this head, both from the guard this PR adds rather than from the repo it guards. `check-adr-links.sh` scans every tracked file for `docs/adr/*.md` references and fails on ones that do not resolve. The new `check-adr-evil-merge.test.ts` writes such paths into throwaway repos as fixtures for the evil-merge script, so all nine of them read as permanently dangling. The scan now excludes `scripts/cicd/check-adr-*.test.ts`, which is exactly the set whose ADR paths are inputs to the ADR tooling rather than references a reader follows. Ordinary files under `scripts/cicd` are still scanned, and both behaviours are pinned. The exclusion comment cannot spell an example path either, since the scan reads its own source. Also drops the unused `dir` parameter from the test's `commitAll` helper, which failed typecheck as TS6133 and took `lint-and-format` down with it. The `git` closure already carries the working directory. --- scripts/cicd/check-adr-evil-merge.test.ts | 23 ++++++++-------- scripts/cicd/check-adr-links.sh | 10 ++++++- scripts/cicd/check-adr-links.test.ts | 33 +++++++++++++++++++++++ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/scripts/cicd/check-adr-evil-merge.test.ts b/scripts/cicd/check-adr-evil-merge.test.ts index 0ead8eeed98..2665072e13f 100644 --- a/scripts/cicd/check-adr-evil-merge.test.ts +++ b/scripts/cicd/check-adr-evil-merge.test.ts @@ -33,7 +33,6 @@ function write(dir: string, rel: string, contents: string): void { } function commitAll( - dir: string, git: (...args: string[]) => string, message: string ): string { @@ -60,9 +59,9 @@ describe('check-adr-evil-merge', () => { it('passes when the range has no merge commits', () => { const { dir, git } = tempGitRepo() write(dir, 'docs/adr/TOPIC-0001.md', '# adr\n') - const base = commitAll(dir, git, 'base') + const base = commitAll(git, 'base') write(dir, 'src/index.ts', 'export {}\n') - commitAll(dir, git, 'ordinary commit adds an unrelated file') + commitAll(git, 'ordinary commit adds an unrelated file') const result = runScript(dir, base) expect(result.status).toBe(0) @@ -71,10 +70,10 @@ describe('check-adr-evil-merge', () => { it('passes when the ADR arrived on a branch commit and the merge only integrates it', () => { const { dir, git } = tempGitRepo() write(dir, 'src/index.ts', 'export {}\n') - const base = commitAll(dir, git, 'base') + const base = commitAll(git, 'base') git('checkout', '-b', 'feature') write(dir, 'docs/adr/TOPIC-0002.md', '# adr\n') - commitAll(dir, git, 'branch commit adds the ADR') + commitAll(git, 'branch commit adds the ADR') git('checkout', 'main') git('merge', '--no-ff', '--no-edit', 'feature') @@ -85,13 +84,13 @@ describe('check-adr-evil-merge', () => { it('fails when a merge commit introduces a docs/adr file present in neither parent', () => { const { dir, git } = tempGitRepo() write(dir, 'src/index.ts', 'export {}\n') - commitAll(dir, git, 'base') + commitAll(git, 'base') git('checkout', '-b', 'feature') write(dir, 'src/feature.ts', 'export {}\n') - commitAll(dir, git, 'branch commit') + commitAll(git, 'branch commit') git('checkout', 'main') write(dir, 'src/main-drift.ts', 'export {}\n') - const mainDrift = commitAll(dir, git, 'main drifts independently') + const mainDrift = commitAll(git, 'main drifts independently') git('merge', '--no-ff', '--no-commit', 'feature') // Smuggle governance content into the merge itself: present in NEITHER parent. write(dir, 'docs/adr/TOPIC-0003-evil.md', '# smuggled\n') @@ -106,13 +105,13 @@ describe('check-adr-evil-merge', () => { it('does not flag a merge that only resolves conflicts in files both parents already have', () => { const { dir, git } = tempGitRepo() write(dir, 'docs/adr/TOPIC-0004.md', '# adr\n') - commitAll(dir, git, 'base') + commitAll(git, 'base') git('checkout', '-b', 'feature') write(dir, 'docs/adr/TOPIC-0004.md', '# adr with branch edit\n') - commitAll(dir, git, 'branch edits the ADR') + commitAll(git, 'branch edits the ADR') git('checkout', 'main') write(dir, 'docs/adr/TOPIC-0004.md', '# adr with main edit\n') - const mainEdit = commitAll(dir, git, 'main edits the ADR') + const mainEdit = commitAll(git, 'main edits the ADR') expect(() => git('merge', '--no-ff', '--no-edit', 'feature')).toThrow() write(dir, 'docs/adr/TOPIC-0004.md', '# adr resolved\n') git('add', '.') @@ -125,7 +124,7 @@ describe('check-adr-evil-merge', () => { it('is a no-op when the base is the all-zero new-branch sentinel', () => { const { dir, git } = tempGitRepo() write(dir, 'docs/adr/TOPIC-0005.md', '# adr\n') - commitAll(dir, git, 'base') + commitAll(git, 'base') const result = runScript(dir, '0'.repeat(40)) expect(result.status).toBe(0) diff --git a/scripts/cicd/check-adr-links.sh b/scripts/cicd/check-adr-links.sh index c69d3544030..e8b6a18faa4 100755 --- a/scripts/cicd/check-adr-links.sh +++ b/scripts/cicd/check-adr-links.sh @@ -10,8 +10,16 @@ set -euo pipefail repo_root="$(git rev-parse --show-toplevel)" cd "$repo_root" +# The ADR tooling's own tests build throwaway repos whose fixtures are ADR paths +# that deliberately do not exist here (TOPIC-0001 and friends, spelled out in +# those files). They are inputs to those scripts, not references a reader could +# follow, so scanning them would make every such fixture a permanent dangling +# ref. Note this comment cannot spell such a path either: the scan reads its own +# source too. +adr_fixture_sources=':(exclude)scripts/cicd/check-adr-*.test.ts' + # git grep exit code 1 means "no matches", which is success for this check. -if refs=$(git grep -nEo 'docs/adr/[A-Za-z0-9._/-]+\.md' -- .); then +if refs=$(git grep -nEo 'docs/adr/[A-Za-z0-9._/-]+\.md' -- . "$adr_fixture_sources"); then : else grep_status=$? diff --git a/scripts/cicd/check-adr-links.test.ts b/scripts/cicd/check-adr-links.test.ts index 914e4bfeb0f..d14a550cfec 100644 --- a/scripts/cicd/check-adr-links.test.ts +++ b/scripts/cicd/check-adr-links.test.ts @@ -92,6 +92,39 @@ describe('check-adr-links', () => { expect(result.status).toBe(0) }) + it('ignores the ADR tooling tests, whose fixture paths never exist', () => { + // `check-adr-evil-merge.test.ts` writes `docs/adr/TOPIC-0001.md` into + // throwaway repos to exercise the evil-merge guard. Those strings are + // inputs to that script, not references a reader follows, so scanning + // them would make every fixture a permanent dangling ref here. + const { dir, git } = tempGitRepo() + write( + dir, + 'scripts/cicd/check-adr-evil-merge.test.ts', + `write(dir, '${adrPath('TOPIC-0001.md')}', '# fixture\\n')\n` + ) + git('add', '.') + git('commit', '-m', 'fixture') + + const result = runScript(dir) + expect(result.status).toBe(0) + }) + + it('still scans ordinary files under scripts/cicd', () => { + const { dir, git } = tempGitRepo() + write( + dir, + 'scripts/cicd/check-adr-links.sh', + `# see ${adrPath('TOPIC-0404-missing.md')}\n` + ) + git('add', '.') + git('commit', '-m', 'fixture') + + const result = runScript(dir) + expect(result.status).toBe(1) + expect(result.stderr).toContain(adrPath('TOPIC-0404-missing.md')) + }) + it('propagates git grep errors', () => { const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'adr-links-not-git-')) temporaryDirectories.push(dir) From 7fd611ad8deecb9309a8dffe38d47ebb5484ac35 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sat, 26 Sep 2026 02:11:17 -0700 Subject: [PATCH 3/3] ci: stop the evil-merge guard passing when it did not run Three of the four review findings; the fourth is already fixed on this branch and is answered on the thread rather than re-fixed. - `|| true` on the `rev-list` turned a range the guard cannot resolve into an empty range, so it exited 0 without looking at any history. That is the exact shape a force-push produces - `github.event.before` orphaned - and a guard that reports green when it did not run is worse than no guard. It now exits 2, keeping "I could not run" distinct from the exit 1 that means "I found one", and prints git's own message plus what to do about it. - The pathspec matched the whole `docs/adr/` directory while the documented contract is `docs/adr/*.md`, so a merge adding a diagram was reported as smuggled governance content. Narrowed to the contract. - The clean cases asserted only the exit status, so a guard that passed while printing warnings looked identical to a silent one. `expectSilentPass` now pins status, stderr and stdout together for all four. Two cases added for the first two behaviours, and all three changes are mutation-verified: restoring `|| true` reddens the unresolvable-range case, widening the pathspec reddens the non-Markdown case, and making a clean run print to stderr reddens the no-merges case. 7/7 green restored. --- scripts/cicd/check-adr-evil-merge.sh | 22 ++++++++- scripts/cicd/check-adr-evil-merge.test.ts | 58 +++++++++++++++++++---- 2 files changed, 70 insertions(+), 10 deletions(-) diff --git a/scripts/cicd/check-adr-evil-merge.sh b/scripts/cicd/check-adr-evil-merge.sh index 820b645c9e1..0d5f94bf927 100755 --- a/scripts/cicd/check-adr-evil-merge.sh +++ b/scripts/cicd/check-adr-evil-merge.sh @@ -17,12 +17,30 @@ set -euo pipefail base="${1:?usage: check-adr-evil-merge.sh [head-rev]}" head="${2:-HEAD}" path='docs/adr/' +# The contract in the header is `docs/adr/*.md`. Matching the whole directory +# instead would fail a merge that adds a diagram or a fixture under it and +# report that as smuggled governance content. +pathspec='docs/adr/*.md' if [[ "$base" =~ ^0+$ ]]; then exit 0 fi -merges="$(git rev-list --merges "$base..$head" 2>/dev/null || true)" +# A range this script cannot resolve is not an empty range. `|| true` turned an +# unavailable base - which is what a force-push leaves behind in +# `github.event.before` - into a silent pass, so the guard reported green +# precisely when it had not looked. Exit 2 to keep "I could not run" distinct +# from the exit 1 that means "I found one". +rev_list_err="$(mktemp)" +trap 'rm -f "$rev_list_err"' EXIT +if ! merges="$(git rev-list --merges "$base..$head" 2>"$rev_list_err")"; then + echo "ERROR: cannot resolve the revision range ${base}..${head}" >&2 + sed 's/^/ git: /' "$rev_list_err" >&2 + echo " The guard did not run, so this is NOT evidence that no ADR was" >&2 + echo " evil-merged. Check out with fetch-depth: 0, or pass a base that" >&2 + echo " still exists (a force-push can orphan github.event.before)." >&2 + exit 2 +fi if [ -z "$merges" ]; then exit 0 fi @@ -49,7 +67,7 @@ for merge in $merges; do echo " on its own commit so per-commit review tools can see it." >&2 fail=1 fi - done < <(git diff-tree -r --name-only --diff-filter=A --no-commit-id "$first_parent" "$merge" -- "$path") + done < <(git diff-tree -r --name-only --diff-filter=A --no-commit-id "$first_parent" "$merge" -- "$pathspec") done if [ "$fail" -ne 0 ]; then diff --git a/scripts/cicd/check-adr-evil-merge.test.ts b/scripts/cicd/check-adr-evil-merge.test.ts index 2665072e13f..c9904c61738 100644 --- a/scripts/cicd/check-adr-evil-merge.test.ts +++ b/scripts/cicd/check-adr-evil-merge.test.ts @@ -56,6 +56,17 @@ afterEach(() => { }) describe('check-adr-evil-merge', () => { + // A guard that exits 0 while printing to stderr reads as a pass with a + // warning, and nobody reads CI warnings. Exit status alone cannot tell the + // two apart, so every clean case asserts silence as well. + function expectSilentPass(result: ReturnType): void { + expect({ status: result.status, stderr: result.stderr }).toEqual({ + status: 0, + stderr: '' + }) + expect(result.stdout).toBe('') + } + it('passes when the range has no merge commits', () => { const { dir, git } = tempGitRepo() write(dir, 'docs/adr/TOPIC-0001.md', '# adr\n') @@ -63,8 +74,7 @@ describe('check-adr-evil-merge', () => { write(dir, 'src/index.ts', 'export {}\n') commitAll(git, 'ordinary commit adds an unrelated file') - const result = runScript(dir, base) - expect(result.status).toBe(0) + expectSilentPass(runScript(dir, base)) }) it('passes when the ADR arrived on a branch commit and the merge only integrates it', () => { @@ -77,8 +87,7 @@ describe('check-adr-evil-merge', () => { git('checkout', 'main') git('merge', '--no-ff', '--no-edit', 'feature') - const result = runScript(dir, base) - expect(result.status).toBe(0) + expectSilentPass(runScript(dir, base)) }) it('fails when a merge commit introduces a docs/adr file present in neither parent', () => { @@ -117,8 +126,7 @@ describe('check-adr-evil-merge', () => { git('add', '.') git('commit', '--no-edit') - const result = runScript(dir, mainEdit) - expect(result.status).toBe(0) + expectSilentPass(runScript(dir, mainEdit)) }) it('is a no-op when the base is the all-zero new-branch sentinel', () => { @@ -126,7 +134,41 @@ describe('check-adr-evil-merge', () => { write(dir, 'docs/adr/TOPIC-0005.md', '# adr\n') commitAll(git, 'base') - const result = runScript(dir, '0'.repeat(40)) - expect(result.status).toBe(0) + expectSilentPass(runScript(dir, '0'.repeat(40))) + }) + + it('ignores a non-Markdown file smuggled into a merge', () => { + const { dir, git } = tempGitRepo() + write(dir, 'src/index.ts', 'export {}\n') + commitAll(git, 'base') + git('checkout', '-b', 'feature') + write(dir, 'src/feature.ts', 'export {}\n') + commitAll(git, 'branch commit') + git('checkout', 'main') + write(dir, 'src/main-drift.ts', 'export {}\n') + const mainDrift = commitAll(git, 'main drifts independently') + git('merge', '--no-ff', '--no-commit', 'feature') + // The documented contract is `docs/adr/*.md`. A diagram is not governance + // content taking zero review, and reporting it as an evil-merged ADR + // teaches people to ignore the guard. + write(dir, 'docs/adr/diagram.svg', '\n') + git('add', '.') + git('commit', '-m', 'merge main and add an asset') + + expectSilentPass(runScript(dir, mainDrift)) + }) + + it('refuses to report a pass when the range cannot be resolved', () => { + const { dir, git } = tempGitRepo() + write(dir, 'docs/adr/TOPIC-0006.md', '# adr\n') + commitAll(git, 'base') + + // What a force-push leaves in `github.event.before`: a real-looking sha + // that no longer exists. Silently treating it as an empty range is the + // one outcome the guard must never produce. + const result = runScript(dir, 'f'.repeat(40)) + expect(result.status).not.toBe(0) + expect(result.status).not.toBe(1) + expect(result.stderr).toContain('cannot resolve the revision range') }) })