// Task 168 — per-tool emit assertion for conversation-memory-expunge.
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { setupEmitCapture } from "./_helpers/emit-capture.js";
vi.mock("../../lib/neo4j.js", () => ({
    getDriver: () => ({}),
}));
vi.mock("../../lib/graph-prune.js", () => ({
    expungeConversationMemory: vi.fn(),
}));
import { conversationMemoryExpunge } from "../conversation-memory-expunge.js";
import { expungeConversationMemory } from "../../lib/graph-prune.js";
describe("conversation-memory-expunge — emit wrapper wired", () => {
    let emit;
    beforeEach(() => {
        emit = setupEmitCapture();
        vi.mocked(expungeConversationMemory).mockReset();
    });
    afterEach(() => emit.restore());
    it("emits result=ok line on happy path", async () => {
        vi.mocked(expungeConversationMemory).mockResolvedValue({
            sessionId: "conv-1",
            pattern: ".*",
            nodesScanned: 0,
            propertiesNulled: 0,
            affectedNodeIds: [],
        });
        await conversationMemoryExpunge({
            accountId: "acct-1",
            sessionId: "conv-1",
            pattern: ".*",
        });
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.tag).toBe("mcp:memory");
        expect(body.level).toBe("info");
        expect(body.line).toContain("conversation-memory-expunge");
        expect(body.line).toContain("result=ok");
    });
    it("emits result=error line when expungeConversationMemory throws", async () => {
        vi.mocked(expungeConversationMemory).mockRejectedValue(new Error("driver error"));
        await expect(conversationMemoryExpunge({
            accountId: "acct-1",
            sessionId: "conv-1",
            pattern: ".*",
        })).rejects.toThrow(/driver error/);
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.level).toBe("error");
        expect(body.line).toContain("conversation-memory-expunge");
        expect(body.line).toContain("result=error");
    });
});
//# sourceMappingURL=conversation-memory-expunge-emit.test.js.map