Files
CLIProxyAPI/internal/runtime/executor/helps/vertex_payload_helpers_test.go
Luis Pater 6e6afab99a refactor: migrate gjson, sjson, and base64 to MoeForge/moego
- Replace tidwall/gjson and tidwall/sjson with github.com/MoeForge/moego/ojson
  and encoding/base64 with github.com/MoeForge/moego/base64 across the main
  module and examples
- Introduce cross-method *ojson.Doc request rewriting pipelines across
  thinking, signature, client/codex, runtime/executor/helps, pluginhost, and
  all provider executors with FinalizePayloadDoc as the final semantic barrier
- Convert all consecutive JSON mutations (>= 2 Set/SetRaw/Delete operations)
  to batch edits on ojson.Doc
- Upgrade read-only byte paths to ojson.GetBytesNoCopy,
  ojson.GetManyBytesNoCopy, and util.ParseGJSONBytesNoCopy with explicit
  strings.Clone ownership protection across streaming and persistent state
- Use base64.StdEncoding.ValidateString for zero-allocation signature checks
  and base64.EncodeDataURL for single-allocation data URL construction
2026-11-03 03:05:04 +08:00

46 lines
1.8 KiB
Go

package helps
import (
"strings"
"testing"
"github.com/MoeForge/moego/ojson"
)
func TestStripVertexToolCallIDsReusesPayloadWithoutIDs(t *testing.T) {
input := []byte(`{"contents":[{"role":"model","parts":[{"functionCall":{"name":"lookup","args":{"id":9007199254740993}}}]}]}`)
output := StripVertexOpenAIResponsesToolCallIDs(input, "openai-response")
if &output[0] != &input[0] {
t.Fatal("payload without tool call IDs was copied")
}
}
func TestStripVertexToolCallIDsRebuildsContentsOnce(t *testing.T) {
input := []byte(`{"contents":[{"role":"model","parts":[{"functionCall":{"id":"call_1","name":"lookup","args":{"id":9007199254740993}}}]},{"role":"user","parts":[{"functionResponse":{"id":"call_1","name":"lookup","response":{"id":"keep"}}}]}]}`)
output := StripVertexOpenAIResponsesToolCallIDs(input, "openai-response")
if ojson.GetBytes(output, "contents.0.parts.0.functionCall.id").Exists() {
t.Fatal("functionCall.id was not removed")
}
if ojson.GetBytes(output, "contents.1.parts.0.functionResponse.id").Exists() {
t.Fatal("functionResponse.id was not removed")
}
if got := ojson.GetBytes(output, "contents.1.parts.0.functionResponse.response.id").String(); got != "keep" {
t.Fatalf("nested response id = %q, want keep", got)
}
if got := ojson.GetBytes(output, "contents.0.parts.0.functionCall.args.id").Raw; got != "9007199254740993" {
t.Fatalf("large integer = %s, want exact original value", got)
}
}
var benchmarkVertexPayloadOutput []byte
func BenchmarkStripVertexToolCallIDsLargeNoopPayload(b *testing.B) {
input := []byte(`{"contents":[{"role":"user","parts":[{"text":"` + strings.Repeat("x", 8<<20) + `"}]}]}`)
b.ReportAllocs()
b.SetBytes(int64(len(input)))
b.ResetTimer()
for b.Loop() {
benchmarkVertexPayloadOutput = StripVertexOpenAIResponsesToolCallIDs(input, "openai-response")
}
}