mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-16 22:57:53 +08:00
- 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
49 lines
2.0 KiB
Go
49 lines
2.0 KiB
Go
package helps
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/MoeForge/moego/ojson"
|
|
)
|
|
|
|
func TestEnsureMetaMuseToolNamespacePreservesCallerTools(t *testing.T) {
|
|
input := []byte(`{"input":"hello","tool_choice":"auto","tools":[{"type":"function","name":"muse","parameters":{"type":"object","properties":{"value":{"type":"integer"}}}},{"type":"namespace","name":"client","tools":[{"type":"function","name":"lookup"}]},{"type":"web_search"}]}`)
|
|
original := bytes.Clone(input)
|
|
got := EnsureMetaMuseToolNamespace(input)
|
|
if !ojson.ValidBytes(got) {
|
|
t.Fatalf("invalid JSON: %s", got)
|
|
}
|
|
tools := ojson.GetBytes(got, "tools").Array()
|
|
before := ojson.GetBytes(input, "tools").Array()
|
|
if len(tools) != len(before)+1 {
|
|
t.Fatalf("tool count = %d, want %d", len(tools), len(before)+1)
|
|
}
|
|
namespace := tools[len(before)]
|
|
if namespace.Get("type").String() != "namespace" || namespace.Get("name").String() != "muse" || namespace.Get("tools.0.name").String() != "submit_reminder_decision" {
|
|
t.Fatalf("missing canonical namespace: %s", namespace.Raw)
|
|
}
|
|
for i, tool := range before {
|
|
if tools[i].Raw != tool.Raw {
|
|
t.Fatalf("caller tool %d changed: %s", i, tools[i].Raw)
|
|
}
|
|
}
|
|
if ojson.GetBytes(got, "input").String() != "hello" || ojson.GetBytes(got, "tool_choice").String() != "auto" || !bytes.Equal(input, original) {
|
|
t.Fatal("unrelated fields or caller buffer changed")
|
|
}
|
|
if again := EnsureMetaMuseToolNamespace(got); !bytes.Equal(again, got) {
|
|
t.Fatal("second pass duplicated the namespace")
|
|
}
|
|
}
|
|
|
|
func TestEnsureMetaMuseToolNamespaceLeavesUnrelatedBodiesUnchanged(t *testing.T) {
|
|
for _, input := range []string{
|
|
``, `{"input":"hello"}`, `{"tools":null}`, `{"tools":{}}`, `{"tools":[]}`,
|
|
`{"tools":[{"type":"function","name":"lookup"},{"type":"namespace","name":"muse","description":"caller supplied","tools":[{"type":"function","name":"read_file"}]}]}`,
|
|
} {
|
|
if got := EnsureMetaMuseToolNamespace([]byte(input)); string(got) != input {
|
|
t.Fatalf("body changed: %s -> %s", input, got)
|
|
}
|
|
}
|
|
}
|