Skip to content

Commit a326612

Browse files
author
f0-1528
committed
test(opencode-go,requesty): pin the abort assertions the new lint rule exposed
The compile arm failed on three lint errors after main was absorbed (merge commit 801a672, 602 files, no conflicts). Two of them sit in src/api/providers/__tests__/opencode-go.spec.ts, a file this pull request never touched: the branch adds abortSubstringSelector to the spec lint configs, and main's already-merged assertions then fail that new rule on the merge ref. A head-only lint run reports the same two rows one line earlier, at 1134 and 1485, so the failure is the merge-tree class a head-only run cannot see. In the merged tree eslint reports exactly the arm's three rows - 1135:10, 1486:10 and 964:36 - and exits 1. opencode-go.spec.ts:1137 - the double is now one object shared by the two listeners that race to reject the next() promise, and the test asserts rejects.toBe(abortDouble). The stream path propagates the SDK-level rejection unchanged, so identity is the strongest true statement; asserting an AbortError name and a provider message there would assert a contract this handler does not have. opencode-go.spec.ts:1495 - the Responses completion path wraps every failure (opencode-go.ts:439 throws "Opencode Go completion error: <message>"), so the row pins name "Error" and that whole message instead of a bare substring that a raw SDK error would match too. requesty.spec.ts:966 - the fixed sleep becomes the shared flushMacrotasks() helper (src/test-utils/timers.ts): a rejection that ends up handled has no observable condition to poll, which is what that helper is for, and setTimeout is what the rule bans in specs. Controls in this repo, on the merged tree: eslint over src exits 1 with those three errors before the change and 0 after; the two spec files report 177 passed after it; and mutating the two pinned details - asserting a fresh but equal error object, and dropping the provider prefix from the message - fails exactly those two tests ("expected Error: request aborted to be Error: request aborted", and the mismatch on { name: 'Error', message: 'Opencode Go completion error: request aborted' }) and nothing else. Test-only: no implementation file is touched, eslint-suppressions counts are unchanged for every entry (opencode-go.spec.ts stays 3).
1 parent 801a672 commit a326612

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,13 +1100,19 @@ describe("OpencodeGoHandler", () => {
11001100

11011101
it("stops an in-flight Responses iterator when its abort signal rejects the read", async () => {
11021102
const controller = new AbortController()
1103+
// The iterator's own listener and the request-level listener race to reject the same
1104+
// promise, so the double is one object and the assertion below pins which rejection
1105+
// propagated. opencode-go hands the caller's signal straight to the SDK and never
1106+
// normalises it into a provider AbortError, so there is no provider message to assert
1107+
// on this path: identity is the strongest statement that is true here.
1108+
const abortDouble = new Error("request aborted")
11031109
let rejectNext: ((reason?: unknown) => void) | undefined
11041110
const iterator = {
11051111
next: vitest.fn().mockImplementation(
11061112
() =>
11071113
new Promise((_resolve, reject) => {
11081114
rejectNext = reject
1109-
controller.signal.addEventListener("abort", () => reject(new Error("request aborted")), {
1115+
controller.signal.addEventListener("abort", () => reject(abortDouble), {
11101116
once: true,
11111117
})
11121118
}),
@@ -1117,7 +1123,7 @@ describe("OpencodeGoHandler", () => {
11171123
},
11181124
}
11191125
mockResponsesCreate.mockImplementation(async (_body: unknown, options: { signal?: AbortSignal }) => {
1120-
options.signal?.addEventListener("abort", () => rejectNext?.(new Error("request aborted")), {
1126+
options.signal?.addEventListener("abort", () => rejectNext?.(abortDouble), {
11211127
once: true,
11221128
})
11231129
return iterator
@@ -1132,7 +1138,7 @@ describe("OpencodeGoHandler", () => {
11321138
await vitest.waitFor(() => expect(mockResponsesCreate).toHaveBeenCalled())
11331139
controller.abort()
11341140

1135-
await expect(nextPromise).rejects.toThrow("request aborted")
1141+
await expect(nextPromise).rejects.toBe(abortDouble)
11361142
expect(iterator.return).toHaveBeenCalled()
11371143
})
11381144

@@ -1473,8 +1479,14 @@ describe("OpencodeGoHandler", () => {
14731479

14741480
it("rejects non-streaming Responses completion when the abort signal fires", async () => {
14751481
const controller = new AbortController()
1482+
// One double object here too. The Responses completion path wraps every failure
1483+
// (`opencode-go.ts:439` throws `Opencode Go completion error: <message>`), so the
1484+
// abort surfaces as a new Error carrying the double's text behind the provider prefix,
1485+
// not as the double and not as an AbortError. The assertion below pins that whole
1486+
// message; a bare "abort" substring would also match a raw SDK error.
1487+
const abortDouble = new Error("request aborted")
14761488
const request = new Promise<never>((_resolve, reject) => {
1477-
controller.signal.addEventListener("abort", () => reject(new Error("request aborted")), { once: true })
1489+
controller.signal.addEventListener("abort", () => reject(abortDouble), { once: true })
14781490
})
14791491
mockResponsesCreate.mockReturnValue(request)
14801492
const handler = new OpencodeGoHandler(lunaOptions)
@@ -1483,7 +1495,10 @@ describe("OpencodeGoHandler", () => {
14831495
await vitest.waitFor(() => expect(mockResponsesCreate).toHaveBeenCalled())
14841496
controller.abort()
14851497

1486-
await expect(completion).rejects.toThrow("request aborted")
1498+
await expect(completion).rejects.toMatchObject({
1499+
name: "Error",
1500+
message: `Opencode Go completion error: ${abortDouble.message}`,
1501+
})
14871502
})
14881503

14891504
it("completePrompt calls responses.create and returns output_text", async () => {

‎src/api/providers/__tests__/requesty.spec.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { makeApiHandlerOptions } from "../../../test-utils/api"
2020
import { asyncStreamFrom, collectStream } from "../../../test-utils/stream"
2121
import { clearAllMocks } from "../../../test-utils/reset"
2222
import { withSettleGuard } from "../../../test-utils/settle-guard"
23+
import { flushMacrotasks } from "../../../test-utils/timers"
2324

2425
const mockCreate = vitest.fn()
2526

@@ -960,8 +961,10 @@ describe("RequestyHandler", () => {
960961

961962
// The lookup fails after the request already settled as aborted.
962963
rejectLookup(new Error("late lookup failure"))
963-
// Node reports an unhandled rejection only after the microtask queue drains.
964-
await new Promise((resolve) => setTimeout(resolve, 0))
964+
// Node reports an unhandled rejection only after the queue drains, and a rejection
965+
// that ends up handled has no observable state to poll, so drain the queue through
966+
// the shared helper instead of sleeping.
967+
await flushMacrotasks()
965968
expect(unhandled).toHaveLength(0)
966969
} finally {
967970
process.off("unhandledRejection", onUnhandledRejection)

0 commit comments

Comments
 (0)