Files
PaperClipAI/tests/ai-connections-app/inline-repair.live.spec.ts
DottaandPaperclip 8d6232e7b0 feat: reuse provider sign-in across AI connection workflows (#13248)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Users connect provider accounts during onboarding and agent setup.
> - They should reuse and manage those accounts through the existing
Connectors interface.
> - A second login wizard would diverge from the established provider
workflows.
> - This pull request composes the existing sign-in components into
Connections and agent configuration.
> - Users can select accounts without changing their agent's harness or
model.

## Linked Issues or Issue Description

**Problem or motivation**
AI credentials are configured separately from Connections. Agents cannot
consistently reuse a responsible user's account or a permitted shared
account.

**Proposed solution**
Manage AI accounts with the existing Connections grants and permissions.
Keep model and harness selection independent from credential selection.
Preserve legacy authentication until validated adoption.

**Alternatives considered**
A separate credential registry would duplicate ownership and access
policy. Automatic fallback would risk using the wrong account.

**Roadmap alignment**
This extends the shipped Apps, multi-user, secrets, and agent-runtime
capabilities. The maintainer requested the feature and reviewed the UI.
Related groundwork: #11899 (connection permissions), #10910 (connection
wizard), #11692 (Claude subscription profiles), and #11854 (Codex
account rotation).

## What Changed

- Add compact AI-account management to the existing Connectors pages.
- Reuse AgentProviderConnection, AdapterLoginPanel, AdapterLoginChrome,
and authentication controllers.
- Add the shared connection picker to agent setup/settings and task
requests.
- Preserve onboarding's sequence and reuse existing accounts.
- Add local-login recovery, retry, cancellation, and React StrictMode
handling.
- Add interactive Storybook scenarios, design-guide examples, and app
acceptance checks.

This is part 2 of the AI Connections change. The runtime foundation in
#13247 is merged. This PR now targets master.

## Verification

- Updated against master `47ded8bf9`, including the landed runtime
foundation and upstream task-search changes.
- Full workspace typecheck, production build, Storybook build, and token
gates passed on the integrated branch. Final local-login changes passed
59 focused tests; new-agent and inbox regression suites passed 63 tests.
- Browser checks verified automatic local Claude account detection,
resumable Codex login commands, retry, focus restoration, and
desktop/phone layouts. Commands create their isolated directory before
invoking the CLI.
- All CI test, browser, build, packaging, and runner jobs passed on
final head `dd17d3211931dd70aaa6ea619d83a7f9966dd18e`. The fresh
Greptile review is 5/5, the security scan passed, and there are no
unresolved review threads. The final CI aggregate gates passed.
- Local general-server coverage passed 11,804 tests; three
port-collision failures passed in an isolated 25-test rerun. All 6,111
UI tests passed. CLI coverage passed 484 tests; its remaining doctor
test requires port 3199, which is occupied by an unrelated report server
on this Mac. The complete CLI suite passed in CI.
- Live browser testing verified Codex API-key reconnect inside a task
card on desktop and phone. Real provider runs resumed and completed with
unchanged connection/grant identity and agent routing.
- Tested opening, cancelling, reopening, and completing connection
creation. A regression confirms Connect another account cannot submit
the new-agent form or copy provider keys into agent settings.
- Added shared inline repair, automatic local sign-in checks, and
responsive connection dialogs. Standalone Daytona installation ignores
workspace configuration and suppresses dependency scripts. Its
standalone build also passed with CI's exact pnpm 9.15.4.
- Destructive live tests are excluded by default. Explicit opt-in, local
deployment checks, and matching disposable fixture identities are
required before any mutation.

## Risks

- Local Codex/Grok creation requires the connection-specific terminal
login command.
- Browser sign-in uses the existing supported-environment controllers.
- This update verifies live local Claude detection and Codex API-key
task repair. New subscription authorization/refresh and
independent-human/native-runner isolation were not reverified in this
update.
- No agent automatically adopts managed Connections.

## Model Used

OpenAI GPT-6 through Codex, with reasoning, repository tools, code
execution, and browser testing. The exact runtime model identifier and
context-window size are not exposed in this session.

## Checklist

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

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-09-12 16:51:26 -05:00

91 lines
6.5 KiB
TypeScript

