| package promptcompat |
|
|
| import "testing" |
|
|
| func TestAppendThinkingInjectionToLatestUserStringContent(t *testing.T) { |
| messages := []any{ |
| map[string]any{"role": "user", "content": "older"}, |
| map[string]any{"role": "assistant", "content": "ok"}, |
| map[string]any{"role": "user", "content": "latest"}, |
| } |
|
|
| out, changed := AppendThinkingInjectionToLatestUser(messages) |
| if changed { |
| t.Fatal("expected thinking injection to be disabled") |
| } |
| if len(out) != len(messages) { |
| t.Fatalf("expected messages unchanged, got %#v", out) |
| } |
| } |
|
|
| func TestAppendThinkingInjectionToLatestUserArrayContent(t *testing.T) { |
| messages := []any{ |
| map[string]any{ |
| "role": "user", |
| "content": []any{ |
| map[string]any{"type": "text", "text": "latest"}, |
| }, |
| }, |
| } |
|
|
| out, changed := AppendThinkingInjectionToLatestUser(messages) |
| if changed { |
| t.Fatal("expected thinking injection to be disabled") |
| } |
| if len(out) != len(messages) { |
| t.Fatalf("expected messages unchanged, got %#v", out) |
| } |
| } |
|
|
| func TestAppendThinkingInjectionToLatestUserCustomPrompt(t *testing.T) { |
| messages := []any{ |
| map[string]any{"role": "user", "content": "latest"}, |
| } |
|
|
| out, changed := AppendThinkingInjectionPromptToLatestUser(messages, "custom thinking format") |
| if changed { |
| t.Fatal("expected custom thinking injection to be disabled") |
| } |
| if len(out) != len(messages) { |
| t.Fatalf("expected messages unchanged, got %#v", out) |
| } |
| } |
|
|
| func TestAppendThinkingInjectionToLatestUserSkipsDuplicate(t *testing.T) { |
| messages := []any{ |
| map[string]any{"role": "user", "content": "latest\n\n" + DefaultThinkingInjectionPrompt}, |
| } |
|
|
| out, changed := AppendThinkingInjectionToLatestUser(messages) |
| if changed { |
| t.Fatal("expected thinking injection to be disabled") |
| } |
| if len(out) != 1 { |
| t.Fatalf("unexpected messages: %#v", out) |
| } |
| } |
|
|