(t *testing.T)
| 331 | } |
| 332 | |
| 333 | func TestFallbackCooldownState(t *testing.T) { |
| 334 | t.Parallel() |
| 335 | |
| 336 | synctest.Test(t, func(t *testing.T) { |
| 337 | mockModel := &mockProvider{id: "test/model", stream: newStreamBuilder().AddContent("ok").AddStopWithUsage(1, 1).Build()} |
| 338 | tm := team.New(team.WithAgents( |
| 339 | agent.New("test-agent", "test instruction", agent.WithModel(mockModel)), |
| 340 | )) |
| 341 | rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{})) |
| 342 | require.NoError(t, err) |
| 343 | |
| 344 | agentName := "test-agent" |
| 345 | |
| 346 | // Initially no cooldown |
| 347 | assert.Nil(t, rt.fallback.cooldowns.Get(agentName), "should have no cooldown initially") |
| 348 | |
| 349 | // Fake clock so cooldown expiry needs no sleeping. |
| 350 | current := time.Now() |
| 351 | rt.fallback.cooldowns.now = func() time.Time { return current } |
| 352 | |
| 353 | // Set cooldown with short duration for testing |
| 354 | rt.fallback.cooldowns.Set(agentName, 0, 100*time.Millisecond) |
| 355 | state := rt.fallback.cooldowns.Get(agentName) |
| 356 | require.NotNil(t, state, "should have cooldown state") |
| 357 | assert.Equal(t, 0, state.fallbackIndex) |
| 358 | |
| 359 | // Advance fake time past the cooldown |
| 360 | current = current.Add(101 * time.Millisecond) |
| 361 | assert.Nil(t, rt.fallback.cooldowns.Get(agentName), "cooldown should have expired") |
| 362 | |
| 363 | // Set cooldown again and then clear it |
| 364 | rt.fallback.cooldowns.Set(agentName, 1, 1*time.Hour) |
| 365 | require.NotNil(t, rt.fallback.cooldowns.Get(agentName)) |
| 366 | |
| 367 | rt.fallback.cooldowns.Clear(agentName) |
| 368 | assert.Nil(t, rt.fallback.cooldowns.Get(agentName), "cooldown should be cleared") |
| 369 | }) |
| 370 | } |
| 371 | |
| 372 | func TestGetEffectiveCooldown(t *testing.T) { |
| 373 | t.Parallel() |
nothing calls this directly
no test coverage detected