// Task 168 — per-tool emit assertion for memory-ingest-extract.
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { setupEmitCapture } from "./_helpers/emit-capture.js";
vi.mock("node:fs/promises", async () => {
    const actual = await vi.importActual("node:fs/promises");
    return {
        ...actual,
        readFile: vi.fn().mockResolvedValue("hello world\n"),
        stat: vi.fn().mockResolvedValue({ size: 12 }),
    };
});
import { memoryIngestExtract } from "../memory-ingest-extract.js";
describe("memory-ingest-extract — emit wrapper wired", () => {
    let emit;
    beforeEach(() => {
        emit = setupEmitCapture();
    });
    afterEach(() => emit.restore());
    it("emits result=ok line on happy path (text/plain)", async () => {
        await memoryIngestExtract({
            storagePath: "/tmp/task-168/stub.txt",
            filename: "stub.txt",
            mimeType: "text/plain",
            attachmentId: "00000000-0000-0000-0000-000000000001",
        });
        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-ingest-extract");
        expect(body.line).toContain("result=ok");
    });
    it("emits result=error line when attachmentId is missing (invalid-input)", async () => {
        await expect(memoryIngestExtract({
            storagePath: "/tmp/task-168/stub.txt",
            filename: "stub.txt",
            mimeType: "text/plain",
            attachmentId: "",
        })).rejects.toThrow(/requires attachmentId/);
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.level).toBe("error");
        expect(body.line).toContain("memory-ingest-extract");
        expect(body.line).toContain("result=error");
    });
});
//# sourceMappingURL=memory-ingest-extract-emit.test.js.map