mirror of
https://github.com/coder/coder.git
synced 2026-06-03 13:08:25 +00:00
c650aabbef
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.
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package workspacesdk
|
|
|
|
import (
|
|
neturl "net/url"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAgentAPIPath(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("encodes reserved query characters", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
path := "/tmp/a&b ?#%c.md"
|
|
got := agentAPIPath("/api/v0/resolve-path", neturl.Values{
|
|
"path": []string{path},
|
|
})
|
|
|
|
parsed, err := neturl.Parse(got)
|
|
require.NoError(t, err)
|
|
require.Equal(t, "/api/v0/resolve-path", parsed.Path)
|
|
require.Equal(t, path, parsed.Query().Get("path"))
|
|
})
|
|
|
|
t.Run("preserves all query values", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got := agentAPIPath("/api/v0/read-file-lines", neturl.Values{
|
|
"path": []string{"/tmp/plan v1#.md"},
|
|
"offset": []string{"10"},
|
|
"limit": []string{"20"},
|
|
"max_file_size": []string{"30"},
|
|
"max_line_bytes": []string{"40"},
|
|
"max_response_lines": []string{"50"},
|
|
"max_response_bytes": []string{"60"},
|
|
})
|
|
|
|
parsed, err := neturl.Parse(got)
|
|
require.NoError(t, err)
|
|
require.Equal(t, "/api/v0/read-file-lines", parsed.Path)
|
|
require.Equal(t, "/tmp/plan v1#.md", parsed.Query().Get("path"))
|
|
require.Equal(t, "10", parsed.Query().Get("offset"))
|
|
require.Equal(t, "20", parsed.Query().Get("limit"))
|
|
require.Equal(t, "30", parsed.Query().Get("max_file_size"))
|
|
require.Equal(t, "40", parsed.Query().Get("max_line_bytes"))
|
|
require.Equal(t, "50", parsed.Query().Get("max_response_lines"))
|
|
require.Equal(t, "60", parsed.Query().Get("max_response_bytes"))
|
|
})
|
|
}
|