console: registrar scan rejects every Handle/HandleFunc
Task 2 review R1 P1: registrarViolations only recognised a mux reached through a field named mux, so `mux := s.mux; mux.HandleFunc(...)` in NewServer escaped every scanner. Any selector named Handle or HandleFunc outside registerRoute now fails, whatever its receiver and whether it is called or taken as a value, which also covers http's default mux. TestRegistrarViolationsRefusesAliases plants each shape; mutation 11 in the notes records the alias case failing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+56
−12
docs/superpowers/notes/2026-11-09-parity-guard-mutations.md+8 −0internal/console/claim_routes_test.go+41 −0internal/console/svcroutes_test.go+7 −12
diff --git a/docs/superpowers/notes/2026-11-09-parity-guard-mutations.md b/docs/superpowers/notes/2026-11-09-parity-guard-mutations.md| index c6914f75a..8f016c8ea 100644 |
| --- a/docs/superpowers/notes/2026-11-09-parity-guard-mutations.md |
| +++ b/docs/superpowers/notes/2026-11-09-parity-guard-mutations.md |
| @@ -18,6 +18,7 @@ in the committed tree. |
| | 8 | `_, _ = principalFrom(r.Context())` in the `GET /healthz` Build literal's inner body | TestAuthCLIFamilyResolvesOnlyPersons | `GET /healthz: resolves a bearer through principalFrom at routedecls.go:367:11 — ...` | |
| | 9 | `POST /auth/cli/revoke` declaration removed | TestAuthCLIFamilyResolvesOnlyPersons | `POST /auth/cli/revoke: not found as a plain declaration; either it moved or the walker is broken` | |
| | 10 | `gateDemo.holds` returns false | TestRouteDeclsMatchRegistrations | `GET /api/box/demo-builds: no configuration registers it (gate "demo" never holds)` (one per demo declaration) and `gate "demo" is never on in the configuration matrix` | |
| +| 11 | `mux := s.mux; mux.HandleFunc("GET /api/cli/unlisted", s.handleHome)` added in NewServer (Task 2 review R1 P1) | TestClaimConsoleMuxHasOneRegistrar; every scanner test (checked with TestAuthCLIFamilyResolvesOnlyPersons) | `mux registration outside registerRoute: server.go:1946:2`. Before the fix this passed: the scan only recognised a receiver field named `mux`. | |
| ## What the mutations found |
| @@ -27,3 +28,10 @@ of it is a bare identifier the scan never saw. That gap predates this |
| branch (the old scanner had the same match). e9d1a97b makes the scan match |
| identifiers, which covers selector names too; mutation 8 then failed as |
| shown, and mutation 6 was rerun and still fails. |
| + |
| +Mutation 11 comes from the Task 2 review (round 1, P1). The registrar scan |
| +now rejects every selector named Handle or HandleFunc outside registerRoute, |
| +whatever the receiver and whether it is called or taken as a value, and |
| +TestRegistrarViolationsRefusesAliases plants the alias, a method value of |
| +HandleFunc, http's default mux (call and package-level var), a helper method |
| +value and a mux registration in another Server method. |
diff --git a/internal/console/claim_routes_test.go b/internal/console/claim_routes_test.go| index 21ba10c47..707ed27ba 100644 |
| --- a/internal/console/claim_routes_test.go |
| +++ b/internal/console/claim_routes_test.go |
| @@ -1,6 +1,9 @@ |
| package console |
| import ( |
| + "go/ast" |
| + "go/parser" |
| + "go/token" |
| "os" |
| "slices" |
| "strings" |
| @@ -63,3 +66,41 @@ func TestClaimConsoleMuxHasOneRegistrar(t *testing.T) { |
| t.Fatal("found no mux registration in registerRoute; the walk is broken") |
| } |
| } |
| + |
| +// TestRegistrarViolationsRefusesAliases: the registrar scan rejects a mux |
| +// registration however its receiver is spelled, and a helper reached |
| +// through a method value, while the one allowed site stays clean. |
| +func TestRegistrarViolationsRefusesAliases(t *testing.T) { |
| + const clean = `package console |
| + |
| +import "net/http" |
| + |
| +func (s *Server) registerRoute(d routeDecl, h http.HandlerFunc) { s.mux.HandleFunc(d.Pattern, h) } |
| +` |
| + scan := func(t *testing.T, src string) ([]string, int) { |
| + t.Helper() |
| + fset := token.NewFileSet() |
| + f, err := parser.ParseFile(fset, "planted.go", src, 0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return registrarViolations(fset, []*ast.File{f}) |
| + } |
| + if v, n := scan(t, clean); len(v) != 0 || n != 1 { |
| + t.Fatalf("clean source: violations %q, mux sites %d (want none and 1)", v, n) |
| + } |
| + for _, c := range []struct{ name, src string }{ |
| + {"local alias of the mux", "func NewServer(s *Server) { mux := s.mux; mux.HandleFunc(\"GET /api/cli/unlisted\", s.handleHome) }"}, |
| + {"method value of HandleFunc", "func NewServer(s *Server) { h := s.mux.HandleFunc; h(\"GET /x\", s.handleHome) }"}, |
| + {"default mux", "func NewServer(s *Server) { http.HandleFunc(\"GET /x\", s.handleHome) }"}, |
| + {"default mux Handle in a var", "var _ = func() bool { http.Handle(\"/x\", nil); return true }()"}, |
| + {"helper method value", "func NewServer(s *Server) { f := s.registerRoute; f(routeDecl{Pattern: \"GET /x\"}, s.handleHome) }"}, |
| + {"mux registration in another Server method", "func (s *Server) other() { s.mux.Handle(\"/x\", nil) }"}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + if v, _ := scan(t, clean+"\n"+c.src+"\n"); len(v) == 0 { |
| + t.Errorf("not reported: %s", c.src) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/console/svcroutes_test.go b/internal/console/svcroutes_test.go| index f22b2da09..e40f21447 100644 |
| --- a/internal/console/svcroutes_test.go |
| +++ b/internal/console/svcroutes_test.go |
| @@ -1152,9 +1152,12 @@ var registrarSites = map[string]map[string]bool{ |
| // registrarViolations reports, with its position, every mention of a |
| // registration helper outside registrarSites (a call, a method value or a |
| -// method expression alike) and every mux registration outside |
| -// registerRoute. muxSites counts registerRoute's own mux registrations, so |
| -// a caller can tell an empty walk from a clean one. |
| +// method expression alike) and every selector named Handle or HandleFunc |
| +// outside registerRoute, whatever its receiver: s.mux, a local alias of |
| +// it, http's default mux, or a method value taken to call later. Nothing |
| +// else in the package has a reason to name either. muxSites counts the |
| +// ones inside registerRoute, so a caller can tell an empty walk from a |
| +// clean one. |
| func registrarViolations(fset *token.FileSet, files []*ast.File) (violations []string, muxSites int) { |
| for _, f := range files { |
| var enclosing *ast.FuncDecl |
| @@ -1172,7 +1175,7 @@ func registrarViolations(fset *token.FileSet, files []*ast.File) (violations []s |
| if registrationHelpers[name] && !(onServer && registrarSites[site][name]) { |
| violations = append(violations, fmt.Sprintf("%s outside registerDecls and the helpers forwarding to registerRoute: %s", name, fset.Position(sel.Pos()))) |
| } |
| - if (name == "Handle" || name == "HandleFunc") && isMuxRegistration(sel) { |
| + if name == "Handle" || name == "HandleFunc" { |
| if onServer && site == "registerRoute" { |
| muxSites++ |
| } else { |
| @@ -1209,14 +1212,6 @@ func receiverIsServer(fd *ast.FuncDecl) bool { |
| return ok && id.Name == "Server" |
| } |
| -// isMuxRegistration reports whether a selector is a call on something's `mux` |
| -// field — s.mux.HandleFunc and friends — as opposed to any other method that |
| -// happens to share the name. |
| -func isMuxRegistration(sel *ast.SelectorExpr) bool { |
| - recv, ok := sel.X.(*ast.SelectorExpr) |
| - return ok && recv.Sel.Name == "mux" |
| -} |
| - |
| // stringLit unwraps an argument that is a plain quoted string. |
| func stringLit(e ast.Expr) (string, bool) { |
| lit, ok := e.(*ast.BasicLit) |