Files
sausheong 445614757b fix: support Claude Opus 5 / Sonnet 5 adaptive thinking; unique Gemini tool-call IDs
Anthropic: add claude-opus-5 and claude-sonnet-5 to the adaptive-thinking-only
model list. These models also think by default when the thinking param is
omitted (unlike Fable 5/Mythos/Opus 4.7/4.8), so ReasoningOff now sends an
explicit {type:"disabled"} on them instead of relying on omission.

Gemini: replace the empty-FunctionCall.ID fallback (function name) with a
synthetic toolu_-shaped random ID. The name-based fallback wasn't unique —
repeated calls to the same tool in one conversation collided on one ID,
which produced duplicate tool_use ids if that history was later replayed to
a different (Anthropic) model on a routing switch, rejected with a 400.
2026-07-28 13:40:22 +08:00

56 lines
1.9 KiB
Go

package gemini
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
"github.com/sausheong/harness/llm"
)
func TestGeminiResolveSystemPromptPrefersParts(t *testing.T) {
got := geminiResolveSystemPrompt(llm.ChatRequest{
SystemPrompt: "legacy",
SystemPromptParts: []llm.SystemPromptPart{{Text: "alpha"}, {Text: "beta"}},
})
require.Equal(t, "alpha\nbeta", got)
}
func TestGeminiResolveSystemPromptFallsBackToString(t *testing.T) {
got := geminiResolveSystemPrompt(llm.ChatRequest{SystemPrompt: "only-string"})
require.Equal(t, "only-string", got)
}
func TestGeminiResolveSystemPromptEmpty(t *testing.T) {
got := geminiResolveSystemPrompt(llm.ChatRequest{})
require.Equal(t, "", got)
}
func TestGeminiUsageBuffer_KeepsLast(t *testing.T) {
var last *llm.Usage
last = updateUsage(last, 10, 5)
last = updateUsage(last, 20, 9) // final cumulative
require.NotNil(t, last)
require.Equal(t, 20, last.InputTokens)
require.Equal(t, 9, last.OutputTokens)
}
// TestSyntheticToolCallID_UniqueAndAnthropicShaped guards against the bug
// where an empty Gemini FunctionCall.ID fell back to the function name.
// That fallback isn't a valid provider-neutral tool-call ID shape, and
// worse, it isn't unique: two calls to the same tool (parallel calls, or
// the same tool called again later in a conversation — routine for a
// coding agent re-reading files) collided on one ID. When that history
// was later replayed to Anthropic on a routing switch, the duplicate
// tool_use ids were rejected with a 400.
func TestSyntheticToolCallID_UniqueAndAnthropicShaped(t *testing.T) {
seen := make(map[string]bool)
for range 100 {
id := syntheticToolCallID()
require.True(t, strings.HasPrefix(id, "toolu_"),
"synthetic ID must be shaped like an Anthropic tool_use id so a later replay to Anthropic is accepted")
require.False(t, seen[id], "synthetic IDs must be unique across calls in the same process")
seen[id] = true
}
}