/**
 * area-summary.test.ts — Tests 1-4 for the deterministic area-summary card.
 *
 * D0042: vitest only, no node:test.
 * D0045: AreaSummaryBodySchema satisfies z.ZodType<AreaSummaryBody> compile-time gate.
 */
import { describe, expect, it } from "vitest";
import { AreaSummaryBodySchema, generateAreaSummary } from "../area-summary.js";
// Test 1: schema satisfies compile-time gate
const _satisfiesCheck = AreaSummaryBodySchema;
const silentLogger = {
    debug: () => { },
    info: () => { },
    warn: () => { },
    error: () => { },
    step: () => { },
    section: () => { },
    table: () => { },
};
const noopProgress = {
    phaseStart: () => { },
    phaseProgress: () => { },
    phaseComplete: () => { },
};
function makeCtx() {
    return {
        llm: undefined,
        model: "anthropic:claude-sonnet-4-6",
        logger: silentLogger,
        progress: noopProgress,
        versions: {
            graderJudgmentsVersion: "1.0.0",
            ensembleVersion: "1.0.0",
            diagnosisVersion: "0.1.0",
            cardVersion: "1.0.0",
        },
        runId: "run-001",
        reportId: "report-001",
    };
}
function makeReportWithScores(scores) {
    return {
        id: "report-001",
        completedAt: "2026-01-01T00:00:00Z",
        durationMs: 1000,
        provenance: {
            runId: "run-001",
            mode: "standard",
            areas: [],
            taskIds: [],
            models: [],
            graderModel: "gpt-4o",
            source: "local",
            evalFingerprint: "",
            trigger: "manual",
            git: undefined,
        },
        summary: {
            belowCritical: [],
            lowestArea: "groq",
            lowestScore: Math.min(...(scores.length ? scores : [0])),
            overall: {
                avgCeilingScore: 80,
                avgScore: 75,
                avgDocLift: 5,
                avgDocQualityGap: 20,
                avgFloorScore: 70,
                negativeDocLiftCount: 0,
            },
            scores: scores.map((s, i) => ({
                feature: `area-${i + 1}`,
                ceilingScore: 80,
                codeCorrectness: s,
                docCoverage: s,
                docLift: 5,
                docQualityGap: 20,
                floorScore: s - 5,
                negativeDocLift: false,
                taskCompletion: s,
                testCount: 10,
                totalCost: 0.05,
                totalScore: s,
            })),
        },
    };
}
describe("AreaSummaryBodySchema (Test 1)", () => {
    it("satisfies z.ZodType<AreaSummaryBody> (compile-time check assigned above)", () => {
        // Runtime check: valid payload parses successfully
        const result = AreaSummaryBodySchema.safeParse({ summary: "test summary" });
        expect(result.success).toBe(true);
        // The _satisfiesCheck assignment above is the actual compile-time gate
        expect(_satisfiesCheck).toBeDefined();
    });
});
describe("generateAreaSummary (Test 2)", () => {
    it("returns a ready card with summary including area count and mean score for 3 areas at [80, 60, 70]", async () => {
        const report = makeReportWithScores([80, 60, 70]);
        const card = await generateAreaSummary(report, makeCtx());
        expect(card.status).toBe("ready");
        if (card.status === "ready") {
            expect(card.cardType).toBe("area-summary");
            expect(card.meta.cardVersion).toBe("area-summary@0.1.0");
            expect(card.meta.generatedAt).toBeTruthy();
        }
    });
});
describe("generateAreaSummary — summary content (Test 3)", () => {
    it("summary includes BOTH the area count AND mean score to one decimal", async () => {
        const report = makeReportWithScores([80, 60, 70]);
        const card = await generateAreaSummary(report, makeCtx());
        expect(card.status).toBe("ready");
        if (card.status === "ready") {
            const body = card.body;
            // Mean of [80, 60, 70] = 70.0
            expect(body.summary).toContain("3");
            expect(body.summary).toContain("70.0");
        }
    });
});
describe("generateAreaSummary — zero areas guard (Test 4)", () => {
    it("returns missing card with 'report has no areas' reason for zero-area report", async () => {
        const report = makeReportWithScores([]);
        const card = await generateAreaSummary(report, makeCtx());
        expect(card.status).toBe("missing");
        if (card.status === "missing") {
            expect(card.cardType).toBe("area-summary");
            expect(card.reason).toContain("no areas");
        }
    });
});
