fix(build): restore the go fix fixpoint, and give the formatter one owner

A "reduce Taskfile bloat" refactor (2e00777f) removed the fixpoint loop from
task fmt and deleted the guard test that proved it, putting the tree back to a
single go fix pass with nothing left to notice. One pass is not a fixpoint:
stditerators rewrites `for i := range t.NumFields()` into a field iterator that
copies its loop variable, and forvar only deletes that copy on the following
pass, leaving a tree copyloopvar rejects. archie-core-wwho regressed silently.

Restore the loop and the guard. The deploy workflow has always inlined its own
single `go fix ./...`, which is how the same hazard reached CI as a spurious
git-diff failure rather than a lint error (archie-core-6kda); it now calls task
fmt, the one owner of the formatter sequence, and its guard rejects an inline
copy so the split cannot come back.
This commit is contained in:
sam committed 2026-10-03 02:28:33 +10:00
1 parent a95062c9ac
commit ba37e37e53
4 files changed
+73 -6

No files matched your search

+8 -2
View File
@@ -68,6 +68,7 @@ jobs:
run: |
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.2
go install mvdan.cc/gofumpt@v0.11.0
go install github.com/go-task/task/v3/cmd/task@v3.48.0
- name: Install protobuf tools
run: bash tools/proto.sh install
@@ -99,8 +100,13 @@ jobs:
- name: Quality gate
run: |
go fix ./...
golangci-lint fmt
# The formatter sequence has one owner: task fmt, which drives go fix
# to a fixpoint and then the configured lint formatters. This step
# used to inline its own single `go fix ./...`, which leaves the
# redundant loop-variable copy that copyloopvar rejects -- the hazard
# of archie-core-wwho, surfacing here as a spurious git-diff failure
# (archie-core-6kda).
task fmt
git diff --exit-code
bash tools/proto.sh lint
bash tools/proto.sh check
+25 -2
View File
@@ -10,9 +10,32 @@ tasks:
- task --list
fmt:
desc: Fix and format Go source
desc: Fix and format Go source with the gate's configured formatters
cmds:
- go fix ./...
# One go fix pass is not a fixpoint: it applies each fixer once, to the
# parse it started with, so a rewrite made by one fixer is only fixed up
# by the next pass. stditerators turns `for i := range t.NumField()` into
# a field iterator that copies its loop variable, and forvar deletes that
# copy on the following pass -- leaving the copy behind for copyloopvar
# to reject. Apply passes until a dry run reports nothing left to fix,
# and fail rather than hand the lint step a tree it must reject.
- |
set -eu
converged=false
for pass in 1 2 3 4 5 6 7 8 9 10; do
go fix ./...
if go fix -diff ./... >/dev/null; then
converged=true
break
fi
done
if [ "$converged" != true ]; then
echo "go fix still rewrites the tree after 10 passes" >&2
exit 1
fi
# This must use the same engine and configuration as task lint. Running
# standalone gofumpt cannot reproduce gci's custom import grouping, so it
# can leave a tree that the gate rejects.
- golangci-lint fmt
proto:install:
+16 -1
View File
@@ -85,7 +85,7 @@ func TestDeployWorkflowUsesConfiguredFormatters(t *testing.T) {
source := readDeploymentFile(t, ".github/workflows/deploy.yml")
for _, required := range []string{
"github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.2",
"golangci-lint fmt",
"task fmt",
"git diff --exit-code",
"golangci-lint run ./...",
} {
@@ -93,6 +93,21 @@ func TestDeployWorkflowUsesConfiguredFormatters(t *testing.T) {
t.Errorf("deploy workflow is missing formatter gate %q", required)
}
}
// task fmt is the one owner of the formatter sequence, and it drives go fix to
// a fixpoint. An inline single pass here leaves the redundant loop-variable
// copy that copyloopvar rejects -- the hazard of archie-core-wwho, which
// surfaces in this workflow as a spurious git-diff failure rather than a lint
// error (archie-core-6kda). A comment may name the command while explaining
// why it is absent; only a line that is itself a command inlines it.
for line := range strings.SplitSeq(source, "\n") {
trimmed := strings.TrimSpace(line)
if strings.HasPrefix(trimmed, "#") {
continue
}
if strings.HasPrefix(trimmed, "go fix") || trimmed == "golangci-lint fmt" {
t.Errorf("deploy workflow runs %q inline; task fmt owns the formatter sequence", trimmed)
}
}
if strings.Contains(source, "gofumpt -w .") {
t.Error("deploy workflow bypasses the configured formatter set")
}
+24 -1
View File
@@ -73,7 +73,10 @@ func TestFormattingUsesOneConfiguredWriter(t *testing.T) {
}
fmtTask := taskfile[fmtStart:fmtEnd]
const applyFix = "go fix ./..."
const (
applyFix = "go fix ./..."
verifyFix = "go fix -diff ./..."
)
fix := strings.Index(fmtTask, applyFix)
format := strings.Index(fmtTask, "golangci-lint fmt")
if fix < 0 || format < 0 || fix > format {
@@ -82,6 +85,26 @@ func TestFormattingUsesOneConfiguredWriter(t *testing.T) {
if strings.Contains(fmtTask, "gofumpt -") {
t.Error("fmt task bypasses the configured formatter set with standalone gofumpt")
}
// One go fix pass is not a fixpoint: stditerators rewrites
// `for i := range t.NumField()` into a field iterator that copies its loop
// variable, and forvar only deletes that copy on the following pass. A tree
// that stops after one pass is therefore one copyloopvar rejects, so fmt has
// to keep applying passes and prove the plateau with a dry run that exits
// clean only when nothing is left to fix.
//
// This assertion was deleted by a "reduce Taskfile bloat" commit along with
// the loop it guarded, which put the tree back to a single pass with nothing
// to notice. It is the reason the loop is checked for here rather than only
// the presence of a go fix invocation.
if !strings.Contains(fmtTask, verifyFix) {
t.Error("fmt task does not prove that repeated go fix passes have reached a fixpoint")
}
if got := strings.Count(fmtTask, applyFix); got != 1 {
t.Errorf("fmt task applies go fix %d times inline, want 1: the repetition belongs to the fixpoint loop", got)
}
if got := strings.Count(fmtTask, verifyFix); got != 1 {
t.Errorf("fmt task verifies the go fix fixpoint %d times, want 1", got)
}
if got, owned := strings.Count(taskfile, applyFix), strings.Count(fmtTask, applyFix); got != owned {
t.Errorf("Taskfile invokes go fix %d times, %d of them through task fmt: formatting has one owner", got, owned)
}