mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 10:52:17 +03:00
Rebased onto the tip and completed, per the maintainer's call to finish the wiring rather than merge the capability alone. What changed since your version: The tip had already cleared the TS2554 by deleting the 16th argument, leaving a comment that the highWaterMark stays at the helper default. So the base-red you found is gone, but the 64 KB #12179 asked for was still not applied and your new parameter had no caller. glm.ts now passes it, which is what turns the capability into the fix. Your test file also hung the runner: every stream createSSEStream builds arms a 10s idle watchdog via setInterval in start, and nothing cancelled them, so node:test waited on a non-empty event loop long after the assertions passed. Cancelling each readable in an after hook runs the cancel handler that clears the timer — the file now reports in about 7 seconds. Worth knowing for future stream tests. Your five assertions are unchanged and all pass. Reading the writable's desiredSize to measure the queue budget the stream was actually built with, rather than standing in for it, is the detail that makes this testable at all — and the 0-budget case pinning `??` against `||` is the kind of thing that silently rots otherwise. Thank you also for separating your own red checks from the base's and reporting what you found there. That is how #12919's identical failures got explained instead of chased.
97 lines
3.0 KiB
TypeScript
97 lines
3.0 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
createSSEStream,
|
|
createSSETransformStreamWithLogger,
|
|
} from "../../open-sse/utils/stream.ts";
|
|
import { FORMATS } from "../../open-sse/translator/formats.ts";
|
|
|
|
// A TransformStream's writable queue starts with `desiredSize === highWaterMark`,
|
|
// so reading it off a fresh writer measures the queue budget the stream was
|
|
// actually built with rather than standing in for it.
|
|
// Each stream arms a 10s idle watchdog (setInterval in createSSEStream's start).
|
|
// Cancelling the readable runs the TransformStream's cancel handler, which clears
|
|
// it — without this the node:test runner never sees an empty event loop and the
|
|
// file hangs after the assertions have already passed.
|
|
const openStreams: TransformStream[] = [];
|
|
|
|
const writableBudget = (transform: TransformStream) => {
|
|
openStreams.push(transform);
|
|
return transform.writable.getWriter().desiredSize;
|
|
};
|
|
|
|
test.after(async () => {
|
|
for (const transform of openStreams) {
|
|
await transform.readable.cancel().catch(() => {});
|
|
}
|
|
});
|
|
|
|
const DEFAULT = 16384;
|
|
|
|
test.describe("SSE stream buffer budget", () => {
|
|
test("defaults to the 16 KB every provider used before it was configurable", () => {
|
|
const transform = createSSEStream({
|
|
targetFormat: FORMATS.CLAUDE,
|
|
sourceFormat: FORMATS.OPENAI,
|
|
});
|
|
|
|
assert.equal(writableBudget(transform), DEFAULT);
|
|
});
|
|
|
|
test("createSSEStream honours an explicit budget", () => {
|
|
const transform = createSSEStream({
|
|
targetFormat: FORMATS.CLAUDE,
|
|
sourceFormat: FORMATS.OPENAI,
|
|
streamBufferBytes: 65536,
|
|
});
|
|
|
|
assert.equal(writableBudget(transform), 65536);
|
|
});
|
|
|
|
// The defect this pins: glm.ts has passed a 16th positional argument since
|
|
// #12179, and the signature stopped at 15. It was a type error, and the value
|
|
// was dropped — the 64 KB that call site asks for never reached the queue.
|
|
// These are the exact 16 arguments glm.ts passes.
|
|
test("the convenience wrapper carries a 16th positional budget through", () => {
|
|
const transform = createSSETransformStreamWithLogger(
|
|
FORMATS.CLAUDE,
|
|
FORMATS.OPENAI,
|
|
"zai",
|
|
null,
|
|
null,
|
|
"glm-4.6",
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
false,
|
|
false,
|
|
undefined,
|
|
undefined,
|
|
65536
|
|
);
|
|
|
|
assert.equal(writableBudget(transform), 65536);
|
|
});
|
|
|
|
test("the wrapper still defaults when no budget is given", () => {
|
|
const transform = createSSETransformStreamWithLogger(FORMATS.CLAUDE, FORMATS.OPENAI);
|
|
|
|
assert.equal(writableBudget(transform), DEFAULT);
|
|
});
|
|
|
|
test("a budget of 0 is honoured rather than treated as absent", () => {
|
|
// `?? DEFAULT` and `|| DEFAULT` differ here, and 0 is a legitimate
|
|
// highWaterMark: it makes the queue apply backpressure immediately.
|
|
const transform = createSSEStream({
|
|
targetFormat: FORMATS.CLAUDE,
|
|
sourceFormat: FORMATS.OPENAI,
|
|
streamBufferBytes: 0,
|
|
});
|
|
|
|
assert.equal(writableBudget(transform), 0);
|
|
});
|
|
});
|