TestKnownProviderGatesFetch is the regression test for issue #3165: a lookup for a provider the knownProvider predicate rejects (a user-defined custom provider) must resolve locally without ever fetching the models.dev catalog, while a known provider may still trigger a fetch.
(t *testing.T)
| 50 | // provider) must resolve locally without ever fetching the models.dev catalog, |
| 51 | // while a known provider may still trigger a fetch. |
| 52 | func TestKnownProviderGatesFetch(t *testing.T) { |
| 53 | t.Parallel() |
| 54 | |
| 55 | // A cache path that does not exist, so there is no on-disk catalog to fall |
| 56 | // back on — the cold-start situation from the issue. |
| 57 | cacheFile := filepath.Join(t.TempDir(), "models_dev.json") |
| 58 | fetched, fetch := trackingFetcher() |
| 59 | store, err := NewStore( |
| 60 | WithCache(cacheFile), |
| 61 | WithKnownProvider(func(p string) bool { return p == "openai" }), |
| 62 | WithFetcher(fetch), |
| 63 | ) |
| 64 | require.NoError(t, err) |
| 65 | |
| 66 | ctx := expiredContext(t) |
| 67 | |
| 68 | // Custom provider: not known -> resolves locally, no network attempt. |
| 69 | *fetched = false |
| 70 | _, err = store.GetModel(ctx, NewID("mistral_gateway", "mistral-small-latest")) |
| 71 | require.Error(t, err) |
| 72 | assert.False(t, *fetched, "custom provider must not trigger a models.dev fetch") |
| 73 | assert.Contains(t, err.Error(), `provider "mistral_gateway" not found`) |
| 74 | |
| 75 | // Known provider: a cold cache still warrants a fetch — confirming the gate |
| 76 | // did not disable fetching wholesale. The fetch fails here (unreachable |
| 77 | // network) so the lookup falls back to the embedded snapshot. |
| 78 | *fetched = false |
| 79 | _, _ = store.GetModel(ctx, NewID("openai", "gpt-4o")) |
| 80 | assert.True(t, *fetched, "known provider must still fetch the catalog when the cache is cold") |
| 81 | } |
| 82 | |
| 83 | // TestNoPredicateAlwaysAllowsFetch guards the default, backwards-compatible |
| 84 | // behaviour: with no knownProvider predicate every provider may fetch. |
nothing calls this directly
no test coverage detected