Files
PaperClipAI/server/src/services/native-runtime/antigravity-release.test.ts
T
DottaandPaperclip e04efb9734 feat(antigravity): allow plugin Runner-task and remote Google sign-in targets once released (#22940)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The native Runner executes Google Antigravity on local hosts, Core
managed sandboxes, and plugin Runner-task environments such as Paperclip
Computer.
> - Before this change, Paperclip refused Google sign-in on all remote
targets even after release, returned an unavailable error when testing
Antigravity on plugin Runner-task environments, and did not wire remote
refresh-token write-back on Core sandboxes or released Antigravity
profile resolution.
> - Paperclip Cloud needs Google Antigravity to run with both Gemini API
keys and Google sign-in on both plugin Runner-task environments and Core
managed sandboxes once the profile flips from pending to qualified.
> - This pull request lifts the released-state remote sign-in refusal,
wires plugin Runner-task probing and released profile resolution for
Antigravity, adds Core sandbox remote sign-in write-back and checkpoint
exclusion, and keeps pending-release candidate grants restricted to
API-key non-plugin targets.
> - The benefit is that flipping the Antigravity profile from pending to
qualified immediately enables picker selection, agent creation/save,
Test probing, and execution with either Gemini API keys or Google
sign-in on both plugin Runner-task environments and Core sandboxes.

## Linked Issues or Issue Description

- Refs #22923 (Item 6 of
`doc/plans/2026-11-25-antigravity-cloud-rollout.md`, gaps G6 and G7)
- Pairs with #22933 (Item 2: Antigravity sign-in task credential and
plugin write-back) and #22935 (Item 3: keep per-turn-only harnesses
per-turn on warm environments)
- Refs #22930 (Item 1: Gemini API key task credential for plugin
Runners)

## What Changed

- **Remote Google sign-in policy & credential preparation
(`antigravity-connection-policy.ts`,
`antigravity-runner-credentials.ts`)**:
- Allow both Gemini API key and Google sign-in on remote targets in
`antigravityConnectionRefusal` once `releasePending` is `false`, while
keeping `lifecycleMode: "warm"` refused and keeping pending-release
candidate grants API-key-only on non-plugin remote targets.
- Strip all `GOOGLE_*` and non-selected `GEMINI_*` variables (plus
`PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET`) in
`prepareAntigravityRunnerCredentials`, enforce
`antigravityConnectionRefusal` using `antigravityReleasePending()`, and
pass pure sanitized sign-in JSON on remote runs (without local `/swarm`
metadata).
- **Core sandbox remote sign-in write-back & checkpoint safety
(`native-credential-store.ts`, `native-session-executor.ts`,
`antigravity-runner-credentials.ts`)**:
- Extend `createNativeCredentialStore` to support `provider:
"antigravity"` (`acp_token.json` and `auth-refresh.json`) over local and
remote command runners.
- Add optional `runtimeStore` support to `antigravityCredentialTurn` and
wire it in `native-session-executor.ts` for Core remote sandboxes so
rotated Google refresh tokens copy back after process retirement and
remote credential files are scrubbed.
- Exclude
`antigravity-home/antigravity-acp/{acp_token.json,auth-refresh.json,auth-refresh.json.tmp,logs}`
from remote ACPX session checkpoints.
- Enforce `antigravityConnectionRefusal` in `preparePluginTaskOwner` and
reject pending `pluginTask` execution in
`assertAntigravityExecutionAdmissible` (defense in depth).
- **Plugin Runner-task probing, released profile resolution & agent
save/setup (`provider-profile.ts`, `plugin-runner-probe.ts`,
`antigravity-connection-probe.ts`, `agent-environment-test.ts`,
`agents.ts`, `NewAgentSetup.tsx`)**:
- Add `antigravity` to `DEFAULT_ACPX_RUNNER_MODELS` and the qualified
ACPX agent allowlist in `provider-profile.ts`, requiring an explicit
non-placeholder model ID and checking `antigravityReleasePending()`.
- Wire `testAntigravityConnection` to delegate plugin Runner-task
targets to `probePluginRunnerEnvironment` instead of returning `"Google
Antigravity is unavailable in this hosting environment."`, and update
`probePluginRunnerEnvironment` to run `admissionOnly: true` for
Antigravity with either Gemini API key or Google sign-in once released,
returning `antigravity_metadata_verified`.
- Allow Core sandbox/SSH `probeAntigravityExecutionTarget` for Google
sign-in once released, preserve `antigravity_remote_runtime_ready` warn
status in `agent-environment-test.ts` and `NewAgentSetup.tsx`.
- Allow released Antigravity creation without `enableNativeRunner`,
allow released remote sign-in account model discovery on the tenant
host, and refuse pending plugin targets even when a `linux-x64`
candidate grant exists.
- Note on existing >1,000-line files: edits to
`server/src/routes/agents.ts` and
`server/src/services/native-runtime/native-session-executor.ts` are
minimal wiring at existing Antigravity call sites (+12 and +26 net
lines).
- **Tests**:
- Updated `antigravity-runner-credentials.test.ts`,
`native-credential-store.test.ts`, `antigravity-save-refusal.test.ts`,
`antigravity-connection-probe.test.ts`, `antigravity-release.test.ts`,
`adapter-routes.test.ts`, `agent-runner-selection.test.ts`,
`agent-environment-test-status.test.ts`,
`native-session-executor.test.ts`, and
`ui/src/lib/cloud-harness-policy.test.ts`.
- Added
`server/src/services/native-runtime/plugin-runner-probe-antigravity.test.ts`.

