codehealth: the scan runs as its own CI step, 60-code-health
Measured once locally at nice and GOMAXPROCS=4: the scan took 165 s on a cold build cache and 18 s warm. The untagged half reuses the compiles make test already does; the tagged half (rootrunner and the cutover witnesses' tag) compiles every package and its test variant again, since tags change the cache key and vet leaves the vetted package itself uncompiled. That is over the plan's budget for 10-gate, so the scan moves out. - make code-health runs TestCodeHealth (skipped without CODEHEALTH_GATE) and requires its PASS line; the new .amadan/ci.d/60-code-health runs that target. Its -v log prints the sites below the record and the line metrics' physical lengths. - The record comparison is renamed 61-code-health-record. - make test keeps the fixture tests and a new TestRecordFile, which checks the record's syntax and sorted form (0.2 s). - AGENTS.md, .amadan/README.md and the record's header follow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 files changed,
+103
−43
.amadan/README.md+18 −15.amadan/ci.d/60-code-health+25 −0.amadan/ci.d/{60-code-health-record => 61-code-health-record}+1 −1.amadan/code-health.tsv+7 −6AGENTS.md+6 −4Makefile+16 −1internal/codehealth/codehealth_test.go+23 −10internal/codehealth/record_test.go+7 −6
CI cancelled — superseded by a newer push — run details
diff --git a/.amadan/README.md b/.amadan/README.md| index 97ea99a0e..7cc1b2a90 100644 |
| --- a/.amadan/README.md |
| +++ b/.amadan/README.md |
| @@ -42,8 +42,8 @@ could not see them, and the code-health ratchet's two on 2026-11-17. |
| | tagged vet | `10-gate` | `go vet -tags rootrunner,carlos_cutover_witness ./...`, via `make test`: the root-runner tests are type-checked, not run | |
| | `staticcheck` | `40-staticcheck` | `make staticcheck`: v0.8.2, bug checks only; `staticcheck.conf` names the families still off | |
| | `govulncheck` | `50-govulncheck` | `make govulncheck`: v1.8.0 over this module and `launchctx`; fails only on vulnerabilities the code calls, less the exceptions file; see below | |
| -| code-health gate | `10-gate` | `TestCodeHealth` (`internal/codehealth`), via `make test`: the code against `.amadan/code-health.tsv`; see below | |
| -| code-health record | `60-code-health-record` | the record against the merge base's copy; see below | |
| +| code-health gate | `60-code-health` | `make code-health`: the code against `.amadan/code-health.tsv`, scanned with type information; see below | |
| +| code-health record | `61-code-health-record` | the record against the merge base's copy; see below | |
| ## `govulncheck`: what turns it red |
| @@ -87,27 +87,30 @@ context, long functions and files, and more; its header lists them and |
| says how they are counted). Two checks hold it, and a count can only |
| go down: |
| -- **`TestCodeHealth`**, in `make test`, scans the tree with type |
| +- **`60-code-health`** (`make code-health`) scans the tree with type |
| information and fails when the code has more at a site than the |
| - record allows, or an offence at a site with no line. Fewer passes. |
| - `make code-health-record` then lowers the record; it never adds or |
| - raises a line. A moved site keeps its allowance with |
| - `MOVE='<old>:<new>'`. |
| -- **`60-code-health-record`** compares the record with the merge base's |
| + record allows, or an offence at a site with no line. Fewer passes, |
| + and the log prints those sites. `make code-health-record` then |
| + lowers the record; it never adds or raises a line. A moved site keeps |
| + its allowance with `MOVE='<old>:<new>'`. |
| +- **`61-code-health-record`** compares the record with the merge base's |
| copy and fails on a line that is new or higher there unless it ends in |
| a new `# raised: <reason>`, or is a `# moved-from:` transfer within the |
| old site's allowance. So a raise is always a visible, reviewed edit. |
| -The second step needs main's history, which the runner's shallow clone |
| -lacks: it fetches main from `origin` (readable without credentials) and, |
| +The scan is its own step, not part of `make test`, because of its cost. |
| +It type-checks every package and its tests twice, with no tags and with |
| +the gate's tags. The untagged half reuses the compiles `make test` |
| +already does. The tagged half compiles every package and its test |
| +variant again: on a cold cache the scan took 165 s at `GOMAXPROCS=4`, |
| +against 20 s warm. `make test` still runs the package's fixture tests |
| +and checks the record's syntax. |
| + |
| +The record step needs main's history, which the runner's shallow clone |
| +lacks. It fetches main from `origin` (readable without credentials) and, |
| the first time on a workspace, unshallows the clone. Its header says |
| how it finds the base, and why it uses HEAD's parent on main. |
| -The scan takes about 20 s on a warm build cache, at `GOMAXPROCS=4`. It |
| -type-checks every package under two tag sets, so a cold cache costs |
| -the compiles the gate's vet and test jobs also need. That is why it |
| -runs inside `10-gate` and not as a step of its own. |
| - |
| ## `gofmt`: ported by widening it, not by reproducing it |
| This section is the reason it was safe to delete the workflow, so it is |
diff --git a/.amadan/ci.d/60-code-health b/.amadan/ci.d/60-code-health| new file mode 100755 |
| index 000000000..47d7036b3 |
| --- /dev/null |
| +++ b/.amadan/ci.d/60-code-health |
| @@ -0,0 +1,25 @@ |
| +#!/bin/sh |
| +# The code-health ratchet (the Go code health plan, |
| +# docs/superpowers/plans/2026-11-16-go-code-health.md, Part 2): the code |
| +# against .amadan/code-health.tsv. `make code-health` is the one |
| +# definition; this step only runs it, so a developer gets the same answer |
| +# with the same command. |
| +# |
| +# Red means the code has more of some offence at a site than the record |
| +# allows, or an offence at a site with no line; the log names each one. |
| +# Fewer than the record is green, and the log prints those sites too |
| +# ("below the record"): `make code-health-record` lowers them. The |
| +# record's header says what is counted and how a moved site keeps its |
| +# allowance. 61-code-health-record checks the other half: that the record |
| +# itself only went down. |
| +# |
| +# Its own step rather than part of 10-gate's `make test`: the scan |
| +# type-checks every package with its tests under no tags and under the |
| +# gate's tags. The untagged half reuses the gate's own compiles, but the |
| +# tagged half compiles every package and its test variant again, which on |
| +# a cold cache took 165 s on a 4-core budget (20 s warm). `make test` |
| +# still runs the package's fixture tests and checks the record's syntax. |
| +set -eu |
| +. .amadan/go-toolchain.sh |
| + |
| +make code-health |
diff --git a/.amadan/ci.d/60-code-health-record b/.amadan/ci.d/61-code-health-record| similarity index 97% |
| rename from .amadan/ci.d/60-code-health-record |
| rename to .amadan/ci.d/61-code-health-record |
| index 0b43517e8..b27050637 100755 |
| --- a/.amadan/ci.d/60-code-health-record |
| +++ b/.amadan/ci.d/61-code-health-record |
| @@ -2,7 +2,7 @@ |
| # The code-health record may only go down (the Go code health plan, |
| # docs/superpowers/plans/2026-11-16-go-code-health.md, Part 2). |
| # |
| -# The gate (TestCodeHealth, in 10-gate's make test) compares the code with |
| +# The gate (TestCodeHealth, run by 60-code-health) compares the code with |
| # .amadan/code-health.tsv. This step compares the record with the merge |
| # base's copy, so the record cannot be raised to fit the code: a line that |
| # is new, or higher than at the merge base, fails here unless it carries a |
diff --git a/.amadan/code-health.tsv b/.amadan/code-health.tsv| index 4249e8d09..455f4bec7 100644 |
| --- a/.amadan/code-health.tsv |
| +++ b/.amadan/code-health.tsv |
| @@ -12,12 +12,13 @@ |
| # GOOS=linux, twice: with no tags and with the gate's (rootrunner and the |
| # cutover witnesses'). A site seen in both counts once. Generated files, |
| # testdata and files built only for other systems or architectures are not |
| -# scanned; go test ./internal/codehealth/ -run '^TestCodeHealth$' -v lists |
| -# them, with every count and the line metrics' physical lengths. |
| +# scanned; make code-health lists them, with every count and the line |
| +# metrics' physical lengths. |
| # |
| -# - The gate (TestCodeHealth, in make test) fails when the code has more at a |
| -# site than its line allows, or an offence at a site with no line. Fewer is |
| -# fine: the gate says so, and the record can be lowered. |
| +# - The gate (make code-health, CI's 60-code-health step) fails when the |
| +# code has more at a site than its line allows, or an offence at a site |
| +# with no line. Fewer is fine: the gate prints it, and the record can be |
| +# lowered. |
| # - make code-health-record lowers lines to what the code has and drops the |
| # sites that are gone. It never adds a line or raises one. |
| # - A site that moved (a rename, or a move to another package) keeps its |
| @@ -26,7 +27,7 @@ |
| # "# moved-from: <old>", and its count plus what is left at the old site |
| # can never exceed the old allowance. |
| # - Anything else that adds or raises a line is a hand edit ending in |
| -# "# raised: <reason>". CI's 60-code-health-record step compares this file |
| +# "# raised: <reason>". CI's 61-code-health-record step compares this file |
| # with the merge base's copy and fails on an added or raised line without |
| # a new "# raised:" or a valid "# moved-from:". |
| # |
diff --git a/AGENTS.md b/AGENTS.md| index f61269b17..ad1456b00 100644 |
| --- a/AGENTS.md |
| +++ b/AGENTS.md |
| @@ -308,9 +308,11 @@ anything. |
| These come from the 2026-11-16 code audit (#1123) and the code-health |
| plan (`docs/superpowers/plans/2026-11-16-go-code-health.md`). Each |
| -names what holds it. "The ratchet" is `TestCodeHealth` in |
| -`internal/codehealth`: the counts in `.amadan/code-health.tsv` can only |
| -go down (its header and `.amadan/README.md` say how). |
| +names what holds it. "The ratchet" is `make code-health` (CI's |
| +`60-code-health` step, `TestCodeHealth` in `internal/codehealth`): the |
| +counts in `.amadan/code-health.tsv` can only go down (its header and |
| +`.amadan/README.md` say how). It is not part of `make test`; run it |
| +before pushing a branch that touches Go. |
| - **Network calls carry a deadline; AWS clients come from |
| `internal/rootaws`.** `TestAWSClientsAreBounded` (internal/rootaws) |
| @@ -338,7 +340,7 @@ go down (its header and `.amadan/README.md` say how). |
| When the ratchet fails, fix the code. A rename or a move to another |
| package keeps its allowance with `make code-health-record |
| MOVE='<old>:<new>'`. A deliberate raise is a hand edit ending in |
| -`# raised: <reason>`, which CI's `60-code-health-record` step checks |
| +`# raised: <reason>`, which CI's `61-code-health-record` step checks |
| against the merge base. After removing offences, `make |
| code-health-record` lowers the record; it never adds or raises a line. |
diff --git a/Makefile b/Makefile| index c59f749db..33a69c13e 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -7,7 +7,7 @@ LDFLAGS := -s -w -X github.com/carlosframework/platform/internal/version.Build=$ |
| GOOS ?= |
| GOARCH ?= |
| -.PHONY: test build build-console fmt staticcheck govulncheck census-card census-propose code-health-record console-mockup-kit parity-doc |
| +.PHONY: test build build-console fmt staticcheck govulncheck census-card census-propose code-health code-health-record console-mockup-kit parity-doc |
| # The build gate: vet, format, tests. `.amadan/ci.d/10-gate` runs this same |
| # target, so what CI checks and what you check are one definition. |
| @@ -133,6 +133,21 @@ census-propose: |
| @if [ -z '$(NAME)' ] || [ -z '$(CLAIMS)' ]; then echo "usage: make census-propose NAME=<branch> CLAIMS=<file>" >&2; exit 2; fi; \ |
| CARLOS_CENSUS_PROPOSE='$(NAME)'; export CARLOS_CENSUS_PROPOSE; $(CENSUS_CLAIMS); $(CENSUS_RUN) |
| +# The code-health ratchet's gate, as CI runs it (.amadan/ci.d/60-code-health): |
| +# scans the tree and fails where the code is above .amadan/code-health.tsv, |
| +# naming the site. It prints every count, the sites below the record, the |
| +# line metrics' physical lengths and the files it did not scan. Not part |
| +# of `make test`: on a cold build cache the scan's tagged half compiles |
| +# every package again under the gate's tags. The test skips without |
| +# CODEHEALTH_GATE, and a skipped test exits 0, so its PASS line must show. |
| +code-health: |
| + @out=$$(mktemp "$${TMPDIR:-/tmp}/code-health.XXXXXX") || exit 1; \ |
| + trap 'rm -f "$$out"' EXIT; \ |
| + CODEHEALTH_GATE=1 go test ./internal/codehealth/ -run '^TestCodeHealth$$' -count=1 -v >"$$out" 2>&1; rc=$$?; \ |
| + grep -v '^=== RUN' "$$out"; \ |
| + if [ $$rc -eq 0 ] && ! grep -q '^--- PASS: TestCodeHealth (' "$$out"; then echo "code-health: TestCodeHealth did not PASS (skipped, filtered out or renamed)" >&2; rc=1; fi; \ |
| + exit $$rc |
| + |
| # The code-health ratchet's record, .amadan/code-health.tsv (its header |
| # says how the ratchet works): lowers every line to what the code has and |
| # drops the sites that are gone. It never adds or raises a line, and it |
diff --git a/internal/codehealth/codehealth_test.go b/internal/codehealth/codehealth_test.go| index 0cddb40aa..a0c7a0216 100644 |
| --- a/internal/codehealth/codehealth_test.go |
| +++ b/internal/codehealth/codehealth_test.go |
| @@ -60,7 +60,7 @@ func report(w io.Writer, res *scanResult, listSkipped bool) { |
| fmt.Fprintf(w, "release-importers: %s\n", strings.Join(res.importers, " ")) |
| if !listSkipped { |
| fmt.Fprintf(w, "not scanned: %d files built only for other systems, architectures or tags, or generated\n"+ |
| - "(go test ./internal/codehealth/ -run '^TestCodeHealth$' -v lists them)\n", len(res.skipped)) |
| + "(make code-health lists them)\n", len(res.skipped)) |
| return |
| } |
| var skipped []string |
| @@ -71,12 +71,9 @@ func report(w io.Writer, res *scanResult, listSkipped bool) { |
| fmt.Fprintf(w, "not scanned (%d files):\n %s\n", len(skipped), strings.Join(skipped, "\n ")) |
| } |
| -// TestCodeHealth is the ratchet's gate. It fails when the code has more |
| -// offences at a site than .amadan/code-health.tsv allows, naming the site, |
| -// and when the record is not in its one sorted form. Fewer than the record |
| -// passes, logging the lower number, so two branches that each remove a |
| -// different offence both pass, and so does main after both. |
| -func TestCodeHealth(t *testing.T) { |
| +// TestRecordFile holds .amadan/code-health.tsv to its syntax and its one |
| +// sorted form, in make test, so a hand edit that breaks it fails at once. |
| +func TestRecordFile(t *testing.T) { |
| data, err := os.ReadFile(recordPath) |
| if err != nil { |
| t.Fatal(err) |
| @@ -88,6 +85,22 @@ func TestCodeHealth(t *testing.T) { |
| if string(rec.format()) != string(data) { |
| t.Errorf(".amadan/code-health.tsv is not in its sorted form, or its header is out of date: make code-health-record rewrites it") |
| } |
| +} |
| + |
| +// TestCodeHealth is the ratchet's gate. It fails when the code has more |
| +// offences at a site than .amadan/code-health.tsv allows, naming the site. |
| +// Fewer than the record passes, logging the lower number, so two branches |
| +// that each remove a different offence both pass, and so does main after |
| +// both. |
| +// |
| +// It runs only under make code-health (CI's 60-code-health step), not in |
| +// make test: on a cold build cache the scan's second tag set costs a |
| +// compile of every package, which is more than the gate should carry. |
| +func TestCodeHealth(t *testing.T) { |
| + if os.Getenv("CODEHEALTH_GATE") != "1" { |
| + t.Skip("run by make code-health (CI's 60-code-health)") |
| + } |
| + rec := readRecord(t, recordPath) |
| res := scanRepo(t) |
| var b strings.Builder |
| report(&b, res, true) |
| @@ -115,7 +128,7 @@ func TestCodeHealth(t *testing.T) { |
| t.Errorf("the code is above .amadan/code-health.tsv at %d sites:%s\n"+ |
| "Each is a new offence, or more at an old site. Fix it (AGENTS.md, \"Writing Go here\"). If it moved\n"+ |
| "(a rename, another package): make code-health-record MOVE='<old>:<new>'. A deliberate raise is a\n"+ |
| - "hand edit ending in \"# raised: <reason>\", which CI's 60-code-health-record step checks.", len(over), b.String()) |
| + "hand edit ending in \"# raised: <reason>\", which CI's 61-code-health-record step checks.", len(over), b.String()) |
| } |
| // TestCodeHealthRecord is make code-health-record: it lowers the record |
| @@ -157,7 +170,7 @@ func TestCodeHealthRecord(t *testing.T) { |
| fmt.Println("--- end code-health-record ---") |
| } |
| -// TestRecordAgainstBase is CI's 60-code-health-record step: it compares |
| +// TestRecordAgainstBase is CI's 61-code-health-record step: it compares |
| // the record with the merge base's copy (CODEHEALTH_BASE names it) and |
| // fails on an added or raised line that carries neither a new |
| // "# raised: <reason>" nor a valid "# moved-from:" transfer. It reads the |
| @@ -165,7 +178,7 @@ func TestCodeHealthRecord(t *testing.T) { |
| func TestRecordAgainstBase(t *testing.T) { |
| path := os.Getenv("CODEHEALTH_BASE") |
| if path == "" { |
| - t.Skip("run by .amadan/ci.d/60-code-health-record") |
| + t.Skip("run by .amadan/ci.d/61-code-health-record") |
| } |
| base, head := readRecord(t, path), readRecord(t, recordPath) |
| problems, notes := checkAgainstBase(base, head) |
diff --git a/internal/codehealth/record_test.go b/internal/codehealth/record_test.go| index 4d074f4e1..ae103be20 100644 |
| --- a/internal/codehealth/record_test.go |
| +++ b/internal/codehealth/record_test.go |
| @@ -27,12 +27,13 @@ const recordHeader = `# The code-health ratchet's record (internal/codehealth; t |
| # GOOS=linux, twice: with no tags and with the gate's (rootrunner and the |
| # cutover witnesses'). A site seen in both counts once. Generated files, |
| # testdata and files built only for other systems or architectures are not |
| -# scanned; go test ./internal/codehealth/ -run '^TestCodeHealth$' -v lists |
| -# them, with every count and the line metrics' physical lengths. |
| +# scanned; make code-health lists them, with every count and the line |
| +# metrics' physical lengths. |
| # |
| -# - The gate (TestCodeHealth, in make test) fails when the code has more at a |
| -# site than its line allows, or an offence at a site with no line. Fewer is |
| -# fine: the gate says so, and the record can be lowered. |
| +# - The gate (make code-health, CI's 60-code-health step) fails when the |
| +# code has more at a site than its line allows, or an offence at a site |
| +# with no line. Fewer is fine: the gate prints it, and the record can be |
| +# lowered. |
| # - make code-health-record lowers lines to what the code has and drops the |
| # sites that are gone. It never adds a line or raises one. |
| # - A site that moved (a rename, or a move to another package) keeps its |
| @@ -41,7 +42,7 @@ const recordHeader = `# The code-health ratchet's record (internal/codehealth; t |
| # "# moved-from: <old>", and its count plus what is left at the old site |
| # can never exceed the old allowance. |
| # - Anything else that adds or raises a line is a hand edit ending in |
| -# "# raised: <reason>". CI's 60-code-health-record step compares this file |
| +# "# raised: <reason>". CI's 61-code-health-record step compares this file |
| # with the merge base's copy and fails on an added or raised line without |
| # a new "# raised:" or a valid "# moved-from:". |
| # |