import { describe, it, expect } from "vitest";
import { TYPED_EDGE_ALLOWLIST, TYPED_EDGE_TYPES, PROSE_BEARING_LABELS, isAllowedTypedEdge, isTypedEntityEdgeType, } from "../typed-edge-schema.js";
describe("typed-edge-schema", () => {
    it("exports a non-empty allowlist", () => {
        expect(TYPED_EDGE_ALLOWLIST.length).toBeGreaterThan(0);
    });
    it("covers the nine seed edge types from the task brief", () => {
        const expected = [
            "ATTENDED",
            "WORKS_AT",
            "INVESTED_IN",
            "FOUNDED",
            "ADVISES",
            "MENTIONS",
            "AUTHORED",
            "ATTACHED_TO",
            "REFERENCES",
        ].sort();
        expect([...TYPED_EDGE_TYPES]).toEqual(expected);
    });
    it("PROSE_BEARING_LABELS matches the brief", () => {
        expect([...PROSE_BEARING_LABELS].sort()).toEqual(["ConversationArchive", "Idea", "KnowledgeDocument", "Meeting", "Message", "Note", "Page", "Post", "Report"].sort());
    });
    it("accepts a known-legal triple", () => {
        expect(isAllowedTypedEdge("Person", "FOUNDED", "Organization")).toBe(true);
        expect(isAllowedTypedEdge("Person", "ATTENDED", "Event")).toBe(true);
        expect(isAllowedTypedEdge("Message", "MENTIONS", "Person")).toBe(true);
    });
    it("rejects a triple not in the allowlist", () => {
        expect(isAllowedTypedEdge("Person", "IS", "City")).toBe(false);
        expect(isAllowedTypedEdge("Person", "FOUNDED", "City")).toBe(false);
        expect(isAllowedTypedEdge("Event", "ATTENDED", "Person")).toBe(false);
    });
    it("every allowlist entry has non-empty strings", () => {
        for (const pair of TYPED_EDGE_ALLOWLIST) {
            expect(pair.sourceLabel.length).toBeGreaterThan(0);
            expect(pair.edgeType.length).toBeGreaterThan(0);
            expect(pair.targetLabel.length).toBeGreaterThan(0);
        }
    });
    it("isTypedEntityEdgeType identifies edge types present in the allowlist", () => {
        // Task 482 — document-ingest's writer uses this to decide whether to
        // validate a classifier-emitted edge's source/target labels.
        expect(isTypedEntityEdgeType("FOUNDED")).toBe(true);
        expect(isTypedEntityEdgeType("WORKS_AT")).toBe(true);
        expect(isTypedEntityEdgeType("INVESTED_IN")).toBe(true);
        expect(isTypedEntityEdgeType("ADVISES")).toBe(true);
        expect(isTypedEntityEdgeType("MENTIONS")).toBe(true);
    });
    it("isTypedEntityEdgeType returns false for document-ingest-only edges absent from the allowlist", () => {
        expect(isTypedEntityEdgeType("HAS_SECTION")).toBe(false);
        expect(isTypedEntityEdgeType("NEXT")).toBe(false);
        expect(isTypedEntityEdgeType("HAS_POSITION")).toBe(false);
        expect(isTypedEntityEdgeType("AT")).toBe(false);
        expect(isTypedEntityEdgeType("PARTY")).toBe(false);
        expect(isTypedEntityEdgeType("PARTICIPANT")).toBe(false);
        expect(isTypedEntityEdgeType("SPEAKER")).toBe(false);
        expect(isTypedEntityEdgeType("DEFINES")).toBe(false);
    });
    it("documents that :FOUNDED targeting :Section is rejected (Task 482 regression)", () => {
        // The BioSymm website ingest defect: classifier emitted
        // `(:Person)-[:FOUNDED]->(:Section)` for founders in a Team section.
        // The writer guard rejects this because `Section` is not a valid
        // FOUNDED target. The correct shape lands on `:Organization`.
        expect(isAllowedTypedEdge("Person", "FOUNDED", "Section")).toBe(false);
        expect(isAllowedTypedEdge("Section", "FOUNDED", "Person")).toBe(false);
        expect(isAllowedTypedEdge("Person", "FOUNDED", "Organization")).toBe(true);
        expect(isAllowedTypedEdge("Person", "FOUNDED", "LocalBusiness")).toBe(true);
    });
    it("no duplicate entries in the allowlist", () => {
        const seen = new Set();
        for (const { sourceLabel, edgeType, targetLabel } of TYPED_EDGE_ALLOWLIST) {
            const key = `${sourceLabel}|${edgeType}|${targetLabel}`;
            expect(seen.has(key)).toBe(false);
            seen.add(key);
        }
    });
});
//# sourceMappingURL=typed-edge-schema.test.js.map