Skip to content

Commit 3bed483

Browse files
committed
test(code-index): cover registry retry after construction failure
1 parent ef7cdda commit 3bed483

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎src/services/code-index/__tests__/code-index-manager-registry.spec.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,22 @@ describe("CodeIndexManagerRegistry", () => {
108108
expect(CodeIndexManagerRegistry.getAllInstances()).toEqual([a, b])
109109
})
110110

111+
it("does not cache a scope when manager construction fails and permits retry for the same path", () => {
112+
const error = new Error("construction failed")
113+
vi.mocked(CodeIndexManager).mockImplementationOnce(function () {
114+
throw error
115+
})
116+
117+
expect(() => CodeIndexManagerRegistry.getOrCreate(context, "/first")).toThrow(error)
118+
expect(CodeIndexManagerRegistry.getAllInstances()).toEqual([])
119+
120+
const manager = CodeIndexManagerRegistry.getOrCreate(context, "/first")
121+
expect(manager).toBe(vi.mocked(CodeIndexManager).mock.results[1].value)
122+
expect(CodeIndexManagerRegistry.getAllInstances()).toEqual([manager])
123+
expect(CodeIndexManagerRegistry.getOrCreate(context, "/first")).toBe(manager)
124+
expect(CodeIndexManager).toHaveBeenCalledTimes(2)
125+
})
126+
111127
it("returns a snapshot that cannot mutate the cache", () => {
112128
expect(CodeIndexManagerRegistry.getAllInstances()).toEqual([])
113129
const manager = CodeIndexManagerRegistry.getOrCreate(context)

0 commit comments

Comments
 (0)