update: sync local changes with latest features

This commit is contained in:
2026-06-22 11:26:25 +07:00
parent 1cf55126f5
commit 98412aa0bb
16 changed files with 491 additions and 33 deletions

View File

@@ -466,4 +466,50 @@ describe("wrapQoderSSE", () => {
const wrapped = wrapQoderSSE(r, "qoder/auto");
expect(wrapped).toBe(r);
});
// Regression: Qoder quota-exceeded returns HTTP 200 with a non-200
// statusCodeValue inside the SSE envelope. The first-chunk peek must
// detect this and return an error Response (not HTTP 200).
it("first-chunk quota error (429 envelope) returns error Response with proper status", async () => {
const errorBody = JSON.stringify({
code: "112",
message: JSON.stringify({ pricingUrl: "https://qoder.com/pricing" }),
});
const env = JSON.stringify({ statusCodeValue: 429, body: errorBody });
const wrapped = await wrapQoderSSE(
makeResponse([`data: ${env}\n\n`], { status: 200 }),
"qoder/qmodel_latest",
);
// Must NOT be 200 — the error should be surfaced as a proper HTTP error
expect(wrapped.status).toBe(429);
expect(wrapped.ok).toBe(false);
const json = await wrapped.json();
expect(json.error.message).toContain("quota exceeded");
});
// Regression: when a mid-stream error arrives after some successful chunks,
// the shared midStreamError object must be populated so that
// handleNonStreamingResponse and buildOnStreamComplete can trigger cooldown.
it("mid-stream error populates the shared midStreamError object", async () => {
const goodInner = JSON.stringify({ choices: [{ delta: { content: "hi" } }] });
const goodEnv = JSON.stringify({ statusCodeValue: 200, body: goodInner });
const errorBody = JSON.stringify({
code: "112",
message: JSON.stringify({ pricingUrl: "https://qoder.com/pricing" }),
});
const errorEnv = JSON.stringify({ statusCodeValue: 429, body: errorBody });
const midStreamError = {};
const wrapped = await wrapQoderSSE(
makeResponse([`data: ${goodEnv}\n\ndata: ${errorEnv}\n\n`], { status: 200 }),
"qoder/qmodel_latest",
midStreamError,
);
await drain(wrapped);
expect(midStreamError.error).toBeDefined();
expect(midStreamError.error.status).toBe(429);
expect(midStreamError.error.message).toContain("quota exceeded");
expect(midStreamError.error.errorCode).toBe("112");
});
});