From 01b18dcf32efc48950c85201c143c7cc21b857fb Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Thu, 9 Apr 2026 19:24:55 +0000 Subject: [PATCH] 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 --- v2/request_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/v2/request_test.go b/v2/request_test.go index dfb0d54..7d7989e 100644 --- a/v2/request_test.go +++ b/v2/request_test.go @@ -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) } } + +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) + } +}