mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 23:56:43 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Issue reviews use thread confirmations to record explicit verdicts > - The server allowed users to resolve review confirmations but rejected all agent actors > - This one-way rule prevented an eligible agent reviewer from completing a review > - The existing review policy already defines which actor can submit a verdict > - This pull request applies that policy to agent confirmation verdicts on writable issues > - The benefit is a consistent review gate for users and agents with preserved audit attribution ## Linked Issues or Issue Description - Builds on: #10931 (merged into master before this PR) - Refs #8617 ## What Changed - Allow eligible agents to accept or reject pending review confirmations on issues they can write. - Allow a creator agent to withdraw its own pending review confirmation when the review policy permits it. - Reuse the review verdict policy check for users and agents. - Require an explicit, same-run review-confirmation binding so unrelated board-only confirmations stay protected. - Preserve board-only tool action confirmations and existing user attribution. - Add route and service tests for agent accept, reject, withdrawal, human-only denial, and user attribution. ## Verification - `pnpm exec vitest run packages/shared/src/validators/issue.test.ts server/src/__tests__/issue-execution-policy-routes.test.ts server/src/__tests__/issue-review-policy.test.ts server/src/__tests__/issue-thread-interaction-routes.test.ts server/src/__tests__/issue-thread-interactions-service.test.ts server/src/__tests__/issue-stalled-review-decision-routes.test.ts` (256 passed after rebasing onto master and the atomic binding fix) - `pnpm --filter @paperclipai/shared typecheck` - `pnpm --filter @paperclipai/server typecheck` - `pnpm -r typecheck` - `env -u AWS_ACCESS_KEY_ID -u AWS_SECRET_ACCESS_KEY pnpm test:run` - `pnpm build` ## Risks - The change expands who can resolve pending review confirmations. The existing issue write checks and review policy limit this access. - Tool action confirmations remain board-only. - The pull request depends on the review policy helper from #10931, which is now merged into master. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. The roadmap marks Agent Reviews and Approvals as shipped. This pull request fixes a narrow server behavior gap in that shipped capability. ## Model Used - OpenAI Codex, model `gpt-5.6-sol`, with reasoning, tool use, and code execution. The runtime does not expose the context window size. ## 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 - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
221 lines
7.4 KiB
TypeScript
221 lines
7.4 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
import { activityLog, agents, companies, createDb, issues, type Db } from "@paperclipai/db";
|
|
import { HttpError } from "../errors.js";
|
|
import {
|
|
assertIssueReviewVerdictActorAllowed,
|
|
isIssueReviewVerdictInteraction,
|
|
} from "../services/issue-review-policy.js";
|
|
import {
|
|
getEmbeddedPostgresTestSupport,
|
|
startEmbeddedPostgresTestDatabase,
|
|
} from "./helpers/embedded-postgres.js";
|
|
|
|
const embeddedPostgresSupport = await getEmbeddedPostgresTestSupport();
|
|
const describeEmbeddedPostgres = embeddedPostgresSupport.supported ? describe : describe.skip;
|
|
|
|
describeEmbeddedPostgres("issue review verdict policy", () => {
|
|
let db!: ReturnType<typeof createDb>;
|
|
let tempDb: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>> | null = null;
|
|
|
|
beforeAll(async () => {
|
|
tempDb = await startEmbeddedPostgresTestDatabase("paperclip-issue-review-policy-");
|
|
db = createDb(tempDb.connectionString);
|
|
}, 30_000);
|
|
|
|
afterEach(async () => {
|
|
await db.delete(activityLog);
|
|
await db.delete(issues);
|
|
await db.delete(agents);
|
|
await db.delete(companies);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await tempDb?.cleanup();
|
|
});
|
|
|
|
async function seedReview(policy: "not_creator" | "human_only") {
|
|
const companyId = randomUUID();
|
|
const requesterAgentId = randomUUID();
|
|
const peerAgentId = randomUUID();
|
|
const issueId = randomUUID();
|
|
await db.insert(companies).values({
|
|
id: companyId,
|
|
name: "Review Policy Company",
|
|
issuePrefix: "RPC",
|
|
requireBoardApprovalForNewAgents: false,
|
|
});
|
|
await db.insert(agents).values([
|
|
{
|
|
id: requesterAgentId,
|
|
companyId,
|
|
name: "Requester",
|
|
role: "engineer",
|
|
status: "idle",
|
|
adapterType: "codex_local",
|
|
adapterConfig: {},
|
|
runtimeConfig: {},
|
|
permissions: {},
|
|
},
|
|
{
|
|
id: peerAgentId,
|
|
companyId,
|
|
name: "Peer reviewer",
|
|
role: "engineer",
|
|
status: "idle",
|
|
adapterType: "codex_local",
|
|
adapterConfig: {},
|
|
runtimeConfig: {},
|
|
permissions: {},
|
|
},
|
|
]);
|
|
const [issue] = await db.insert(issues).values({
|
|
id: issueId,
|
|
companyId,
|
|
title: "Review this",
|
|
status: "in_review",
|
|
priority: "medium",
|
|
reviewPolicy: policy,
|
|
createdByAgentId: requesterAgentId,
|
|
}).returning();
|
|
return { issue, companyId, requesterAgentId, peerAgentId };
|
|
}
|
|
|
|
it("does no database work for the default anyone policy", async () => {
|
|
const noQueryDb = new Proxy({}, {
|
|
get() {
|
|
throw new Error("default policy must not query");
|
|
},
|
|
}) as Db;
|
|
|
|
await expect(assertIssueReviewVerdictActorAllowed(noQueryDb, {
|
|
issue: { id: randomUUID(), companyId: randomUUID(), reviewPolicy: null },
|
|
actor: { type: "agent", id: randomUUID() },
|
|
})).resolves.toBeUndefined();
|
|
});
|
|
|
|
it("blocks the in-review requester under not_creator and admits another agent", async () => {
|
|
const seeded = await seedReview("not_creator");
|
|
expect(seeded.issue.reviewPolicy).toBe("not_creator");
|
|
await db.insert(activityLog).values({
|
|
companyId: seeded.companyId,
|
|
actorType: "agent",
|
|
actorId: seeded.requesterAgentId,
|
|
agentId: seeded.requesterAgentId,
|
|
action: "issue.updated",
|
|
entityType: "issue",
|
|
entityId: seeded.issue.id,
|
|
details: { status: "in_review", _previous: { status: "in_progress" } },
|
|
});
|
|
|
|
const denied = assertIssueReviewVerdictActorAllowed(db, {
|
|
issue: seeded.issue,
|
|
actor: { type: "agent", id: seeded.requesterAgentId },
|
|
});
|
|
await expect(denied).rejects.toMatchObject<HttpError>({
|
|
status: 403,
|
|
details: expect.objectContaining({
|
|
code: "review_policy_denied",
|
|
policy: "not_creator",
|
|
allowedActor: "writer_other_than_review_requester",
|
|
}),
|
|
});
|
|
await expect(assertIssueReviewVerdictActorAllowed(db, {
|
|
issue: seeded.issue,
|
|
actor: { type: "agent", id: seeded.peerAgentId },
|
|
})).resolves.toBeUndefined();
|
|
});
|
|
|
|
it("ignores later in-review snapshots that did not record a status transition", async () => {
|
|
const seeded = await seedReview("not_creator");
|
|
await db.insert(activityLog).values([
|
|
{
|
|
companyId: seeded.companyId,
|
|
actorType: "agent",
|
|
actorId: seeded.requesterAgentId,
|
|
agentId: seeded.requesterAgentId,
|
|
action: "issue.updated",
|
|
entityType: "issue",
|
|
entityId: seeded.issue.id,
|
|
details: { status: "in_review", _previous: { status: "in_progress" } },
|
|
createdAt: new Date("2026-08-06T00:00:00.000Z"),
|
|
},
|
|
{
|
|
companyId: seeded.companyId,
|
|
actorType: "agent",
|
|
actorId: seeded.peerAgentId,
|
|
agentId: seeded.peerAgentId,
|
|
action: "issue.updated",
|
|
entityType: "issue",
|
|
entityId: seeded.issue.id,
|
|
details: { status: "in_review", priority: "high" },
|
|
createdAt: new Date("2026-08-06T00:01:00.000Z"),
|
|
},
|
|
]);
|
|
|
|
await expect(assertIssueReviewVerdictActorAllowed(db, {
|
|
issue: seeded.issue,
|
|
actor: { type: "agent", id: seeded.requesterAgentId },
|
|
})).rejects.toMatchObject<HttpError>({
|
|
status: 403,
|
|
details: expect.objectContaining({ code: "review_policy_denied" }),
|
|
});
|
|
await expect(assertIssueReviewVerdictActorAllowed(db, {
|
|
issue: seeded.issue,
|
|
actor: { type: "agent", id: seeded.peerAgentId },
|
|
})).resolves.toBeUndefined();
|
|
});
|
|
|
|
it("classifies only confirmations created by the review requester as review verdicts", async () => {
|
|
const seeded = await seedReview("not_creator");
|
|
await db.insert(activityLog).values({
|
|
companyId: seeded.companyId,
|
|
actorType: "agent",
|
|
actorId: seeded.requesterAgentId,
|
|
agentId: seeded.requesterAgentId,
|
|
action: "issue.updated",
|
|
entityType: "issue",
|
|
entityId: seeded.issue.id,
|
|
details: {
|
|
status: "in_review",
|
|
reviewInteractionId: "review-confirmation",
|
|
_previous: { status: "in_progress" },
|
|
},
|
|
});
|
|
|
|
await expect(isIssueReviewVerdictInteraction(db, {
|
|
issue: seeded.issue,
|
|
interaction: { id: "review-confirmation", createdByAgentId: seeded.requesterAgentId },
|
|
})).resolves.toBe(true);
|
|
await expect(isIssueReviewVerdictInteraction(db, {
|
|
issue: seeded.issue,
|
|
interaction: { id: "review-confirmation", createdByAgentId: seeded.peerAgentId },
|
|
})).resolves.toBe(false);
|
|
await expect(isIssueReviewVerdictInteraction(db, {
|
|
issue: seeded.issue,
|
|
interaction: { id: "requester-sibling", createdByAgentId: seeded.requesterAgentId },
|
|
})).resolves.toBe(false);
|
|
});
|
|
|
|
it("uses authenticated principal type for human_only", async () => {
|
|
const seeded = await seedReview("human_only");
|
|
expect(seeded.issue.reviewPolicy).toBe("human_only");
|
|
const denied = assertIssueReviewVerdictActorAllowed(db, {
|
|
issue: seeded.issue,
|
|
actor: { type: "agent", id: seeded.requesterAgentId },
|
|
});
|
|
await expect(denied).rejects.toMatchObject<HttpError>({
|
|
status: 403,
|
|
details: expect.objectContaining({
|
|
code: "review_policy_denied",
|
|
policy: "human_only",
|
|
allowedActor: "authenticated_user_with_issue_write_access",
|
|
}),
|
|
});
|
|
await expect(assertIssueReviewVerdictActorAllowed(db, {
|
|
issue: seeded.issue,
|
|
actor: { type: "user", id: "board-user" },
|
|
})).resolves.toBeUndefined();
|
|
});
|
|
});
|