Files
inventory-plus-plus/work-summaries/work-summary-Claude-2026-08-06-2026.md
angelandClaude Sonnet 5 707aa65ddc tests: migrate assertions to testify's assert/require
Replaces raw t.Error/t.Errorf/t.Fatal/t.Fatalf across every test file
that has any (domains/accounts, domains/authentication,
domains/raw_events, domains/amazon, domains/reports x2) with testify's
assert (non-halting) / require (halting) equivalents. The three
Example-based tests (server/ui/svg, server/ui/charts) have no
*testing.T at all - nothing to convert there.

require.Eventually replaces several hand-rolled polling loops in
domains/amazon/mock_test.go. Its condition function runs on a separate
goroutine (confirmed in testify's source), so calling require.* from
inside one - which two of the new Eventually calls initially did, via
the isProcessed helper - is unsafe per Go's testing rules (t.FailNow
must only be called from the test's own goroutine). Fixed by splitting
a *testing.T-free queryIsProcessed(ctx, pool, shopID, eventID) out of
isProcessed for use inside those closures specifically.

github.com/stretchr/testify promoted from an indirect to a direct
dependency (go.mod only - it was already present transitively, so
go.sum is unchanged).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XEDaCB7C2NEBgyvqEtZuxY
2026-08-20 00:36:55 -06:00

5.5 KiB

Work Summary — 2026-08-06 20:26

Task

Migrate all test files from raw t.Error/t.Errorf/t.Fatal/t.Fatalf to github.com/stretchr/testify's assert/require packages, throughout the whole test suite.

Scope found

9 test files total. Three (server/ui/svg/svg_test.go, server/ui/charts/bar_test.go, server/ui/charts/line_test.go) are Example functions with no *testing.T parameter at all - Go's stdlib compares their output against a // Output: comment, a fundamentally different mechanism testify can't attach to. Nothing to convert there; confirmed via grep that none of the three contain any t.Error/t.Fatal/*testing.T usage.

The remaining 6 were converted: domains/accounts/accounts_test.go, domains/authentication/dev_test.go, domains/raw_events/events_test.go, domains/amazon/mock_test.go, domains/reports/events_test.go, domains/reports/reports_test.go.

Conventions used

  • require.* where the original was t.Fatal/t.Fatalf (halts the test) - error checks, and any assertion a later line depends on (e.g. indexing into a slice whose length was just checked).
  • assert.* where the original was t.Error/t.Errorf (non-halting) - independent value checks that don't gate subsequent code.
  • require.ErrorIs/require.NoError in place of manual errors.Is/if err != nil checks.
  • require.Eventually in place of hand-rolled polling loops (for !condition() { if timeout { t.Fatal }; sleep }) in domains/amazon/mock_test.go - a direct, more concise match for that exact pattern, and it already existed in testify rather than needing a custom helper.
  • assert.NotNil/require.NotNil guarding a subsequent field access, matching testify's own idiom for avoiding a nil-pointer panic in a non-fatal assertion chain (if assert.NotNil(t, x) { assert.Equal(t, ..., x.Field) }).
  • github.com/stretchr/testify added as a direct dependency (go get + go mod tidy; it was already an indirect transitive dependency of something else, so it only became "direct" once actual imports existed for go mod tidy to key off of).

A correctness issue caught and fixed during the conversion (not a testify bug - a bug in my own test code)

require.Eventually runs its condition function via go checkCond() - a separate goroutine (confirmed by reading testify's source at assert/assertions.go:1988). Go's testing package requires t.FailNow() (which require.* calls internally) to only ever be invoked from the test's own goroutine; calling it from a spawned goroutine doesn't panic cleanly, it just silently fails to report the real error and can leave things in a confusing state. Two of my initial require.Eventually(...) calls wrapped isProcessed(t, ...), which internally used require.NoError - exactly this hazard, latent until the underlying query ever actually errored. Fixed by splitting a t-free queryIsProcessed(ctx, pool, shopID, eventID) (bool, error) out of isProcessed, and having the Eventually closures call that directly (treating a query error as "not yet satisfied" rather than halting), while isProcessed itself (used from the main test goroutine elsewhere) still wraps it with require.NoError for a clear, immediate failure there.

Verification

  • go build ./... / go vet ./... clean.
  • gofmt -l clean on every file touched (the only gofmt-flagged files repo-wide are pre-existing generated *_with_context.go files this task didn't touch).
  • grep -rn "t\.Error\|t\.Fatal" --include="*_test.go" . - only two hits, both in explanatory comments, not actual calls.
  • Every package with tests passes individually and in the safe (non-colliding) combination - see "Follow-up" below for why domains/amazon was verified separately from the rest rather than via one go test ./... run.

Follow-up surfaced (separate from this task, not fixed here)

While confirming everything with a full-suite run, go test ./... hung and eventually timed out inside domains/amazon, with a goroutine stuck in pgxpool.Pool.Close()'s sync.WaitGroup.Wait. Root-caused: (*Mocks).processUnprocessedEvents's query has no shop_id filter - it processes every unprocessed row in mock.shop_amazon_events system-wide. domains/reports' tests also insert platform='amazon' raw events (unrelated fixture data, for its own listing-count tests), which the DB trigger copies into that same table. When go test ./... runs both packages' test binaries concurrently (the default), domains/amazon's tests can end up processing - and asserting on - events that belong to a different test in a different package entirely. Confirmed directly: running domains/amazon + domains/reports together reproduced a spy receiving 4 events instead of the expected 1, three of them from domains/reports' fixture shop. This likely also explains the hang: more cross-package NOTIFY traffic raises the odds of hitting a narrow race in listenForNotifications where its notification-forwarding goroutine can block forever on an unbuffered channel send if ProcessEvents has just exited (context cancelled), leaking the connection and hanging pool.Close().

This pre-dates and is unrelated to the testify conversion - it only became reachable once domains/reports' tests started writing platform='amazon' events in a recent session. Per user direction, verified the conversion by running domains/amazon on its own and every other tested package together (both clean, repeated runs, no leftovers), and left the underlying mock.go bug as an explicit follow-up task rather than fixing it as a side effect of this one.