Skip to content

Commit df3e889

Browse files
author
easonLiangWorldedtech
committed
config-eslint,api: close the escaped-group hole and reach the ignored workflow tests
abortSubstringSelector consumed escaped dots and anchors but stopped at an inline non-capturing group, so toThrow(/^Request was aborted\.$/) and toThrow(/abort(?:ed)?/i) fell through the rule while the same message written as a string was flagged. The pattern branch now consumes a (?:ed|ion|al)? group verbatim, and the four workflow tests that are exempt from the path-traversal selectors get the abort rule back instead of losing the whole block. Assertions tightened where they were blind: Requesty's normalised completion message instead of a substring that the unwrapped SDK error also satisfies, the model-lookup rejection by object identity, the ask abort message by task and instance id, and a case where only the per-request timeout may abort while the caller signal stays live. Controls, each run and reverted: rule suite 90/90 with the new tail, 89/90 with the old one and with the workflow mapping removed; requesty spec fails on the exact message when handleOpenAIError is bypassed at both catch sites, fails on Object.is when the lookup assertion takes a copy, and times out in the settle guard at timeoutMs 100_000; the ask assertion fails against foreign task ids. eslint over src is 0 findings before and after, the repo-wide abort-rule count stays 11, the four workflow files score 0 under the selector alone, and the mutation selection is 46 executable lines against main tip / 0 packages against head^1 (cap 500).
1 parent 177fb95 commit df3e889

5 files changed

