Files
CLIProxyAPI/internal/runtime/executor/helps/meta_tools_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

89 lines
2.6 KiB
Go

package helps
import (
"testing"
"github.com/MoeForge/moego/ojson"
)
func TestSanitizeMetaWebSearchTools_StripsSearchContentTypesFromWebSearch(t *testing.T) {
input := []byte(`{
"model": "muse-spark-1.3",
"tools": [
{
"type": "function",
"name": "lookup",
"parameters": {"type": "object"}
},
{
"type": "web_search",
"external_web_access": true,
"search_content_types": ["text", "image"]
},
{
"type": "web_search_preview",
"search_content_types": ["text", "image"]
},
{
"type": "namespace",
"name": "search_group",
"tools": [
{
"type": "web_search",
"search_content_types": ["text"]
}
]
}
]
}`)
got := SanitizeMetaWebSearchTools(input)
// web_search at index 1 must have search_content_types stripped
tool1 := ojson.GetBytes(got, "tools.1")
if tool1.Get("type").String() != "web_search" {
t.Fatalf("tools.1 type = %q, want web_search", tool1.Get("type").String())
}
if tool1.Get("search_content_types").Exists() {
t.Fatalf("tools.1 still has search_content_types: %s", tool1.Raw)
}
if !tool1.Get("external_web_access").Bool() {
t.Fatalf("tools.1 external_web_access was lost: %s", tool1.Raw)
}
// web_search_preview at index 2 must retain search_content_types
tool2 := ojson.GetBytes(got, "tools.2")
if tool2.Get("type").String() != "web_search_preview" {
t.Fatalf("tools.2 type = %q, want web_search_preview", tool2.Get("type").String())
}
if !tool2.Get("search_content_types").Exists() {
t.Fatalf("tools.2 search_content_types missing: %s", tool2.Raw)
}
// nested web_search in namespace at index 3 must have search_content_types stripped
nestedTool := ojson.GetBytes(got, "tools.3.tools.0")
if nestedTool.Get("type").String() != "web_search" {
t.Fatalf("tools.3.tools.0 type = %q, want web_search", nestedTool.Get("type").String())
}
if nestedTool.Get("search_content_types").Exists() {
t.Fatalf("tools.3.tools.0 still has search_content_types: %s", nestedTool.Raw)
}
// function tool at index 0 must be unchanged
tool0 := ojson.GetBytes(got, "tools.0")
if tool0.Get("name").String() != "lookup" {
t.Fatalf("tools.0 name = %q, want lookup", tool0.Get("name").String())
}
}
func TestSanitizeMetaWebSearchTools_NoToolsOrEmpty(t *testing.T) {
if got := SanitizeMetaWebSearchTools(nil); len(got) != 0 {
t.Fatalf("expected empty output for nil input, got %s", got)
}
payloadWithoutTools := []byte(`{"model":"muse-spark-1.3","input":"hello"}`)
if got := SanitizeMetaWebSearchTools(payloadWithoutTools); string(got) != string(payloadWithoutTools) {
t.Fatalf("expected unmodified payload, got %s", got)
}
}