// Task 168 — per-tool emit assertion for memory-rename-attachment.
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/attachments.js", () => ({
    assertUUID: vi.fn(),
    readMeta: vi.fn(),
    attachmentDir: () => "/tmp/task-168-stub",
}));
vi.mock("node:fs/promises", async () => {
    const actual = await vi.importActual("node:fs/promises");
    return { ...actual, writeFile: vi.fn().mockResolvedValue(undefined) };
});
import { memoryRenameAttachment } from "../memory-rename-attachment.js";
import { readMeta } from "../../lib/attachments.js";
describe("memory-rename-attachment — emit wrapper wired", () => {
    let emit;
    beforeEach(() => {
        emit = setupEmitCapture();
        vi.mocked(readMeta).mockReset();
        mockSession.run.mockReset();
    });
    afterEach(() => emit.restore());
    it("emits result=ok line on happy path (filename unchanged → no-op)", async () => {
        vi.mocked(readMeta).mockResolvedValue({
            filename: "same.md",
            mimeType: "text/markdown",
            attachmentId: "00000000-0000-0000-0000-000000000001",
            sizeBytes: 0,
            uploadedAt: "2026-01-01T00:00:00Z",
        });
        await memoryRenameAttachment({
            accountId: "acct-1",
            attachmentId: "00000000-0000-0000-0000-000000000001",
            newFilename: "same.md",
        });
        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-rename-attachment");
        expect(body.line).toContain("result=ok");
    });
    it("emits result=error line on empty newFilename (invalid-input)", async () => {
        await expect(memoryRenameAttachment({
            accountId: "acct-1",
            attachmentId: "00000000-0000-0000-0000-000000000001",
            newFilename: "",
        })).rejects.toThrow(/must not be empty/);
        expect(emit.fetchSpy).toHaveBeenCalledTimes(1);
        const body = emit.captures()[0];
        expect(body.level).toBe("error");
        expect(body.line).toContain("memory-rename-attachment");
        expect(body.line).toContain("result=error");
        // "must not be empty" does not match classifyReason's `must be ` pattern,
        // so it falls through to neo4j-driver-error (the closed-enum catch-all).
        // The contract being verified is wrapper wiring per tool, not the slug
        // mapping — that's covered exhaustively in log-ingest.test.ts.
        expect(body.line).toContain("reason=neo4j-driver-error");
    });
});
//# sourceMappingURL=memory-rename-attachment-emit.test.js.map