Files
ersatztv/scripts
timothy 50f2068be1 fix(803,664): fence the HEAD alias on the PR timeline's pull_push count
`scripts/pr-changed-files.sh` binds its paged enumeration by re-reading `.base.ref`,
`.base.sha` and `.head.sha` after paging and comparing them to what it expected. That
is a comparison of a value against itself, so it detects movement still in effect at
the end and is blind to an alias. The BASE alias (`main -> S -> main`) was fenced by
#706's monotonic `change_target_branch` count. The HEAD alias was fenced by nothing:
a force-push `H1 -> H2 -> H1` across the paging round trips leaves the final `.head.sha`
comparison equal while the middle pages came from `H2`, so a mixed file list can produce
a docs-only exemption `success` no single head ever justified.

Two issues found this independently — #664 from the #649 cold review, #803 from #778's
read-then-write inventory — which is the argument for fixing it rather than documenting
it a third time.

Measured on the live instance before choosing an option:

* Gitea is 1.27.1. `GET /compare/{base}...{head}` still returns `total_commits` and
  `commits` and NO `files` key (probed over a 12-commit range), so pinning the diff to
  two shas remains unavailable. This independently confirms #747's re-dating of the
  same claim from 1.25.4.
* The timeline records every push as a `pull_push` event carrying
  `{"is_force_push": bool, "commit_ids": [...]}`. PR #802 has eighteen (all false),
  PR #761 five (three true). An ABA is necessarily two pushes, so the count moves by
  two where the sha moves by zero.
* PR #761 really went `8798a1d -> 830a407 -> 8798a1d`. The alias shape occurs in
  ordinary force-push-and-revert; no attacker is required.
* The fence does not abstain on its own trigger. Across 20 triggered
  (push -> `pull_request_target` run) pairs on PRs #802/#834/#761 the `pull_push` event
  predates its own run's `started_at` by 26-102s. That margin is runner queue latency,
  so it is a deployment property, not an API guarantee, and is recorded as such.

So `count_retargets` becomes `count_pr_mutations`: one walk, two tallies, one shared
trust flag, a separate fence arm and diagnostic per axis. `is_force_push` is deliberately
not read — an ordinary push also invalidates a mid-flight enumeration, and an ABA's
restoring push can be non-forced when `H1` is an ancestor.

The advisory hook gets the other half of #803: `$sha` was captured once at the top and
every later check (CI status, H10 status, verdict comments) addressed it, so a push
landing across the enumeration was checked against the commit it replaced. `.head.sha`
is now re-read at the SAME hoist and off the SAME response as the base re-read, so the
two axes cannot describe different instants; a moved head denies, an unreadable one asks.

#803's floor — three contracts that asserted more than the code did — lands too:
`pr-changed-files.sh`'s `exit 0` contract line, its head re-read comment, and
`review-verdict.yml`'s call-site claim that `exit 0` means "complete and bound to $SHA".

Mutation-proved rather than asserted. Deleting the head arm reddens 4 tests; keying on
the count's VALUE instead of its MOVEMENT reddens the settled-history test (every PR has
a non-zero push count, so that mutation would withhold every exemption — the #751 shape);
folding both event types into one tally reddens the separation test. An earlier draft of
that separation test claimed to catch the folding mutation and stayed GREEN under it —
it posed only the base-moves direction — so it now poses both, and states which one is
unobservable and why.

Verification: 1109 passed, 2 skipped (`PYTHONPATH=. python3 -m pytest scripts/tests -q`);
ruff check + format clean; decisions-validate OK; YAML and `bash -n` clean on every
touched shell body. No `.cs` touched, so the BOM/format gate does not apply.

fixes #803
fixes #664
Decisions-Edit: yes
2026-08-28 23:21:45 +02:00
..
2024-01-15 10:29:07 -06:00
2024-01-16 13:28:46 -06:00