// Task 168 — per-tool emit assertion for memory-restore.
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { setupEmitCapture, makeMockSession } from "./_helpers/emit-capture.js";
const mockSession = makeMockSession([
// restoreNode call uses session.run; the children walk runs a second query.
// We mock restoreNode directly below so these sequence rows don't fire.
]);
vi.mock("../../lib/neo4j.js", () => ({
    getSession: () => mockSession,
}));
vi.mock("../../../../../../lib/graph-trash/dist/index.js", () => ({
    restoreNode: vi.fn(),
}));
import { memoryRestore } from "../memory-restore.js";
import { restoreNode } from "../../../../../../lib/graph-trash/dist/index.js";
describe("memory-restore — emit wrapper wired", () => {
    let emit;
    beforeEach(() => {
        emit = setupEmitCapture();
        vi.mocked(restoreNode).mockReset();
        mockSession.run.mockReset();
    });
    afterEach(() => emit.restore());
    it("emits result=ok line on happy path", async () => {
        vi.mocked(restoreNode).mockResolvedValue({
            restored: true,
            nodeId: "4:eid:1",
            labels: ["Person"],
            restoredKeys: {},
        });
        await memoryRestore({ accountId: "acct-1", elementId: "4:eid: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-restore");
        expect(body.line).toContain("result=ok");
    });
    it("emits result=error line when restoreNode throws", async () => {
        vi.mocked(restoreNode).mockRejectedValue(new Error("conflicting unique-key holder"));
        await expect(memoryRestore({ accountId: "acct-1", elementId: "4:eid:1" })).rejects.toThrow(/conflicting/);
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.level).toBe("error");
        expect(body.line).toContain("memory-restore");
        expect(body.line).toContain("result=error");
    });
});
//# sourceMappingURL=memory-restore-emit.test.js.map