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

AntigravityAcpSupport.test.ts

723 lines26.7 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 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 };
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 ]) {
173 expect(antigravityPermissionDisposition(policy, otherCall)).toBe("ask");
174 }
175 },
176 );
177});
178​
179describe("applyAntigravityAcpModelSelection", () => {
180 it.effect("restores the saved model instead of the cold-resume default", () =>
181 Effect.gen(function* () {
182 const { runtime, selections } = makeModelRuntime();
183 const model = yield* applyAntigravityAcpModelSelection({
184 runtime,
185 model: "gemini-saved",
186 mapError: (cause) => cause,
187 });
188​
189 expect(model).toBe("gemini-saved");
190 expect(selections).toEqual(["gemini-saved"]);
191 }),
192 );
193​
194 it.effect.each([undefined, null, ANTIGRAVITY_DEFAULT_MODEL])(
195 "uses the native default for %s without sending an internal model ID",
196 (requestedModel) =>
197 Effect.gen(function* () {
198 const { runtime, selections } = makeModelRuntime();
199 const model = yield* applyAntigravityAcpModelSelection({
200 runtime,
201 model: requestedModel,
202 mapError: (cause) => cause,
203 });
204​
205 expect(model).toBe("gemini-default");
206 expect(selections).toEqual([]);
207 }),
208 );
209​
210 it.effect("selects the manifest default for the alias when the account offers it", () =>
211 Effect.gen(function* () {
212 const { runtime, selections } = makeModelRuntime();
213 const model = yield* applyAntigravityAcpModelSelection({
214 runtime,
215 model: ANTIGRAVITY_DEFAULT_MODEL,
216 defaultModel: "gemini-saved",
217 mapError: (cause) => cause,
218 });
219 expect(model).toBe("gemini-saved");
220 expect(selections).toEqual(["gemini-saved"]);
221​
222 const { runtime: other, selections: otherSelections } = makeModelRuntime();
223 const fallback = yield* applyAntigravityAcpModelSelection({
224 runtime: other,
225 model: ANTIGRAVITY_DEFAULT_MODEL,
226 defaultModel: "gemini-not-offered",
227 mapError: (cause) => cause,
228 });
229 expect(fallback).toBe("gemini-default");
230 expect(otherSelections).toEqual([]);
231 }),
232 );
233​
234 it.effect.each(["gemini-removed", "Gemini saved", "gemini-saved[reasoning=high]"])(
235 "rejects unavailable or non-native model ID %s without selecting a fallback",
236 (model) =>
237 Effect.gen(function* () {
238 const { runtime, selections } = makeModelRuntime();
239 const error = yield* applyAntigravityAcpModelSelection({
240 runtime,
241 model,
242 mapError: (cause) => cause,
243 }).pipe(Effect.flip);
244​
245 expect(error).toMatchObject({
246 _tag: "AcpRequestError",
247 code: -32602,
248 errorMessage: expect.stringContaining(`'${model}' is unavailable`),
249 });
250 expect(selections).toEqual([]);
251 }),
252 );
253​
254 it.effect("accepts exact model IDs from grouped native options", () =>
255 Effect.gen(function* () {
256 const { runtime, selections } = makeModelRuntime([
257 {
258 ...modelConfig,
259 options: [{ groupId: "gemini", name: "Gemini", options: modelConfig.options }],
260 },
261 ]);
262 const model = yield* applyAntigravityAcpModelSelection({
263 runtime,
264 model: "gemini-saved",
265 mapError: (cause) => cause,
266 });
267​
268 expect(model).toBe("gemini-saved");
269 expect(selections).toEqual(["gemini-saved"]);
270 }),
271 );
272​
273 it.effect("passes a model ID saved on runtime 1.3 to the agent as its 1.4 family", () =>
274 Effect.gen(function* () {
275 // The cold-resume model has no thinking option, so the level is unknown locally.
276 const { runtime, selections } = makeModelRuntime([
277 {
278 ...modelConfig,
279 currentValue: "gpt-oss-120b-medium",
280 options: [
281 { value: "gemini-3.8-flash", name: "Gemini 3.8 Flash" },
282 { value: "gpt-oss-120b-medium", name: "GPT-OSS 120B (Medium)" },
283 ],
284 },
285 ]);
286 const model = yield* applyAntigravityAcpModelSelection({
287 runtime,
288 model: "gemini-3.8-flash-low",
289 mapError: (cause) => cause,
290 });
291​
292 expect(model).toBe("gemini-3.8-flash");
293 expect(selections).toEqual(["model=gemini-3.8-flash-low (unlisted)"]);
294 }),
295 );
296});
297​
298const imageAttachment = {
299 type: "image",
300 id: "thread-00000000-0000-4000-8000-000000000001",
301 name: "screen.png",
302 mimeType: "image/png",
303 sizeBytes: 1,
304} satisfies ChatAttachment;
305​
306const textAttachment = {
307 type: "file",
308 id: "thread-00000000-0000-4000-8000-000000000002-tsx",
309 name: "example.tsx",
310 mimeType: "application/octet-stream",
311 sizeBytes: 1,
312} satisfies ChatAttachment;
313​
314const pdfAttachment = {
315 type: "file",
316 id: "thread-00000000-0000-4000-8000-000000000003-pdf",
317 name: "report.pdf",
318 mimeType: "application/pdf",
319 sizeBytes: 1,
320} satisfies ChatAttachment;
321​
322const makeAttachmentFixture = Effect.fn("AntigravityAcpSupportTest.makeAttachmentFixture")(
323 function* () {
324 const fs = yield* FileSystem.FileSystem;
325 const path = yield* Path.Path;
326 const attachmentsDir = yield* fs.makeTempDirectoryScoped({
327 prefix: "t3-antigravity-attachments-",
328 });
329 const write = Effect.fn("AntigravityAcpSupportTest.writeAttachment")(function* (
330 attachment: ChatAttachment,
331 content: string | Uint8Array,
332 ) {
333 const filePath = resolveAttachmentPath({ attachmentsDir, attachment });
334 if (filePath === null) throw new Error("Invalid test attachment path.");
335 if (typeof content === "string") yield* fs.writeFileString(filePath, content);
336 else yield* fs.writeFile(filePath, content);
337 return { filePath, uri: (yield* path.toFileUrl(filePath)).href };
338 });
339 const resolve = (attachment: ChatAttachment) =>
340 resolveAttachmentPath({ attachmentsDir, attachment });
341 return { fs, attachmentsDir, resolve, write };
342 },
343);
344​
345it.layer(NodeServices.layer)("buildAntigravityPrompt", (it) => {
346 it.effect("sends image bytes as native image content alongside the user prompt", () =>
347 Effect.gen(function* () {
348 const fixture = yield* makeAttachmentFixture();
349 const bytes = Buffer.from(
350 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jY9kAAAAASUVORK5CYII=",
351 "base64",
352 );
353 yield* fixture.write(imageAttachment, bytes);
354 const prompt = yield* buildAntigravityPrompt({
355 input: " Explain this image. ",
356 attachments: [imageAttachment],
357 resolveAttachmentPath: fixture.resolve,
358 promptCapabilities: { image: true, audio: true, embeddedContext: true },
359 });
360​
361 expect(prompt).toEqual([
362 { type: "text", text: "Explain this image." },
363 { type: "image", data: bytes.toString("base64"), mimeType: "image/png" },
364 ]);
365 }),
366 );
367​
368 it.effect.each(["utf8", "utf16le", "utf16be"] as const)(
369 "embeds %s code from the selected environment and keeps the upload in place",
370 (encoding) =>
371 Effect.gen(function* () {
372 const selectedEnvironment = yield* makeAttachmentFixture();
373 const otherEnvironment = yield* makeAttachmentFixture();
374 const source = ' const name = "caf\u00e9 πŸš€";\r\n';
375 const bytes =
376 encoding === "utf8" ? Buffer.from(source) : Buffer.from("\ufeff" + source, "utf16le");
377 if (encoding === "utf16be") bytes.swap16();
378 const upload = yield* selectedEnvironment.write(textAttachment, bytes);
379 yield* otherEnvironment.write(textAttachment, "Different environment.");
380 const prompt = yield* buildAntigravityPrompt({
381 input: undefined,
382 attachments: [textAttachment],
383 resolveAttachmentPath: selectedEnvironment.resolve,
384 promptCapabilities: { image: true, audio: true, embeddedContext: true },
385 });
386​
387 expect(prompt).toEqual([
388 {
389 type: "resource",
390 resource: { uri: upload.uri, mimeType: "application/octet-stream", text: source },
391 },
392 ]);
393 expect(Buffer.from(yield* selectedEnvironment.fs.readFile(upload.filePath))).toEqual(bytes);
394 expect(
395 yield* selectedEnvironment.fs.readDirectory(selectedEnvironment.attachmentsDir),
396 ).toHaveLength(1);
397 }),
398 );
399​
400 it.effect("keeps folded clipboard text out of native context", () =>
401 Effect.gen(function* () {
402 const fixture = yield* makeAttachmentFixture();
403 const pastedText = {
404 ...textAttachment,
405 name: "pasted-text.txt",
406 mimeType: "text/plain",
407 source: { _tag: "pasted-text" as const },
408 } satisfies ChatAttachment;
409 yield* fixture.write(pastedText, "A very large crash report");
410​
411 const prompt = yield* buildAntigravityPrompt({
412 input: "Inspect the pasted text only as needed.",
413 attachments: [pastedText],
414 resolveAttachmentPath: fixture.resolve,
415 promptCapabilities: { image: true, audio: true, embeddedContext: true },
416 });
417​
418 expect(prompt).toEqual([{ type: "text", text: "Inspect the pasted text only as needed." }]);
419 }),
420 );
421​
422 it.effect.each([
423 { name: "archive.zip", mimeType: "application/zip" },
424 { name: "clip.mp4", mimeType: "video/mp4" },
425 { name: "recording.aiff", mimeType: "audio/aiff" },
426 { name: "large.pdf", mimeType: "application/pdf", sizeBytes: 75_000_000 },
427 { name: "large.txt", mimeType: "text/plain", sizeBytes: 1024 * 1024 + 1 },
428 { name: "large.wav", mimeType: "audio/wav", sizeBytes: 20 * 1024 * 1024 + 1 },
429 ])("keeps $name as a file path without reading or spending the native media budget", (file) =>
430 Effect.gen(function* () {
431 const fixture = yield* makeAttachmentFixture();
432 const attachment = { ...textAttachment, sizeBytes: 50 * 1024 * 1024, ...file };
433 const upload = yield* fixture.write(attachment, "");
434 yield* fixture.fs.truncate(upload.filePath, attachment.sizeBytes);
435 const pdf = yield* fixture.write(pdfAttachment, "");
436 yield* fixture.fs.truncate(pdf.filePath, 50 * 1024 * 1024);
437 const input = `Inspect the file at ${upload.filePath}`;
438 const prompt = yield* buildAntigravityPrompt({
439 input,
440 attachments: [attachment, pdfAttachment],
441 resolveAttachmentPath: fixture.resolve,
442 promptCapabilities: { image: true, audio: true, embeddedContext: true },
443 }).pipe(
444 Effect.provideService(FileSystem.FileSystem, {
445 ...fixture.fs,
446 stream: () => {
447 throw new Error("Path attachments must not be read into the prompt");
448 },
449 }),
450 );
451 expect(prompt).toEqual([
452 { type: "text", text: input },
453 {
454 type: "resource_link",
455 uri: pdf.uri,
456 name: "report.pdf",
457 mimeType: "application/pdf",
458 size: 50 * 1024 * 1024,
459 },
460 ]);
461 }),
462 );
463​
464 it.effect.each([undefined, {}, { image: false, audio: false, embeddedContext: false }])(
465 "keeps attachments path-only when native prompt capabilities are absent: %s",
466 (promptCapabilities) =>
467 Effect.gen(function* () {
468 const fixture = yield* makeAttachmentFixture();
469 const audio = {
470 ...textAttachment,
471 id: "unsupported-audio",
472 name: "audio.wav",
473 mimeType: "audio/wav",
474 };
475 const gifAttachment = {
476 ...imageAttachment,
477 id: "unsupported-gif",
478 name: "animation.gif",
479 mimeType: "image/gif",
480 };
481 const gif = yield* fixture.write(gifAttachment, "GIF89a");
482 const image = yield* fixture.write(imageAttachment, "pixels");
483 const pdf = yield* fixture.write(pdfAttachment, "%PDF-1.7");
484 const text = yield* fixture.write(textAttachment, "hello");
485 const sound = yield* fixture.write(audio, "RIFF");
486 const input = `Read ${image.filePath}, ${gif.filePath}, ${pdf.filePath}, ${text.filePath}, and ${sound.filePath}`;
487 const prompt = yield* buildAntigravityPrompt({
488 input,
489 attachments: [imageAttachment, gifAttachment, pdfAttachment, textAttachment, audio],
490 resolveAttachmentPath: fixture.resolve,
491 promptCapabilities,
492 }).pipe(
493 Effect.provideService(FileSystem.FileSystem, {
494 ...fixture.fs,
495 stream: () =>
496 Effect.die("Unnegotiated attachments must not be read").pipe(Stream.fromEffect),
497 }),
498 );
499 expect(prompt).toEqual([{ type: "text", text: input }]);
500 expect(
501 yield* buildAntigravityPrompt({
502 input: "Continue",
503 attachments: [],
504 resolveAttachmentPath: fixture.resolve,
505 promptCapabilities,
506 }),
507 ).toEqual([{ type: "text", text: "Continue" }]);
508 }),
509 );
510​
511 it.effect("sends supported audio files as native audio content", () =>
512 Effect.gen(function* () {
513 const fixture = yield* makeAttachmentFixture();
514 const audioAttachment = {
515 ...textAttachment,
516 id: "recording-1",
517 name: "recording.wav",
518 mimeType: "audio/wav",
519 } satisfies ChatAttachment;
520 const bytes = Buffer.from("RIFF....WAVEfmt ", "latin1");
521 yield* fixture.write(audioAttachment, bytes);
522 const prompt = yield* buildAntigravityPrompt({
523 input: "Transcribe this.",
524 attachments: [audioAttachment],
525 resolveAttachmentPath: fixture.resolve,
526 promptCapabilities: { image: true, audio: true, embeddedContext: true },
527 });
528​
529 expect(prompt).toEqual([
530 { type: "text", text: "Transcribe this." },
531 { type: "audio", data: bytes.toString("base64"), mimeType: "audio/wav" },
532 ]);
533 }),
534 );
535​
536 it.effect.each([{ image: true }])(
537 "keeps unsupported image formats path-only with capabilities %s",
538 (promptCapabilities) =>
539 Effect.gen(function* () {
540 const fixture = yield* makeAttachmentFixture();
541 const attachment = { ...imageAttachment, name: "animation.gif", mimeType: "image/gif" };
542 const upload = yield* fixture.write(attachment, "GIF89a");
543 const input = `Analyze the image at ${upload.filePath}`;
544 const prompt = yield* buildAntigravityPrompt({
545 input,
546 attachments: [attachment],
547 resolveAttachmentPath: fixture.resolve,
548 promptCapabilities,
549 }).pipe(
550 Effect.provideService(FileSystem.FileSystem, {
551 ...fixture.fs,
552 stream: () => Effect.die("Unsupported images must not be read").pipe(Stream.fromEffect),
553 }),
554 );
555​
556 expect(prompt).toEqual([{ type: "text", text: input }]);
557 }),
558 );
559​
560 it.effect("rejects oversized images using file size instead of upload metadata", () =>
561 Effect.gen(function* () {
562 const fixture = yield* makeAttachmentFixture();
563 const upload = yield* fixture.write(imageAttachment, "");
564 yield* fixture.fs.truncate(upload.filePath, PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1);
565 const error = yield* buildAntigravityPrompt({
566 input: "Read this attachment.",
567 attachments: [imageAttachment],
568 resolveAttachmentPath: fixture.resolve,
569 promptCapabilities: { image: true, audio: true, embeddedContext: true },
570 }).pipe(Effect.flip);
571 expect(error).toMatchObject({
572 _tag: "AcpRequestError",
573 code: -32602,
574 errorMessage: expect.stringContaining("'screen.png' is too large"),
575 });
576 }),
577 );
578​
579 it.effect("keeps PDF overflow on the file-path route", () =>
580 Effect.gen(function* () {
581 const fixture = yield* makeAttachmentFixture();
582 const secondAttachment = {
583 ...pdfAttachment,
584 id: `${pdfAttachment.id}-second`,
585 name: "second.pdf",
586 };
587 const first = yield* fixture.write(pdfAttachment, "");
588 const second = yield* fixture.write(secondAttachment, "");
589 yield* fixture.fs.truncate(first.filePath, (50 * 1024 * 1024) / 2);
590 yield* fixture.fs.truncate(second.filePath, (50 * 1024 * 1024) / 2);
591 const input = {
592 input: `Read ${first.filePath} and ${second.filePath}`,
593 attachments: [pdfAttachment, secondAttachment],
594 resolveAttachmentPath: fixture.resolve,
595 promptCapabilities: { image: true, audio: true, embeddedContext: true },
596 };
597 const prompt = yield* buildAntigravityPrompt(input);
598 expect(prompt).toEqual([
599 { type: "text", text: input.input },
600 {
601 type: "resource_link",
602 uri: first.uri,
603 name: "report.pdf",
604 mimeType: "application/pdf",
605 size: (50 * 1024 * 1024) / 2,
606 },
607 {
608 type: "resource_link",
609 uri: second.uri,
610 name: "second.pdf",
611 mimeType: "application/pdf",
612 size: (50 * 1024 * 1024) / 2,
613 },
614 ]);
615​
616 yield* fixture.fs.truncate(second.filePath, (50 * 1024 * 1024) / 2 + 1);
617 expect(yield* buildAntigravityPrompt(input)).toEqual([
618 { type: "text", text: input.input },
619 {
620 type: "resource_link",
621 uri: first.uri,
622 name: "report.pdf",
623 mimeType: "application/pdf",
624 size: (50 * 1024 * 1024) / 2,
625 },
626 ]);
627 }),
628 );
629​
630 it.effect("still rejects images when the native budget is full", () =>
631 Effect.gen(function* () {
632 const fixture = yield* makeAttachmentFixture();
633 const pdf = yield* fixture.write(pdfAttachment, "");
634 yield* fixture.fs.truncate(pdf.filePath, 50 * 1024 * 1024);
635 yield* fixture.write(imageAttachment, new Uint8Array([1]));
636 const error = yield* buildAntigravityPrompt({
637 input: "Inspect both attachments.",
638 attachments: [pdfAttachment, imageAttachment],
639 resolveAttachmentPath: fixture.resolve,
640 promptCapabilities: { image: true, audio: true, embeddedContext: true },
641 }).pipe(Effect.flip);
642 expect(error).toMatchObject({
643 _tag: "AcpRequestError",
644 errorMessage: expect.stringContaining("'screen.png' is too large"),
645 });
646 }),
647 );
648​
649 it.effect("rejects aggregate overflow when a text upload grows after its size check", () =>
650 Effect.gen(function* () {
651 const fixture = yield* makeAttachmentFixture();
652 const pdf = yield* fixture.write(pdfAttachment, "");
653 const text = yield* fixture.write(textAttachment, "a");
654 yield* fixture.fs.truncate(pdf.filePath, 50 * 1024 * 1024 - 1);
655 const error = yield* buildAntigravityPrompt({
656 input: undefined,
657 attachments: [pdfAttachment, textAttachment],
658 resolveAttachmentPath: fixture.resolve,
659 promptCapabilities: { image: true, audio: true, embeddedContext: true },
660 }).pipe(
661 Effect.provideService(FileSystem.FileSystem, {
662 ...fixture.fs,
663 stat: Effect.fn("AntigravityAcpSupportTest.growAfterStat")(function* (filePath: string) {
664 const info = yield* fixture.fs.stat(filePath);
665 if (filePath === text.filePath) {
666 yield* fixture.fs.writeFileString(filePath, "ab");
667 }
668 return info;
669 }),
670 }),
671 Effect.flip,
672 );
673​
674 expect(error).toMatchObject({
675 _tag: "AcpRequestError",
676 code: -32602,
677 errorMessage: "Attachment 'example.tsx' changed while being read and is too large.",
678 });
679 }),
680 );
681​
682 it.effect.each([
683 { bytes: new Uint8Array([0x80]), message: "is not a UTF-8 text file" },
684 { bytes: new Uint8Array([0xff, 0xfe, 0x61]), message: "is not a UTF-16LE text file" },
685 { bytes: new Uint8Array([0xfe, 0xff, 0x00, 0x00]), message: "contains binary data" },
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});