mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 10:07:24 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Google Antigravity agents can sign in with a Google subscription. On hosted public deployments the server starts the pinned Antigravity runtime and relays the pasted loopback redirect (#22932). > - The server looked for that runtime only in the server package's vendored assets and the OS-account cache. The Docker image keeps the verified closure in the build-owned provider pack (`PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH`). > - So every hosted attempt failed before the runtime started, and the page showed "Google sign-in did not complete. Start sign-in again." with no sign-in link. Every failure reason became that one message, and nothing was logged. > - #22983 added the pack lookup as an option that each caller had to pass. That leaves several search paths that can drift: installation verification still used none. > - This pull request moves the pack lookup into the one canonical resolver, gives sign-in failures a typed reason with one plain-language message each, and logs a secret-free reason code. > - The benefit is that sign-in, model discovery and installation verification always find the same verified runtime, and a server without the runtime says why. ## Linked Issues or Issue Description Refs #22932, Refs #22983 **Describe the bug** On a hosted authenticated public deployment, the user chooses Google Antigravity and then "Google Subscription". The page immediately shows "Google sign-in did not complete. Start sign-in again." `POST .../ai-connections/local/attempts` returns 201, and every `POST .../ai-connections/local/check` returns `sign_in_required` with the same message and no `authorizationUrl`. **Steps to reproduce** 1. Run the standard image as an authenticated public deployment. Do not create an Antigravity runtime cache in the server account. 2. Create an agent with Google Antigravity and choose Google Subscription. 3. See the error before any sign-in step runs. **Expected behavior** The server starts the pinned runtime from the image's provider pack and shows the Google sign-in link. If the server has no runtime, the message says so in plain language and does not tell the user to start again. **Root cause** `antigravityNativeDistributionSpec()` resolved `<server>/dist/vendor/paperclip-runner/provider-assets/antigravity/<target>` and then `$HOME/.paperclip/runtimes/antigravity/<target>/<closure>`. The image ships the closure at `$PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH/provider-assets/antigravity/linux-x64`. `startAntigravityBrowserLogin` caught every failure with a bare `catch` and showed the generic message. The #22932 tests mocked both the runtime resolution and the installation check. ## What Changed - Runner: `antigravityNativeDistributionSpec` is the one resolver for every caller. The search order is: the runner package's own assets (runnerd binds Runner children to the selected pack with `PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT`), then the deployment provider pack from `PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH`, then the OS-account cache. The pack root must be a normalized absolute path. The pack goes through the manifest and link checks of `resolveRunnerProviderAssetsRoot` from #22983. The pinned closure digest check is unchanged. - Runner: the `providerPackageRoot` option on `startAntigravityBrowserLogin`, `discoverAntigravityModels` and `antigravityNativeDistributionSpec` is removed. The server no longer reads the pack path. - Runner: sign-in failures have a typed reason (`runtime_unavailable`, `start_failed`, `login_incomplete`, `aborted`). One table maps each reason to its message. A missing runtime reports "This server does not have the current Google Antigravity runtime, so Google sign-in cannot start. Use a Google API key instead, or update Paperclip on this server." - Runner: model discovery throws `AntigravityRuntimeUnavailableError` when the runtime is missing. The server shows a plain-language message for it instead of "Could not load models for this Google account". - Server: sign-in failures, except cancelled attempts, are logged with a secret-free code such as `ANTIGRAVITY_SIGN_IN_RUNTIME_UNAVAILABLE`. A missing runtime during model discovery is logged as `ANTIGRAVITY_RUNTIME_UNAVAILABLE`. ## Verification - Red on master, green on this branch: - `antigravity-installation.test.ts`: pack resolution, precedence, cache fallback, link and path refusal, and one test that binds sign-in, model discovery and `verifyAntigravityInstallation` to the same pack with no vendored assets. - `antigravity-auth.test.ts`: one test for each failure reason and its message. - `antigravity-models.test.ts`: a missing runtime gives `AntigravityRuntimeUnavailableError` without a launch. - `pnpm --filter @paperclipai/paperclip-runner exec vitest run` on the antigravity auth, stream-order, installation, models and provider-assets-root suites: 76 of 76 pass. - `server/src/__tests__/local-ai-browser-login-google.test.ts`, `antigravity-connection-models.test.ts` and `antigravity-local-ai-login.test.ts`: 33 of 33 pass. - The runner `tsc --noEmit` and the server `tsc --noEmit` pass. - `node tests/runner-e2e/source-sdk-public-inputs.mjs <HEAD> --check` reports no registry change. - `pnpm verify` returned exit 2 (runner test files are outside the resolved test graphs). Required CI supplies the broad coverage. - Not run: a live Google sign-in against the real closure in a hosted image. That needs a deploy and a real Google account. ## Risks - Low risk. The pack is used only when the packaged assets are absent and the pack contains the target. A modified pack still fails the pinned closure check. - A pack root that is relative or contains `..` now fails as "runtime unavailable" instead of being ignored silently. - Error text changes only for failures before the runtime initializes. > 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 - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use (shell, file edits, test runs). ## 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 <noreply@anthropic.com>
162 lines
10 KiB
TypeScript
162 lines
10 KiB
TypeScript
import { antigravityApiKeyModels } from "@paperclipai/shared";
|
|
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
const mocks = vi.hoisted(() => ({ managed: vi.fn(), discover: vi.fn(), cleanup: vi.fn(),
|
|
warn: vi.fn(),
|
|
CleanupError: class extends Error {
|
|
constructor(readonly retired: Promise<void>) { super("cleanup pending"); }
|
|
},
|
|
UnavailableError: class extends Error {
|
|
readonly code = "ANTIGRAVITY_RUNTIME_UNAVAILABLE";
|
|
},
|
|
}));
|
|
const spawned = vi.hoisted(() => vi.fn());
|
|
vi.mock("node:child_process", async original => {
|
|
const actual = await original<typeof import("node:child_process")>();
|
|
const record = (name: string) => (...args: unknown[]) => { spawned(name); return (actual as never as Record<string, (...a: unknown[]) => unknown>)[name]!(...args); };
|
|
return { ...actual, spawn: record("spawn"), execFile: record("execFile"), fork: record("fork"), exec: record("exec") };
|
|
});
|
|
vi.mock("../services/ai-connection-runtime.js", () => ({ prepareManagedAiRuntime: mocks.managed }));
|
|
vi.mock("../middleware/logger.js", () => ({ logger: { warn: mocks.warn } }));
|
|
vi.mock("../vendor/paperclip-runner/index.js", () => ({
|
|
discoverAntigravityModels: mocks.discover, AntigravityModelDiscoveryCleanupError: mocks.CleanupError,
|
|
AntigravityRuntimeUnavailableError: mocks.UnavailableError,
|
|
}));
|
|
import { antigravityConnectionModels } from "../services/antigravity-connection-models.js";
|
|
import { RetiredCredentialRecoveryError } from "../services/quota-credential-recovery.js";
|
|
import { reconcileRetainedGoogleCleanup } from "../services/retained-google-credential-cleanup.js";
|
|
|
|
const input = { companyId: "company", userId: "alice", binding: { provider: "google", method: "subscription", mode: "responsible_user" } as const,
|
|
allowUninstalledShared: false };
|
|
let sequence = 0;
|
|
let scope = { companyId: "company", accountKey: "" };
|
|
beforeEach(() => { vi.clearAllMocks(); scope = { companyId: "company", accountKey: `catalog-${++sequence}` }; mocks.cleanup.mockResolvedValue(undefined); mocks.managed.mockImplementation(async () => {
|
|
void reconcileRetainedGoogleCleanup(scope).catch(() => undefined);
|
|
return {
|
|
attribution: { method: "subscription" }, config: { env: { GEMINI_HOME: "/private/selected-google-home" } },
|
|
cleanup: () => mocks.cleanup(), retainedCleanupScope: scope,
|
|
}; }); });
|
|
afterEach(async () => { vi.useRealTimers(); mocks.cleanup.mockResolvedValue(undefined); await reconcileRetainedGoogleCleanup(scope); });
|
|
|
|
it("uses the selected account lifecycle and returns only its model catalog", async () => {
|
|
const models = [{ id: "exact-google-model", label: "Google model" }];
|
|
mocks.discover.mockResolvedValue({ models, defaultModelId: "exact-google-model" });
|
|
expect(await antigravityConnectionModels({} as never, input)).toEqual(models);
|
|
expect(mocks.managed).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
|
companyId: "company", responsibleUserId: "alice", adapterType: "paperclip_runner", binding: input.binding,
|
|
allowUninstalledPersonal: true, allowUninstalledShared: false, config: { provider: "acpx", acpxAgent: "antigravity" },
|
|
}));
|
|
expect(mocks.discover).toHaveBeenCalledWith("/private/selected-google-home");
|
|
expect(mocks.cleanup).toHaveBeenCalledExactlyOnceWith();
|
|
});
|
|
|
|
it("reports a missing server runtime plainly and logs its reason code", async () => {
|
|
mocks.discover.mockRejectedValueOnce(new mocks.UnavailableError("runtime missing"));
|
|
await expect(antigravityConnectionModels({} as never, input)).rejects.toThrow(
|
|
"This server does not have the current Google Antigravity runtime, so Google account models cannot load. Use a Google API key instead, or update Paperclip on this server.");
|
|
expect(mocks.warn).toHaveBeenCalledWith({ companyId: "company", code: "ANTIGRAVITY_RUNTIME_UNAVAILABLE" }, "Antigravity model discovery runtime is unavailable");
|
|
expect(mocks.cleanup).toHaveBeenCalledExactlyOnceWith();
|
|
});
|
|
|
|
it("returns the pinned API-key catalog for a Gemini API key without preparing a credential or starting a process", async () => {
|
|
const models = await antigravityConnectionModels({} as never, { ...input, binding: { provider: "google", method: "api_key", mode: "responsible_user" } });
|
|
expect(models.map(model => model.id)).toEqual(antigravityApiKeyModels().map(model => model.id));
|
|
expect(models.slice(0, 14).map(model => model.id)).toContain("gemini-3.8-flash-high");
|
|
expect(models.find(model => model.id === "gemini-4-neon-high")?.label).toBe("Gemini 4 Neon (High) · needs a paid Gemini API plan");
|
|
expect(mocks.managed).not.toHaveBeenCalled();
|
|
expect(mocks.discover).not.toHaveBeenCalled();
|
|
expect(spawned).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("answers a sign-in binding that resolves to a Gemini API key with the API-key catalog, never a dead end", async () => {
|
|
mocks.managed.mockResolvedValue({ attribution: { method: "api_key" }, config: { env: { GEMINI_HOME: "/private/home" } }, cleanup: mocks.cleanup });
|
|
const models = await antigravityConnectionModels({} as never, input);
|
|
expect(models).toEqual(antigravityApiKeyModels());
|
|
expect(JSON.stringify(models)).not.toContain("exact model identifier");
|
|
expect(mocks.discover).not.toHaveBeenCalled();
|
|
expect(mocks.cleanup).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("does not disguise an absent private home as Google subscription discovery", async () => {
|
|
mocks.managed.mockResolvedValue({ attribution: { method: "subscription" }, config: { env: {} }, cleanup: mocks.cleanup });
|
|
await expect(antigravityConnectionModels({} as never, input)).rejects.toThrow(/Google/);
|
|
expect(mocks.discover).not.toHaveBeenCalled();
|
|
expect(mocks.cleanup).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("preserves account-resolution denial and sanitizes native discovery errors", async () => {
|
|
mocks.managed.mockRejectedValueOnce(new Error("membership denied"));
|
|
await expect(antigravityConnectionModels({} as never, input)).rejects.toThrow("membership denied");
|
|
expect(mocks.cleanup).not.toHaveBeenCalled();
|
|
mocks.discover.mockRejectedValueOnce(new Error("provider-private-text"));
|
|
await expect(antigravityConnectionModels({} as never, input)).rejects.toThrow("Could not load models");
|
|
expect(mocks.cleanup).toHaveBeenCalledExactlyOnceWith();
|
|
});
|
|
|
|
it("retains the selected credential home until uncertain native cleanup proves retirement", async () => {
|
|
let retire!: () => void;
|
|
const retired = new Promise<void>((resolve) => { retire = resolve; });
|
|
mocks.discover.mockRejectedValueOnce(new mocks.CleanupError(retired));
|
|
await expect(antigravityConnectionModels({} as never, input)).rejects.toThrow("Could not load models");
|
|
expect(mocks.cleanup).not.toHaveBeenCalled();
|
|
retire();
|
|
await retired;
|
|
await vi.waitFor(() => expect(mocks.cleanup).toHaveBeenCalledExactlyOnceWith());
|
|
});
|
|
|
|
it.each(["success", "failure"])("retains storage failure after native discovery %s without background database retries", async outcome => {
|
|
vi.useFakeTimers();
|
|
if (outcome === "success") mocks.discover.mockResolvedValue({ models: [{ id: "exact-model", label: "Model" }] });
|
|
else mocks.discover.mockRejectedValue(new Error("private-provider-token"));
|
|
mocks.cleanup.mockRejectedValueOnce(new Error("private-provider-token database write failure"));
|
|
await expect(antigravityConnectionModels({} as never, input)).rejects.toThrow("Could not complete Google account credential cleanup");
|
|
expect(mocks.cleanup).toHaveBeenCalledTimes(1);
|
|
expect(mocks.managed).toHaveBeenCalledTimes(1);
|
|
expect(mocks.discover).toHaveBeenCalledTimes(1);
|
|
expect(mocks.warn).toHaveBeenCalledExactlyOnceWith({ companyId: "company", code: "ANTIGRAVITY_CATALOG_CREDENTIAL_CLEANUP_PENDING" },
|
|
"Antigravity model-discovery credential cleanup is retained for recovery");
|
|
await vi.advanceTimersByTimeAsync(90_000);
|
|
expect(mocks.cleanup).toHaveBeenCalledTimes(1);
|
|
expect(vi.getTimerCount()).toBe(0);
|
|
});
|
|
|
|
it("waits for native retirement, then lets the durable journal own failed writeback without a retry loop", async () => {
|
|
vi.useFakeTimers();
|
|
let retire!: () => void;
|
|
const retired = new Promise<void>(resolve => { retire = resolve; });
|
|
mocks.discover.mockRejectedValueOnce(new mocks.CleanupError(retired));
|
|
mocks.cleanup.mockRejectedValueOnce(new RetiredCredentialRecoveryError(new Error("private-token first failure")));
|
|
await expect(antigravityConnectionModels({} as never, input)).rejects.toThrow("Could not load models");
|
|
await vi.advanceTimersByTimeAsync(90_000);
|
|
expect(mocks.cleanup).not.toHaveBeenCalled();
|
|
expect(vi.getTimerCount()).toBe(0);
|
|
retire();
|
|
await vi.advanceTimersByTimeAsync(0);
|
|
expect(mocks.cleanup).toHaveBeenCalledTimes(1);
|
|
await vi.advanceTimersByTimeAsync(90_000);
|
|
expect(mocks.cleanup).toHaveBeenCalledTimes(1);
|
|
expect(vi.getTimerCount()).toBe(0);
|
|
expect(mocks.managed).toHaveBeenCalledTimes(1);
|
|
expect(mocks.discover).toHaveBeenCalledTimes(1);
|
|
expect(JSON.stringify(mocks.warn.mock.calls)).not.toContain("private-token");
|
|
});
|
|
|
|
it("retries the original failed journal cleanup independently of model discovery", async () => {
|
|
const order: string[] = [];
|
|
mocks.discover.mockImplementation(async () => { order.push("provider"); return { models: [] }; });
|
|
mocks.cleanup.mockImplementationOnce(async () => { order.push("journal-failed"); throw new Error("storage unavailable"); })
|
|
.mockImplementation(async () => { order.push("journal-saved"); });
|
|
await expect(antigravityConnectionModels({} as never, input)).rejects.toThrow("Could not complete Google account credential cleanup");
|
|
await expect(antigravityConnectionModels({} as never, input)).resolves.toEqual([]);
|
|
expect(order.filter(step => step === "provider")).toHaveLength(2);
|
|
expect(order.filter(step => step === "journal-saved")).toHaveLength(2);
|
|
});
|
|
|
|
it("allows another provider launch while the original cleanup still cannot journal", async () => {
|
|
mocks.discover.mockResolvedValue({ models: [] });
|
|
mocks.cleanup.mockRejectedValue(new Error("storage unavailable"));
|
|
await expect(antigravityConnectionModels({} as never, input)).rejects.toThrow("Could not complete Google account credential cleanup");
|
|
await expect(antigravityConnectionModels({} as never, input)).rejects.toThrow("Could not complete Google account credential cleanup");
|
|
expect(mocks.discover).toHaveBeenCalledTimes(2);
|
|
expect(mocks.cleanup).toHaveBeenCalledTimes(3);
|
|
});
|