diff --git a/cli/src/__tests__/onboard-service.test.ts b/cli/src/__tests__/onboard-service.test.ts index 58abea274e8..3a6ae33e54e 100644 --- a/cli/src/__tests__/onboard-service.test.ts +++ b/cli/src/__tests__/onboard-service.test.ts @@ -1,5 +1,6 @@ import fs from "node:fs"; import path from "node:path"; +import os from "node:os"; import { beforeEach, describe, expect, it, vi } from "vitest"; import { ensureServiceShim, @@ -298,6 +299,35 @@ describe("onboarded service dashboard handoff", () => { expect(openDashboard).not.toHaveBeenCalled(); }); + it("opens a local_trusted board through the operator sign-in link and an authenticated board directly", async () => { + const home = fs.mkdtempSync(path.join(os.tmpdir(), "paperclip-onboard-open-")); + const previous = process.env.PAPERCLIP_HOME; + process.env.PAPERCLIP_HOME = home; + try { + const runtime = { + schemaVersion: 1 as const, instanceId: "default", pid: 123, host: "127.0.0.1", port: 3101, + dashboardUrl: "http://127.0.0.1:3101", startedAt: "2026-08-25T00:00:00.000Z", + }; + for (const deploymentMode of ["local_trusted", "authenticated"] as const) { + const openDashboard = vi.fn(async (_url: string) => true); + const config = dashboardConfig(); + await handoffToOnboardedService({ ...config, server: { ...config.server, deploymentMode } }, { + isInteractive: () => true, + waitUntilReady: async () => runtime, + openDashboard, + info: vi.fn(), + success: vi.fn(), + }); + const opened = new URL(openDashboard.mock.calls[0]![0]); + expect(opened.pathname).toBe(deploymentMode === "local_trusted" ? "/api/local-operator/sign-in" : "/"); + } + } finally { + if (previous === undefined) delete process.env.PAPERCLIP_HOME; + else process.env.PAPERCLIP_HOME = previous; + fs.rmSync(home, { recursive: true, force: true }); + } + }); + it("uses the ready service runtime port before opening the dashboard", async () => { const waitUntilReady = vi.fn(async () => ({ schemaVersion: 1 as const, diff --git a/cli/src/onboard-service.ts b/cli/src/onboard-service.ts index 7846f4ff451..ffc7efb4c9d 100644 --- a/cli/src/onboard-service.ts +++ b/cli/src/onboard-service.ts @@ -31,7 +31,7 @@ export type OnboardServiceOptions = { type EnsureShimResult = { ok: boolean; installedNow: boolean; reason?: string }; type OnboardServiceDashboardConfig = { auth: Pick; - server: Pick; + server: Pick & Partial>; }; type OnboardServiceDashboardDependencies = { @@ -75,8 +75,7 @@ async function waitUntilDashboardReady(timeoutMs = 60_000): Promise process.stdin.isTTY === true && process.stdout.isTTY === true, waitUntilReady: waitUntilDashboardReady, - // A local board that requires the operator credential opens signed in. - openDashboard: (url) => openUrl(localBoardEntryUrl(url)), + openDashboard: openUrl, info: (message) => p.log.info(message), success: (message) => p.log.success(message), warn: (message) => p.log.warn(message), @@ -112,7 +111,10 @@ export async function handoffToOnboardedService( if (!deps.isInteractive() || envDisablesBrowser()) return; - if (await deps.openDashboard(dashboardUrl)) { + // A local_trusted board opens through the operator's sign-in link, so it + // opens signed in when the board requires the operator credential. + const entryUrl = config.server.deploymentMode === "local_trusted" ? localBoardEntryUrl(dashboardUrl) : dashboardUrl; + if (await deps.openDashboard(entryUrl)) { deps.success("Sent the Paperclip dashboard to your browser."); } else { deps.warn(`Could not open a browser automatically. Open ${dashboardUrl} manually.`); diff --git a/server/src/__tests__/local-operator-credential.test.ts b/server/src/__tests__/local-operator-credential.test.ts index a80d095cc94..b9e2be6b9d7 100644 --- a/server/src/__tests__/local-operator-credential.test.ts +++ b/server/src/__tests__/local-operator-credential.test.ts @@ -40,6 +40,7 @@ function startServer(operator: LocalOperatorCredential): Promise<{ server: Serve app.get("/api/whoami", whoami); app.post("/api/whoami", whoami); app.get("/api/attachments/:id/content", whoami); + app.get("/api/issues/:id/file-resources/content", whoami); app.post("/api/attachments/:id/content", whoami); return new Promise((resolve) => { const server = app.listen(0, "127.0.0.1", () => { @@ -181,8 +182,10 @@ describe.skipIf(!supported)("operator browser sign-in", () => { it("lets the browser load a file it was shown with the cookie alone", async () => { const { cookie } = await signIn(); - const response = await fetch(`${base}/api/attachments/a1/content`, { headers: { cookie } }); - expect(await response.json()).toEqual({ type: "board", source: "local_implicit" }); + for (const file of ["/api/attachments/a1/content", "/api/issues/i1/file-resources/content?path=a.txt"]) { + const response = await fetch(`${base}${file}`, { headers: { cookie } }); + expect(await response.json()).toEqual({ type: "board", source: "local_implicit" }); + } }); it("accepts each sign-in link only once", async () => { diff --git a/server/src/middleware/local-operator-credential.ts b/server/src/middleware/local-operator-credential.ts index 9d96efe84a3..35a1820188a 100644 --- a/server/src/middleware/local-operator-credential.ts +++ b/server/src/middleware/local-operator-credential.ts @@ -31,6 +31,7 @@ const DEFAULT_MODE: LocalOperatorCredentialMode = "off"; const DIRECT_BROWSER_READ_PATHS = [ /^\/api\/attachments\/[^/]+\/content$/, /^\/api\/assets\/[^/]+\/content$/, + /^\/api\/issues\/[^/]+\/file-resources\/content$/, /^\/api\/heartbeat-runs\/[^/]+\/provider-trace\/download$/, /^\/api\/companies\/[^/]+\/audit\/agent-actions\.csv$/, /^\/api\/plugins\/[^/]+\/bridge\/stream\/[^/]+$/,