build(tools): lint the tools module in the gate
golangci-lint ran ./... from the repository root, which stops at the root module, so the tools module was never linted and had drifted unseen. task check already closes this hole for tests with test:tools; lint now has the same shape in lint:tools, which runs in the tools directory rather than passing a path prefix that only rewrites output paths. Fixes the six issues that had accumulated behind it: stripJSComments was 21 cyclomatic complexity against a cap of 15, with the comment-skipping and literal-copying loops inlined into one scanner. It is four named functions now, and the De Morgan warning went with the rewrite. It had no test despite deciding whether a commented-out call reads as a live consumer, so it has one: literals that look like comments, comment markers inside strings, escapes, and unterminated literals and block comments. docsgen's missing-artifact error ended in punctuation, and three test type assertions were unchecked, which panic rather than fail when the generated artifact does not have the shape the case assumes.
This commit is contained in:
1 parent
95743b60cc
commit
959cf45ae2
5 files changed
+109
-38
No files matched your search
@@ -135,7 +135,7 @@ func check(repoRoot, outPath string) error {
|
||||
committed, err := os.ReadFile(committedPath)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return fmt.Errorf(
|
||||
"%s is missing; regenerate it with: go -C tools run ./docsgen --repo-root ..",
|
||||
"%s is missing; regenerate it by running `go -C tools run ./docsgen --repo-root ..` from the tools module",
|
||||
relative,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -195,8 +195,8 @@ func TestCheckReportsChangedSchema(t *testing.T) {
|
||||
t.Fatalf("run() error = %v", err)
|
||||
}
|
||||
mutateGeneratedData(t, output, func(data map[string]any) {
|
||||
schemas := data["schemas"].(map[string]any)
|
||||
schemas["AgentExecutionResult"].(map[string]any)["title"] = "tampered"
|
||||
schemas := mapAt(t, data, "schemas")
|
||||
mapAt(t, schemas, "AgentExecutionResult")["title"] = "tampered"
|
||||
})
|
||||
|
||||
err := check(repoRoot, output)
|
||||
@@ -217,7 +217,7 @@ func TestCheckReportsRemovedSchema(t *testing.T) {
|
||||
t.Fatalf("run() error = %v", err)
|
||||
}
|
||||
mutateGeneratedData(t, output, func(data map[string]any) {
|
||||
delete(data["schemas"].(map[string]any), "MessageEvent")
|
||||
delete(mapAt(t, data, "schemas"), "MessageEvent")
|
||||
})
|
||||
|
||||
err := check(repoRoot, output)
|
||||
@@ -505,3 +505,14 @@ func walkJSON(value any, visitRef func(string)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// mapAt returns the nested object at key, failing the test rather than panicking
|
||||
// when the generated artifact does not have the shape the case assumes.
|
||||
func mapAt(t *testing.T, parent map[string]any, key string) map[string]any {
|
||||
t.Helper()
|
||||
child, ok := parent[key].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("%s is %T, want an object", key, parent[key])
|
||||
}
|
||||
return child
|
||||
}
|
||||
Reference in new issue
Block a user