// Task 168 — per-tool emit assertion for memory-ingest.
//
// Happy-path stub would require unraveling document-hierarchy, embeddings,
// llm-classifier, graph-trash, and the entire section-write cypher batch —
// out of proportion with the brief's "minimal new test file" guidance. The
// error path is sufficient to verify the wrapper-is-wired contract per the
// brief's drop-wrapper experiment, plus a no-deep-deps happy path via the
// conversation-document branch is verified by the existing memory-ingest
// behaviour tests (content gates in memory-ingest.test.ts).
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", () => ({
    embed: vi.fn(),
    embedBatch: vi.fn(),
}));
vi.mock("../memory-ingest-extract.js", () => ({
    extractCache: new Map(),
    memoryIngestExtract: vi.fn(),
}));
vi.mock("../../lib/document-hierarchy.js", () => ({
    deleteDocumentChildren: vi.fn(),
}));
vi.mock("../../../../../../lib/graph-trash/dist/index.js", () => ({
    restoreNode: vi.fn(),
}));
import { memoryIngest } from "../memory-ingest.js";
describe("memory-ingest — emit wrapper wired", () => {
    let emit;
    beforeEach(() => {
        emit = setupEmitCapture();
        mockSession.run.mockReset();
    });
    afterEach(() => emit.restore());
    it("emits result=error reason=invalid-input on missing scope", async () => {
        await expect(memoryIngest({
            accountId: "acct-1",
            attachmentId: "att-1",
            documentSummary: "doc",
            anchorNodeId: "4:anchor:1",
            anchorLabel: "UserProfile",
            sections: [],
            scope: "",
        })).rejects.toThrow(/scope is required/);
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.tag).toBe("mcp:memory");
        expect(body.level).toBe("error");
        expect(body.line).toContain("memory-ingest");
        expect(body.line).toContain("result=error");
        expect(body.line).toContain("reason=invalid-input");
    });
    it("emits result=error on missing anchorNodeId (invalid-input via 'is required')", async () => {
        await expect(memoryIngest({
            accountId: "acct-1",
            attachmentId: "att-1",
            documentSummary: "doc",
            anchorNodeId: "",
            anchorLabel: "UserProfile",
            sections: [],
            scope: "shared",
        })).rejects.toThrow(/anchorNodeId is required/);
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.level).toBe("error");
        expect(body.line).toContain("memory-ingest");
        expect(body.line).toContain("result=error");
        expect(body.line).toContain("reason=invalid-input");
    });
});
//# sourceMappingURL=memory-ingest-emit.test.js.map