test(models): cover recovery after empty offline start

Assert the empty catalog path recovers live models and writes a cache once discovery is available again, including the real pi extension entrypoint used by /reload.
This commit is contained in:
Patrick Wozniak
2026-08-02 10:42:31 +02:00
parent 634beb8378
commit e20953d890
2 changed files with 41 additions and 0 deletions
+23
View File
@@ -136,6 +136,29 @@ describe("loadCommandCodeModels()", () => {
})
})
it("recovers live models after an empty offline start", async () => {
await withTemporaryCache(async ({ cachePath }) => {
const empty = await loadCommandCodeModels({
cachePath,
fetchImpl: failingFetch(),
})
assert.equal(empty.source, "empty")
assert.deepEqual(empty.models, [])
const recovered = await loadCommandCodeModels({
cachePath,
fetchImpl: successfulFetch(),
})
assert.deepEqual(recovered, { models: EXPECTED_MODELS, source: "live" })
assert.deepEqual(
commandCodeModelsFromCache(JSON.parse(await readFile(cachePath, "utf-8"))),
EXPECTED_MODELS,
)
})
})
it("ignores a corrupt cache after a failed refresh", async () => {
await withTemporaryCache(async ({ cachePath }) => {
await writeFile(cachePath, "not json", "utf-8")