Files
fleet/.github/workflows/ci.yml
CatoandClaude Opus 5.5 31de29870b fix(scripts): grep -q is never the reader of a pipe under pipefail (#140)
* fix(scripts): grep -q is never the reader of a pipe under pipefail

`echo "$x" | grep -q PAT` under `set -o pipefail` can report "not found"
for text that IS there: grep -q exits on its first match and closes the
pipe, the writer takes SIGPIPE (141), and pipefail makes the pipeline
status 141, so an `if` takes the else branch on a successful match.

It is not confined to payloads past the ~4KB pipe buffer. Measured in
loki (loki#874) on a real 1,158-byte output, 3,000 calls: 2/3000 false
misses for a phrase near the top, 0/3000 via a here-string. Rare per
call; a suite makes hundreds. loki's retire-site suite went red on
exactly those phrases twice this week.

48 copies in 14 scripts here, rewritten to `grep -q PAT <<<"$x"`,
including:
- auto-merge-sweep.sh: the required-check coverage test. A false miss
  marks a green job "uncovered".
- gc-merged-worktrees.sh: `in_use`. A false miss reads a live session's
  worktree as unused. The pushed / clean / MERGED guards still stand, so
  it cannot lose work, but it can remove a directory from under a live
  session.
- cicd-hygiene, nav-contract, org-drift, verify-floor audits and
  verify-predicates: false passes and false findings.

Checked: all 14 files pass `bash -n`; every file is a 1:1 line swap (48
lines); the 8 line-continuation sites keep the here-string before the
trailing backslash; fleet's 30 CI test scripts pass before and after
(30/30 -> 30/30); workflows still parse.

Gate: scripts/ci/test-no-grep-q-in-a-pipe.sh, wired into ci.yml. Scans
scripts/ and templates/, self-tests its detector both ways, and was
proven by restoring the original auto-merge-sweep.sh line.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>

* fix(ci): main was red on a ratchet that fell, and a sweep test lied

Two failures on fleet main that were blocking every PR, including this
one. Neither was caused by the grep -q rewrite: main (7ed94a2, the base
of this branch) failed CI on the same step for the same reason.

1. org-drift ratchet fell. `org-drift-audit.sh --check` failed on main
   since c43464d with "baseline entries with no matching violation - the
   ratchet fell: bitbaum/README.md". Good news: someone fixed that drift.
   Nobody lowered the baseline, so main stayed red and the auto-merge
   sweep refused everything. Line removed; --check now passes (44 repos
   swept, 3 known violations, no new contradictions).

2. test-auto-merge-sweep.sh lied. Its verdict `[ "$FAIL" -eq 0 ]` sat at
   line 400 of 473, with ~70 lines of tests appended after it. A bash
   script exits with its LAST command's status, so the verdict was
   discarded: the suite exited 0 while printing "27 passed, 1 failed",
   and its later tests were not even counted. Verdict moved to the end;
   the suite now counts 38.

   The hidden failure was real and was mine: test 13 asserted the sweep
   always "waits for CI to catch up" when the newest base run is for an
   older commit. The deadlock fix changed that - it waits only while a
   run is in flight, and otherwise dispatches CI. Test 13 now asserts
   both cases (13a waits and dispatches nothing; 13b dispatches and does
   not merge). `rearms()` moved above its first use.

Proven by mutation: an injected late failure now fails the suite;
reverting the sweep to always-wait fails 13b; making it never wait fails
13a.

Gate: scripts/ci/test-verdict-is-last.sh, wired into ci.yml, requires
every suite's verdict to be its file's last command. Proven by restoring
the old mid-file verdict. All 34 fleet CI commands are now green, and
none exits 0 while reporting a failure.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>

---------

Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 11:58:34 -07:00

389 lines
21 KiB
YAML

# The fleet's central automation defends every other repo's branch, so its own
# CI is the last one that may quietly stop working. Moved here from dotfiles
# 2026-08-28 — this repo is the audits, the templates and the registry; the
# environment stayed behind.
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
verify:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
# Shell must parse. install.sh is what lands on a new machine; a syntax
# error there is discovered at the worst possible moment.
- name: Shell syntax
run: |
set -euo pipefail
found=0
while IFS= read -r f; do
found=$((found + 1))
bash -n "$f"
done < <(find . -name '*.sh' -not -path './.git/*')
echo "shell syntax: ok ($found script(s) checked)"
# Every CI template must be valid YAML — a broken template is copied
# into a repo and fails there, far from here.
- name: Templates are valid YAML
run: |
set -euo pipefail
found=0
for f in templates/ci/*.yml; do
[ -e "$f" ] || continue
found=$((found + 1))
python3 -c "import yaml,sys; yaml.safe_load(open(sys.argv[1]))" "$f"
done
[ "$found" -gt 0 ] || { echo "no CI templates found — did they move?" >&2; exit 1; }
echo "templates parse: ok ($found template(s))"
# And THIS repo's own workflows, which nothing checked until 2026-09-21 —
# when `internal-currency.yml` merged to main as invalid YAML. The
# failure mode is why it matters: a workflow GitHub cannot parse does not
# go red, it is registered with its file PATH where its name belongs and
# simply never runs, on dispatch or on schedule. A silence that reads
# exactly like health.
#
# Two halves, because they fail independently: the file must parse and
# keep `name:`/`on:`, and every `run:` block must be valid shell once
# YAML has stripped its indentation. The second is what catches the
# flush-left heredoc that ends a block scalar mid-command.
- name: This repo's workflows parse, and their shell is shell
run: bash scripts/ci/check-workflows.sh
- name: The workflow checker still bites, and stays quiet when it should
run: bash scripts/ci/test-check-workflows.sh
# `echo/printf "$x" | grep -q` under pipefail reports a MISS on a match
# when grep exits first and the writer takes SIGPIPE. It is not confined
# to large payloads (2/3000 false misses at 1.1 KB, loki#874), and 48
# copies here included the auto-merge sweep. Here-strings only.
- name: No shell script pipes a writer into grep -q
run: bash scripts/ci/test-no-grep-q-in-a-pipe.sh
# A bash script exits with its LAST command's status. The sweep suite's
# verdict sat mid-file with ~70 lines of tests after it, so it exited 0
# while printing "1 failed" and a stale test hid on main.
- name: Every test suite's verdict is its last command
run: bash scripts/ci/test-verdict-is-last.sh
# The template's whole premise is that "verified" is defined ONCE, in
# package.json `verify`, and CI calls it verbatim. If a template stops
# doing that, the premise is gone and nobody would notice.
- name: Templates still call the verify SSOT
run: |
set -euo pipefail
for f in templates/ci/ci-npm.yml templates/ci/ci-pnpm.yml; do
grep -q 'run verify' "$f" || {
echo "$f no longer calls the verify SSOT — the template's core promise" >&2
exit 1
}
done
echo "verify SSOT: present in both templates"
# The fleet audit enforces the template's premise across every repo, so it
# is the last thing that may quietly stop working. Its wiring rules are
# tested BOTH ways: that each still bites against a violating fixture, and
# that conforming shapes are not flagged — a checker that cries wolf gets
# ignored, which is the same end state as no checker.
#
# The rules sit in verify-predicates.sh so they are testable at all: the
# audit is remote-only by design, and a rule that can only be exercised by
# a live API call is a rule nobody re-tests after editing its regex.
- name: The verify-contract rules can still go red
run: bash scripts/ci/test-verify-predicates.sh
# The duplication ratchet's entire value is that it CAN go red. A ratchet
# that silently passes while duplication rises certifies the thing it was
# built to stop. Its counting half needs the API; its deciding half is
# pure text and is tested here against fixtures, with no network.
- name: The duplication ratchet can still go red
run: bash scripts/ci/test-shared-inventory.sh
# The hygiene ratchet decides from workflow TEXT, so its deciding half is
# provable with fixtures and no network — which is what makes it safe to
# run on every PR. Both directions are asserted: it must flag a deploy
# that cancels itself and a Next repo building cold, and it must NOT flag
# a CI workflow that cancels (correct), a deploy that is a repo's only
# verifier, or a non-Next repo with no .next/cache to restore. A predicate
# that never matches passes just as quietly as one that works.
- name: The CI/CD hygiene ratchet can go red, and stays quiet when it should
run: bash scripts/ci/test-cicd-hygiene-audit.sh
# The stranded-work guard replaces a check that failed by being ignorable:
# git-health reported orangecat's 118 dirty files every day for ten days
# and changed nothing. This one keys on AGE and stays silent when healthy,
# so both failure modes are gates — it must go red on aged work, and it
# must stay quiet on a fresh tree, or it gets muted and is then absent.
- name: The stranded-work guard can go red, and stays quiet when it should
run: bash scripts/fleet/test-stranded-work.sh
# This one DELETES CHECKOUTS, so its only interesting failure is a false
# positive. Every refusal in the predicate is a case that would otherwise
# have destroyed the single existing copy of some work, and each is pinned
# separately — a combined "unsafe" fixture is exactly what hides one guard
# silently inverting.
- name: The worktree GC refuses everything it should
run: bash scripts/fleet/test-gc-merged-worktrees.sh
# The sweep decides what ships in every repo that calls it, so it is the
# last script here that should be untested — and until now it was. These
# run the REAL script against a fake `gh`, exercising shipped control flow
# rather than a description of it. Ported from evig, the only repo that
# had them, when its copy of the script was centralised.
- name: The auto-merge sweep behaves
run: bash scripts/ci/test-auto-merge-sweep.sh
# The origin proof is only worth anything if it cannot be produced for
# content that did not exist and cannot be edited afterwards. Both halves
# are pinned with a fake calendar: a private repo's name never reaches
# the public manifest, an unchanged org stamps nothing, and a manifest
# edited after stamping fails its own proof AND the next link's.
- name: The origin proof cannot be forged quietly
run: bash scripts/ci/test-origin-proof.sh
# The register is what a public page says about when real work existed,
# so its test is about what it must NOT claim: a private repo listed, a
# pending proof called anchored, "proven since" taken from the newest
# manifest instead of the oldest anchored one.
- name: The origin register claims only what the proofs support
run: node scripts/ci/test-origin-register.mjs
# This audit reports on apps nobody is watching, so its own failure mode
# is silence. Pinned both ways with a fixture register and a fake gh: a
# live app with no committed env example is flagged, one with keys at
# its app_dir under any accepted name is not, a prospect is ignored, and
# the ratchet goes red only when the count rises.
- name: The bus-factor audit still detects, and still stays quiet
run: bash scripts/ci/test-bus-factor-audit.sh
# The entity-drift detector, both directions. Its first version counted
# type names and its only finding across the org was the sentence that
# FIXES the problem, so the fixtures here are the real historical text:
# three copies that must fire, two false positives that must not.
- name: The entity-drift audit still detects, and still stays quiet
run: python3 scripts/ci/test_entity_drift.py
# The readings are a public statement of the numbers the bet rests on,
# so the test is about not lying: a favour is not a paying client, '-'
# is unknown not zero, our own products are not clients, a package npm
# could not answer for is null not zero, and history grows only when a
# reading changes.
- name: The readings cannot flatter
run: node scripts/ci/test-readings.mjs
# This detector reports on repos nobody is watching, so its own failure
# mode is silence: a clean report from a broken audit is worse than no
# audit, because it prints a ✓. Both sides are pinned — the real AOZ
# regression is still caught, corrected code stays quiet — plus the two
# false positives the first live run produced (xAI's `grok-3-mini` filed
# under Groq, and a computed `${...}` id read as a pin). No network, no
# key, no checkout, so it runs here as well as in the daily sweep.
- name: The model-pin audit still detects, and still stays quiet
run: node scripts/ci/test-model-pin-audit.mjs
- name: The hosted-Supabase audit still detects, and still stays quiet
run: bash scripts/ci/test-hosted-supabase-audit.sh
- name: The org-drift audit still detects, and still stays quiet
run: bash scripts/ci/test-org-drift-audit.sh
# The judgement is a pure function of (repos, register, allow), so its
# test needs no network — the fixtures are the shapes that were live on
# 2026-09-11, including hirnli's correct-but-looks-wrong homepage.
- name: The repo-metadata audit still detects, and still stays quiet
run: node scripts/ci/test-repo-metadata-audit.mjs
# Same doctrine: the currency ratchet reports on repos nobody touches,
# so its own test pins both sides — the real 2026-08-31 staleness
# (aoz-begleitung's manifest, dead-owner ai-kit pin) is caught, a current
# manifest stays quiet, and an unreadable repo is UNCHECKED, never clean.
- name: The version-currency audit still detects, and still stays quiet
run: node scripts/ci/test-version-currency.mjs
# The audit above judges MAJORS, which is the wrong instrument for our own
# packages — we ship features in minors, so ten repos can be six minors
# behind ai-kit while it reports zero gaps. This one sees that, and OPENS
# the PR rather than reporting it. Its decisions are pure, so they are
# proved here before a scheduled run is trusted to push a branch to
# thirteen repositories. Both sides pinned: the same-major drift is
# caught, a current repo stays silent, and `workspace:*` or a git pin
# comes back untouched — quietly rewriting a range somebody chose is the
# worst thing this script could do.
- name: The currency reconciler bumps what it should, and nothing else
run: node scripts/ci/test-currency-reconciler.mjs
# This one guards a fix that ALREADY reverted once: petvity's
# NEXTAUTH_URL was fixed in Aug and was wrong again in Sep, advertising
# https://localhost:4013 in public JSON for weeks. So the detector's own
# silence is the thing to distrust. Both sides are pinned from captured
# payloads — the real regression is caught, the repaired payload stays
# quiet, a 500 from next-auth FAILS rather than being read as "no data",
# and a site with no next-auth SKIPs rather than crying wolf. No network.
- name: The next-auth origin guard still detects, and still stays quiet
run: node scripts/ci/test-nextauth-origin-audit.mjs
# Merged is not live. Most commits here never fire their own Deploy — they
# ride the auto-merge reconciler — so the audit's common case is "covered
# by a LATER successful deploy", and demanding an exact-SHA run would
# report nearly the whole fleet stale while everything was fine. The
# fixtures pin that, both boundaries of the grace window, and that a
# failed/cancelled/in-progress deploy never counts as shipped.
- name: The deploy-freshness audit still detects, and still stays quiet
run: node scripts/ci/test-deploy-freshness-audit.mjs
# The registry that every other audit's advice points at was the one
# thing nothing measured: on 2026-09-12 bip-kit had eight adopters and no
# row, while being MENTIONED in the prose — so the fixtures pin that a
# mention is not a row, and that the aliases half the fleet installs
# under (`npm:`, `github:`) resolve to the package rather than the key.
- name: The shared-registry audit still detects, and still stays quiet
run: node scripts/ci/test-shared-registry-audit.mjs
# The identity gate's own sweep runs weekly (product-identity.yml) because
# it reads the register over the network; its JUDGEMENT is a pure function
# of the rows, so it is pinned here on every change. Both directions plus
# a mutation: flipping one FIELDS row to published must turn a previously
# clean product red, or the table is decoration and rule 1 is the whole
# audit forever.
- name: The product-identity audit still detects, and still stays quiet
run: node scripts/ci/test-product-identity-audit.mjs
# This script can DELETE repositories, so its selector is pinned in both
# directions on every fixture and its --yes guard is exercised through
# the script itself, not re-implemented. Four mutants (selector ignores
# the topic, substring instead of exact match, guard removed, silent
# empty result) were each confirmed to turn it red before it shipped.
- name: The ephemeral-repo pruner selects only what is marked
run: bash scripts/ci/test-prune-ephemeral-repos.sh
# The gate on the gates. Twenty-one audits here police every repo and
# nothing policed them: on 2026-09-17 four were red, stale or cancelled
# for days with no signal anywhere. Its own worst bug was caught by this
# suite before it shipped — word-splitting a cron expression globs the
# `*` fields against the working directory, so staleness never fired.
- name: The audit-health rules bite, and stay quiet on conforming shapes
run: bash scripts/ci/test-audit-health.sh
# NO phantom-secret check here, and the reason is worth the paragraph.
#
# The check needs the names of the secrets that exist. The API listing
# needs a scope no token in this repo has, so the only way to get them is
# `toJSON(secrets)` — and a workflow that references the secrets context
# UNDER A `pull_request` TRIGGER is held by GitHub for manual approval:
# the run completes `action_required` with ZERO JOBS, and nothing
# executes. Measured four times, and the factor is exactly that:
#
# #105 audit-health, pull_request, no toJSON -> ran
# #106 audit-health, pull_request, toJSON -> action_required
# #106 ci.yml, pull_request, no toJSON -> ran
# #107 ci.yml, pull_request, toJSON -> action_required
#
# An unapproved run reads as "not passing" and blocks the merge queue,
# and POST /actions/runs/:id/approve refuses it ("not from a fork pull
# request"). So on a PR the check cannot run at all, and pretending
# otherwise would ship the decoration this repo exists to delete.
#
# It therefore lives in audit-health.yml's DAILY run, which is scheduled
# and not gated, and which pushes a Telegram when it bites. A phantom
# secret introduced by a PR is caught within a day rather than at merge.
# That is a real gate on a slower clock, which beats a fake one on a fast
# clock.
# Rung 5's detector — the one that finds credential material in a
# RESPONSE rather than a pattern in code. It shipped 2026-09-15 with this
# suite and a real cross-account disclosure to its name, and nothing ran
# either of them until 2026-09-17. Both directions: a bcrypt digest in a
# flight payload must fire, a correctly projected response and a by-design
# share token must not.
- name: The secret-in-response detector bites, and stays quiet when it should
run: python3 scripts/audit/test-secret-in-response.py
# And the sweep on top of it, which answers a different question: does one
# app's finding reach exit 1, and is a host we could not reach withheld
# rather than counted clean. It caught the sweep announcing a clean fleet
# when every host was unreachable.
- name: The secret-in-response sweep aggregates honestly
run: bash scripts/audit/test-secret-in-response-sweep.sh
# A workflow that COMMITS TO MAIN must re-arm CI, or it stalls the queue.
#
# A push made with GITHUB_TOKEN triggers no workflows, so main gets no CI
# run for that commit and the auto-merge sweep refuses everything with
# "main is at <tip> but the newest CI run is for <older>" until a human
# dispatches CI by hand — which nothing tells them to do. Hit four times
# in two days (readings, then origin proof) before it was named, each
# time silently holding every open PR in the repo.
#
# The sweep already re-arms after its OWN merges for exactly this reason.
# The three workflows that commit to main simply never got the same line,
# and nothing noticed because each one looks fine in isolation.
#
# Inline like the other one-invariant gates here. Proven by mutation:
# deleting any of the three re-arms turns this red.
# Moved out of this file 2026-09-21 and narrowed, after it produced its
# first false positive: it keyed on `grep -q 'git push'`, which is
# coarser than the invariant its own name states, and demanded that a
# workflow pushing a FEATURE branch to ANOTHER repository dispatch
# fleet's CI. The gate was not wrong — it indexed more than it was
# trusted to cover — and the remedy is the one this file keeps reaching
# for: narrow it to the invariant, and put it where fixtures can reach
# it, exactly as the verify-contract rules live in verify-predicates.sh.
- name: Every workflow that pushes to main re-arms CI
run: bash scripts/ci/check-rearm.sh
# The narrowing is the change that most needs pinning from both sides: a
# gate loosened until it stops complaining and a gate that cries wolf end
# in the same place. Eleven fixtures, no network — the bare push, the
# explicit `origin main`, `HEAD:main`, and the doorway a variable target
# would otherwise open when the file sets it to main.
- name: The re-arm gate still bites, and stays quiet when it should
run: bash scripts/ci/test-check-rearm.sh
# The sweep's own logic had no test at all — only `bash -n` — and it
# deadlocked bitbaum/loki for fifteen days while exiting 0 every ten
# minutes. Drives the real script against a stubbed gh: it must dispatch
# CI when the base tip has no run and none is coming, must NOT dispatch
# when CI is genuinely in flight (that caused a cancellation storm), and
# must still refuse to merge onto a base it has no verdict for.
- name: The sweep cannot deadlock waiting for CI that will never run
run: bash scripts/test/auto-merge-sweep-no-base-ci.sh
# Org-drift guard: a new contradiction in public docs fails the check.
# Uses gh CLI to scan bitbaum org repos. The baseline holds existing
# violations; new ones cannot land.
- name: No new org contradictions
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bash scripts/ci/org-drift-audit.sh --check
# A repository page is the first thing anyone opens and the furthest
# surface from the code. On 2026-09-11, 13 registered apps had no
# homepage at all and one pointed at a domain that is not the app's.
- name: Repo metadata agrees with the register
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node scripts/ci/repo-metadata-audit.mjs --check
# Drift guard. The fleet is on v7; templates handing out v4 is exactly
# how this repo fell behind the repos it governs.
- name: No stale action versions
run: |
set -euo pipefail
if grep -rnE 'actions/(checkout|setup-node)@v[1-6]\b' templates/; then
echo "stale action version in a template — the fleet is on v7" >&2
exit 1
fi
echo "action versions: no stale pins"