Skip to content

chore(ci): dedupe repeated workflow shell into scripts/ci, and gate it - #740

Merged
athvin merged 3 commits into
mainfrom
chore/ci-shell-dry
Nov 6, 2026
Merged

athvin merged 3 commits into
mainfrom
chore/ci-shell-dry

Conversation

@athvin

@athvin athvin commented Nov 6, 2026

Copy link
Copy Markdown
Owner

scripts-home-check.sh asks whether every shell file is under scripts/, and the answer has been yes for a while. A workflow's run: block is shell with no file, so it was invisible to that gate — and that is where it accumulated.

Deduped — the same shell, more than once

Helper Replaces The drift it was hiding
build-cost.sh 7 copies in rust.yml Two variants: five printed df, two did not — and df is the line that distinguishes a slow build from a full disk (which surfaces as linking with cc failed, not ENOSPC)
reclaim-disk.sh 4 copies (rust.yml ×3, kind.yml) Each had re-derived the errno-28 safety argument in its own words
install-helm.sh 3 copies Each pinned HELM_VERSION: v3.19.0 separately — three places to bump, two to forget, and the chart tier could lint against one helm while the deploy rendered with another
pass-key.sh + pass-decide.sh the pass gate in rust.yml and frontend.yml ~30 duplicated lines arguing why the skip is safe to trust
tf-step-summary.sh infra.yml's plan + apply summaries The plan copy swallowed a missing file with `
install-rust.sh 7 toolchain installs Two variants; now names --toolchain stable so the call sites no longer depend on their cwd

No open PR loses its pass marker. Both keys were verified byte-identical to the old inline logic against the same tree. A dead second awk in the frontend copy — filtering on an always-empty regex, so matching everything — is dropped rather than carried.

Extracted — single site, real logic

rust-detect.sh is the headline: the last of the four detect steps still inline (frontend/infra/images already had one), and the only one whose event branching no test could reach. Plus duckdb-cache-repair.sh, api-breaking-gate.sh, helm-lint.sh, tf-validate-all.sh, tf-apply-plan.sh, tf-drift-plan.sh, four deploy-*.sh and three agent-task-*.sh. Each carries the reasoning that sat above it; ${{ }} interpolated into shell became env:.

Left inline deliberately: five blocks of at most two commands with no control flow, and folded run: > scalars (one command however they wrap). The threshold is a stated rule, not a judgement call per site.

The new gate

workflow-shell-check.sh — a budget, not a ban: more than 3 lines of shell, or any control flow at any length, must move to scripts/ci/. The second clause is load-bearing; a three-line if is under any budget and is still a decision nothing can test in place. Comments are free, folded scalars are one command, generated workflows are skipped using the same marker test actionlint.sh uses. Runs in make check and in the ungated S9 job.

Its self-test runs first, and earned its place: the first parser missed the bare - run: | step form entirely — a form this repo uses — and mis-measured folded scalars. Both were caught by fixtures, not by reading.

Two bugs found on the way

  • gen_infra_coverage was silently wrong. It grepped infra.yml for the validate loop. Extracting the loop made it render every stack as unvalidated and report bootstrap/organization as covered by no tier. A silently wrong generated reference is worse than a stale one — it goes green the moment it is committed. It now searches both homes and fails loudly on zero via err_quiet, and the positive control was mutation-tested.
  • set -u broke the cold-cache path. In duckdb-cache-repair.sh, expanding an empty array under -u made the absent-tree path — the normal one — exit 1. The inline original ran under GitHub's bash -eo pipefail; that is restored, with the reason recorded so it is not re-added.

pass-key.sh also grew a positive control: zero keyed paths emits no key, so the gate runs. A key computed over an empty tree is the one outcome that must never happen — every PR colliding on one hash and skipping the gate on another's green.

Verification

actionlint, scripts-home-check, detect-paths-test, pass-gate-test (16 assertions), skills-check-test, workflow-shell-check and its self-test (16 assertions), and make skills-check are all green locally. pass-gate-test.sh drives the real pass-key.sh against throwaway commits via a PASS_KEY_REF seam rather than re-deriving its filter, and was mutation-tested against four distinct breakages.

The cargo tiers are untouched by this diff and left to CI, which runs them in full — scripts/ci/ is not exempt in detect-paths.sh, so this PR pays the whole backend gate.

