mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-02 19:08:33 +01:00
Document computer routes and restore experimental setting order
This commit is contained in:
1 parent
1c4d403044
commit
dd8a5c38af
5 files changed
+187
-133
No files matched your search
@@ -38,6 +38,7 @@ const apiPrefixes: Record<string, string> = {
|
||||
"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,
|
||||
|
||||
@@ -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<string, unknown>) => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
@@ -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<string, unknown>) => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user