mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +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.
142 lines
3.7 KiB
Go
142 lines
3.7 KiB
Go
package chattool
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestValidateAskUserQuestionArgs(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
args askUserQuestionArgs
|
|
wantErr string
|
|
}{
|
|
{
|
|
name: "QuestionsRequired",
|
|
args: askUserQuestionArgs{},
|
|
wantErr: "questions is required",
|
|
},
|
|
{
|
|
name: "HeaderRequired",
|
|
args: askUserQuestionArgs{Questions: []askUserQuestion{{
|
|
Header: " \t ",
|
|
Question: "What should we build?",
|
|
Options: validAskUserQuestionOptions(2),
|
|
}}},
|
|
wantErr: "questions[0].header is required",
|
|
},
|
|
{
|
|
name: "QuestionRequired",
|
|
args: askUserQuestionArgs{Questions: []askUserQuestion{{
|
|
Header: "Scope",
|
|
Question: "\n\t ",
|
|
Options: validAskUserQuestionOptions(2),
|
|
}}},
|
|
wantErr: "questions[0].question is required",
|
|
},
|
|
{
|
|
name: "TooFewOptions",
|
|
args: askUserQuestionArgs{Questions: []askUserQuestion{{
|
|
Header: "Scope",
|
|
Question: "What should we build?",
|
|
Options: validAskUserQuestionOptions(1),
|
|
}}},
|
|
wantErr: "questions[0].options must contain 2-4 items",
|
|
},
|
|
{
|
|
name: "TooManyOptions",
|
|
args: askUserQuestionArgs{Questions: []askUserQuestion{{
|
|
Header: "Scope",
|
|
Question: "What should we build?",
|
|
Options: validAskUserQuestionOptions(5),
|
|
}}},
|
|
wantErr: "questions[0].options must contain 2-4 items",
|
|
},
|
|
{
|
|
name: "OptionLabelRequired",
|
|
args: askUserQuestionArgs{Questions: []askUserQuestion{{
|
|
Header: "Scope",
|
|
Question: "What should we build?",
|
|
Options: []askUserQuestionOption{
|
|
{Label: " ", Description: "Build the API first."},
|
|
{Label: "Frontend", Description: "Build the UI first."},
|
|
},
|
|
}}},
|
|
wantErr: "questions[0].options[0].label is required",
|
|
},
|
|
{
|
|
name: "OptionDescriptionRequired",
|
|
args: askUserQuestionArgs{Questions: []askUserQuestion{{
|
|
Header: "Scope",
|
|
Question: "What should we build?",
|
|
Options: []askUserQuestionOption{
|
|
{Label: "Backend", Description: "\t"},
|
|
{Label: "Frontend", Description: "Build the UI first."},
|
|
},
|
|
}}},
|
|
wantErr: "questions[0].options[0].description is required",
|
|
},
|
|
{
|
|
name: "ValidTwoOptions",
|
|
args: askUserQuestionArgs{Questions: []askUserQuestion{{
|
|
Header: "Scope",
|
|
Question: "What should we build?",
|
|
Options: validAskUserQuestionOptions(2),
|
|
}}},
|
|
},
|
|
{
|
|
name: "ValidFourOptions",
|
|
args: askUserQuestionArgs{Questions: []askUserQuestion{{
|
|
Header: "Scope",
|
|
Question: "What should we build?",
|
|
Options: validAskUserQuestionOptions(4),
|
|
}}},
|
|
},
|
|
{
|
|
name: "SecondQuestionInvalid",
|
|
args: askUserQuestionArgs{Questions: []askUserQuestion{
|
|
{
|
|
Header: "Scope",
|
|
Question: "What should we build?",
|
|
Options: validAskUserQuestionOptions(2),
|
|
},
|
|
{
|
|
Header: "Timeline",
|
|
Question: "\t ",
|
|
Options: validAskUserQuestionOptions(2),
|
|
},
|
|
}},
|
|
wantErr: "questions[1].question is required",
|
|
},
|
|
}
|
|
|
|
for _, testCase := range tests {
|
|
t.Run(testCase.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
err := validateAskUserQuestionArgs(testCase.args)
|
|
if testCase.wantErr == "" {
|
|
require.NoError(t, err)
|
|
return
|
|
}
|
|
|
|
require.EqualError(t, err, testCase.wantErr)
|
|
})
|
|
}
|
|
}
|
|
|
|
func validAskUserQuestionOptions(count int) []askUserQuestionOption {
|
|
options := []askUserQuestionOption{
|
|
{Label: "Backend", Description: "Build the API first."},
|
|
{Label: "Frontend", Description: "Build the UI first."},
|
|
{Label: "Docs", Description: "Write the docs first."},
|
|
{Label: "Tests", Description: "Start with tests first."},
|
|
{Label: "Research", Description: "Investigate the problem first."},
|
|
}
|
|
|
|
return append([]askUserQuestionOption(nil), options[:count]...)
|
|
}
|