mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
chore: standardize on *_internal_test.go for white-box tests (#25601)
My agent added `//nolint:testpackage` to a test file on one of my PRs. Again. This PR cleans it up across the entire repo and updates the in-repo conventions so future agents stop doing it. The repo already has a precedent for white-box tests that need to touch unexported symbols: `*_internal_test.go` (145+ existing files). The `testpackage` linter's default `skip-regexp` exempts that filename suffix, so the `//nolint:testpackage` directive is unnecessary in every case where someone reached for it. This PR renames 51 such files to `*_internal_test.go` via `git mv` so blame and history follow, and strips the dead directive from 2 files that were already correctly named (`coderd/oauth2provider/authorize_internal_test.go`, `coderd/x/chatd/advisor_internal_test.go`). `.claude/docs/TESTING.md` now documents the rule explicitly under *Test Package Naming*, which is imported into the root `AGENTS.md` via `@.claude/docs/TESTING.md`. The rule: prefer `package foo_test`; if you need internal access, rename the file to `*_internal_test.go` rather than adding a nolint directive.
This commit is contained in:
+23
-13
@@ -30,7 +30,16 @@ issues.
|
||||
|
||||
### Test Package Naming
|
||||
|
||||
- **Test packages**: Use `package_test` naming (e.g., `identityprovider_test`) for black-box testing
|
||||
- **Black-box tests**: Default to a `package foo_test` test file (e.g.,
|
||||
`identityprovider_test`). This is what the `testpackage` linter enforces.
|
||||
- **White-box / internal tests**: When a test needs to touch unexported
|
||||
symbols, put it in a file named `*_internal_test.go` with `package foo`.
|
||||
The `testpackage` linter's `skip-regexp` already exempts that filename
|
||||
suffix, so no `//nolint:testpackage` directive is needed.
|
||||
- **Do not add `//nolint:testpackage`.** If a test needs internal access,
|
||||
rename the file to `*_internal_test.go` instead. A directive plus a
|
||||
justification comment is strictly worse than the established naming
|
||||
convention, and the repo standardizes on the latter.
|
||||
|
||||
## RFC Protocol Testing
|
||||
|
||||
@@ -50,7 +59,7 @@ issues.
|
||||
|
||||
### Test File Structure
|
||||
|
||||
```
|
||||
```text
|
||||
coderd/
|
||||
├── oauth2.go # Implementation
|
||||
├── oauth2_test.go # Main tests
|
||||
@@ -69,20 +78,20 @@ coderd/
|
||||
|
||||
### Running Tests
|
||||
|
||||
| Command | Purpose |
|
||||
|---------|---------|
|
||||
| `make test` | Run all Go tests |
|
||||
| `make test RUN=TestFunctionName` | Run specific test |
|
||||
| `go test -v ./path/to/package -run TestFunctionName` | Run test with verbose output |
|
||||
| `make test-race` | Run tests with Go race detector |
|
||||
| `make test-e2e` | Run end-to-end tests |
|
||||
| Command | Purpose |
|
||||
|------------------------------------------------------|---------------------------------|
|
||||
| `make test` | Run all Go tests |
|
||||
| `make test RUN=TestFunctionName` | Run specific test |
|
||||
| `go test -v ./path/to/package -run TestFunctionName` | Run test with verbose output |
|
||||
| `make test-race` | Run tests with Go race detector |
|
||||
| `make test-e2e` | Run end-to-end tests |
|
||||
|
||||
### Frontend Testing
|
||||
|
||||
| Command | Purpose |
|
||||
|---------|---------|
|
||||
| `pnpm test` | Run frontend tests |
|
||||
| `pnpm check` | Run code checks |
|
||||
| Command | Purpose |
|
||||
|--------------|--------------------|
|
||||
| `pnpm test` | Run frontend tests |
|
||||
| `pnpm check` | Run code checks |
|
||||
|
||||
## Common Testing Issues
|
||||
|
||||
@@ -218,6 +227,7 @@ func BenchmarkFunction(b *testing.B) {
|
||||
```
|
||||
|
||||
Run benchmarks with:
|
||||
|
||||
```bash
|
||||
go test -bench=. -benchmem ./package/path
|
||||
```
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
//nolint:testpackage // Tests private env helpers directly.
|
||||
package reconnectingpty
|
||||
|
||||
import (
|
||||
@@ -1,4 +1,4 @@
|
||||
package agent //nolint:testpackage // Exercises internal agent secrets handling.
|
||||
package agent
|
||||
|
||||
import (
|
||||
"testing"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package apidump //nolint:testpackage // tests unexported internals
|
||||
package apidump
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package apidump //nolint:testpackage // tests unexported internals
|
||||
package apidump
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package apidump //nolint:testpackage // shares test helpers with apidump_test.go
|
||||
package apidump
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatcompletions //nolint:testpackage // tests unexported internals
|
||||
package chatcompletions
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatcompletions //nolint:testpackage // tests unexported internals
|
||||
package chatcompletions
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatcompletions //nolint:testpackage // tests unexported internals
|
||||
package chatcompletions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatcompletions //nolint:testpackage // tests unexported internals
|
||||
package chatcompletions
|
||||
|
||||
import (
|
||||
"io"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package messages //nolint:testpackage // tests unexported internals
|
||||
package messages
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package messages //nolint:testpackage // tests unexported internals
|
||||
package messages
|
||||
|
||||
import (
|
||||
"io"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package messages //nolint:testpackage // tests unexported internals
|
||||
package messages
|
||||
|
||||
import (
|
||||
"testing"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package messages //nolint:testpackage // tests unexported internals
|
||||
package messages
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package responses //nolint:testpackage // tests unexported internals
|
||||
package responses
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package responses //nolint:testpackage // tests unexported internals
|
||||
package responses
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package responses //nolint:testpackage // tests unexported internals
|
||||
package responses
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package responses //nolint:testpackage // tests unexported internals
|
||||
package responses
|
||||
|
||||
import (
|
||||
"io"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package integrationtest //nolint:testpackage // tests unexported internals
|
||||
package integrationtest
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package integrationtest //nolint:testpackage // tests unexported internals
|
||||
package integrationtest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package integrationtest //nolint:testpackage // tests unexported internals
|
||||
package integrationtest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package integrationtest //nolint:testpackage // tests unexported internals
|
||||
package integrationtest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package integrationtest //nolint:testpackage // tests unexported internals
|
||||
package integrationtest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package integrationtest //nolint:testpackage // tests unexported internals
|
||||
package integrationtest
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package integrationtest //nolint:testpackage // tests unexported internals
|
||||
package integrationtest
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package aibridge //nolint:testpackage // tests unexported newPassthroughRouter
|
||||
package aibridge
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
@@ -1,4 +1,4 @@
|
||||
package provider //nolint:testpackage // tests unexported internals
|
||||
package provider
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -1,4 +1,4 @@
|
||||
package provider //nolint:testpackage // tests unexported internals
|
||||
package provider
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -1,4 +1,4 @@
|
||||
package provider //nolint:testpackage // tests unexported internals
|
||||
package provider
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -1,4 +1,3 @@
|
||||
//nolint:testpackage // Internal test for unexported hashOAuth2State helper.
|
||||
package oauth2provider
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package coderd //nolint:testpackage // Tests the unexported resolveTemplateMetaUpdate helper.
|
||||
package coderd
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package chatd //nolint:testpackage // Accesses unexported advisor helpers.
|
||||
package chatd
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package chatd //nolint:testpackage
|
||||
package chatd
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatdebug //nolint:testpackage // Checks unexported normalized structs against fantasy source types.
|
||||
package chatdebug
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatdebug //nolint:testpackage // Uses unexported normalization helpers.
|
||||
package chatdebug
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatdebug //nolint:testpackage // Uses unexported recorder helpers.
|
||||
package chatdebug
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatdebug //nolint:testpackage // Uses unexported recorder helpers.
|
||||
package chatdebug
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatdebug //nolint:testpackage // Uses unexported recorder helpers.
|
||||
package chatdebug
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatloop //nolint:testpackage // Uses internal symbols.
|
||||
package chatloop
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatloop //nolint:testpackage // Uses internal symbols.
|
||||
package chatloop
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chattool //nolint:testpackage // Uses internal symbols.
|
||||
package chattool
|
||||
|
||||
import (
|
||||
"testing"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chattool //nolint:testpackage // Uses internal symbols.
|
||||
package chattool
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package chatd //nolint:testpackage // Uses internal cache state.
|
||||
package chatd
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatd //nolint:testpackage // Uses internal symbols.
|
||||
package chatd
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package chatd //nolint:testpackage // Uses internal symbols.
|
||||
package chatd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,4 +1,4 @@
|
||||
package chatd //nolint:testpackage // Keeps internal helper tests in-package.
|
||||
package chatd
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatd //nolint:testpackage
|
||||
package chatd
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package chatd //nolint:testpackage // Tests internal title override helpers.
|
||||
package chatd
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package chatd //nolint:testpackage // Keeps chatd unit tests in the package.
|
||||
package chatd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -1,4 +1,3 @@
|
||||
//nolint:testpackage
|
||||
package codersdk
|
||||
|
||||
import (
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
//nolint:testpackage // This test exercises the internal query builder directly because agent requests need a live tailnet connection.
|
||||
package workspacesdk
|
||||
|
||||
import (
|
||||
@@ -1,4 +1,4 @@
|
||||
package runner //nolint:testpackage // Tests unexported failure classification helpers.
|
||||
package runner
|
||||
|
||||
import (
|
||||
"testing"
|
||||
Reference in New Issue
Block a user