From b6a8f6430f686c0907b22306bef05e071796d3db Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Tue, 7 Jul 2026 09:02:28 -0700 Subject: [PATCH] test(engine): simulate fallback split-close in single promptWithFallback call (specifyTask no longer loops) --- .../triage-split-into-subtasks-delete.test.ts | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/engine/src/__tests__/triage-split-into-subtasks-delete.test.ts b/packages/engine/src/__tests__/triage-split-into-subtasks-delete.test.ts index 70612d3742..739070b860 100644 --- a/packages/engine/src/__tests__/triage-split-into-subtasks-delete.test.ts +++ b/packages/engine/src/__tests__/triage-split-into-subtasks-delete.test.ts @@ -8,11 +8,20 @@ import { TriageProcessor } from "../triage.js"; const { mockCreateFnAgent } = vi.hoisted(() => ({ mockCreateFnAgent: vi.fn() })); -vi.mock("../pi.js", () => ({ - createFnAgent: mockCreateFnAgent, - describeModel: vi.fn().mockReturnValue("mock-model"), - promptWithFallback: vi.fn(), -})); +vi.mock("../pi.js", () => { + /* + FNXC:EngineTests 2026-07-07-08:05: + triage.ts specifyTask now (FN-7559) checks `err instanceof ModelFallbackExhaustedError` in its catch and (earlier, agentWork) calls `formatModelMarkerDetails`. The pi mock must expose both so the instanceof guard is callable and agentWork's model-marker formatting resolves, instead of crashing happy-path specifyTask runs. + */ + class ModelFallbackExhaustedError extends Error {} + return { + ModelFallbackExhaustedError, + createFnAgent: mockCreateFnAgent, + describeModel: vi.fn().mockReturnValue("mock-model"), + formatModelMarkerDetails: vi.fn((model: string) => model), + promptWithFallback: vi.fn(), + }; +}); vi.mock("@fusion/core", async (importOriginal) => { const { createEngineCoreMock } = await import("../test/mockCore.js"); @@ -118,13 +127,13 @@ describe("triage split/delete lineage forwarding", () => { const captured = { current: [] as any[] }; mockSessionFactory(captured); - let promptCallCount = 0; + /* + FNXC:TriageSplitLineage 2026-07-07-09:05: + specifyTask now invokes promptWithFallback exactly once — the multi-call retry loop that this test simulated (creating children on the 4th call) no longer exists, so the fallback never fired and deleteTask(removeLineageReferences) was never reached. Simulate the split-close inside that single promptWithFallback call instead. The removeLineageReferences lineage-forwarding invariant (FN-5129/FN-5131) is what this test guards, regardless of how many prompt calls precede it. + */ const { promptWithFallback } = await import("../pi.js"); (promptWithFallback as ReturnType).mockImplementation(async () => { - promptCallCount += 1; - if (promptCallCount === 4) { - await createChildrenFromTool(captured.current); - } + await createChildrenFromTool(captured.current); }); const processor = new TriageProcessor(store, "/test/root", { pollIntervalMs: 100_000 });