## Verification

- Local Vitest (all passed against a released-profile fixture as well as
the real pending profile):
- `pnpm --filter @paperclipai/server exec vitest run
src/services/native-runtime/antigravity-runner-credentials.test.ts
src/services/native-runtime/native-credential-store.test.ts
src/services/native-runtime/antigravity-release.test.ts
src/services/native-runtime/plugin-runner-probe-antigravity.test.ts
src/services/native-runtime/plugin-runner-probe-runner-mismatch.test.ts
src/services/native-runtime/plugin-runner-credentials.test.ts
src/__tests__/antigravity-connection-probe.test.ts
src/__tests__/antigravity-save-refusal.test.ts
src/__tests__/antigravity-managed-subscription.test.ts
src/__tests__/antigravity-plugin-task-credential-writeback.test.ts
src/services/agent-runner-selection.test.ts
src/services/agent-environment-test-status.test.ts` (12 files, 425 tests
passed)
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/adapter-routes.test.ts --hookTimeout=60000` (36 passed)
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/agent-test-environment-routes.test.ts --hookTimeout=60000
-t "passes the selected Antigravity"` (1 passed)
- `pnpm --filter @paperclipai/server exec vitest run
src/services/native-runtime/native-session-executor.test.ts -t "projects
the selected Antigravity subscription"` (2 passed)
- `pnpm --filter @paperclipai/ui exec vitest run
src/lib/cloud-harness-policy.test.ts` (36 passed)
- Typechecks:
  - `pnpm --filter @paperclipai/server exec tsc --noEmit` (passed)
  - `pnpm --filter @paperclipai/ui typecheck` (passed)
- Not run live: the real Antigravity profile remains `pending` until
Item 8; live staging verification on Paperclip Computer and Core managed
sandboxes is covered by Item 12.

## Risks

- Low risk while the Antigravity profile remains `pending`: all new
remote sign-in and plugin Runner-task paths stay gated behind
`!antigravityReleasePending()`, and pending-release candidate behavior
remains unchanged (and tighter on plugin environments).
- Once Item 8 flips the profile to qualified, released Antigravity
agents on Core sandboxes and plugin Runner-task environments will use
the paths tested here; live acceptance on staging is gated by Items
9–12.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Google Gemini (Antigravity agent with tool use and code execution)

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-25 08:36:37 -06:00

290 lines
18 KiB
TypeScript

