Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 66 additions & 28 deletions apps/server/src/provider/Layers/AntigravityAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,9 @@ it.layer(layer)("AntigravityAdapter", (it) => {
}),
);

it.effect("waits for native cancellation before a steer changes the model", () =>
it.effect("queues a follow-up turn until the in-flight prompt completes", () =>
Effect.gen(function* () {
const h = yield* makeHarness({ holdCancel: true });
const h = yield* makeHarness();
yield* h.adapter.startSession({
threadId,
cwd: process.cwd(),
Expand All @@ -609,38 +609,34 @@ it.layer(layer)("AntigravityAdapter", (it) => {
const second = yield* h.adapter
.sendTurn({
threadId,
input: "Steer the turn",
input: "Follow-up prompt",
modelSelection: { instanceId, model: nativeAlternative },
})
.pipe(Effect.forkChild);
expect(yield* h.nextCancellation).toBe(1);
expect(h.calls.slice(marker)).toEqual(["cancel:1"]);
yield* h.emitNative({
_tag: "ContentDelta",
text: "The first prompt stopped.",
rawPayload: {},
});
yield* Deferred.succeed(h.cancelRelease, undefined);
.pipe(Effect.forkChild({ startImmediately: true }));

expect(h.hasActivePrompt()).toBe(true);
expect(h.calls.slice(marker)).toEqual([]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

yield* Deferred.succeed(initialPrompt.result, { stopReason: "end_turn" });
const firstResult = yield* Fiber.join(first);

const replacement = yield* h.nextPrompt;
expect(replacement.content).toEqual([
{ type: "text", text: "Steer the turn" },
{ type: "text", text: "Follow-up prompt" },
{
type: "text",
text: expect.stringContaining(`Antigravity harness, as ${nativeAlternative}`),
},
]);
expect(h.calls.slice(marker)).toEqual([
"cancel:1",
"drained:1",
`model:${nativeAlternative}`,
"mode:default",
"prompt:2",
]);
yield* Deferred.succeed(replacement.result, { stopReason: "end_turn" });
const [oldResult, newResult] = yield* Effect.all([Fiber.join(first), Fiber.join(second)]);
expect(oldResult.turnId).toBe(newResult.turnId);
yield* h.waitForEvent((event) => event.type === "turn.completed");
expect(h.seen.filter((event) => event.type === "turn.completed")).toHaveLength(1);
const secondResult = yield* Fiber.join(second);
expect(firstResult.turnId).not.toBe(secondResult.turnId);
expect(h.seen.filter((event) => event.type === "turn.completed")).toHaveLength(2);
expect((yield* h.adapter.listSessions())[0]).toMatchObject({
status: "ready",
activeTurnId: undefined,
Expand All @@ -649,6 +645,48 @@ it.layer(layer)("AntigravityAdapter", (it) => {
}),
);

it.effect("queued follow-up turn without explicit model inherits updated session model", () =>
Effect.gen(function* () {
const h = yield* makeHarness();
yield* h.adapter.startSession({
threadId,
cwd: process.cwd(),
runtimeMode: "approval-required",
});
const first = yield* h.adapter
.sendTurn({
threadId,
input: "First prompt",
modelSelection: { instanceId, model: nativeAlternative },
})
.pipe(Effect.forkChild);
const initialPrompt = yield* h.nextPrompt;

const second = yield* h.adapter
.sendTurn({
threadId,
input: "Second queued prompt without model",
})
.pipe(Effect.forkChild({ startImmediately: true }));

expect(h.hasActivePrompt()).toBe(true);

yield* Deferred.succeed(initialPrompt.result, { stopReason: "end_turn" });
yield* Fiber.join(first);

const replacement = yield* h.nextPrompt;
expect(replacement.content).toEqual([
{ type: "text", text: "Second queued prompt without model" },
{
type: "text",
text: expect.stringContaining(`Antigravity harness, as ${nativeAlternative}`),
},
]);
yield* Deferred.succeed(replacement.result, { stopReason: "end_turn" });
yield* Fiber.join(second);
}),
);

it.effect("rejects an unavailable steer model without cancelling current work", () =>
Effect.gen(function* () {
const h = yield* makeHarness();
Expand Down Expand Up @@ -685,17 +723,20 @@ it.layer(layer)("AntigravityAdapter", (it) => {
runtimeMode: "approval-required",
});
const first = yield* h.adapter.sendTurn({ threadId, input: "First" }).pipe(Effect.forkChild);
yield* h.nextPrompt;
const prompt1 = yield* h.nextPrompt;
h.controls.failModel = true;
const failed = yield* h.adapter
.sendTurn({
threadId,
input: "Replacement",
modelSelection: { instanceId, model: nativeAlternative },
})
.pipe(Effect.exit);
expect(Exit.isFailure(failed)).toBe(true);
.pipe(Effect.forkChild);
yield* Deferred.succeed(prompt1.result, { stopReason: "end_turn" });
yield* Fiber.join(first);
yield* h.waitForEvent((event) => event.type === "turn.completed");
const failedExit = yield* Fiber.join(failed).pipe(Effect.exit);
expect(Exit.isFailure(failedExit)).toBe(true);
const ended = yield* h.waitForEvent((event) => event.type === "turn.completed");
expect(ended.payload.state).toBe("failed");
expect((yield* h.adapter.listSessions())[0]).toMatchObject({
Expand Down Expand Up @@ -1090,6 +1131,8 @@ it.layer(layer)("AntigravityAdapter", (it) => {
const steering = yield* h.adapter
.sendTurn({ threadId, input: "Change direction" })
.pipe(Effect.forkChild);
yield* Deferred.succeed(prompt.result, { stopReason: "end_turn" });
yield* Fiber.join(sending);
const replacement = yield* h.nextPrompt;
yield* Deferred.succeed(replacement.result, { stopReason: "end_turn" });
yield* Fiber.join(steering);
Expand All @@ -1101,12 +1144,7 @@ it.layer(layer)("AntigravityAdapter", (it) => {
taskId: "trajectory:4",
title: "Antigravity subagent batch",
taskType: "subagent_batch",
status:
stop === "disconnect"
? "failed"
: stop === "cancel" || stop === "steer"
? "cancelled"
: "idle",
status: stop === "disconnect" ? "failed" : stop === "cancel" ? "cancelled" : "idle",
});
if (stop === "disconnect")
yield* h.waitForEvent((event) => event.type === "session.exited");
Expand Down
Loading
Loading