qoder: test that a BOM before a stream chunk's body doesn't drop its text
#185 trims a chunk's body before parsing it in events(), and nothing tested it. The envelope carries the BOM JSON-escaped, so the response's own decoding doesn't strip it. Run: bun test packages/qoder: 138 pass, 0 fail. With JSON.parse(inner) back, the new test goes red (1 pass, 1 fail in stream.test.mjs).
This commit is contained in:
@@ -31,3 +31,14 @@ test("the usage after the finish is read", async () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
// #185: a chunk's body led by a BOM (JSON-escaped in the envelope, so the
|
||||
// response's own decoding doesn't strip it) is still read, not skipped.
|
||||
test("a BOM before a chunk's body doesn't drop its text", async () => {
|
||||
const chunk = (content, fr) => JSON.stringify({ choices: [{ delta: { content }, ...(fr ? { finish_reason: fr } : {}), index: 0 }], object: "chat.completion.chunk" })
|
||||
const sse = line("" + chunk("Hi")) + line("" + chunk("", "stop")) + line("[DONE]")
|
||||
const out = []
|
||||
for await (const e of _internal.events(new Response(sse).body)) out.push(e)
|
||||
expect(out.map((e) => e.text).filter(Boolean).join("")).toBe("Hi")
|
||||
expect(out.at(-1)?.stop).toBe("stop")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user