qoder: a trimmed or wrapped 10605 is busy, not a lapsed sign-in (#185)

`failure` parses the trimmed body, so a BOM-prefixed 10605 (the SSE envelope carries it as a JSON-escaped U+FEFF that `res.text()` doesn't strip) keeps its 503/Retry-After instead of reading as a lapsed sign-in. An outer body with no code, or code 401/403, whose message is a 10605 body is unwrapped to it; explicit 105/110/406 codes stay authoritative, and malformed or array messages are not unwrapped. Refs #167, #181.

What was run at c9e39e0 (reviewer, bun 1.4.2, macOS):
- bun test packages/qoder: 137 pass, 0 fail. bun scripts/check.mjs qoder: ok.
- Broken by hand: without the unwrap, the 8 wrapper tests go red; parsing `text` instead of the trimmed `msg`, the BOM test goes red; unwrapping regardless of the outer code, the explicit-code test goes red. The `inner.trim()` in events() had no test; a follow-up commit adds one.
- magpie (yetone/magpie main 85eef5d87) in a sandbox HOME, a copy of this package with api3/openapi pointed at a local fake, a planted plugin-auth.json, `magpie provider test qoder`: a 403 `{"code":403,"message":<10605 body>}`, the SSE `{"message":<10605 body>}` envelope and a BOM-prefixed 403 each gave 503 "Qoder is busy for efficient (this plan's queue: p3); try again in 30s"; a 105 still gave 401 lapsed. main's package gave 401 lapsed for the first two.
- Not tried: real Qoder accounts.
This commit is contained in:
lokic7123-star
2026-10-17 17:54:35 +08:00
committed by GitHub
parent a73237c74c
commit 656f3a1fb5
2 changed files with 47 additions and 4 deletions
+33
View File
@@ -78,3 +78,36 @@ test("Qoder's other codes on a 403 aren't a lapsed sign-in either; 105 and no co
expect(f("105", "login expired")).toEqual({ status: 401, message: "the sign-in lapsed — sign in again (Qoder said 403: login expired)" })
expect(_internal.failure(403, "")).toEqual({ status: 401, message: "the sign-in lapsed — sign in again" })
})
test("a BOM in an SSE error body must not turn a resource limit into expired auth", async () => {
const { fetch, sets } = await chat(() => sse({headers:{},body:"\uFEFF"+QUEUED,statusCodeValue:403,statusCode:"FORBIDDEN"}))
expect(await busy(await fetch(API_CHAT,ASK))).toEqual(WANT)
expect(sets).toEqual([])
})
// #167 lists these outer message wrappers as additional ways a structured
// busy response can still reach the sign-in fallback. They are synthetic
// wrappers of the saved upstream queue fixture, not captured live bytes.
for (const [label, outer] of [
["message only", { message: QUEUED }],
["null code", { code: null, message: QUEUED }],
["HTTP code", { code: 403, message: QUEUED }],
["empty queue", { queue: {}, message: QUEUED }],
]) for (const stream of [false, true]) {
test(`a ${label} wrapper preserves the resource failure (SSE=${stream})`, async () => {
const { fetch, sets } = await chat(() => stream
? sse({ headers: {}, body: JSON.stringify(outer), statusCodeValue: 403, statusCode: "FORBIDDEN" })
: new Response(JSON.stringify(outer), { status: 403, headers: { "Content-Type": "application/json" } }))
expect(await busy(await fetch(API_CHAT, ASK))).toEqual(WANT)
expect(sets).toEqual([])
})
}
test("an explicit authentication, credit or request code is not replaced by text inside it", () => {
for (const [code, status] of [["105", 401], ["110", 429], ["406", 400]]) {
expect(_internal.failure(403, JSON.stringify({ code, message: QUEUED })).status).toBe(status)
}
expect(_internal.failure(403, JSON.stringify({ message: '{"code":"10605"' })).status).toBe(401)
expect(_internal.failure(403, JSON.stringify({ message: '[{"code":"10605"}]' })).status).toBe(401)
expect(_internal.failure(403, JSON.stringify({ message: JSON.stringify({ code: "110", message: "credits" }) })).status).toBe(401)
})