gateway tests: a flipped byte in the kept-body test is one that changes the body

TestKeptBodyIsOnlyItsCallers flipped the byte at the middle of a dcz body
and expected a 400. Which byte that is depends on the package's .go files
newAgentChat reads as the conversation, and with plugin_credits_last_test.go
added the middle byte fell on bits zstd doesn't read: the body decoded to the
same request, matched its digest and was rightly passed on (200, reached 2,
3 of 3 on mote; 0 of 3 on origin/main 9bf5848c1 without the new file). The
case now takes the first byte from the middle on whose flip changes what it
decodes to.

Run: go test -count=3 -run TestKeptBodyIsOnlyItsCallers ./internal/gateway
on mote, ok.

At the stack's head (tree 5e30adbc6) on mote: GOOS=linux go vet -tags
nogui ./... and GOOS=windows go vet ./... ok; go test -timeout 45m
./internal/gateway ./internal/provider ./internal/plugin ./internal/routes:
provider, plugin, routes ok; gateway red only on
TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes, red on origin/main
9bf5848c1 too (#7117).
This commit is contained in:
yetone
2026-11-19 17:26:38 +08:00
parent 504db2206e
commit e2e8ea253b
+24 -1
View File
@@ -413,7 +413,7 @@ func TestKeptBodyIsOnlyItsCallers(t *testing.T) {
{"no key", "", "10.0.0.2:1", z, dz},
{"another computer", "keyA", "10.0.0.3:1", z, dz},
{"a corrupt body", "keyA", "10.0.0.2:1", append(slices.Clone(z[:len(z)/2]), 0xff, 0xff, 0xff), dz},
{"a flipped byte", "keyA", "10.0.0.2:1", func() []byte { b := slices.Clone(z); b[len(b)/2] ^= 0x40; return b }(), dz},
{"a flipped byte", "keyA", "10.0.0.2:1", flipped(t, z, first, next), dz},
{"another digest", "keyA", "10.0.0.2:1", z, map[string]string{"Content-Encoding": "dcz", availableDictHeader: sfBinary(sum), BodyDigestHeader: sfBinary(sha256.Sum256(first))}},
{"no digest", "keyA", "10.0.0.2:1", z, map[string]string{"Content-Encoding": "dcz", availableDictHeader: sfBinary(sum)}},
} {
@@ -440,6 +440,29 @@ func TestKeptBodyIsOnlyItsCallers(t *testing.T) {
}
}
// flipped is z with one byte from its middle on flipped where the flip
// changes what it decodes to: a bit zstd doesn't read (a table entry no
// symbol uses) decodes to the same body, which is rightly passed on, so
// which byte that is depends on the package's sources newAgentChat reads.
func flipped(t *testing.T, z, dict, want []byte) []byte {
t.Helper()
for i := len(z) / 2; i < len(z); i++ {
b := slices.Clone(z)
b[i] ^= 0x40
r, err := dczReader(bytes.NewReader(b), dict)
if err != nil {
return b
}
got, err := io.ReadAll(r)
r.Close()
if err != nil || !bytes.Equal(got, want) {
return b
}
}
t.Fatal("no byte past the middle changes the body")
return nil
}
// A magpie keeps no more than dictPerScope bodies of a caller, nor more
// than its bounds in bytes, the least lately used going first.
func TestKeptBodiesBounded(t *testing.T) {