fix(storage): repair orphaned KV routes

Repair orphaned KV routes before serving KV-only configuration.
This commit is contained in:
RhenCloud committed 2026-10-24 15:47:39 +08:00
1 parent 5fcb129170
commit 714953bb76
2 files changed
+32 -1

No files matched your search

+16
View File
@@ -380,6 +380,22 @@ describe("kvConfigStore", () => {
expect(JSON.parse(store.get("config:routes")!)).toEqual([]);
});
it("repairs orphaned routes before a reused group id can inherit them", async () => {
const { kv, store } = createMemoryKV();
store.set("config:groups", JSON.stringify([group("current")]));
store.set(
"config:routes",
JSON.stringify([route("orphan", "reused"), route("live", "current")]),
);
const cfg = kvConfigStore(kv);
expect((await cfg.loadRoutes()).map((r) => r.id)).toEqual(["live"]);
expect(JSON.parse(store.get("config:routes")!)).toEqual([route("live", "current")]);
await expect(cfg.createGroup(group("reused"))).resolves.toBe(true);
expect((await cfg.loadRoutes()).map((r) => r.id)).toEqual(["live"]);
});
it("backfills the same instance whichever cold start wins the race", async () => {
const { kv, store } = createMemoryKV();
store.set("config:groups", JSON.stringify([group("legacy")]));