TestColdCacheFallsBackToSnapshot verifies the new behaviour: when the cache is cold and the network is unreachable, a known-provider lookup resolves against the embedded snapshot instead of erroring out.
(t *testing.T)
| 69 | // is cold and the network is unreachable, a known-provider lookup resolves |
| 70 | // against the embedded snapshot instead of erroring out. |
| 71 | func TestColdCacheFallsBackToSnapshot(t *testing.T) { |
| 72 | t.Parallel() |
| 73 | |
| 74 | cacheFile := filepath.Join(t.TempDir(), "models_dev.json") |
| 75 | fetched, fetch := trackingFetcher() |
| 76 | store, err := NewStore(WithCache(cacheFile), WithFetcher(fetch)) |
| 77 | require.NoError(t, err) |
| 78 | |
| 79 | // gpt-4o is present in the embedded snapshot; the fetch fails, so the |
| 80 | // resolution must come from the snapshot. |
| 81 | m, err := store.GetModel(t.Context(), NewID("openai", "gpt-4o")) |
| 82 | require.NoError(t, err) |
| 83 | assert.True(t, *fetched, "a cold cache must still attempt a fetch first") |
| 84 | assert.NotEmpty(t, m.Name) |
| 85 | } |
| 86 | |
| 87 | // TestSnapshotFallbackIsNotMemoized guards against pinning the embedded |
| 88 | // fallback for the Store's lifetime: a transient fetch failure must degrade to |
nothing calls this directly
no test coverage detected