Skip to content
Source
Sign inSign up
Open History to see the last commit

provider.test.ts

56 lines1.8 KB

1import { describe, expect, it } from "vite-plus/test";
2import * as Schema from "effect/Schema";
3​
4import { ThreadId } from "./baseSchemas.ts";
5import { ProviderSendTurnInput, ProviderUploadFeedbackError } from "./provider.ts";
6​
7const decodeProviderSendTurnInput = Schema.decodeUnknownSync(ProviderSendTurnInput);
8​
9describe("ProviderSendTurnInput", () => {
10 it.each(["image", "file"])(
11 "caps total image bytes for %s attachments without charging videos",
12 (type) => {
13 const image = {
14 type,
15 id: "image",
16 name: "image.png",
17 mimeType: "image/png",
18 sizeBytes: 10 * 1024 * 1024,
19 };
20 const video = {
21 type: "file",
22 id: "video",
23 name: "video.mp4",
24 mimeType: "video/mp4",
25 sizeBytes: 50 * 1024 * 1024,
26 };
27 expect(
28 decodeProviderSendTurnInput({
29 threadId: "thread-1",
30 attachments: [...Array.from({ length: 8 }, () => image), video],
31 }).attachments,
32 ).toHaveLength(9);
33 expect(() =>
34 decodeProviderSendTurnInput({
35 threadId: "thread-1",
36 attachments: [...Array.from({ length: 8 }, () => image), { ...image, sizeBytes: 1 }],
37 }),
38 ).toThrow(/80 MiB/);
39 },
40 );
41});
42​
43describe("provider feedback", () => {
44 it("keeps the failed thread and original cause without exposing upstream text", () => {
45 const cause = new Error("provider request secret");
46 const error = new ProviderUploadFeedbackError({
47 threadId: ThreadId.make("thread-1"),
48 cause,
49 });
50​
51 expect(error.threadId).toBe("thread-1");
52 expect(error.cause).toBe(cause);
53 expect(error.message).toBe("Failed to upload feedback for thread thread-1.");
54 expect(error.message).not.toContain("provider request secret");
55 });
56});