1package provider
2
3import "testing"
4
5func TestSystemWithDeveloperContextSeparatesStableAndDynamicText(t *testing.T) {
6 stable, dynamic, messages := systemWithDeveloperContext(Request{
7 System: "stable instructions",
8 SystemContext: "legacy host context",
9 Messages: []Message{
10 {Role: RoleDeveloper, Content: []Content{TextBlock{Text: "dynamic host context"}}},
11 {Role: RoleUser, Content: []Content{TextBlock{Text: "user task"}}},
12 },
13 })
14 if stable != "stable instructions" {
15 t.Fatalf("stable = %q", stable)
16 }
17 if dynamic != "legacy host context\n\ndynamic host context" {
18 t.Fatalf("dynamic = %q", dynamic)
19 }
20 if len(messages) != 1 || messages[0].Role != RoleUser {
21 t.Fatalf("messages = %#v, want only the user task", messages)
22 }
23}
24
25func TestAnthropicDeveloperContextFollowsStableCacheBoundary(t *testing.T) {
26 req, err := (&anthropicClient{}).buildRequest(Request{
27 Model: "claude-sonnet-4-5",
28 System: "stable instructions",
29 Messages: []Message{
30 {Role: RoleDeveloper, Content: []Content{TextBlock{Text: "dynamic host context"}}},
31 {Role: RoleUser, Content: []Content{TextBlock{Text: "user task"}}},
32 },
33 })
34 if err != nil {
35 t.Fatal(err)
36 }
37 if len(req.System) != 2 || req.System[0].Text != "stable instructions" || req.System[0].CacheControl == nil || req.System[1].Text != "dynamic host context" || req.System[1].CacheControl != nil {
38 t.Fatalf("system blocks = %#v", req.System)
39 }
40}
41
42func TestOpenAICompatUsesSystemRoleForDeepSeekDeveloperContext(t *testing.T) {
43 tests := []struct {
44 name string
45 client *openaiClient
46 model string
47 want string
48 }{
49 {name: "direct DeepSeek", client: NewDeepSeek("key", "").(*openaiClient), model: "deepseek-v4-flash", want: "system"},
50 {name: "OpenCode Go DeepSeek", client: NewOpenAICompat(ProviderOpenCodeGo, "key", "https://example.test/v1", "").(*openaiClient), model: "deepseek/deepseek-v4.1-flash", want: "system"},
51 {name: "OpenCode Go other model", client: NewOpenAICompat(ProviderOpenCodeGo, "key", "https://example.test/v1", "").(*openaiClient), model: "other/model", want: "developer"},
52 }
53 for _, test := range tests {
54 t.Run(test.name, func(t *testing.T) {
55 req, err := test.client.buildRequest(Request{
56 Model: test.model,
57 Messages: []Message{
58 {Role: RoleDeveloper, Content: []Content{TextBlock{Text: "dynamic host context"}}},
59 {Role: RoleUser, Content: []Content{TextBlock{Text: "user task"}}},
60 },
61 })
62 if err != nil {
63 t.Fatal(err)
64 }
65 if len(req.Messages) != 2 || req.Messages[0].Role != test.want || req.Messages[0].Content != "dynamic host context" {
66 t.Fatalf("messages = %#v, want developer context as %q", req.Messages, test.want)
67 }
68 })
69 }
70}
71
72func TestBedrockDeveloperContextFollowsStableCacheBoundary(t *testing.T) {
73 req, err := (&bedrockClient{region: "us-east-1"}).buildRequest(Request{
74 Model: "anthropic.claude-sonnet-4-5-20250929-v1:0",
75 System: "stable instructions",
76 Messages: []Message{
77 {Role: RoleDeveloper, Content: []Content{TextBlock{Text: "dynamic host context"}}},
78 {Role: RoleUser, Content: []Content{TextBlock{Text: "user task"}}},
79 },
80 })
81 if err != nil {
82 t.Fatal(err)
83 }
84 if len(req.System) != 3 || req.System[0]["text"] != "stable instructions" || req.System[1]["cachePoint"] == nil || req.System[2]["text"] != "dynamic host context" {
85 t.Fatalf("system blocks = %#v", req.System)
86 }
87}