fix(handlers/discovery): nil-guard role in filterPeersByQuery — type assertion panic on empty role (closes #730) #731

Closed
fullstack-engineer wants to merge 1 commits from fix/730-discovery-filter-nil-role into staging

1 Commits

Author SHA1 Message Date
bdb9869a1e fix(handlers/discovery): nil-guard role in filterPeersByQuery — type assertion panic on empty role
All checks were successful
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 8s
sop-tier-check / tier-check (pull_request) Successful in 9s
audit-force-merge / audit (pull_request) Has been skipped
filterPeersByQuery did `role := p["role"].(string)` without checking nil.
When a workspace has an empty role, queryPeerMaps sets peer["role"] = nil
(discovery.go:340), causing a panic when GET /registry/:id/peers?q=... is
called with a non-empty q param.

Fix: check nil before the type assertion, defaulting to "" so nil-role
peers are skipped for role-filtering but still returned for name matches.

Adds discovery_filter_test.go — 9 cases covering empty/whitespace q,
name-only match, role-only match, nil-role panic regression (the primary
fault case), case-insensitivity, no-match, and nil/empty peer lists.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-12 14:24:56 +00:00