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 HostProcess from "@t3tools/shared/HostProcess";
9import * as Effect from "effect/Effect";
10import * as FileSystem from "effect/FileSystem";
11import * as Path from "effect/Path";
12import * as Stream from "effect/Stream";
13import * as EffectAcpErrors from "effect-acp/errors";
14import type * as EffectAcpSchema from "effect-acp/compat";
15
16import { resolveAttachmentPath } from "../../attachmentStore.ts";
17import {
18 applyAntigravityAcpModelSelection,
19 antigravityClientInfo,
20 antigravitySessionMeta,
21 buildAntigravityPrompt,
22 isQualifiedAntigravityRelease,
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.4.1", filter: false, native: false, ownName: false },
64 { version: "1.4.2", filter: true, native: false, ownName: false },
65 { version: "1.4.4", filter: true, native: false, ownName: false },
66 { version: "1.4.5", filter: true, native: true, ownName: false },
67 { version: "1.4.6", filter: false, native: false, ownName: false },
68 { version: "1.5.0", filter: false, native: false, ownName: false },
69 { version: "1.5.1", filter: false, native: false, ownName: true },
70 { version: "1.3.0", filter: false, native: false, ownName: false },
71 { version: undefined, filter: false, native: false, ownName: false },
72 { version: "unknown", filter: false, native: false, ownName: false },
73 ])(
74 "$version: workflow filter $filter, native reads and system prompt $native, own client name $ownName",
75 ({ version, filter, native, ownName }) => {
76 const initialize = {
77 protocolVersion: 1,
78 ...(version === undefined ? {} : { agentInfo: { name: "antigravity-acp", version } }),
79 };
80 // Helpers send no append, so only the workflow filter can apply.
81 expect(antigravitySessionMeta(initialize)).toEqual(
82 filter ? { antigravity: { disabledTools: ["run_workflow"] } } : undefined,
83 );
84 const antigravity = {
85 ...(filter ? { disabledTools: ["run_workflow"] } : {}),
86 ...(native ? { systemPrompt: { append: "<pull_request_linking/>" } } : {}),
87 };
88 expect(antigravitySessionMeta(initialize, "<pull_request_linking/>")).toEqual(
89 filter || native ? { antigravity } : undefined,
90 );
91 expect(isQualifiedAntigravityRelease(version)).toBe(native);
92 expect(antigravityClientInfo(version).name).toBe(ownName ? "t3-code" : "zed");
93 },
94 );
95});
96
97describe("applyAntigravityAcpModelSelection", () => {
98 it.effect("restores the saved model instead of the cold-resume default", () =>
99 Effect.gen(function* () {
100 const { runtime, selections } = makeModelRuntime();
101 const model = yield* applyAntigravityAcpModelSelection({
102 runtime,
103 model: "gemini-saved",
104 mapError: (cause) => cause,
105 });
106
107 expect(model).toBe("gemini-saved");
108 expect(selections).toEqual(["gemini-saved"]);
109 }),
110 );
111
112 it.effect.each([undefined, null, ANTIGRAVITY_DEFAULT_MODEL])(
113 "uses the native default for %s without sending an internal model ID",
114 (requestedModel) =>
115 Effect.gen(function* () {
116 const { runtime, selections } = makeModelRuntime();
117 const model = yield* applyAntigravityAcpModelSelection({
118 runtime,
119 model: requestedModel,
120 mapError: (cause) => cause,
121 });
122
123 expect(model).toBe("gemini-default");
124 expect(selections).toEqual([]);
125 }),
126 );
127
128 it.effect("selects the manifest default for the alias when the account offers it", () =>
129 Effect.gen(function* () {
130 const { runtime, selections } = makeModelRuntime();
131 const model = yield* applyAntigravityAcpModelSelection({
132 runtime,
133 model: ANTIGRAVITY_DEFAULT_MODEL,
134 defaultModel: "gemini-saved",
135 mapError: (cause) => cause,
136 });
137 expect(model).toBe("gemini-saved");
138 expect(selections).toEqual(["gemini-saved"]);
139
140 const { runtime: other, selections: otherSelections } = makeModelRuntime();
141 const fallback = yield* applyAntigravityAcpModelSelection({
142 runtime: other,
143 model: ANTIGRAVITY_DEFAULT_MODEL,
144 defaultModel: "gemini-not-offered",
145 mapError: (cause) => cause,
146 });
147 expect(fallback).toBe("gemini-default");
148 expect(otherSelections).toEqual([]);
149 }),
150 );
151
152 it.effect.each(["gemini-removed", "Gemini saved", "gemini-saved[reasoning=high]"])(
153 "rejects unavailable or non-native model ID %s without selecting a fallback",
154 (model) =>
155 Effect.gen(function* () {
156 const { runtime, selections } = makeModelRuntime();
157 const error = yield* applyAntigravityAcpModelSelection({
158 runtime,
159 model,
160 mapError: (cause) => cause,
161 }).pipe(Effect.flip);
162
163 expect(error).toMatchObject({
164 _tag: "AcpRequestError",
165 code: -32602,
166 errorMessage: expect.stringContaining(`'${model}' is unavailable`),
167 });
168 expect(selections).toEqual([]);
169 }),
170 );
171
172 it.effect("accepts exact model IDs from grouped native options", () =>
173 Effect.gen(function* () {
174 const { runtime, selections } = makeModelRuntime([
175 {
176 ...modelConfig,
177 options: [{ groupId: "gemini", name: "Gemini", options: modelConfig.options }],
178 },
179 ]);
180 const model = yield* applyAntigravityAcpModelSelection({
181 runtime,
182 model: "gemini-saved",
183 mapError: (cause) => cause,
184 });
185
186 expect(model).toBe("gemini-saved");
187 expect(selections).toEqual(["gemini-saved"]);
188 }),
189 );
190
191 it.effect("passes a model ID saved on runtime 1.3 to the agent as its 1.4 family", () =>
192 Effect.gen(function* () {
193 // The cold-resume model has no thinking option, so the level is unknown locally.
194 const { runtime, selections } = makeModelRuntime([
195 {
196 ...modelConfig,
197 currentValue: "gpt-oss-120b-medium",
198 options: [
199 { value: "gemini-3.8-flash", name: "Gemini 3.8 Flash" },
200 { value: "gpt-oss-120b-medium", name: "GPT-OSS 120B (Medium)" },
201 ],
202 },
203 ]);
204 const model = yield* applyAntigravityAcpModelSelection({
205 runtime,
206 model: "gemini-3.8-flash-low",
207 mapError: (cause) => cause,
208 });
209
210 expect(model).toBe("gemini-3.8-flash");
211 expect(selections).toEqual(["model=gemini-3.8-flash-low (unlisted)"]);
212 }),
213 );
214});
215
216const imageAttachment = {
217 type: "image",
218 id: "thread-00000000-0000-4000-8000-000000000001",
219 name: "screen.png",
220 mimeType: "image/png",
221 sizeBytes: 1,
222} satisfies ChatAttachment;
223
224const textAttachment = {
225 type: "file",
226 id: "thread-00000000-0000-4000-8000-000000000002-tsx",
227 name: "example.tsx",
228 mimeType: "application/octet-stream",
229 sizeBytes: 1,
230} satisfies ChatAttachment;
231
232const pdfAttachment = {
233 type: "file",
234 id: "thread-00000000-0000-4000-8000-000000000003-pdf",
235 name: "report.pdf",
236 mimeType: "application/pdf",
237 sizeBytes: 1,
238} satisfies ChatAttachment;
239
240const makeAttachmentFixture = Effect.fn("AntigravityAcpSupportTest.makeAttachmentFixture")(
241 function* () {
242 const fs = yield* FileSystem.FileSystem;
243 const path = yield* Path.Path;
244 const attachmentsDir = yield* fs.makeTempDirectoryScoped({
245 prefix: "t3-antigravity-attachments-",
246 });
247 const write = Effect.fn("AntigravityAcpSupportTest.writeAttachment")(function* (
248 attachment: ChatAttachment,
249 content: string | Uint8Array,
250 ) {
251 const filePath = resolveAttachmentPath({ attachmentsDir, attachment });
252 if (filePath === null) throw new Error("Invalid test attachment path.");
253 if (typeof content === "string") yield* fs.writeFileString(filePath, content);
254 else yield* fs.writeFile(filePath, content);
255 return { filePath, uri: (yield* path.toFileUrl(filePath)).href };
256 });
257 const resolve = (attachment: ChatAttachment) =>
258 resolveAttachmentPath({ attachmentsDir, attachment });
259 return { fs, attachmentsDir, resolve, write };
260 },
261);
262
263it.layer(NodeServices.layer)("buildAntigravityPrompt", (it) => {
264 it.effect("sends image bytes as native image content alongside the user prompt", () =>
265 Effect.gen(function* () {
266 const fixture = yield* makeAttachmentFixture();
267 const bytes = Buffer.from(
268 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jY9kAAAAASUVORK5CYII=",
269 "base64",
270 );
271 yield* fixture.write(imageAttachment, bytes);
272 const prompt = yield* buildAntigravityPrompt({
273 input: " Explain this image. ",
274 attachments: [imageAttachment],
275 resolveAttachmentPath: fixture.resolve,
276 promptCapabilities: { image: true, audio: true, embeddedContext: true },
277 });
278
279 expect(prompt).toEqual([
280 { type: "text", text: "Explain this image." },
281 { type: "image", data: bytes.toString("base64"), mimeType: "image/png" },
282 ]);
283 }),
284 );
285
286 it.effect("embeds UTF-8 code from the selected environment and keeps the upload in place", () =>
287 Effect.gen(function* () {
288 const selectedEnvironment = yield* makeAttachmentFixture();
289 const otherEnvironment = yield* makeAttachmentFixture();
290 const source = ' const name = "caf\u00e9";\n';
291 const upload = yield* selectedEnvironment.write(textAttachment, source);
292 yield* otherEnvironment.write(textAttachment, "Different environment.");
293 const prompt = yield* buildAntigravityPrompt({
294 input: undefined,
295 attachments: [textAttachment],
296 resolveAttachmentPath: selectedEnvironment.resolve,
297 promptCapabilities: { image: true, audio: true, embeddedContext: true },
298 });
299
300 expect(prompt).toEqual([
301 {
302 type: "resource",
303 resource: { uri: upload.uri, mimeType: "application/octet-stream", text: source },
304 },
305 ]);
306 expect(yield* selectedEnvironment.fs.readFileString(upload.filePath)).toBe(source);
307 expect(
308 yield* selectedEnvironment.fs.readDirectory(selectedEnvironment.attachmentsDir),
309 ).toHaveLength(1);
310 }),
311 );
312
313 it.effect("keeps folded clipboard text out of native context", () =>
314 Effect.gen(function* () {
315 const fixture = yield* makeAttachmentFixture();
316 const pastedText = {
317 ...textAttachment,
318 name: "pasted-text.txt",
319 mimeType: "text/plain",
320 source: { _tag: "pasted-text" as const },
321 } satisfies ChatAttachment;
322 yield* fixture.write(pastedText, "A very large crash report");
323
324 const prompt = yield* buildAntigravityPrompt({
325 input: "Inspect the pasted text only as needed.",
326 attachments: [pastedText],
327 resolveAttachmentPath: fixture.resolve,
328 promptCapabilities: { image: true, audio: true, embeddedContext: true },
329 });
330
331 expect(prompt).toEqual([{ type: "text", text: "Inspect the pasted text only as needed." }]);
332 }),
333 );
334
335 it.effect.each([
336 { name: "archive.zip", mimeType: "application/zip" },
337 { name: "clip.mp4", mimeType: "video/mp4" },
338 { name: "recording.aiff", mimeType: "audio/aiff" },
339 { name: "large.pdf", mimeType: "application/pdf", sizeBytes: 75_000_000 },
340 { name: "large.txt", mimeType: "text/plain", sizeBytes: 1024 * 1024 + 1 },
341 { name: "large.wav", mimeType: "audio/wav", sizeBytes: 20 * 1024 * 1024 + 1 },
342 ])("keeps $name as a file path without reading or spending the native media budget", (file) =>
343 Effect.gen(function* () {
344 const fixture = yield* makeAttachmentFixture();
345 const attachment = { ...textAttachment, sizeBytes: 50 * 1024 * 1024, ...file };
346 const upload = yield* fixture.write(attachment, "");
347 yield* fixture.fs.truncate(upload.filePath, attachment.sizeBytes);
348 const pdf = yield* fixture.write(pdfAttachment, "");
349 yield* fixture.fs.truncate(pdf.filePath, 50 * 1024 * 1024);
350 const input = `Inspect the file at ${upload.filePath}`;
351 const prompt = yield* buildAntigravityPrompt({
352 input,
353 attachments: [attachment, pdfAttachment],
354 resolveAttachmentPath: fixture.resolve,
355 promptCapabilities: { image: true, audio: true, embeddedContext: true },
356 }).pipe(
357 Effect.provideService(FileSystem.FileSystem, {
358 ...fixture.fs,
359 stream: () => {
360 throw new Error("Path attachments must not be read into the prompt");
361 },
362 }),
363 );
364 expect(prompt).toEqual([
365 { type: "text", text: input },
366 {
367 type: "resource_link",
368 uri: pdf.uri,
369 name: "report.pdf",
370 mimeType: "application/pdf",
371 size: 50 * 1024 * 1024,
372 },
373 ]);
374 }),
375 );
376
377 it.effect.each([
378 {
379 case: "a Gemini model id",
380 model: { id: "gemini-3.8-flash", name: "Gemini 3.8 Flash" },
381 linked: true,
382 },
383 {
384 case: "an opaque id named Gemini",
385 model: { id: "agy-model", name: "Gemini 4 Carbon" },
386 linked: true,
387 },
388 { case: "an unknown model", model: { id: "agy-custom", name: "Custom" }, linked: false },
389 { case: "an unlisted opaque id", model: { id: "agy-custom", name: undefined }, linked: false },
390 { case: "an unresolved model", model: undefined, linked: false },
391 {
392 case: "a Claude model",
393 model: { id: "claude-opus-5-5", name: "Claude Opus 5.5" },
394 linked: false,
395 },
396 {
397 case: "an unqualified runtime",
398 agentVersion: "1.4.1",
399 model: { id: "gemini-3.8-flash", name: "Gemini 3.8 Flash" },
400 linked: false,
401 },
402 {
403 case: "a Windows host",
404 platform: "win32" as const,
405 model: { id: "gemini-3.8-flash", name: "Gemini 3.8 Flash" },
406 linked: false,
407 },
408 {
409 case: "a clip over 20 MiB",
410 model: { id: "gemini-3.8-flash", name: "Gemini 3.8 Flash" },
411 linked: false,
412 sizeBytes: 20 * 1024 * 1024 + 1,
413 },
414 ])(
415 "links an MP4 for $case only when supported",
416 ({ agentVersion = "1.4.5", platform = "linux", model, linked, ...size }) =>
417 Effect.gen(function* () {
418 const fixture = yield* makeAttachmentFixture();
419 const clip = {
420 ...textAttachment,
421 id: "clip",
422 name: "clip.mp4",
423 mimeType: "video/mp4",
424 sizeBytes: 6 * 1024 * 1024,
425 ...size,
426 };
427 const upload = yield* fixture.write(clip, "");
428 yield* fixture.fs.truncate(upload.filePath, clip.sizeBytes);
429 const prompt = yield* buildAntigravityPrompt({
430 input: "What colors appear?",
431 attachments: [clip],
432 resolveAttachmentPath: fixture.resolve,
433 promptCapabilities: { image: true, audio: true, embeddedContext: true },
434 agentVersion,
435 currentModel: model,
436 }).pipe(
437 Effect.provideService(HostProcess.Platform, platform),
438 Effect.provideService(FileSystem.FileSystem, {
439 ...fixture.fs,
440 stream: () => Effect.die("Linked video is read by the agent").pipe(Stream.fromEffect),
441 }),
442 );
443 expect(prompt).toEqual([
444 { type: "text", text: "What colors appear?" },
445 ...(linked
446 ? [
447 {
448 type: "resource_link",
449 uri: upload.uri,
450 name: "clip.mp4",
451 mimeType: "video/mp4",
452 size: clip.sizeBytes,
453 },
454 ]
455 : []),
456 ]);
457 }),
458 );
459
460 it.effect.each([undefined, {}, { image: false, audio: false, embeddedContext: false }])(
461 "keeps attachments path-only when native prompt capabilities are absent: %s",
462 (promptCapabilities) =>
463 Effect.gen(function* () {
464 const fixture = yield* makeAttachmentFixture();
465 const audio = {
466 ...textAttachment,
467 id: "unsupported-audio",
468 name: "audio.wav",
469 mimeType: "audio/wav",
470 };
471 const gifAttachment = {
472 ...imageAttachment,
473 id: "unsupported-gif",
474 name: "animation.gif",
475 mimeType: "image/gif",
476 };
477 const gif = yield* fixture.write(gifAttachment, "GIF89a");
478 const image = yield* fixture.write(imageAttachment, "pixels");
479 const pdf = yield* fixture.write(pdfAttachment, "%PDF-1.7");
480 const text = yield* fixture.write(textAttachment, "hello");
481 const sound = yield* fixture.write(audio, "RIFF");
482 const input = `Read ${image.filePath}, ${gif.filePath}, ${pdf.filePath}, ${text.filePath}, and ${sound.filePath}`;
483 const prompt = yield* buildAntigravityPrompt({
484 input,
485 attachments: [imageAttachment, gifAttachment, pdfAttachment, textAttachment, audio],
486 resolveAttachmentPath: fixture.resolve,
487 promptCapabilities,
488 }).pipe(
489 Effect.provideService(FileSystem.FileSystem, {
490 ...fixture.fs,
491 stream: () =>
492 Effect.die("Unnegotiated attachments must not be read").pipe(Stream.fromEffect),
493 }),
494 );
495 expect(prompt).toEqual([{ type: "text", text: input }]);
496 expect(
497 yield* buildAntigravityPrompt({
498 input: "Continue",
499 attachments: [],
500 resolveAttachmentPath: fixture.resolve,
501 promptCapabilities,
502 }),
503 ).toEqual([{ type: "text", text: "Continue" }]);
504 }),
505 );
506
507 it.effect("sends supported audio files as native audio content", () =>
508 Effect.gen(function* () {
509 const fixture = yield* makeAttachmentFixture();
510 const audioAttachment = {
511 ...textAttachment,
512 id: "recording-1",
513 name: "recording.wav",
514 mimeType: "audio/wav",
515 } satisfies ChatAttachment;
516 const bytes = Buffer.from("RIFF....WAVEfmt ", "latin1");
517 yield* fixture.write(audioAttachment, bytes);
518 const prompt = yield* buildAntigravityPrompt({
519 input: "Transcribe this.",
520 attachments: [audioAttachment],
521 resolveAttachmentPath: fixture.resolve,
522 promptCapabilities: { image: true, audio: true, embeddedContext: true },
523 });
524
525 expect(prompt).toEqual([
526 { type: "text", text: "Transcribe this." },
527 { type: "audio", data: bytes.toString("base64"), mimeType: "audio/wav" },
528 ]);
529 }),
530 );
531
532 it.effect.each([undefined, {}, { image: false }, { image: true }])(
533 "keeps unsupported image formats path-only with capabilities %s",
534 (promptCapabilities) =>
535 Effect.gen(function* () {
536 const fixture = yield* makeAttachmentFixture();
537 const attachment = { ...imageAttachment, name: "animation.gif", mimeType: "image/gif" };
538 const upload = yield* fixture.write(attachment, "GIF89a");
539 const input = `Analyze the image at ${upload.filePath}`;
540 const prompt = yield* buildAntigravityPrompt({
541 input,
542 attachments: [attachment],
543 resolveAttachmentPath: fixture.resolve,
544 promptCapabilities,
545 }).pipe(
546 Effect.provideService(FileSystem.FileSystem, {
547 ...fixture.fs,
548 stream: () => Effect.die("Unsupported images must not be read").pipe(Stream.fromEffect),
549 }),
550 );
551
552 expect(prompt).toEqual([{ type: "text", text: input }]);
553 }),
554 );
555
556 it.effect("rejects oversized images using file size instead of upload metadata", () =>
557 Effect.gen(function* () {
558 const fixture = yield* makeAttachmentFixture();
559 const upload = yield* fixture.write(imageAttachment, "");
560 yield* fixture.fs.truncate(upload.filePath, PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1);
561 const error = yield* buildAntigravityPrompt({
562 input: "Read this attachment.",
563 attachments: [imageAttachment],
564 resolveAttachmentPath: fixture.resolve,
565 promptCapabilities: { image: true, audio: true, embeddedContext: true },
566 }).pipe(Effect.flip);
567 expect(error).toMatchObject({
568 _tag: "AcpRequestError",
569 code: -32602,
570 errorMessage: expect.stringContaining("'screen.png' is too large"),
571 });
572 }),
573 );
574
575 it.effect("keeps PDF overflow on the file-path route", () =>
576 Effect.gen(function* () {
577 const fixture = yield* makeAttachmentFixture();
578 const secondAttachment = {
579 ...pdfAttachment,
580 id: `${pdfAttachment.id}-second`,
581 name: "second.pdf",
582 };
583 const first = yield* fixture.write(pdfAttachment, "");
584 const second = yield* fixture.write(secondAttachment, "");
585 yield* fixture.fs.truncate(first.filePath, (50 * 1024 * 1024) / 2);
586 yield* fixture.fs.truncate(second.filePath, (50 * 1024 * 1024) / 2);
587 const input = {
588 input: `Read ${first.filePath} and ${second.filePath}`,
589 attachments: [pdfAttachment, secondAttachment],
590 resolveAttachmentPath: fixture.resolve,
591 promptCapabilities: { image: true, audio: true, embeddedContext: true },
592 };
593 const prompt = yield* buildAntigravityPrompt(input);
594 expect(prompt).toEqual([
595 { type: "text", text: input.input },
596 {
597 type: "resource_link",
598 uri: first.uri,
599 name: "report.pdf",
600 mimeType: "application/pdf",
601 size: (50 * 1024 * 1024) / 2,
602 },
603 {
604 type: "resource_link",
605 uri: second.uri,
606 name: "second.pdf",
607 mimeType: "application/pdf",
608 size: (50 * 1024 * 1024) / 2,
609 },
610 ]);
611
612 yield* fixture.fs.truncate(second.filePath, (50 * 1024 * 1024) / 2 + 1);
613 expect(yield* buildAntigravityPrompt(input)).toEqual([
614 { type: "text", text: input.input },
615 {
616 type: "resource_link",
617 uri: first.uri,
618 name: "report.pdf",
619 mimeType: "application/pdf",
620 size: (50 * 1024 * 1024) / 2,
621 },
622 ]);
623 }),
624 );
625
626 it.effect("still rejects images when the native budget is full", () =>
627 Effect.gen(function* () {
628 const fixture = yield* makeAttachmentFixture();
629 const pdf = yield* fixture.write(pdfAttachment, "");
630 yield* fixture.fs.truncate(pdf.filePath, 50 * 1024 * 1024);
631 yield* fixture.write(imageAttachment, new Uint8Array([1]));
632 const error = yield* buildAntigravityPrompt({
633 input: "Inspect both attachments.",
634 attachments: [pdfAttachment, imageAttachment],
635 resolveAttachmentPath: fixture.resolve,
636 promptCapabilities: { image: true, audio: true, embeddedContext: true },
637 }).pipe(Effect.flip);
638 expect(error).toMatchObject({
639 _tag: "AcpRequestError",
640 errorMessage: expect.stringContaining("'screen.png' is too large"),
641 });
642 }),
643 );
644
645 it.effect("rejects aggregate overflow when a text upload grows after its size check", () =>
646 Effect.gen(function* () {
647 const fixture = yield* makeAttachmentFixture();
648 const pdf = yield* fixture.write(pdfAttachment, "");
649 const text = yield* fixture.write(textAttachment, "a");
650 yield* fixture.fs.truncate(pdf.filePath, 50 * 1024 * 1024 - 1);
651 const error = yield* buildAntigravityPrompt({
652 input: undefined,
653 attachments: [pdfAttachment, textAttachment],
654 resolveAttachmentPath: fixture.resolve,
655 promptCapabilities: { image: true, audio: true, embeddedContext: true },
656 }).pipe(
657 Effect.provideService(FileSystem.FileSystem, {
658 ...fixture.fs,
659 stat: Effect.fn("AntigravityAcpSupportTest.growAfterStat")(function* (filePath: string) {
660 const info = yield* fixture.fs.stat(filePath);
661 if (filePath === text.filePath) {
662 yield* fixture.fs.writeFileString(filePath, "ab");
663 }
664 return info;
665 }),
666 }),
667 Effect.flip,
668 );
669
670 expect(error).toMatchObject({
671 _tag: "AcpRequestError",
672 code: -32602,
673 errorMessage: "Attachment 'example.tsx' changed while being read and is too large.",
674 });
675 }),
676 );
677
678 it.effect.each([
679 { bytes: new Uint8Array([0xff, 0xfe, 0x61]), message: "is not a UTF-8 text file" },
680 { bytes: new Uint8Array([0x61, 0, 0x62]), message: "contains binary data" },
681 ])("rejects binary data disguised as code: $message", ({ bytes, message }) =>
682 Effect.gen(function* () {
683 const fixture = yield* makeAttachmentFixture();
684 yield* fixture.write(textAttachment, bytes);
685 const error = yield* buildAntigravityPrompt({
686 input: undefined,
687 attachments: [textAttachment],
688 resolveAttachmentPath: fixture.resolve,
689 promptCapabilities: { image: true, audio: true, embeddedContext: true },
690 }).pipe(Effect.flip);
691
692 expect(error).toMatchObject({
693 _tag: "AcpRequestError",
694 code: -32602,
695 errorMessage: expect.stringContaining(message),
696 });
697 }),
698 );
699
700 it.effect("reports a missing upload instead of sending only the remaining text", () =>
701 Effect.gen(function* () {
702 const fixture = yield* makeAttachmentFixture();
703 const error = yield* buildAntigravityPrompt({
704 input: "Read this image.",
705 attachments: [imageAttachment],
706 resolveAttachmentPath: fixture.resolve,
707 promptCapabilities: { image: true, audio: true, embeddedContext: true },
708 }).pipe(Effect.flip);
709
710 expect(error).toMatchObject({
711 _tag: "AcpRequestError",
712 code: -32602,
713 errorMessage: "Could not read attachment 'screen.png'.",
714 });
715 }),
716 );
717});