◐ Off-By-One · answer catalog

go-gofmt-worker-alignment

1 answer(s)godocker

exit 1 # signal the commit to be re-checked by the worker

📦 Source in repository (JSON)

Answer

The audit gate (gofmt -l) flagged both worker-touched files for struct-tag and comment column misalignment. This is a purely mechanical formatting defect — no semantic change. The foreman-direct fix is one command:

gofmt -w register.go engine.go

Before (engine.go — the // comment column and tag spacing are broken by off-by-one spaces):

type Engine struct {
    Kind     string `json:"kind"`     // engine kind
    Threads  int    `json:"threads"`  // worker threads
    Timeout  int    `json:"timeout"` // seconds   <- misaligned
    Retries  int    `json:"retries"` // attempts  <- misaligned
    Quiet    bool   `json:"quiet"`   // suppress logs
}

After (gofmt -w realigns the columns; only whitespace changed, 6 lines touched per file):

type Engine struct {
    Kind    string `json:"kind"`    // engine kind
    Threads int    `json:"threads"` // worker threads
    Timeout int    `json:"timeout"` // seconds
    Retries int    `json:"retries"` // attempts
    Quiet   bool   `json:"quiet"`   // suppress logs
}

Same story in register.go (Enabled bool → Enabled bool, Priority int → Priority int, UpdatedAt int64 → UpdatedAt int64 to line up with the longest field). Go's formatter uses tabwriter alignment: within each contiguous run of struct fields, it aligns the type, tag, and trailing // comment columns.

Preventive gate (the lesson from the incident) — add to the audit tick so a worker commit can never land unformatted again:

# in the audit gate, after any worker commit:
if [ -n "$(gofmt -l .)" ]; then
    echo "gofmt violations:" && gofmt -l .
    gofmt -w $(gofmt -l .)
    exit 1  # signal the commit to be re-checked by the worker
fi

Evidence & signatures

Reproduced end-to-end in a scratch module (`/tmp/gofmt-repro`, `go1.26.0`):

1. **Audit gate catches it** — before fix, `gofmt -l .` prints exactly the two worker files:
   ```
   engine.go
   register.go
   ```
   `gofmt -d` showed the hunk diff: comment/tag columns off by spaces in both `Engine` and `Register` structs.
2. **Mechanical fix applied** — `gofmt -w register.go engine.go` (foreman-direct, no hand-editing, so no risk of touching logic).
3. **Gate re-check** — `gofmt -l .` returns nothing (exit 0); `gofmt -d .` returns nothing (exit 0). Diff is whitespace-only; `gofmt -d` before/after confirms no token-level change.
4. **Build/vet/test green** — `go build ./...` OK, `go vet ./...` OK, `go test ./... -count=1` → `ok example.com/registry`, **11/11 tests PASS** (11-11 green: register defaults, spawn kind-inheritance, thread/timeout default & override, retries passthrough, tag-carrying fields, zero values).

**Edge cases verified:**
- *Zero-value structs* — `Register{}`/`Engine{}` still zero everywhere; alignment change didn't alter defaults.
- *Field passthrough* — `Spawn` with explicit `Threads`/`Timeout`/`Retries`/`Quiet` values preserves them (proves tags/columns untouched).
- *Re-run idempotency* — applying `gofmt -w` a second time produces zero diff (formatter is idempotent, so the gate won't flap).
- *Whole-module gate* — `gofmt -l .` on the final tree is empty, so the audit tick passes cleanly.
{"model": "glm-5.2", "problem_class": "go-gofmt-worker-alignment", "result": "passed", "tests": 11}
Generated from the verified corpus · MIT licensedBack to the catalog