docs(648,649): the jq contract + the shared PR-file enumeration record

Adds docs/ci-cd.md "The jq contract" (1.6 floor, the three divergent constructs,
and the deliberate pin-vs-floor asymmetry with its merge-deadlock reason), plus two
decision records: ci.jq-version-contract and ci.shared-pr-file-enumeration.
ci.script-tests-job stops restating the three jq rules and points at the new record.

Also corrects the script-tests preflight description: it is now two steps (git
presence, then jq VERSION via scripts/jq-preflight.sh --expect 1.6), not one.

A literal NUL byte had crept into the ci-cd.md paragraph describing jq 1.6's NUL
truncation — which git treats as a binary file. Replaced with the literal text.

Decisions-Edit: yes
This commit is contained in:
2026-07-26 22:21:07 +02:00
parent 2fd798cccf
commit 63fa81fbb5
5 changed files with 200 additions and 16 deletions
+47 -5
View File
@@ -655,11 +655,53 @@ which is itself a small demonstration of why the suite needed to run in CI at al
`small`-lane Python jobs it adds `actions/setup-python@v5` first. Checkout is at default depth: every `git` call in the suite runs
against a temp repo it creates itself, never this repository's history.
A **preflight step** asserts `jq` and `git` are on PATH before running the suite. Those two tests
exec the real shell scripts, which shell out to `jq` ~26 times; the tests shim `curl` on PATH but
not `jq`, so a runner image without it would surface as ~20 opaque assertion failures instead of one
diagnosis. It deliberately **checks** rather than installs — ersatztv#390 removed run-time
`apt-get` from CI; the fix for a genuine miss is to bake the tool into the runner image.
Two **preflight steps** run before the suite. The first asserts `git` is on PATH; the second runs
`scripts/jq-preflight.sh --expect 1.6`, which checks jq's **version**, not merely its presence (see
"The jq contract" below). Those two tests exec the real shell scripts, which shell out to `jq` ~26
times; the tests shim `curl` on PATH but not `jq`, so a runner image without it would surface as ~20
opaque assertion failures instead of one diagnosis. Both deliberately **check** rather than install —
ersatztv#390 removed run-time `apt-get` from CI; the fix for a genuine miss is to bake the tool into
the runner image.
### The jq contract (ersatztv#648)
> Full rationale: `docs/decisions/records/ci/jq-version-contract.md`.
Every shell gate in this repo — `decisions-guard`, `script-tests`'s own harness,
`pretooluse-merge-consent.sh`, `review-verdict.yml`, `scripts/pr-changed-files.sh` — is authored and
tested on a developer Mac shipping **jq 1.8.x**. The CI runner ships **jq 1.6**. Author to the
1.6-compatible subset; three concrete constructs diverge between the two and each one produced a real
bug when it hit CI for the first time:
- **`jq -e` over EMPTY input.** Exits 4 on jq >= 1.7, but **0** on jq 1.6. A guard that infers
"transport failure" from that exit status silently passes an empty/failed page on 1.6.
- **`` contains("\u0000") `` (or any NUL literal).** The NUL escape truncates to `""` on jq 1.6, so
the containment test is vacuously true for **every** string, not just ones containing a NUL. Use
`explode | index(0)` instead — it is version-stable.
- **Parse-error exit code.** `jq empty` exits 5 on jq >= 1.7 but **4** on jq 1.6 — the same code 1.6
uses for "no output produced". Reading that exit code as a specific failure mode conflates garbage
input with an empty-but-valid response.
`scripts/jq-preflight.sh` makes the running version **observable** in every gate job's log (it prints
the parsed version and asserts a floor of 1.6) so a future divergence can be diagnosed from the log
alone instead of guessing at the runner image.
**Pin vs floor is deliberately asymmetric.** `scripts/jq-preflight.sh --expect 1.6` additionally pins
the version and fails loudly if it drifts, but that mode is used **only** by `script-tests`
(`.gitea/workflows/pr-checks.yml`) — advisory, not a required check. `review-verdict.yml` runs the
no-args floor-only mode and never pins, because that workflow writes `review-verdict/h10`, the
branch-protection-**required** status check on `main`: a hard pin there would mean the day the
runner's jq version changes (a base-image bump, a host reimage — nothing this repo controls), every
PR on `main` stops merging until someone notices and re-pins. A required merge gate cannot fail
because an upstream package manager did its job. The narrower pin on `script-tests` exists precisely
because that job is the suite's only 1.6 coverage — if the runner's jq silently changed, that coverage
would evaporate with no signal, so failing loudly there forces a human decision instead.
Baking a pinned jq into `docker/ci/Dockerfile` was considered and rejected: `review-verdict.yml` is
`runs-on: small` with no toolchain-image pin, and per `ci.small-lane-git-only` the small lane is
git-only, so it gets the **host's** jq regardless of what the toolchain image contains — a pin in the
image provably cannot reach the gate that broke. This was checked against the running binary, not
assumed.
## PR gates workflow
+2
View File
@@ -45,6 +45,7 @@ the link for rationale. Superseded/retired history lives in `archive/`. Regenera
| `ci.functional-e2e-harness` | The `functional-e2e` CI job boots the PR's own code from source via `dotnet run` (`scripts/e2e-local.sh`) and runs deterministic assertions (`scripts/e2e-functional.sh`) as an advisory (non-blocking) job, not a `build` dependency or required check. Originally curl-only; since #445 the same job carries a second, headless-browser step for the contracts curl cannot express — see `ci.ui-e2e-harness`. | 2026-07-16 | [link](records/ci/functional-e2e-harness.md) |
| `ci.gitea-milestone-filter-noop` | Never filter issues with the server-side `?milestones=<name>` parameter — fetch all open issues once and filter LOCALLY on each issue's `.milestone.title`. | 2026-07-21 | [link](records/ci/gitea-milestone-filter-noop.md) |
| `ci.infra-shaped-red-under-load` | When a job dies inside a setup/cache step before your code compiles, check the runner host's load before diagnosing the diff, and never file a CI bug off one sample under pressure. | 2026-07-21 | [link](records/ci/infra-shaped-red-under-load.md) |
| `ci.jq-version-contract` | Every shell gate that shells out to `jq` is authored to the jq 1.6-compatible subset, because the CI runner ships jq 1.6 while every developer Mac ships 1.8.x. `scripts/jq-preflight.sh` (no args) prints the parsed version and asserts a floor of 1.6 in every gate job's log; `scripts/jq-preflight.sh --expect 1.6` additionally pins and fails loudly, but ONLY in the `script-tests` job. `review-verdict.yml` never pins — it writes the branch-protection-required `review-verdict/h10` status, so a hard pin there would turn any jq bump into a repo-wide merge deadlock. | 2026-07-26 | [link](records/ci/jq-version-contract.md) |
| `ci.killed-job-triage` | Never trust a job's `conclusion` field alone — read the log tail and require an `❌ Failure - Main …` marker before treating a red as a real failure. | 2026-07-21 | [link](records/ci/killed-job-triage.md) |
| `ci.monitor-armed-at-pr-open` | Arm a CI monitor on the PR head sha the moment the PR opens, polling the commit-status endpoint — not at the end of the work. | 2026-07-21 | [link](records/ci/monitor-armed-at-pr-open.md) |
| `ci.no-host-health-gating` | Push when your work is validated — never SSH to bumblebee to sample load/RAM first, and never hand-schedule around other sessions' runs. | 2026-07-21 | [link](records/ci/no-host-health-gating.md) |
@@ -52,6 +53,7 @@ the link for rationale. Superseded/retired history lives in `archive/`. Regenera
| `ci.root-screenshot-guard` | The Husky `pre-commit` hook refuses a staged root-level `*.png` (belt-and-suspenders with the `.gitignore` rule); nested `*.png` real assets are unaffected. | 2026-07-12 | [link](records/ci/root-screenshot-guard.md) |
| `ci.runner-placement` | No persistent Roslyn compiler server survives a CI build (`UseSharedCompilation=false` etc., runner env + Dockerfile `ENV`); every `services:` container gets its own explicit `--memory`/`--memory-swap`/`--cpus` cap (it does not inherit the job container's). | 2026-07-17 | [link](records/ci/runner-placement.md) |
| `ci.script-tests-job` | The `scripts/tests/` pytest suite runs on every PR as a dedicated `script-tests` job in `pr-checks.yml` (`runs-on: small`, `setup-python` + `pip install pytest`, `PYTHONPATH=. python3 -m pytest scripts/tests -q`), unconditionally rather than behind a `scripts/**` path filter, and **never as a step inside `decisions-guard`** — a job whose reds a standing rule instructs sessions to ignore must never host a gate whose reds are real. Any new CI gate must be reachable by a failure that is unambiguously attributable to it. | 2026-07-26 | [link](records/ci/script-tests-job.md) |
| `ci.shared-pr-file-enumeration` | A PR's complete set of changed file paths is computed by exactly one implementation, `scripts/pr-changed-files.sh`, called by both `.claude/hooks/pretooluse-merge-consent.sh` (advisory — a failure falls through to a human prompt) and `.gitea/workflows/review-verdict.yml` (enforced — a failure must fail closed, because a match here posts the branch-protection-required `review-verdict/h10` status with nobody in the loop). The script owns exhaustiveness (pagination, rename/path validation, head-sha binding) and returns exit 0 only for a verified-complete list; it does NOT classify paths — each caller keeps its own docs-only allow-list, and the two allow-lists differ on purpose and stay separate. | 2026-07-26 | [link](records/ci/shared-pr-file-enumeration.md) |
| `ci.small-lane-git-only` | `runs-on: small` is defined by what a job does (git-only), not its usual runtime; the two `docker build` jobs (docker-build.yml, ci-image.yml) move to `ubuntu-latest` because their worst-case memory, not median runtime, was pinning the small lane's per-slot cap. | 2026-07-20 | [link](records/ci/small-lane-git-only.md) |
| `ci.ui-e2e-harness` | The UI-interactive E2E flows run as headless Playwright specs (`web/e2e/*.spec.ts`, driven by `scripts/e2e-ui.sh`) in a **second step of the existing advisory `functional-e2e` job**, never their own job; the browser is `chromium-headless-shell` **baked into the CI toolchain image** (`docker/ci/Dockerfile`, `PLAYWRIGHT_VERSION` kept equal to `web/package.json`'s EXACT `@playwright/test` pin), never installed per run; specs are `serial` with `retries: 0` and assert only contracts the curl harness structurally cannot reach. | 2026-07-25 | [link](records/ci/ui-e2e-harness.md) |
| `ci.verify-locally-ci-confirms` | Treat the local build/verify/review pass as the decision point and CI as confirmation — don't idle waiting on a run you have no reason to doubt. | 2026-07-21 | [link](records/ci/verify-locally-ci-confirms.md) |
@@ -0,0 +1,69 @@
---
key: ci.jq-version-contract
title: '2026-07-26 — jq 1.6 is the FLOOR every shell gate must run on; `scripts/jq-preflight.sh` makes the version observable, and only `script-tests` pins it (#648)'
status: active
since: '2026-07-26'
supersedes: none
superseded-by: none
rule: 'Every shell gate that shells out to `jq` is authored to the jq 1.6-compatible subset, because the CI runner ships jq 1.6 while every developer Mac ships 1.8.x. `scripts/jq-preflight.sh` (no args) prints the parsed version and asserts a floor of 1.6 in every gate job''s log; `scripts/jq-preflight.sh --expect 1.6` additionally pins and fails loudly, but ONLY in the `script-tests` job. `review-verdict.yml` never pins — it writes the branch-protection-required `review-verdict/h10` status, so a hard pin there would turn any jq bump into a repo-wide merge deadlock.'
signals: 'jq version divergence, jq 1.6 vs 1.8, jq -e exit code on empty input, contains NUL false positive, jq parse-error exit code collision, jq-preflight, script-tests --expect, review-verdict jq floor, merge deadlock from a pinned dependency · paths: `scripts/jq-preflight.sh`, `.gitea/workflows/review-verdict.yml`, `.gitea/workflows/pr-checks.yml`, `docs/ci-cd.md` · issues: #643, #647, #648, #649'
mechanics: '`scripts/jq-preflight.sh` (no args) -> floor+observability in every gate job; `scripts/jq-preflight.sh --expect 1.6` -> tripwire, `script-tests` job only; `docs/ci-cd.md` -> "The jq contract"'
---
Three independent jq-version divergences hit inside a single day (#643, #647), all in gates written
and tested on a developer Mac (jq 1.8.x) but running on the CI runner (jq 1.6):
- `jq -e` over EMPTY input exits 4 on jq >= 1.7, but **0** on jq 1.6 — the docs-only pagination guard
inferred "transport failure" from that exit status, so on 1.6 a failed page silently passed and the
loop walked past unread pages while still reporting `files_complete=yes`.
- `contains("\u0000")` — the NUL escape truncates to `""` on jq 1.6, so the containment test is
vacuously **true for every string**, not just ones actually containing a NUL. The H10
review-verdict classifier that relied on this was entirely inert on the runner.
- Parse-error exit code: `jq empty` exits 5 on jq >= 1.7 but **4** on jq 1.6 — the same code jq 1.6
uses for "no output produced". A garbage API response and an empty-but-valid one were
indistinguishable, and the garbage case was read as "no comments."
None of these are exotic jq usage — they are constructs anyone would reach for first, and each one
was discovered only because a real gate broke, not because anyone thought to test jq 1.6. That is the
argument for a *contract*, not three point fixes: the failures share one shape (a shell gate's
behavior is a function of an interpreter version nobody was treating as a variable), so patching each
construct as it's found does not converge — it just narrows the next surprise.
**Why 1.6 is the floor and not 1.8.** The runner is the binding constraint, not the author's machine.
Baking a pinned jq into `docker/ci/Dockerfile` was the obvious first idea and was rejected because it
provably cannot cover the gate that actually broke: `review-verdict.yml` is `runs-on: small` with no
toolchain-image pin, and per `ci.small-lane-git-only` the small lane is git-only — it gets the host's
jq 1.6 no matter what the toolchain image contains. That was checked against the running binary, not
assumed. So the fix has to hold at 1.6, in every gate, regardless of which lane it runs in.
**Why the pin is asymmetric.** `scripts/jq-preflight.sh` has two modes on purpose:
- No arguments — print the parsed version and fail only below the 1.6 floor. This is pure
observability: the jq version CI actually used is now in the job log, so a future divergence can be
diagnosed from the log alone instead of by guessing at the runner image. `review-verdict.yml` runs
this mode. It cannot run the pinned mode, because that job's output is the required
`review-verdict/h10` status check on `main` — a hard version pin there means the day the runner's jq
is upgraded (a base-image bump, a host reimage, anything outside this repo's control), every PR
on `main` stops merging until someone notices and re-pins. A required merge gate cannot have a
failure mode that is "an upstream package manager did its job."
- `--expect 1.6` — pin and fail loudly. Used only by `script-tests`, which is advisory (it reddens the
run but is not one of the three required checks). `scripts/tests/` currently exercises the 1.6 code
path only because the runner happens to ship 1.6; if that silently changed, the 1.6 coverage this
whole contract depends on would evaporate with no signal. The tripwire forces a human decision —
re-pin after re-reading this record, or add a real 1.6 matrix leg — instead of letting the coverage
quietly disappear. Failing here costs a red on a non-required job; failing the same way on
`review-verdict.yml` costs every PR its ability to merge.
**The three constructs to avoid, and their version-stable replacements:**
- Never infer "empty input" from a jq exit status — check the string in shell before invoking jq.
- Never use `contains("\u0000")` (or any raw NUL literal) for a control-character test — use
`explode | index(0)`, which does not depend on jq's NUL-escape handling.
- Never infer "parse error" from `jq`'s exit code on ambiguous input — `jq empty` is the portable
parse-only test, but its exit code collides between "no output" (1.6) and "parse error" (1.6, same
code as 1.8's "no output"). Validate the response shape explicitly rather than reading one exit
code as a specific failure mode.
Full narrative of how these were found (inside the #631 `script-tests` rollout) is in
`docs/decisions/records/ci/script-tests-job.md`; this record is the durable contract that came out of
it, rather than the incident log.
+6 -11
View File
@@ -59,17 +59,12 @@ both reds were real:
The second one is the argument for this record in miniature. It sat in the gate that decides whether
a PR skips the Done-when checks, it was covered by an existing test, and that test could not catch it
on a developer Mac (jq 1.8) — only in CI, where the suite had never run. **Standing rules it leaves behind, all three the same shape — never infer a
CONDITION from a jq exit status or a version-dependent builtin:**
- never infer "empty input" from a jq exit status; check the string (`#643`);
- never infer "parse error" from a jq exit status — `jq empty` is the portable test, because
jq >= 1.7 exits 5 where 1.6 exits 4, and 4 is also "no output" (`#647`);
- never use `contains("\u0000")` — on jq 1.6 the escape truncates to `""` and it matches every
string (`#647`). `explode | index(0)` is version-stable.
The runner ships **jq 1.6**; a developer Mac ships 1.8.x. Three divergences were found in one day,
so the durable fix is to pin or preflight the version rather than keep patching constructs —
tracked on `#647`.
on a developer Mac (jq 1.8) — only in CI, where the suite had never run. Two further divergences of
the same shape (a `contains("\u0000")` false positive and a colliding parse-error exit code) turned
up the same day; the durable contract that came out of all three — the exact constructs to avoid, and
why `jq-preflight.sh` pins in `script-tests` but only floors the version in `review-verdict.yml` — is
recorded once, in `ci.jq-version-contract` (`docs/decisions/records/ci/jq-version-contract.md`), and
is not restated here.
An independent cross-family review of that fix then found **two further fail-opens in the same
enumeration, both reachable with no transport error at all** (#643):
@@ -0,0 +1,76 @@
---
key: ci.shared-pr-file-enumeration
title: '2026-07-26 — `scripts/pr-changed-files.sh` is the ONE enumeration of a PR''s changed files; the advisory hook and the enforced gate share mechanism, never policy (#649)'
status: active
since: '2026-07-26'
supersedes: none
superseded-by: none
rule: 'A PR''s complete set of changed file paths is computed by exactly one implementation, `scripts/pr-changed-files.sh`, called by both `.claude/hooks/pretooluse-merge-consent.sh` (advisory — a failure falls through to a human prompt) and `.gitea/workflows/review-verdict.yml` (enforced — a failure must fail closed, because a match here posts the branch-protection-required `review-verdict/h10` status with nobody in the loop). The script owns exhaustiveness (pagination, rename/path validation, head-sha binding) and returns exit 0 only for a verified-complete list; it does NOT classify paths — each caller keeps its own docs-only allow-list, and the two allow-lists differ on purpose and stay separate.'
signals: 'duplicated PR file enumeration, enforced gate weaker than advisory hook, docs-only allow-list drift, shared mechanism not shared policy, pr-changed-files.sh, checkout base ref not PR head, gate judging its own PR, exhaustiveness bug in a security predicate · paths: `scripts/pr-changed-files.sh`, `.claude/hooks/pretooluse-merge-consent.sh`, `.gitea/workflows/review-verdict.yml` · issues: #643, #648, #649'
mechanics: '`scripts/pr-changed-files.sh <owner> <repo> <pr> <expected-head-sha>` -> stdout newline-delimited paths, exit 0 only if complete and bound to the given sha; callers: `.claude/hooks/pretooluse-merge-consent.sh`, `.gitea/workflows/review-verdict.yml`'
---
Before #649, the PR changed-file enumeration existed as two independent implementations. That would
be an ordinary duplication smell anywhere else; here it was actively dangerous, because the two
copies had unequal *consequence*. The advisory hook's failure mode is a human permission prompt — a
missed guard there just means a person gets asked instead of an automatic decision. The enforced
workflow's failure mode is a `success` write to `review-verdict/h10`, the one status branch
protection actually requires — a missed guard there merges an unreviewed PR with nobody asked at all.
**The drift that motivated this.** Four rounds of #643 hardening landed entirely on the copy with the
*lower* stakes. The hook accumulated CR/LF rejection, `..` rejection, a closed `.status` allow-list,
`previous_filename` validation on every row (not just `renamed`), termination only on a validated
empty page, and head-sha binding — while the enforced workflow kept the original, weaker logic. Its
fail-closed behavior on a garbage API response was incidental (an empty `n` erroring a bash
conditional to false), not a designed property. The gate with real authority was strictly weaker than
the gate with none, which is the wrong way around by construction, not by anyone's mistake in a
single review — nothing in the original layout forced the two to move together.
**Why the fix is "one script, two callers" rather than "copy the hardening across."** Copying keeps
the two-implementation shape; the next hardening round would only need to happen twice again, and
there is no mechanism that would surface a second drift before it mattered. Extracting
`scripts/pr-changed-files.sh` makes the enumeration a single artifact with a single test suite
(`scripts/tests/test_pr_changed_files.py`), so a future guard is added once and both callers get it
atomically.
**Mechanism, not policy — the two allow-lists stay separate on purpose.** The extracted script
answers exactly one question: "what is the complete set of paths this PR touches, at one head, or can
we not tell?" It does not decide whether that set makes the PR docs-only. Each caller keeps its own
classification:
- The hook's docs-only pattern also lets `.claude/`, `.gitea/`, `.husky/` through, which is safe there
*only* because a non-match falls through to a human prompt rather than an auto-grant.
- The workflow's is narrower, because there a match posts a green status with nobody in the loop, and
both docs-only and Renovate exemptions are void when the PR touches `.claude/`, `.gitea/`,
`.husky/`, `scripts/` or `docker/ci/` — the gate must not be able to exempt itself from review by
editing itself.
Merging the two allow-lists would have quietly widened the enforced exemption to match the advisory
one, turning a difference that exists for a reason into an accident of refactoring. Sharing the
enumeration closes the drift that actually caused harm without touching the part that was correctly
different.
**What the shared script owns.** Six guards, all now exercised by one test suite instead of a subset
in each caller:
- CR/LF rejection and `..` rejection on every path.
- A closed `.status` allow-list (`added`/`modified`/`removed`/`renamed`/`copied`), not an open
denylist.
- `previous_filename` validated on **every** row the extraction consumes, not only rows whose
`.status` is `renamed` — a `modified`/`copied` row can still carry it, and an earlier fix that
validated only the `renamed` case was found incomplete for exactly this reason (see
`ci.script-tests-job` for the review trail).
- Termination only on a validated **empty** page — Gitea's paging can return fewer rows than
requested well before the real end of the list, so "short page" is not a valid termination signal.
- Head-sha binding: the head is re-read after enumeration, and the caller must refuse to trust the
list if it moved mid-enumeration, since paging is several round-trips and a force-push between them
would otherwise yield a list belonging to no single commit.
**`review-verdict.yml` also now checks out the PR's BASE ref, never the head**, so the workflow that
judges a PR cannot be rewritten by that same PR to weaken its own judgment — a PR editing
`review-verdict.yml` executes the *pre-PR* version of the gate against itself.
**Severity, stated honestly.** Every enumeration defect found in this area (#643) downgraded a
mechanical deny/ask to a human prompt on the hook side; none produced a silent self-merge on their
own. It is still a real weakening worth fixing — the whole point of #649 is that the same class of
bug on the *enforced* copy would not have been merely a downgrade.