From dd8a5c38af7c27eb78982d57b8a2838e8d55a7f5 Mon Sep 17 00:00:00 2001 From: Dotta Date: Sat, 10 Oct 2026 09:02:06 -0500 Subject: [PATCH] Document computer routes and restore experimental setting order --- server/src/__tests__/openapi-routes.test.ts | 18 +++ .../modules/computers/adapters/boat.test.ts | 123 +++++++++++++++++- .../computers/adapters/remote-program.test.ts | 121 ----------------- server/src/routes/openapi.ts | 36 +++++ ui/src/pages/InstanceExperimentalSettings.tsx | 22 ++-- 5 files changed, 187 insertions(+), 133 deletions(-) delete mode 100644 server/src/modules/computers/adapters/remote-program.test.ts diff --git a/server/src/__tests__/openapi-routes.test.ts b/server/src/__tests__/openapi-routes.test.ts index 2518a63df53..3c276c945b6 100644 --- a/server/src/__tests__/openapi-routes.test.ts +++ b/server/src/__tests__/openapi-routes.test.ts @@ -38,6 +38,7 @@ const apiPrefixes: Record = { "cloud.ts": "/api/cloud", "customer-success.ts": "/api/customer-success/v1", "companies.ts": "/api/companies", + "computers.ts": "/api", "company-skills.ts": "/api", "company-skill-policy.ts": "/api", "connection-intents.ts": "/api", @@ -864,6 +865,23 @@ describe("openapi routes", () => { expect(decision.requestBody.content["application/json"].schema.required).toEqual(expect.arrayContaining(["approve", "approvalCode"])); }); + it("documents board-only computer ownership and private viewer responses", () => { + const { spec } = loadSpecRoutes(); + for (const suffix of ["", "/connect", "/presence", "/disconnect", "/preview"]) { + const operation = spec.paths[`/api/issues/{issueId}/computer${suffix}`][suffix ? "post" : "get"]; + expect(operation["x-paperclip-authorization"]).toEqual({ actor: "board" }); + expect(operation.responses["404"]).toBeDefined(); + } + const viewer = spec.paths["/api/issues/{issueId}/computer/connect"].post; + expect(viewer.responses["200"].headers["Cache-Control"].schema.enum).toEqual(["no-store"]); + expect(viewer.responses["200"].content["application/json"].schema.required).toContain("owner"); + const preview = spec.paths["/api/issues/{issueId}/computer/preview"].post; + expect(preview.requestBody.content["application/json"].schema.properties.owner).toBeUndefined(); + const disconnect = spec.paths["/api/issues/{issueId}/computer/disconnect"].post; + expect(disconnect.responses["204"]).toBeDefined(); + expect(disconnect.description).toContain("disabled"); + }); + it("covers the mounted server routes exactly", () => { const { routes: actualRoutes, diff --git a/server/src/modules/computers/adapters/boat.test.ts b/server/src/modules/computers/adapters/boat.test.ts index c74d40797b2..5cec21e4066 100644 --- a/server/src/modules/computers/adapters/boat.test.ts +++ b/server/src/modules/computers/adapters/boat.test.ts @@ -1,4 +1,16 @@ -import { describe, it, expect, vi } from "vitest"; +import { + mkdtempSync, + realpathSync, + rmSync, + symlinkSync, + writeFileSync, + mkdirSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { spawnSync } from "node:child_process"; +import { remoteProgram } from "./remote-program.js"; +import { afterEach, describe, it, expect, vi } from "vitest"; import { boatBackend } from "./boat.js"; import type { ComputerRecord } from "../domain/ledger.js"; const record: ComputerRecord = { @@ -94,3 +106,112 @@ describe("Boat transport validation", () => { ).rejects.toMatchObject({ code: "provider_error" }); }); }); + +const roots: string[] = []; +function fixture() { + const temp = realpathSync(mkdtempSync(join(tmpdir(), "computer-files-"))); + roots.push(temp); + const root = join(temp, "home"); + const call = (input: Record) => { + const result = spawnSync( + "python3", + ["-c", remoteProgram.replaceAll("/home/user/paperclip/", `${temp}/`)], + { input: JSON.stringify({ ...input, root }), encoding: "utf8" }, + ); + if (result.status !== 0) throw new Error(result.stderr); + return JSON.parse(result.stdout); + }; + return { root, temp, call }; +} +afterEach(() => { + for (const root of roots.splice(0)) + rmSync(root, { recursive: true, force: true }); +}); +describe("confined computer files", () => { + it("seeds absent home only and preserves existing content", () => { + const f = fixture(); + expect( + f.call({ + action: "seed", + files: { "nested/one": Buffer.from("first").toString("base64") }, + }), + ).toEqual({ seeded: true }); + expect( + f.call({ + action: "seed", + files: { "nested/one": Buffer.from("overwrite").toString("base64") }, + }), + ).toEqual({ seeded: false }); + expect( + Buffer.from( + f.call({ action: "read", path: "nested/one" }).base64, + "base64", + ).toString(), + ).toBe("first"); + }); + it("rejects traversal, symlink escapes, and oversized reads", () => { + const f = fixture(); + f.call({ + action: "seed", + files: { ok: Buffer.from("12345").toString("base64") }, + }); + mkdirSync(join(f.temp, "outside")); + writeFileSync(join(f.temp, "outside", "secret"), "private"); + symlinkSync(join(f.temp, "outside"), join(f.root, "escape")); + expect(f.call({ action: "read", path: "../outside/secret" })).toEqual({ + error: "invalid", + }); + expect(f.call({ action: "read", path: "escape/secret" })).toEqual({ + error: "invalid", + }); + expect(f.call({ action: "read", path: "ok", maxBytes: 4 })).toEqual({ + error: "invalid", + }); + }); + it("rejects stale edits and uses no-clobber move semantics", () => { + const f = fixture(); + f.call({ action: "seed", files: {} }); + const first = f.call({ + action: "write", + path: "file", + expectedSha256: null, + base64: Buffer.from("one").toString("base64"), + }); + const second = f.call({ + action: "write", + path: "file", + expectedSha256: first.sha256, + base64: Buffer.from("two").toString("base64"), + }); + expect( + f.call({ + action: "write", + path: "file", + expectedSha256: first.sha256, + base64: "", + }), + ).toEqual({ error: "conflict" }); + expect( + f.call({ + action: "move", + path: "file", + to: "other", + expectedSha256: second.sha256, + }), + ).toEqual({ sha256: second.sha256 }); + expect(f.call({ action: "list" }).map((e: any) => e.name)).toEqual([ + "other", + ]); + expect( + f.call({ action: "remove", path: "other", expectedSha256: first.sha256 }), + ).toEqual({ error: "conflict" }); + }); + it("roundtrips binary bytes without interpreting text", () => { + const f = fixture(); + const bytes = Buffer.from([0, 255, 254, 13, 10, 128]); + f.call({ action: "seed", files: { binary: bytes.toString("base64") } }); + expect( + Buffer.from(f.call({ action: "read", path: "binary" }).base64, "base64"), + ).toEqual(bytes); + }); +}); diff --git a/server/src/modules/computers/adapters/remote-program.test.ts b/server/src/modules/computers/adapters/remote-program.test.ts deleted file mode 100644 index 1e2eb853436..00000000000 --- a/server/src/modules/computers/adapters/remote-program.test.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { afterEach, describe, expect, it } from "vitest"; -import { - mkdtempSync, - realpathSync, - rmSync, - symlinkSync, - writeFileSync, - mkdirSync, -} from "node:fs"; -import { tmpdir } from "node:os"; -import { join } from "node:path"; -import { spawnSync } from "node:child_process"; -import { remoteProgram } from "./remote-program.js"; -const roots: string[] = []; -function fixture() { - const temp = realpathSync(mkdtempSync(join(tmpdir(), "computer-files-"))); - roots.push(temp); - const root = join(temp, "home"); - const call = (input: Record) => { - const result = spawnSync( - "python3", - ["-c", remoteProgram.replaceAll("/home/user/paperclip/", `${temp}/`)], - { input: JSON.stringify({ ...input, root }), encoding: "utf8" }, - ); - if (result.status !== 0) throw new Error(result.stderr); - return JSON.parse(result.stdout); - }; - return { root, temp, call }; -} -afterEach(() => { - for (const root of roots.splice(0)) - rmSync(root, { recursive: true, force: true }); -}); -describe("confined computer files", () => { - it("seeds absent home only and preserves existing content", () => { - const f = fixture(); - expect( - f.call({ - action: "seed", - files: { "nested/one": Buffer.from("first").toString("base64") }, - }), - ).toEqual({ seeded: true }); - expect( - f.call({ - action: "seed", - files: { "nested/one": Buffer.from("overwrite").toString("base64") }, - }), - ).toEqual({ seeded: false }); - expect( - Buffer.from( - f.call({ action: "read", path: "nested/one" }).base64, - "base64", - ).toString(), - ).toBe("first"); - }); - it("rejects traversal, symlink escapes, and oversized reads", () => { - const f = fixture(); - f.call({ - action: "seed", - files: { ok: Buffer.from("12345").toString("base64") }, - }); - mkdirSync(join(f.temp, "outside")); - writeFileSync(join(f.temp, "outside", "secret"), "private"); - symlinkSync(join(f.temp, "outside"), join(f.root, "escape")); - expect(f.call({ action: "read", path: "../outside/secret" })).toEqual({ - error: "invalid", - }); - expect(f.call({ action: "read", path: "escape/secret" })).toEqual({ - error: "invalid", - }); - expect(f.call({ action: "read", path: "ok", maxBytes: 4 })).toEqual({ - error: "invalid", - }); - }); - it("rejects stale edits and uses no-clobber move semantics", () => { - const f = fixture(); - f.call({ action: "seed", files: {} }); - const first = f.call({ - action: "write", - path: "file", - expectedSha256: null, - base64: Buffer.from("one").toString("base64"), - }); - const second = f.call({ - action: "write", - path: "file", - expectedSha256: first.sha256, - base64: Buffer.from("two").toString("base64"), - }); - expect( - f.call({ - action: "write", - path: "file", - expectedSha256: first.sha256, - base64: "", - }), - ).toEqual({ error: "conflict" }); - expect( - f.call({ - action: "move", - path: "file", - to: "other", - expectedSha256: second.sha256, - }), - ).toEqual({ sha256: second.sha256 }); - expect(f.call({ action: "list" }).map((e: any) => e.name)).toEqual([ - "other", - ]); - expect( - f.call({ action: "remove", path: "other", expectedSha256: first.sha256 }), - ).toEqual({ error: "conflict" }); - }); - it("roundtrips binary bytes without interpreting text", () => { - const f = fixture(); - const bytes = Buffer.from([0, 255, 254, 13, 10, 128]); - f.call({ action: "seed", files: { binary: bytes.toString("base64") } }); - expect( - Buffer.from(f.call({ action: "read", path: "binary" }).base64, "base64"), - ).toEqual(bytes); - }); -}); diff --git a/server/src/routes/openapi.ts b/server/src/routes/openapi.ts index b7378b24539..6fee8f46d70 100644 --- a/server/src/routes/openapi.ts +++ b/server/src/routes/openapi.ts @@ -1367,11 +1367,27 @@ const browserUseOperations = [ ["put", "/api/companies/{companyId}/browser-use-cloud/grants/{grantId}/settings", "Update browser credential settings", browserUseSettingsSchema], ] as const; +const computerOwnerSchema = z.object({ + computerId: z.string().uuid(), ownerId: z.string().uuid(), generation: z.number().int().positive(), +}).strict(); +const computerScopeSchema = z.object({ environmentId: z.string().uuid() }).strict(); +const computerPresenceSchema = computerScopeSchema.extend({ owner: computerOwnerSchema }); +const computerViewerSchema = z.object({ viewerUrl: z.string().url(), expiresAt: z.string().datetime(), owner: computerOwnerSchema }); +const computerOperations = [ + ["get", "/api/issues/{issueId}/computer", "Read the task computer selection", undefined, + z.object({ environmentId: z.string().uuid(), name: z.string() }).nullable()], + ["post", "/api/issues/{issueId}/computer/connect", "Connect to the shared computer desktop", computerScopeSchema, computerViewerSchema], + ["post", "/api/issues/{issueId}/computer/presence", "Refresh an owned computer viewer", computerPresenceSchema, computerViewerSchema], + ["post", "/api/issues/{issueId}/computer/disconnect", "Disconnect an owned computer viewer", computerPresenceSchema, undefined], + ["post", "/api/issues/{issueId}/computer/preview", "Open a task-owned computer port", computerScopeSchema.extend({ port: z.number().int().min(1024).max(65535) }), z.object({ url: z.string().url() })], +] as const; + const BOARD_ONLY_OPERATIONS = new Set([ "GET /api/companies/{companyId}/decision-model", "PUT /api/companies/{companyId}/decision-model", "POST /api/companies/{companyId}/decision-model/test", ...browserUseOperations.map(([method, path]) => `${method.toUpperCase()} ${path}`), + ...computerOperations.map(([method, path]) => `${method.toUpperCase()} ${path}`), "GET /api/companies/{companyId}/ai-connections", "POST /api/companies/{companyId}/ai-connections", "POST /api/companies/{companyId}/ai-connections/local", @@ -2232,6 +2248,26 @@ for (const [method, path, summary, body] of browserUseOperations) { }); } +for (const [method, path, summary, body, response] of computerOperations) { + const success = { + ...(response ? r.ok(response) : r.noContent), + headers: { + "Cache-Control": { schema: { type: "string", enum: ["no-store"] } }, + "Referrer-Policy": { schema: { type: "string", enum: ["no-referrer"] } }, + }, + }; + registry.registerPath({ + method, path, summary, tags: ["Computers"], + description: "Experimental Boat environment operation. Requires board access to the task and its company-bound computer. Viewer URLs are private credentials. Presence refresh cannot extend the original viewer deadline. Disconnect remains available when the experiment is disabled. Preview resolves ownership from the task lease and rejects reserved runner ports.", + request: { params: z.object({ issueId: z.string().uuid() }), ...(body ? { body: jsonBody(body) } : {}) }, + responses: { + [response ? 200 : 204]: success, + 400: r.badRequest, 401: r.unauthorized, 403: r.forbidden, 404: r.notFound, + 409: r.conflict, 422: r.unprocessable, 502: { description: "Computer provider request failed" }, + }, + }); +} + // Voice endpoints accept current authenticated board sessions (or local implicit board), // never agent keys or board API keys. Provider callbacks use signatures and are // intentionally documented separately from this board API contract. diff --git a/ui/src/pages/InstanceExperimentalSettings.tsx b/ui/src/pages/InstanceExperimentalSettings.tsx index d89f6a7fa14..7bc7cb1f086 100644 --- a/ui/src/pages/InstanceExperimentalSettings.tsx +++ b/ui/src/pages/InstanceExperimentalSettings.tsx @@ -608,6 +608,17 @@ export function InstanceExperimentalSettings() { ariaLabel="Toggle guarded dev-server auto-restart" /> + toggleMutation.mutate({ enableBoatEnvironments: checked })} + disabled={toggleMutation.isPending} + settingKey="enableBoatEnvironments" + managed={managedKeys.enableBoatEnvironments} + ariaLabel="Toggle Boat environments" + /> + - toggleMutation.mutate({ enableBoatEnvironments: checked })} - disabled={toggleMutation.isPending} - settingKey="enableBoatEnvironments" - managed={managedKeys.enableBoatEnvironments} - ariaLabel="Toggle Boat environments" - /> -