mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-14 17:40:37 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Issues use `in_review` to request a final decision from an authorized writer > - The server rejected an assignee agent that tried to close its own review, even when the issue had no independent-review rule > - This rejection stopped the default agent workflow and did not represent the configured execution-stage rules > - Paperclip needs an open default and explicit issue-level constraints for teams that require an independent or human verdict > - This pull request removes the unconditional rejection and adds `anyone`, `not_creator`, and `human_only` review policies > - The benefit is a working default path with opt-in, authenticated verdict controls ## Linked Issues or Issue Description Refs #10635, #4429, and #10671. The related public work covers execution-stage independence, self-approval fallback behavior, and durable review paths. This change is distinct. It controls who can resolve an issue review verdict. It keeps configured execution stages active. ## What Changed - Added a nullable `review_policy` issue column. Null has the same meaning as `anyone`. The migration does not backfill existing issues. - Added shared create, update, response, and compact issue contracts for `anyone`, `not_creator`, and `human_only`. - Removed the unconditional agent self-approval rejection for `in_review` issues. - Added one reusable verdict-actor check for terminal status changes and pending interaction accept or reject actions. - Used the authenticated principal type for `human_only`. Agent keys and run tokens remain agent principals. - Used the latest transition into `in_review` to identify the requester for `not_creator`. - Added actionable 403 responses that name the policy, the allowed actor, and the next step. - Kept the configured execution-stage transition and signoff behavior. - Added focused contract, helper, status-route, interaction-route, and execution-stage regression tests. - Updated the implementation specification for the new issue field. ## Verification - `pnpm exec vitest run packages/shared/src/validators/issue.test.ts server/src/__tests__/issue-review-policy.test.ts server/src/__tests__/issue-stalled-review-decision-routes.test.ts --reporter=dot` passed: 42 tests. - `pnpm --filter @paperclipai/shared typecheck` passed. - `pnpm --filter @paperclipai/db typecheck` passed, including migration numbering and safety checks. - `pnpm --filter @paperclipai/server typecheck` passed. - `pnpm run typecheck:build-gaps` passed across server, CLI, plugin SDK/examples, plugin wiki, and UI. - `git diff --check origin/master...HEAD` passed. - SecurityEngineer review approved the authenticated-principal checks and accepted policy-relaxation tradeoff with no required changes. - Greptile reviewed the latest head at 5/5 with zero inline comments or follow-ups. - The latest-head GitHub rollup passed build, typecheck, server/workspace tests, serialized suites, canary, e2e, and external security checks. ## Risks - The migration adds one nullable text column. It has no default and no backfill. - `not_creator` reads the latest recorded transition into `in_review`. It denies the verdict when it cannot identify the requester. - Agents can change or relax `reviewPolicy` when they have issue write access. This is intentional for this issue-level control. - Null and `anyone` do not add a database query to the verdict path. - Configured execution-stage checks still run after the issue-level policy check. > This work aligns with the completed "Agent Reviews and Approvals" and "Enforced Outcomes" roadmap items. It does not add a new roadmap capability. ## Model Used - OpenAI Codex, GPT-5. The exact deployment ID and context-window size are not exposed to the agent. The run used reasoning, repository tools, code execution, and GitHub CLI access. ## 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>
164 lines
5.5 KiB
TypeScript
164 lines
5.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { Issue } from "@paperclipai/shared";
|
|
import { buildIssueTree, countDescendants, filterIssueDescendants } from "./issue-tree";
|
|
|
|
function makeIssue(id: string, parentId: string | null = null): Issue {
|
|
return {
|
|
id,
|
|
identifier: id.toUpperCase(),
|
|
companyId: "company-1",
|
|
projectId: null,
|
|
projectWorkspaceId: null,
|
|
goalId: null,
|
|
parentId,
|
|
title: `Issue ${id}`,
|
|
description: null,
|
|
status: "todo",
|
|
workMode: "standard",
|
|
priority: "medium",
|
|
reviewPolicy: null,
|
|
assigneeAgentId: null,
|
|
assigneeUserId: null,
|
|
responsibleUserId: null,
|
|
createdByAgentId: null,
|
|
createdByUserId: null,
|
|
issueNumber: 1,
|
|
requestDepth: 0,
|
|
billingCode: null,
|
|
assigneeAdapterOverrides: null,
|
|
executionWorkspaceId: null,
|
|
executionWorkspacePreference: null,
|
|
executionWorkspaceSettings: null,
|
|
checkoutRunId: null,
|
|
executionRunId: null,
|
|
executionAgentNameKey: null,
|
|
executionLockedAt: null,
|
|
startedAt: null,
|
|
completedAt: null,
|
|
cancelledAt: null,
|
|
hiddenAt: null,
|
|
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
updatedAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
labels: [],
|
|
labelIds: [],
|
|
myLastTouchAt: null,
|
|
lastExternalCommentAt: null,
|
|
isUnreadForMe: false,
|
|
};
|
|
}
|
|
|
|
describe("buildIssueTree", () => {
|
|
it("returns all items as roots when no parent-child relationships exist", () => {
|
|
const items = [makeIssue("a"), makeIssue("b"), makeIssue("c")];
|
|
const { roots, childMap } = buildIssueTree(items);
|
|
expect(roots.map((r) => r.id)).toEqual(["a", "b", "c"]);
|
|
expect(childMap.size).toBe(0);
|
|
});
|
|
|
|
it("places children under their parent and excludes them from roots", () => {
|
|
const parent = makeIssue("parent");
|
|
const child1 = makeIssue("child1", "parent");
|
|
const child2 = makeIssue("child2", "parent");
|
|
const { roots, childMap } = buildIssueTree([parent, child1, child2]);
|
|
expect(roots.map((r) => r.id)).toEqual(["parent"]);
|
|
expect(childMap.get("parent")?.map((c) => c.id)).toEqual(["child1", "child2"]);
|
|
});
|
|
|
|
it("handles multiple levels of nesting", () => {
|
|
const grandparent = makeIssue("gp");
|
|
const parent = makeIssue("p", "gp");
|
|
const child = makeIssue("c", "p");
|
|
const { roots, childMap } = buildIssueTree([grandparent, parent, child]);
|
|
expect(roots.map((r) => r.id)).toEqual(["gp"]);
|
|
expect(childMap.get("gp")?.map((i) => i.id)).toEqual(["p"]);
|
|
expect(childMap.get("p")?.map((i) => i.id)).toEqual(["c"]);
|
|
});
|
|
|
|
it("promotes orphaned sub-tasks (parent not in list) to root level", () => {
|
|
// child references a parent that is not in the items array (e.g. filtered out)
|
|
const child = makeIssue("child", "missing-parent");
|
|
const unrelated = makeIssue("unrelated");
|
|
const { roots, childMap } = buildIssueTree([child, unrelated]);
|
|
expect(roots.map((r) => r.id)).toEqual(["child", "unrelated"]);
|
|
expect(childMap.size).toBe(0);
|
|
});
|
|
|
|
it("returns empty roots and empty childMap for an empty list", () => {
|
|
const { roots, childMap } = buildIssueTree([]);
|
|
expect(roots).toEqual([]);
|
|
expect(childMap.size).toBe(0);
|
|
});
|
|
|
|
it("preserves list order within roots and within children", () => {
|
|
const p1 = makeIssue("p1");
|
|
const p2 = makeIssue("p2");
|
|
const c1 = makeIssue("c1", "p1");
|
|
const c2 = makeIssue("c2", "p1");
|
|
const { roots, childMap } = buildIssueTree([p1, c1, p2, c2]);
|
|
expect(roots.map((r) => r.id)).toEqual(["p1", "p2"]);
|
|
expect(childMap.get("p1")?.map((c) => c.id)).toEqual(["c1", "c2"]);
|
|
});
|
|
});
|
|
|
|
describe("countDescendants", () => {
|
|
it("returns 0 for a leaf node", () => {
|
|
const { childMap } = buildIssueTree([makeIssue("a")]);
|
|
expect(countDescendants("a", childMap)).toBe(0);
|
|
});
|
|
|
|
it("returns direct child count for a single-level parent", () => {
|
|
const { childMap } = buildIssueTree([
|
|
makeIssue("p"),
|
|
makeIssue("c1", "p"),
|
|
makeIssue("c2", "p"),
|
|
]);
|
|
expect(countDescendants("p", childMap)).toBe(2);
|
|
});
|
|
|
|
it("counts all descendants across multiple levels", () => {
|
|
// P → C → G1, G2 (P has 3 total descendants: C, G1, G2)
|
|
const { childMap } = buildIssueTree([
|
|
makeIssue("p"),
|
|
makeIssue("c", "p"),
|
|
makeIssue("g1", "c"),
|
|
makeIssue("g2", "c"),
|
|
]);
|
|
expect(countDescendants("p", childMap)).toBe(3);
|
|
});
|
|
|
|
it("returns 0 for an id not in the childMap", () => {
|
|
const { childMap } = buildIssueTree([makeIssue("a"), makeIssue("b")]);
|
|
expect(countDescendants("nonexistent", childMap)).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe("filterIssueDescendants", () => {
|
|
it("returns only children and deeper descendants of the requested root", () => {
|
|
const root = makeIssue("root");
|
|
const child = makeIssue("child", "root");
|
|
const grandchild = makeIssue("grandchild", "child");
|
|
const unrelatedParent = makeIssue("other");
|
|
const unrelatedChild = makeIssue("other-child", "other");
|
|
|
|
expect(filterIssueDescendants("root", [
|
|
root,
|
|
child,
|
|
grandchild,
|
|
unrelatedParent,
|
|
unrelatedChild,
|
|
]).map((issue) => issue.id)).toEqual(["child", "grandchild"]);
|
|
});
|
|
|
|
it("handles stale broad issue-list responses without requiring the root in the list", () => {
|
|
const child = makeIssue("child", "root");
|
|
const grandchild = makeIssue("grandchild", "child");
|
|
const globalIssue = makeIssue("global");
|
|
|
|
expect(filterIssueDescendants("root", [
|
|
globalIssue,
|
|
child,
|
|
grandchild,
|
|
]).map((issue) => issue.id)).toEqual(["child", "grandchild"]);
|
|
});
|
|
});
|