lint: fix all 47 noctx findings (httptest.NewRequest without context) #175

Closed
opened 2026-08-07 18:40:22 +02:00 by clawbot · 3 comments
Collaborator

Surveyed 2026-08-07: make check on main fails with 94 lint findings
under golangci-lint 2.12.2 (the version installed for local dev). 47 of
them are noctx, all of the same shape: test code calling
httptest.NewRequest instead of httptest.NewRequestWithContext.

Note: CI is currently green because the Dockerfile lint stage pins
golangci-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:

File Findings
internal/handlers/handlers_test.go 26
internal/middleware/ratelimit_test.go 7
internal/handlers/api_test.go 6
internal/middleware/cors_test.go 3
internal/handlers/render_template_test.go 3
internal/service/auth/auth_test.go 2

Remediation: replace each httptest.NewRequest(...) with
httptest.NewRequestWithContext(t.Context(), ...) (or the enclosing
test'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 zero noctx findings
  • total finding count drops from 94 to 47
  • make test passes unchanged; make fmt run before commit
  • TODO.md updated per the repo workflow (this is the current "Next
    Step" there)
  • lands via PR from a feature branch off main
Surveyed 2026-08-07: `make check` on `main` fails with 94 lint findings under golangci-lint 2.12.2 (the version installed for local dev). 47 of them are `noctx`, all of the same shape: test code calling `httptest.NewRequest` instead of `httptest.NewRequestWithContext`. Note: CI is currently green because the `Dockerfile` lint stage pins golangci-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: | File | Findings | | --- | --- | | `internal/handlers/handlers_test.go` | 26 | | `internal/middleware/ratelimit_test.go` | 7 | | `internal/handlers/api_test.go` | 6 | | `internal/middleware/cors_test.go` | 3 | | `internal/handlers/render_template_test.go` | 3 | | `internal/service/auth/auth_test.go` | 2 | Remediation: replace each `httptest.NewRequest(...)` with `httptest.NewRequestWithContext(t.Context(), ...)` (or the enclosing test'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 zero `noctx` findings - total finding count drops from 94 to 47 - `make test` passes unchanged; `make fmt` run before commit - `TODO.md` updated per the repo workflow (this is the current "Next Step" there) - lands via PR from a feature branch off `main`
clawbot added this to the 1.1.0 milestone 2026-08-07 18:40:22 +02:00
Author
Collaborator

Starting this now on a branch off current main (291f85f).

Definition of done for the PR:

  • all 47 noctx findings gone: every httptest.NewRequest call in
    the six listed test files becomes
    httptest.NewRequestWithContext(t.Context(), ...) (using the
    enclosing test's *testing.T)
  • make lint under golangci-lint 2.12.2: total findings drop from 94
    to 47 (remaining: 23 gosec → #176/#177, 24 goconst#178)
  • make test still green, make fmt run before commit, TODO.md
    Next Step rotated per the repo workflow
  • before/after lint counts stated on the PR
Starting this now on a branch off current `main` (291f85f). Definition of done for the PR: - all 47 `noctx` findings gone: every `httptest.NewRequest` call in the six listed test files becomes `httptest.NewRequestWithContext(t.Context(), ...)` (using the enclosing test's `*testing.T`) - `make lint` under golangci-lint 2.12.2: total findings drop from 94 to 47 (remaining: 23 `gosec` → #176/#177, 24 `goconst` → #178) - `make test` still green, `make fmt` run before commit, `TODO.md` Next Step rotated per the repo workflow - before/after lint counts stated on the PR
Author
Collaborator

Done in PR #183 (branch fix-noctx-lint, commit 2164290): all 47
noctx findings resolved, make lint total 94 → 47, make test and
make fmt-check green. Awaiting independent review (labeled
needs-review).

Done in PR #183 (branch `fix-noctx-lint`, commit 2164290): all 47 `noctx` findings resolved, `make lint` total 94 → 47, `make test` and `make fmt-check` green. Awaiting independent review (labeled needs-review).
Author
Collaborator

Definition of done verified met on main (7a34fc9) — the fix landed
via #187 rather than PR #183, which is now closed as superseded:

  • make lint (pinned golangci-lint v2.12.2, canonical config): 0
    findings, so zero noctx
  • every test-file request is httptest.NewRequestWithContext with
    t.Context(); grep over the main tree finds no remaining
    context-less httptest.NewRequest( call sites
  • make check green in a clean worktree of main (tests with race
    detector, lint, fmt-check)

Closing.

Definition of done verified met on `main` (7a34fc9) — the fix landed via #187 rather than PR #183, which is now closed as superseded: - `make lint` (pinned golangci-lint v2.12.2, canonical config): 0 findings, so zero `noctx` - every test-file request is `httptest.NewRequestWithContext` with `t.Context()`; grep over the `main` tree finds no remaining context-less `httptest.NewRequest(` call sites - `make check` green in a clean worktree of `main` (tests with race detector, lint, `fmt-check`) Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/upaas#175