// Task 168 — per-tool emit assertion for memory-classify.
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { setupEmitCapture } from "./_helpers/emit-capture.js";
vi.mock("../memory-ingest-extract.js", () => ({
    extractCache: new Map(),
    memoryIngestExtract: vi.fn(),
}));
vi.mock("../../lib/llm-classifier.js", () => ({
    classifyDocument: vi.fn(),
}));
import { memoryClassify } from "../memory-classify.js";
import { extractCache } from "../memory-ingest-extract.js";
import { classifyDocument } from "../../lib/llm-classifier.js";
const liveSchemaSource = {
    recognisedLabels: () => new Set(["UserProfile", "Position", "Education"]),
};
describe("memory-classify — emit wrapper wired", () => {
    let emit;
    beforeEach(() => {
        emit = setupEmitCapture();
        vi.mocked(classifyDocument).mockReset();
        extractCache.clear();
    });
    afterEach(() => emit.restore());
    it("emits result=ok line on happy path", async () => {
        extractCache.set("att-1", { text: "doc body" });
        vi.mocked(classifyDocument).mockResolvedValue({
            sections: [],
            documentEdges: [],
        });
        await memoryClassify({
            accountId: "acct-1",
            attachmentId: "att-1",
            anchorDescription: "subject = UserProfile",
            liveSchemaSource,
        });
        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-classify");
        expect(body.line).toContain("result=ok");
    });
    it("emits result=error line when cached extract is missing", async () => {
        await expect(memoryClassify({
            accountId: "acct-1",
            attachmentId: "missing",
            anchorDescription: "subject = UserProfile",
            liveSchemaSource,
        })).rejects.toThrow(/No cached extract/);
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.level).toBe("error");
        expect(body.line).toContain("memory-classify");
        expect(body.line).toContain("result=error");
    });
});
//# sourceMappingURL=memory-classify-emit.test.js.map