Lines changed: 91 additions & 7 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ export const abortSubstringSelector = {
6868
selector:
6969
// The escaped-dot and escaped-anchor forms keep a backslash in the pattern text, so the tail
7070
// 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.
72-
"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)?[\\\\.$]*$/i])",
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])",
7376
message:
7477
"A bare 'abort' substring also matches a raw SDK error. Assert the AbortError name and the full provider message.",
7578
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,13 @@ describe("abort assertions in the extension ESLint config", () => {
284284
const srcRoot = fileURLToPath(new URL("../../src/", import.meta.url))
285285
const eslint = new ESLint({ cwd: srcRoot })
286286

287-
for (const filename of ["core/task/__tests__/example.spec.ts", "core/config/__tests__/example.spec.ts"]) {
287+
for (const filename of [
288+
"core/task/__tests__/example.spec.ts",
289+
"core/config/__tests__/example.spec.ts",
290+
// The workflow tests are exempt from the path-traversal selectors, not from the abort
291+
// rule; listing one proves the lane that re-applies it actually resolves for them.
292+
"services/__tests__/pr-review-state-workflow.test.ts",
293+
]) {
288294
it(`checks rejected and accepted assertions in ${filename}`, async () => {
289295
const resolved = await eslint.calculateConfigForFile(filename)
290296
const syntaxConfig = [
@@ -303,6 +309,15 @@ describe("abort assertions in the extension ESLint config", () => {
303309
["await expect(p).rejects.toThrow(/^Request was aborted\\.$/)", 1],
304310
["await expect(p).rejects.toThrowError(/request aborted\\.$/i)", 1],
305311
["await expect(p).rejects.toThrow(/^request aborted\\$/)", 1],
312+
// An inline non-capturing group is regex source, not part of the asserted
313+
// message: an anchored match that stops short of it lets a bare abort through.
314+
["await expect(p).rejects.toThrow(/abort(?:ed)?/i)", 1],
315+
["await expect(p).rejects.toThrowError(/^request aborted(?:ed)?$/i)", 1],
316+
["await expect(p).rejects.toThrow(/cancel(?:ed)?/i)", 0],
317+
[
318+
"await expect(p).rejects.toThrow(/^The Requesty request was aborted(?:ed)? because the peer closed the stream\\.$/)",
319+
0,
320+
],
306321
['await expect(p).rejects.not.toThrow("aborted")', 0],
307322
["await expect(p).rejects.toThrow(/^Request was aborted because the peer closed the stream\\.$/)", 0],
308323
[

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

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,10 @@ describe("RequestyHandler", () => {
764764

765765
expect(error).toBeInstanceOf(Error)
766766
expect((error as Error).name).not.toBe("AbortError")
767-
expect((error as Error).message).toContain("API Error")
767+
// Assert the normalised message, not a substring: "API Error" is also the message of
768+
// the unwrapped SDK error, so a catch that skipped handleOpenAIError would pass a
769+
// contains-check while the provider contract was gone.
770+
expect((error as Error).message).toBe("Requesty completion error: API Error")
768771
},
769772
)
770773

@@ -998,7 +1001,9 @@ describe("RequestyHandler", () => {
9981001
return Promise.reject(lookupError)
9991002
})
10001003

1001-
await expect(handler.completePrompt("test prompt")).rejects.toThrow("lookup failed")
1004+
// The handler rethrows this exact object, and the fixture owns it: pin the identity rather
1005+
// than the message text, which a rebuilt copy of the same failure would also satisfy.
1006+
await expect(handler.completePrompt("test prompt")).rejects.toBe(lookupError)
10021007
})
10031008

10041009
it("normalizes raw AbortError lookup failures to the provider AbortError", async () => {
@@ -1207,6 +1212,44 @@ describe("RequestyHandler", () => {
12071212
)
12081213
})
12091214

1215+
it("lets the per-request timeout abort the request while the caller signal stays live", async () => {
1216+
// The caller signal is live and never aborted here, so only the timer may end the request.
1217+
// The combined-options test above aborts through the controller and cannot see a merged
1218+
// signal that drops the timeout whenever a caller signal exists; this one hangs if it does.
1219+
const handler = new RequestyHandler(mockOptions)
1220+
const controller = new AbortController()
1221+
1222+
let notifyCreateStarted!: () => void
1223+
const createStarted = new Promise<void>((resolve) => {
1224+
notifyCreateStarted = resolve
1225+
})
1226+
let requestSignal: AbortSignal | undefined
1227+
mockCreate.mockImplementationOnce(async (_params: unknown, options?: { signal?: AbortSignal }) => {
1228+
notifyCreateStarted()
1229+
requestSignal = options?.signal
1230+
await new Promise<void>((resolve) => {
1231+
if (options?.signal?.aborted) {
1232+
resolve()
1233+
} else {
1234+
options?.signal?.addEventListener("abort", () => resolve(), { once: true })
1235+
}
1236+
})
1237+
const abortError = new Error("The user aborted a request")
1238+
abortError.name = "AbortError"
1239+
throw abortError
1240+
})
1241+
1242+
const promise = handler.completePrompt("test prompt", { abortSignal: controller.signal, timeoutMs: 25 })
1243+
void promise.catch(() => {})
1244+
await withSettleGuard(createStarted)
1245+
1246+
await expect(withSettleGuard(promise)).rejects.toMatchObject({ name: "AbortError" })
1247+
expect(controller.signal.aborted).toBe(false)
1248+
expect(requestSignal).toBeDefined()
1249+
expect(requestSignal).not.toBe(controller.signal)
1250+
expect(requestSignal?.aborted).toBe(true)
1251+
})
1252+
12101253
it("settles on abort while the SDK is sleeping between retries instead of waiting for the completion", async () => {
12111254
// [email protected] runs "await sleep(timeoutMillis)" inside retryRequest before issuing the
12121255
// next attempt, and that sleep does not observe the request signal: awaiting the SDK call

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ const getQueueTaskTestAccess = (task: Task) => task as unknown as QueueTaskTestA
1515

1616
describe("Task.ask queued message drain", () => {
1717
function createTask(provider?: { getState: () => Promise<Record<string, boolean>> }) {
18-
const task = Object.create(Task.prototype) as Task
18+
// Distinct task and instance ids, so an abort assertion can name this task instead of
19+
// accepting whatever the fixture left unset.
20+
const task = Object.create(Task.prototype, {
21+
taskId: { value: "task-ask-drain", enumerable: true },
22+
instanceId: { value: "instance-ask-drain", enumerable: true },
23+
}) as Task
1924
setAbortLatch(task, false)
2025
;(task as any).clineMessages = []
2126
;(task as any).askResponse = undefined
@@ -349,7 +354,11 @@ describe("Task.ask queued message drain", () => {
349354
setAbortLatch(task, true)
350355
finishAddingAsk()
351356

352-
await expect(ask).rejects.toThrow(/#ask\] task \S+ aborted$/)
357+
// The abort must name this task and this instance: a regex that accepts any id would also
358+
// 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")
353362
expect(task.messageQueueService.messages).toHaveLength(1)
354363
expect(task.messageQueueService.claimNextMessage()?.text).toBe("Persist me later")
355364
})

‎src/eslint.config.mjs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ export default [
144144
"no-restricted-syntax": ["error", ...testPathTraversalSelectors, abortSubstringSelector],
145145
},
146146
},
147+
{
148+
// The four workflow tests ignored above are exempt from the path-traversal selectors
149+
// because they read root-level config. That exception was never about abort
150+
// assertions, so re-apply the abort rule for exactly those files.
151+
files: [
152+
"**/services/__tests__/pr-review-state-workflow.test.ts",
153+
"**/services/__tests__/stale-pr-clock-workflow.test.ts",
154+
"**/services/__tests__/fork-review-followup-workflow.test.ts",
155+
"**/services/__tests__/workflow-self-listen.test.ts",
156+
],
157+
rules: {
158+
"no-restricted-syntax": ["error", abortSubstringSelector],
159+
},
160+
},
147161
{
148162
// A later block replaces no-restricted-syntax for the same files, so repeat the traversal selectors.
149163
files: ["api/**/__tests__/**/*.spec.ts"],

0 commit comments

Comments
 (0)