Worth a close look at review: deploy.yml, drift.yml, kind.yml and agent-task.yml are not exercised by a pull request, so their extractions were verified by local smoke tests (including input-validation and injection cases for agent-task-ids.sh) rather than by this PR going green.

🤖 Generated with Claude Code

bmoore813 and others added 2 commits November 6, 2026 09:42
`scripts-home-check.sh` asks whether every shell FILE is under `scripts/`,
and the answer has been yes for a while. A workflow's `run:` block is shell
with no file, so it was invisible to that gate — and that is where it
accumulated.

Deduped (the same shell, more than once):

- `build-cost.sh` replaces 7 copies in rust.yml, in two variants: five
  printed `df` and two did not, and `df` is the line that tells a slow build
  from a full disk. Now one copy that always prints all three.
- `reclaim-disk.sh` replaces 4 copies (rust.yml x3, kind.yml), each of which
  had re-derived the errno-28 safety argument in its own words.
- `install-helm.sh` replaces 3 copies, each pinning `HELM_VERSION: v3.19.0`
  separately. One pin now; the chart tier and the deploy can no longer
  render with different helms.
- `pass-key.sh` / `pass-decide.sh` replace the content-addressed pass gate in
  both rust.yml and frontend.yml, together with ~30 duplicated lines arguing
  why it is safe to trust. Verified byte-identical: both gates compute the
  same key as before, so no open PR loses its marker. Dropped a dead second
  `awk` in the frontend copy that filtered on an always-empty regex.
- `tf-step-summary.sh` replaces infra.yml's plan and apply summaries.
- `install-rust.sh` replaces 7 toolchain installs, and names
  `--toolchain stable` so the call sites no longer depend on their cwd.

Extracted (single site, real logic): `rust-detect.sh` — the last of the four
detect steps still inline, and the only one whose event branching no test
could reach — plus `duckdb-cache-repair.sh`, `api-breaking-gate.sh`,
`helm-lint.sh`, `tf-validate-all.sh`, `tf-apply-plan.sh`, `tf-drift-plan.sh`,
four `deploy-*.sh` and three `agent-task-*.sh`. Each carries the reasoning
that was above it; `${{ }}` interpolation into shell became `env:`.

Left inline deliberately: five blocks of at most two commands with no control
flow, and folded `run: >` scalars, which are one command however they wrap.

New gate, `workflow-shell-check.sh` — a budget, not a ban: more than 3 lines
of shell, or any control flow at any length, must move to `scripts/ci/`. In
`make check` and in the ungated S9 job. Its self-test runs first, and earned
it: the first parser missed the bare `- run: |` step form entirely (a form
this repo uses), and mis-measured folded scalars.

Two bugs found and fixed on the way:

- `gen_infra_coverage` in skills-check.sh grepped infra.yml for the validate
  loop. Extracting the loop made it render every stack as unvalidated and
  report `bootstrap/organization` as covered by no tier — a silently WRONG
  generated reference, which goes green the moment it is committed. It now
  searches both homes and fails loudly on zero, via `err_quiet`.
- `set -u` in `duckdb-cache-repair.sh` made the empty-array path (the normal
  one on a cold cache) exit 1. The inline original ran under GitHub's
  `bash -eo pipefail`; that is restored, with the reason recorded.

`pass-key.sh` grew a positive control: zero keyed paths emits NO key, so the
gate runs. A key over an empty tree is the one outcome that must never
happen — every PR colliding on one hash and skipping on another's green.
`pass-gate-test.sh` (16 assertions) drives the real script against throwaway
commits rather than re-deriving its filter, and was mutation-tested against
four breakages.

Verified: actionlint, scripts-home-check, detect-paths-test, pass-gate-test,
skills-check-test, workflow-shell-check(-test) all green; both pass keys
byte-identical to the old inline logic. The cargo tiers are untouched by this
diff and left to CI, which runs them in full (scripts/ci is not exempt).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Extracting infra.yml's helm install and `helm lint` into scripts removed
them from the chart tier's own path filter. Inline, they lived in
`.github/workflows/infra.yml`, which the pattern matches — so the tier
re-ran on any edit to them. As files they matched nothing, so a PR editing
only `helm-lint.sh` would no longer render or schema-check a chart.

That is the `paths:`-filter trap in CLAUDE.md — a change to a gate not
triggering the gate it defines — arriving through a refactor rather than
through a filter, which is the direction nothing was watching for.

`install-helm.sh` is in the pattern too: it owns the helm pin for three
workflows, so a bump must render the charts with the helm that will
deploy them.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

