// Task 168 — per-tool emit assertion for memory-reindex.
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/embeddings.js", () => ({
    embedBatch: vi.fn().mockResolvedValue([]),
}));
import { memoryReindex } from "../memory-reindex.js";
describe("memory-reindex — emit wrapper wired", () => {
    let emit;
    beforeEach(() => {
        emit = setupEmitCapture();
        mockSession.run.mockReset();
        mockSession.close.mockReset();
    });
    afterEach(() => emit.restore());
    it("emits result=ok line on happy path (all nodes have embeddings)", async () => {
        // First call: count returns total=0, tool returns early.
        mockSession.run.mockResolvedValueOnce({
            records: [{ get: () => ({ toNumber: () => 0 }) }],
        });
        await memoryReindex("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-reindex");
        expect(body.line).toContain("result=ok");
    });
    it("emits result=error line when session.run throws", async () => {
        mockSession.run.mockRejectedValue(new Error("driver disconnected"));
        await expect(memoryReindex("acct-1")).rejects.toThrow(/driver disconnected/);
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.level).toBe("error");
        expect(body.line).toContain("memory-reindex");
        expect(body.line).toContain("result=error");
    });
});
//# sourceMappingURL=memory-reindex-emit.test.js.map