import { describe, it, expect, vi, beforeEach } from "vitest";
describe("embed input capping", () => {
    beforeEach(() => vi.restoreAllMocks());
    it("caps an oversized input to EMBED_INPUT_MAX_CHARS before POST and returns a vector", async () => {
        const huge = "x".repeat(100_000);
        let sentInput;
        vi.stubGlobal("fetch", vi.fn(async (_url, init) => {
            sentInput = JSON.parse(init.body).input;
            return {
                ok: true,
                json: async () => ({ embeddings: [[0.1, 0.2]] }),
            };
        }));
        const { embed, EMBED_INPUT_MAX_CHARS } = await import("../../lib/embeddings.js");
        const vec = await embed(huge);
        expect(vec).toEqual([0.1, 0.2]);
        expect(sentInput.length).toBe(EMBED_INPUT_MAX_CHARS);
    });
    it("embedBatch caps each oversized element, leaves short ones intact", async () => {
        let sent = [];
        vi.stubGlobal("fetch", vi.fn(async (_u, init) => {
            sent = JSON.parse(init.body).input;
            return {
                ok: true,
                json: async () => ({ embeddings: sent.map(() => [0.1]) }),
            };
        }));
        const { embedBatch, EMBED_INPUT_MAX_CHARS } = await import("../../lib/embeddings.js");
        await embedBatch(["short", "y".repeat(50_000)]);
        expect(sent[0]).toBe("short");
        expect(sent[1].length).toBe(EMBED_INPUT_MAX_CHARS);
    });
});
//# sourceMappingURL=embeddings-cap.test.js.map