Files
plugins/packages/devin/gzip-request.test.mjs
T
Jinx 4fd68ba046 devin: gzip a Connect request frame past 8 KiB, as the devin CLI does (#275, BGMYE)
Devin's nginx turns a GetChatMessage body past 10 MiB away with 413, so a
long turn failed. A Connect frame's message is now gzipped (flag 1,
Connect-Content-Encoding: gzip) past 8 KiB, as the devin CLI sends it.

Review commit da6c664 on top of 05d8a65, from the official client: the
devin CLI 3000.11.92, run in a sandbox through a logging proxy, sends 8,083
bytes plain and 8,333 gzipped, names the encoding only on a gzipped frame,
and sends no Connect-Accept-Encoding. The PR's 64 KiB threshold, header on
every request and Connect-Accept-Encoding were changed to match.

Run at da6c664fa917ee995a10a457a10fb94ad743e8ab: bun test in packages/devin,
98 pass 0 fail; bun scripts/check.mjs devin ok. The new tests are red on
main f906a22 (3 fail) and on 05d8a65 (3 fail). Live, owner's account,
swe-1-6: a 12 MiB plain frame gets 413, gzipped it passes nginx (the model
then refuses the size); complete() with a short and a >64 KiB message both
200.
2026-10-21 00:21:16 +08:00

61 lines
2.3 KiB
JavaScript

// Devin's nginx turns away a request body past 10 MiB on the wire (413
// Request Entity Too Large), so a long turn goes gzipped, a short one as it
// was, at the size the devin CLI gzips from (8,083 bytes plain, 8,333
// gzipped, captured from 3000.11.92).
import { expect, test } from "bun:test"
import { gunzipSync } from "node:zlib"
import { _internal } from "./index.mjs"
const unframe = (b) => ({ flags: b[0], data: b.subarray(5, 5 + new DataView(b.buffer, b.byteOffset).getUint32(1)) })
test("a short message goes as it is", () => {
const msg = new TextEncoder().encode("hi")
const { flags, data } = unframe(_internal.frame(msg))
expect(flags).toBe(0)
expect([...data]).toEqual([...msg])
})
test("the CLI's sizes: 8,083 bytes go as they are, 8,333 gzipped", () => {
expect(unframe(_internal.frame(new Uint8Array(8083))).flags).toBe(0)
expect(unframe(_internal.frame(new Uint8Array(8333))).flags).toBe(1)
})
test("a long message goes gzipped, and inflates to itself", () => {
const msg = new TextEncoder().encode("x".repeat(12 << 20))
const out = _internal.frame(msg)
const { flags, data } = unframe(out)
expect(flags).toBe(1)
expect(out.length).toBeLessThan(1 << 20)
expect(Buffer.from(gunzipSync(data)).equals(Buffer.from(msg))).toBe(true)
})
const sent = async (content) => {
let seen
const was = globalThis.fetch
globalThis.fetch = async (url, init) => {
seen = init
return new Response("{}", { status: 400 })
}
try {
await _internal.complete({ key: "k", server: "https://devin.test", families: [] }, { model: "swe-2", messages: [{ role: "user", content }] })
} finally {
globalThis.fetch = was
}
return seen
}
test("a long chat request is gzipped and says so", async () => {
const seen = await sent("y".repeat(200 << 10))
expect(seen.headers["Connect-Content-Encoding"]).toBe("gzip")
expect(unframe(seen.body).flags).toBe(1)
// the CLI asks for no encoding of the reply; Devin gzips it anyway
expect(seen.headers["Connect-Accept-Encoding"]).toBeUndefined()
})
test("a short chat request names no encoding, as the CLI's doesn't", async () => {
const seen = await sent("hi")
expect(unframe(seen.body).flags).toBe(0)
expect(seen.headers["Connect-Content-Encoding"]).toBeUndefined()
expect(seen.headers["Connect-Accept-Encoding"]).toBeUndefined()
})