Files
magpie/internal/gateway/codex_portable_test.go
T
yetone 19901812e7 gateway: a ported Codex rollout reads the same through magpie as magpie's compaction item did
TestPortedCompactionReadsTheSame: codexInputAs sends the same input for
magpie's item and for the message sessions.PortCodexRollouts writes in its
place, for a magpie model (native or not) and for Codex's own.

Run: go test ./internal/gateway -run TestPortedCompactionReadsTheSame.
2026-10-21 03:05:24 +08:00

36 lines
1.2 KiB
Go

package gateway
import (
"encoding/json"
"reflect"
"testing"
"github.com/yetone/magpie/internal/codexsummary"
)
// A rollout written portable (sessions.PortCodexRollouts) holds, in place
// of magpie's compaction item, the message the gateway sends for it: what
// reaches the model through magpie is the same either way, for a magpie
// model and for Codex's own, natively compacted or not.
func TestPortedCompactionReadsTheSame(t *testing.T) {
enc := codexsummary.Encrypted("Progress: done.\nNext: tests.")
msg, _ := codexsummary.Message(enc)
body := func(item any) []byte {
b, _ := json.Marshal(map[string]any{"model": "gpt-5.4", "input": []any{
userMessage("fix the build"), item, userMessage("go on")}})
return b
}
before := body(map[string]any{"type": "compaction", "id": "cmp_magpie_1", "encrypted_content": enc})
after := body(msg)
for _, c := range []struct{ magpieModel, native bool }{{true, false}, {true, true}, {false, false}} {
a, _ := codexInputAs(before, c.magpieModel, c.native)
b, _ := codexInputAs(after, c.magpieModel, c.native)
var x, y any
json.Unmarshal(a, &x)
json.Unmarshal(b, &y)
if !reflect.DeepEqual(x, y) {
t.Errorf("%+v: magpie's item sent as\n%s\nthe ported message as\n%s", c, a, b)
}
}
}