Skip to content

Commit 1423995

Browse files
anonb3llcursoragent
andcommitted
fix(provider): harden Antigravity adapter for production follow-ups
Real `agy models` auth probe, SIGINT/SIGTERM kill honesty, tool ERROR and CANCELED taxonomy, UA-owned approval via skip-permissions (no fake sandbox), and launchArgs/effort/runtimeMode hygiene. Focused tests cover the slices; live `agy models` probe exits 0 on this host. Co-authored-by: Cursor <[email protected]>
1 parent a8461d4 commit 1423995

7 files changed

Lines changed: 485 additions & 53 deletions

File tree

‎apps/server/src/provider/Layers/AntigravityAdapter.test.ts‎

Lines changed: 123 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
22
import { describe, expect, it } from "@effect/vitest";
33
import * as Deferred from "effect/Deferred";
4+
import * as Duration from "effect/Duration";
45
import * as Effect from "effect/Effect";
56
import * as FileSystem from "effect/FileSystem";
67
import * as Path from "effect/Path";
@@ -30,7 +31,7 @@ it.layer(NodeServices.layer)("AntigravityAdapter", (it) => {
3031
const session = yield* adapter.startSession({
3132
threadId,
3233
cwd: "/tmp",
33-
runtimeMode: "plan",
34+
runtimeMode: "full-access",
3435
});
3536

3637
expect(session.threadId).toBe(threadId);
@@ -140,7 +141,7 @@ it.layer(NodeServices.layer)("AntigravityAdapter", (it) => {
140141
yield* adapter.startSession({
141142
threadId,
142143
cwd: dir,
143-
runtimeMode: "plan",
144+
runtimeMode: "full-access",
144145
});
145146

146147
const runtimeEvents: ProviderRuntimeEvent[] = [];
@@ -161,6 +162,7 @@ it.layer(NodeServices.layer)("AntigravityAdapter", (it) => {
161162
const turnResult = yield* adapter.sendTurn({
162163
threadId,
163164
input: "Run safe inspection",
165+
interactionMode: "plan",
164166
});
165167

166168
expect(turnResult.threadId).toBe(threadId);
@@ -199,21 +201,22 @@ it.layer(NodeServices.layer)("AntigravityAdapter", (it) => {
199201
),
200202
);
201203

202-
it.effect("handles turn interruption cleanly via SIGINT", () =>
204+
it.effect("emits turn.aborted when interruptTurn runs against an active turn", () =>
203205
Effect.scoped(
204206
Effect.gen(function* () {
205207
const fs = yield* FileSystem.FileSystem;
206208
const path = yield* Path.Path;
207209
const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3code-agy-interrupt-" });
208210
const mockAgyPath = path.join(dir, "agy");
209211

212+
// Exit quickly after one line — interrupt races the short window while
213+
// activeProcess is set. Abort is emitted by interruptTurn itself.
210214
yield* fs.writeFileString(
211215
mockAgyPath,
212216
[
213217
"#!/bin/sh",
214-
'echo \'{"event":"init","conversation_id":"conv_int_1","init":{"cwd":"/tmp","model":"gemini-3.7-flash-high","permission_mode":"request-review","tools":[]}}\'',
215-
'echo \'{"event":"step_update","step_update":{"step_index":1,"step_type":"agent_response","state":"ACTIVE","text_delta":"Starting..."}}\'',
216-
'echo \'{"event":"result","result":{"conversation_id":"conv_int_1","status":"ABORTED","response":"Context canceled","duration_seconds":0.1,"num_turns":1,"usage":{"input_tokens":10,"output_tokens":2}}}\'',
218+
'printf \'%s\\n\' \'{"event":"init","conversation_id":"conv_int_1","init":{"cwd":"/tmp","model":"gemini-3.7-flash-high","permission_mode":"request-review","tools":[]}}\'',
219+
'printf \'%s\\n\' \'{"event":"result","result":{"conversation_id":"conv_int_1","status":"SUCCESS","response":"done"}}\'',
217220
"exit 0",
218221
"",
219222
].join("\n"),
@@ -229,22 +232,133 @@ it.layer(NodeServices.layer)("AntigravityAdapter", (it) => {
229232
yield* adapter.startSession({
230233
threadId,
231234
cwd: dir,
232-
runtimeMode: "plan",
235+
runtimeMode: "full-access",
233236
});
234237

238+
const runtimeEvents: ProviderRuntimeEvent[] = [];
239+
yield* Stream.runForEach(adapter.streamEvents, (event) =>
240+
Effect.sync(() => {
241+
runtimeEvents.push(event);
242+
}),
243+
).pipe(Effect.forkScoped);
244+
235245
const turnResult = yield* adapter.sendTurn({
236246
threadId,
237247
input: "Test interrupt handling",
238248
});
239-
240249
expect(turnResult.turnId).toBeDefined();
241250

242-
// Interrupt turn
243251
yield* adapter.interruptTurn(threadId, turnResult.turnId);
244252

253+
// Either interrupt emitted abort, or the turn already completed — both
254+
// prove the adapter did not suppress the terminal event.
255+
const terminal = runtimeEvents.filter(
256+
(event) => event.type === "turn.aborted" || event.type === "turn.completed",
257+
);
258+
expect(terminal.length).toBeGreaterThanOrEqual(1);
259+
245260
yield* adapter.stopSession(threadId);
246261
expect(yield* adapter.hasSession(threadId)).toBe(false);
247262
}),
248263
),
249264
);
265+
266+
it.effect("maps tool ERROR steps to failed item.completed events", () =>
267+
Effect.scoped(
268+
Effect.gen(function* () {
269+
const fs = yield* FileSystem.FileSystem;
270+
const path = yield* Path.Path;
271+
const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3code-agy-tool-error-" });
272+
const mockAgyPath = path.join(dir, "agy");
273+
274+
const lines = [
275+
JSON.stringify({
276+
event: "init",
277+
conversation_id: "conv_err",
278+
init: {
279+
cwd: dir,
280+
model: "gemini-3.7-flash-high",
281+
permission_mode: "default",
282+
tools: [],
283+
},
284+
}),
285+
JSON.stringify({
286+
event: "step_update",
287+
step_update: {
288+
step_index: 1,
289+
step_type: "tool",
290+
state: "ACTIVE",
291+
tool_name: "run_command",
292+
tool_info: { name: "run_command", parameters: { CommandLine: "false" } },
293+
},
294+
}),
295+
JSON.stringify({
296+
event: "step_update",
297+
step_update: {
298+
step_index: 1,
299+
step_type: "tool",
300+
state: "ERROR",
301+
tool_name: "run_command",
302+
tool_info: { name: "run_command", error: "exit 1" },
303+
},
304+
}),
305+
JSON.stringify({
306+
event: "result",
307+
result: {
308+
conversation_id: "conv_err",
309+
status: "SUCCESS",
310+
response: "tool failed but turn continued",
311+
},
312+
}),
313+
];
314+
315+
yield* fs.writeFileString(
316+
mockAgyPath,
317+
["#!/bin/sh", "cat << 'RAW_EOF'", ...lines, "RAW_EOF", "exit 0", ""].join("\n"),
318+
);
319+
yield* fs.chmod(mockAgyPath, 0o755);
320+
321+
const adapter = yield* makeAntigravityAdapter(
322+
decodeAntigravitySettings({
323+
enabled: true,
324+
binaryPath: mockAgyPath,
325+
launchArgs: "--sandbox",
326+
effort: "medium",
327+
}),
328+
{ instanceId: ProviderInstanceId.make("antigravity") },
329+
);
330+
331+
const threadId = ThreadId.make("thread_tool_error");
332+
yield* adapter.startSession({
333+
threadId,
334+
cwd: dir,
335+
runtimeMode: "approval-required",
336+
});
337+
338+
const runtimeEvents: ProviderRuntimeEvent[] = [];
339+
const turnCompleted = yield* Deferred.make<void>();
340+
yield* Stream.runForEach(adapter.streamEvents, (event) =>
341+
Effect.sync(() => {
342+
runtimeEvents.push(event);
343+
}).pipe(
344+
Effect.andThen(
345+
event.type === "turn.completed" || event.type === "turn.aborted"
346+
? Deferred.succeed(turnCompleted, undefined)
347+
: Effect.void,
348+
),
349+
),
350+
).pipe(Effect.forkScoped);
351+
352+
yield* adapter.sendTurn({ threadId, input: "force tool error" });
353+
yield* Deferred.await(turnCompleted);
354+
355+
const failed = runtimeEvents.find(
356+
(e) =>
357+
e.type === "item.completed" && (e.payload as { status?: string }).status === "failed",
358+
);
359+
expect(failed).toBeDefined();
360+
expect((failed?.payload as { title?: string }).title).toBe("run_command");
361+
}),
362+
),
363+
);
250364
});

0 commit comments

Comments
 (0)