// Task 413 / Task 420 — operator-hint folding in the compiled-truth rewriter.
//
// Validates: hint appears verbatim in the user message in both admin and
// public modes; empty/oversize hints throw; the no-events refusal yields
// when a hint is supplied (operator correction is sufficient justification).
import { describe, it, expect, vi, beforeEach } from "vitest";
const callOauthLlmMock = vi.fn();
vi.mock("../../../../../../lib/oauth-llm/dist/index.js", () => ({
    callOauthLlm: (...args) => callOauthLlmMock(...args),
}));
import { rewriteCompiledTruth, OPERATOR_HINT_MAX_CHARS } from "../compiled-truth-rewriter.js";
describe("compiled-truth-rewriter — operator hint (Task 413)", () => {
    beforeEach(() => {
        callOauthLlmMock.mockReset();
        callOauthLlmMock.mockResolvedValue({ kind: "ok", text: "Rewritten summary." });
    });
    it("folds the operator hint into the user message with precedence wording", async () => {
        await rewriteCompiledTruth({
            subjectLabel: "Person",
            subjectName: "Adam Langley",
            currentTruth: "Adam used to work at Acme.",
            events: [
                { occurredAt: "2026-05-01T00:00:00Z", kind: "mentioned", summary: "Mentioned in chat" },
            ],
            operatorHint: "Adam now works at Anthropic, not Acme.",
        });
        const call = callOauthLlmMock.mock.calls[0][0];
        expect(call.userMessage).toContain("Operator correction");
        expect(call.userMessage).toContain("Adam now works at Anthropic, not Acme.");
        expect(call.system).toContain("Operator correction is supplied and contradicts the timeline");
    });
    it("folds the operator hint into public-mode user message and uses the public-voice system prompt", async () => {
        await rewriteCompiledTruth({
            mode: "public",
            subjectLabel: "Organization",
            subjectName: "Acme",
            currentTruth: "",
            events: [
                { occurredAt: "2026-05-01T00:00:00Z", kind: "mentioned", summary: "ev" },
            ],
            operatorHint: "Acme acquired BetaCo in 2026.",
        });
        const call = callOauthLlmMock.mock.calls[0][0];
        expect(call.userMessage).toContain("Operator correction");
        expect(call.userMessage).toContain("Acme acquired BetaCo in 2026.");
        // Public-voice rules carry through — operator-voice phrasings remain banned.
        expect(call.system).toContain("public-facing");
        expect(call.system).toContain("No operator-voice constructions");
        expect(call.system).toContain("Operator correction is supplied");
    });
    it("rejects empty operatorHint", async () => {
        await expect(rewriteCompiledTruth({
            subjectLabel: "Person",
            subjectName: "Adam",
            currentTruth: "",
            events: [],
            operatorHint: "   ",
        })).rejects.toThrow(/non-empty/);
    });
    it("rejects operatorHint over the cap", async () => {
        await expect(rewriteCompiledTruth({
            subjectLabel: "Person",
            subjectName: "Adam",
            currentTruth: "",
            events: [],
            operatorHint: "x".repeat(OPERATOR_HINT_MAX_CHARS + 1),
        })).rejects.toThrow(/exceeds cap/);
    });
    it("no-events refusal yields when an operator hint is supplied", async () => {
        // Without a hint, an empty timeline refuses.
        const refused = await rewriteCompiledTruth({
            subjectLabel: "Person",
            subjectName: "Adam",
            currentTruth: "",
            events: [],
        });
        expect(refused).toEqual({ kind: "refused", reason: "no-events" });
        // With a hint, the rewriter proceeds even with an empty timeline —
        // the operator correction is sufficient new material.
        const result = await rewriteCompiledTruth({
            subjectLabel: "Person",
            subjectName: "Adam",
            currentTruth: "",
            events: [],
            operatorHint: "Adam joined Anthropic in 2025.",
        });
        expect(result.kind).toBe("ok");
    });
});
//# sourceMappingURL=compiled-truth-rewriter-operator-hint.test.js.map