lint: fix all 47 noctx findings (httptest.NewRequest without context) #175
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Surveyed 2026-08-07:
make checkonmainfails with 94 lint findingsunder golangci-lint 2.12.2 (the version installed for local dev). 47 of
them are
noctx, all of the same shape: test code callinghttptest.NewRequestinstead ofhttptest.NewRequestWithContext.Note: CI is currently green because the
Dockerfilelint stage pinsgolangci-lint v2.10.1, which does not report these. The findings are
real under the current linter and block a locally green
make check;CI parity is tracked separately (bump of the lint stage pin).
All 47 findings are in test files:
internal/handlers/handlers_test.gointernal/middleware/ratelimit_test.gointernal/handlers/api_test.gointernal/middleware/cors_test.gointernal/handlers/render_template_test.gointernal/service/auth/auth_test.goRemediation: replace each
httptest.NewRequest(...)withhttptest.NewRequestWithContext(t.Context(), ...)(or the enclosingtest's context where a subtest closure already has one). Purely
mechanical; no production code changes.
Definition of done:
make lint(golangci-lint ≥ 2.12) reports zeronoctxfindingsmake testpasses unchanged;make fmtrun before commitTODO.mdupdated per the repo workflow (this is the current "NextStep" there)
mainStarting this now on a branch off current
main(291f85f).Definition of done for the PR:
noctxfindings gone: everyhttptest.NewRequestcall inthe six listed test files becomes
httptest.NewRequestWithContext(t.Context(), ...)(using theenclosing test's
*testing.T)make lintunder golangci-lint 2.12.2: total findings drop from 94to 47 (remaining: 23
gosec→ #176/#177, 24goconst→ #178)make teststill green,make fmtrun before commit,TODO.mdNext Step rotated per the repo workflow
Done in PR #183 (branch
fix-noctx-lint, commit2164290): all 47noctxfindings resolved,make linttotal 94 → 47,make testandmake fmt-checkgreen. Awaiting independent review (labeledneeds-review).
Definition of done verified met on
main(7a34fc9) — the fix landedvia #187 rather than PR #183, which is now closed as superseded:
make lint(pinned golangci-lint v2.12.2, canonical config): 0findings, so zero
noctxhttptest.NewRequestWithContextwitht.Context(); grep over themaintree finds no remainingcontext-less
httptest.NewRequest(call sitesmake checkgreen in a clean worktree ofmain(tests with racedetector, lint,
fmt-check)Closing.