Skip to content

ci: enable govet for test files in golangci-lint - #2784

Closed
t-kikuc wants to merge 1 commit into
mainfrom
ci/enable-govet-for-tests
Closed

ci: enable govet for test files in golangci-lint#2784
t-kikuc wants to merge 1 commit into
mainfrom
ci/enable-govet-for-tests

Conversation

@t-kikuc

@t-kikuc t-kikuc commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

What this PR does

Remove run.tests: false from .golangci.yml and replace with per-linter exclusion rules, so that govet runs on test files while other linters remain excluded. Fix existing sync.Map value copy violation detected by the copylocks analyzer.

Background

.golangci.yml had run.tests: false, which excluded all test files from all linters including govet. govet has very low false-positive rates and catches real bugs — the copylocks analyzer, for example, has existed since at least Go 1.21 but its violations in test files were invisible in CI.

Other linters (errcheck, goheader, lll, etc.) can be noisy on test files, so enabling tests: true globally is not ideal. golangci-lint v2 supports per-linter exclusion via linters.exclusions.rules, which allows enabling govet for tests while keeping other linters excluded.

Verification commands

# Confirm govet detects test file issues (before the test fix)
golangci-lint run --timeout 3m0s ./pkg/api/api/...
# → 5 copylocks violations in save_api_key_last_used_at_test.go

# Confirm 0 issues after the fix
golangci-lint run --timeout 3m0s ./cmd/... ./evaluation/go/... ./pkg/... ./hack/... ./test/...
# → 0 issues

# Confirm no other govet violations exist in test files
go vet ./cmd/... ./pkg/... ./evaluation/go/...
# → 0 errors

Points

  • The copylocks issue in save_api_key_last_used_at_test.go predates this PR — it was never detected because test files were excluded from linting
  • The test struct fields existingCache sync.Map / expectedCache sync.Map are replaced with setupCache func(*sync.Map) / expectedCache map[string]apikeyLastUsedAt to avoid value copies of sync.Map

Remove `run.tests: false` and replace with per-linter exclusion
rules so that govet runs on test files while other linters remain
excluded. Fix sync.Map value copy violation detected by copylocks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings August 25, 2026 02:13

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

Enables govet checks for Go test files while suppressing noisier linters.

Changes:

  • Replaces the global test exclusion with per-linter exclusions.
  • Refactors cache tests to avoid copying sync.Map.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
.golangci.yml Enables govet for tests while excluding other linters.
pkg/api/api/save_api_key_last_used_at_test.go Avoids sync.Map value copies in test cases.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@t-kikuc t-kikuc closed this Aug 28, 2026
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.

2 participants