mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-30 21:49:18 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Issue interactions give agents and people a structured decision record. > - Resolver routes used different authorization rules. > - Some routes blocked valid agents, including task watchdogs with normal issue access. > - The API did not show who could resolve a pending interaction. > - This pull request gives every interaction kind one resolver policy evaluator. > - The benefit is a clear decision path with consistent governance and company isolation. ## Linked Issues or Issue Description Fixes: #8087 Refs: #7403 Related PR: #11082 proposes board-only confirmation rules. This change keeps human-only review as an explicit policy. **What happened?** Agents could create issue interactions. Some resolver routes still required board access. This left valid agent confirmations pending. Task watchdogs could see the same problem without board identity. **Expected behavior** Every interaction kind must use one resolver policy contract. The contract must support `anyone`, `not_creator`, and `human_only`. It must also apply all normal governance controls. **Steps to reproduce** 1. Create a `request_confirmation` interaction as an agent. 2. Resolve it with another authorized agent. 3. Observe the board-only denial. **Paperclip version or commit** The problem exists on `master` before this change. **Deployment mode** Local development with `pnpm dev`. ## What Changed - Add canonical policies for `anyone`, `not_creator`, and `human_only`. - Use one server evaluator for every interaction kind. - Apply named addressees, company limits, review rules, and task watchdog scope. - Charge cross-issue resolutions to the existing per-run action limit. - Return the effective resolver audience in attention and interaction data. - Show the audience, governance choices, and denial reasons in the board UI. - Add telemetry, API documents, product documents, and regression fixtures. - Add migration provenance for safe legacy behavior. - Make migration `0218` safe for complete replays and partial prior runs. ## Product Rules - An interaction records a response. It does not grant authority for the next action. - `anyone` lets any authorized issue participant respond. - `not_creator` requires a responder other than the interaction creator. - `human_only` requires an authorized person. - A named addressee, company policy, or governed action can narrow the audience. - These controls cannot widen the audience. - A task watchdog uses the same rules as an ordinary agent. - A task watchdog does not receive board authority. - An agent resolution on another issue uses the shared cross-issue action limit. - Legacy pending interactions keep their earlier restrictions. - The UI shows the effective audience and a permanent denial reason. ## Verification - `pnpm --filter @paperclipai/db check:migrations` - `pnpm --filter @paperclipai/db typecheck` - `pnpm exec vitest run packages/db/src/issue-thread-interaction-resolver-policy-migration.test.ts` - The focused PostgreSQL test applies migration `0218` twice. - The test also completes a partial prior run and preserves existing provenance. - The latest GitHub head has 29 successful checks. - The opt-in Storybook visual check skipped as expected. - Greptile reports 5/5 with no open comments. ## Risks - New interaction writes use `anyone` by default. - Callers must select `not_creator` or `human_only` when they need stricter review. - Legacy pending interactions keep the old creator and human restrictions. - Migration `0218` fills only missing provenance fields during recovery. - Cross-issue resolutions can reach the existing action limit. - The shared evaluator affects every interaction kind. - Route, service, database, shared contract, and UI tests cover these rules. > This work matches the Agent Reviews and Approvals direction in `ROADMAP.md`. It does not duplicate a planned item. ## Model Used OpenAI Codex, GPT-5. The runtime does not expose the exact deployment ID or context window. The agent used reasoning, repository tools, shell commands, and test execution. ## 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 linked public issues or described the issue with the required labels - [x] I have not referenced internal Paperclip issues or links - [x] My branch name describes the change and contains no internal ticket id - [x] I have run tests locally and they pass - [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 Paperclip CI gates are green - [x] Greptile is 5/5 with no open comments - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
231 lines
8.7 KiB
TypeScript
231 lines
8.7 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { act as reactAct } from "react";
|
|
import { flushSync } from "react-dom";
|
|
import { createRoot, type Root } from "react-dom/client";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
ISSUE_THREAD_INTERACTION_KINDS as INTERACTION_KINDS,
|
|
type InteractionResolverGovernance,
|
|
} from "@paperclipai/shared";
|
|
import {
|
|
GOVERNANCE_UNSET,
|
|
InteractionGovernancePanel,
|
|
applyGovernanceChange,
|
|
toGovernanceSelectValue,
|
|
} from "./InteractionGovernancePanel";
|
|
import { TooltipProvider } from "./ui/tooltip";
|
|
|
|
let root: Root | null = null;
|
|
let container: HTMLDivElement | null = null;
|
|
|
|
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
async function act(callback: () => void | Promise<void>) {
|
|
if (typeof reactAct === "function") {
|
|
await reactAct(callback);
|
|
return;
|
|
}
|
|
let result: void | Promise<void> = undefined;
|
|
flushSync(() => {
|
|
result = callback();
|
|
});
|
|
await result;
|
|
}
|
|
|
|
function renderPanel(governance: InteractionResolverGovernance = {}, onChange = vi.fn()) {
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
root = createRoot(container);
|
|
act(() => {
|
|
root?.render(
|
|
<TooltipProvider>
|
|
<InteractionGovernancePanel governance={governance} onChange={onChange} />
|
|
</TooltipProvider>,
|
|
);
|
|
});
|
|
return { host: container, onChange };
|
|
}
|
|
|
|
/** Exact visible text of a closed select trigger (the chevron contributes none). */
|
|
function triggerText(host: HTMLElement, testId: string): string {
|
|
const trigger = host.querySelector(`[data-testid="${testId}"]`);
|
|
expect(trigger).toBeTruthy();
|
|
return (trigger?.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
}
|
|
|
|
afterEach(() => {
|
|
if (root) {
|
|
act(() => root?.unmount());
|
|
}
|
|
container?.remove();
|
|
root = null;
|
|
container = null;
|
|
});
|
|
|
|
describe("InteractionGovernancePanel", () => {
|
|
it("presents Anyone as the visible default for a company with no overrides", () => {
|
|
const { host } = renderPanel();
|
|
|
|
const defaultSelect = host.querySelector('[data-testid="governance-request_confirmation-default"]');
|
|
expect(defaultSelect?.textContent).toContain("Anyone (default)");
|
|
const cap = host.querySelector('[data-testid="governance-request_confirmation-cap"]');
|
|
expect(cap?.textContent).toContain("No cap");
|
|
});
|
|
|
|
it("describes the open default without presenting it as board-required", () => {
|
|
const { host } = renderPanel();
|
|
const copy = host.textContent ?? "";
|
|
|
|
expect(copy).toContain("Thread interactions are open by default");
|
|
expect(copy).toContain("the board or any agent, including the one that asked");
|
|
expect(copy).not.toContain("Board only");
|
|
expect(copy).not.toContain("always require the board");
|
|
// Governed tool approvals keep their human-only guarantee.
|
|
expect(copy).toContain("Tool-approval confirmations always stay");
|
|
expect(copy).toContain("Human only");
|
|
});
|
|
|
|
it("shows a stored narrowing override on the matching row", () => {
|
|
const { host } = renderPanel({
|
|
request_confirmation: { defaultPolicy: "human_only", cap: "not_creator" },
|
|
});
|
|
|
|
expect(
|
|
host.querySelector('[data-testid="governance-request_confirmation-default"]')?.textContent,
|
|
).toContain("Human only");
|
|
expect(
|
|
host.querySelector('[data-testid="governance-request_confirmation-cap"]')?.textContent,
|
|
).toContain("Anyone except creator");
|
|
// Untouched kinds still read as open.
|
|
expect(
|
|
host.querySelector('[data-testid="governance-suggest_tasks-default"]')?.textContent,
|
|
).toContain("Anyone (default)");
|
|
});
|
|
|
|
/**
|
|
* PAP-17297: an empty `<SelectValue />` lets Radix portal the selected
|
|
* option's whole subtree — label *and* effect sentence — into the closed
|
|
* trigger, where `line-clamp-1` clipped it. `toContain` assertions cannot see
|
|
* that, so these check the trigger's exact text.
|
|
*/
|
|
it("shows only the complete selected label in a closed trigger", () => {
|
|
const { host } = renderPanel();
|
|
|
|
for (const kind of INTERACTION_KINDS) {
|
|
expect(triggerText(host, `governance-${kind}-default`)).toBe("Anyone (default)");
|
|
expect(triggerText(host, `governance-${kind}-cap`)).toBe("No cap");
|
|
}
|
|
});
|
|
|
|
it("keeps a narrowed trigger free of the option effect sentence", () => {
|
|
const { host } = renderPanel({
|
|
request_confirmation: { defaultPolicy: "human_only", cap: "not_creator" },
|
|
});
|
|
|
|
expect(triggerText(host, "governance-request_confirmation-default")).toBe("Human only");
|
|
expect(triggerText(host, "governance-request_confirmation-cap")).toBe("Anyone except creator");
|
|
// The effect prose belongs to the option list, never the trigger.
|
|
expect(host.textContent).not.toContain("New cards wait for a person on the board");
|
|
expect(host.textContent).not.toContain("narrowed to exclude its creator");
|
|
expect(host.textContent).not.toContain("New cards are open");
|
|
});
|
|
|
|
it("still offers the effect sentence inside the open option list", async () => {
|
|
const { host } = renderPanel();
|
|
const trigger = host.querySelector<HTMLElement>(
|
|
'[data-testid="governance-request_confirmation-default"]',
|
|
);
|
|
expect(trigger).toBeTruthy();
|
|
|
|
await act(() => {
|
|
trigger?.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true }));
|
|
});
|
|
|
|
const listbox = document.querySelector('[data-slot="select-content"]');
|
|
const listText = listbox?.textContent ?? "";
|
|
expect(listText).toContain("Anyone (default)");
|
|
expect(listText).toContain(
|
|
"New cards are open — the board or any agent can respond, including the one that asked.",
|
|
);
|
|
expect(listText).toContain("New cards wait for a person on the board. Agents are turned away.");
|
|
// Each option keeps a label-only typeahead value so keyboard search does not
|
|
// match the effect prose.
|
|
expect(
|
|
Array.from(listbox?.querySelectorAll('[data-slot="select-item"]') ?? []).length,
|
|
).toBe(3);
|
|
// Reflow guard: the popover is capped so long prose wraps instead of
|
|
// stretching past a narrow viewport.
|
|
expect(listbox?.className).toContain("max-w-(--sz-280px)");
|
|
});
|
|
|
|
it("renders a select for every interaction kind", () => {
|
|
const { host } = renderPanel();
|
|
expect(host.querySelectorAll('[data-testid$="-default"]')).toHaveLength(5);
|
|
expect(host.querySelectorAll('[data-testid$="-cap"]')).toHaveLength(5);
|
|
});
|
|
|
|
it("surfaces a save failure", () => {
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
root = createRoot(container);
|
|
act(() => {
|
|
root?.render(
|
|
<TooltipProvider>
|
|
<InteractionGovernancePanel
|
|
governance={{}}
|
|
onChange={vi.fn()}
|
|
errorMessage="Failed to save interaction governance"
|
|
/>
|
|
</TooltipProvider>,
|
|
);
|
|
});
|
|
expect(container.textContent).toContain("Failed to save interaction governance");
|
|
});
|
|
});
|
|
|
|
describe("toGovernanceSelectValue", () => {
|
|
it("treats an absent override as the open default", () => {
|
|
expect(toGovernanceSelectValue(undefined)).toBe(GOVERNANCE_UNSET);
|
|
});
|
|
|
|
it("treats a stored open audience — canonical or legacy alias — as the default", () => {
|
|
expect(toGovernanceSelectValue("anyone")).toBe(GOVERNANCE_UNSET);
|
|
expect(toGovernanceSelectValue("board_or_agents")).toBe(GOVERNANCE_UNSET);
|
|
});
|
|
|
|
it("canonicalizes stored narrowing values, including the legacy board_only alias", () => {
|
|
expect(toGovernanceSelectValue("not_creator")).toBe("not_creator");
|
|
expect(toGovernanceSelectValue("human_only")).toBe("human_only");
|
|
expect(toGovernanceSelectValue("board_only")).toBe("human_only");
|
|
});
|
|
});
|
|
|
|
describe("applyGovernanceChange", () => {
|
|
it("stores a narrowing override", () => {
|
|
expect(applyGovernanceChange({}, "request_confirmation", "defaultPolicy", "human_only")).toEqual({
|
|
request_confirmation: { defaultPolicy: "human_only" },
|
|
});
|
|
});
|
|
|
|
it("clears the override when the open default is re-selected", () => {
|
|
const current: InteractionResolverGovernance = {
|
|
request_confirmation: { defaultPolicy: "human_only" },
|
|
};
|
|
expect(
|
|
applyGovernanceChange(current, "request_confirmation", "defaultPolicy", GOVERNANCE_UNSET),
|
|
).toEqual({});
|
|
// Immutable: the caller's map is untouched.
|
|
expect(current.request_confirmation?.defaultPolicy).toBe("human_only");
|
|
});
|
|
|
|
it("keeps a sibling field when only one is cleared", () => {
|
|
const current: InteractionResolverGovernance = {
|
|
request_confirmation: { defaultPolicy: "human_only", cap: "not_creator" },
|
|
};
|
|
expect(applyGovernanceChange(current, "request_confirmation", "cap", GOVERNANCE_UNSET)).toEqual({
|
|
request_confirmation: { defaultPolicy: "human_only" },
|
|
});
|
|
});
|
|
});
|