// @vitest-environment node
import { describe, it, expect, vi } from "vitest";
import { normaliseTagStr } from "../dream-cycle/phase-tag-normalisation.js";
describe("normaliseTagStr", () => {
    it("lowercases and strips non-alphanumeric non-separator chars", () => {
        expect(normaliseTagStr("AI")).toBe("ai");
        expect(normaliseTagStr("ai")).toBe("ai");
        expect(normaliseTagStr("A.I.")).toBe("ai");
        expect(normaliseTagStr("machine-learning")).toBe("machine-learning");
        expect(normaliseTagStr("  spaced  ")).toBe("spaced");
        expect(normaliseTagStr("C++")).toBe("c");
    });
});
describe("phaseTagNormalisation", () => {
    it("returns phase=7, name='tag-normalisation', applies merged count", async () => {
        // Simulate: 2 KD nodes with tags; node eid-1 needs normalisation.
        // 1 DefinedTerm group with 2 variants.
        const runMock = vi.fn()
            // Call 1: find KD nodes with tags
            .mockResolvedValueOnce({
            records: [
                { get: (k) => k === "eid" ? "eid-1" : ["AI", "A.I."] },
                { get: (k) => k === "eid" ? "eid-2" : ["machine-learning"] },
            ],
        })
            // Call 2: update KD node eid-1 (tags changed)
            .mockResolvedValueOnce({ records: [] })
            // Call 3: find DefinedTerm variants
            .mockResolvedValueOnce({
            records: [
                { get: (k) => k === "eid" ? "dt-1" : (k === "name" ? "AI" : undefined) },
                { get: (k) => k === "eid" ? "dt-2" : (k === "name" ? "ai" : undefined) },
            ],
        })
            // Call 4: retarget edges for dt-2 → dt-1 canonical
            .mockResolvedValueOnce({ records: [] });
        const ctx = {
            accountId: "acc-1",
            session: { run: runMock },
            config: {},
        };
        const { phaseTagNormalisation } = await import("../dream-cycle/phase-tag-normalisation.js");
        const result = await phaseTagNormalisation(ctx);
        expect(result.phase).toBe(7);
        expect(result.name).toBe("tag-normalisation");
        // 1 KD node updated + 1 DefinedTerm merged = 2
        expect(result.applied).toBe(2);
        expect(result.deferred).toBe(0);
    });
});
//# sourceMappingURL=phase-tag-normalisation.test.js.map