import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { basename, join } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
// Both release states are exercised against the same build: the pending
// candidate declaration that ships today, and the qualified declaration the
// flip produces (no qualificationStatus, profile version bumped), as the Kimi
// probe tests stub it.
const release = vi.hoisted(() => ({ pending: true }));
vi.mock("../../vendor/paperclip-runner/index.js", async importOriginal => {
const original = await importOriginal<typeof import("../../vendor/paperclip-runner/index.js")>();
const { qualificationStatus: _pending, ...qualified } = original.QUALIFIED_ACPX_PROFILES.antigravity;
const released = { ...qualified, agentProfileVersion: qualified.agentProfileVersion + 1 };
const profiles = { ...original.QUALIFIED_ACPX_PROFILES };
Object.defineProperty(profiles, "antigravity", { enumerable: true,
get: () => release.pending ? original.QUALIFIED_ACPX_PROFILES.antigravity : released });
return { ...original, QUALIFIED_ACPX_PROFILES: profiles };
});
import { NativeProviderStateIncompatibleError, QUALIFIED_ACPX_PROFILES, type NativeExecutionInput } from "../../vendor/paperclip-runner/index.js";
import { ANTIGRAVITY_CANDIDATE_ADMISSION_ENV } from "./acpx-qualification.js";
import {
antigravityCandidateForRunnerTarget,
antigravityForcesSameSessionRecovery,
antigravityReleasePending,
antigravityUsesRunScopedState,
assertAntigravityExecutionAdmissible,
} from "./antigravity-release.js";
import { buildNativeExecutionInput } from "./native-execution-input.js";
import { nativeSessionFailureDisposition, nativeSessionFailureSourceCode, retireNeverOpenedCandidateRunRoot, scopedRunnerdStateRoot } from "./native-session-executor.js";
import { NATIVE_PROVIDER_STATE_INCOMPATIBLE } from "./native-session-resume.js";
import { nativeRuntimeContextFixture } from "./runtime-context.test-fixture.js";
const companyId = "10000000-0000-4000-8000-000000000001";
const model = "gemini-3.8-flash-low";
const localHost = process.platform === "darwin" && process.arch === "arm64";
const distributions = JSON.parse(readFileSync(new URL("../../../../packages/paperclip-runner/antigravity-distributions.json", import.meta.url), "utf8"));
function antigravityExecution(input: { runId?: string; issueId?: string; workspaceId?: string; sessionId?: string } = {}) {
const runId = input.runId ?? "40000000-0000-4000-8000-000000000004";
const execution = buildNativeExecutionInput({
companyId, runId, agentId: "30000000-0000-4000-8000-000000000003",
issue: { id: input.issueId ?? "20000000-0000-4000-8000-000000000002", identifier: "AG-1", title: "Test", description: null, workMode: "standard" },
taskPrompt: "Only the current turn",
workspace: { id: input.workspaceId ?? "90000000-0000-4000-8000-000000000009", cwd: "/workspace", repoUrl: null, repoRef: null, branchName: null },
normalizedSessionId: input.sessionId ?? "60000000-0000-4000-8000-000000000006",
provider: "acpx", acpxAgent: "antigravity", model, acpxPermissionMode: "approve-all",
completionContract: { id: "70000000-0000-4000-8000-000000000007", sha256: `sha256:${"a".repeat(64)}`, schemaVersion: "paperclip.run-result.v1",
contract: { revision: "1", objective: "Test", criteria: [{ id: "objective", requirement: "Answer" }] } },
runtimeContext: nativeRuntimeContextFixture(),
}) as NativeExecutionInput;
// The execution input binds the profile version the running release declares.
(execution.provider as { profile: { agentProfileVersion: number } }).profile.agentProfileVersion =
QUALIFIED_ACPX_PROFILES.antigravity.agentProfileVersion;
return execution;
}
const candidateGrant = (target = "darwin-arm64", changes: Record<string, unknown> = {}) => {
const [platform, architecture] = target.split("-");
return JSON.stringify({ schema: "paperclip.acpx-candidate-admission.v1", companyId,
agent: "antigravity", model, profileDigest: QUALIFIED_ACPX_PROFILES.antigravity.commandDigest,
nativeClosureDigest: `sha256:${distributions.platforms[target].closureSha256}`,
platform, architecture, expiresAt: Date.now() + 60_000, ...changes });
};
afterEach(() => { release.pending = true; vi.unstubAllEnvs(); });
describe("Antigravity executor admission", () => {
const admissible = (execution: NativeExecutionInput, changes: Partial<Parameters<typeof assertAntigravityExecutionAdmissible>[0]> = {}) =>
() => assertAntigravityExecutionAdmissible({ execution, useRunnerd: true, remoteTarget: false, ...changes });
it("requires the exact local per-turn candidate grant while the profile is pending", () => {
expect(antigravityReleasePending()).toBe(true);
const execution = antigravityExecution();
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, undefined);
expect(admissible(execution)).toThrow(/paperclip_runner_antigravity_candidate_ineligible/);
if (!localHost) return;
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, candidateGrant());
expect(admissible(execution)).not.toThrow();
// A local grant never admits a cloud run.
for (const change of [{ remoteTarget: true }, { restartRecovery: { kind: "same_run" } }, { useRunnerd: false }, { backend: {} }]) {
expect(admissible(execution, change)).toThrow(/candidate_ineligible/);
}
const warm = { ...execution, session: { ...execution.session, lifecyclePolicy: { mode: "warm", idleTimeoutMs: 1 } } } as NativeExecutionInput;
expect(admissible(warm)).toThrow(/candidate_ineligible/);
});
it("admits a cloud run only with a linux-x64 grant naming the patched closure, for the granted company", () => {
const execution = antigravityExecution();
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, candidateGrant("linux-x64"));
expect(admissible(execution, { remoteTarget: true })).not.toThrow();
expect(admissible(execution, { remoteTarget: true, pluginTask: true })).toThrow(/candidate_ineligible/);
const warm = { ...execution, session: { ...execution.session, lifecyclePolicy: { mode: "warm", idleTimeoutMs: 1 } } } as NativeExecutionInput;
expect(admissible(warm, { remoteTarget: true })).toThrow(/candidate_ineligible/);
expect(admissible(execution, { remoteTarget: true, restartRecovery: { kind: "reattach_remote_runner" } })).toThrow(/candidate_ineligible/);
const otherCompany = { ...execution, binding: { ...execution.binding, companyId: "10000000-0000-4000-8000-0000000000ff" } } as NativeExecutionInput;
expect(admissible(otherCompany, { remoteTarget: true })).toThrow(/candidate_ineligible/);
for (const grant of [candidateGrant("linux-arm64"), candidateGrant("darwin-arm64"),
candidateGrant("linux-x64", { nativeClosureDigest: `sha256:${distributions.platforms["linux-x64"].vendorClosureSha256}` }),
candidateGrant("linux-x64", { model: "gemini-3.8-flash-high" })]) {
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, grant);
expect(admissible(execution, { remoteTarget: true })).toThrow(/candidate_ineligible/);
}
});
it("takes the general qualified path after the flip: no grant, restart recovery, remote and warm targets", () => {
release.pending = false;
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, undefined);
const execution = antigravityExecution();
expect(admissible(execution)).not.toThrow();
expect(admissible(execution, { remoteTarget: true, pluginTask: true })).not.toThrow();
expect(admissible(execution, { remoteTarget: true, restartRecovery: { kind: "reattach_remote_runner" } })).not.toThrow();
const preconfigured = { ...execution, homeMode: "preconfigured" } as NativeExecutionInput;
expect(admissible(preconfigured)).not.toThrow();
});
});
describe("Antigravity agent picker candidate", () => {
const cloud = { driver: "sandbox", platform: "linux", architecture: "x64", libc: "glibc" as const, glibcVersion: "2.39" };
it("offers a cloud environment only the company's own unexpired linux-x64 grant", () => {
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, candidateGrant("linux-x64"));
expect(antigravityCandidateForRunnerTarget(companyId, cloud)).toMatchObject({ model, platform: "linux", architecture: "x64" });
expect(antigravityCandidateForRunnerTarget(companyId, { driver: "sandbox", managedCloudImage: true })).toMatchObject({ model });
expect(antigravityCandidateForRunnerTarget("10000000-0000-4000-8000-00000000000f", cloud)).toBeUndefined();
expect(antigravityCandidateForRunnerTarget(companyId, { ...cloud, architecture: "arm64" })).toBeUndefined();
expect(antigravityCandidateForRunnerTarget(companyId, { driver: "plugin", runnerTasks: true })).toBeUndefined();
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, candidateGrant("linux-x64", { expiresAt: Date.now() - 1 }));
expect(() => antigravityCandidateForRunnerTarget(companyId, cloud)).toThrow();
});
it("does not open a cloud environment with a grant for this host", () => {
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, candidateGrant("darwin-arm64"));
expect(() => antigravityCandidateForRunnerTarget(companyId, cloud)).toThrow(/does not match the execution target/);
});
it("offers a cloud environment nothing when its Linux libc cannot run the Runner", () => {
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, candidateGrant("linux-x64"));
for (const target of [
{ ...cloud, libc: "musl" as const, glibcVersion: undefined },
{ ...cloud, libc: "unknown" as const, glibcVersion: undefined },
{ ...cloud, glibcVersion: "2.35" },
{ driver: "ssh", platform: "linux", architecture: "x64", libc: "glibc" as const, glibcVersion: "2.31" },
]) expect(antigravityCandidateForRunnerTarget(companyId, target)).toBeUndefined();
expect(antigravityCandidateForRunnerTarget(companyId, { driver: "ssh", platform: "linux", architecture: "x64", libc: "glibc", glibcVersion: "2.41" }))
.toMatchObject({ model });
});
it("offers this host only a grant that names this host", () => {
// Pin the host to darwin-arm64 so the result does not depend on the machine
// running the test. A cloud (linux-x64) grant is valid for an untargeted
// lookup on every host, so only a host-bound lookup refuses it.
const host = { platform: Object.getOwnPropertyDescriptor(process, "platform")!, arch: Object.getOwnPropertyDescriptor(process, "arch")! };
Object.defineProperty(process, "platform", { ...host.platform, value: "darwin" });
Object.defineProperty(process, "arch", { ...host.arch, value: "arm64" });
try {
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, candidateGrant("linux-x64"));
expect(() => antigravityCandidateForRunnerTarget(companyId, { driver: "local" })).toThrow(/does not match the execution target/);
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, candidateGrant("darwin-arm64"));
expect(antigravityCandidateForRunnerTarget(companyId, { driver: "local" })).toMatchObject({ model, platform: "darwin", architecture: "arm64" });
} finally {
Object.defineProperty(process, "platform", host.platform);
Object.defineProperty(process, "arch", host.arch);
}
});
it("offers no candidate once the profile is released", () => {
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, candidateGrant("linux-x64"));
release.pending = false;
expect(antigravityCandidateForRunnerTarget(companyId, cloud)).toBeUndefined();
expect(antigravityCandidateForRunnerTarget(companyId, { driver: "local" })).toBeUndefined();
});
});
describe("Antigravity recovery policy and state root", () => {
it("forces the candidate's same-session recovery and per-run root only while pending", () => {
const execution = antigravityExecution();
const nextRun = antigravityExecution({ runId: "50000000-0000-4000-8000-000000000005" });
expect(antigravityForcesSameSessionRecovery(execution.provider)).toBe(true);
expect(antigravityUsesRunScopedState(execution)).toBe(true);
expect(scopedRunnerdStateRoot(execution)).not.toBe(scopedRunnerdStateRoot(nextRun));
release.pending = false;
expect(antigravityForcesSameSessionRecovery(execution.provider)).toBe(false);
expect(antigravityUsesRunScopedState(execution)).toBe(false);
// Qualified: one root per session scope, kept across the session's runs.
expect(scopedRunnerdStateRoot(execution)).toBe(scopedRunnerdStateRoot(nextRun));
});
it.each([false, true])("never shares a state root across subtasks or workspaces (pending=%s)", pending => {
release.pending = pending;
const parent = antigravityExecution();
const subtask = antigravityExecution({ issueId: "21000000-0000-4000-8000-000000000002",
workspaceId: "91000000-0000-4000-8000-000000000009", sessionId: "61000000-0000-4000-8000-000000000006" });
const otherWorkspace = antigravityExecution({ workspaceId: "92000000-0000-4000-8000-000000000009" });
const roots = new Set([parent, subtask, otherWorkspace].map(scopedRunnerdStateRoot));
expect(roots.size).toBe(3);
});
});
describe("Antigravity candidate same-run startup retry", () => {
let stateBase: string;
beforeEach(() => {
stateBase = mkdtempSync(join(tmpdir(), "antigravity-candidate-root-"));
vi.stubEnv("PAPERCLIP_RUNNER_STATE_DIR", stateBase);
});
afterEach(() => rmSync(stateBase, { recursive: true, force: true }));
/** What a candidate runner leaves after its session.open failed and it suspended. */
function writeFailedOpenRoot(execution: NativeExecutionInput, provider: Record<string, unknown> = {}) {
const root = scopedRunnerdStateRoot(execution);
mkdirSync(join(root, "control-plane"), { recursive: true, mode: 0o700 });
mkdirSync(join(root, "runner"), { recursive: true, mode: 0o700 });
writeFileSync(join(root, "control-plane", "control-plane-state.json"), JSON.stringify({
schema: "paperclip.runner.durable.control-plane-state.v2",
identity: { runnerInstanceId: "80000000-0000-4000-8000-000000000008", environmentLeaseId: execution.binding.executionWorkspaceId,
runId: execution.binding.runId, normalizedSessionId: execution.session.normalizedSessionId },
}));
writeFileSync(join(root, "runner", "acpx-provider-state.json"), JSON.stringify({
schema: "paperclip.runner.acpx-provider-state.v3", lifecycle: "closed", identity: null, activeTurnId: null,
providerExitUnconfirmed: false, semanticResult: null, pendingEvents: [], pendingRuntimeRequests: {}, openSemanticCalls: [],
...provider,
}));
return root;
}
const quarantined = (root: string) => existsSync(join(stateBase, "quarantine"))
&& readdirSync(join(stateBase, "quarantine")).some(name => name.startsWith(`${basename(root)}.identity_indeterminate.`));
it("retires a root whose session.open never opened a provider session, so the retry starts fresh", async () => {
const execution = antigravityExecution();
const root = writeFailedOpenRoot(execution);
expect(await retireNeverOpenedCandidateRunRoot(execution, root)).toBe(true);
expect(existsSync(root)).toBe(false);
expect(quarantined(root)).toBe(true);
});
it("keeps a root that opened a provider session or started a turn, and every root once released", async () => {
for (const provider of [
{ lifecycle: "suspended", identity: { kind: "acpx", acpxRecordId: "record" } },
{ lifecycle: "closed", identity: { kind: "acpx", acpxRecordId: "record" } },
{ lifecycle: "turn_active", activeTurnId: "turn" },
{ providerExitUnconfirmed: true },
]) {
const execution = antigravityExecution();
const root = writeFailedOpenRoot(execution, provider);
expect(await retireNeverOpenedCandidateRunRoot(execution, root)).toBe(false);
expect(existsSync(root)).toBe(true);
rmSync(root, { recursive: true, force: true });
}
// Another run's root is never this run's to retire.
const other = antigravityExecution({ runId: "50000000-0000-4000-8000-000000000005" });
const otherRoot = writeFailedOpenRoot(other);
expect(await retireNeverOpenedCandidateRunRoot(antigravityExecution(), otherRoot)).toBe(false);
expect(existsSync(otherRoot)).toBe(true);
release.pending = false;
const released = antigravityExecution();
const releasedRoot = writeFailedOpenRoot(released);
expect(await retireNeverOpenedCandidateRunRoot(released, releasedRoot)).toBe(false);
expect(existsSync(releasedRoot)).toBe(true);
});
});
describe("Antigravity state saved by the pending candidate, resumed by the qualified release", () => {
it("refuses the candidate's in-flight state permanently and by name, never as a retryable interruption", () => {
// Saved before the deploy under the candidate's profile version.
const saved = antigravityExecution();
release.pending = false;
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, undefined);
let refusal: unknown;
try {
assertAntigravityExecutionAdmissible({ execution: saved, useRunnerd: true, remoteTarget: false,
restartRecovery: { kind: "same_run_resume" } });
} catch (error) { refusal = error; }
expect(refusal).toBeInstanceOf(NativeProviderStateIncompatibleError);
const code = nativeSessionFailureSourceCode(refusal);
expect(code).toBe(NATIVE_PROVIDER_STATE_INCOMPATIBLE);
expect(nativeSessionFailureDisposition(1, new Date(), code)).toMatchObject({
phase: "terminal_failure", failureCode: NATIVE_PROVIDER_STATE_INCOMPATIBLE, nextAttemptAt: null });
});
it("refuses an older qualified profile version by the same name", () => {
release.pending = false;
const saved = antigravityExecution();
(saved.provider as { profile: { agentProfileVersion: number } }).profile.agentProfileVersion -= 1;
expect(() => assertAntigravityExecutionAdmissible({ execution: saved, useRunnerd: true, remoteTarget: false }))
.toThrow(NativeProviderStateIncompatibleError);
});
});