✨ feat(server): api.v2_enabled hot-reload via middleware gate (ADR-0023 Phase 4) #56
Reference in New Issue
Block a user
Delete Branch "feat/adr-0023-phase4-v2-hot-reload"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes ADR-0023 fully — all 4 phases shipped. Approach: always-register v2 routes + Server.v2EnabledGate middleware that reads live config and 404s when disabled. No router rebuild needed. 3 unit tests cover blocked / passes / hot-reload-mid-life. Race detector clean. Full BDD green. Final 'deferred' rationale turns out to have been wrong — cost was 25 lines of middleware + tests, not a chi refactor.
Closes ADR-0023 — all 4 phases now shipped. Final field: api.v2_enabled. Approach: always-register-with-middleware-gate. - /api/v2/* routes are now registered UNCONDITIONALLY at startup - new Server.v2EnabledGate middleware reads the live config on every request and returns 404 + {"error":"not_found","message":"v2 API is currently disabled"} when api.v2_enabled is false - the existing Config.WatchAndApply hot-reload pipeline already keeps the config struct fresh — no extra plumbing needed - flag flip takes effect on the NEXT request (not in-flight ones) - no router rebuild, no restart Tested via 3 unit tests in pkg/server/v2_gate_test.go: - blocked-when-disabled: 404 + correct error message + JSON content-type - passes-when-enabled: NOT 404, gate message ABSENT (handler executed) - hot-reload-mid-life: same Server, same router, config flipped between two requests → 404 then 200, proves the gate reads live config Race detector clean. Full BDD suite green. ADR-0023 status promoted to "Implemented" (no more parenthetical phase tracking). The original "deferred" rationale in ADR-0023 listed router refactor as the cost. Turns out the cost was minimal: ~25 lines of middleware + 3 tests + an `if` block deletion.