gui test: a route the CLI's list doesn't name fails internal/gui too

TestEveryRouteHasACommandOrIsNamed (internal/cli) went red on main for a new GUI route six times in a week (#5946, #6162, #6677, #6724, #6786): GUI changes run internal/gui, not internal/cli. TestEveryRouteIsNamedForTheCLI reads the same HandleFunc routes and fails when one isn't a key in internal/cli/settings_parity_test.go, so the run a GUI change already does catches it. The CLI test still checks which command each route has. LESSONS: the 11-15 case and the rule that a check repeatedly missed goes where the work runs.

Run at origin/main ec5b96c44 plus this, on mica: go test -count=1 ./internal/gui ok (185s); TestEveryRouteIsNamedForTheCLI red with the quit/disconnect line taken out of notYet ("POST /api/quit/disconnect (api.go) isn't named ..."), green with it. gofmt -l clean. Not run: Linux and Windows vet (test-only file, os/filepath/regexp only).
This commit is contained in:
yetone
2026-11-16 01:18:18 +08:00
parent ec5b96c44f
commit 3173c4f41e
2 changed files with 56 additions and 1 deletions
+9 -1
View File
@@ -408,7 +408,15 @@ TestSettingsSaveKeepsWhatItDoesNotSend (internal/gui) every setting.
Both bodies say what they ran; neither ran `go test ./internal/cli`
(40s). The same day three commits that each fit the core's script
budget at their own base left it 4 bytes over together (61a93b531).
- Seen 1× (2026-11-11).
- 11-15: 261f48226 (Disconnect and quit) added POST /api/quit/disconnect
and ran internal/gui and five GUI files, not internal/cli. The CLI
guard was red on ubuntu and macOS CI at 0ffb21f83 (#6786). After
this rule had been written and missed again, the check moved to the
package GUI changes do run: internal/gui's
TestEveryRouteIsNamedForTheCLI fails on a route that the CLI's list
doesn't name. When a rule keeps being missed, put its check where
the work already runs.
- Seen 2× (2026-11-11, 2026-11-15).
**A full run gives the slow packages room.** `go test ./...` at the default
10m timeout times out in internal/gateway (#2108), and under load in
+47
View File
@@ -0,0 +1,47 @@
package gui
import (
"os"
"path/filepath"
"regexp"
"strings"
"testing"
)
// Every /api route this package serves is named in internal/cli's route
// list (cliForRoute or notYet in settings_parity_test.go), checked here
// too: a GUI change runs this package, and a new route unnamed there left
// TestEveryRouteHasACommandOrIsNamed red on main again and again (#5946,
// #6162, #6677, #6724, #6786), each found by CI after the push. That
// test still says which command a route has; this one only says the
// route was named at all.
func TestEveryRouteIsNamedForTheCLI(t *testing.T) {
list, err := os.ReadFile(filepath.Join("..", "cli", "settings_parity_test.go"))
if err != nil {
t.Fatal(err)
}
files, err := filepath.Glob("*.go")
if err != nil {
t.Fatal(err)
}
re := regexp.MustCompile(`HandleFunc\("([A-Z]+ /api/[^"]*)"`)
n := 0
for _, f := range files {
if strings.HasSuffix(f, "_test.go") {
continue
}
b, err := os.ReadFile(f)
if err != nil {
t.Fatal(err)
}
for _, m := range re.FindAllStringSubmatch(string(b), -1) {
n++
if !strings.Contains(string(list), `"`+m[1]+`":`) {
t.Errorf("%s (%s) isn't named in internal/cli/settings_parity_test.go: add it to cliForRoute with its command, or to notYet with why there's none", m[1], f)
}
}
}
if n < 200 {
t.Fatalf("read %d routes", n)
}
}