feat(antigravity): refuse /swarm in Plan mode; route tests for the trusted request

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DottaandClaude Opus 5.5 committed 2026-11-23 23:02:04 -06:00
1 parent c83f18280c
commit 417c695a9a
4 files changed
+56 -5

No files matched your search

@@ -162,6 +162,17 @@ vi.mock("../services/access.js", () => ({
accessService: () => mockAccessService,
}));
const mockSwarm = vi.hoisted(() => ({
refusal: vi.fn(async (): Promise<string | null> => null),
record: vi.fn(async () => undefined),
}));
vi.mock("../services/antigravity-swarm.js", () => ({
ANTIGRAVITY_SWARM_COMMAND: "swarm",
ANTIGRAVITY_SWARM_UNAVAILABLE: "antigravity_swarm_unavailable",
antigravitySwarmCommentRefusal: mockSwarm.refusal,
recordAntigravitySwarmRequest: mockSwarm.record,
}));
vi.mock("../services/activity-log.js", () => ({
logActivity: mockLogActivity,
}));
@@ -1301,6 +1312,42 @@ describe("issue comment reopen routes", () => {
);
});
it("records a signed-in user's /swarm request and marks the assignee's wake with it", async () => {
mockSwarm.refusal.mockResolvedValue(null);
mockIssueService.getById.mockResolvedValue(makeIssue("blocked"));
mockIssueService.update.mockImplementation(async (_id: string, patch: Record<string, unknown>) => ({ ...makeIssue("blocked"), ...patch }));
const res = await request(await installActor(createApp()))
.post("/api/issues/11111111-1111-4111-8111-111111111111/comments")
.send({ body: "two helpers write a.txt and b.txt", nativeCommand: "swarm" });
expect(res.status).toBe(201);
expect(mockSwarm.record).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ commentId: "comment-1", userId: "local-board" }));
await waitForWakeup(() => expect(mockHeartbeatService.wakeup).toHaveBeenCalledWith(
"22222222-2222-4222-8222-222222222222",
expect.objectContaining({ contextSnapshot: expect.objectContaining({ antigravitySwarmCommentId: "comment-1" }) }),
));
});
it("refuses an unavailable /swarm in plain language and posts nothing", async () => {
mockSwarm.refusal.mockResolvedValue("Swarm is not turned on for this Paperclip.");
mockIssueService.getById.mockResolvedValue(makeIssue("todo"));
const res = await request(await installActor(createApp()))
.post("/api/issues/11111111-1111-4111-8111-111111111111/comments")
.send({ body: "do it", nativeCommand: "swarm" });
expect(res.status).toBe(422);
expect(res.body).toMatchObject({ error: "Swarm is not turned on for this Paperclip.", code: "antigravity_swarm_unavailable" });
expect(mockIssueService.addComment).not.toHaveBeenCalled();
expect(mockHeartbeatService.wakeup).not.toHaveBeenCalled();
});
it("accepts a swarm request only from a signed-in user", async () => {
mockIssueService.getById.mockResolvedValue(makeIssue("todo"));
const res = await request(await installActor(createApp(), { type: "agent", agentId: "33333333-3333-4333-8333-333333333333", companyId: "company-1" }))
.post("/api/issues/11111111-1111-4111-8111-111111111111/comments")
.send({ body: "do it", nativeCommand: "swarm" });
expect(res.status).toBe(403);
expect(mockIssueService.addComment).not.toHaveBeenCalled();
});
it("moves in-progress issues with a scheduled retry back to todo via POST human comments", async () => {
const issue = {
...makeIssue("in_progress"),
@@ -11,6 +11,7 @@ describe("trusted /swarm for Google Antigravity", () => {
expect(antigravitySwarmRefusal({ enabled: true, agent: { adapterType: "paperclip_runner", adapterConfig: { provider: "acpx", acpxAgent: "claude" } } }))
.toMatch(/Google Antigravity agent/);
expect(antigravitySwarmRefusal({ enabled: true, agent: antigravity, remote: true })).toMatch(/this computer/);
expect(antigravitySwarmRefusal({ enabled: true, agent: antigravity, planning: true })).toMatch(/Plan mode/);
});
it("reads a swarm request only from the wake's structured marker, never from comment text", () => {
+7 -4
View File
@@ -34,11 +34,13 @@ export function antigravitySwarmRefusal(input: {
enabled: boolean;
agent: { adapterType: string; adapterConfig: unknown } | null;
remote?: boolean;
planning?: boolean;
}): string | null {
if (!input.enabled) {
return "Swarm is not turned on for this Paperclip. An instance admin can turn on \"Google Antigravity swarm\" in Settings, Experimental.";
}
if (!isAntigravityAgent(input.agent)) return "Swarm works only for tasks assigned to a Google Antigravity agent.";
if (input.planning) return "Swarm is not available while the task is in Plan mode: helpers change files. Approve the plan first, then send /swarm.";
if (input.remote) return "Swarm is not available for this agent: it runs only on this computer, not in a cloud or remote environment.";
return null;
}
@@ -56,12 +58,12 @@ async function swarmEnabled(db: Db): Promise<boolean> {
}
/** Comment-time check, so an unavailable swarm is refused before anything is posted. */
export async function antigravitySwarmCommentRefusal(db: Db, issue: { companyId: string; assigneeAgentId: string | null }): Promise<string | null> {
export async function antigravitySwarmCommentRefusal(db: Db, issue: { companyId: string; assigneeAgentId: string | null; workMode?: string | null }): Promise<string | null> {
const [agent] = issue.assigneeAgentId
? await db.select({ adapterType: agents.adapterType, adapterConfig: agents.adapterConfig }).from(agents)
.where(and(eq(agents.id, issue.assigneeAgentId), eq(agents.companyId, issue.companyId)))
: [];
return antigravitySwarmRefusal({ enabled: await swarmEnabled(db), agent: agent ?? null });
return antigravitySwarmRefusal({ enabled: await swarmEnabled(db), agent: agent ?? null, planning: issue.workMode === "planning" });
}
/**
@@ -89,6 +91,7 @@ export async function resolveAntigravitySwarmRun(db: Db, input: {
agent: { id: string; adapterType: string; adapterConfig: unknown };
context: unknown;
remote: boolean;
planning: boolean;
}): Promise<boolean> {
const commentId = requestedAntigravitySwarmCommentId(input.context);
if (!commentId) return false;
@@ -99,14 +102,14 @@ export async function resolveAntigravitySwarmRun(db: Db, input: {
sql`${activityLog.details}->>'commentId' = ${commentId}`))
.limit(1);
if (!requested) return false;
const refusal = antigravitySwarmRefusal({ enabled: await swarmEnabled(db), agent: input.agent, remote: input.remote });
const refusal = antigravitySwarmRefusal({ enabled: await swarmEnabled(db), agent: input.agent, remote: input.remote, planning: input.planning });
if (refusal) throw new PaperclipRunnerProviderProfileError(ANTIGRAVITY_SWARM_UNAVAILABLE, refusal);
await logActivity(db, {
companyId: input.companyId, actorType: "system", actorId: "paperclip", agentId: input.agent.id, runId: input.runId,
issueId: input.issueId, action: "issue.antigravity_swarm_started", entityType: "issue", entityId: input.issueId,
details: {
commentId,
summary: "Started a Google Antigravity swarm with helpers. Helper actions inside the task folder are approved automatically; actions outside it are blocked. Usage is reported as one total for the coordinator and its helpers.",
summary: "Started a Google Antigravity swarm with helpers. Helper actions are approved automatically by Antigravity's auto mode, which keeps file changes in the task folder; helper shell commands are not visible to Paperclip and Paperclip does not sandbox them on this computer. Usage is one total for the coordinator and its helpers.",
},
});
return true;
@@ -841,7 +841,7 @@ export async function selectHeartbeatRuntime(db: Db, input: HeartbeatRuntimeSele
const antigravitySwarm = agent.adapterType === "paperclip_runner"
&& await resolveAntigravitySwarmRun(db, {
companyId: agent.companyId, issueId: issueRef.id, runId: run.id, agent,
context, remote: executionTarget?.kind === "remote",
context, remote: executionTarget?.kind === "remote", planning: executionMode === "plan",
});
const buildExecution = ({ normalizedSessionId, resumedSession }: { normalizedSessionId: string; resumedSession: boolean }) =>
buildNativeExecutionInput({