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

AntigravityAcpSupport.test.ts

713 lines25.8 KB

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