import { test, expect } from "@playwright/test";
// Explicitly opt in with a disposable task/account and a real provider key.
// All writes use the UI. API reads only verify identity and execution outcomes.
const disposableMarker = process.env.AI_REPAIR_TEST_DISPOSABLE_MARKER;
const destructiveOptIn = process.env.AI_REPAIR_TEST_ALLOW_DESTRUCTIVE === "1";
const companyId = process.env.AI_CONNECTIONS_TEST_COMPANY_ID;
const issueId = process.env.AI_REPAIR_TEST_ISSUE_ID;
const connectionId = process.env.AI_REPAIR_TEST_CONNECTION_ID;
const providerKey = process.env.AI_REPAIR_TEST_KEY;
test.use({ trace: "off", video: "off" });
test.skip(!destructiveOptIn || !disposableMarker || !companyId || !issueId || !connectionId || !providerKey, "Live repair requires explicit disposable fixtures and a provider key");
test("repair the selected AI account inside the task and continue without another message", async ({ page, request }, testInfo) => {
test.setTimeout(240_000);
if (process.env.AI_REPAIR_TEST_NARROW === "1") await page.setViewportSize({ width: 390, height: 844 });
// Fail before any mutation unless every target belongs to the same explicitly
// marked disposable fixture. Never run this scenario against a remote host.
const origin = new URL(testInfo.project.use.baseURL!);
expect(origin.protocol).toBe("http:");
expect(["127.0.0.1", "[::1]"]).toContain(origin.hostname);
expect(disposableMarker).toMatch(/^[a-f0-9]{32}$/);
const fixtureName = `AI Repair QA ${disposableMarker}`;
const health = await (await request.get("/api/health")).json();
expect(health.deploymentMode).toBe("local_trusted");
const companies = await (await request.get("/api/companies")).json();
const company = companies.find((company: { id: string }) => company.id === companyId);
expect(company).toMatchObject({ id: companyId, name: fixtureName });
const prefix = company.issuePrefix;
const taskBefore = await (await request.get(`/api/issues/${issueId}`)).json();
const agentBefore = await (await request.get(`/api/agents/${taskBefore.assigneeAgentId}`)).json();
expect(taskBefore).toMatchObject({ companyId, title: fixtureName });
expect(agentBefore).toMatchObject({ companyId, name: fixtureName, adapterType: "codex_local" });
const agents = await (await request.get(`/api/companies/${companyId}/agents`)).json();
expect(agents.map((agent: { id: string }) => agent.id)).toEqual([agentBefore.id]);
const list = async () => (await (await request.get(`/api/companies/${companyId}/ai-connections`)).json()).connections;
const before = await list();
const accountBefore = before.find((connection: { id: string }) => connection.id === connectionId);
expect(before).toHaveLength(1);
expect(accountBefore).toMatchObject({ companyId, name: fixtureName, provider: "openai", method: "api_key", ownership: "personal" });
expect(accountBefore.isDefault).toBe(true);
expect(["connected", "revoked"]).toContain(accountBefore.status);
await page.goto(`/${prefix}/apps/${connectionId}/permissions`);
if (accountBefore.status === "connected") {
await page.getByRole("button", { name: "Revoke identity", exact: true }).click();
await page.getByRole("alertdialog").getByRole("button", { name: "Revoke identity", exact: true }).click();
}
await expect(page.locator("header").getByText("Revoked", { exact: true })).toBeVisible();
await page.goto(`/${prefix}/issues/${issueId}`);
let proof = `QA-IN-CARD-REPAIR-${Date.now()}: 1147`;
const pending = (await (await request.get(`/api/issues/${issueId}/interactions`)).json()).some((interaction: {kind: string; status: string; payload: {purpose?: string}}) => interaction.kind === "connection_intent" && interaction.status === "pending" && interaction.payload.purpose === "ai");
if (pending) {
const comments = await (await request.get(`/api/issues/${issueId}/comments`)).json();
proof = comments.map((comment: {body: string}) => comment.body.match(/QA-IN-CARD-REPAIR-\d+: 1147/)?.[0]).filter(Boolean).at(-1);
expect(proof).toBeTruthy();
} else {
await page.getByRole("textbox", { name: "editable markdown" }).fill(`Inline repair acceptance: calculate 31 * 37. Post exactly ${proof}, then mark Done. This first attempt should block on my revoked default; I will reconnect it inside this task. Do not change configuration, create subtasks, or modify files.`);
await page.getByRole("button", { name: "Send", exact: true }).click();
}
const fix = page.getByRole("button", { name: "Fix connection", exact: true });
await expect(fix).toBeVisible({ timeout: 60_000 });
await fix.click();
const inline = page.getByTestId("ai-connection-inline-repair");
await expect(inline.getByLabel("Connection name")).toHaveValue(accountBefore.name);
await expect(inline.getByLabel("Connection name")).toBeDisabled();
await expect(page.getByRole("dialog")).toHaveCount(0);
await inline.getByRole("button", { name: /^(Back|Cancel)$/ }).click();
await expect(page.getByTestId("ai-connection-inline-repair")).toHaveCount(0);
await expect(page.getByTestId("connection-intent-focus-target").filter({ has: fix })).toBeFocused();
await fix.click();
await inline.getByRole("radio", { name: "OpenAI API", exact: true }).click();
const keyField = inline.getByPlaceholder("Enter API key here");
await expect(keyField).toBeVisible();
await inline.screenshot({ path: testInfo.outputPath("inline-repair-before.png") });
// Never include credentials in a failed action's error/trace output.
try { await keyField.fill(providerKey!); } catch { throw new Error("Could not fill the private credential field"); }
await inline.getByRole("button", { name: "Connect", exact: true }).click();
await expect(page.getByTestId("ai-connection-inline-repair")).toHaveCount(0, { timeout: 60_000 });
await expect(page.getByText(proof, { exact: true })).toBeVisible({ timeout: 120_000 });
await expect.poll(async () => (await (await request.get(`/api/issues/${issueId}`)).json()).status).toBe("done");
const after = await list();
expect(after).toHaveLength(before.length);
expect(after.find((connection: { id: string }) => connection.id === connectionId)).toMatchObject({ id: connectionId, grantId: accountBefore.grantId, isDefault: true, status: "connected" });
const agentAfter = await (await request.get(`/api/agents/${taskBefore.assigneeAgentId}`)).json();
expect(agentAfter.adapterType).toBe(agentBefore.adapterType);
expect(agentAfter.adapterConfig).toEqual(agentBefore.adapterConfig);
expect(agentAfter.runtimeConfig).toEqual(agentBefore.runtimeConfig);
await page.screenshot({ path: testInfo.outputPath("inline-repair-completed.png"), fullPage: true });
});