Skip to content

Commit 9ae937b

Browse files
test(opencode-go): abort the Anthropic request mid-flight so the completion catch runs
The abort-identity test aborted its controller before completePrompt was called, so the error surfaced during model resolution and the anthropic completion catch's isRequestAborted(error, options?.abortSignal) branch was never reached. The mock now rejects with a generic Error from an abort listener on the request signal the provider forwarded - the shape the sibling Responses test in this file uses - and the test aborts only after messages.create has been called. Control on the branch itself: disabling the anthropic completion catch leaves the old test passing unchanged and fails the new one with "Opencode Go completion error: The Opencode Go request was aborted", so the new shape reaches the branch the old shape did not. Dropping the second argument to isRequestAborted still passes under both shapes: with a mid-request abort the error that reaches the catch is the merged-signal AbortError, so the caller-signal argument is not yet load-bearing in either shape. That is a limit of this change, not a claim that it is closed. Gate accounting: packageForPath() returns null for this spec path, so the mutation-diff leg charges 0 changed lines for this commit.
1 parent 68d3663 commit 9ae937b

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

‎src/api/providers/__tests__/opencode-go.spec.ts‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,21 +1409,33 @@ describe("OpencodeGoHandler", () => {
14091409
expect(Object.keys(requestOptions ?? {})).not.toContain("timeout")
14101410
})
14111411

1412-
it("completePrompt preserves abort identity when the caller aborts (Anthropic path)", async () => {
1413-
// Emulate the Anthropic SDK: an aborted request signal rejects with
1414-
// APIUserAbortError ("Request was aborted." — the trailing period would
1415-
// fail task-level abort detection, so the provider must normalize it).
1416-
mockAnthropicCreate.mockImplementation(async (_params: unknown, options: { signal?: AbortSignal }) => {
1417-
if (options?.signal?.aborted) {
1418-
throw new AnthropicAbortError()
1419-
}
1420-
throw new Error("boom")
1421-
})
1412+
it("completePrompt preserves abort identity when the caller aborts mid-request (Anthropic path)", async () => {
1413+
// The abort has to land after the request starts. A pre-aborted signal is
1414+
// caught by resolveModelWithAbort during model resolution, so the completion
1415+
// catch in opencode-go.ts (the isRequestAborted branch) never runs and the
1416+
// test would pass without exercising it. The mock rejects with a generic
1417+
// Error rather than an abort-shaped one, exactly the shape the sibling
1418+
// Responses test uses, so normalizing it proves the catch consults the
1419+
// caller signal argument and not just the error name or message.
1420+
mockAnthropicCreate.mockImplementation(
1421+
(_params: unknown, options: { signal?: AbortSignal }) =>
1422+
new Promise<never>((_resolve, reject) => {
1423+
const signal = options?.signal
1424+
if (!signal) {
1425+
reject(new Error("the provider forwarded no request signal"))
1426+
return
1427+
}
1428+
signal.addEventListener("abort", () => reject(new Error("boom")), { once: true })
1429+
}),
1430+
)
14221431
const handler = new OpencodeGoHandler(anthropicOptions)
14231432
const controller = new AbortController()
1433+
const completion = handler.completePrompt("ping", { abortSignal: controller.signal })
1434+
1435+
await vitest.waitFor(() => expect(mockAnthropicCreate).toHaveBeenCalled())
14241436
controller.abort()
14251437

1426-
const error = await handler.completePrompt("ping", { abortSignal: controller.signal }).then(
1438+
const error = await completion.then(
14271439
() => undefined,
14281440
(e: unknown) => e,
14291441
)

0 commit comments

Comments
 (0)