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)
| 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. |
| 160 | func 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 | |
| 189 | func TestCache_DisabledHasNoEffect(t *testing.T) { |
| 190 | t.Parallel() |
nothing calls this directly
no test coverage detected