MCPcopy Index your code
hub / github.com/docker/docker-agent / TestKnownProviderGatesFetch

Function TestKnownProviderGatesFetch

pkg/modelsdev/store_test.go:52–81  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

50// provider) must resolve locally without ever fetching the models.dev catalog,
51// while a known provider may still trigger a fetch.
52func 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.

Callers

nothing calls this directly

Calls 9

GetModelMethod · 0.95
trackingFetcherFunction · 0.85
WithKnownProviderFunction · 0.85
WithFetcherFunction · 0.85
expiredContextFunction · 0.85
NewIDFunction · 0.85
NewStoreFunction · 0.70
WithCacheFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected