Skip to content

Commit deee63a

Browse files
committed
fix(eslint): tighten abort assertion guards and test lane coverage
1 parent bd60384 commit deee63a

3 files changed

Lines changed: 68 additions & 7 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export const apiProviderHygieneConfig = {
6565

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 = {
68-
selector: "CallExpression[callee.property.name='toThrow'][arguments.0.value=/^[Aa]bort(ed)?$/]",
68+
selector:
69+
"CallExpression[callee.property.name=/^toThrow(Error)?$/]:not([callee.object.property.name='not']):matches([arguments.0.value=/^[Aa]bort(ed)?$/], [arguments.0.regex.pattern=/^[Aa]bort(ed)?$/])",
6970
message:
7071
"A bare 'abort' substring also matches a raw SDK error. Assert the AbortError name and the full provider message.",
7172
}

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

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import assert from "node:assert/strict"
22
import { describe, it } from "node:test"
3+
import { fileURLToPath, URL } from "node:url"
34

4-
import { Linter } from "eslint"
5+
import { ESLint, Linter } from "eslint"
56
import typescriptEslint from "typescript-eslint"
67

78
import { apiProviderHygieneConfig, apiProviderTestSelectors, apiSpecTsIgnoreConfig } from "./api-provider-hygiene.js"
@@ -174,7 +175,13 @@ describe("api provider hygiene: spec loops", () => {
174175
})
175176
}
176177

177-
for (const code of ['await expect(p).rejects.toThrow("aborted")', "expect(() => f()).toThrow('abort')"]) {
178+
for (const code of [
179+
'await expect(p).rejects.toThrow("aborted")',
180+
"expect(() => f()).toThrow('abort')",
181+
'await expect(p).rejects.toThrowError("aborted")',
182+
"expect(() => f()).toThrow(/abort/i)",
183+
"await expect(p).rejects.toThrowError(/aborted/i)",
184+
]) {
178185
it(`flags a bare abort substring: ${code}`, () => {
179186
assert.equal(lintSpec(code).length, 1)
180187
})
@@ -184,6 +191,11 @@ describe("api provider hygiene: spec loops", () => {
184191
'await expect(p).rejects.toThrow("The Requesty request was aborted")',
185192
'await expect(p).rejects.toMatchObject({ name: "AbortError" })',
186193
'await expect(p).rejects.toThrow("API Error")',
194+
'expect(() => f()).not.toThrow("aborted")',
195+
'await expect(p).rejects.not.toThrow("aborted")',
196+
"expect(() => f()).not.toThrowError(/abort/i)",
197+
"await expect(p).rejects.not.toThrowError(/aborted/i)",
198+
"await expect(p).rejects.toThrow(/^The Requesty request was aborted$/)",
187199
]) {
188200
it(`allows: ${code}`, () => {
189201
assert.deepEqual(lintSpec(code), [])
@@ -261,3 +273,39 @@ describe("api provider hygiene: @ts-ignore in specs", () => {
261273
assert.deepEqual(lintSpecFile("// @ts-ignore x\nhandler.client", "services/__tests__/example.spec.ts"), [])
262274
})
263275
})
276+
277+
// Resolve each lane through the extension's real config before exercising its syntax rules.
278+
// Isolating syntax rules avoids requiring fixture files in the TypeScript project.
279+
describe("abort assertions in the extension ESLint config", () => {
280+
const srcRoot = fileURLToPath(new URL("../../src/", import.meta.url))
281+
const eslint = new ESLint({ cwd: srcRoot })
282+
283+
for (const filename of ["core/task/__tests__/example.spec.ts", "core/config/__tests__/example.spec.ts"]) {
284+
it(`checks rejected and accepted assertions in ${filename}`, async () => {
285+
const resolved = await eslint.calculateConfigForFile(filename)
286+
const syntaxConfig = [
287+
{
288+
files: ["**/*.ts"],
289+
languageOptions: { parser: typescriptEslint.parser },
290+
rules: { "no-restricted-syntax": resolved.rules["no-restricted-syntax"] },
291+
},
292+
]
293+
for (const [code, expectedCount] of [
294+
['await expect(p).rejects.toThrow("aborted")', 1],
295+
["await expect(p).rejects.toThrowError(/abort/i)", 1],
296+
['await expect(p).rejects.not.toThrow("aborted")', 0],
297+
[
298+
'await expect(p).rejects.toMatchObject({ name: "AbortError", message: "The Requesty request was aborted" })',
299+
0,
300+
],
301+
]) {
302+
const messages = linter.verify(code, syntaxConfig, { filename })
303+
assert.equal(messages.length, expectedCount, code)
304+
if (expectedCount) {
305+
assert.equal(messages[0].ruleId, "no-restricted-syntax")
306+
assert.match(messages[0].message, /bare 'abort' substring/)
307+
}
308+
}
309+
})
310+
}
311+
})

‎src/core/task/__tests__/ask-abort-race.spec.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ describe("Task.ask abort during the auto-approval await", () => {
4747
task["abort"] = true
4848
gate.release()
4949

50-
await expect(askPromise).rejects.toThrow(/aborted/)
50+
await expect(askPromise).rejects.toMatchObject({
51+
name: "Error",
52+
message: `[RooCode#ask] task ${task.taskId}.${task.instanceId} aborted`,
53+
})
5154
expect(task["addToClineMessages"]).not.toHaveBeenCalled()
5255
expect(task["lastMessageTs"]).toBeUndefined()
5356
})
@@ -65,7 +68,10 @@ describe("Task.ask abort during the auto-approval await", () => {
6568
task["abort"] = true
6669
gate.release()
6770

68-
await expect(askPromise).rejects.toThrow(/aborted/)
71+
await expect(askPromise).rejects.toMatchObject({
72+
name: "Error",
73+
message: `[RooCode#ask] task ${task.taskId}.${task.instanceId} aborted`,
74+
})
6975
expect(task["addToClineMessages"]).not.toHaveBeenCalled()
7076
expect(task["lastMessageTs"]).toBeUndefined()
7177
})
@@ -86,7 +92,10 @@ describe("Task.ask abort during the auto-approval await", () => {
8692
task["abort"] = true
8793
gate.release()
8894

89-
await expect(askPromise).rejects.toThrow(/aborted/)
95+
await expect(askPromise).rejects.toMatchObject({
96+
name: "Error",
97+
message: `[RooCode#ask] task ${task.taskId}.${task.instanceId} aborted`,
98+
})
9099
expect(task["clineMessages"]).toEqual([original])
91100
expect(task["saveClineMessages"]).not.toHaveBeenCalled()
92101
expect(task["updateClineMessage"]).not.toHaveBeenCalled()
@@ -105,7 +114,10 @@ describe("Task.ask abort during the auto-approval await", () => {
105114
task["abort"] = true
106115
gate.release()
107116

108-
await expect(askPromise).rejects.toThrow(/aborted/)
117+
await expect(askPromise).rejects.toMatchObject({
118+
name: "Error",
119+
message: `[RooCode#ask] task ${task.taskId}.${task.instanceId} aborted`,
120+
})
109121
expect(task["addToClineMessages"]).not.toHaveBeenCalled()
110122
expect(task.messageQueueService.claimNextMessage()?.text).toBe("queued feedback")
111123
})

0 commit comments

Comments
 (0)