// Task 168 — per-tool emit assertion for memory-delete.
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", () => ({
    trashNode: vi.fn(),
}));
vi.mock("../../lib/filter-token.js", () => ({
    verifyFilterToken: vi.fn(),
    filterTokenFingerprint: () => "fp",
}));
vi.mock("../memory-find-candidates.js", () => ({
    reverifyCandidate: vi.fn(),
}));
import { memoryDelete } from "../memory-delete.js";
import { trashNode } from "../../../../../../lib/graph-trash/dist/index.js";
import { verifyFilterToken } from "../../lib/filter-token.js";
describe("memory-delete — emit wrapper wired", () => {
    let emit;
    beforeEach(() => {
        emit = setupEmitCapture();
        vi.mocked(trashNode).mockReset();
        vi.mocked(verifyFilterToken).mockReset();
        mockSession.run.mockReset();
        // Task 443 — memoryDelete now resolves the target's labels before
        // calling trashNode. Return an empty label list so the gate passes
        // and the existing happy/error paths still flow through trashNode.
        mockSession.run.mockResolvedValue({
            records: [{ get: (k) => (k === "labels" ? [] : undefined) }],
        });
    });
    afterEach(() => emit.restore());
    it("emits result=ok line on happy path (no filter token)", async () => {
        vi.mocked(trashNode).mockResolvedValue({
            trashed: true,
            alreadyTrashed: false,
            nodeId: "4:eid:1",
            labels: ["Person"],
            trashedAt: "2026-05-19T00:00:00Z",
            originalKeys: {},
        });
        await memoryDelete({ 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-delete");
        expect(body.line).toContain("result=ok");
    });
    it("emits result=error line when trashNode throws", async () => {
        vi.mocked(trashNode).mockRejectedValue(new Error("Node not found or not owned by this account (ID: 4:eid:1)."));
        await expect(memoryDelete({ accountId: "acct-1", elementId: "4:eid:1" })).rejects.toThrow(/not found/);
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.level).toBe("error");
        expect(body.line).toContain("memory-delete");
        expect(body.line).toContain("result=error");
        expect(body.line).toContain("reason=invalid-input");
    });
});
//# sourceMappingURL=memory-delete-emit.test.js.map