mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-04 19:28:46 +01:00
## Thinking Path > - Paperclip helps people manage AI agents at work. > - Native Runner owns execution and task authority. > - Operators need an explicit native Cursor Cloud choice. > - Tools/files need company, task, session and run scope. > - This connects setup and lifecycle to Runner Core. > - Legacy agents retain their selected runtime/history. ## Linked Issues or Issue Description Depends on #18068. Managed-only API placement and API-owned Stop containment are in #18310. Refs #5664, #11803, #17299, and #17471. No duplicate native integration was found. ## What Changed - Add explicit native setup, Test, saved settings and dispatch with no-prompt account/catalog/callback checks. - Scope MCP to company, agent, task, session and run through authenticated HTTPS. Register verified artifacts/work products; preserve unpriced accounting, completion and budgets. - Connect Question/Plan continuation, cold handoff and admitted fresh sessions; recheck waiting admission under the task lock. - Present audited Stop intent while preserving physical containment proof; bound typed Stop metadata. Preserve title edits through preference/navigation readiness. - Select one live/history representation per run to prevent duplicate settled cards. Integrate upstream task/read-state/retry/schema contracts and repair two test fixtures. ## Verification Core #18068 merged normally as `3910352c923a`. Product head `5a60f541c982` has passing repository CI/build/browser checks, including required `ci / verify` and `ci / e2e`, plus a fresh exact-head Greptile 5/5 review with zero unresolved threads. Two non-required external app checks remain pending: Paperclip Review is queued waiting for its assigned agent; Superagent Security Scan is reviewing the diff. These are not claimed completed. The normal merge endpoint enforces the repository rules; no policy or status override is used. The dependent Top PR is addressing its fresh deferred-Stop review finding. Product `5a60f541c982` passed 270 UI and 20 selected Cloud/native/disk-full tests, UI/server typechecks, tokens and maps. Top’s clean normal merge passed tokens/maps/diff checks; its matrix is pending. Earlier receipts retain Core’s 47 Rust, 4 compiled-native retirement and 19 settlement controls, normal Runner build, and runtime 9af build/recursive typecheck. Reproduced loading/shutdown CI fixture failures passed 7/7 browser and 121/121 unit tests, including a broken-unsubscribe negative control. No timeout/oracle was relaxed. The actual-parent restack adopts 75 mainline paths, including schema/permission and generic runtime changes, beyond the prior two fixture repairs and client projection fix. The full difference from hosted `9af1a5de42a2` is therefore larger than four files; backend source also differs. The merged config-read checks match Core391, and the Cursor placement/runtime/relay/selection modules match frozen9af; selected affected regressions pass. Paid proof keeps its actual 9af source/image identity. The separately tested live/history card fix is not claimed deployed on that host. On 9af, original saved settings survived reopening and fresh no-prompt Test authenticated catalog/model/binding; no new Save is claimed. Fresh Linux admission passed. With `claude-sonnet-4-5`, Artifact downloaded exact 27 bytes and matched 121 canonical identities in complete S3-served history. First Stop’s strict quiet FAILED on a 10.373-second gap despite independent cancellation/no late artifact. One targeted unchanged-sampler retry retained all 24 samples: 35.076 seconds quiet / maximum gap 4.584 seconds, 67 ordered canonical identities, and separate CANCELLED/artifact-absent status after the original 180-second deadline. The pre-reload duplicate settled card is disclosed. Exact-ID cleanup for the three new provider agents is awaiting authorization, so full grades and the fresh Artifact’s post-cleanup download remain blocked. A historical deleted-provider artifact was newly downloaded on 9af; original F226 Question/Plan/reconnect and cleanup proof keep their identities. Retained failures: stale fixture 132/133; E8 48/135 with 87 reset-hook failures; Mac 17 SQL failures/skips; earlier title/startup/custody/Stop/deletion failures with unknown causes/bounded recoveries; `dea023` Stop’s warning/50 duplicate identities; pre-repair ACK and original Core CI failures. WSP’s 251-assertion, 7/8-suite attempt failed physical PostgreSQL teardown; the unchanged wrapper rerun passed 128. Retry alone establishes no cause or full local-suite pass. All paid attempts remain recorded; vendor dollar cost is UNKNOWN. ## Risks Experimental: Cursor independently acknowledges neither the effective model nor instruction digest before the first prompt. Explicit values are submitted and checked through behavior; unpriced provider dollar cost stays UNKNOWN. Callbacks need authenticated reachable HTTPS. Scope, revocation, budgets, completion and cleanup remain authoritative. Operator Stop intent is separate from physical containment. Saved legacy agents retain their selected runtime. Prior shared title-save/deletion failures remain disclosed. ## Model Used OpenAI Codex, GPT-6 family, assisted with reasoning, repository tools, code execution, browser verification, and delegated code review. The serving model’s exact API ID and context window are not exposed. No value is inferred from the model catalog. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used and the limits of available model metadata - [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 linked public issues or described the issue in this PR - [x] I have not referenced internal or instance-local Paperclip issues or links - [x] My branch describes the change and contains no internal ticket ID - [x] I have run the scoped local tests reported above; pending gates are stated separately - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation - [x] I have considered and documented the risks - [x] All required CI gates pass on the current head - [x] Fresh Greptile is 5/5 with no unresolved findings on the current head - [x] I will address all reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
132 lines
8.0 KiB
TypeScript
132 lines
8.0 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { assertInterruptedChat, prepareChatBrief, publishChatBrief } from "./chat-stories.js";
|
|
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { execFile } from "node:child_process";
|
|
import { promisify } from "node:util";
|
|
import { runnerMatrix } from "./catalog.js";
|
|
import { buildRunnerE2EProcessEnvironment } from "./harness-env.js";
|
|
|
|
vi.mock("node:fs/promises", async importOriginal => {
|
|
const actual = await importOriginal<typeof import("node:fs/promises")>();
|
|
return { ...actual, writeFile: vi.fn(actual.writeFile) };
|
|
});
|
|
|
|
const run = { id: "run", companyId: "company", agentId: "agent", status: "succeeded", runtimeMode: "native", contextSnapshot: { issueId: "chat" } };
|
|
const valid = {
|
|
first: "Read the brief", followup: "Change the launch day", reference: "BRIEF123", marker: "UPDATED123", issueId: "chat",
|
|
boundaryRun: { ...run, status: "running" }, activeAtFollowup: { ...run, status: "running" },
|
|
comments: [{ id: "first", body: "Read the brief" }, { id: "followup", body: "Change the launch day" },
|
|
{ id: "answer", authorAgentId: "agent", createdByRunId: "run", body: "BRIEF123 UPDATED123" }],
|
|
runs: [run], revisedPlan: JSON.stringify({ launchDay: "Friday", reference: "BRIEF123", revision: "UPDATED123" }),
|
|
};
|
|
|
|
describe("active chat follow-up oracle", () => {
|
|
it("creates the missing fixture directory and waits for the host-supplied brief", async () => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "chat-brief-test-"));
|
|
try {
|
|
const { gate, ready, scriptPath } = await prepareChatBrief(path.join(root, "new workspace"), "fixture");
|
|
const command = promisify(execFile)(process.execPath, [scriptPath], { timeout: 5_000 });
|
|
try {
|
|
await expect.poll(() => readFile(ready, "utf8").catch(() => "")).toBe("waiting");
|
|
} finally {
|
|
await publishChatBrief(gate, "BRIEF fixture result");
|
|
expect((await command).stdout.trim()).toBe("BRIEF fixture result");
|
|
}
|
|
} finally {
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
it("accepts either steering or one queued successor, with the saved correction", () => {
|
|
expect(() => assertInterruptedChat(valid)).not.toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, runs: [run, { ...run, id: "successor" }], comments: [...valid.comments.slice(0, 2), { ...valid.comments[2]!, createdByRunId: "successor" }] })).not.toThrow();
|
|
});
|
|
it("rejects follow-ups sent after the active boundary", () => {
|
|
expect(() => assertInterruptedChat({ ...valid, boundaryRun: run })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, activeAtFollowup: run })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, activeAtFollowup: { ...valid.activeAtFollowup, id: "other" } })).toThrow();
|
|
});
|
|
it("rejects lost or duplicated input, missing file evidence, and stale plans", () => {
|
|
expect(() => assertInterruptedChat({ ...valid, comments: [...valid.comments, { ...valid.comments[2]!, id: "duplicate-reply" }] })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, comments: [...valid.comments.slice(0, 2), { ...valid.comments[2]!, createdByRunId: "unrelated" }] })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, comments: valid.comments.filter(c => c.id !== "followup") })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, comments: [...valid.comments, { id: "duplicate", body: valid.followup }] })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, comments: [...valid.comments.slice(0, 2), { id: "answer", authorAgentId: "agent", body: "UPDATED123" }] })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, revisedPlan: valid.revisedPlan.replace("Friday", "Monday") })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, revisedPlan: "The updated plan is saved." })).toThrow();
|
|
});
|
|
it("rejects failed, unfinished, duplicated, or unrelated execution", () => {
|
|
for (const status of ["running", "queued", "failed", "cancelled"])
|
|
expect(() => assertInterruptedChat({ ...valid, runs: [{ ...run, status }] })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, runs: [] })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, runs: [run, run, run] })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, runs: [run, run] })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, runs: [{ ...run, id: "other" }] })).toThrow();
|
|
expect(() => assertInterruptedChat({ ...valid, runs: [{ ...run, contextSnapshot: { issueId: "other" } }] })).toThrow();
|
|
});
|
|
it("keeps setup and interruption stories native, local, opt-in, and outside API-tool overrides", () => {
|
|
const cells = runnerMatrix.filter(cell => cell.suite.id === "agent-chat-stories");
|
|
expect(cells).toHaveLength(6);
|
|
for (const cell of cells) {
|
|
expect(cell.suite.manualOnly).toBe(true);
|
|
expect(cell.profile.generation).toBe("native");
|
|
expect(cell.environment.id).toBe("local");
|
|
expect(buildRunnerE2EProcessEnvironment({}, [cell]).PAPERCLIP_RUNNER_API_TOOLS_ENABLED).toBeUndefined();
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
describe("bounded chat brief fixture", () => {
|
|
it("publishes the complete brief atomically while a real worker is waiting", async () => {
|
|
const directory = await mkdtemp(path.join(tmpdir(), "chat-brief-atomic-"));
|
|
const actual = await vi.importActual<typeof import("node:fs/promises")>("node:fs/promises");
|
|
let releaseWrite!: () => void;
|
|
const pausedWrite = new Promise<void>(resolve => { releaseWrite = resolve; });
|
|
let exposedEmptyWrite!: (file: Parameters<typeof writeFile>[0]) => void;
|
|
const emptyWrite = new Promise<Parameters<typeof writeFile>[0]>(resolve => { exposedEmptyWrite = resolve; });
|
|
let running: Promise<{ stdout: string; stderr: string }> | undefined;
|
|
let publishing: Promise<void> | undefined;
|
|
try {
|
|
const brief = await prepareChatBrief(directory, "atomic", 5_000);
|
|
running = promisify(execFile)(process.execPath, [brief.scriptPath]);
|
|
await expect.poll(() => readFile(brief.ready, "utf8").catch(() => "")).toBe("waiting");
|
|
vi.mocked(writeFile).mockImplementationOnce(async (file, data, options) => {
|
|
await actual.writeFile(file, "");
|
|
exposedEmptyWrite(file);
|
|
await pausedWrite;
|
|
await actual.writeFile(file, data, typeof options === "object" ? { ...options, flag: "w" } : options);
|
|
});
|
|
publishing = publishChatBrief(brief.gate, "A complete multiword brief.");
|
|
const stagedFile = await emptyWrite;
|
|
expect(await readFile(stagedFile, "utf8")).toBe("");
|
|
await expect(readFile(brief.gate, "utf8")).rejects.toHaveProperty("code", "ENOENT");
|
|
releaseWrite();
|
|
await publishing;
|
|
expect((await running).stdout.trim()).toBe("A complete multiword brief.");
|
|
} finally {
|
|
releaseWrite();
|
|
await publishing;
|
|
await running?.catch(() => undefined);
|
|
vi.mocked(writeFile).mockImplementation(actual.writeFile);
|
|
await rm(directory, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
it("releases a waiting worker and rejects an unbounded wait", async () => {
|
|
const directory = await mkdtemp(path.join(tmpdir(), "chat-brief-bounded-"));
|
|
try {
|
|
for (const timeout of [0, -1, Infinity, 300_001])
|
|
await expect(prepareChatBrief(directory, "invalid", timeout)).rejects.toThrow("bounded");
|
|
const brief = await prepareChatBrief(directory, "release", 2_000);
|
|
const running = promisify(execFile)(process.execPath, [brief.scriptPath]);
|
|
await expect.poll(() => readFile(brief.ready, "utf8").catch(() => "")).toBe("waiting");
|
|
await publishChatBrief(brief.gate, "Meet at half past ten.");
|
|
expect((await running).stdout.trim()).toBe("Meet at half past ten.");
|
|
const expires = await prepareChatBrief(directory, "expires", 1);
|
|
await expect(promisify(execFile)(process.execPath, [expires.scriptPath])).rejects.toMatchObject({ code: 1 });
|
|
} finally { await rm(directory, { recursive: true, force: true }); }
|
|
});
|
|
});
|