Files
CatoandClaude Opus 5.5 51d3566cb1 feat(fleet): drift.sh — is the same commit on the laptop, GitHub, Gitea and the box? (#572)
Reads the state at every layer instead of a pipeline's record of it:
`git ls-remote` for GitHub, the forge branch API for Gitea, HEAD of each
primary checkout, and the commit the box SERVES (release symlink, .release,
newest releases/ entry, else /api/health `commit`).

Why now: on 2026-11-20 a manual pass found the dotfiles checkout 8 PRs behind,
9 checkouts up to 724 commits behind on long-landed branches, and evig serving
a release one PR old — while deploy-freshness-audit.mjs, which reads GitHub
Deploy RUNS, had been blind since Actions stopped on 2026-11-15.

Silent when clean. A layer it cannot read is UNMEASURED and printed, never
folded into fine or gone: its first real run called six healthy repos "gone"
because GitHub throttled a parallel burst, so only "not found" means gone,
and each read is retried once. 19 tests on real repos; five mutations each
turn the suite red.

Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 12:59:55 +01:00

493 lines
27 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:
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
# Laptop = GitHub = Gitea = box. The failure that matters is a layer it
# could not read being reported as fine or as gone: its first real run
# called six healthy repos "gone" because GitHub throttled a burst. So
# "unreadable" is pinned as its own verdict, distinct from both.
- name: The drift check sees every layer, and never mistakes a failed read for an answer
run: bash scripts/fleet/test-drift.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
# Package repos are created from a declaration with no human looking, so
# the self-test is about refusing: a malformed declaration, a source path
# that escapes its repo, a package with no verify or no version each stop
# the run before anything is created, and an existing repo is never a
# target.
- name: Declared package repos are created safely, or not at all
run: node scripts/packages/test-create-package-repos.mjs
# The same for app and service repos: created empty, with exactly the
# visibility the declaration states, or not at all.
- name: Declared app repos are created safely, or not at all
run: node scripts/repos/test-create-app-repos.mjs
- name: Package repository settings stay enabled and fail closed
run: node scripts/packages/test-reconcile-package-repo-settings.mjs
# The one-off move of four unscoped packages under @bitbaum: renames
# specifiers and dependency keys, never prose, lockfiles or changelogs.
- name: The package-scope rename touches specifiers and nothing else
run: node scripts/packages/test-rename-package.mjs
# Every package repo is rendered from templates/package, and existing
# ones are offered its missing files by pull request. So the template's
# workflows must parse and hold valid shell (they fail far from here
# otherwise), the template must carry every required file — release.yml
# is how a package's owner ships from Loki — and the sync must offer only
# what a repo lacks, never twice, never over a person's "no".
- name: The package template's workflows parse, and their shell is shell
run: bash scripts/ci/check-workflows.sh templates/package/.github/workflows
- name: The package template is complete, and the sync only adds what is missing
run: node scripts/packages/test-sync-package-template.mjs
- name: Package release staging contract
run: node --test scripts/packages/release-staging.test.mjs
# The wake script holds a dispatch button for every repo in the org; its one
# decision is pure and pinned both ways, with a cap.
- name: The sweep wake wakes what has work and leaves the rest
run: node scripts/ci/test-sweep-wake.mjs
- name: Authenticated product integration checks
run: node --test scripts/test/auth-integration.test.mjs
- name: Generated PR ownership and workflow admission
run: node --test scripts/ci/generated-pr.test.mjs
- name: Registry publication concurrency and recovery
run: node --test scripts/ci/publish-package-registry.test.mjs
- name: Required app check policy regression tests
run: node --test scripts/ci/app-required-checks.test.mjs
# The daily auth parity check's verdicts: configured-but-missing and
# shown-but-broken fail, not-configured-yet does not.
- name: Auth parity verdicts
run: node --test scripts/ci/auth-parity.test.mjs
- name: Verified release notifications
run: node scripts/packages/test-release-notify.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 Google Fonts audit still detects, and still stays quiet
run: bash scripts/ci/test-google-fonts-audit.sh
- name: The content-site browser smoke still fails on Google Fonts and on errors
run: node --test scripts/test/static-browser-smoke.test.mjs
- name: The org-drift audit still detects, and still stays quiet
run: bash scripts/ci/test-org-drift-audit.sh
# Docs held to their OWN repo: paths, links, scripts, stack majors and
# retired names an agent would act on. Also the sweep's docs gate, so a
# broken detector here is a broken merge gate everywhere.
- name: The docs-truth audit still detects, and still stays quiet
run: node scripts/ci/test-docs-truth-audit.mjs
# Served pages held to the registers: retired names, forbidden claims,
# stale copyright, dead same-site links.
- name: The live-claims audit still detects, and still stays quiet
run: node scripts/ci/test-live-claims-audit.mjs
# A package tagged on GitHub but missing from npm (ENEEDAUTH): reported
# with the npm Trusted Publisher fix, quiet while a release is publishing.
- name: The npm publish-lag audit still detects, and still stays quiet
run: node scripts/ci/test-npm-publish-lag-audit.mjs
# 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
node --test scripts/ci/package-release-target.test.mjs scripts/ci/shared-manifest-paths.test.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
# Generated registry/readings/proof changes use ordinary PRs. A direct
# main writer would bypass required checks even if it re-armed CI later.
- name: No workflow writes directly to main
run: bash scripts/ci/check-rearm.sh --forbid-main-writers
# 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
# Repo metadata (homepages, descriptions) is LIVE GitHub state no PR can
# change, so it is not judged per PR: it went red on every fleet PR on
# 2026-10-19 over five repos nobody had touched, including the PR that
# added the reconciler meant to repair them. repo-metadata.yml now writes
# homepages from the register daily and reports what is left; the
# detector's unit test still runs above, per PR.
# templates/app is the starter every new product is created from, so a
# defect in it ships into every repo made after it. Its contract — the
# blessed majors, the verify floor, the CI/CD hygiene rules, the security
# invariants — is checked here with the fleet's own judges, no network.
# The app-template job below installs, verifies and signs people in.
- name: The app starter holds the fleet's contract
run: |
node --test scripts/ci/package-composition-audit.test.mjs scripts/ci/package-rollout-gate.test.mjs scripts/ci/runs-for-sha.test.mjs scripts/ci/package-rollout-cli.test.mjs scripts/ci/package-canary-audit.test.mjs scripts/ci/git-package-currency.test.mjs scripts/ci/preferred-package-update.test.mjs scripts/ci/currency-toolchain.test.mjs scripts/ci/canary-currency-plan.test.mjs scripts/ci/currency-managed-mirrors.test.mjs
node --test scripts/test/auth-journey.test.mjs scripts/test/auth-browser.test.mjs scripts/test/auth-totp.test.mjs
node --test scripts/ci/release-receipt.test.mjs scripts/ci/verify-live-release-receipt.test.mjs
bash scripts/templates/test-app-template.sh
# 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"
# The starter, the way a product made from it runs: rendered with a test
# slug, installed from its lockfile, `pnpm run verify` (format, lint,
# typecheck, unit tests, build), and its accounts driven end to end against
# a real Postgres. Without this the template could rot while every check
# above stayed green — it is the one directory here nothing else executes.
app-template:
runs-on: ubuntu-latest
timeout-minutes: 20
services:
postgres:
image: postgres:17
env:
POSTGRES_USER: app
POSTGRES_PASSWORD: app
POSTGRES_DB: starter_test
ports: ["5432:5432"]
options: >-
--health-cmd "pg_isready -U app -d starter_test"
--health-interval 5s --health-timeout 5s --health-retries 10
steps:
- uses: actions/checkout@v7
- uses: pnpm/action-setup@v6
with:
package_json_file: templates/app/package.json
- uses: actions/setup-node@v7
with:
node-version-file: templates/app/.nvmrc
- name: Render, install, verify, sign in
env:
DATABASE_URL: postgres://app:app@localhost:5432/starter_test
NEXT_TELEMETRY_DISABLED: "1"
run: bash scripts/templates/test-app-template.sh --full