import { describe, it, expect } from "vitest";
import { CONVERSATION_SOURCES, isConversationSource, } from "../../lib/conversation-normalisers/types.js";
import { getNormaliser, whatsappTextNormaliser } from "../../lib/conversation-normalisers/index.js";
// ---------------------------------------------------------------------------
// source-agnosticism contract.
//
// The point of the refactor is that every normaliser produces the SAME
// `ParsedLine[]` shape and the SAME NormaliserResult contract regardless of
// source. Downstream pipeline code (sessionize, classify, memory-ingest)
// must not branch on `source` — only on the normaliser output.
//
// This file pins that contract: a stub normaliser and the live whatsapp-text
// normaliser are interchangeable from the writer's perspective; `source`
// flows through as a property only.
// ---------------------------------------------------------------------------
describe("ConversationSource enum", () => {
    it("includes the closed Phase-0 set", () => {
        const expected = [
            "whatsapp",
            "telegram",
            "signal",
            "linkedin-messages",
            "zoom-transcript",
            "meeting-minutes",
            "imessage",
            "slack",
            "x-dm",
            "email",
            "other",
        ];
        expect([...CONVERSATION_SOURCES].sort()).toEqual(expected.sort());
    });
    it("isConversationSource accepts members and rejects everything else", () => {
        expect(isConversationSource("whatsapp")).toBe(true);
        expect(isConversationSource("slack")).toBe(true);
        expect(isConversationSource("Whatsapp")).toBe(false); // case-sensitive enum
        expect(isConversationSource("twitter")).toBe(false);
        expect(isConversationSource(undefined)).toBe(false);
        expect(isConversationSource(123)).toBe(false);
    });
});
describe("getNormaliser registry", () => {
    it("returns the whatsapp-text normaliser for source='whatsapp'", () => {
        expect(getNormaliser("whatsapp")).toBe(whatsappTextNormaliser);
    });
    it("loud-fails on an enum member that has no normaliser yet", () => {
        expect(() => getNormaliser("telegram")).toThrow(/no normaliser implemented for source="telegram"/);
    });
});
describe("ConversationNormaliser shape parity", () => {
    // A stub normaliser — proves the pipeline path is uniform across sources.
    const stubNormaliser = () => ({
        parsedLines: [
            { dateSent: "2026-04-30T10:00:00+00:00", body: "Alice: hi", sequenceIndex: 0 },
            { dateSent: "2026-04-30T10:01:00+00:00", body: "Bob: yo", sequenceIndex: 1 },
        ],
        archiveSha256: "0".repeat(64),
        archiveSourceFile: "stub.txt",
        counters: { parsed: 2, systemSkipped: 0, mediaSkipped: 0, parseErrors: 0 },
    });
    it("a stub normaliser and the live whatsapp-text normaliser produce structurally identical NormaliserResult shapes", () => {
        const stubResult = stubNormaliser({ filePath: "/dev/null", accountId: "acct", timezone: "UTC" });
        expect("parsedLines" in stubResult).toBe(true);
        expect("archiveSha256" in stubResult).toBe(true);
        expect("archiveSourceFile" in stubResult).toBe(true);
        expect("counters" in stubResult).toBe(true);
        // ParsedLine has dateSent, body, sequenceIndex — no senderName.
        // Bodies carry the source's `Sender:` prefix verbatim.
        const line = stubResult.parsedLines[0];
        expect(typeof line.dateSent).toBe("string");
        expect(typeof line.body).toBe("string");
        expect(typeof line.sequenceIndex).toBe("number");
    });
});
//# sourceMappingURL=conversation-normalisers-source-agnosticism.test.js.map