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

chatAttachment.test.ts

76 lines2.6 KB

1import { assert, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Exit from "effect/Exit";
4import * as Schema from "effect/Schema";
5​
6import {
7 ChatAttachment,
8 isProviderSendTurnSupportedImageMimeType,
9 PROVIDER_SEND_TURN_MAX_FILE_BYTES,
10 SnapShotAccessibility,
11} from "./chatAttachment.ts";
12​
13const decodeAttachment = Schema.decodeUnknownEffect(ChatAttachment);
14const decodeSnapShotAccessibility = Schema.decodeUnknownEffect(SnapShotAccessibility);
15​
16it.effect("tolerates attachment types from newer builds", () =>
17 Effect.gen(function* () {
18 const attachment = yield* decodeAttachment({
19 type: "somethingnew",
20 id: "thread-1-00000000-0000-4000-8000-000000000003-glb",
21 name: "scene.glb",
22 mimeType: "model/gltf-binary",
23 sizeBytes: 12,
24 });
25 assert.strictEqual(attachment.type, "somethingnew");
26 }),
27);
28​
29it.effect("rejects malformed known attachment types instead of tolerating them", () =>
30 Effect.gen(function* () {
31 const base = {
32 id: "thread-1-00000000-0000-4000-8000-000000000003-pdf",
33 name: "report.pdf",
34 mimeType: "application/pdf",
35 };
36 const oversizedFile = yield* Effect.exit(
37 decodeAttachment({ ...base, type: "file", sizeBytes: PROVIDER_SEND_TURN_MAX_FILE_BYTES + 1 }),
38 );
39 assert.strictEqual(Exit.isFailure(oversizedFile), true);
40 const badMimeImage = yield* Effect.exit(
41 decodeAttachment({ ...base, type: "image", mimeType: "application/pdf", sizeBytes: 12 }),
42 );
43 assert.strictEqual(Exit.isFailure(badMimeImage), true);
44 }),
45);
46​
47it.effect("rejects accessibility trees above the serialized payload limit", () =>
48 Effect.gen(function* () {
49 const result = yield* Effect.exit(
50 decodeSnapShotAccessibility({
51 format: "element-tree",
52 coordinateSpace: "captured-image",
53 imageSize: { width: 800, height: 600 },
54 truncated: false,
55 root: {
56 role: "window",
57 bounds: { x: 0, y: 0, width: 800, height: 600 },
58 children: Array.from({ length: 10 }, () => ({
59 role: "text",
60 value: "x".repeat(8_000),
61 bounds: null,
62 children: [],
63 })),
64 },
65 }),
66 );
67​
68 assert.strictEqual(Exit.isFailure(result), true);
69 }),
70);
71​
72it("isProviderSendTurnSupportedImageMimeType accepts raster formats and rejects svg", () => {
73 assert.strictEqual(isProviderSendTurnSupportedImageMimeType("image/png"), true);
74 assert.strictEqual(isProviderSendTurnSupportedImageMimeType("IMAGE/JPEG"), true);
75 assert.strictEqual(isProviderSendTurnSupportedImageMimeType("image/svg+xml"), false);
76});