fix(local): open the sign-in link only for local_trusted boards and allow workspace file downloads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DottaandClaude Opus 5.5 committed 2026-11-14 14:52:13 -06:00
1 parent 573f006499
commit 8cb171bf69
4 files changed
+42 -6

No files matched your search

+30
View File
@@ -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,
+6 -4
View File
@@ -31,7 +31,7 @@ export type OnboardServiceOptions = {
type EnsureShimResult = { ok: boolean; installedNow: boolean; reason?: string };
type OnboardServiceDashboardConfig = {
auth: Pick<PaperclipConfig["auth"], "baseUrlMode" | "publicBaseUrl">;
server: Pick<PaperclipConfig["server"], "host" | "port">;
server: Pick<PaperclipConfig["server"], "host" | "port"> & Partial<Pick<PaperclipConfig["server"], "deploymentMode">>;
};
type OnboardServiceDashboardDependencies = {
@@ -75,8 +75,7 @@ async function waitUntilDashboardReady(timeoutMs = 60_000): Promise<PaperclipRun
const defaultDashboardDependencies: OnboardServiceDashboardDependencies = {
isInteractive: () => 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.`);
@@ -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 () => {
@@ -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\/[^/]+$/,