terraform plan

b8f3f67 · run log and full plans

env add change destroy
state-backend (plan only) 0 0 0
core 0 0 0
dev 0 0 0
prod 0 0 0

Planned with -refresh=false, so this is the config-versus-state diff and
not out-of-band drift. That is a security choice, not a speed one: a refreshing
plan reads secret values, and the plan role is assumable from any PR branch —
which can edit the workflow it runs under. Drift is caught at apply time, which
refreshes fully.

`pass-gate-test.sh` built its probe trees with `git commit-tree`, which needs a
committer identity. `actions/checkout` configures none and the runner's passwd
entry has an empty name, so CI died on

    fatal: empty ident name (for <runner@...>) not allowed

while a laptop passed, because git there auto-detects a name from the OS. That
asymmetry is the whole reason the first run was red: the test was green
locally and could not have been green on any runner.

`pass-key.sh` only ever runs `git ls-tree -r "$REF"`, and that accepts a
tree-ish — so `git write-tree` is enough and no commit object is needed. The
test now depends on no ambient git config at all. Verified by running it with
`GIT_*_NAME` forced empty and the global/system config nulled, which
reproduces the runner exactly.

Also guarded the helper. When `probe` failed it returned empty, `keyat` fell
through to its `HEAD` default, and the assertions degraded to comparing HEAD
with HEAD — caught, but reported as "two equal keys" rather than "the probe is
broken". `probed` now exits 2 on an empty OID.

Re-mutation-tested after the change: dropping the HIT check, dropping the
COUPLED re-admit, and ignoring PASS_KEY_REF are each still caught.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 80c05f2 into main Nov 6, 2026
47 checks passed
athvin added a commit that referenced this pull request Nov 6, 2026
…#741)

Two of the three open items from #740. The third — promoting
`workflow pins (S9)` to a required check — is branch-protection
configuration rather than a file in this tree, and is applied separately.

COVERAGE FOR THE AGENT-TASK SCRIPTS (`scripts/ci/agent-task-test.sh`, 25
assertions, in the ungated S9 job).

`agent-task.yml` is `workflow_dispatch` only and needs
`CLAUDE_CODE_OAUTH_TOKEN` and `AGENT_APP_KEY`, neither of which this repo
has — so dispatching it to exercise the extraction would die at the agent
step having proved nothing about the three scripts that run before and
around it, and would leave an `agent-wip/<run-id>` branch on the remote for
the trouble. All three are pure logic over environment variables, so a test
covers them completely and covers them on every PR rather than once.

The load-bearing half is input validation. `resume` is a dispatch input that
reaches `refs/heads/agent-wip/$RESUME` and the agent's prompt, so it is
attacker-shaped text until proven numeric: the suite rejects command
substitution, backticks, path traversal, leading and trailing whitespace,
negatives, decimals and over-length digits, and accepts the documented
20-digit bound so the rule cannot degrade to "reject everything long". It
also pins that `agent-task-summary.sh` renders absent, empty, status-less
and malformed structured output as three distinct cells without failing a
step that runs on `always()`, and that `agent-task-checkpoint.sh` refuses an
empty WIP rather than pushing to `refs/heads/`.

Mutation-tested: unanchoring the regex, dropping the length bound, removing
the validation entirely, and removing the jq fallback are each caught, on the
assertions that should catch them.

The other two extractions #740 left unexercised are now verified by real
runs instead, both dispatched against `main`:

- `drift.yml` (read-only by construction — the role holds no S3 write):
  `tf-drift-plan.sh` succeeded on all four stacks, and `classify the
  refresh` consumed its output, so the script really did write both the
  redacted text and the JSON.
- `kind.yml`: `reclaim-disk.sh` and `install-kind-tools.sh` both succeeded.
  The probe job itself is a ~2h executor e2e that fails for reasons predating
  this work; the two steps this change owns are early and are proven.

DESCRIPTION BUDGET. All four skills in the warning band are trimmed under it,
so the generated budget table now reads "none; every skill can take another
clause" — which was the point of the warning: headroom to absorb a routing
tail without an unrelated PR discovering the cap as a failed gate.

Only redundancy and prose were cut, never a routing clause or a `Use when`
trigger — CLAUDE.md's generated routing table is byte-identical after regen,
which is the check that the triggers survived. Headroom now: land-pr 891
(+133), project-board 913 (+111), skill-audit 956 (+68), security 957 (+67).

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants