From b5f4c3e55c9b0d9f3072394b9f51acf88575e28b Mon Sep 17 00:00:00 2001 From: philluiz2323 Date: Mon, 27 Jul 2026 09:01:04 -0700 Subject: [PATCH] test(registry): cover refreshRegistry all-sources-failed path refreshRegistry's status:error syncRuns branch (every API candidate + raw fallback exhausted) had no test ? only the successful raw-GitHub fallback was covered. Add a regression asserting the thrown error and persisted error sync_runs row. Closes #9314 --- test/unit/registry.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/unit/registry.test.ts b/test/unit/registry.test.ts index 8cdd783bac..08edbdf2d5 100644 --- a/test/unit/registry.test.ts +++ b/test/unit/registry.test.ts @@ -423,4 +423,27 @@ describe("registry normalization", () => { expect(snapshot.warnings.length).toBeGreaterThan(0); expect(snapshot.repositories[0]?.repo).toBe("JSONbored/loopover"); }); + + it("marks the sync run as error when every registry source fails (#9314)", async () => { + // Cover both warning-push branches: non-OK responses and thrown fetch errors. + let probeIndex = 0; + vi.stubGlobal("fetch", async () => { + probeIndex += 1; + if (probeIndex % 2 === 0) throw new Error(`network down ${probeIndex}`); + return new Response("not found", { status: 404 }); + }); + + const env = createTestEnv(); + await expect(refreshRegistry(env)).rejects.toThrow("No registry source returned usable data."); + + const row = await env.DB.prepare("SELECT status, warnings_json, error_summary FROM sync_runs WHERE job_type = ? ORDER BY rowid DESC LIMIT 1") + .bind("refresh-registry") + .first<{ status: string; warnings_json: string; error_summary: string }>(); + expect(row?.status).toBe("error"); + expect(row?.error_summary).toContain("No registry source returned usable data."); + const warnings = JSON.parse(row?.warnings_json ?? "[]") as string[]; + // 6 API candidates + the GITTENSOR_REGISTRY_URL raw fallback. + expect(warnings).toHaveLength(7); + expect(warnings.every((warning) => warning.startsWith("Registry probe failed:"))).toBe(true); + }); });