Skip to content

test: fix golangci-lint errcheck/staticcheck issues in test code#323

Merged
lizhengfeng101 merged 2 commits into
mainfrom
fix/lint-test-code
Jul 8, 2026
Merged

test: fix golangci-lint errcheck/staticcheck issues in test code#323
lizhengfeng101 merged 2 commits into
mainfrom
fix/lint-test-code

Conversation

@lizhengfeng101

Copy link
Copy Markdown
Collaborator

What

Fixes all 54 golangci-lint findings in test code (production code untouched):

  • errcheck — unchecked error returns. Setup-critical calls (repo init, os.WriteFile, os.Chdir into the target dir, Shutdown) now assert via t.Fatalf; cleanup / best-effort calls (defer Close, os.Chmod, os.Unsetenv, stdout-capture scaffolding) use an explicit _ =.
  • ST1018 — two Unicode control characters (U+009B/U+009D) in output_test.go replaced with / escapes.
  • SA6003range []rune("abc") simplified to range "abc" in provider_tui_test.go.
  • ineffassign — ineffectual assignment in util_test.go (added an assertion so the appended copy is actually checked).

The bulk is internal/llm/resolver_test.go (36 os.WriteFile setup calls).

Why

Go Report Card has been sunset (its badge was removed in #319). This is the first step of replacing it with golangci-lint as a real static-analysis gate. Clearing the existing lint findings first — starting with zero-risk test-only changes — keeps the eventual "wire up golangci-lint + CI + badge" change decoupled and easy to review. Production-code findings will follow in a separate PR.

Verification

  • make check (gofmt + vet) passes
  • make test passes (all 22 packages, no failures)
  • golangci-lint run --max-issues-per-linter 0 --max-same-issues 0 ./... reports zero remaining test-code issues

First step of replacing the sunset Go Report Card with golangci-lint.
Resolve all 54 lint findings in test files (errcheck unchecked error
returns, ST1018 Unicode control chars, SA6003 range over []rune,
ineffassign): setup calls now assert errors via t.Fatalf, cleanup and
best-effort calls use explicit `_ =`. No production code touched;
make check and make test both pass.
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

OpenCodeReview: No supported files changed.

@MuoDoo MuoDoo requested a review from Copilot July 8, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR removes existing golangci-lint findings in test code only to prepare the repo for adopting golangci-lint as a CI/static-analysis gate.

Changes:

  • Replaced unchecked error returns in tests with t.Fatalf(...) for setup-critical operations and explicit ignores (_ = ...) for best-effort cleanup.
  • Fixed staticcheck/ST1018 issues by escaping Unicode control characters in string literals and simplified a rune-range loop.
  • Addressed an ineffectual assignment by adding an assertion that validates the intended slice behavior.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/viewer/store_load_test.go Ignore cleanup Chmod errors explicitly to satisfy errcheck.
internal/viewer/server_extra_test.go Explicitly ignore Close() error in test.
internal/viewer/handler_test.go Ignore cleanup Chmod errors explicitly.
internal/telemetry/provider_test.go Explicitly ignore os.Unsetenv errors.
internal/telemetry/exporter_test.go Ignore pipe close errors and explicitly ignore io.Copy return values.
internal/telemetry/events_test.go Explicitly ignore pipe Close() error.
internal/telemetry/config_test.go Check WriteFile errors; explicitly ignore Unsetenv errors.
internal/session/persist_test.go Ignore file close / flush errors explicitly.
internal/pathutil/path_test.go Ignore cleanup Chdir error explicitly.
internal/model/model_test.go Check json.Unmarshal error paths explicitly.
internal/mcp/stdio_test.go Ignore Close() error explicitly in deferred cleanup.
internal/mcp/client_test.go Ignore Close() error explicitly in deferred cleanup.
internal/llm/resolver_test.go Check os.WriteFile errors for generated config fixtures.
internal/llm/message_test.go Check os.WriteFile errors for test RC fixtures.
internal/config/toolsconfig/toolsconfig_test.go Check os.WriteFile errors for tools.json fixtures.
internal/agent/util_test.go Add assertion to ensure appended copy is actually validated.
cmd/opencodereview/shared_test.go Check Chdir error and ignore deferred restore error explicitly.
cmd/opencodereview/provider_tui_test.go Simplify range []rune("abc") to range "abc".
cmd/opencodereview/provider_cmd_test.go Explicitly ignore pipe Close() error.
cmd/opencodereview/output_test.go Replace raw Unicode control chars with escaped sequences.
cmd/opencodereview/output_helpers_test.go Explicitly ignore pipe Close() and ReadFrom return values; check Unmarshal in some cases.
cmd/opencodereview/git_test.go Check git command results and Chdir error; ignore deferred restore error explicitly.
cmd/opencodereview/emit_run_result_test.go Ignore tracer provider Shutdown() error explicitly in deferred cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/opencodereview/shared_test.go Outdated
Comment on lines +82 to +86
origDir, _ := os.Getwd()
defer os.Chdir(origDir)
os.Chdir(dir)
defer func() { _ = os.Chdir(origDir) }()
if err := os.Chdir(dir); err != nil {
t.Fatalf("chdir: %v", err)
}
Comment thread cmd/opencodereview/git_test.go Outdated
Comment on lines +102 to +106
origDir, _ := os.Getwd()
defer os.Chdir(origDir)
os.Chdir(dir)
defer func() { _ = os.Chdir(origDir) }()
if err := os.Chdir(dir); err != nil {
t.Fatalf("chdir: %v", err)
}
Comment on lines 166 to 170
if sh.persist != nil {
sh.persist.mu.Lock()
sh.persist.writer.Flush()
_ = sh.persist.writer.Flush()
sh.persist.mu.Unlock()
}
Comment thread internal/telemetry/exporter_test.go Outdated
Comment on lines 164 to 165
_ = w.Close()
os.Stderr = oldStderr
Comment thread internal/telemetry/exporter_test.go Outdated
Comment on lines +186 to +187
var buf bytes.Buffer
io.Copy(&buf, r)
_, _ = io.Copy(&buf, r)
Address Copilot review feedback on #323. Some errors previously silenced
with `_ =` to satisfy errcheck actually affect test correctness or can
pollute later tests, so fail loudly instead:

- shared_test.go / git_test.go: check os.Getwd() and report deferred
  os.Chdir restore failures (t.Errorf) so a failed restore can't leave
  later tests running in the wrong working directory.
- persist_test.go: fail on writer.Flush() error since it is a
  precondition for the JSONL assertions.
- exporter_test.go: fail on pipe Close()/io.Copy errors that determine
  the asserted stderr output.

@css521 css521 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101 lizhengfeng101 merged commit e2d75b7 into main Jul 8, 2026
5 checks passed
@lizhengfeng101 lizhengfeng101 deleted the fix/lint-test-code branch July 8, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants