carlos / platform Public

console: the mux is reached only through registerRoute

Task 2 review R2: handing s.mux to another package's Mount registered
routes no scan or claimEntries saw. registrarViolations now refuses
every selector named mux in non-test console code outside registerRoute
and NewServer's perf.Middleware wrap, and a mux: field outside NewServer,
with "the console's mux is reached only through registerRoute". The
registrar test also checks Server's only ServeMux field is the
unexported mux. New fixtures plant an external Mount, an alias, a
reassignment, a call argument, a getter and a stray literal; mutation 12
records the Mount case.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev a06cfc26194f836400fccf86e86f6923dee37e5f parent 14dbd24
3 files changed, +110 −3
  • docs/superpowers/notes/2026-11-09-parity-guard-mutations.md +10 −0
  • internal/console/claim_routes_test.go +42 −0
  • internal/console/svcroutes_test.go +58 −3

Intent

Human

<task-notification> <task-id>ad95ce8dfa03af549</task-id> <tool-use-id>toolu_01XCnv8YRTJRR5WwTZcNpLDx</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2185be7a-bc2c-4a32-953d-1ee7721363e3/tasks/ad95ce8dfa03af549.output</output-file> <status>completed</status> <summary>Agent "Implement Task 4: rule, discussions, Luna" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Task 4 is done. Both test runs pass, and the Luna copy pass came back with no flags. **Commit:** 14dbd242 `parity: AGENTS.md rule and work-package discussions` **Discussions:** nine repo-level threads, all set to Feature Request. | Package | Discussion | |---|---| | wp-instances | #734 | | wp-settings | #735 | | wp-schedules-sidecars | #736 | | wp-email-storage | #737 | | wp-cli-verbs | #738 | | wp-fleets-relay | #739 | | wp-db-run | #740 | | wp-terminal | #741 | | wp-import | #742 | Each number is in `parity/packages.tsv` and the page is regenerated. **Tests:** `go test ./internal/parity/ -count=1` and `go test ./internal/console/ -count=1 -run Parity` both pass. gofmt and vet are clean. I blanked one package's number and `TestParityPackagesFiled` failed, naming that package, then I put the number back. **Concerns:** - **Page link:** the hub has no `/-/blob/` URLs, so I took the file link shape from the repo page's own links: `https://amadan.net/carlos/platform?ref=main&amp;path=docs/parity.md#wp-...`. Each body also links the copy on the branch, because the page is not on main yet. I haven't checked that the `#wp-...` anchors scroll to the section in amadan's file view. - **Luna's AGENTS.md wording:** it says "When a branch closes a gap, move its row to `both`" instead of "in the branch that builds the missing side". It means the same thing, so I applied it as written. - **Copy changes:** I applied all of Luna's table and rejected nothing. One `page_test.go` expected string changed to match the new line about subcommands. - **Not committed:** the report sits in `.superpowers/`, which git doesn't track. No `internal/console/*.go` file was touched, and the scratch directory is removed. Full report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-parity-guard/.superpowers/sdd/2026-11-09-parity-guard/task-4-report.md</result> <usage><subagent_tokens>87665</subagent_tokens><tool_uses>39</tool_uses><duration_ms>321734</duration_ms></usage> </task-notification>

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 8f016c8ea..011d55668 100644
--- a/docs/superpowers/notes/2026-11-09-parity-guard-mutations.md
+++ b/docs/superpowers/notes/2026-11-09-parity-guard-mutations.md
@@ -19,6 +19,7 @@ in the committed tree.
| 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`. |
+| 12 | `instanceupdates.Mount(s.mux, "unlisted", nil, nil)` added in NewServer (Task 2 review R2) | TestClaimConsoleMuxHasOneRegistrar; every scanner test (checked with TestAuthCLIFamilyResolvesOnlyPersons) | `mux referenced at server.go:1946:24: the console's mux is reached only through registerRoute`. Before the fix this passed: Mount calls HandleFunc in another package. |
## What the mutations found
@@ -35,3 +36,12 @@ 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.
+
+Mutation 12 comes from the Task 2 review (round 2). Rather than another
+registration pattern, the registrar scan now holds one boundary: in
+non-test console code a selector named mux appears only inside
+registerRoute and in NewServer's perf.Middleware(...)(s.mux) wrap, and the
+field is set only in NewServer's literal. TestClaimConsoleMuxHasOneRegistrar
+also checks Server's only *http.ServeMux field is the unexported mux.
+TestRegistrarViolationsRefusesAliases adds an external Mount, an alias, a
+reassignment, a function argument, a getter and a literal outside NewServer.
diff --git a/internal/console/claim_routes_test.go b/internal/console/claim_routes_test.go
index 707ed27ba..e8c57a407 100644
--- a/internal/console/claim_routes_test.go
+++ b/internal/console/claim_routes_test.go
@@ -65,6 +65,36 @@ func TestClaimConsoleMuxHasOneRegistrar(t *testing.T) {
if muxSites == 0 {
t.Fatal("found no mux registration in registerRoute; the walk is broken")
}
+ // The field the boundary guards: unexported, and the only one of its
+ // type, so there is no second spelling of the console's mux.
+ var muxFields []string
+ for _, f := range files {
+ ast.Inspect(f, func(n ast.Node) bool {
+ ts, ok := n.(*ast.TypeSpec)
+ if !ok || ts.Name.Name != "Server" {
+ return true
+ }
+ st, ok := ts.Type.(*ast.StructType)
+ if !ok {
+ return true
+ }
+ for _, fld := range st.Fields.List {
+ star, ok := fld.Type.(*ast.StarExpr)
+ if !ok {
+ continue
+ }
+ if sel, ok := star.X.(*ast.SelectorExpr); ok && sel.Sel.Name == "ServeMux" {
+ for _, name := range fld.Names {
+ muxFields = append(muxFields, name.Name)
+ }
+ }
+ }
+ return false
+ })
+ }
+ if !slices.Equal(muxFields, []string{"mux"}) {
+ t.Errorf("Server's *http.ServeMux fields are %q, want exactly the unexported mux", muxFields)
+ }
}
// TestRegistrarViolationsRefusesAliases: the registrar scan rejects a mux
@@ -76,6 +106,12 @@ func TestRegistrarViolationsRefusesAliases(t *testing.T) {
import "net/http"
func (s *Server) registerRoute(d routeDecl, h http.HandlerFunc) { s.mux.HandleFunc(d.Pattern, h) }
+
+func NewServer() *Server {
+ s := &Server{mux: http.NewServeMux()}
+ s.handler = perf.Middleware(s.perf, perf.Options{})(s.mux)
+ return s
+}
`
scan := func(t *testing.T, src string) ([]string, int) {
t.Helper()
@@ -96,6 +132,12 @@ func (s *Server) registerRoute(d routeDecl, h http.HandlerFunc) { s.mux.HandleFu
{"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) }"},
+ {"mux handed to another package", "func NewServer(s *Server) { instanceupdates.Mount(s.mux, nil) }"},
+ {"mux aliased", "func NewServer(s *Server) { m := s.mux; _ = m }"},
+ {"mux reassigned", "func NewServer(s *Server, x *http.ServeMux) { s.mux = x }"},
+ {"mux passed to a function", "func NewServer(s *Server) { f(s.mux) }"},
+ {"mux getter", "func (s *Server) Mux() *http.ServeMux { return s.mux }"},
+ {"mux set outside NewServer", "func other() *Server { return &Server{mux: http.NewServeMux()} }"},
} {
t.Run(c.name, func(t *testing.T) {
if v, _ := scan(t, clean+"\n"+c.src+"\n"); len(v) == 0 {
diff --git a/internal/console/svcroutes_test.go b/internal/console/svcroutes_test.go
index e40f21447..ddf506288 100644
--- a/internal/console/svcroutes_test.go
+++ b/internal/console/svcroutes_test.go
@@ -1158,19 +1158,50 @@ var registrarSites = map[string]map[string]bool{
// 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.
+//
+// It also holds the boundary those checks rest on: the console's mux is
+// reached only through registerRoute. Any selector named mux is refused
+// except inside registerRoute and the one perf.Middleware(...)(s.mux) wrap
+// in NewServer, and the field is set (mux: in a literal) only in
+// NewServer. So the mux cannot be passed to another package's Mount,
+// aliased, reassigned or returned by a getter, any of which would
+// register routes no scan or claimEntries sees.
func registrarViolations(fset *token.FileSet, files []*ast.File) (violations []string, muxSites int) {
+ const muxBoundary = "the console's mux is reached only through registerRoute"
for _, f := range files {
var enclosing *ast.FuncDecl
+ wrapped := map[*ast.SelectorExpr]bool{}
+ for _, d := range f.Decls {
+ fd, ok := d.(*ast.FuncDecl)
+ if !ok || fd.Recv != nil || fd.Name.Name != "NewServer" || fd.Body == nil {
+ continue
+ }
+ ast.Inspect(fd.Body, func(n ast.Node) bool {
+ if sel, ok := perfWrappedMux(n); ok {
+ wrapped[sel] = true
+ }
+ return true
+ })
+ }
var visit func(n ast.Node) bool
visit = func(n ast.Node) bool {
+ site, onServer := "", false
+ if enclosing != nil {
+ site, onServer = enclosing.Name.Name, receiverIsServer(enclosing)
+ }
+ if kv, ok := n.(*ast.KeyValueExpr); ok {
+ if id, ok := kv.Key.(*ast.Ident); ok && id.Name == "mux" && !(enclosing != nil && enclosing.Recv == nil && site == "NewServer") {
+ violations = append(violations, fmt.Sprintf("mux set outside NewServer at %s: %s", fset.Position(kv.Pos()), muxBoundary))
+ }
+ return true
+ }
sel, ok := n.(*ast.SelectorExpr)
if !ok {
return true
}
name := sel.Sel.Name
- site, onServer := "", false
- if enclosing != nil {
- site, onServer = enclosing.Name.Name, receiverIsServer(enclosing)
+ if name == "mux" && !(onServer && site == "registerRoute") && !wrapped[sel] {
+ violations = append(violations, fmt.Sprintf("mux referenced at %s: %s", fset.Position(sel.Pos()), muxBoundary))
}
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())))
@@ -1199,6 +1230,30 @@ func registrarViolations(fset *token.FileSet, files []*ast.File) (violations []s
return violations, muxSites
}
+// perfWrappedMux matches perf.Middleware(...)(x.mux) and returns x.mux.
+func perfWrappedMux(n ast.Node) (*ast.SelectorExpr, bool) {
+ call, ok := n.(*ast.CallExpr)
+ if !ok || len(call.Args) != 1 {
+ return nil, false
+ }
+ inner, ok := call.Fun.(*ast.CallExpr)
+ if !ok {
+ return nil, false
+ }
+ fn, ok := inner.Fun.(*ast.SelectorExpr)
+ if !ok || fn.Sel.Name != "Middleware" {
+ return nil, false
+ }
+ if pkg, ok := fn.X.(*ast.Ident); !ok || pkg.Name != "perf" {
+ return nil, false
+ }
+ sel, ok := call.Args[0].(*ast.SelectorExpr)
+ if !ok || sel.Sel.Name != "mux" {
+ return nil, false
+ }
+ return sel, true
+}
+
// receiverIsServer reports whether fd is a method on *Server.
func receiverIsServer(fd *ast.FuncDecl) bool {
if fd.Recv == nil || len(fd.Recv.List) != 1 {