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