// Task 168 — per-tool emit assertion for memory-empty-trash.
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { setupEmitCapture, makeMockSession } from "./_helpers/emit-capture.js";
const mockSession = makeMockSession();
vi.mock("../../lib/neo4j.js", () => ({
    getSession: () => mockSession,
}));
vi.mock("../../../../../../lib/graph-trash/dist/index.js", () => ({
    emptyTrash: vi.fn(),
}));
vi.mock("../../lib/attachments.js", () => ({
    removeAttachmentDir: vi.fn().mockResolvedValue(undefined),
}));
import { memoryEmptyTrash } from "../memory-empty-trash.js";
import { emptyTrash } from "../../../../../../lib/graph-trash/dist/index.js";
describe("memory-empty-trash — emit wrapper wired", () => {
    let emit;
    beforeEach(() => {
        emit = setupEmitCapture();
        vi.mocked(emptyTrash).mockReset();
    });
    afterEach(() => emit.restore());
    it("emits result=ok line on happy path", async () => {
        vi.mocked(emptyTrash).mockResolvedValue({
            graceDays: 30,
            dryRun: false,
            candidates: [],
            emptied: 0,
        });
        await memoryEmptyTrash({ accountId: "acct-1" });
        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("memory-empty-trash");
        expect(body.line).toContain("result=ok");
    });
    it("emits result=error line when emptyTrash throws", async () => {
        vi.mocked(emptyTrash).mockRejectedValue(new Error("session expired"));
        await expect(memoryEmptyTrash({ accountId: "acct-1" })).rejects.toThrow(/session expired/);
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.level).toBe("error");
        expect(body.line).toContain("memory-empty-trash");
        expect(body.line).toContain("result=error");
    });
});
//# sourceMappingURL=memory-empty-trash-emit.test.js.map