From 4285366e7991f2c451954d29f7af0a0224432d6b Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Wed, 25 Nov 2026 09:48:56 -0600 Subject: [PATCH] test(antigravity): prove positive run-start cases reach the coordinator claim with a strict DB fake (#22947) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Agents can run on the Google Antigravity harness, and run start has a release gate for it > - #22943 added run-start tests for that gate > - Two positive cases only checked that the error was not the gate error, so an unrelated early failure also passed > - The fixture database returned itself for every method and an empty result for every query, so the tests accepted any database access > - This pull request makes each positive case prove that the run reached the step after admission, and makes the fake database strict > - The benefit is that a regression before the coordinator claim, or an unexpected database call, now fails the tests ## Linked Issues or Issue Description Refs #22943 **What happened?** Two positive run-start cases in `antigravity-run-start.test.ts` passed when the run failed for any reason other than the gate. The fixture database in `antigravity.test-fixture.ts` silently accepted any call. **What did you expect to happen?** Each positive case proves that the run got past admission to a known later step. The fake database rejects calls that the tests do not use. **Steps to reproduce** Add a temporary `throw` in `executePaperclipNativeSessionAttempt` just before the coordinator claim. The old tests still pass (6 of 6). ## What Changed - The granted Core sandbox case and the released plugin Runner-task case now require the exact `native_finalization_coordinator_missing` error. This error comes from the coordinator claim, which is after admission. - Both cases also check the exact database reads: the coordinator lookup and its locked re-read. The plugin case also checks the plugin lease lookup before them. - The older-profile case now checks that it is refused before any database read. - `emptyDb()` is now a typed fake. It supports only `select`, `from`, `innerJoin`, `where`, `limit`, `for("update")`, `then`, and `transaction`. It records each table read and throws a clear error for any other method or lock mode. ## Verification - `cd server && npx vitest run src/services/native-runtime/antigravity-run-start.test.ts src/services/native-runtime/antigravity-release.test.ts`: 16 of 16 pass. - Red/green: with a temporary `throw` just before the coordinator claim, the new tests fail in the two positive cases ("got 'fixture_break_before_coordinator_claim'"). The old tests pass with the same break (6 of 6). The temporary change is not part of this PR. - `cd server && npx tsc --noEmit -p .`: clean. ## Risks - Low risk. This is a test-only change. No product code changes. - If run start adds or reorders database reads, these tests fail and need an update. That is intended. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, in Claude Code with tool use (shell, file edits). ## 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 - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 --- .../antigravity-run-start.test.ts | 21 ++++---- .../antigravity.test-fixture.ts | 48 +++++++++++++++---- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/server/src/services/native-runtime/antigravity-run-start.test.ts b/server/src/services/native-runtime/antigravity-run-start.test.ts index a7068f6bb5d..8d240fa34fc 100644 --- a/server/src/services/native-runtime/antigravity-run-start.test.ts +++ b/server/src/services/native-runtime/antigravity-run-start.test.ts @@ -73,10 +73,12 @@ const pluginTarget = () => ({ kind: "remote", transport: "sandbox", providerKey: remoteCwd: "/unused", runnerTask: describeTask }) as unknown as AdapterExecutionTarget; const sandboxTarget = () => ({ kind: "remote", transport: "sandbox", remoteCwd: "/workspace", runner: { execute: vi.fn() } }) as unknown as AdapterExecutionTarget; -const runStart = (execution: NativeExecutionInput, runnerExecutionTarget: AdapterExecutionTarget) => - executePaperclipNativeSession({ db: emptyDb(), execution, useRunnerd: true, runnerInstanceId: "antigravity-run-start", +const runStart = (execution: NativeExecutionInput, runnerExecutionTarget: AdapterExecutionTarget, db = emptyDb()) => + executePaperclipNativeSession({ db, execution, useRunnerd: true, runnerInstanceId: "antigravity-run-start", runnerIngressAuthorized: true, runnerExecutionTarget }); const INELIGIBLE = /paperclip_runner_antigravity_candidate_ineligible/; +const COORDINATOR_CLAIM = /^native_finalization_coordinator_missing$/; +const coordinatorReads = [{ table: "native_run_finalizations", locked: false }, { table: "native_run_finalizations", locked: true }]; let ownerFactory: MockInstance; beforeEach(() => { @@ -100,8 +102,9 @@ describe("Antigravity run start while the profile is pending", () => { it("admits a granted Core sandbox run past the gate, and still refuses the same grant on a plugin Runner-task target", async () => { grant.admitted = true; - const admitted = await runStart(antigravityExecution(), sandboxTarget()).then(() => null, (error: unknown) => error); - expect(String(admitted)).not.toMatch(INELIGIBLE); + const db = emptyDb(); + await expect(runStart(antigravityExecution(), sandboxTarget(), db)).rejects.toThrow(COORDINATOR_CLAIM); + expect(db.reads).toEqual(coordinatorReads); expect(grant.targets).toContainEqual({ platform: "linux", architecture: "x64" }); await expect(runStart(antigravityExecution(), pluginTarget())).rejects.toThrow(INELIGIBLE); expect(describeTask).not.toHaveBeenCalled(); @@ -112,12 +115,14 @@ describe("Antigravity run start while the profile is pending", () => { describe("Antigravity run start once the profile is released", () => { it("passes the gate on a plugin Runner-task target and refuses state saved under another profile version", async () => { expect(antigravityReleasePending()).toBe(false); - const current = await runStart(antigravityExecution(), pluginTarget()).then(() => null, (error: unknown) => error); - expect(String(current)).not.toMatch(INELIGIBLE); - expect(current).not.toBeInstanceOf(NativeProviderStateIncompatibleError); + const db = emptyDb(); + await expect(runStart(antigravityExecution(), pluginTarget(), db)).rejects.toThrow(COORDINATOR_CLAIM); + expect(db.reads).toEqual([{ table: "environment_leases", locked: false }, ...coordinatorReads]); const older = antigravityExecution(); (older.provider as { profile: { agentProfileVersion: number } }).profile.agentProfileVersion -= 1; - await expect(runStart(older, pluginTarget())).rejects.toBeInstanceOf(NativeProviderStateIncompatibleError); + const olderDb = emptyDb(); + await expect(runStart(older, pluginTarget(), olderDb)).rejects.toBeInstanceOf(NativeProviderStateIncompatibleError); + expect(olderDb.reads).toEqual([]); }); it.each(["api_key", "sign_in"] as const)("hands a %s plugin Runner task only its typed credential", async method => { diff --git a/server/src/services/native-runtime/antigravity.test-fixture.ts b/server/src/services/native-runtime/antigravity.test-fixture.ts index 68ca4d45e89..24867bed59f 100644 --- a/server/src/services/native-runtime/antigravity.test-fixture.ts +++ b/server/src/services/native-runtime/antigravity.test-fixture.ts @@ -1,4 +1,5 @@ import type { Db } from "@paperclipai/db"; +import { getTableName, type Table } from "drizzle-orm"; import { QUALIFIED_ACPX_PROFILES, type NativeExecutionInput } from "../../vendor/paperclip-runner/index.js"; import { buildNativeExecutionInput } from "./native-execution-input.js"; import { nativeRuntimeContextFixture } from "./runtime-context.test-fixture.js"; @@ -6,14 +7,45 @@ import { nativeRuntimeContextFixture } from "./runtime-context.test-fixture.js"; export const ANTIGRAVITY_FIXTURE_COMPANY_ID = "10000000-0000-4000-8000-000000000001"; export const ANTIGRAVITY_FIXTURE_MODEL = "gemini-3.8-flash-low"; -export function emptyDb(): Db { - const db: Db = new Proxy(() => undefined, { - get: (_target, key) => key === "then" ? (resolve: (rows: unknown[]) => unknown) => resolve([]) - : key === "transaction" ? async (operation: (tx: Db) => unknown) => operation(db) - : () => db, - apply: () => db, - }) as unknown as Db; - return db; +export type AntigravityDbRead = { table: string; locked: boolean }; +export type AntigravityFixtureDb = Db & { reads: AntigravityDbRead[] }; + +function strict(target: T, label: string): T { + return new Proxy(target, { + get: (object, key) => { + if (typeof key === "symbol" || key in object) return Reflect.get(object, key); + throw new Error(`antigravity fixture: unexpected ${label}.${key}`); + }, + }); +} + +export function emptyDb(): AntigravityFixtureDb { + const reads: AntigravityDbRead[] = []; + const select = () => strict({ + from: (table: Table) => { + const read = { table: getTableName(table), locked: false }; + reads.push(read); + const query = strict({ + innerJoin: () => query, + where: () => query, + limit: () => query, + for: (mode: string) => { + if (mode !== "update") throw new Error(`antigravity fixture: unexpected lock ${mode}`); + read.locked = true; + return query; + }, + then: (resolve: (rows: never[]) => unknown, reject?: (error: unknown) => unknown) => + Promise.resolve([] as never[]).then(resolve, reject), + }, `select from ${read.table}`); + return query; + }, + }, "select"); + const db = strict({ + reads, + select, + transaction: async (operation: (tx: Db) => unknown) => operation(strict({ select }, "transaction") as unknown as Db), + }, "db"); + return db as unknown as AntigravityFixtureDb; } export function antigravityExecution(input: { runId?: string; issueId?: string; workspaceId?: string; sessionId?: string } = {}) {