mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 14:35:17 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The restart chaos harness proves that real agent tasks survive control-plane restarts > - Its coding workloads run in a tiny chaoscli fixture. Real work happens in large repositories, where workspace setup, copy and restore cost more and fail differently > - The campaign asks for real coding tasks in a fresh Paperclip clone, run under restarts > - This pull request adds the smallest support for that: a `--workspace-repo` option and an R1 workload > - The benefit is restart coverage for code changes in a real repository, graded by running the agent's own test and a hidden case ## Linked Issues or Issue Description Refs #20071, #20089 **What is missing?** The harness can only seed the generated chaoscli fixture as the project workspace. There is no way to run restart chaos against a code change in a real repository. **Expected behavior** An operator can name a git repository. The harness clones it fresh as the workspace, and a workload asks for a real code change in it with an oracle that runs the result. ## What Changed - `--workspace-repo <git repository>`: `seedChaosLab` clones it (shallow, from committed HEAD, `--no-hardlinks`) as the project workspace instead of the chaoscli fixture. Local only. - R1 workload: the agent adds `packages/shared/src/chaos/slug-<nonce>.ts` with `chaosSlug` and a `node:test` file, and runs it. The nonce names keep concurrent tasks from colliding in one repository. - The R1 oracle runs the agent's test with `node --test` and a hidden case against the module through Node's type stripping. - Collect commands can take an `argv` function of the nonce. - Config rules: R1 and `--workspace-repo` go together. B1 and B5 (which need the chaoscli fixture) do not combine with it. R1 is not a default workload. - README section "Code change in a real repository". ## Verification - `npx vitest run` in `tests/restart-chaos`: 195 passed, including new tests for the config pairing, R1 grading with the nonce argv, and a shallow clone of a fixture repository. - `node scripts/typecheck-test-projects.mjs tests/restart-chaos`: clean. - I checked the oracle commands by hand on Node 26: `node --test` on a `.ts` test and `node --input-type=module -e 'import … from "./…ts"'` both work. - A live R1 wave against a Paperclip clone runs after the current chaos wave frees the harness slot. Its result will be posted here before merge. ## Risks - A shallow clone of a large repository adds seconds to wave seeding. That is one clone per wave. - The oracle uses Node's built-in type stripping. A runtime without it fails `node_test` and `hidden_case`, which shows as an oracle failure, not a false pass. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code execution in Claude Code. ## 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 - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
4.9 KiB
TypeScript
74 lines
4.9 KiB
TypeScript
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { oracleSandboxProfile, runOracleCommand } from "./oracle-sandbox.js";
|
|
import { createFixtureRepository } from "./seed.js";
|
|
|
|
const directories: string[] = [];
|
|
afterEach(async () => { await Promise.all(directories.splice(0).map(directory => rm(directory, { recursive: true, force: true }))); });
|
|
const temp = async (prefix: string) => { const directory = await mkdtemp(path.join(os.tmpdir(), prefix)); directories.push(directory); return directory; };
|
|
|
|
describe("oracle sandbox", () => {
|
|
it("denies the protected roots and re-allows the workspace", () => {
|
|
const profile = oracleSandboxProfile({ workspace: "/w", scratch: "/s", protectedRoots: ["/Users/me"] });
|
|
expect(profile).toContain('(deny file-read* (subpath "/Users/me"))');
|
|
expect(profile).toContain("(deny network*)");
|
|
expect(profile.indexOf('(allow file-read* (subpath "/w")')).toBeGreaterThan(profile.indexOf("(deny file-read*"));
|
|
});
|
|
|
|
it("re-allows only the named files, such as the node executable, never a directory under a protected root", () => {
|
|
const profile = oracleSandboxProfile({ workspace: "/w", scratch: "/s", protectedRoots: ["/Users/me"], readableFiles: ["/Users/me/bin/node"] });
|
|
expect(profile.indexOf('(allow file-read* (literal "/Users/me/bin/node"))')).toBeGreaterThan(profile.indexOf('(deny file-read* (subpath "/Users/me"))'));
|
|
expect(profile).not.toContain('(allow file-read* (subpath "/Users/me")');
|
|
expect(profile).not.toContain('(allow file-read* (subpath "/Users/me/bin")');
|
|
});
|
|
|
|
it("refuses to run unsandboxed on other platforms unless allowed", async () => {
|
|
const result = await runOracleCommand(["true"], "/", { platform: "linux" });
|
|
expect(result.exitCode).toBeNull();
|
|
expect(result.stderr).toMatch(/refused/);
|
|
});
|
|
|
|
it.runIf(process.platform === "darwin")("protects an instance root that contains the workspace, except the workspace itself", async () => {
|
|
const instanceRoot = await temp("restart-chaos-instance-");
|
|
await writeFile(path.join(instanceRoot, "master.key"), "canary-master-key\n");
|
|
const workspace = path.join(instanceRoot, "fixtures", "chaos-sandbox");
|
|
await createFixtureRepository(workspace, 1);
|
|
const leak = await runOracleCommand(["/bin/cat", path.join(instanceRoot, "master.key")], workspace, { protectedRoots: [instanceRoot] });
|
|
expect(leak.stdout).not.toContain("canary-master-key");
|
|
const greet = await runOracleCommand(["python3", "-m", "chaoscli", "greet", "chaos"], workspace, { protectedRoots: [instanceRoot] });
|
|
expect(greet.stdout.trim()).toBe("hello, chaos");
|
|
}, 60_000);
|
|
|
|
it.runIf(process.platform === "darwin")("lets node resolve modules in a workspace inside a protected root without exposing its contents", async () => {
|
|
const instanceRoot = await temp("restart-chaos-instance-");
|
|
await writeFile(path.join(instanceRoot, "master.key"), "canary-master-key\n");
|
|
const workspace = path.join(instanceRoot, "fixtures", "workspace-repo");
|
|
await mkdir(workspace, { recursive: true });
|
|
await writeFile(path.join(workspace, "slug.ts"), "export const slug = (value: string): string => value.toLowerCase();\n");
|
|
const run = await runOracleCommand([process.execPath, "--input-type=module", "-e", "import { slug } from \"./slug.ts\"; console.log(slug(\"OK\"));"],
|
|
workspace, { protectedRoots: [instanceRoot], readableFiles: [process.execPath] });
|
|
expect(run).toMatchObject({ exitCode: 0 });
|
|
expect(run.stdout.trim()).toBe("ok");
|
|
const leak = await runOracleCommand([process.execPath, "-e", `console.log(require("node:fs").readFileSync(${JSON.stringify(path.join(instanceRoot, "master.key"))}, "utf8"))`],
|
|
workspace, { protectedRoots: [instanceRoot], readableFiles: [process.execPath] });
|
|
expect(leak.stdout).not.toContain("canary-master-key");
|
|
const listing = await runOracleCommand(["/bin/ls", instanceRoot], workspace, { protectedRoots: [instanceRoot] });
|
|
expect(listing.stdout).not.toContain("master.key");
|
|
}, 60_000);
|
|
|
|
it.runIf(process.platform === "darwin")("keeps agent code away from protected files but runs the fixture tests", async () => {
|
|
const secretRoot = await temp("restart-chaos-secret-");
|
|
await writeFile(path.join(secretRoot, ".secrets"), "OPENAI_API_KEY=canary-value\n");
|
|
const workspace = await temp("restart-chaos-ws-");
|
|
await createFixtureRepository(workspace, 1);
|
|
const leak = await runOracleCommand(["/bin/cat", path.join(secretRoot, ".secrets")], workspace, { protectedRoots: [secretRoot] });
|
|
expect(leak.exitCode).not.toBe(0);
|
|
expect(leak.stdout).not.toContain("canary-value");
|
|
const greet = await runOracleCommand(["python3", "-m", "chaoscli", "greet", "chaos"], workspace, { protectedRoots: [secretRoot] });
|
|
expect(greet).toMatchObject({ exitCode: 0 });
|
|
expect(greet.stdout.trim()).toBe("hello, chaos");
|
|
}, 60_000);
|
|
});
|