Skip to content

Commit 982fef4

Browse files
test(api): kill the surviving conditional mutant in completePrompt's catch
The mutation advisory on this head was 'src/api/providers/requesty.ts:342: Survived ConditionalExpression mutant (replacement: false)'. Line 342 is the isRequestAborted guard in completePrompt's catch, the statement the review row pointed at. Judging it: It is not an equivalent mutant. The guard's condition is 'isRequestAborted(error, requestAbortSignal)', and the shared helper resolveModelWithAbort runs the identical check before it rethrows. A failure the helper judged non-abort can still meet an aborted signal at the provider's catch, because a microtask boundary sits between the helper's catch and this one: the helper rethrows the genuine failure, the caller's signal fires in that gap, and this guard then converts the genuine failure into the Task.ts abort contract. Mutating the condition to false propagates the genuine failure instead, which is an observable difference in the name and message of the thrown error. The aggregate line 'fetchers/requesty.ts:107: 2 mutation test gaps; example: ...' and the NoCoverage StringLiteral at :116 are advisory lines, not per-mutant results, and are not what this commit addresses. It was a real coverage gap, measured both ways: with the condition replaced by 'false' the provider suite passed 61 of 61 and tsc reported no errors, so nothing in the suite distinguished the guard from its own negation. The new test drives exactly the interleaving - the model lookup rejects with a name-'Error' / message-'catalog request failed' failure, and the caller's signal aborts from a Promise.resolve().then scheduled by the failure object's first property read, which happens inside the helper's check and therefore after it and before this catch resumes - and asserts name 'AbortError' and message 'The Requesty request was aborted'. Measured: on the real code 62 passed; under the mutant 1 failed with "AssertionError: expected 'Error' to be 'AbortError'". No Stryker directive was added and src/eslint-suppressions.json is unchanged (git diff --numstat against HEAD is empty). Package-level gate for the touched package, per the campaign rule: pnpm --dir src test. It fails in this worktree for two pre-existing, environment-caused files that my change does not touch: __tests__/dist_assets.spec.ts (no dist/ build in this worktree - the directory is absent) and services/rules/__tests__/rules.spec.ts (EPERM: operation not permitted, symlink ...). Running those two files alone here, with my change present and inert for them, gives 45 failed of 56, so they fail without my change too. No api/providers file fails in the package run.
1 parent a93038b commit 982fef4

1 file changed

Lines changed: 43 additions & 2 deletions

File tree

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,47 @@ describe("RequestyHandler", () => {
14441444

14451445
await expect(handler.completePrompt("test prompt")).rejects.toThrow("Unexpected error")
14461446
})
1447+
1448+
it("reports the abort contract when a lookup failure races the caller abort", async () => {
1449+
// Discriminates the guard in the completePrompt catch: the lookup fails for a real
1450+
// reason (name Error, message not an abort shape) and the caller signal fires one
1451+
// microtask later. The shared lookup helper runs its own abort check first, sees a
1452+
// not-yet-aborted signal and rethrows the genuine failure; the provider catch then
1453+
// sees the aborted signal and must normalize to the Task.ts abort contract. The
1454+
// abort is scheduled from the first property read of the failure object, which
1455+
// happens inside that helper check, so it lands after the helper check and before
1456+
// this catch resumes. No timers and no sleeps are involved.
1457+
const handler = new RequestyHandler(mockOptions)
1458+
const controller = new AbortController()
1459+
let abortScheduled = false
1460+
class LookupFailure extends Error {
1461+
override get name(): string {
1462+
if (!abortScheduled) {
1463+
abortScheduled = true
1464+
void Promise.resolve().then(() => {
1465+
controller.abort()
1466+
})
1467+
}
1468+
return "Error"
1469+
}
1470+
override get message(): string {
1471+
return "catalog request failed"
1472+
}
1473+
}
1474+
vitest.mocked(getModels).mockRejectedValueOnce(new LookupFailure())
1475+
1476+
const outcome: unknown = await handler
1477+
.completePrompt("test prompt", { abortSignal: controller.signal })
1478+
.then(
1479+
(value): unknown => value,
1480+
(caught: unknown): unknown => caught,
1481+
)
1482+
if (!(outcome instanceof Error)) {
1483+
throw new Error("expected the abort contract to reject with an Error, got " + typeof outcome)
1484+
}
1485+
expect(outcome.name).toBe("AbortError")
1486+
expect(outcome.message).toBe("The Requesty request was aborted")
1487+
})
14471488
it("should pass abort signal through to client", async () => {
14481489
const handler = new RequestyHandler(mockOptions)
14491490
const controller = new AbortController()
@@ -1601,7 +1642,7 @@ describe("RequestyHandler", () => {
16011642
expect(mockCreate).not.toHaveBeenCalled()
16021643
})
16031644

1604-
it("rethrows non-abort model lookup failures from completePrompt", async () => {
1645+
it("rethrows non-abort model lookup outcomes from completePrompt", async () => {
16051646
const handler = new RequestyHandler(mockOptions)
16061647
const { getModels } = await import("../fetchers/modelCache")
16071648
const lookupError = new Error("lookup failed")
@@ -1612,7 +1653,7 @@ describe("RequestyHandler", () => {
16121653
await expect(handler.completePrompt("test prompt")).rejects.toThrow("lookup failed")
16131654
})
16141655

1615-
it("normalizes raw AbortError lookup failures to the provider AbortError", async () => {
1656+
it("normalizes raw AbortError lookup outcomes to the provider AbortError", async () => {
16161657
const handler = new RequestyHandler(mockOptions)
16171658
const { getModels } = await import("../fetchers/modelCache")
16181659
const rawAbort = new Error("The user aborted a request")

0 commit comments

Comments
 (0)