/**
 * Task 595 — inline compiled-truth reconciliation gate in memory-ingest.
 *
 * All assertions read source to avoid live-DB dependencies, matching the
 * pattern established by the existing memory-ingest.test.ts suite.
 */
import { describe, it, expect } from "vitest";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
const INGEST_PATH = resolve(import.meta.dirname, "../../tools/memory-ingest.ts");
function src() {
    return readFileSync(INGEST_PATH, "utf-8");
}
describe("memory-ingest — inline compiled-truth gate (Task 595)", () => {
    it("IngestParams declares inlineRewrite, forceRewrite, inlineRewriteThreshold", () => {
        const s = src();
        expect(s).toContain("inlineRewrite?: boolean");
        expect(s).toContain("forceRewrite?: boolean");
        expect(s).toContain("inlineRewriteThreshold?: number");
    });
    it("IngestResult declares inlineRewriteCandidates and inlineRewriteDeferred optional fields", () => {
        const s = src();
        expect(s).toMatch(/inlineRewriteCandidates\?:\s*InlineRewriteCandidate\[\]/);
        expect(s).toMatch(/inlineRewriteDeferred\?:\s*InlineRewriteDeferred\[\]/);
    });
    it("imports InlineRewriteCandidate and InlineRewriteDeferred from compiled-truth-revision", () => {
        const s = src();
        expect(s).toContain("InlineRewriteCandidate");
        expect(s).toContain("InlineRewriteDeferred");
        expect(s).toMatch(/from ["']\.\.\/lib\/compiled-truth-revision\.js["']/);
    });
    it("queryInlineRewriteCandidates queries MENTIONS and REFERENCES edges via HAS_SECTION*0..1", () => {
        const s = src();
        expect(s).toContain("queryInlineRewriteCandidates");
        expect(s).toContain("HAS_SECTION*0..1");
        expect(s).toMatch(/MENTIONS\|REFERENCES/);
    });
    it("label extraction uses known primary-label allowlist for deterministic ordering", () => {
        const s = src();
        // Must not use NOT IN filter (non-deterministic ordering for multi-labeled nodes).
        // Must use IN filter against a closed set of compiledTruth-bearing labels.
        expect(s).toMatch(/l IN \[.*'Person'.*'Organization'.*'Concept'/);
        expect(s).not.toContain("l NOT IN ['Trashed']");
    });
    it("gate only runs when inlineRewrite param is true", () => {
        const s = src();
        expect(s).toMatch(/if\s*\(\s*params\.inlineRewrite\s*\)/);
    });
    it("applies 7-day cooldown window and forceRewrite bypass", () => {
        const s = src();
        expect(s).toContain("7 * 24 * 60 * 60 * 1000");
        expect(s).toMatch(/params\.forceRewrite/);
    });
    it("emits the observability log line with op=compiled-truth-inline", () => {
        const s = src();
        expect(s).toContain("op=compiled-truth-inline");
        expect(s).toContain("entitiesChecked=");
        expect(s).toContain("entitiesRecompiled=");
        expect(s).toContain("entitiesDeferred=");
    });
    it("default threshold is 2 when inlineRewriteThreshold is not provided", () => {
        const s = src();
        expect(s).toContain("inlineRewriteThreshold ?? 2");
    });
});
//# sourceMappingURL=memory-ingest-inline-rewrite.test.js.map