Make AddRoute idempotent (upsert instead of reject duplicates)
AddRoute now updates an existing route if one already exists for the same (listener, hostname) pair, instead of returning AlreadyExists. This makes repeated deploys idempotent — the MCP agent can register routes on every deploy without needing to remove them first. - DB: INSERT ... ON CONFLICT DO UPDATE (SQLite upsert) - In-memory: overwrite existing route unconditionally - gRPC: error code changed from AlreadyExists to Internal (for real DB errors) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -679,16 +679,12 @@ func TestListenerStateRoutes(t *testing.T) {
|
||||
}
|
||||
|
||||
// AddRoute
|
||||
if err := ls.AddRoute("b.test", l4Route("127.0.0.1:2")); err != nil {
|
||||
t.Fatalf("AddRoute: %v", err)
|
||||
}
|
||||
ls.AddRoute("b.test", l4Route("127.0.0.1:2"))
|
||||
|
||||
// AddRoute duplicate
|
||||
if err := ls.AddRoute("b.test", l4Route("127.0.0.1:3")); err == nil {
|
||||
t.Fatal("expected error for duplicate route")
|
||||
}
|
||||
// AddRoute duplicate (upsert — updates in place)
|
||||
ls.AddRoute("b.test", l4Route("127.0.0.1:3"))
|
||||
|
||||
// Routes snapshot
|
||||
// Routes snapshot — still 2 routes, the duplicate replaced the first.
|
||||
routes := ls.Routes()
|
||||
if len(routes) != 2 {
|
||||
t.Fatalf("expected 2 routes, got %d", len(routes))
|
||||
@@ -708,8 +704,8 @@ func TestListenerStateRoutes(t *testing.T) {
|
||||
if len(routes) != 1 {
|
||||
t.Fatalf("expected 1 route, got %d", len(routes))
|
||||
}
|
||||
if routes["b.test"].Backend != "127.0.0.1:2" {
|
||||
t.Fatalf("expected b.test → 127.0.0.1:2, got %q", routes["b.test"].Backend)
|
||||
if routes["b.test"].Backend != "127.0.0.1:3" {
|
||||
t.Fatalf("expected b.test → 127.0.0.1:3 (upserted), got %q", routes["b.test"].Backend)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user