Skip to content

Commit 617c9d4

Browse files
lsr911lsr911
andauthored
fix: isolate async model resolution mock from sync mock in test (#93714)
The 'can preserve asynchronous provider model discovery' test was flaky because resolveModelAsyncMock in beforeEach delegates to resolveModelMock. When useAsyncModelResolution=true, the test asserted resolveModelMock was not called, but the delegation caused it to be called, failing CI on two lanes. Fix: use a standalone vi.fn() for the async resolver in this test, and explicitly reset resolveModelMock before the assertion to guard against mock state leakage from prior tests. Fixes #92117 Co-authored-by: lsr911 <[email protected]>
1 parent 76658cd commit 617c9d4

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/agents/simple-completion-runtime.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,11 @@ describe("prepareSimpleCompletionModel", () => {
476476
});
477477

478478
it("can preserve asynchronous provider model discovery", async () => {
479-
hoisted.resolveModelAsyncMock.mockResolvedValueOnce({
479+
// Use a standalone mock so the default beforeEach delegation from
480+
// resolveModelAsyncMock → resolveModelMock does not pollute call
481+
// history. The point of the test is that when useAsyncModelResolution
482+
// is true, only the async resolver is invoked.
483+
const resolveModelAsync = vi.fn().mockResolvedValue({
480484
model: {
481485
provider: "anthropic",
482486
id: "claude-opus-4-6",
@@ -486,18 +490,21 @@ describe("prepareSimpleCompletionModel", () => {
486490
},
487491
modelRegistry: {},
488492
});
493+
// Reset the hoisted sync mock so any leftover calls from earlier tests
494+
// or beforeEach setup don't cause a false positive.
495+
hoisted.resolveModelMock.mockReset();
489496

490497
const result = await prepareSimpleCompletionModel({
491498
cfg: undefined,
492499
provider: "anthropic",
493500
modelId: "claude-opus-4-6",
494501
useAsyncModelResolution: true,
495-
modelResolver: hoisted.resolveModelAsyncMock,
502+
modelResolver: resolveModelAsync,
496503
});
497504

498505
expectPreparedModelResult(result);
499506
expect(hoisted.resolveModelMock).not.toHaveBeenCalled();
500-
expect(hoisted.resolveModelAsyncMock).toHaveBeenCalledWith(
507+
expect(resolveModelAsync).toHaveBeenCalledWith(
501508
"anthropic",
502509
"claude-opus-4-6",
503510
undefined,

0 commit comments

Comments
 (0)