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

47 lines
2.5 KiB
Go

package helps
import (
"context"
"testing"
"github.com/MoeForge/moego/ojson"
"github.com/router-for-me/CLIProxyAPI/v8/internal/clienterror"
sdktranslator "github.com/router-for-me/CLIProxyAPI/v8/sdk/translator"
)
// A turn that only holds a file the target cannot receive is refused with a named
// 400, through both the single and the pair translation, with and without compat.
func TestClaudeContainerUploadReturns400(t *testing.T) {
payload := []byte(`{"messages":[{"role":"user","content":[{"type":"container_upload","file_id":"file-example"}]}]}`)
for _, to := range []sdktranslator.Format{sdktranslator.FormatGemini, sdktranslator.FormatOpenAI, sdktranslator.FormatCodex, sdktranslator.FormatInteractions} {
for _, compat := range []bool{false, true} {
_, single := TranslateRequestReturningError(context.Background(), nil, nil, sdktranslator.FormatClaude, to, "m", payload, false, compat)
_, _, pair := TranslateRequestPairReturningError(context.Background(), nil, nil, sdktranslator.FormatClaude, to, "m", payload, payload, false, compat)
for name, err := range map[string]error{"single": single, "pair": pair} {
if err == nil || err.Error() != "unsupported content part: container_upload" || clienterror.HTTPStatusFromError(err) != 400 {
t.Errorf("to=%s compat=%v %s: err = %v, want a 400 naming container_upload", to, compat, name, err)
}
}
}
}
}
// TestByteWrappersKeepAJSONBodyForAnUnsendableFile guards the executors that still
// ignore the error: they must get a request body, never an empty one.
func TestByteWrappersKeepAJSONBodyForAnUnsendableFile(t *testing.T) {
payload := []byte(`{"model":"m","messages":[{"role":"user","content":[{"type":"container_upload","file_id":"file-absent"}]}]}`)
for _, to := range []sdktranslator.Format{sdktranslator.FormatOpenAI, sdktranslator.FormatCodex, sdktranslator.FormatInteractions, sdktranslator.FormatGemini} {
for _, compat := range []bool{false, true} {
original, working := TranslateRequestPairWithAPIKeyModelCompatibility(context.Background(), nil, nil, sdktranslator.FormatClaude, to, "m", payload, payload, false, compat)
for _, body := range [][]byte{original, working} {
if !ojson.ValidBytes(body) || len(body) < 2 {
t.Fatalf("to=%s compat=%v: body = %q", to, compat, body)
}
}
if _, _, err := TranslateRequestPairReturningError(context.Background(), nil, nil, sdktranslator.FormatClaude, to, "m", payload, payload, false, compat); err == nil {
t.Fatalf("to=%s compat=%v: the checked variant lost the error", to, compat)
}
}
}
}