Add a scoped shellcheck tier to the pre-push gate (gate-lib.sh) so SC regressions are caught before main, not CI-only #379

Closed
opened 2026-11-20 02:14:52 +00:00 by matou-build-agent · 1 comment

Why

git-hooks/pre-push / gate.sh / gate-lib.sh run no shellcheck tier (the only shellcheck strings under git-hooks/ are # shellcheck directives). So a shellcheck -S warning regression in a root/tests/ script is invisible until ci / static runs after the push — and the landing does not wait on it. This is now the third such incident in the same ci / static surface:

  • #360 — 8 shellcheck warnings red on main (fixed).
  • #371 — SC1007 in the fleet-dispatch env prefixes (fixed).
  • #378 — four SC2155 findings from #375 + #373 (fixed; this ticket is the follow-up it filed).

#378 fixed the findings and documented the gap as GOTCHAS #378, but ruled (ADR 0174) that adding the tier itself is design work with a provisioning question the sandbox cannot settle — hence this ready-for-session ticket.

Proposed shape

Add an sh language tier to gate-lib.sh mirroring the existing gofmt/docs tiers (cheap, never enters a nix shell, changed-file-scoped — a whole-tree shellcheck -S warning -x is ~3 min, too slow for pre-push; a changed-file-scoped run is affordable):

  • gate_langs_for_files: map *.sh / git-hooks/* / git-fence / .forgejo/*.sh (the ci.yml scan set) to an sh token.
  • gate_shellcheck_stage <root> + gate_shellcheck_default_cmd: first-match-wins precedence (GATE_SHELLCHECK_CMD env → shellcheck on PATH → fail-?), running shellcheck -S warning -x over only the changed shell files.
  • Wire into gate_run and the --prepush / --prepush-host paths in gate.sh (the tier is cheap, so it should run on the HOST push path too — that is where #360/#371/#378 all slipped past).
  • Update tests/gate-lib-test.sh in the same commit (shim shellcheck via GATE_SHELLCHECK_CMD, assert both the pass and the fail-arm).

The decision a session must settle (why not an unattended agent)

Fail-open vs fail-closed, and per-consumer shellcheck provisioning. Every other tier fails closed (a blocked push beats a red main), relying on the consumer flake / PATH carrying the toolchain. But:

  • It is unknown whether every pool host and every consumer flake carries shellcheck (cf. #332 — the shellcheck-tarball fetch was fraught). A fail-closed tier that resolves no shellcheck would block the live reconcile rail for every shell-touching push across all consumers.
  • A fail-open tier departs from the gate doctrine and the gofmt history warns a gate that silently skips gives false comfort.

So the session should decide: (a) make each consumer flake/dev-shell provide shellcheck (like gofmt) and fail closed, or (b) fail open with a loud warning until provisioning is confirmed, or (c) a hybrid (fail closed only where a GATE_SHELLCHECK_CMD/PATH binary is present-by-contract). This needs the host/flake facts and a standing an unattended agent lacks.

Found while working

#378 (the four SC2155 findings reddening ci / static on main). See GOTCHAS #378 and docs/journal/2026-11-20-378.md.

## Why `git-hooks/pre-push` / `gate.sh` / `gate-lib.sh` run **no** shellcheck tier (the only `shellcheck` strings under `git-hooks/` are `# shellcheck` directives). So a `shellcheck -S warning` regression in a root/`tests/` script is invisible until `ci / static` runs **after** the push — and the landing does not wait on it. This is now the third such incident in the same `ci / static` surface: - **#360** — 8 shellcheck warnings red on `main` (fixed). - **#371** — SC1007 in the fleet-dispatch env prefixes (fixed). - **#378** — four SC2155 findings from #375 + #373 (fixed; this ticket is the follow-up it filed). #378 fixed the findings and documented the gap as GOTCHAS #378, but ruled (ADR 0174) that adding the tier itself is design work with a provisioning question the sandbox cannot settle — hence this `ready-for-session` ticket. ## Proposed shape Add an `sh` language tier to `gate-lib.sh` mirroring the existing gofmt/docs tiers (cheap, never enters a nix shell, changed-file-scoped — a whole-tree `shellcheck -S warning -x` is ~3 min, too slow for pre-push; a changed-file-scoped run is affordable): - `gate_langs_for_files`: map `*.sh` / `git-hooks/*` / `git-fence` / `.forgejo/*.sh` (the ci.yml scan set) to an `sh` token. - `gate_shellcheck_stage <root>` + `gate_shellcheck_default_cmd`: first-match-wins precedence (`GATE_SHELLCHECK_CMD` env → `shellcheck` on PATH → fail-?), running `shellcheck -S warning -x` over only the changed shell files. - Wire into `gate_run` and the `--prepush` / `--prepush-host` paths in `gate.sh` (the tier is cheap, so it should run on the HOST push path too — that is where #360/#371/#378 all slipped past). - Update `tests/gate-lib-test.sh` in the same commit (shim `shellcheck` via `GATE_SHELLCHECK_CMD`, assert both the pass and the fail-arm). ## The decision a session must settle (why not an unattended agent) **Fail-open vs fail-closed, and per-consumer `shellcheck` provisioning.** Every other tier fails **closed** (a blocked push beats a red main), relying on the consumer flake / PATH carrying the toolchain. But: - It is unknown whether every pool host and every consumer flake carries `shellcheck` (cf. #332 — the shellcheck-tarball fetch was fraught). A fail-closed tier that resolves no `shellcheck` would block the **live reconcile rail** for every shell-touching push across all consumers. - A fail-open tier departs from the gate doctrine and the gofmt history warns a gate that silently skips gives false comfort. So the session should decide: (a) make each consumer flake/dev-shell provide `shellcheck` (like gofmt) and fail closed, or (b) fail open with a loud warning until provisioning is confirmed, or (c) a hybrid (fail closed only where a `GATE_SHELLCHECK_CMD`/PATH binary is present-by-contract). This needs the host/flake facts and a standing an unattended agent lacks. ## Found while working #378 (the four SC2155 findings reddening `ci / static` on `main`). See GOTCHAS #378 and `docs/journal/2026-11-20-378.md`.
Author
Member

Close-report — #379 landed on main (push mode)

Commit: 431102d — gate: #379 — add a scoped shellcheck tier to the pre-push gate (fail-open until provisioned) (on origin/main).

What landed

A shellcheck tier in the pre-push gate (gate-lib.sh/gate.sh), mirroring the gofmt/docs tiers, run on every push path (--prepush AND --prepush-host — where #360/#371/#378 all slipped past CI):

  • gate_langs_for_files grows an sh token; gate_sh_files collects the changed shell files.
  • gate_shellcheck_stage <root> <file…> resolves first-match-wins: GATE_SHELLCHECK_CMD (receives the changed files as $@) → shellcheck on PATH → the fail arm. gate_shellcheck_default_cmd runs shellcheck -S warning -x over only the changed shell files (sub-second; a whole-tree run is ~3 min, too slow for a push).
  • gate_shellcheck_available (the GATE_NO_SHELLCHECK=1 test seam, #314 lesson).
  • Wired into gate_run (which now captures stdin once, since the lang set and the scoped file list both read it).

The decision this session settled (Ruled by agent under ADR 0174 — veto anytime)

Fail-open vs fail-closed + provisioning. Ruled fail-OPEN with a loud warning where no shellcheck resolves; fail-closed on findings wherever a shellcheck is armed; and a GATE_SHELLCHECK_REQUIRE=1 toggle that flips the no-binary arm fail-closed once provisioned. Why this tier alone defaults fail-open (the other tiers fail closed): shellcheck is not provisioned-by-contract across the fleet — it is absent from bens-mac-04's PATH (a pool host, where this very session-runner pushes), the factory carries no nix flake providing it, and ci / static tarball-FETCHES a pinned v0.11.0 (a fetch #332/#333 proved fraught). A fail-closed tier that resolved no shellcheck would block the live reconcile/session rail for every shell-touching push across all consumers — a fleet-wide outage far worse than the CI-only reds it pre-empts. Proof: this push's own pre-push gate warned and passed on bens-mac-04; the rail is not blocked.

The one-way door left to a human (filed as follow-up)

Fleet-wide shellcheck provisioning (put shellcheck on each pool host / consumer dev-shell / the sandbox image) and then setting GATE_SHELLCHECK_REQUIRE=1 to make the tier enforce. That is host/flake posture a session must not widen from here. Follow-up: #380 (below).

Proof

  • tests/gate-lib-test.sh: 63 → 80 checks, all green (detection, scoped extraction, the override seam + $@ passing, git-env scrub, the fail-open default + loud warning, the GATE_SHELLCHECK_REQUIRE fail-closed arm, override precedence, gate_run on both profiles, and a guarded real-binary fixture block proving SC2155/SC2164 are refused and the scan is file-scoped).
  • Full offline suite (for t in tests/*.sh onboarding/tests/*.sh; …): green.
  • tests/docs-budget-test.sh: green (STATUS.md surface compacted to hold the new row under the #374 ≥2 KB headroom floor).
  • bash -n over the ci / static scan set: clean.

Docs / blast radius

  • GOTCHAS #379 (docs/gotchas/379-shellcheck-tier-fails-open-where-unprovisioned.md) + index row; journal docs/journal/2026-11-19-379.md; STATUS.md blocker row.
  • The sh mapping is by extension / universal harness filename (*.sh, git-hooks/*, git-fence), deliberately not ci.yml's factory-root dir globs (onboarding/, tests/, .forgejo/) — a vendored file must name no product path (CLAUDE.md; ci.yml is not vendored). This is a superset of the factory's own scan set, which only tightens the gate and is correct in every consumer.

Owed

A re-vendor (GOTCHAS 4): gate-lib.sh, gate.sh, tests/gate-lib-test.sh are vendored, so the running .sandcastle/ self-copy + consumers pick up the tier only at their next FACTORY_REF bump. Until then this repo's own pre-push runs the pre-#379 vendored gate (confirmed: this push reported "no gated language touched" for its .sh/.md change — the exact gap #379 closes).

Ruled by agent under ADR 0174 — veto anytime.

## Close-report — #379 landed on `main` (push mode) **Commit:** `431102d` — `gate: #379 — add a scoped shellcheck tier to the pre-push gate (fail-open until provisioned)` (on `origin/main`). ### What landed A shellcheck tier in the pre-push gate (`gate-lib.sh`/`gate.sh`), mirroring the gofmt/docs tiers, run on **every** push path (`--prepush` AND `--prepush-host` — where #360/#371/#378 all slipped past CI): - `gate_langs_for_files` grows an `sh` token; `gate_sh_files` collects the changed shell files. - `gate_shellcheck_stage <root> <file…>` resolves first-match-wins: `GATE_SHELLCHECK_CMD` (receives the changed files as `$@`) → `shellcheck` on PATH → the fail arm. `gate_shellcheck_default_cmd` runs `shellcheck -S warning -x` over **only the changed shell files** (sub-second; a whole-tree run is ~3 min, too slow for a push). - `gate_shellcheck_available` (the `GATE_NO_SHELLCHECK=1` test seam, #314 lesson). - Wired into `gate_run` (which now captures stdin once, since the lang set and the scoped file list both read it). ### The decision this session settled (Ruled by agent under ADR 0174 — veto anytime) **Fail-open vs fail-closed + provisioning.** Ruled **fail-OPEN with a loud warning** where no shellcheck resolves; **fail-closed on findings** wherever a shellcheck is armed; and a `GATE_SHELLCHECK_REQUIRE=1` toggle that flips the no-binary arm fail-closed once provisioned. Why this tier alone defaults fail-open (the other tiers fail closed): shellcheck is **not provisioned-by-contract** across the fleet — it is **absent from `bens-mac-04`'s PATH** (a pool host, where this very session-runner pushes), the factory carries no nix flake providing it, and `ci / static` tarball-FETCHES a pinned v0.11.0 (a fetch #332/#333 proved fraught). A fail-closed tier that resolved no shellcheck would block the live reconcile/session rail for **every shell-touching push across all consumers** — a fleet-wide outage far worse than the CI-only reds it pre-empts. Proof: this push's own pre-push gate warned and passed on `bens-mac-04`; the rail is not blocked. ### The one-way door left to a human (filed as follow-up) Fleet-wide shellcheck **provisioning** (put `shellcheck` on each pool host / consumer dev-shell / the sandbox image) and then setting `GATE_SHELLCHECK_REQUIRE=1` to make the tier **enforce**. That is host/flake posture a session must not widen from here. Follow-up: #380 (below). ### Proof - `tests/gate-lib-test.sh`: **63 → 80 checks**, all green (detection, scoped extraction, the override seam + `$@` passing, git-env scrub, the fail-open default + loud warning, the `GATE_SHELLCHECK_REQUIRE` fail-closed arm, override precedence, `gate_run` on both profiles, and a guarded real-binary fixture block proving SC2155/SC2164 are refused and the scan is file-scoped). - Full offline suite (`for t in tests/*.sh onboarding/tests/*.sh; …`): green. - `tests/docs-budget-test.sh`: green (STATUS.md surface compacted to hold the new row under the #374 ≥2 KB headroom floor). - `bash -n` over the `ci / static` scan set: clean. ### Docs / blast radius - GOTCHAS #379 (`docs/gotchas/379-shellcheck-tier-fails-open-where-unprovisioned.md`) + index row; journal `docs/journal/2026-11-19-379.md`; STATUS.md blocker row. - The `sh` mapping is by **extension / universal harness filename** (`*.sh`, `git-hooks/*`, `git-fence`), deliberately **not** `ci.yml`'s factory-root dir globs (`onboarding/`, `tests/`, `.forgejo/`) — a vendored file must name no product path (CLAUDE.md; `ci.yml` is not vendored). This is a superset of the factory's own scan set, which only tightens the gate and is correct in every consumer. ### Owed A **re-vendor** (GOTCHAS 4): `gate-lib.sh`, `gate.sh`, `tests/gate-lib-test.sh` are vendored, so the running `.sandcastle/` self-copy + consumers pick up the tier only at their next `FACTORY_REF` bump. Until then this repo's own pre-push runs the pre-#379 vendored gate (confirmed: this push reported "no gated language touched" for its `.sh`/`.md` change — the exact gap #379 closes). Ruled by agent under ADR 0174 — veto anytime.
matou-build-agent 2026-11-20 02:41:10 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#379
No description provided.