Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { describe, expect, it } from "@effect/vitest";
3import {
4 ANTIGRAVITY_DEFAULT_MODEL,
5 PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
6 type ChatAttachment,
7} from "@t3tools/contracts";
8import * as Effect from "effect/Effect";
9import * as FileSystem from "effect/FileSystem";
10import * as Path from "effect/Path";
11import * as Stream from "effect/Stream";
12import * as EffectAcpErrors from "effect-acp/errors";
13import type * as EffectAcpSchema from "effect-acp/compat";
14
15import { resolveAttachmentPath } from "../../attachmentStore.ts";
16import {
17 applyAntigravityAcpModelSelection,
18 antigravityClientInfo,
19 antigravityPermissionDisposition,
20 antigravitySessionMeta,
21 antigravitySessionMode,
22 buildAntigravityPrompt,
23} from "./AntigravityAcpSupport.ts";
24
25const modelConfig = {
26 id: "model",
27 name: "Model",
28 type: "select",
29 currentValue: "gemini-default",
30 options: [
31 { value: "gemini-default", name: "Gemini default" },
32 { value: "gemini-saved", name: "Gemini saved" },
33 ],
34} satisfies EffectAcpSchema.SessionConfigOption;
35
36function makeModelRuntime(
37 configOptions: ReadonlyArray<EffectAcpSchema.SessionConfigOption> = [modelConfig],
38 failure?: EffectAcpErrors.AcpError,
39) {
40 const selections: string[] = [];
41 const setModel = Effect.fn("AntigravityAcpSupportTest.setModel")(function* (model: string) {
42 if (failure) return yield* failure;
43 selections.push(model);
44 });
45 const setConfigOption = Effect.fn("AntigravityAcpSupportTest.setConfigOption")(function* (
46 configId: string,
47 value: string | boolean,
48 options?: { readonly allowUnlistedValue?: boolean },
49 ) {
50 selections.push(
51 `${configId}=${String(value)}${options?.allowUnlistedValue === true ? " (unlisted)" : ""}`,
52 );
53 return { configOptions };
54 });
55 return {
56 runtime: { getConfigOptions: Effect.succeed(configOptions), setModel, setConfigOption },
57 selections,
58 };
59}
60
61describe("Antigravity release gates", () => {
62 it.each([
63 { version: "1.5.0", ownName: false, advertisedAppend: false },
64 { version: "1.5.1", ownName: true, advertisedAppend: false },
65 { version: "1.5.7", ownName: true, advertisedAppend: true },
66 { version: undefined, ownName: false, advertisedAppend: false },
67 { version: "unknown", ownName: false, advertisedAppend: false },
68 ])(
69 "$version: advertised system append $advertisedAppend, own client name $ownName",
70 ({ version, ownName, advertisedAppend }) => {
71 const initialize = {
72 protocolVersion: 1,
73 ...(advertisedAppend
74 ? { agentCapabilities: { _meta: { antigravity: { systemPrompt: { append: true } } } } }
75 : {}),
76 ...(version === undefined
77 ? {}
78 : { agentInfo: { name: "Antigravity ACP Server", version } }),
79 };
80 // Helpers send no append.
81 expect(antigravitySessionMeta(initialize)).toBeUndefined();
82 expect(antigravitySessionMeta(initialize, "<pull_request_linking/>")).toEqual(
83 advertisedAppend
84 ? { antigravity: { systemPrompt: { append: "<pull_request_linking/>" } } }
85 : undefined,
86 );
87 expect(antigravityClientInfo(version).name).toBe(ownName ? "t3-code" : "zed");
88 },
89 );
90});
91
92describe("Antigravity Auto", () => {
93 it.each([
94 { offered: ["default", "accept-edits", "auto", "plan"], expected: "auto" },
95 { offered: ["default", "accept-edits", "plan"], expected: "default" },
96 ])("runs as $expected when the session offers $offered", ({ offered, expected }) => {
97 const modeState = {
98 currentModeId: "default",
99 availableModes: offered.map((id) => ({ id, name: id })),
100 };
101 expect(antigravitySessionMode("auto", modeState)).toBe(expected);
102 });
103
104 it.each(["execute", "read"] as const)("asks about the %s requests agy's Auto sends", (kind) => {
105 const request = {
106 sessionId: "session-1",
107 toolCall: { toolCallId: "call-1", title: "Tool call", kind },
108 options: [{ optionId: "allow", name: "Allow", kind: "allow_once" }],
109 } satisfies EffectAcpSchema.RequestPermissionRequest;
110 expect(antigravityPermissionDisposition({ runtimeMode: "auto", cwd: null }, request)).toBe(
111 "ask",
112 );
113 });
114
115 it.each([{ type: "readOnly" }, { type: "workspaceWrite", writableRoots: [] }])(
116 "keeps the $type sandbox's denials in Auto",
117 (sandboxPolicy) => {
118 const request = {
119 sessionId: "session-1",
120 toolCall: {
121 toolCallId: "call-1",
122 title: "Edit",
123 kind: "edit",
124 locations: [{ path: "/outside-workspace/file.txt" }],
125 },
126 options: [{ optionId: "allow", name: "Allow", kind: "allow_once" }],
127 } satisfies EffectAcpSchema.RequestPermissionRequest;
128 expect(
129 antigravityPermissionDisposition(
130 { runtimeMode: "auto", cwd: "/workspace", sandboxPolicy },
131 request,
132 ),
133 ).toBe("deny");
134 },
135 );
136
137 it.each(["auto", "auto-accept-edits"] as const)(
138 "runs only server-qualified T3 MCP calls unasked in %s",
139 (runtimeMode) => {
140 const policy = { runtimeMode, cwd: "/workspace" };
141 const request = (
142 title: string,
143 rawInput?: Record<string, unknown>,
144 ): EffectAcpSchema.RequestPermissionRequest => ({
145 sessionId: "session-1",
146 toolCall: { toolCallId: "call-1", title, kind: "execute", rawInput },
147 options: [{ optionId: "allow", name: "Allow", kind: "allow_once" }],
148 });
149 for (const t3Call of [
150 request("Run mcp_t3-code_t3_thread_list?"),
151 request("MCP Tool delegate_task", { ServerName: "t3-code", ToolName: "delegate_task" }),
152 ]) {
153 expect(antigravityPermissionDisposition(policy, t3Call)).toBe("allow");
154 expect(
155 antigravityPermissionDisposition({ ...policy, approvalPolicy: "on-request" }, t3Call),
156 ).toBe("ask");
157 expect(
158 antigravityPermissionDisposition(
159 { ...policy, sandboxPolicy: { type: "readOnly" } },
160 t3Call,
161 ),
162 ).toBe("deny");
163 }
164 for (const otherCall of [
165 // Names no server, so another MCP server's tool of the same name looks identical.
166 request("Running preview_status"),
167 request("Run mcp_github_create_issue"),
168 request("MCP Tool preview_status", { ServerName: "other", ToolName: "preview_status" }),
169 request("Run mcp_t3-code_preview_status", {
170 CommandLine: "Run mcp_t3-code_preview_status",
171 }),
172 // A directly called tool's rawInput is its own arguments, whatever their names.
173 request("Run mcp_github_create_issue", {
174 ServerName: "t3-code",
175 ToolName: "delegate_task",
176 }),
177 request("Running create_issue", { ServerName: "t3-code", ToolName: "delegate_task" }),
178 // call_mcp_tool is titled for the tool it calls.
179 request("MCP Tool create_issue", { ServerName: "t3-code", ToolName: "delegate_task" }),
180 ]) {
181 expect(antigravityPermissionDisposition(policy, otherCall)).toBe("ask");
182 }
183 },
184 );
185});
186
187describe("applyAntigravityAcpModelSelection", () => {
188 it.effect("restores the saved model instead of the cold-resume default", () =>
189 Effect.gen(function* () {
190 const { runtime, selections } = makeModelRuntime();
191 const model = yield* applyAntigravityAcpModelSelection({
192 runtime,
193 model: "gemini-saved",
194 mapError: (cause) => cause,
195 });
196
197 expect(model).toBe("gemini-saved");
198 expect(selections).toEqual(["gemini-saved"]);
199 }),
200 );
201
202 it.effect.each([undefined, null, ANTIGRAVITY_DEFAULT_MODEL])(
203 "uses the native default for %s without sending an internal model ID",
204 (requestedModel) =>
205 Effect.gen(function* () {
206 const { runtime, selections } = makeModelRuntime();
207 const model = yield* applyAntigravityAcpModelSelection({
208 runtime,
209 model: requestedModel,
210 mapError: (cause) => cause,
211 });
212
213 expect(model).toBe("gemini-default");
214 expect(selections).toEqual([]);
215 }),
216 );
217
218 it.effect("selects the manifest default for the alias when the account offers it", () =>
219 Effect.gen(function* () {
220 const { runtime, selections } = makeModelRuntime();
221 const model = yield* applyAntigravityAcpModelSelection({
222 runtime,
223 model: ANTIGRAVITY_DEFAULT_MODEL,
224 defaultModel: "gemini-saved",
225 mapError: (cause) => cause,
226 });
227 expect(model).toBe("gemini-saved");
228 expect(selections).toEqual(["gemini-saved"]);
229
230 const { runtime: other, selections: otherSelections } = makeModelRuntime();
231 const fallback = yield* applyAntigravityAcpModelSelection({
232 runtime: other,
233 model: ANTIGRAVITY_DEFAULT_MODEL,
234 defaultModel: "gemini-not-offered",
235 mapError: (cause) => cause,
236 });
237 expect(fallback).toBe("gemini-default");
238 expect(otherSelections).toEqual([]);
239 }),
240 );
241
242 it.effect.each(["gemini-removed", "Gemini saved", "gemini-saved[reasoning=high]"])(
243 "rejects unavailable or non-native model ID %s without selecting a fallback",
244 (model) =>
245 Effect.gen(function* () {
246 const { runtime, selections } = makeModelRuntime();
247 const error = yield* applyAntigravityAcpModelSelection({
248 runtime,
249 model,
250 mapError: (cause) => cause,
251 }).pipe(Effect.flip);
252
253 expect(error).toMatchObject({
254 _tag: "AcpRequestError",
255 code: -32602,
256 errorMessage: expect.stringContaining(`'${model}' is unavailable`),
257 });
258 expect(selections).toEqual([]);
259 }),
260 );
261
262 it.effect("accepts exact model IDs from grouped native options", () =>
263 Effect.gen(function* () {
264 const { runtime, selections } = makeModelRuntime([
265 {
266 ...modelConfig,
267 options: [{ groupId: "gemini", name: "Gemini", options: modelConfig.options }],
268 },
269 ]);
270 const model = yield* applyAntigravityAcpModelSelection({
271 runtime,
272 model: "gemini-saved",
273 mapError: (cause) => cause,
274 });
275
276 expect(model).toBe("gemini-saved");
277 expect(selections).toEqual(["gemini-saved"]);
278 }),
279 );
280
281 it.effect("passes a model ID saved on runtime 1.3 to the agent as its 1.4 family", () =>
282 Effect.gen(function* () {
283 // The cold-resume model has no thinking option, so the level is unknown locally.
284 const { runtime, selections } = makeModelRuntime([
285 {
286 ...modelConfig,
287 currentValue: "gpt-oss-120b-medium",
288 options: [
289 { value: "gemini-3.8-flash", name: "Gemini 3.8 Flash" },
290 { value: "gpt-oss-120b-medium", name: "GPT-OSS 120B (Medium)" },
291 ],
292 },
293 ]);
294 const model = yield* applyAntigravityAcpModelSelection({
295 runtime,
296 model: "gemini-3.8-flash-low",
297 mapError: (cause) => cause,
298 });
299
300 expect(model).toBe("gemini-3.8-flash");
301 expect(selections).toEqual(["model=gemini-3.8-flash-low (unlisted)"]);
302 }),
303 );
304});
305
306const imageAttachment = {
307 type: "image",
308 id: "thread-00000000-0000-4000-8000-000000000001",
309 name: "screen.png",
310 mimeType: "image/png",
311 sizeBytes: 1,
312} satisfies ChatAttachment;
313
314const textAttachment = {
315 type: "file",
316 id: "thread-00000000-0000-4000-8000-000000000002-tsx",
317 name: "example.tsx",
318 mimeType: "application/octet-stream",
319 sizeBytes: 1,
320} satisfies ChatAttachment;
321
322const pdfAttachment = {
323 type: "file",
324 id: "thread-00000000-0000-4000-8000-000000000003-pdf",
325 name: "report.pdf",
326 mimeType: "application/pdf",
327 sizeBytes: 1,
328} satisfies ChatAttachment;
329
330const makeAttachmentFixture = Effect.fn("AntigravityAcpSupportTest.makeAttachmentFixture")(
331 function* () {
332 const fs = yield* FileSystem.FileSystem;
333 const path = yield* Path.Path;
334 const attachmentsDir = yield* fs.makeTempDirectoryScoped({
335 prefix: "t3-antigravity-attachments-",
336 });
337 const write = Effect.fn("AntigravityAcpSupportTest.writeAttachment")(function* (
338 attachment: ChatAttachment,
339 content: string | Uint8Array,
340 ) {
341 const filePath = resolveAttachmentPath({ attachmentsDir, attachment });
342 if (filePath === null) throw new Error("Invalid test attachment path.");
343 if (typeof content === "string") yield* fs.writeFileString(filePath, content);
344 else yield* fs.writeFile(filePath, content);
345 return { filePath, uri: (yield* path.toFileUrl(filePath)).href };
346 });
347 const resolve = (attachment: ChatAttachment) =>
348 resolveAttachmentPath({ attachmentsDir, attachment });
349 return { fs, attachmentsDir, resolve, write };
350 },
351);
352
353it.layer(NodeServices.layer)("buildAntigravityPrompt", (it) => {
354 it.effect("sends image bytes as native image content alongside the user prompt", () =>
355 Effect.gen(function* () {
356 const fixture = yield* makeAttachmentFixture();
357 const bytes = Buffer.from(
358 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jY9kAAAAASUVORK5CYII=",
359 "base64",
360 );
361 yield* fixture.write(imageAttachment, bytes);
362 const prompt = yield* buildAntigravityPrompt({
363 input: " Explain this image. ",
364 attachments: [imageAttachment],
365 resolveAttachmentPath: fixture.resolve,
366 promptCapabilities: { image: true, audio: true, embeddedContext: true },
367 });
368
369 expect(prompt).toEqual([
370 { type: "text", text: "Explain this image." },
371 { type: "image", data: bytes.toString("base64"), mimeType: "image/png" },
372 ]);
373 }),
374 );
375
376 it.effect.each(["utf8", "utf16le", "utf16be"] as const)(
377 "embeds %s code from the selected environment and keeps the upload in place",
378 (encoding) =>
379 Effect.gen(function* () {
380 const selectedEnvironment = yield* makeAttachmentFixture();
381 const otherEnvironment = yield* makeAttachmentFixture();
382 const source = ' const name = "caf\u00e9 🚀";\r\n';
383 const bytes =
384 encoding === "utf8" ? Buffer.from(source) : Buffer.from("\ufeff" + source, "utf16le");
385 if (encoding === "utf16be") bytes.swap16();
386 const upload = yield* selectedEnvironment.write(textAttachment, bytes);
387 yield* otherEnvironment.write(textAttachment, "Different environment.");
388 const prompt = yield* buildAntigravityPrompt({
389 input: undefined,
390 attachments: [textAttachment],
391 resolveAttachmentPath: selectedEnvironment.resolve,
392 promptCapabilities: { image: true, audio: true, embeddedContext: true },
393 });
394
395 expect(prompt).toEqual([
396 {
397 type: "resource",
398 resource: { uri: upload.uri, mimeType: "application/octet-stream", text: source },
399 },
400 ]);
401 expect(Buffer.from(yield* selectedEnvironment.fs.readFile(upload.filePath))).toEqual(bytes);
402 expect(
403 yield* selectedEnvironment.fs.readDirectory(selectedEnvironment.attachmentsDir),
404 ).toHaveLength(1);
405 }),
406 );
407
408 it.effect("keeps folded clipboard text out of native context", () =>
409 Effect.gen(function* () {
410 const fixture = yield* makeAttachmentFixture();
411 const pastedText = {
412 ...textAttachment,
413 name: "pasted-text.txt",
414 mimeType: "text/plain",
415 source: { _tag: "pasted-text" as const },
416 } satisfies ChatAttachment;
417 yield* fixture.write(pastedText, "A very large crash report");
418
419 const prompt = yield* buildAntigravityPrompt({
420 input: "Inspect the pasted text only as needed.",
421 attachments: [pastedText],
422 resolveAttachmentPath: fixture.resolve,
423 promptCapabilities: { image: true, audio: true, embeddedContext: true },
424 });
425
426 expect(prompt).toEqual([{ type: "text", text: "Inspect the pasted text only as needed." }]);
427 }),
428 );
429
430 it.effect("keeps a Shift-JIS CSV as a file path instead of failing the prompt", () =>
431 Effect.gen(function* () {
432 const fixture = yield* makeAttachmentFixture();
433 const csv = {
434 ...textAttachment,
435 name: "sample.csv",
436 mimeType: "text/csv",
437 } satisfies ChatAttachment;
438 // "オーダー番号,ステータス\n1001,完了\n" encoded as CP932.
439 const upload = yield* fixture.write(
440 csv,
441 Buffer.from("8349815b835f815b94d48d862c83588365815b835e83580a313030312c8aae97b90a", "hex"),
442 );
443 const input = `How many rows does this CSV have? ${upload.filePath}`;
444
445 const prompt = yield* buildAntigravityPrompt({
446 input,
447 attachments: [csv],
448 resolveAttachmentPath: fixture.resolve,
449 promptCapabilities: { image: true, audio: true, embeddedContext: true },
450 });
451
452 expect(prompt).toEqual([{ type: "text", text: input }]);
453 }),
454 );
455
456 it.effect.each([
457 { name: "archive.zip", mimeType: "application/zip" },
458 { name: "clip.mp4", mimeType: "video/mp4" },
459 { name: "recording.aiff", mimeType: "audio/aiff" },
460 { name: "large.pdf", mimeType: "application/pdf", sizeBytes: 75_000_000 },
461 { name: "large.txt", mimeType: "text/plain", sizeBytes: 1024 * 1024 + 1 },
462 { name: "large.wav", mimeType: "audio/wav", sizeBytes: 20 * 1024 * 1024 + 1 },
463 ])("keeps $name as a file path without reading or spending the native media budget", (file) =>
464 Effect.gen(function* () {
465 const fixture = yield* makeAttachmentFixture();
466 const attachment = { ...textAttachment, sizeBytes: 50 * 1024 * 1024, ...file };
467 const upload = yield* fixture.write(attachment, "");
468 yield* fixture.fs.truncate(upload.filePath, attachment.sizeBytes);
469 const pdf = yield* fixture.write(pdfAttachment, "");
470 yield* fixture.fs.truncate(pdf.filePath, 50 * 1024 * 1024);
471 const input = `Inspect the file at ${upload.filePath}`;
472 const prompt = yield* buildAntigravityPrompt({
473 input,
474 attachments: [attachment, pdfAttachment],
475 resolveAttachmentPath: fixture.resolve,
476 promptCapabilities: { image: true, audio: true, embeddedContext: true },
477 }).pipe(
478 Effect.provideService(FileSystem.FileSystem, {
479 ...fixture.fs,
480 stream: () => {
481 throw new Error("Path attachments must not be read into the prompt");
482 },
483 }),
484 );
485 expect(prompt).toEqual([
486 { type: "text", text: input },
487 {
488 type: "resource_link",
489 uri: pdf.uri,
490 name: "report.pdf",
491 mimeType: "application/pdf",
492 size: 50 * 1024 * 1024,
493 },
494 ]);
495 }),
496 );
497
498 it.effect.each([undefined, {}, { image: false, audio: false, embeddedContext: false }])(
499 "keeps attachments path-only when native prompt capabilities are absent: %s",
500 (promptCapabilities) =>
501 Effect.gen(function* () {
502 const fixture = yield* makeAttachmentFixture();
503 const audio = {
504 ...textAttachment,
505 id: "unsupported-audio",
506 name: "audio.wav",
507 mimeType: "audio/wav",
508 };
509 const gifAttachment = {
510 ...imageAttachment,
511 id: "unsupported-gif",
512 name: "animation.gif",
513 mimeType: "image/gif",
514 };
515 const gif = yield* fixture.write(gifAttachment, "GIF89a");
516 const image = yield* fixture.write(imageAttachment, "pixels");
517 const pdf = yield* fixture.write(pdfAttachment, "%PDF-1.7");
518 const text = yield* fixture.write(textAttachment, "hello");
519 const sound = yield* fixture.write(audio, "RIFF");
520 const input = `Read ${image.filePath}, ${gif.filePath}, ${pdf.filePath}, ${text.filePath}, and ${sound.filePath}`;
521 const prompt = yield* buildAntigravityPrompt({
522 input,
523 attachments: [imageAttachment, gifAttachment, pdfAttachment, textAttachment, audio],
524 resolveAttachmentPath: fixture.resolve,
525 promptCapabilities,
526 }).pipe(
527 Effect.provideService(FileSystem.FileSystem, {
528 ...fixture.fs,
529 stream: () =>
530 Effect.die("Unnegotiated attachments must not be read").pipe(Stream.fromEffect),
531 }),
532 );
533 expect(prompt).toEqual([{ type: "text", text: input }]);
534 expect(
535 yield* buildAntigravityPrompt({
536 input: "Continue",
537 attachments: [],
538 resolveAttachmentPath: fixture.resolve,
539 promptCapabilities,
540 }),
541 ).toEqual([{ type: "text", text: "Continue" }]);
542 }),
543 );
544
545 it.effect.each(["audio/wav", "audio/wav;codecs=1", "Audio/WAV \t; codecs=1"])(
546 "sends supported audio files as native audio content (%s)",
547 (mimeType) =>
548 Effect.gen(function* () {
549 const fixture = yield* makeAttachmentFixture();
550 const audioAttachment = {
551 ...textAttachment,
552 id: "recording-1",
553 name: "recording.wav",
554 mimeType,
555 } satisfies ChatAttachment;
556 const bytes = Buffer.from("RIFF....WAVEfmt ", "latin1");
557 yield* fixture.write(audioAttachment, bytes);
558 const prompt = yield* buildAntigravityPrompt({
559 input: "Transcribe this.",
560 attachments: [audioAttachment],
561 resolveAttachmentPath: fixture.resolve,
562 promptCapabilities: { image: true, audio: true, embeddedContext: true },
563 });
564
565 expect(prompt).toEqual([
566 { type: "text", text: "Transcribe this." },
567 { type: "audio", data: bytes.toString("base64"), mimeType: "audio/wav" },
568 ]);
569 }),
570 );
571
572 it.effect.each([{ image: true }])(
573 "keeps unsupported image formats path-only with capabilities %s",
574 (promptCapabilities) =>
575 Effect.gen(function* () {
576 const fixture = yield* makeAttachmentFixture();
577 const attachment = { ...imageAttachment, name: "animation.gif", mimeType: "image/gif" };
578 const upload = yield* fixture.write(attachment, "GIF89a");
579 const input = `Analyze the image at ${upload.filePath}`;
580 const prompt = yield* buildAntigravityPrompt({
581 input,
582 attachments: [attachment],
583 resolveAttachmentPath: fixture.resolve,
584 promptCapabilities,
585 }).pipe(
586 Effect.provideService(FileSystem.FileSystem, {
587 ...fixture.fs,
588 stream: () => Effect.die("Unsupported images must not be read").pipe(Stream.fromEffect),
589 }),
590 );
591
592 expect(prompt).toEqual([{ type: "text", text: input }]);
593 }),
594 );
595
596 it.effect("rejects oversized images using file size instead of upload metadata", () =>
597 Effect.gen(function* () {
598 const fixture = yield* makeAttachmentFixture();
599 const upload = yield* fixture.write(imageAttachment, "");
600 yield* fixture.fs.truncate(upload.filePath, PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1);
601 const error = yield* buildAntigravityPrompt({
602 input: "Read this attachment.",
603 attachments: [imageAttachment],
604 resolveAttachmentPath: fixture.resolve,
605 promptCapabilities: { image: true, audio: true, embeddedContext: true },
606 }).pipe(Effect.flip);
607 expect(error).toMatchObject({
608 _tag: "AcpRequestError",
609 code: -32602,
610 errorMessage: expect.stringContaining("'screen.png' is too large"),
611 });
612 }),
613 );
614
615 it.effect("keeps PDF overflow on the file-path route", () =>
616 Effect.gen(function* () {
617 const fixture = yield* makeAttachmentFixture();
618 const secondAttachment = {
619 ...pdfAttachment,
620 id: `${pdfAttachment.id}-second`,
621 name: "second.pdf",
622 };
623 const first = yield* fixture.write(pdfAttachment, "");
624 const second = yield* fixture.write(secondAttachment, "");
625 yield* fixture.fs.truncate(first.filePath, (50 * 1024 * 1024) / 2);
626 yield* fixture.fs.truncate(second.filePath, (50 * 1024 * 1024) / 2);
627 const input = {
628 input: `Read ${first.filePath} and ${second.filePath}`,
629 attachments: [pdfAttachment, secondAttachment],
630 resolveAttachmentPath: fixture.resolve,
631 promptCapabilities: { image: true, audio: true, embeddedContext: true },
632 };
633 const prompt = yield* buildAntigravityPrompt(input);
634 expect(prompt).toEqual([
635 { type: "text", text: input.input },
636 {
637 type: "resource_link",
638 uri: first.uri,
639 name: "report.pdf",
640 mimeType: "application/pdf",
641 size: (50 * 1024 * 1024) / 2,
642 },
643 {
644 type: "resource_link",
645 uri: second.uri,
646 name: "second.pdf",
647 mimeType: "application/pdf",
648 size: (50 * 1024 * 1024) / 2,
649 },
650 ]);
651
652 yield* fixture.fs.truncate(second.filePath, (50 * 1024 * 1024) / 2 + 1);
653 expect(yield* buildAntigravityPrompt(input)).toEqual([
654 { type: "text", text: input.input },
655 {
656 type: "resource_link",
657 uri: first.uri,
658 name: "report.pdf",
659 mimeType: "application/pdf",
660 size: (50 * 1024 * 1024) / 2,
661 },
662 ]);
663 }),
664 );
665
666 it.effect("still rejects images when the native budget is full", () =>
667 Effect.gen(function* () {
668 const fixture = yield* makeAttachmentFixture();
669 const pdf = yield* fixture.write(pdfAttachment, "");
670 yield* fixture.fs.truncate(pdf.filePath, 50 * 1024 * 1024);
671 yield* fixture.write(imageAttachment, new Uint8Array([1]));
672 const error = yield* buildAntigravityPrompt({
673 input: "Inspect both attachments.",
674 attachments: [pdfAttachment, imageAttachment],
675 resolveAttachmentPath: fixture.resolve,
676 promptCapabilities: { image: true, audio: true, embeddedContext: true },
677 }).pipe(Effect.flip);
678 expect(error).toMatchObject({
679 _tag: "AcpRequestError",
680 errorMessage: expect.stringContaining("'screen.png' is too large"),
681 });
682 }),
683 );
684
685 it.effect("rejects aggregate overflow when a text upload grows after its size check", () =>
686 Effect.gen(function* () {
687 const fixture = yield* makeAttachmentFixture();
688 const pdf = yield* fixture.write(pdfAttachment, "");
689 const text = yield* fixture.write(textAttachment, "a");
690 yield* fixture.fs.truncate(pdf.filePath, 50 * 1024 * 1024 - 1);
691 const error = yield* buildAntigravityPrompt({
692 input: undefined,
693 attachments: [pdfAttachment, textAttachment],
694 resolveAttachmentPath: fixture.resolve,
695 promptCapabilities: { image: true, audio: true, embeddedContext: true },
696 }).pipe(
697 Effect.provideService(FileSystem.FileSystem, {
698 ...fixture.fs,
699 stat: Effect.fn("AntigravityAcpSupportTest.growAfterStat")(function* (filePath: string) {
700 const info = yield* fixture.fs.stat(filePath);
701 if (filePath === text.filePath) {
702 yield* fixture.fs.writeFileString(filePath, "ab");
703 }
704 return info;
705 }),
706 }),
707 Effect.flip,
708 );
709
710 expect(error).toMatchObject({
711 _tag: "AcpRequestError",
712 code: -32602,
713 errorMessage: "Attachment 'example.tsx' changed while being read and is too large.",
714 });
715 }),
716 );
717
718 it.effect.each([
719 { bytes: new Uint8Array([0x80]), name: "invalid UTF-8" },
720 { bytes: new Uint8Array([0xff, 0xfe, 0x61]), name: "invalid UTF-16LE" },
721 { bytes: new Uint8Array([0xfe, 0xff, 0x00, 0x00]), name: "UTF-16BE NUL" },
722 { bytes: new Uint8Array([0x61, 0, 0x62]), name: "NUL byte" },
723 ])("keeps undecodable code as a file path: $name", ({ bytes }) =>
724 Effect.gen(function* () {
725 const fixture = yield* makeAttachmentFixture();
726 yield* fixture.write(textAttachment, bytes);
727 const prompt = yield* buildAntigravityPrompt({
728 input: "Read this file.",
729 attachments: [textAttachment],
730 resolveAttachmentPath: fixture.resolve,
731 promptCapabilities: { image: true, audio: true, embeddedContext: true },
732 });
733
734 expect(prompt).toEqual([{ type: "text", text: "Read this file." }]);
735 }),
736 );
737
738 it.effect("reports a missing upload instead of sending only the remaining text", () =>
739 Effect.gen(function* () {
740 const fixture = yield* makeAttachmentFixture();
741 const error = yield* buildAntigravityPrompt({
742 input: "Read this image.",
743 attachments: [imageAttachment],
744 resolveAttachmentPath: fixture.resolve,
745 promptCapabilities: { image: true, audio: true, embeddedContext: true },
746 }).pipe(Effect.flip);
747
748 expect(error).toMatchObject({
749 _tag: "AcpRequestError",
750 code: -32602,
751 errorMessage: "Could not read attachment 'screen.png'.",
752 });
753 }),
754 );
755});