import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { resolve } from "node:path";
// Task 636 — a Preference proposal must carry an embedding so the wired node is
// findable by vector search at creation, not only after a reindex.
const mockSession = {
    run: vi.fn(),
    close: vi.fn().mockResolvedValue(undefined),
};
vi.mock("../../lib/neo4j.js", () => ({ getSession: () => mockSession }));
vi.mock("../../lib/log-ingest.js", () => ({
    withWriteEvent: async (_i, body) => body(),
}));
vi.mock("../../lib/embeddings.js", () => ({
    embed: vi.fn().mockResolvedValue([0.4, 0.5, 0.6]),
}));
describe("conversation-archive-derive-insights — preference embedding", () => {
    let scratch;
    let orig;
    let deriveInsights;
    beforeEach(async () => {
        scratch = mkdtempSync(resolve(tmpdir(), "pref-embed-"));
        orig = process.env.PLATFORM_ROOT;
        process.env.PLATFORM_ROOT = resolve(scratch, "platform");
        mockSession.run.mockReset();
        vi.resetModules();
        deriveInsights = (await import("../conversation-archive-derive-insights.js"))
            .conversationArchiveDeriveInsights;
    });
    afterEach(() => {
        if (orig === undefined)
            delete process.env.PLATFORM_ROOT;
        else
            process.env.PLATFORM_ROOT = orig;
        rmSync(scratch, { recursive: true, force: true });
    });
    it("embeds the Preference proposal (mergeCypher + mergeParams)", async () => {
        mockSession.run.mockResolvedValueOnce({
            records: [{ get: (k) => (k === "eid" ? "4:CHUNK:1" : null) }],
        });
        const result = await deriveInsights({
            accountId: "acct",
            archiveElementId: "4:ARCH:1",
            chunkElementId: "4:CHUNK:1",
            claims: [
                {
                    kind: "preference",
                    evidenceSnippet: "only meets on Tuesdays",
                    subject: null,
                    object: null,
                    payload: {
                        preferenceCategory: "meeting",
                        preferenceKey: "day-of-week",
                        preferenceValue: "Tuesday",
                    },
                },
            ],
        });
        expect(result.proposals).toHaveLength(1);
        const p = result.proposals[0];
        expect(p.kind).toBe("preference");
        expect(p.mergeCypher).toContain("p.embedding = $embedding");
        expect(p.mergeParams.embedding).toEqual([0.4, 0.5, 0.6]);
    });
});
//# sourceMappingURL=conversation-archive-preference-embed.test.js.map