From fff0755b581debb5373a43364e882e770cd15e28 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 16 Nov 2026 06:01:50 +0800 Subject: [PATCH] gateway: TestPassthroughResponsesBigLastEvent leaves a held stream's keepalive out of its comparison On macOS CI at 2d106b5c1 (job 132940460364) the test failed with "200, 17 bytes added" after taking 5.83s. That is past keepHeldEvery (5s), so the held stream's agent got one ": keepalive\n" comment. A comment at the start of a line is no change to the reply, and every SSE client skips it. The "17" was itself wrong. The message counted against the raw reply, not the expected one, which has "m1" renamed to "fake/m1" (5 more bytes). The real difference was 12 bytes, exactly one keepalive line. The test now drops only keepalive comments at a line's start, then compares byte for byte. When it fails, it names the byte where the bodies part and what is there on each side. Run (mote, at origin/main e34228669): - Probe that sets keepaliveEvery and keepHeldEvery to 1ms and keepHeldAfter to 0, then calls the test. The old test was red 3 of 3 with CI's exact message ("17 bytes added"). The new test was green 3 of 3. A slowly streamed variant counted 1 keepalive and 12 bytes extra, and its body equals the expected one once the keepalive is dropped. The probe is not committed. - go vet ./internal/gateway: ok. - go test ./internal/gateway -run 'Passthrough|Severed|CutMidLine|CutAfter': ok. Not run: the whole gateway package or the full suite. This is a change to one test's comparison, with no product code touched. --- internal/gateway/passthrough_severed_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/gateway/passthrough_severed_test.go b/internal/gateway/passthrough_severed_test.go index 9ad7f551f..8fbec9a21 100644 --- a/internal/gateway/passthrough_severed_test.go +++ b/internal/gateway/passthrough_severed_test.go @@ -7,6 +7,7 @@ import ( "io" "net/http" "net/http/httptest" + "regexp" "strings" "testing" @@ -291,8 +292,16 @@ func TestPassthroughResponsesBigLastEvent(t *testing.T) { f := &fake{reply: reply} setup(t, "responses", f) code, body := post(t, "/v1/responses", `{"model":"fake/m1","stream":true,"input":"hi"}`) - if code != 200 || body != namedAs(reply, "fake/m1") { - t.Fatalf("a whole stream with a big last event was changed: %d, %d bytes added", code, len(body)-len(reply)) + // a stream held past keepHeldEvery (5s; 5.83s on macOS CI at + // 2d106b5c1) has its agent kept alive with a comment at a line's + // start, which is no change to the reply: only those are left out + kept := regexp.MustCompile(`(?m)^: keepalive\n`).ReplaceAllString(body, "") + if want := namedAs(reply, "fake/m1"); code != 200 || kept != want { + i := 0 + for i < len(kept) && i < len(want) && kept[i] == want[i] { + i++ + } + t.Fatalf("a whole stream with a big last event was changed: %d, %d bytes added; from byte %d it has %q where it should have %q", code, len(kept)-len(want), i, kept[i:min(len(kept), i+80)], want[i:min(len(want), i+80)]) } }