import { buildDriftAnalysisPrompt, DRIFT_STEP_ASSESS, DRIFT_STEP_ENDPOINT_EXISTENCE, DRIFT_STEP_RESPONSE_SHAPE, DRIFT_STEP_ADDITIVE_FIELDS, DRIFT_STEP_AUTH_AUTHZ, DRIFT_STEP_BEHAVIORAL_CONTRACT, DRIFT_STEP_ASSIGN_ACTION, DRIFT_STEP_APPLY, DRIFT_STEP_CALL_TOOL, } from "./drift-analysis-prompt.js";
import { buildDriftOutputChecklist } from "./driftAnalysisSections.js";
const STATE_FILE = "/tmp/skyramp-analysis-abc123.json";
// ── Step label constants ──────────────────────────────────────────────────────
describe("DRIFT_STEP_* label constants", () => {
    it("main steps are sequentially numbered from 1", () => {
        expect(DRIFT_STEP_ASSESS).toBe("1");
        expect(DRIFT_STEP_APPLY).toBe("2");
        expect(DRIFT_STEP_CALL_TOOL).toBe("3");
    });
    it("sub-steps are numbered within their parent", () => {
        expect(DRIFT_STEP_ENDPOINT_EXISTENCE).toBe("1.1");
        expect(DRIFT_STEP_RESPONSE_SHAPE).toBe("1.2");
        expect(DRIFT_STEP_ADDITIVE_FIELDS).toBe("1.3");
        expect(DRIFT_STEP_AUTH_AUTHZ).toBe("1.4");
        expect(DRIFT_STEP_BEHAVIORAL_CONTRACT).toBe("1.5");
        expect(DRIFT_STEP_ASSIGN_ACTION).toBe("1.6");
    });
});
// ── buildDriftOutputChecklist ─────────────────────────────────────────────────
describe("buildDriftOutputChecklist", () => {
    it("includes recommendations, updateInstructions, and skyramp_actions CTA", () => {
        const checklist = buildDriftOutputChecklist(3, 0, STATE_FILE);
        expect(checklist).toContain("recommendations");
        expect(checklist).toContain("updateInstructions");
        expect(checklist).toContain(STATE_FILE);
        expect(checklist).toContain("skyramp_actions");
    });
    it("does not contain JSON shape — schema is authoritative", () => {
        const checklist = buildDriftOutputChecklist(3, 0, STATE_FILE);
        expect(checklist).not.toContain('"testFile":');
        expect(checklist).not.toContain('"action":');
    });
    it("CTA appears exactly once", () => {
        const checklist = buildDriftOutputChecklist(3, 0, STATE_FILE);
        const ctaCount = (checklist.match(/call `skyramp_actions`/g) || []).length;
        expect(ctaCount).toBe(1);
    });
});
// ── buildDriftAnalysisPrompt ──────────────────────────────────────────────────
describe("buildDriftAnalysisPrompt", () => {
    function prompt() {
        return buildDriftAnalysisPrompt({
            existingTests: [],
            scannedEndpoints: [],
            repositoryPath: "/repo",
            stateFile: STATE_FILE,
        });
    }
    it("wraps output in drift_analysis_rules XML tags", () => {
        expect(prompt()).toContain("<drift_analysis_rules>");
        expect(prompt()).toContain("</drift_analysis_rules>");
    });
    it("does not contain the persona statement or context header", () => {
        expect(prompt()).not.toContain("You are acting as a Skyramp Integration Architect");
        expect(prompt()).not.toContain("# Test Health Analysis");
    });
    it("includes recommendations guidance and updateInstructions", () => {
        expect(prompt()).toContain("recommendations");
        expect(prompt()).toContain("updateInstructions");
    });
    it("includes all PromptPlan steps", () => {
        const p = prompt();
        expect(p).toContain(`### Step ${DRIFT_STEP_ASSESS}:`);
        expect(p).toContain(`### Step ${DRIFT_STEP_ENDPOINT_EXISTENCE}:`);
        expect(p).toContain(`### Step ${DRIFT_STEP_RESPONSE_SHAPE}:`);
        expect(p).toContain(`### Step ${DRIFT_STEP_ADDITIVE_FIELDS}:`);
        expect(p).toContain(`### Step ${DRIFT_STEP_AUTH_AUTHZ}:`);
        expect(p).toContain(`### Step ${DRIFT_STEP_BEHAVIORAL_CONTRACT}:`);
        expect(p).toContain(`### Step ${DRIFT_STEP_ASSIGN_ACTION}:`);
        expect(p).toContain(`### Step ${DRIFT_STEP_APPLY}:`);
        expect(p).toContain(`### Step ${DRIFT_STEP_CALL_TOOL}:`);
    });
    it("skyramp_actions CTA appears exactly once", () => {
        const ctaCount = (prompt().match(/call `skyramp_actions`/g) || []).length;
        expect(ctaCount).toBe(1);
    });
});
// ── Scanned endpoints no longer in prompt output ─────────────────────────────
// The context header (repo, diff, test list, scanned endpoints) was removed —
// skyramp_analyze_changes already delivers that context to the conversation.
// The scanned endpoints rendering tests were removed along with the header.
// The [object Object] bug that was guarded against is no longer reachable via
// this prompt path.
