MCPcopy Create free account
hub / github.com/docker/docker-agent / TestCache_StorageIsAStopHookBuiltin

Function TestCache_StorageIsAStopHookBuiltin

pkg/runtime/cache_test.go:160–187  ·  view source on GitHub ↗

TestCache_DisabledHasNoEffect verifies that when the agent has no cache attached, every call goes through to the model. TestCache_StorageIsAStopHookBuiltin asserts the architectural contract that the cache_response storage is wired through the new hook system as a stop-hook builtin (not as a hard-co

(t *testing.T)

Source from the content-addressed store, hash-verified

158// a stop-hook builtin (not as a hard-coded runtime call). It is the
159// regression test for the migration to the hooks mechanism.
160func TestCache_StorageIsAStopHookBuiltin(t *testing.T) {
161 t.Parallel()
162
163 c, err := cache.New(cache.Config{Enabled: true})
164 require.NoError(t, err)
165
166 root := agent.New("root", "You are a test agent",
167 agent.WithModel(&messageRecordingProvider{id: "test/mock"}),
168 agent.WithCache(c),
169 )
170 tm := team.New(team.WithAgents(root))
171
172 rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{}))
173 require.NoError(t, err)
174
175 // The runtime should have auto-injected a stop hook of type=builtin
176 // pointing at BuiltinCacheResponse for an agent that has a cache.
177 exec := rt.hooksExec(root)
178 require.NotNil(t, exec, "a cache-enabled agent must have a hooks executor")
179 require.True(t, exec.Has(hooks.EventStop), "cache-enabled agent must have a stop hook")
180
181 // The cache_response builtin must be registered on the runtime's
182 // private hooks registry; that's the seam that lets the closure
183 // reach back to a.Cache() through Input.AgentName.
184 fn, ok := rt.hooksRegistry.LookupBuiltin(BuiltinCacheResponse)
185 require.True(t, ok, "cache_response builtin must be registered")
186 require.NotNil(t, fn)
187}
188
189func TestCache_DisabledHasNoEffect(t *testing.T) {
190 t.Parallel()

Callers

nothing calls this directly

Calls 13

hooksExecMethod · 0.95
NewFunction · 0.92
NewFunction · 0.92
WithModelFunction · 0.92
WithCacheFunction · 0.92
NewFunction · 0.92
WithAgentsFunction · 0.92
NewLocalRuntimeFunction · 0.85
WithSessionCompactionFunction · 0.85
WithModelStoreFunction · 0.85
ContextMethod · 0.80
LookupBuiltinMethod · 0.80

Tested by

no test coverage detected