mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-18 16:46:17 +00:00
Issue #285's first fix (5f31616) registered the rename PUT inside a chi subrouter at `/streaming/account/{account}/device`, alongside the existing POST handlers. A *second* subrouter was already declared at `/streaming/account/{account}/device/{device}` for the per-device sub-resources (presets, recent, group, …). chi's radix tree treats those two registrations as overlapping prefixes and at request time prefers the more-specific `/device/{device}` subrouter — which had no root-level method handlers. A PUT to /device/X fell through to the [UNHANDLED] catch-all, got proxied to streaming.bose.com, came back as 401 from CloudFront. Speakers retried in a loop. The handlers-package regression test passed because the test router in `pkg/service/handlers/main_test.go` is flatter (one subrouter for device, no `/device/{device}` nested block). The route snapshot test passed because `chi.Walk` enumerates each subrouter's registrations independently — it doesn't simulate how the radix tree will resolve a runtime request when subrouters overlap. Reproduced against the actual production setupRouter in TestPUTRenameRoutesToLocalHandler (new in router_test.go). Before this commit: 404 / [UNHANDLED] / 401 proxy. After: 200 from HandleMargeUpdateDevice. Fix: collapse the two subrouters into one. All `/device` routes — the POST/PUT/DELETE on the device resource itself plus the GET/POST sub-resources — share a single `r.Route("/device", ...)` block with explicit `/{device}/...` paths inside. No radix-tree ambiguity. Knock-on: the `r.Delete("/device/{device}", server.HandleMargeRemoveDevice)` that lived at the outer `/account/{account}` level moves into the unified `/device` subrouter for symmetry. Its prior placement was also being shadowed by the radix overlap, which is why the route snapshot's first regeneration after this fix grew by exactly one DELETE line — that route was never resolvable at runtime under the old structure either. Refs #285. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>