mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-23 00:53:38 +02:00
## Thinking Path > - Paperclip is the open source control plane for agent companies. > - People choose a harness when creating an agent. > - The server should resolve that harness to a qualified runner. > - Codex is the first harness in the staged default rollout. > - Saved agents must retain their execution choices. > - New Codex agents therefore use Paperclip Runner on qualified macOS/Linux targets, with an explicit Legacy override. ## Linked Issues or Issue Description Refs #16028, #15555, #15673, #15422, #15631, #15926, #15932, #16149. The runtime/install prerequisite and release repair are merged. This slice owns Codex creation, setup, configuration and preservation. Other harness defaults remain unchanged. It adds no database migration; incoming master migrations, required maps and regression coverage are retained. ## What Changed - Resolve `runner: auto | paperclip | legacy` at the common creation boundary across onboarding, API/CLI, hires, built-ins, plugins and imports. Freeze pending hires and export resolved execution choices. - Preserve existing runners on upgrades, unrelated edits and import updates, including compatible accounts, workspace settings, Codex effort and intentional clears. - Use the underlying harness picker and branding; put the runner override in Advanced. Use the shared dropdown and update production-component stories and creation contracts. - Support qualified Apple Silicon, Intel Mac, Linux x64 and Linux ARM64. Linux requires GNU libc 2.39+. Disabled, external, unsupported and unqualified combinations retain their applicable Legacy execution. - Test the selected runtime/account/model/environment. Ordinary Connect probes eligible immutable managed targets and refreshes scoped discovery. Creation/discovery do not provision. Auth, dependency, incompatible-setting and cleanup failures remain actionable without changing runners. - Keep setup probes read-only, preserve local/SSH isolation and resolve packaged assets before staging credentials. Bound cleanup reads by the remaining absolute deadline; physically close every owned ingress socket before endpoint release. Unconfirmed cleanup retains recovery state. - Preserve validated completed-onboarding callbacks through startup recovery. First file-producing work belongs to the child task and uses the existing dependency/block handoff and task-scoped registration. - Reuse existing E2E fixtures, artifact checks, reporting and controls. Keep Docker/Cargo/native compilation remote. Paperclip tarballs contain no Codex payloads; official optional npm platform dependencies remain. ## Verification Current tested head: `1c03a8815672d82c264a9b08d4ea1984e8fae107`. **Merge-ready: required CI, fresh review, package qualification, Mac core acceptance and Test task/follow-up acceptance pass.** The existing attachment and native-continuity oracles independently verify both Test downloads, run attribution and unchanged native/provider/workspace identities. The maintainer authorized a code-owner-review exception for this PR only. The first Test setup failure and normal Board completion-review friction are retained below. Actual post-merge packages and private Cloud distribution remain separate qualification gates. - [Current CI](https://github.com/paperclipai/paperclip/actions/runs/38564241625): all 48 ordinary jobs and required verify/E2E pass. Attempt 1 retained six simultaneous host-shutdown cancellations. One failed-only retry passes those six lanes and two aggregates, preserving 40 successes. Actual integration checkout `53104c1` combines this head with master `c80`; it is not relabeled as the branch tree. Fresh exact-head Greptile 5/5, 30 resolved threads, no actionable findings. - [Exact-source package qualification](https://github.com/paperclipai/paperclip/actions/runs/38565287239): nine applicable jobs pass, nine conditional jobs skip. Four remote native producers; Linux x64 clean install; Intel Mac, Apple Silicon and Linux ARM64 native startup/physical cleanup controls. All 18 tarballs/four daemon source/hash/manifest bindings and 343 migrations through 0344 verify. No Codex payload is packed. These hosted tarballs are not a published npm canary. - Normal Apple Silicon installation and credential-free native startup/cleanup pass using the packaged daemon, with no source build or provider turn. Fresh installed DB initialization passes. Upgrade 651a→1c03 preserves all three complete execution configs, accounts, ten recorded run profiles, paused budgets, active incidents, cost summaries and two historical unpriced events. Historical recovery state is retained. - Cleanup regressions: four delayed-read baseline failures become 15 passing deadline/authority controls. No-acknowledgement and prior-error socket ownership regressions become 12 passing controls. Direct runtime/server types, maps: 35 areas / 176 IDs, diff checks and independent reviews pass. Permission/auth/reconnect policy and the 10-second setup budget remain intact. - Existing source coverage includes creation/selection/imports, pending approvals, recovery, account/lifecycle handling, mounted forms, dropdowns and E2E support. Full typechecks/tests/build/token and applicable Storybook checks pass in the recorded current CI; no duplicate suite or weakened grader. - Literal 9546 live Mac proof: ordinary Auto Codex onboarding, useful document, real completed-child callback/reply, seven successful native runs, manual follow-up and independently downloaded1,101-byte child file. Existing Legacy title edit/reload preserves execution; two real Legacy runs produce independently checked15/34-byte files. These remain historical source records. - Current literal 1c03 Mac core acceptance passes independent checks: ordinary Auto native Codex onboarding without runner override; only timeout 180 seconds/concurrency 1 saved; six successful native runs and six serialized turns (maximum overlap 1); both same-task continuity checks and five mechanical callback checks; actual rendered parent reply and exact child downloads. The useful handoff advances from revision 1 to 2. Both files are 48 bytes, SHA-256 `8b742bd4e8123a7c078f0a8d9f3449fbfa8a320d7d90be641a2818db3c53d92c` and `f42db9774fa06e804ab7d596fc8b922a2b638921c418b87d0111151d290a6afe`; exactly one byte changes and old history remains. The agent is paused with zero active runs/errors. Both artifact work products have `isPrimary=false`, and descriptive titles fail a stricter title-helper assumption; these retained results are scoped editorial follow-up, not new merge gates. Six source-bound screenshots are uploaded and verified in the private primary QA report. - [Literal 9546 managed proof](https://d1p6rlowie26tp.cloudfront.net/runner-e2e/campaigns/gha-38485488621-1/index.html): original 19 assertions and completed judge pass, four native turns, child-bound240-byte file and session/workspace continuity. Checkout reports a verified generated target-lock mutation; full final porcelain was not retained. Signed execution-image identity remains separate from Core source. - Actual 651a Test deployment succeeds on one owned/pinned target. One ordinary Auto API-key Connect then fails native cleanup before hire. Controller turn/drain/suspend completion and service-recorded environment cleanup are observed; they do not certify physical deletion or native authority retirement. Failure/recovery/unknown holds are retained. No Legacy switch or unchanged paid retry. The two source repairs above require actual treatment. - [Current immutable Core preview](https://github.com/paperclipai/paperclip/actions/runs/38570365725) and matching DB/shared artifacts pass. One owned, pinned Test target serves exact `1c03`; identical migration history correctly skips the migrator. Ordinary Auto Codex Connect succeeds and hires native; saved native selection and QA bounds survive reload. The initial child preparation attempt fails before provider work, with actual stdout identifying `renewal_deadline`; its trigger remains unknown and the failure is retained. Normal Board **Try again** and **Resume** recover the child to Done, producing a browser-verified 44-byte file, SHA-256 `0a8458b1efcc2d7a0d815689458c4caab039a46c7c7a3e5805de6bc8b1a96ecc`. The actual parent callback reports the completed child document/file. The existing validator requires a parent-owned attachment, so recovery enters normal Review; after byte checking, normal **Approve completion** reaches parent Done. No forced status or duplicate parent file is used. The validator is unchanged from integrated and current master. Autonomous initial callback-to-Done is not proven. The same-child follow-up completes document revision 2 and publishes a second independently downloaded 44-byte file, SHA-256 `22022257300fae762784632d08d3bbe0bab61e2ce81f91864a14dcd7aa464591`; only the revision digit changes. The unchanged existing native-continuity and attachment oracles pass. All ten recorded runs are terminal: nine native successes and the retained pre-provider setup failure. The QA agent is paused with zero active runs. The pre-existing parent evidence scope mismatch is a separate follow-up, with ordinary completion review exercised rather than a forced status or relaxed validation. This unsigned Core preview remains distinct from post-merge private Cloud composition. ## Risks - Saved agents are not migrated. Explicit runner changes use normal configuration/session rules; historical runs retain their recorded execution. - Native readiness depends on verified assets and server-owned target qualification. A Legacy probe, HTTP200 or successful account save cannot prove native readiness. - Recovery exceptions remain restricted to validated completed-onboarding reports; process-loss, ownership and terminal-state safeguards remain active. Unexecuted live journeys stay open. - Linux ARM paid tasks, Windows, Alpine and 32-bit ARM remain deferred. Cold Cargo cache misses are recorded; no warm-cache speedup is claimed. - Historical invoices/physical cleanup remain unconfirmed and held. After merge, exact published npm canary, signed standard image/migrator, private composition and serving/live acceptance still require qualification. Production deployment/default promotion is not authorized. ## Model Used OpenAI Codex, GPT-6 family, with reasoning, tools, code execution and parallel agents. Exact serving snapshot and context-window size are not exposed. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used with available 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 linked public issues or PRs above - [x] I have not referenced internal/instance-local Paperclip issues or links - [x] My branch name describes the change and contains no internal ticket id - [x] I have run the stated focused tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation - [x] I have considered and documented risks - [x] All Paperclip CI gates are green on the current candidate - [x] Greptile is 5/5 with no open findings on the current candidate - [x] I will address all reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
961 lines
50 KiB
TypeScript
961 lines
50 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { act } from "react";
|
|
import { createRoot, type Root } from "react-dom/client";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
|
import { queryKeys } from "@/lib/queryKeys";
|
|
import { NewAgent } from "./NewAgent";
|
|
import { ApiError } from "@/api/client";
|
|
|
|
const api = vi.hoisted(() => ({
|
|
get: vi.fn(),
|
|
adapterModels: vi.fn(),
|
|
list: vi.fn(),
|
|
hire: vi.fn(),
|
|
testEnvironment: vi.fn(),
|
|
getAdapterAuthSignal: vi.fn(),
|
|
getClaudeOAuthTokenStatus: vi.fn(),
|
|
}));
|
|
const envApi = vi.hoisted(() => ({ list: vi.fn(), capabilities: vi.fn() }));
|
|
const settings = vi.hoisted(() => ({
|
|
get: vi.fn(),
|
|
getExperimental: vi.fn(),
|
|
getGeneral: vi.fn(),
|
|
}));
|
|
const secrets = vi.hoisted(() => ({
|
|
create: vi.fn(),
|
|
remove: vi.fn(),
|
|
list: vi.fn(),
|
|
listMyUserSecrets: vi.fn(),
|
|
createUserSecretDefinition: vi.fn(),
|
|
createMyUserSecret: vi.fn(),
|
|
rotateMyUserSecret: vi.fn(),
|
|
removeUserSecretDefinition: vi.fn(),
|
|
}));
|
|
const state = vi.hoisted(() => ({
|
|
params: new URLSearchParams(),
|
|
adapters: [] as object[],
|
|
navigate: vi.fn(),
|
|
openNewIssue: vi.fn(),
|
|
}));
|
|
const managedApi = vi.hoisted(() => ({
|
|
list: vi.fn(async () => ({ currentUserId: "user-1", canManageConnections: true, connections: [] })),
|
|
create: vi.fn(async () => ({ connectionId: "managed-connection", grantId: "managed-grant" })),
|
|
setDefault: vi.fn(async () => ({})),
|
|
}));
|
|
vi.mock("@/api/ai-connections", () => ({ aiConnectionsApi: managedApi }));
|
|
vi.mock("@/api/agents", () => ({ agentsApi: api }));
|
|
vi.mock("@/api/environments", () => ({ environmentsApi: envApi }));
|
|
vi.mock("@/api/instanceSettings", () => ({ instanceSettingsApi: settings }));
|
|
vi.mock("@/api/secrets", () => ({ secretsApi: secrets }));
|
|
const adapterApi = vi.hoisted(() => ({ list: vi.fn() }));
|
|
vi.mock("@/api/adapters", () => ({ adaptersApi: adapterApi }));
|
|
vi.mock("@/context/CompanyContext", () => ({
|
|
useCompany: () => ({ selectedCompanyId: "company-1" }),
|
|
}));
|
|
vi.mock("../context/BreadcrumbContext", () => ({
|
|
useBreadcrumbs: () => ({ setBreadcrumbs: vi.fn() }),
|
|
}));
|
|
vi.mock("@/context/DialogContext", () => ({
|
|
useDialogActions: () => ({ openNewIssue: state.openNewIssue }),
|
|
}));
|
|
vi.mock("@/lib/router", () => ({
|
|
useNavigate: () => state.navigate,
|
|
useSearchParams: () => [state.params],
|
|
}));
|
|
// Exercise API/persistence contracts with deterministic presentation primitives.
|
|
// The actual searchable dropdown and login panel are covered by their tests and browser verification.
|
|
vi.mock("@/components/AgentConfigForm", () => ({
|
|
ModelDropdown: ({
|
|
value,
|
|
onChange,
|
|
}: {
|
|
value: string;
|
|
onChange: (value: string) => void;
|
|
}) => (
|
|
<input
|
|
aria-label="Model"
|
|
value={value}
|
|
onChange={(e) => onChange(e.target.value)}
|
|
/>
|
|
),
|
|
AdapterLoginPanel: ({ onConnected }: { onConnected: (id: string) => void }) => (
|
|
<button onClick={() => onConnected("login-session")}>
|
|
Complete subscription login
|
|
</button>
|
|
),
|
|
}));
|
|
vi.mock("@/components/onboarding/PillGuy", () => ({ PillGuy: () => null }));
|
|
vi.mock("motion/react", () => ({
|
|
AnimatePresence: ({ children }: any) => children,
|
|
MotionConfig: ({ children }: any) => children,
|
|
motion: {
|
|
span: ({ children }: any) => <span>{children}</span>,
|
|
div: ({ children, initial, animate, exit, transition, ...rest }: any) => (
|
|
<div {...rest}>{children}</div>
|
|
),
|
|
},
|
|
}));
|
|
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
|
|
let root: Root;
|
|
let container: HTMLDivElement;
|
|
let cache: QueryClient;
|
|
async function settle() {
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
});
|
|
}
|
|
async function click(text: string) {
|
|
const button = [...container.querySelectorAll("button")].find(
|
|
(b) => b.textContent?.trim() === text,
|
|
);
|
|
expect(button, `Missing button ${text}`).toBeTruthy();
|
|
await act(async () => button!.click());
|
|
await settle();
|
|
}
|
|
async function fill(label: string, value: string) {
|
|
const input = container.querySelector(
|
|
`[aria-label="${label}"]`,
|
|
) as HTMLInputElement;
|
|
expect(input).toBeTruthy();
|
|
await act(async () => {
|
|
Object.getOwnPropertyDescriptor(
|
|
HTMLInputElement.prototype,
|
|
"value",
|
|
)!.set!.call(input, value);
|
|
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
});
|
|
}
|
|
async function render(adapter = "pi_local", runnerProvider = "codex") {
|
|
state.params = new URLSearchParams({
|
|
name: "Atlas",
|
|
adapterType: adapter,
|
|
runnerProvider,
|
|
});
|
|
await act(async () =>
|
|
root.render(
|
|
<QueryClientProvider client={cache}>
|
|
<TooltipProvider><NewAgent /></TooltipProvider>
|
|
</QueryClientProvider>,
|
|
),
|
|
);
|
|
await settle();
|
|
}
|
|
async function connect(provider: string) {
|
|
await click(provider + "Subscription");
|
|
await click("Connect");
|
|
}
|
|
const pass = {
|
|
adapterType: "pi_local",
|
|
status: "pass",
|
|
checks: [
|
|
{ code: "hello_probe_passed", level: "info", message: "Model replied" },
|
|
],
|
|
testedAt: "2026-09-07T00:00:00Z",
|
|
};
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
adapterApi.list.mockImplementation(async () => state.adapters);
|
|
managedApi.list.mockResolvedValue({ currentUserId: "user-1", canManageConnections: true, connections: [] });
|
|
container = document.createElement("div");
|
|
document.body.append(container);
|
|
root = createRoot(container);
|
|
cache = new QueryClient({
|
|
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
|
|
});
|
|
state.adapters = [
|
|
"claude_local",
|
|
"codex_local",
|
|
"opencode_local",
|
|
"pi_local",
|
|
"paperclip_runner", "cursor_cloud", "cursor", "gemini_local", "kimi_local", "grok_local", "hermes_local", "hermes_gateway",
|
|
].map((type) => ({ type, loaded: true, disabled: false }));
|
|
api.adapterModels.mockResolvedValue([]);
|
|
api.list.mockResolvedValue([{ id: "ceo", role: "ceo", status: "idle" }]);
|
|
api.getAdapterAuthSignal.mockResolvedValue({ status: "present" });
|
|
api.getClaudeOAuthTokenStatus.mockRejectedValue(new ApiError("Not found", 404, null));
|
|
api.testEnvironment.mockResolvedValue(pass);
|
|
api.hire.mockImplementation(async (_company, input) => ({
|
|
agent: { ...input, id: "new-agent", status: "idle", urlKey: "atlas" },
|
|
}));
|
|
envApi.list.mockResolvedValue([
|
|
{ id: "local-1", name: "Local", driver: "local", config: {} },
|
|
]);
|
|
envApi.capabilities.mockResolvedValue({ sandboxProviders: {} });
|
|
settings.get.mockResolvedValue({ defaultEnvironmentId: "local-1" });
|
|
settings.getExperimental.mockResolvedValue({ enableNativeRunner: true });
|
|
settings.getGeneral.mockResolvedValue({ executionMode: "any" });
|
|
secrets.list.mockResolvedValue([]);
|
|
secrets.create.mockResolvedValue({ id: "org-secret-1" });
|
|
secrets.remove.mockResolvedValue({ ok: true });
|
|
secrets.listMyUserSecrets.mockResolvedValue([]);
|
|
secrets.createUserSecretDefinition.mockResolvedValue({ id: "definition-1" });
|
|
secrets.createMyUserSecret.mockResolvedValue({ id: "secret-1" });
|
|
secrets.removeUserSecretDefinition.mockResolvedValue({ ok: true });
|
|
});
|
|
afterEach(async () => {
|
|
await act(async () => root.unmount());
|
|
cache.clear();
|
|
container.remove();
|
|
});
|
|
describe("New agent setup", () => {
|
|
it("records an explicit legacy choice when it matches the Windows default, then preserves it on Linux", async () => {
|
|
settings.get.mockResolvedValue({ defaultEnvironmentId: "local-1" });
|
|
envApi.list.mockResolvedValue([
|
|
{ id: "local-1", name: "Windows", driver: "local", status: "active", config: {} },
|
|
{ id: "linux-ssh", name: "Linux", driver: "ssh", status: "active", config: {} },
|
|
]);
|
|
adapterApi.list.mockImplementation(async (context?: { environmentId?: string | null }) => state.adapters.map((adapter: any) =>
|
|
adapter.type === "codex_local" ? { ...adapter, supportedRunners: context?.environmentId === "linux-ssh" ? ["paperclip", "legacy"] : ["legacy"], defaultRunner: context?.environmentId === "linux-ssh" ? "paperclip" : "legacy" } : adapter));
|
|
await render("codex_local");
|
|
await act(async () => (container.querySelector("summary") as HTMLElement).click());
|
|
const runner = container.querySelector<HTMLButtonElement>('[aria-label="Runner"]')!;
|
|
expect(runner.textContent).toBe("Legacy runner (default)");
|
|
await act(async () => runner.click());
|
|
await act(async () => document.querySelector<HTMLButtonElement>('[role="option"][data-value="legacy"]')!.click());
|
|
await connect("OpenAI");
|
|
expect(api.testEnvironment).toHaveBeenLastCalledWith("company-1", "codex_local", expect.objectContaining({ runner: "legacy" }));
|
|
const environment = container.querySelector<HTMLSelectElement>('select[aria-label="Environment"]')!;
|
|
await act(async () => { environment.value = "linux-ssh"; environment.dispatchEvent(new Event("change", { bubbles: true })); });
|
|
await settle();
|
|
await connect("OpenAI");
|
|
await click("Finish setup");
|
|
expect(api.testEnvironment).toHaveBeenLastCalledWith("company-1", "codex_local", expect.objectContaining({ environmentId: "linux-ssh", runner: "legacy" }));
|
|
expect(api.hire.mock.calls[0][1]).toMatchObject({ adapterType: "codex_local", runner: "legacy" });
|
|
});
|
|
|
|
it("preserves an old native Codex setup link on an unqualified target with the experiment off", async () => {
|
|
settings.getExperimental.mockResolvedValue({ enableNativeRunner: false });
|
|
adapterApi.list.mockImplementation(async () => state.adapters.map((adapter: any) => adapter.type === "codex_local" ? { ...adapter, supportedRunners: ["legacy"], defaultRunner: "legacy" } : adapter));
|
|
api.testEnvironment.mockImplementation(async (_company, adapterType, payload) => {
|
|
if (adapterType === "codex_local" && payload.runner === "paperclip") throw new Error("This target is not qualified for a new native default.");
|
|
return { ...pass, adapterType, checks: [{ code: "paperclip_runner_codex_hello_probe_passed", level: "info", message: "Native runtime replied" }] };
|
|
});
|
|
await render("paperclip_runner", "codex");
|
|
await connect("OpenAI");
|
|
await click("Finish setup");
|
|
expect(api.testEnvironment).toHaveBeenCalledWith("company-1", "paperclip_runner", expect.objectContaining({ runner: "paperclip", adapterConfig: expect.objectContaining({ provider: "codex" }) }));
|
|
expect(api.hire.mock.calls[0][1]).toMatchObject({ adapterType: "paperclip_runner", runner: "paperclip", adapterConfig: { provider: "codex" } });
|
|
});
|
|
|
|
it("discovers the runner for the selected target and rechecks after changing environments", async () => {
|
|
settings.get.mockResolvedValue({ defaultEnvironmentId: "linux-ssh" });
|
|
envApi.list.mockResolvedValue([
|
|
{ id: "local-1", name: "Windows", driver: "local", status: "active", config: {} },
|
|
{ id: "linux-ssh", name: "Linux", driver: "ssh", status: "active", config: {} },
|
|
]);
|
|
adapterApi.list.mockImplementation(async (context?: { companyId: string; environmentId?: string | null }) => state.adapters.map((adapter: any) =>
|
|
adapter.type === "codex_local" ? { ...adapter, supportedRunners: ["paperclip", "legacy"], defaultRunner: context?.environmentId === "linux-ssh" ? "paperclip" : "legacy" } : adapter));
|
|
await render("codex_local");
|
|
await act(async () => (container.querySelector("summary") as HTMLElement).click());
|
|
expect(container.querySelector('[aria-label="Runner"]')?.textContent).toBe("Paperclip Runner (default)");
|
|
expect(adapterApi.list).toHaveBeenCalledWith({ companyId: "company-1", environmentId: "linux-ssh" });
|
|
await connect("OpenAI");
|
|
expect(api.testEnvironment.mock.calls[0][2].environmentId).toBe("linux-ssh");
|
|
const environment = container.querySelector<HTMLSelectElement>('select[aria-label="Environment"]')!;
|
|
await act(async () => {
|
|
environment.value = "local-1";
|
|
environment.dispatchEvent(new Event("change", { bubbles: true }));
|
|
});
|
|
await settle();
|
|
await act(async () => (container.querySelector("summary") as HTMLElement).click());
|
|
expect(container.querySelector('[aria-label="Runner"]')?.textContent).toBe("Legacy runner (default)");
|
|
expect(adapterApi.list).toHaveBeenCalledWith({ companyId: "company-1", environmentId: "local-1" });
|
|
await connect("OpenAI");
|
|
await click("Finish setup");
|
|
expect(api.testEnvironment).toHaveBeenCalledTimes(2);
|
|
expect(api.testEnvironment).toHaveBeenLastCalledWith("company-1", "codex_local", expect.objectContaining({ environmentId: "local-1" }));
|
|
expect(api.hire.mock.calls[0][1]).not.toHaveProperty("runner");
|
|
});
|
|
it("surfaces failed target discovery without guessing a default and permits explicit legacy recovery", async () => {
|
|
adapterApi.list.mockImplementation(async (context?: object) => {
|
|
if (context) throw new Error("SSH target is unavailable. Check its connection.");
|
|
return state.adapters;
|
|
});
|
|
await render("codex_local");
|
|
await settle();
|
|
await act(async () => (container.querySelector("summary") as HTMLElement).click());
|
|
expect(container.querySelector('[aria-label="Runner"]')?.textContent).toBe("Automatic selection unavailable");
|
|
expect(container.textContent).toContain("SSH target is unavailable. Check its connection.");
|
|
expect(container.textContent).not.toContain("Legacy runner (default)");
|
|
expect(container.textContent).toContain("Retry runner discovery");
|
|
await act(async () => container.querySelector<HTMLButtonElement>('[aria-label="Runner"]')!.click());
|
|
await act(async () => [...document.querySelectorAll<HTMLButtonElement>('[role="option"]')].find(option => option.textContent === "Legacy runner")!.click());
|
|
await connect("OpenAI");
|
|
await click("Finish setup");
|
|
expect(api.testEnvironment.mock.calls[0][2]).toMatchObject({ runner: "legacy" });
|
|
expect(api.hire.mock.calls[0][1]).toMatchObject({ runner: "legacy" });
|
|
});
|
|
it.each(["Linux x64", "Mac arm64", "Mac x64"])("uses automatic Codex resolution through setup and hire without the experimental gate (%s)", async name => {
|
|
settings.getExperimental.mockResolvedValue({ enableNativeRunner: false });
|
|
envApi.list.mockResolvedValue([{ id: "local-1", name, driver: "local", status: "active", config: {} }]);
|
|
state.adapters = (state.adapters as any[]).map(adapter => adapter.type === "codex_local" ? { ...adapter, supportedRunners: ["paperclip", "legacy"], defaultRunner: "paperclip" } : adapter);
|
|
await render("codex_local");
|
|
await act(async () => (container.querySelector("summary") as HTMLElement).click());
|
|
expect(container.querySelector('[aria-label="Runner"]')?.textContent).toBe("Paperclip Runner (default)");
|
|
await connect("OpenAI");
|
|
await click("Finish setup");
|
|
expect(api.hire.mock.calls[0][1].adapterType).toBe("codex_local");
|
|
expect(api.hire.mock.calls[0][1]).not.toHaveProperty("runner");
|
|
expect(api.testEnvironment.mock.calls[0][1]).toBe("codex_local");
|
|
expect(api.testEnvironment.mock.calls[0][2]).not.toHaveProperty("runner");
|
|
expect(api.hire.mock.calls[0][1].adapterConfig.dangerouslyBypassApprovalsAndSandbox).not.toBe(true);
|
|
});
|
|
|
|
it("allows the explicit legacy override before authentication and rechecks it after a runner change", async () => {
|
|
state.adapters = (state.adapters as any[]).map(adapter => adapter.type === "codex_local" ? { ...adapter, supportedRunners: ["paperclip", "legacy"], defaultRunner: "paperclip" } : adapter);
|
|
await render("codex_local");
|
|
await act(async () => (container.querySelector("summary") as HTMLElement).click());
|
|
await act(async () => container.querySelector<HTMLButtonElement>('[aria-label="Runner"]')!.click());
|
|
await act(async () => [...document.querySelectorAll<HTMLButtonElement>('[role="option"]')].find(option => option.textContent === "Legacy runner")!.click());
|
|
await connect("OpenAI");
|
|
expect(api.testEnvironment.mock.calls[0][2].runner).toBe("legacy");
|
|
await act(async () => (container.querySelector("summary") as HTMLElement).click());
|
|
await act(async () => container.querySelector<HTMLButtonElement>('[aria-label="Runner"]')!.click());
|
|
await act(async () => [...document.querySelectorAll<HTMLButtonElement>('[role="option"]')].find(option => option.textContent === "Paperclip Runner (default)")!.click());
|
|
await click("Finish setup");
|
|
expect(api.testEnvironment).toHaveBeenLastCalledWith("company-1", "codex_local", expect.objectContaining({ runner: "paperclip" }));
|
|
expect(api.hire.mock.calls[0][1]).toMatchObject({ adapterType: "codex_local", runner: "paperclip" });
|
|
});
|
|
it("creates Dot through its independent choice without CLI or model setup, then routes to pairing", async () => {
|
|
settings.getExperimental.mockResolvedValue({ enableNativeRunner: false, enableOpenAiDot: true, enablePublicMcp: true });
|
|
await render("paperclip_runner", "openai_dot");
|
|
expect(container.textContent).toContain("OpenAI Dot");
|
|
expect(container.querySelector('[aria-label="Model"]')).toBeNull();
|
|
expect(container.textContent).not.toContain("Connect a model");
|
|
expect(container.textContent).toContain("Check prerequisites");
|
|
expect(container.textContent).not.toContain("runtime and model can respond");
|
|
await click("Finish setup");
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
expect(container.textContent).toContain("Acknowledge external provider billing");
|
|
await act(async () => container.querySelector<HTMLButtonElement>('[role="switch"]')!.click());
|
|
await click("Finish setup");
|
|
expect(api.hire).toHaveBeenCalledWith("company-1", expect.objectContaining({ adapterType: "paperclip_runner", adapterConfig: {
|
|
provider: "openai_dot", lifecycleMode: "per_turn", allowUnmeteredProvider: true, dotWorkspaceAccess: false, dotAttachmentAccess: false,
|
|
} }));
|
|
expect(container.textContent).toContain("Your Dot agent has been created");
|
|
await click("Pair Dot");
|
|
expect(state.navigate).toHaveBeenLastCalledWith("/agents/atlas/runtime");
|
|
expect(state.openNewIssue).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it.each(["claude_local", "codex_local"])("can choose a sign-in environment in Configure before connecting %s", async (adapterType) => {
|
|
settings.get.mockResolvedValue({ defaultEnvironmentId: "no-login" });
|
|
envApi.list.mockResolvedValue([
|
|
{ id: "no-login", name: "No browser sign-in", status: "active", driver: "sandbox", config: { provider: "other" } },
|
|
{ id: "login-env", name: "Browser sign-in", status: "active", driver: "sandbox", config: { provider: "daytona" } },
|
|
]);
|
|
envApi.capabilities.mockResolvedValue({ sandboxProviders: { daytona: { supportsLoginPty: true } } });
|
|
api.getAdapterAuthSignal.mockResolvedValue({ status: "missing" });
|
|
await render(adapterType);
|
|
expect(container.textContent).toContain("does not support browser sign-in");
|
|
expect(container.querySelector('select[aria-label="Environment"]')).toBeNull();
|
|
await click("2Configure");
|
|
expect(container.querySelector('button[type="submit"]')).toBeNull();
|
|
expect([...container.querySelectorAll("button")].find(button => button.textContent?.trim() === "Run test")?.disabled).toBe(true);
|
|
await click("Connect model");
|
|
expect(api.testEnvironment).not.toHaveBeenCalled();
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
await click("2Configure");
|
|
const select = container.querySelector('select[aria-label="Environment"]') as HTMLSelectElement;
|
|
await act(async () => {
|
|
select.value = "login-env";
|
|
select.dispatchEvent(new Event("change", { bubbles: true }));
|
|
});
|
|
await settle();
|
|
expect(container.querySelector('select[aria-label="Environment"]')).toBeNull();
|
|
await click("Complete subscription login");
|
|
await click("Finish setup");
|
|
expect(api.hire.mock.calls[0][1]).toMatchObject({ defaultEnvironmentId: "login-env", runtimeConfig: { aiConnection: { method: "subscription" } } });
|
|
});
|
|
it("waits for the resolved environment before allowing a credential-mode selection", async () => {
|
|
let resolveEnvironments!: (value: object[]) => void;
|
|
envApi.list.mockImplementationOnce(() => new Promise<object[]>(resolve => { resolveEnvironments = resolve; }));
|
|
await render("codex_local");
|
|
expect(container.textContent).toContain("Loading connection settings");
|
|
expect(container.querySelector('[role="radiogroup"][aria-label="Connection type"]')).toBeNull();
|
|
await act(async () => resolveEnvironments([{ id: "local-1", name: "Local", driver: "local", config: {} }]));
|
|
await settle();
|
|
await click("OpenAIAPI key");
|
|
expect(container.querySelector('[aria-label="API key"]')).not.toBeNull();
|
|
await settle();
|
|
expect(container.querySelector('[aria-label="API key"]')).not.toBeNull();
|
|
});
|
|
it.each([false, true])("selects the Grok environment in Configure (managed-only=%s)", async (managedOnly) => {
|
|
settings.getExperimental.mockResolvedValue({ enableNativeRunner: true, enableManagedSandboxOnly: managedOnly });
|
|
envApi.list.mockResolvedValue([
|
|
{ id: "local-1", name: "Local", status: "active", driver: "local", config: {} },
|
|
{ id: "grok-sandbox", name: "Grok sandbox", status: "active", driver: "sandbox", config: { provider: "daytona" } },
|
|
]);
|
|
secrets.listMyUserSecrets.mockResolvedValue([{
|
|
definition: { id: "grok-key", companyId: "company-1", key: "XAI_API_KEY", name: "Grok key", status: "active" },
|
|
secret: { companyId: "company-1", status: "active" },
|
|
}]);
|
|
await render("paperclip_runner", "grok");
|
|
expect(container.querySelector('select[aria-label="Environment"]')).toBeNull();
|
|
await click("GrokAPI key");
|
|
await click("Use saved API key");
|
|
const select = container.querySelector('select[aria-label="Environment"]') as HTMLSelectElement;
|
|
expect(select.disabled).toBe(false);
|
|
expect([...select.options].some((option) => option.value === "local-1")).toBe(!managedOnly);
|
|
await act(async () => {
|
|
select.value = "grok-sandbox";
|
|
select.dispatchEvent(new Event("change", { bubbles: true }));
|
|
});
|
|
await settle();
|
|
if (container.querySelector('[role="radiogroup"][aria-label="Connection type"]')) {
|
|
await click("GrokAPI key");
|
|
await click("Use saved API key");
|
|
}
|
|
expect(api.testEnvironment).toHaveBeenCalledWith("company-1", "paperclip_runner", expect.objectContaining({ environmentId: "grok-sandbox" }));
|
|
await click("Finish setup");
|
|
expect(api.hire.mock.calls[0][1].defaultEnvironmentId).toBe("grok-sandbox");
|
|
});
|
|
it.each([false, true])("keeps non-Codex runner setup links gated when the experiment is disabled (cloud=%s)", async (cloud) => {
|
|
cache.setQueryData(queryKeys.health, { status: "ok", cloud: { managed: cloud } });
|
|
settings.getExperimental.mockResolvedValue({ enableNativeRunner: false });
|
|
await render("paperclip_runner", "claude");
|
|
expect(container.textContent).toContain("This adapter is unavailable");
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
});
|
|
it("blocks direct setup links for unsupported Cloud adapters", async () => {
|
|
cache.setQueryData(queryKeys.health, {
|
|
status: "ok",
|
|
cloud: { managed: true },
|
|
});
|
|
await render("pi_local");
|
|
expect(container.textContent).toContain("This adapter is unavailable");
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
});
|
|
it.each([
|
|
["grok_local", "subscription"], ["grok_local", "api_key"],
|
|
["paperclip_runner", "subscription"], ["paperclip_runner", "api_key"],
|
|
])("configures %s Grok on Cloud with an xAI %s connection", async (adapterType, method) => {
|
|
cache.setQueryData(queryKeys.health, {
|
|
status: "ok",
|
|
cloud: { managed: true },
|
|
});
|
|
envApi.list.mockResolvedValue([
|
|
{ id: "sandbox-1", name: "Paperclip Cloud", driver: "sandbox", config: { provider: "daytona" } },
|
|
]);
|
|
envApi.capabilities.mockResolvedValue({
|
|
sandboxProviders: { daytona: { supportsLoginPty: true } },
|
|
});
|
|
settings.get.mockResolvedValue({ defaultEnvironmentId: "sandbox-1" });
|
|
settings.getExperimental.mockResolvedValue({ enableManagedSandboxOnly: true, enableNativeRunner: true });
|
|
api.getAdapterAuthSignal.mockResolvedValue({ status: "missing" });
|
|
api.testEnvironment.mockResolvedValue({ ...pass, adapterType });
|
|
await render(adapterType, "grok");
|
|
expect(container.textContent).toContain("Connect a model");
|
|
expect(container.textContent).not.toContain("Connect Atlas to Grok");
|
|
if (method === "subscription") {
|
|
await click("GrokSubscription");
|
|
await click("Complete subscription login");
|
|
} else {
|
|
await click("GrokAPI key");
|
|
await fill("API key", "example-test-secret");
|
|
await click("Connect");
|
|
expect(managedApi.create).toHaveBeenCalledWith("company-1", expect.objectContaining({
|
|
provider: "xai", method: "api_key", apiKey: "example-test-secret",
|
|
}));
|
|
}
|
|
const model = adapterType === "paperclip_runner" ? "grok-4.7" : "grok-code-fast-1";
|
|
await fill("Model", model);
|
|
await click("Run test");
|
|
const binding = { provider: "xai", method, mode: "responsible_user" };
|
|
expect(api.testEnvironment).toHaveBeenLastCalledWith("company-1", adapterType, expect.objectContaining({
|
|
environmentId: "sandbox-1",
|
|
adapterConfig: expect.objectContaining({ model, ...(adapterType === "paperclip_runner" ? { provider: "acpx", acpxAgent: "grok", acpxPermissionMode: "approve-all" } : {}) }),
|
|
aiConnection: binding,
|
|
testCredentials: {},
|
|
}));
|
|
await click("Finish setup");
|
|
expect(api.hire).toHaveBeenCalledTimes(1);
|
|
expect(api.hire.mock.calls[0][1]).toMatchObject({
|
|
adapterType,
|
|
defaultEnvironmentId: "sandbox-1",
|
|
adapterConfig: { model, ...(adapterType === "paperclip_runner" ? { provider: "acpx", acpxAgent: "grok", acpxPermissionMode: "approve-all" } : {}) },
|
|
runtimeConfig: { aiConnection: binding, heartbeat: { enabled: false } },
|
|
});
|
|
expect(JSON.stringify(api.testEnvironment.mock.calls)).not.toContain("example-test-secret");
|
|
expect(JSON.stringify(api.hire.mock.calls)).not.toContain("example-test-secret");
|
|
expect(container.textContent).toContain("Your agent is ready");
|
|
});
|
|
it("sends Cursor Cloud repo/ref and transient API key, then saves an organization secret", async () => {
|
|
await render("cursor_cloud");
|
|
expect(container.querySelector('[aria-label="Model"]')).toBeNull();
|
|
expect(container.querySelector('[aria-label="Thinking effort"]')).toBeNull();
|
|
await fill("GitHub repository", "https://github.com/paperclipai/paperclip");
|
|
await fill("Branch", "master");
|
|
await fill("CURSOR_API_KEY", "cursor-test-key");
|
|
await click("Run test");
|
|
expect(api.testEnvironment.mock.calls[0][2]).toMatchObject({
|
|
adapterConfig: { repoUrl: "https://github.com/paperclipai/paperclip", repoStartingRef: "master" },
|
|
testCredentials: { CURSOR_API_KEY: "cursor-test-key" },
|
|
});
|
|
expect(secrets.create).not.toHaveBeenCalled();
|
|
await click("Finish setup");
|
|
const config = api.hire.mock.calls[0][1].adapterConfig;
|
|
expect(config).toMatchObject({ repoUrl: "https://github.com/paperclipai/paperclip", repoStartingRef: "master", env: {
|
|
CURSOR_API_KEY: { type: "secret_ref", secretId: "org-secret-1", version: "latest" },
|
|
} });
|
|
expect(config).not.toHaveProperty("repository");
|
|
expect(config).not.toHaveProperty("branch");
|
|
expect(JSON.stringify(config)).not.toContain("cursor-test-key");
|
|
expect(secrets.create).toHaveBeenCalledWith("company-1", expect.objectContaining({ value: "cursor-test-key" }));
|
|
});
|
|
it("requires a new Cursor Cloud key even when organization and personal keys exist", async () => {
|
|
secrets.list.mockResolvedValue([{ id: "existing", key: "CURSOR_API_KEY", name: "Cursor", status: "active" }]);
|
|
secrets.listMyUserSecrets.mockResolvedValue([{ definition: { key: "CURSOR_API_KEY" }, secret: { id: "personal-key" } }]);
|
|
await render("cursor_cloud");
|
|
expect(container.textContent).not.toContain("Or use an organization secret");
|
|
await fill("GitHub repository", "https://github.com/example/repo");
|
|
await click("Finish setup");
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
expect(container.textContent).toContain("Enter a Cursor API key");
|
|
await fill("CURSOR_API_KEY", "new-cursor-key");
|
|
await click("Finish setup");
|
|
expect(secrets.create).toHaveBeenCalledWith("company-1", expect.objectContaining({ value: "new-cursor-key" }));
|
|
expect(api.hire.mock.calls[0][1].adapterConfig.env.CURSOR_API_KEY).toMatchObject({ type: "secret_ref", secretId: "org-secret-1" });
|
|
});
|
|
it.each([
|
|
["cursor", "CURSOR_API_KEY"],
|
|
["gemini_local", "GEMINI_API_KEY"],
|
|
["hermes_local", "OPENROUTER_API_KEY"],
|
|
])("provides %s credentials to tests and stores only a secret reference", async (adapter, key) => {
|
|
await render(adapter);
|
|
await fill(key, "adapter-test-key");
|
|
await click("Finish setup");
|
|
expect(api.testEnvironment.mock.calls[0][2].testCredentials).toEqual({ [key]: "adapter-test-key" });
|
|
expect(api.hire.mock.calls[0][1].adapterConfig.env[key]).toMatchObject({ type: "secret_ref", secretId: "org-secret-1" });
|
|
expect(container.querySelector('[aria-label="Thinking effort"]')).toBeNull();
|
|
});
|
|
it("defines a Kimi API model without overriding it with a CLI model alias", async () => {
|
|
await render("kimi_local");
|
|
await fill("KIMI_MODEL_API_KEY", "kimi-test-key");
|
|
await click("Run test");
|
|
expect(api.testEnvironment).not.toHaveBeenCalled();
|
|
expect(container.textContent).toContain("Enter the Kimi API model name");
|
|
await fill("Kimi API model name", "kimi-for-coding");
|
|
await fill("Kimi API base URL", "https://api.kimi.com/coding/v1");
|
|
await click("Finish setup");
|
|
const config = api.hire.mock.calls[0][1].adapterConfig;
|
|
expect(config).not.toHaveProperty("model");
|
|
expect(config.env).toMatchObject({
|
|
KIMI_MODEL_NAME: { type: "plain", value: "kimi-for-coding" },
|
|
KIMI_MODEL_BASE_URL: { type: "plain", value: "https://api.kimi.com/coding/v1" },
|
|
KIMI_MODEL_API_KEY: { type: "secret_ref", secretId: "org-secret-1" },
|
|
});
|
|
});
|
|
it("configures Hermes Gateway URL and its top-level secret reference", async () => {
|
|
await render("hermes_gateway");
|
|
expect(container.querySelector('[aria-label="Model"]')).toBeNull();
|
|
await fill("Hermes API base URL", "https://hermes.example.com");
|
|
await fill("API_SERVER_KEY", "hermes-test-key");
|
|
await click("Finish setup");
|
|
expect(api.testEnvironment.mock.calls[0][2]).toMatchObject({
|
|
adapterConfig: { apiBaseUrl: "https://hermes.example.com" },
|
|
testCredentials: { API_SERVER_KEY: "hermes-test-key" },
|
|
});
|
|
expect(api.hire.mock.calls[0][1].adapterConfig.apiKey).toMatchObject({ type: "secret_ref", secretId: "org-secret-1" });
|
|
expect(JSON.stringify(api.hire.mock.calls)).not.toContain("hermes-test-key");
|
|
});
|
|
it("uses the shared Grok connection flow and hides ignored Kimi and OpenCode effort controls", async () => {
|
|
await render("grok_local");
|
|
expect(container.textContent).toContain("Connect a model");
|
|
expect(container.textContent).not.toContain("Connect Atlas to Grok");
|
|
await render("opencode_local");
|
|
expect(container.querySelector('[aria-label="Thinking effort"]')).toBeNull();
|
|
});
|
|
it("restores confirmation on refresh without hiring again", async () => {
|
|
api.get.mockResolvedValue({
|
|
id: "saved-agent",
|
|
companyId: "company-1",
|
|
name: "Atlas",
|
|
adapterType: "pi_local",
|
|
adapterConfig: { model: "openrouter/anthropic/claude-sonnet-4.6" },
|
|
status: "idle",
|
|
});
|
|
state.params = new URLSearchParams({
|
|
name: "Atlas",
|
|
adapterType: "pi_local",
|
|
createdAgentId: "saved-agent",
|
|
});
|
|
await act(async () =>
|
|
root.render(
|
|
<QueryClientProvider client={cache}>
|
|
<TooltipProvider><NewAgent /></TooltipProvider>
|
|
</QueryClientProvider>,
|
|
),
|
|
);
|
|
await settle();
|
|
expect(container.textContent).toContain("Your agent is ready");
|
|
expect(container.textContent).not.toContain("Finish setup");
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
await click("Assign Atlas a Task");
|
|
expect(state.openNewIssue).toHaveBeenCalledWith({
|
|
assigneeAgentId: "saved-agent",
|
|
status: "todo",
|
|
});
|
|
});
|
|
it("does not advance connection after a timed-out provider probe", async () => {
|
|
api.testEnvironment.mockResolvedValue({
|
|
...pass,
|
|
status: "warn",
|
|
checks: [
|
|
{
|
|
code: "claude_hello_probe_timed_out",
|
|
level: "warn",
|
|
message: "Claude hello probe timed out.",
|
|
},
|
|
],
|
|
});
|
|
await render("claude_local");
|
|
await connect("Claude");
|
|
expect(container.textContent).toContain("Claude hello probe timed out.");
|
|
expect(container.textContent).not.toContain("Finish setup");
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it.each(["claude_local", "codex_local"])(
|
|
"connects %s, creates once, and assigns a task",
|
|
async (adapter) => {
|
|
await render(adapter);
|
|
await connect(adapter === "claude_local" ? "Claude" : "OpenAI");
|
|
expect(api.testEnvironment).toHaveBeenCalledWith(
|
|
"company-1",
|
|
adapter,
|
|
expect.objectContaining({ environmentId: "local-1" }),
|
|
);
|
|
await click("Finish setup");
|
|
expect(api.hire).toHaveBeenCalledTimes(1);
|
|
expect(api.hire.mock.calls[0][1]).toMatchObject({
|
|
name: "Atlas",
|
|
adapterType: adapter,
|
|
reportsTo: "ceo",
|
|
runtimeConfig: { heartbeat: { enabled: false } },
|
|
});
|
|
expect(container.textContent).toContain("Your agent is ready");
|
|
await click("Assign Atlas a Task");
|
|
expect(state.openNewIssue).toHaveBeenCalledWith({
|
|
assigneeAgentId: "new-agent",
|
|
status: "todo",
|
|
});
|
|
},
|
|
);
|
|
it.each([
|
|
["claude_local", "claude", "Claude", "ANTHROPIC_API_KEY"],
|
|
["codex_local", "codex", "OpenAI", "OPENAI_API_KEY"],
|
|
["paperclip_runner", "claude", "Claude", "ANTHROPIC_API_KEY"],
|
|
["paperclip_runner", "codex", "OpenAI", "OPENAI_API_KEY"],
|
|
])("stores %s %s as a reusable connection before hiring", async (adapter, runner, provider, key) => {
|
|
await render(adapter, runner);
|
|
await click(provider + "API key");
|
|
await fill("API key", "connection-key");
|
|
await click("Connect");
|
|
const binding = { provider: key === "ANTHROPIC_API_KEY" ? "anthropic" : "openai", method: "api_key", mode: "responsible_user" };
|
|
expect(managedApi.create).toHaveBeenCalledWith("company-1", expect.objectContaining({ apiKey: "connection-key", provider: binding.provider }));
|
|
expect(api.testEnvironment.mock.calls[0][2].testCredentials).toEqual({});
|
|
expect(api.testEnvironment.mock.calls[0][2].aiConnection).toEqual(binding);
|
|
expect(container.textContent).toContain("Configure your agent");
|
|
expect(container.querySelector('[role="combobox"][aria-label="Connection"]')).toBeNull();
|
|
expect(secrets.createUserSecretDefinition).not.toHaveBeenCalled();
|
|
await click("Finish setup");
|
|
expect(api.hire.mock.calls[0][1].runtimeConfig.aiConnection).toEqual(binding);
|
|
expect(managedApi.create).toHaveBeenCalledTimes(1);
|
|
expect(JSON.stringify(api.hire.mock.calls)).not.toContain("connection-key");
|
|
});
|
|
it.each([
|
|
["claude_local", "claude", "Claude", "ANTHROPIC_API_KEY"],
|
|
["codex_local", "codex", "OpenAI", "OPENAI_API_KEY"],
|
|
["paperclip_runner", "claude", "Claude", "ANTHROPIC_API_KEY"],
|
|
["paperclip_runner", "codex", "OpenAI", "OPENAI_API_KEY"],
|
|
])("defaults %s %s to a saved key and preserves its reference through hire", async (adapter, runner, provider, key) => {
|
|
secrets.listMyUserSecrets.mockResolvedValue([{
|
|
definition: { id: "existing-key", companyId: "company-1", key, name: "Existing key", status: "active" },
|
|
secret: { companyId: "company-1", status: "active" },
|
|
}]);
|
|
await render(adapter, runner);
|
|
await click(provider + "API key");
|
|
expect((container.querySelector("select[aria-label='Saved API key']") as HTMLSelectElement).value).toBe("user:existing-key");
|
|
await click("Use saved API key");
|
|
const binding = { type: "user_secret_ref", key, version: "latest" };
|
|
expect(api.testEnvironment.mock.calls[0][2].adapterConfig.env[key]).toEqual(binding);
|
|
expect(api.testEnvironment.mock.calls[0][2].testCredentials).toEqual({});
|
|
await click("Finish setup");
|
|
expect(api.hire.mock.calls[0][1].adapterConfig.env[key]).toEqual(binding);
|
|
expect(secrets.createUserSecretDefinition).not.toHaveBeenCalled();
|
|
expect(secrets.createMyUserSecret).not.toHaveBeenCalled();
|
|
expect(secrets.rotateMyUserSecret).not.toHaveBeenCalled();
|
|
});
|
|
it.each(["codex_local", "paperclip_runner"])("keeps a saved connection chosen in Connect when hiring %s", async (adapter) => {
|
|
await render(adapter, "codex");
|
|
managedApi.list.mockResolvedValue({
|
|
currentUserId: "user-1",
|
|
connections: [{
|
|
id: "00000000-0000-4000-8000-000000000021", grantId: "00000000-0000-4000-8000-000000000022", companyId: "company-1",
|
|
provider: "openrouter", method: "api_key", name: "Company OpenRouter",
|
|
ownership: "shared", isDefault: false, status: "connected",
|
|
routing: { kind: "openrouter", protocol: "responses", auth: "bearer", models: [] },
|
|
}],
|
|
} as any);
|
|
await click("AdvancedCustom Gateway");
|
|
const picker = container.querySelector('[role="combobox"][aria-label="Connection"]')!;
|
|
await act(async () => picker.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true })));
|
|
await settle();
|
|
const option = [...document.querySelectorAll('[role="option"]')].find(node => node.textContent?.includes("Company OpenRouter")) as HTMLElement;
|
|
expect(option).toBeTruthy();
|
|
await act(async () => option.click());
|
|
await settle();
|
|
await click("Use connection");
|
|
expect(container.textContent).toContain("Configure your agent");
|
|
expect(container.querySelector('[role="combobox"][aria-label="Connection"]')).toBeNull();
|
|
await click("Run test");
|
|
const binding = { provider: "openrouter", method: "api_key", mode: "shared", connectionId: "00000000-0000-4000-8000-000000000021", grantId: "00000000-0000-4000-8000-000000000022" };
|
|
expect(api.testEnvironment.mock.calls[0][2].aiConnection).toEqual(binding);
|
|
await click("Finish setup");
|
|
expect(api.hire.mock.calls[0][1].runtimeConfig.aiConnection).toEqual(binding);
|
|
});
|
|
it("requires the current connection choice to connect before Configure can save it", async () => {
|
|
await render("codex_local");
|
|
managedApi.list.mockResolvedValue({ currentUserId: "user-1", connections: [{
|
|
id: "00000000-0000-4000-8000-000000000021", grantId: "00000000-0000-4000-8000-000000000022", companyId: "company-1",
|
|
provider: "openrouter", method: "api_key", name: "Company OpenRouter", ownership: "shared", isDefault: false, status: "connected",
|
|
routing: { kind: "openrouter", protocol: "responses", auth: "bearer", models: [] },
|
|
}] } as any);
|
|
await click("AdvancedCustom Gateway");
|
|
const picker = container.querySelector('[role="combobox"][aria-label="Connection"]')!;
|
|
await act(async () => picker.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true })));
|
|
await settle();
|
|
const option = [...document.querySelectorAll('[role="option"]')].find(node => node.textContent?.includes("Company OpenRouter")) as HTMLElement;
|
|
await act(async () => option.click());
|
|
await settle();
|
|
await click("2Configure");
|
|
expect(container.textContent).not.toContain("Finish setup");
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
await click("Connect model");
|
|
await click("OpenAIAPI key");
|
|
await fill("API key", "new-api-credential");
|
|
await click("2Configure");
|
|
expect(container.textContent).not.toContain("Finish setup");
|
|
expect(api.testEnvironment).not.toHaveBeenCalled();
|
|
await click("Connect model");
|
|
await click("OpenAIAPI key");
|
|
await fill("API key", "new-api-credential");
|
|
await click("Connect");
|
|
await click("Connection");
|
|
await click("2Configure");
|
|
expect(container.textContent).not.toContain("Finish setup");
|
|
await click("Connect model");
|
|
await click("OpenAIAPI key");
|
|
await fill("API key", "new-api-credential");
|
|
await click("Connect");
|
|
await click("Finish setup");
|
|
expect(api.hire.mock.calls[0][1].runtimeConfig.aiConnection).toEqual({ provider: "openai", method: "api_key", mode: "responsible_user" });
|
|
});
|
|
it.each(["pi_local"])(
|
|
"persists %s OpenRouter credentials only as a secret reference",
|
|
async (adapter) => {
|
|
await render(adapter);
|
|
await fill("Model", "openrouter/anthropic/claude-sonnet-4.6");
|
|
await fill("OPENROUTER_API_KEY", "example-test-secret");
|
|
await click("Run test");
|
|
expect(secrets.rotateMyUserSecret).not.toHaveBeenCalled();
|
|
expect(secrets.createMyUserSecret).not.toHaveBeenCalled();
|
|
expect(api.testEnvironment.mock.calls[0][2].testCredentials).toEqual({ OPENROUTER_API_KEY: "example-test-secret" });
|
|
await click("Finish setup");
|
|
expect(api.hire.mock.calls[0][1].adapterConfig.env.OPENROUTER_API_KEY).toEqual({
|
|
type: "secret_ref",
|
|
secretId: "org-secret-1",
|
|
version: "latest",
|
|
});
|
|
expect(secrets.create).toHaveBeenCalledWith(
|
|
"company-1", expect.objectContaining({ value: "example-test-secret" }),
|
|
);
|
|
expect(JSON.stringify(api.hire.mock.calls)).not.toContain(
|
|
"example-test-secret",
|
|
);
|
|
expect(secrets.create).toHaveBeenCalledTimes(1);
|
|
},
|
|
);
|
|
it("connects OpenRouter before testing and hiring OpenCode without copying credentials into the agent", async () => {
|
|
await render("opencode_local");
|
|
const model = "openrouter/anthropic/claude-sonnet-4.6";
|
|
await fill("Model", model);
|
|
const connectionSelect = container.querySelector('[role="combobox"][aria-label="Connection"]')!;
|
|
await act(async () => connectionSelect.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true })));
|
|
await settle();
|
|
const connectOption = [...document.querySelectorAll('[role="option"]')].find(option => option.textContent?.includes("Connect an account"))!;
|
|
expect(connectOption).toBeTruthy();
|
|
await act(async () => (connectOption as HTMLElement).click());
|
|
await settle();
|
|
const dialog = document.querySelector('[role="dialog"]')!;
|
|
expect(dialog).toBeTruthy();
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
expect(api.testEnvironment).not.toHaveBeenCalled();
|
|
const advanced = [...dialog.querySelectorAll("summary")].find(node => node.textContent?.includes("Advanced providers"))!;
|
|
await act(async () => advanced.click());
|
|
const openrouter = [...dialog.querySelectorAll("button")].find(node => node.textContent?.includes("OpenRouter"))!;
|
|
await act(async () => openrouter.click());
|
|
await settle();
|
|
const input = dialog.querySelector('[aria-label="API key"]') as HTMLInputElement;
|
|
expect(input).toBeTruthy();
|
|
await act(async () => {
|
|
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(input, "example-test-secret");
|
|
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
});
|
|
const connectButton = [...dialog.querySelectorAll("button")].find((button) => button.textContent?.trim() === "Connect")!;
|
|
expect(connectButton.disabled).toBe(false);
|
|
await act(async () => connectButton.click());
|
|
await settle();
|
|
expect(document.querySelector('[role="dialog"]')).toBeNull();
|
|
expect(managedApi.setDefault).not.toHaveBeenCalled();
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
expect(api.testEnvironment).not.toHaveBeenCalled();
|
|
expect(managedApi.create).toHaveBeenCalledWith("company-1", expect.objectContaining({
|
|
provider: "openrouter", method: "api_key", apiKey: "example-test-secret",
|
|
}));
|
|
const binding = { provider: "openrouter", method: "api_key", mode: "shared", connectionId: "managed-connection", grantId: "managed-grant" };
|
|
|
|
await click("Run test");
|
|
expect(api.testEnvironment.mock.calls[0][2]).toEqual(expect.objectContaining({
|
|
aiConnection: binding, testCredentials: {},
|
|
adapterConfig: expect.objectContaining({ model }),
|
|
}));
|
|
await click("Finish setup");
|
|
expect(api.hire.mock.calls[0][1]).toEqual(expect.objectContaining({
|
|
adapterType: "opencode_local",
|
|
runtimeConfig: expect.objectContaining({ aiConnection: binding }),
|
|
adapterConfig: expect.objectContaining({ model }),
|
|
}));
|
|
expect(managedApi.create).toHaveBeenCalledTimes(1);
|
|
expect(secrets.create).not.toHaveBeenCalled();
|
|
expect(JSON.stringify(api.testEnvironment.mock.calls)).not.toContain("example-test-secret");
|
|
expect(JSON.stringify(api.hire.mock.calls)).not.toContain("example-test-secret");
|
|
});
|
|
it.each(["codex", "claude", "opencode"])(
|
|
"uses the correct native %s runner",
|
|
async (runner) => {
|
|
await render("paperclip_runner", runner);
|
|
if (runner !== "opencode")
|
|
await connect(runner === "claude" ? "Claude" : "OpenAI");
|
|
else await fill("Model", "openrouter/anthropic/claude-sonnet-4.6");
|
|
await click("Finish setup");
|
|
const config = api.hire.mock.calls[0][1].adapterConfig;
|
|
if (runner === "codex") {
|
|
expect(api.hire.mock.calls[0][1]).toMatchObject({ adapterType: "paperclip_runner", runner: "paperclip" });
|
|
expect(api.testEnvironment).toHaveBeenCalledWith("company-1", "paperclip_runner", expect.objectContaining({ runner: "paperclip" }));
|
|
} else expect(config.provider).toBe(runner === "claude" ? "acpx" : runner);
|
|
if (runner === "claude") {
|
|
expect(config.acpxAgent).toBe("claude");
|
|
expect(config.model).toMatch(/^claude-/);
|
|
}
|
|
if (runner === "codex") expect(config.acpxAgent).toBeUndefined();
|
|
},
|
|
);
|
|
it("does not create when the test fails and permits retry", async () => {
|
|
await render();
|
|
await fill("Model", "openrouter/unknown/model");
|
|
api.testEnvironment.mockResolvedValueOnce({ ...pass, status: "fail" });
|
|
await click("Run test");
|
|
await click("Finish setup");
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
expect(container.textContent).toContain("Couldn't connect");
|
|
await click("Retry test");
|
|
await click("Finish setup");
|
|
expect(api.hire).toHaveBeenCalledTimes(1);
|
|
});
|
|
it("does not rotate a working provider credential when a new key fails its test", async () => {
|
|
secrets.listMyUserSecrets.mockResolvedValue([{ definition: { id: "existing-definition", key: "OPENROUTER_API_KEY" }, secret: { id: "working-secret" } }]);
|
|
await render();
|
|
await fill("Model", "openrouter/anthropic/claude-sonnet-4.6");
|
|
await fill("OPENROUTER_API_KEY", "invalid-replacement");
|
|
api.testEnvironment.mockResolvedValueOnce({ ...pass, status: "fail" });
|
|
await click("Run test");
|
|
expect(secrets.rotateMyUserSecret).not.toHaveBeenCalled();
|
|
expect(secrets.createUserSecretDefinition).not.toHaveBeenCalled();
|
|
expect(api.testEnvironment.mock.calls[0][2].testCredentials.OPENROUTER_API_KEY).toBe("invalid-replacement");
|
|
await click("Finish setup");
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
});
|
|
it("does not store a key when leaving after a successful test", async () => {
|
|
await render();
|
|
await fill("Model", "openrouter/anthropic/claude-sonnet-4.6");
|
|
await fill("OPENROUTER_API_KEY", "abandoned-key");
|
|
await click("Run test");
|
|
await act(async () => root.render(null));
|
|
expect(secrets.createUserSecretDefinition).not.toHaveBeenCalled();
|
|
});
|
|
it("removes the staged credential when hiring fails", async () => {
|
|
await render();
|
|
await fill("Model", "openrouter/anthropic/claude-sonnet-4.6");
|
|
await fill("OPENROUTER_API_KEY", "new-key");
|
|
api.hire.mockRejectedValueOnce(new Error("Creation rejected"));
|
|
await click("Finish setup");
|
|
expect(secrets.remove).toHaveBeenCalledWith("org-secret-1");
|
|
expect(container.textContent).toContain("Creation rejected");
|
|
});
|
|
it("preserves the creation error when credential cleanup also fails", async () => {
|
|
await render();
|
|
await fill("Model", "openrouter/anthropic/claude-sonnet-4.6");
|
|
await fill("OPENROUTER_API_KEY", "new-key");
|
|
api.hire.mockRejectedValueOnce(new Error("Agent quota exceeded"));
|
|
secrets.remove.mockRejectedValueOnce(new Error("Cleanup unavailable"));
|
|
await click("Finish setup");
|
|
expect(container.textContent).toContain("Agent quota exceeded");
|
|
expect(container.textContent).toContain("Could not remove an unused setup credential");
|
|
});
|
|
it("requires an explicit provider/model for Pi", async () => {
|
|
await render();
|
|
await click("Run test");
|
|
expect(api.testEnvironment).not.toHaveBeenCalled();
|
|
expect(container.textContent).toContain("provider/model format");
|
|
});
|
|
it("blocks a disabled runner even when opened through a URL", async () => {
|
|
state.adapters = [
|
|
{ type: "codex_local", loaded: true, disabled: false },
|
|
{ type: "paperclip_runner", loaded: true, disabled: true },
|
|
];
|
|
await render("paperclip_runner");
|
|
expect(container.textContent).toContain("This adapter is unavailable");
|
|
expect(api.testEnvironment).not.toHaveBeenCalled();
|
|
expect(api.hire).not.toHaveBeenCalled();
|
|
});
|
|
it("keeps pending agents behind approval and disables task assignment", async () => {
|
|
api.hire.mockResolvedValue({
|
|
agent: { id: "new-agent", name: "Atlas", status: "pending_approval" },
|
|
});
|
|
await render();
|
|
await fill("Model", "openrouter/anthropic/claude-sonnet-4.6");
|
|
await click("Finish setup");
|
|
expect(container.textContent).toContain("Agent submitted for approval");
|
|
await click("Assign Atlas a Task");
|
|
expect(state.openNewIssue).not.toHaveBeenCalled();
|
|
});
|
|
it("uses the same managed environment for connection testing and creation", async () => {
|
|
envApi.list.mockResolvedValue([
|
|
{ id: "sandbox-1", driver: "sandbox", config: { provider: "daytona" } },
|
|
]);
|
|
envApi.capabilities.mockResolvedValue({
|
|
sandboxProviders: { daytona: { supportsLoginPty: true } },
|
|
});
|
|
settings.get.mockResolvedValue({ defaultEnvironmentId: "sandbox-1" });
|
|
settings.getExperimental.mockResolvedValue({
|
|
enableManagedSandboxOnly: true,
|
|
});
|
|
api.getClaudeOAuthTokenStatus.mockResolvedValue({ secretId: "saved-oauth", latestVersion: 1 });
|
|
await render("claude_local");
|
|
await click("ClaudeSubscription");
|
|
await click("Use saved subscription");
|
|
await click("Finish setup");
|
|
expect(api.testEnvironment.mock.calls[0][2].environmentId).toBe(
|
|
"sandbox-1",
|
|
);
|
|
expect(api.hire.mock.calls[0][1]).toMatchObject({
|
|
defaultEnvironmentId: "sandbox-1",
|
|
applyStoredClaudeLogin: true,
|
|
});
|
|
});
|
|
});
|