mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-03 09:37:19 +01:00
## Thinking Path > - Paperclip manages agents and their work. > - Users choose providers and managed accounts while adding agents. > - Antigravity was missing from the ordinary additional-agent picker and its saved Google path did not complete native readiness. > - A user needs a successful Test, an enabled task action, and a stable account binding. > - This pull request connects the ordinary setup flow to the native candidate. > - It also preserves retired credential refreshes across database failures and server restarts. ## Linked Issues or Issue Description Built on merged #18188 and #18187. Refs: #12503, #14938 for related legacy CLI proposals. **Agent or provider** Google Antigravity ACP 1.4.3. **Why this adapter is useful** Users need to set up an Antigravity agent and run real work through their managed Google subscription. **How the agent is invoked** Native Paperclip Runner uses the pinned Antigravity ACP runtime. Exact operator admission remains required; the local candidate result does not enable general release. ## What Changed - Show Google Antigravity in the ordinary adapter grid and preserve the draft choice when setup resumes. - Reuse the same user’s saved personal default Google subscription and discover the exact low model through the native account. - Run a prompt-free native Test and wait for authoritative readiness before enabling task assignment. - Carry the managed account through native runs and recover retired refreshes through the existing encrypted, fsynced journal with exact generation checks. - Retain the latest rotated credential through verification, storage, and partial home-removal failures. Retry the exact account’s retained cleanup before another provider use. - Reconcile cleanup before taking the credential mutation lock, fence owners arriving during lock acquisition, and support nested lock holders without a join cycle. - Bound sign-in retirement outside database transactions and preserve claims for the existing cleanup owner; one pending sign-in does not block unrelated accounts. - Cover Gemini and Pi API-key recovery, keep API-key bulk manual-model editing usable, and keep adapter discovery available after candidate expiry. - Skip taskless native timer work before run or credential admission. Preserve current master monitor and deadline scheduling. ## Verification - The registered local saved-Google-subscription journey passed all 16 matchers in 196,520 ms using eval source `12aba` against actual serving source `4a37ee7c`. Both turns stayed in one conversation, produced exact downloaded files of 61 and 119 bytes after reload, and used distinct native primary processes. All observed owners retired, leases released, and credential fences settled. Independent readback confirmed Done work, no active owned runs, a connected saved account, and the retained agent paused for inspection. - The measured runtime is production-equivalent to pre-restack `65ef31dc` except its test-only transport fixture correction. Current-master head `ff7c9249` preserves all 99 product paths: 98 exact blobs and only eight inherited plugin-panel lines in `agents.ts`. Its native binary was rebuilt for inherited Codex-only diagnostic changes; the changed Rust behavior is outside Antigravity's ACPX execution path. Shared native/UI changes have focused regression coverage. The recorded live result is not represented as a measured replay of `ff7c9249`. - Full workspace build and typecheck passed on `ff7c9249`. All 376 focused tests in 14 files passed, covering Google credential/retirement controls and the inherited native-tool, redaction, route, and UI recovery changes. Token gates, maps, and diff checks passed. The required-close fixture was separately demonstrated red, then passed all 317 selected provider-wiring cases. - [Current-head CI](https://github.com/paperclipai/paperclip/actions/runs/40959387972) is green: 55 successful checks, two skipped workflow checks, and an optional neutral review check. Required `ci / verify` and `ci / e2e` passed. Greptile and Paperclip Review both report 5/5 on exact `ff7c9249`, with zero unresolved review threads. - This qualifies the selected operator-authorized local saved-subscription candidate. The original exploratory journey remains historical evidence; the repeatable fixed-driver eval is in the next PR. ## Risks - Google refresh recovery must preserve the exact grant, account, and credential generation. An uncertain native owner or failed encrypted handoff retains the private home and blocks cleanup. - A successful local saved-subscription candidate does not qualify fresh OAuth, API keys, Cloud, Linux, other models, or general release. - Timer filtering changes only taskless native Runner admissions. Existing task-bound monitors and legacy adapters retain their owners. ## Model Used OpenAI Codex (GPT-6). The host did not expose the exact model revision or context limit. The model used tools for code edits, tests, and review. ## 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>
139 lines
9.5 KiB
TypeScript
139 lines
9.5 KiB
TypeScript
import { access, mkdir, rm, stat } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { AdapterEnvironmentTestContext } from "@paperclipai/adapter-utils";
|
|
|
|
const mocks = vi.hoisted(() => ({ probe: vi.fn(), admission: vi.fn(), credentials: vi.fn(), copyBack: vi.fn(), remove: vi.fn(), turn: vi.fn(), warn: vi.fn() }));
|
|
vi.mock("../middleware/logger.js", () => ({ logger: { warn: mocks.warn } }));
|
|
vi.mock("../vendor/paperclip-runner/index.js", async original => ({
|
|
...await original<object>(), probeNativeRunnerEnvironment: mocks.probe,
|
|
}));
|
|
vi.mock("../services/native-runtime/acpx-qualification.js", () => ({ resolveAntigravityCandidateAdmission: mocks.admission }));
|
|
vi.mock("../services/native-runtime/antigravity-runner-credentials.js", () => ({
|
|
prepareAntigravityRunnerCredentials: mocks.credentials, antigravityCredentialTurn: mocks.turn,
|
|
}));
|
|
vi.mock("../services/native-runtime/native-codex-runner.js", () => ({ resolvePaperclipRunnerBinary: () => "/owned/runnerd" }));
|
|
import { antigravityConnectionProbeFailure, testAntigravityConnection } from "../services/antigravity-connection-probe.js";
|
|
import { NativeEnvironmentProbeCleanupError, resolveAcpxRuntimeRoot } from "../vendor/paperclip-runner/index.js";
|
|
|
|
const model = "exact-google-model";
|
|
const admission = { agent: "antigravity", model, companyId: "company-1" };
|
|
const roots: string[] = [];
|
|
const context: AdapterEnvironmentTestContext = { companyId: "company-1", adapterType: "paperclip_runner",
|
|
config: { provider: "acpx", acpxAgent: "antigravity", model, env: { GEMINI_HOME: "/selected/provider", PATH: "/selected/bin" } },
|
|
managedAiCredentialHome: "/selected/provider", executionTarget: null,
|
|
};
|
|
const receipt = { provider: "acpx", providerDriver: "acpx_runtime", effectiveModel: model,
|
|
sessionAdmissionPassed: true, admissionOnly: true, helloProbePassed: false };
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
mocks.admission.mockReturnValue(admission);
|
|
mocks.credentials.mockImplementation(async input => ({ environment: { ...input.environment, PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET: "fixture-managed-credential" }, home: "/selected/provider", credential: "fixture-managed-credential" }));
|
|
mocks.turn.mockImplementation(() => ({ copyBack: mocks.copyBack, remove: mocks.remove }));
|
|
mocks.probe.mockImplementation(async options => {
|
|
roots.push(options.runtimeDirectory);
|
|
await options.onCleanupConfirmed();
|
|
return receipt;
|
|
});
|
|
});
|
|
afterEach(async () => {
|
|
vi.unstubAllEnvs();
|
|
await Promise.all(roots.splice(0).map(root => rm(root, { recursive: true, force: true })));
|
|
});
|
|
|
|
describe("Google Antigravity setup admission", () => {
|
|
it("reports the observed installation failure with a repair action and only closed server diagnostics", () => {
|
|
const privateValue = "fixture-private-token /private/selected-google-home";
|
|
const error = new Error(privateValue);
|
|
Object.defineProperty(error, "runnerCommandResult", { value: { commandType: "session.open", status: "failed", request: privateValue,
|
|
result: { code: "command_execution_failed", message: "failed to start ACPX provider: ACPX sidecar command session.open was rejected (retryable=false, classification=admission_installation)" } } });
|
|
const result = antigravityConnectionProbeFailure("company-1", error);
|
|
expect(result).toMatchObject({ status: "fail", checks: [{ code: "antigravity_installation_check_failed",
|
|
message: "Paperclip could not complete the local Google Antigravity installation check.", hint: expect.stringContaining("instance operator") }] });
|
|
expect(mocks.warn).toHaveBeenCalledExactlyOnceWith({ companyId: "company-1", code: "antigravity_installation_check_failed",
|
|
errorClass: "Error", commandCode: "command_execution_failed", classification: "admission_installation", retryable: false },
|
|
"Antigravity installation check failed before account verification");
|
|
expect(JSON.stringify([result, mocks.warn.mock.calls])).not.toMatch(/fixture-private-token|\/private\/selected-google-home/);
|
|
expect(JSON.stringify(result)).not.toMatch(/reconnect|sign in/i);
|
|
});
|
|
|
|
it("does not parse outer serialized errors or copy unknown codes, classes or native output", () => {
|
|
const privateValue = "fixture-private-token /private/selected-google-home";
|
|
for (const native of [{ code: privateValue, message: privateValue }, { code: "command_execution_failed",
|
|
message: "failed to start ACPX provider: ACPX sidecar command session.open was rejected (retryable=false, classification=admission_installation)" + privateValue }]) {
|
|
const nativeMessage = native.message;
|
|
const error = new Error(`PRP command session.open failed: ${nativeMessage}`);
|
|
error.name = privateValue;
|
|
Object.defineProperty(error, "runnerCommandResult", { value: { commandType: "session.open", status: "failed",
|
|
result: native } });
|
|
const result = antigravityConnectionProbeFailure("company-1", error);
|
|
expect(result.checks[0].code).toBe("antigravity_admission_failed");
|
|
expect(JSON.stringify([result, mocks.warn.mock.calls])).not.toMatch(/fixture-private-token|\/private\/selected-google-home/);
|
|
}
|
|
const rawOnly = new Error('PRP command session.open failed: {"code":"command_execution_failed","classification":"admission_installation"}');
|
|
expect(antigravityConnectionProbeFailure("company-1", rawOnly).checks[0].code).toBe("antigravity_admission_failed");
|
|
});
|
|
|
|
it("preserves physical cleanup ownership instead of converting its typed error into a connection result", () => {
|
|
const retired = Promise.resolve();
|
|
const error = new NativeEnvironmentProbeCleanupError(retired, new Error("fixture-private-token"), [new Error("fixture private path")]);
|
|
expect(() => antigravityConnectionProbeFailure("company-1", error)).toThrow(error);
|
|
expect(mocks.warn).not.toHaveBeenCalled();
|
|
expect(error.retired).toBe(retired);
|
|
});
|
|
|
|
it("uses the selected managed account, exact candidate and a private runtime without a model turn", async () => {
|
|
vi.stubEnv("GEMINI_API_KEY", "ambient-key-must-not-enter");
|
|
vi.stubEnv("GOOGLE_APPLICATION_CREDENTIALS", "/ambient-google-credential");
|
|
const order: string[] = [];
|
|
mocks.copyBack.mockImplementation(async () => { order.push("copy-back"); });
|
|
mocks.remove.mockImplementation(async () => { order.push("scrub"); });
|
|
let root = "";
|
|
mocks.probe.mockImplementation(async options => {
|
|
root = options.runtimeDirectory; roots.push(root);
|
|
expect((await stat(root)).mode & 0o777).toBe(0o700);
|
|
expect((await stat(options.transportOptions.acpxRuntimeDirectory)).mode & 0o777).toBe(0o700);
|
|
expect(options).toMatchObject({ provider: "acpx", model, admissionOnly: true,
|
|
environment: { PATH: "/selected/bin", PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET: "fixture-managed-credential" },
|
|
transportOptions: { runnerBinary: "/owned/runnerd", acpxAgent: "antigravity", acpxCandidateAdmission: admission,
|
|
acpxPermissionMode: "approve-reads", acpxPermissionModePinned: true } });
|
|
expect(options.environment.GEMINI_API_KEY).toBeUndefined();
|
|
expect(options.environment.GOOGLE_APPLICATION_CREDENTIALS).toBeUndefined();
|
|
const identity = options.transportOptions.prpIdentity;
|
|
const nativeHome = join(await resolveAcpxRuntimeRoot(options.transportOptions.acpxRuntimeDirectory, identity.normalizedSessionId), "antigravity-home");
|
|
expect(mocks.turn).toHaveBeenCalledWith({ managedHome: "/selected/provider", runtimeHome: nativeHome, credential: "fixture-managed-credential" });
|
|
await mkdir(nativeHome, { recursive: true });
|
|
order.push("retired");
|
|
await options.onCleanupConfirmed();
|
|
await expect(access(root)).rejects.toMatchObject({ code: "ENOENT" });
|
|
return receipt;
|
|
});
|
|
const result = await testAntigravityConnection(context, model);
|
|
expect(result.status).toBe("pass");
|
|
expect(result.checks).toContainEqual(expect.objectContaining({ code: "antigravity_metadata_verified" }));
|
|
expect(mocks.admission).toHaveBeenCalledExactlyOnceWith({ companyId: "company-1", model });
|
|
expect(mocks.credentials).toHaveBeenCalledWith(expect.objectContaining({ managedHome: "/selected/provider", remote: false, lifecycleMode: "per_turn" }));
|
|
expect(order).toEqual(["retired", "copy-back", "scrub"]);
|
|
});
|
|
|
|
it.each(["effectiveModel", "providerDriver", "sessionAdmissionPassed", "admissionOnly", "helloProbePassed"] as const)("rejects a mismatched %s receipt after cleanup", async field => {
|
|
mocks.probe.mockImplementation(async options => {
|
|
roots.push(options.runtimeDirectory);
|
|
await options.onCleanupConfirmed();
|
|
return { ...receipt, [field]: typeof receipt[field] === "string" ? "different" : !receipt[field] };
|
|
});
|
|
await expect(testAntigravityConnection(context, model)).rejects.toThrow("no matching account and model admission receipt");
|
|
expect(mocks.copyBack).toHaveBeenCalledOnce();
|
|
expect(mocks.remove).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("rejects an unavailable company or remote target before reading credentials or launching native code", async () => {
|
|
mocks.admission.mockReturnValue(undefined);
|
|
await expect(testAntigravityConnection(context, model)).rejects.toThrow("not available for this company");
|
|
await expect(testAntigravityConnection({ ...context, executionTarget: { kind: "remote" } as AdapterEnvironmentTestContext["executionTarget"] }, model))
|
|
.rejects.toThrow("requires the Paperclip host");
|
|
expect(mocks.credentials).not.toHaveBeenCalled();
|
|
expect(mocks.probe).not.toHaveBeenCalled();
|
|
});
|
|
});
|