fix: isolate async model resolution mock from sync mock in test (#93714) · openclaw/openclaw@617c9d4
lsr911
·
2026-06-17
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -476,7 +476,11 @@ describe("prepareSimpleCompletionModel", () => {
|
476 | 476 | }); |
477 | 477 | |
478 | 478 | 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({ |
480 | 484 | model: { |
481 | 485 | provider: "anthropic", |
482 | 486 | id: "claude-opus-4-6", |
@@ -486,18 +490,21 @@ describe("prepareSimpleCompletionModel", () => {
|
486 | 490 | }, |
487 | 491 | modelRegistry: {}, |
488 | 492 | }); |
| 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(); |
489 | 496 | |
490 | 497 | const result = await prepareSimpleCompletionModel({ |
491 | 498 | cfg: undefined, |
492 | 499 | provider: "anthropic", |
493 | 500 | modelId: "claude-opus-4-6", |
494 | 501 | useAsyncModelResolution: true, |
495 | | -modelResolver: hoisted.resolveModelAsyncMock, |
| 502 | +modelResolver: resolveModelAsync, |
496 | 503 | }); |
497 | 504 | |
498 | 505 | expectPreparedModelResult(result); |
499 | 506 | expect(hoisted.resolveModelMock).not.toHaveBeenCalled(); |
500 | | -expect(hoisted.resolveModelAsyncMock).toHaveBeenCalledWith( |
| 507 | +expect(resolveModelAsync).toHaveBeenCalledWith( |
501 | 508 | "anthropic", |
502 | 509 | "claude-opus-4-6", |
503 | 510 | undefined, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。