Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import * as Schema from "effect/Schema";
3
4import { ThreadId } from "./baseSchemas.ts";
5import {
6 ProviderSendTurnInput,
7 ProviderSessionStartInput,
8 ProviderUploadFeedbackError,
9} from "./provider.ts";
10
11const decodeProviderSessionStartInput = Schema.decodeUnknownSync(ProviderSessionStartInput);
12const decodeProviderSendTurnInput = Schema.decodeUnknownSync(ProviderSendTurnInput);
13
14function getOptionValue(
15 options: ReadonlyArray<{ id: string; value: unknown }> | undefined,
16 id: string,
17): unknown {
18 return options?.find((option) => option.id === id)?.value;
19}
20
21describe("ProviderSessionStartInput", () => {
22 it("accepts codex-compatible payloads", () => {
23 const parsed = decodeProviderSessionStartInput({
24 threadId: "thread-1",
25 provider: "codex",
26 cwd: "/tmp/workspace",
27 modelSelection: {
28 provider: "codex",
29 model: "gpt-5.3-codex",
30 options: [
31 { id: "reasoningEffort", value: "high" },
32 { id: "fastMode", value: true },
33 ],
34 },
35 runtimeMode: "full-access",
36 });
37 expect(parsed.runtimeMode).toBe("full-access");
38 expect(parsed.modelSelection?.instanceId).toBe("codex");
39 expect(parsed.modelSelection?.model).toBe("gpt-5.3-codex");
40 expect(getOptionValue(parsed.modelSelection?.options, "reasoningEffort")).toBe("high");
41 expect(getOptionValue(parsed.modelSelection?.options, "fastMode")).toBe(true);
42 });
43});
44
45describe("ProviderSendTurnInput", () => {
46 it.each(["image", "file"])(
47 "caps total image bytes for %s attachments without charging videos",
48 (type) => {
49 const image = {
50 type,
51 id: "image",
52 name: "image.png",
53 mimeType: "image/png",
54 sizeBytes: 10 * 1024 * 1024,
55 };
56 const video = {
57 type: "file",
58 id: "video",
59 name: "video.mp4",
60 mimeType: "video/mp4",
61 sizeBytes: 50 * 1024 * 1024,
62 };
63 expect(
64 decodeProviderSendTurnInput({
65 threadId: "thread-1",
66 attachments: [...Array.from({ length: 8 }, () => image), video],
67 }).attachments,
68 ).toHaveLength(9);
69 expect(() =>
70 decodeProviderSendTurnInput({
71 threadId: "thread-1",
72 attachments: [...Array.from({ length: 8 }, () => image), { ...image, sizeBytes: 1 }],
73 }),
74 ).toThrow(/80 MiB/);
75 },
76 );
77});
78
79describe("provider feedback", () => {
80 it("keeps the failed thread and original cause without exposing upstream text", () => {
81 const cause = new Error("provider request secret");
82 const error = new ProviderUploadFeedbackError({
83 threadId: ThreadId.make("thread-1"),
84 cause,
85 });
86
87 expect(error.threadId).toBe("thread-1");
88 expect(error.cause).toBe(cause);
89 expect(error.message).toBe("Failed to upload feedback for thread thread-1.");
90 expect(error.message).not.toContain("provider request secret");
91 });
92});