import { describe, expect, it } from "vitest";
import { buildUserContentWithAttachments, routePromptCommandInput } from "./prompt-routing.js";
describe("prompt-template slash commands with attachments", () => {
    it("routes /expand input to a wrapper containing user args", () => {
        const route = routePromptCommandInput("/expand do X");
        expect(route).not.toBeNull();
        expect(route?.cmdName).toBe("expand");
        expect(route?.cmdArgs).toBe("do X");
        expect(route?.fullPrompt).toContain(route?.promptText);
        expect(route?.fullPrompt).toContain("## User Instructions");
        expect(route?.fullPrompt).toContain("do X");
    });
    it("routes markdown and multiline text without losing rendered edge cases", () => {
        const args = "prove **bold** UI renders\n- keep `code` text\n- wrap very long labels";
        const route = routePromptCommandInput(`/expand ${args}`);
        expect(route).toMatchObject({ cmdName: "expand", cmdArgs: args });
        expect(route?.fullPrompt).toContain(`## User Instructions\n\n${args}`);
        expect(route?.fullPrompt).toContain("**bold** UI renders");
        expect(route?.fullPrompt).toContain("`code` text");
    });
    it("does not route an unknown command", () => {
        expect(routePromptCommandInput("/not-a-command do X")).toBeNull();
    });
    it("builds multimodal user content with the full prompt text and image block", () => {
        const fullPrompt = "Command prompt\n\n## User Instructions\n\ndo X";
        const imageAttachment = {
            kind: "image",
            fileName: "screenshot.png",
            filePath: "/tmp/screenshot.png",
            mediaType: "image/png",
            data: "iVBORw0KGgo=",
        };
        const content = buildUserContentWithAttachments(fullPrompt, [imageAttachment], true, false);
        expect(content).toEqual([
            { type: "text", text: fullPrompt },
            { type: "image", mediaType: "image/png", data: "iVBORw0KGgo=" },
        ]);
    });
    it("wraps text attachments in file-tag text blocks", () => {
        const textAttachment = {
            kind: "text",
            fileName: "notes.txt",
            filePath: "/tmp/notes.txt",
            mediaType: "text/plain",
            data: "important context",
        };
        const content = buildUserContentWithAttachments("Analyze this", [textAttachment], true, false);
        expect(content).toEqual([
            { type: "text", text: "Analyze this" },
            { type: "text", text: '<file name="notes.txt">\nimportant context\n</file>' },
        ]);
    });
    it("returns the original prompt string when no attachments are provided", () => {
        const fullPrompt = "Command prompt\n\n## User Instructions\n\ndo X";
        expect(buildUserContentWithAttachments(fullPrompt, [], true, false)).toBe(fullPrompt);
    });
    it("routes video via the read tool when the model supports video", () => {
        const videoAttachment = {
            kind: "video",
            fileName: "clip.mp4",
            filePath: "/tmp/clip.mp4",
            mediaType: "video/mp4",
            data: "AAAA",
        };
        const content = buildUserContentWithAttachments("Watch this", [videoAttachment], true, true);
        expect(Array.isArray(content)).toBe(true);
        const parts = content;
        expect(parts[0]).toEqual({ type: "text", text: "Watch this" });
        // Video-capable models are pointed at the file to read (not inlined), so
        // the read tool can auto-compress + deliver it in the provider's format.
        expect(parts[1].type).toBe("text");
        expect(parts[1].text).toContain("read tool");
        expect(parts[1].text).toContain("/tmp/clip.mp4");
    });
    it("states the attachment plainly (no analysis framing) when the model lacks video", () => {
        const videoAttachment = {
            kind: "video",
            fileName: "clip.mp4",
            filePath: "/tmp/clip.mp4",
            mediaType: "video/mp4",
            data: "AAAA",
        };
        const content = buildUserContentWithAttachments("Watch this", [videoAttachment], true, false);
        expect(Array.isArray(content)).toBe(true);
        const parts = content;
        expect(parts[0]).toEqual({ type: "text", text: "Watch this" });
        expect(parts[1].type).toBe("text");
        // No "watch/analyze this video" framing for a model that can't; just states
        // the file and offers ffmpeg as a fallback.
        expect(parts[1].text).toContain("cannot watch video");
        expect(parts[1].text).toContain("/tmp/clip.mp4");
        expect(parts[1].text).not.toContain("read tool");
    });
    it("handles a large path-only video (no inline base64) for video models", () => {
        const videoAttachment = {
            kind: "video",
            fileName: "big.mp4",
            filePath: "/tmp/big.mp4",
            mediaType: "video/mp4",
            data: "", // large clip: no inline base64, path-only
        };
        const content = buildUserContentWithAttachments("Watch this", [videoAttachment], true, true);
        expect(Array.isArray(content)).toBe(true);
        const parts = content;
        expect(parts[1].type).toBe("text");
        expect(parts[1].text).toContain("read tool");
        expect(parts[1].text).toContain("/tmp/big.mp4");
    });
});
//# sourceMappingURL=slash-command-images.test.js.map