mirror of
https://gh-proxy.org/https://github.com/klinsmaya/CLIProxyAPI.git
synced 2026-11-08 09:26:52 +08:00
- Replaced per-item `sjson.SetRawBytes(out, "input.-1"/"messages.-1", ...)` appends, which reparsed and rewrote the growing output document on every conversation item, causing O(n^2) work on long histories. - Applied the same approach to both interactions translation directions and the OpenAI Responses to Chat Completions path.
24 lines
576 B
Go
24 lines
576 B
Go
package common
|
|
|
|
import "testing"
|
|
|
|
func TestJoinRawArray(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
items [][]byte
|
|
want string
|
|
}{
|
|
{name: "empty", want: "[]"},
|
|
{name: "single", items: [][]byte{[]byte(`{"id":1}`)}, want: `[{"id":1}]`},
|
|
{name: "multiple", items: [][]byte{[]byte(`{"id":1}`), []byte(`{"id":2}`)}, want: `[{"id":1},{"id":2}]`},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
if got := string(JoinRawArray(test.items)); got != test.want {
|
|
t.Fatalf("JoinRawArray() = %s, want %s", got, test.want)
|
|
}
|
|
})
|
|
}
|
|
}
|