| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/provider" |
| 9 | ) |
| 10 | |
| 11 | func TestEstimateMessagesTokensOmitsEncryptedSearchRaw(t *testing.T) { |
| 12 | visible := provider.ServerSearchCall{ |
| 13 | ID: "s1", Query: "q", |
| 14 | Results: []provider.ServerSearchHit{{Title: "T", URL: "https://a.example"}}, |
| 15 | } |
| 16 | withRaw := []provider.Message{{ |
| 17 | Role: provider.RoleAssistant, Content: "answer", |
| 18 | ServerSearch: []provider.ServerSearchCall{{ |
| 19 | ID: visible.ID, Query: visible.Query, Results: visible.Results, |
| 20 | Raw: json.RawMessage(strings.Repeat("E", 50_000)), |
| 21 | }}, |
| 22 | }} |
| 23 | withoutRaw := []provider.Message{{ |
| 24 | Role: provider.RoleAssistant, |
| 25 | Content: "answer", |
| 26 | ServerSearch: []provider.ServerSearchCall{visible}, |
| 27 | }} |
| 28 | if got, want := estimateMessagesTokens(withRaw), estimateMessagesTokens(withoutRaw); got != want { |
| 29 | t.Fatalf("estimateMessagesTokens with raw = %d, without = %d", got, want) |
| 30 | } |
| 31 | if estimateSamplingRequestInputTokens(provider.Request{Messages: withRaw}) != estimateSamplingRequestInputTokens(provider.Request{Messages: withoutRaw}) { |
| 32 | t.Fatal("interrupted-usage estimate counted encrypted search raw") |
| 33 | } |
| 34 | } |
| 35 |