Files
go-llm/v2/anthropic/cache_test.go
Steve Dudenhoeffer 4c6dfb9058 test(v2/anthropic): drop placeholder import sentinel from cache_test.go
Removes the blank-assign workaround that was only needed because the
anth import was being kept alive for Task 5's use. Task 5 will bring
the import back when it actually references anth.CacheControlTypeEphemeral.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 19:29:14 +00:00

82 lines
2.7 KiB
Go

package anthropic
import (
"testing"
"gitea.stevedudenhoeffer.com/steve/go-llm/v2/provider"
)
// TestBuildRequest_MultiSystemUsedWhenSystemPresent verifies that after the
// refactor, the Anthropic provider uses MultiSystem (multi-part) rather than
// the flat System string when a system message is present. This is
// behavior-preserving — the upstream client's MarshalJSON prefers
// MultiSystem when both are set.
func TestBuildRequest_MultiSystemUsedWhenSystemPresent(t *testing.T) {
p := New("test-key")
req := provider.Request{
Model: "claude-sonnet-4-6",
Messages: []provider.Message{
{Role: "system", Content: "you are helpful"},
{Role: "user", Content: "hello"},
},
}
anthReq := p.buildRequest(req)
if len(anthReq.MultiSystem) != 1 {
t.Fatalf("expected 1 MultiSystem part, got %d", len(anthReq.MultiSystem))
}
if anthReq.MultiSystem[0].Text != "you are helpful" {
t.Errorf("expected MultiSystem text 'you are helpful', got %q", anthReq.MultiSystem[0].Text)
}
if anthReq.MultiSystem[0].Type != "text" {
t.Errorf("expected MultiSystem type 'text', got %q", anthReq.MultiSystem[0].Type)
}
if anthReq.System != "" {
t.Errorf("expected System string to be empty when MultiSystem is used, got %q", anthReq.System)
}
}
// TestBuildRequest_MultipleSystemMessagesConcatenated verifies that multiple
// system messages are joined into a single MultiSystem part (preserving
// existing newline-joined behavior from the old code).
func TestBuildRequest_MultipleSystemMessagesConcatenated(t *testing.T) {
p := New("test-key")
req := provider.Request{
Model: "claude-sonnet-4-6",
Messages: []provider.Message{
{Role: "system", Content: "part A"},
{Role: "system", Content: "part B"},
{Role: "user", Content: "hello"},
},
}
anthReq := p.buildRequest(req)
if len(anthReq.MultiSystem) != 1 {
t.Fatalf("expected 1 MultiSystem part after concat, got %d", len(anthReq.MultiSystem))
}
expected := "part A\npart B"
if anthReq.MultiSystem[0].Text != expected {
t.Errorf("expected MultiSystem text %q, got %q", expected, anthReq.MultiSystem[0].Text)
}
}
// TestBuildRequest_NoSystemMessage verifies that when there's no system
// message, both System and MultiSystem are empty.
func TestBuildRequest_NoSystemMessage(t *testing.T) {
p := New("test-key")
req := provider.Request{
Model: "claude-sonnet-4-6",
Messages: []provider.Message{
{Role: "user", Content: "hello"},
},
}
anthReq := p.buildRequest(req)
if len(anthReq.MultiSystem) != 0 {
t.Errorf("expected empty MultiSystem when no system message, got %d parts", len(anthReq.MultiSystem))
}
if anthReq.System != "" {
t.Errorf("expected empty System string, got %q", anthReq.System)
}
}