test(v2): cover empty-messages and disabled-but-non-nil cacheConfig edges

Adds two boundary tests suggested by code review:
- TestBuildProviderRequest_CachingEnabled_EmptyMessages: verifies
  that caching with an empty message list still emits a CacheHints
  with LastCacheableMessageIndex=-1, not a spurious breakpoint.
- TestBuildProviderRequest_CachingNonNilButDisabled: verifies that
  an explicitly-disabled cacheConfig (non-nil, enabled=false)
  produces nil CacheHints, exercising the &&-guard branch that
  the previous "disabled" test left untested.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-09 19:24:55 +00:00
parent 4b401fcc0d
commit 01b18dcf32

View File

@@ -240,3 +240,26 @@ func TestBuildProviderRequest_CachingEnabled_OnlySystem(t *testing.T) {
t.Errorf("expected LastCacheableMessageIndex=-1 when no non-system messages, got %d", req.CacheHints.LastCacheableMessageIndex) t.Errorf("expected LastCacheableMessageIndex=-1 when no non-system messages, got %d", req.CacheHints.LastCacheableMessageIndex)
} }
} }
func TestBuildProviderRequest_CachingEnabled_EmptyMessages(t *testing.T) {
cfg := &requestConfig{cacheConfig: &cacheConfig{enabled: true}}
req := buildProviderRequest("m", nil, cfg)
if req.CacheHints == nil {
t.Fatal("expected CacheHints to be set even with no messages")
}
if req.CacheHints.CacheSystem {
t.Error("expected CacheSystem=false with no messages")
}
if req.CacheHints.LastCacheableMessageIndex != -1 {
t.Errorf("expected LastCacheableMessageIndex=-1 with no messages, got %d", req.CacheHints.LastCacheableMessageIndex)
}
}
func TestBuildProviderRequest_CachingNonNilButDisabled(t *testing.T) {
cfg := &requestConfig{cacheConfig: &cacheConfig{enabled: false}}
msgs := []Message{SystemMessage("sys"), UserMessage("hi")}
req := buildProviderRequest("m", msgs, cfg)
if req.CacheHints != nil {
t.Errorf("expected nil CacheHints when cacheConfig.enabled=false, got %+v", req.CacheHints)
}
}