Skip to content

Commit 5ac4e51

Browse files
test(api): cover the non-abort path of the qwen-code 401 retry
Closes the remaining changed-line gap in qwen-code.ts: a 401 whose retry fails with a non-abort error must be rethrown unchanged (the abort check's false branch).
1 parent c235479 commit 5ac4e51

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/api/providers/__tests__/qwen-code-native-tools.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,26 @@ describe("QwenCodeHandler Native Tools", () => {
696696
expect((caught as Error).message).not.toBe("Request was aborted.") // not the raw SDK error
697697
expect(mockCreate).toHaveBeenCalledTimes(2) // first attempt 401, then the aborted retry
698698
})
699+
700+
it("should rethrow a non-abort error from the 401 retry unchanged", async () => {
701+
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(tokenResponse()))
702+
const apiError = new Error("boom")
703+
mockCreate.mockRejectedValueOnce(unauthorizedError()).mockRejectedValueOnce(apiError)
704+
705+
const stream = handler.createMessage("test prompt", [], {
706+
taskId: "t1",
707+
abortSignal: new AbortController().signal,
708+
})
709+
let caught: unknown
710+
try {
711+
await collectStream(stream)
712+
} catch (error) {
713+
caught = error
714+
}
715+
716+
expect(caught).toBe(apiError)
717+
expect(mockCreate).toHaveBeenCalledTimes(2)
718+
})
699719
})
700720

701721
describe("completePrompt", () => {
@@ -839,6 +859,22 @@ describe("QwenCodeHandler Native Tools", () => {
839859
expect((caught as Error).message).not.toBe("Request was aborted.") // not the raw SDK error
840860
expect(mockCreate).toHaveBeenCalledTimes(2) // first attempt 401, then the aborted retry
841861
})
862+
863+
it("should rethrow a non-abort error from the 401 retry unchanged", async () => {
864+
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(tokenResponse()))
865+
const apiError = new Error("boom")
866+
mockCreate.mockRejectedValueOnce(unauthorizedError()).mockRejectedValueOnce(apiError)
867+
868+
let caught: unknown
869+
try {
870+
await handler.completePrompt("hi", { abortSignal: new AbortController().signal })
871+
} catch (error) {
872+
caught = error
873+
}
874+
875+
expect(caught).toBe(apiError)
876+
expect(mockCreate).toHaveBeenCalledTimes(2)
877+
})
842878
})
843879
})
844880
})

0 commit comments

Comments
 (0)