From 3a0e3d558fc77cf1b6dd56fcfdee92cfaee1e9c8 Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Sat, 13 Jun 2026 08:55:33 -0700 Subject: [PATCH] FN-6363: stabilize memory insight AI mock Stabilizes memory extraction and audit route tests by restoring the expected createFnAgent mock behavior.\n\n- Add a focused helper that returns structured insight extraction output from the mocked AI session.\n- Reset the mock around memory extract and audit tests so earlier route tests cannot leak incompatible behavior.\n\nFiles changed:\n .../src/__tests__/routes-settings.test.ts | 28 ++++++++++++++++++++++\n 1 file changed, 28 insertions(+) Fusion-Task-Id: FN-6363 Fusion-Task-Lineage: d4b93c51-3d30-4a97-90e9-72e2dd660501 --- .../src/__tests__/routes-settings.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/dashboard/src/__tests__/routes-settings.test.ts b/packages/dashboard/src/__tests__/routes-settings.test.ts index e1757ad198..6bff37c484 100644 --- a/packages/dashboard/src/__tests__/routes-settings.test.ts +++ b/packages/dashboard/src/__tests__/routes-settings.test.ts @@ -161,6 +161,31 @@ import { createFnAgent } from "@fusion/engine"; const mockIsGhAvailable = vi.mocked(isGhAvailable); const mockIsGhAuthenticated = vi.mocked(isGhAuthenticated); +function resetCreateFnAgentMockForInsightExtraction(): void { + vi.mocked(createFnAgent).mockImplementation(async (options?: { onText?: (delta: string) => void }) => { + const session = { + state: { + messages: [] as Array<{ role: string; content: string }>, + }, + prompt: vi.fn(async function (this: { state: { messages: Array<{ role: string; content: string }> } }, message: string) { + options?.onText?.("mock-ai-output"); + this.state.messages.push({ role: "user", content: message }); + this.state.messages.push({ + role: "assistant", + content: JSON.stringify({ + summary: "Extracted insights", + insights: [{ category: "pattern", content: "Persist reusable memory-audit conventions" }], + prunedMemory: "## Architecture\n\nDurable architecture notes.", + }), + }); + }), + dispose: vi.fn(), + }; + + return { session } as never; + }); +} + function createMockGlobalSettingsStore() { return { getSettings: vi.fn().mockResolvedValue({}), @@ -2760,6 +2785,7 @@ describe("POST /api/memory/extract", () => { let rootDir: string; beforeEach(() => { + resetCreateFnAgentMockForInsightExtraction(); rootDir = mkdtempSync(join(tmpdir(), "fusion-memory-extract-")); mkdirSync(join(rootDir, ".fusion"), { recursive: true }); store = createMockStore({ @@ -2769,6 +2795,7 @@ describe("POST /api/memory/extract", () => { afterEach(() => { rmSync(rootDir, { recursive: true, force: true }); + resetCreateFnAgentMockForInsightExtraction(); }); function buildApp() { @@ -2889,6 +2916,7 @@ describe("GET /api/memory/audit", () => { let rootDir: string; beforeEach(() => { + resetCreateFnAgentMockForInsightExtraction(); rootDir = mkdtempSync(join(tmpdir(), "fusion-memory-audit-")); mkdirSync(join(rootDir, ".fusion", "memory"), { recursive: true }); store = createMockStore({