Skip to content

Commit 622bb32

Browse files
committed
fix: address CodeRabbit abort assertion findings
1 parent 729fad6 commit 622bb32

4 files changed

Lines changed: 19 additions & 10 deletions

File tree

‎packages/config-eslint/api-provider-hygiene.js‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,9 @@ export const apiProviderHygieneConfig = {
6666
// Shared by every spec lane, not only src/api: an abort assertion must not pass on a raw SDK error.
6767
export const abortSubstringSelector = {
6868
selector:
69-
// The escaped-dot and escaped-anchor forms keep a backslash in the pattern text, so the tail
70-
// has to allow one before the dot or anchor; without it /^Request was aborted\\.$/ slips
71-
// through the rule while the same message written as a string is flagged. The pattern
72-
// branch also has to consume a non-capturing group verbatim, because an inline
73-
// (?:ed)? is regex source, not a message character, and an anchored match that stops
74-
// short of it leaves /abort(?:ed)?/i unflagged.
75-
"CallExpression[callee.property.name=/^toThrow(Error)?$/]:not([callee.object.property.name='not']):matches([arguments.0.value=/^[$^]?(the )?(request )?(was )?abort(ed)?[\\\\.$]*$/i], [arguments.0.regex.pattern=/^[$^]?(the )?(request )?(was )?abort(ed)?(?:\\(\\?:(?:ed|ion|al)\\)\\?)?[\\\\.$]*$/i])",
69+
// Strings contain literal punctuation; only regex source can contain anchors, wildcards,
70+
// optional suffix groups, or word boundaries around the generic abort wording.
71+
"CallExpression[callee.property.name=/^toThrow(Error)?$/]:not([callee.object.property.name='not']):matches([arguments.0.value=/^(the )?(request )?(was )?abort(ed)?[.]*$/i], [arguments.0.regex.pattern=/^[$^]?(?:\\.\\*)?(the )?(request )?(was )?abort(ed)?(?:\\(\\?:(?:ed|ion|al)\\)\\??)?(?:\\\\b)?(?:\\.\\*)?[\\\\.$]*$/i])",
7672
message:
7773
"A bare 'abort' substring also matches a raw SDK error. Assert the AbortError name and the full provider message.",
7874
}

‎packages/config-eslint/api-provider-hygiene.test.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ describe("abort assertions in the extension ESLint config", () => {
306306
// An escaped dot in the source text is still a bare abort substring: the pattern
307307
// keeps a backslash, so the matcher must allow it before the trailing dot or anchor.
308308
["await expect(p).rejects.toThrow(/^aborted$/)", 1],
309+
["await expect(p).rejects.toThrow(/.*aborted.*/i)", 1],
310+
["await expect(p).rejects.toThrowError(/abort(?:ed)/i)", 1],
311+
["await expect(p).rejects.toThrow(/aborted\\b/i)", 1],
312+
['await expect(p).rejects.toThrow("abort$")', 0],
313+
['await expect(p).rejects.toThrow("^abort")', 0],
314+
["await expect(p).rejects.toThrow(/.*The Requesty request was aborted.*/i)", 0],
315+
["await expect(p).rejects.toThrow(/The Requesty request was aborted\\b/i)", 0],
309316
["await expect(p).rejects.toThrow(/^Request was aborted\\.$/)", 1],
310317
["await expect(p).rejects.toThrowError(/request aborted\\.$/i)", 1],
311318
["await expect(p).rejects.toThrow(/^request aborted\\$/)", 1],

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,9 @@ describe("RequestyHandler", () => {
10121012
name: "AbortError",
10131013
message: "The Requesty request was aborted",
10141014
})
1015+
const lookupSignal = vitest.mocked(getModels).mock.calls.at(-1)?.[0].signal
1016+
expect(lookupSignal).toBeInstanceOf(AbortSignal)
1017+
expect(lookupSignal?.aborted, "the timeout must cancel the model lookup").toBe(true)
10151018
expect(controller.signal.aborted, "the timeout must not surface through the caller signal").toBe(false)
10161019
expect(mockCreate, "the lookup must not fall through into a completion").not.toHaveBeenCalled()
10171020
})

‎src/core/task/__tests__/ask-queued-message-drain.spec.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,12 @@ describe("Task.ask queued message drain", () => {
356356

357357
// The abort must name this task and this instance: a regex that accepts any id would also
358358
// pass for another task's abort or a different prefix.
359-
const rejection = await ask.catch((e: unknown) => e)
360-
expect((rejection as Error).message).toBe(`[ZooCode#ask] task ${task.taskId}.${task.instanceId} aborted`)
361-
expect((rejection as Error).message).toBe("[ZooCode#ask] task task-ask-drain.instance-ask-drain aborted")
359+
await expect(ask).rejects.toMatchObject({
360+
message: `[ZooCode#ask] task ${task.taskId}.${task.instanceId} aborted`,
361+
})
362+
await expect(ask).rejects.toMatchObject({
363+
message: "[ZooCode#ask] task task-ask-drain.instance-ask-drain aborted",
364+
})
362365
expect(task.messageQueueService.messages).toHaveLength(1)
363366
expect(task.messageQueueService.claimNextMessage()?.text).toBe("Persist me later")
364367
})

0 commit comments

Comments
 (0)