Skip to content

Commit fa2bfd9

Browse files
authored
test(registry): cover refreshRegistry all-sources-failed path (#9396)
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
1 parent 9f56b2a commit fa2bfd9

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

test/unit/registry.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,27 @@ describe("registry normalization", () => {
423423
expect(snapshot.warnings.length).toBeGreaterThan(0);
424424
expect(snapshot.repositories[0]?.repo).toBe("JSONbored/loopover");
425425
});
426+
427+
it("marks the sync run as error when every registry source fails (#9314)", async () => {
428+
// Cover both warning-push branches: non-OK responses and thrown fetch errors.
429+
let probeIndex = 0;
430+
vi.stubGlobal("fetch", async () => {
431+
probeIndex += 1;
432+
if (probeIndex % 2 === 0) throw new Error(`network down ${probeIndex}`);
433+
return new Response("not found", { status: 404 });
434+
});
435+
436+
const env = createTestEnv();
437+
await expect(refreshRegistry(env)).rejects.toThrow("No registry source returned usable data.");
438+
439+
const row = await env.DB.prepare("SELECT status, warnings_json, error_summary FROM sync_runs WHERE job_type = ? ORDER BY rowid DESC LIMIT 1")
440+
.bind("refresh-registry")
441+
.first<{ status: string; warnings_json: string; error_summary: string }>();
442+
expect(row?.status).toBe("error");
443+
expect(row?.error_summary).toContain("No registry source returned usable data.");
444+
const warnings = JSON.parse(row?.warnings_json ?? "[]") as string[];
445+
// 6 API candidates + the GITTENSOR_REGISTRY_URL raw fallback.
446+
expect(warnings).toHaveLength(7);
447+
expect(warnings.every((warning) => warning.startsWith("Registry probe failed:"))).toBe(true);
448+
});
426449
});

0 commit comments

Comments
 (0)