Files
PaperClipAI/server/src/__tests__/responsibility-tools.test.ts
T
DottaandClaude Opus 5.5 c0aa7751f8 feat(responsibilities): let agents change areas and responsibilities for their person, with undo (#22261)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - People keep their areas and responsibilities in Paperclip
(experimental, `enableResponsibilities`). #22253 lets agents read them.
> - Agents can still only propose. They cannot rename or archive an
area, change an active responsibility, let one go, or move work between
responsibilities in one step.
> - A person who says "file my weekly routines under Sales" must then do
it by hand.
> - The maintainer chose this rule: an agent may make each change that
its person could make, the person can undo it from the Dashboard
history, and a permanent delete still needs the person's yes on a card.
> - This pull request adds eight change tools and the server rules
behind them.
> - The benefit is that an agent maps work to responsibilities for the
person, and the person keeps control through undo and the delete card.

## Linked Issues or Issue Description

Refs #22253 (phase 1; this pull request is stacked on it).

**Subsystem affected**

Server (responsibility and area routes, Dashboard versions, native
runner tool authority), shared validators and Dashboard types, the
native runner tool catalog, the `paperclip` skill, and the Dashboard
history UI.

**Problem or motivation**

An agent that works for a person can only propose areas and
responsibilities. It cannot change active ones, archive or delete them,
or move filed work in one step. Unfiling needs link IDs. There is no way
for the person to undo an agent's change.

**Proposed solution**

When an agent acts for the person its run works for (`onBehalfOfUserId`)
and that person directed the run (the run's own task is one they made,
such as their chat, or their own message woke it; parent tasks do not
count), apply that person's own rights: their own responsibilities, or
anyone's for a company owner or admin; areas for any active member. Save
each such change as a version of the person's Dashboard, so the existing
history and Undo line show it under the agent's name. Make a permanent
delete wait for an accepted confirmation card that the agent posted. Add
`file` and `unfile` routes that take items by kind and ID, with an
optional move.

**Alternatives considered**

One card for every change, or propose-only. The maintainer chose "act
for me, with undo". A separate undo journal would need a new table and a
new UI; Dashboard versions already have both. A new version cause needs
a check-constraint migration; this change uses `change_set` with no
`interactionId` instead.

## What Changed

- Add tools `create_area`, `update_area`, `delete_area`,
`create_responsibility`, `update_responsibility`,
`delete_responsibility`, `file_under_responsibility` and
`remove_from_responsibility`. They are standard-mode only and hidden
while Responsibilities is off.
- Add the writer rule for agents in `routes/agent-person-authz.ts`
(`agentPersonInCompany`, `agentActsForResponsibilityOwner`), used by
`routes/responsibilities.ts` and `routes/responsibility-areas.ts`. The
person must have directed the run: a person can name anyone as a task's
responsible person, and a run can also work for a routine's person or
the company default, so those runs do not borrow that person's rights.
An agent with no such person keeps the old propose-only rules.
- The response names only the version of the responsibility's owner (for
area changes, the acting person's), and `X-Paperclip-Dashboard-Owner`
says whose history holds it; tools return `dashboardOwnerUserId`. A
change Undo cannot reverse (the name, description, order or un-archiving
of an area other people's proposed or active responsibilities share)
saves no version and is not reported as undoable.
- `/file` without `moveFrom` follows the `/links` rule, so
`create_responsibility` with `fileItems` works for a proposal.
- A title-only create is allowed for an acting agent. It is active by
default and records the agent in `proposedByAgentId`.
- Add `responsibility-agent-changes.ts`. In one transaction that holds
each affected owner's Dashboard lock, it saves the dashboard before the
change (when a person changed it by hand), runs the change on services
bound to that transaction, and saves the result as a `change_set`
version by that agent. The response names the version in
`X-Paperclip-Dashboard-Version`. The tools say Undo only when a version
was saved.
- Dashboard snapshots now also hold each responsibility's filed items,
description, "run by" agent, evidence, health override and note, and
each area's description (optional fields). Restore puts them back. Older
versions still restore as before. A matching older version is upgraded
in place, so the first change after it compares and undoes in full.
- Create and update accept `areaTitle`. The server finds or makes that
area in the same transaction, so a refused change leaves no area. Agent
creates reuse a live responsibility with the same title under a lock, so
retries and parallel calls make no copies.
- Add `POST /api/responsibilities/:id/file` (`items`, optional
`moveFrom`: an ID or `all`) and `POST /api/responsibilities/:id/unfile`
(`items`), each in one transaction.
- Agent deletes need `confirmationId`: an accepted
`request_confirmation` card that this agent posted, with target key
`responsibility-delete:<id>` or `responsibility-area-delete:<id>`.
Someone who may manage the owner must accept it, on the card or by a
verified chat reply. The tools post the card (named after the item),
return `awaiting_confirmation`, and delete on the next call after
acceptance.
- `DELETE /api/responsibility-areas/:id` accepts
`moveResponsibilitiesTo`. Area changes and deletes save versions for
everyone whose Dashboard shows the area.
- Agent activity details now include `onBehalfOfUserId`. The Dashboard
history shows "<agent>, for you" for these versions.
`ResponsibilityDashboardVersionSummary` now has `interactionId`.
- Update the OpenAPI registry and metadata, the `search_api` tool
pointers, the skill, the API reference, the chat directive, the
operation-groups spec, and the pinned counts and SDK source pins.

## Verification

- Server: `vitest run` of the `responsibilit*` tests,
`responsibility-tools.test.ts`, `openapi-routes`, `runner-api*`,
`paperclip-runner-tool-authority` and `task-markdown` all pass. New
tests cover these cases: acting-agent create, update and undo; file,
move and undo; the rule for a person who may not manage the owner;
delete only after an accepted card, including a verified chat reply;
area delete with move and a version for the other owner; undo of a
health override, an area description and an un-archived empty area;
upgrade of an older version; an area by title that a refused change
rolls back; parallel creates.
- UI: `DashboardEditModule.test.tsx` and
`responsibility-dashboard.test.ts` passed. `pnpm --filter
@paperclipai/ui typecheck` passed.
- Server `node scripts/typecheck-layers.mjs` passed.
- Runner: catalog, semantic-tool, eval, protocol-action and
permission-policy tests (284) passed. All generator checks pass.
- I did not run the browser e2e suite locally.

## Risks

- Medium. Agents that work for a person can now change and archive that
person's responsibilities and areas without a card. Every change is a
Dashboard version that the person can restore, and a delete still needs
the card.
- Undo restores titles, sentences, areas, order, status, filed items,
description and the "run by" agent. It does not restore a bar or metric
change; those stay in the metric history.
- A restore of a version from before this change does not touch filed
items, which matches the earlier behavior.
- Undo of a rename or archive of an area that other people also use
keeps its name, as the existing restore rule does for shared areas.
- Manual edits do not take the Dashboard lock. A person's edit that
commits while an agent's change is open can appear in that agent's
version.
- Changes to proposed or let-go responsibilities are not on a Dashboard,
so they cannot be undone there. The tools say so.

## Model Used

Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and
code 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 (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>
2026-11-19 09:29:11 -06:00

312 lines
21 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { callResponsibilityTool, RESPONSIBILITIES_TURNED_OFF_MESSAGE } from "../services/responsibility-tools.js";
const COMPANY = "11111111-1111-4111-8111-111111111111";
const AREA = "22222222-2222-4222-8222-222222222222";
const RESPONSIBILITY = "33333333-3333-4333-8333-333333333333";
const ROUTINE = "44444444-4444-4444-8444-444444444444";
const TASK = "55555555-5555-4555-8555-555555555555";
function rollup(overrides: Record<string, unknown> = {}) {
return {
health: "on_track", computedHealth: "on_track", healthOverridden: false, metric: null,
statusSentence: "12 of 20 investors contacted, 60% of target", workSummary: [{ text: "2 tasks blocked" }],
projects: 1, routines: 2, openTasks: 3, blockedTasks: 2, agentTasks: 1, userTasks: 2, doneTasks: 4,
nextDueAt: null, overdueProjects: [], ...overrides,
};
}
function responsibility(overrides: Record<string, unknown> = {}) {
return {
id: RESPONSIBILITY, companyId: COMPANY, ownerUserId: "owner", areaId: AREA, title: "Fundraising",
description: null, standard: "Every investor conversation has a next step", metricKind: "volume",
metricName: "Investors contacted", metricUnit: null, metricTarget: 20, metricLow: null, metricHigh: null,
metricCurrent: 12, metricDirection: "at_least", metricUpdatedAt: null, runByAgentId: null, status: "active",
source: "manual", evidence: null, healthOverride: null, healthNote: null, sortOrder: 0, proposedByAgentId: null,
confirmedAt: null, createdAt: "2026-11-01T00:00:00.000Z", updatedAt: "2026-11-01T00:00:00.000Z",
rollup: rollup(), ...overrides,
};
}
/** Records each request and answers from a path table; unknown paths are a test failure. */
function fakeApi(routes: Record<string, { status?: number; body: unknown; headers?: Record<string, string> }>) {
const calls: Array<{ url: string; auth: string | null; method?: string; body?: unknown }> = [];
const fetcher = (async (url: string | URL, init?: RequestInit) => {
const href = String(url);
const method = init?.method ?? "GET";
calls.push({
url: href, auth: new Headers(init?.headers).get("authorization"),
...(method !== "GET" ? { method, body: init?.body ? JSON.parse(String(init.body)) : undefined } : {}),
});
const path = href.replace("http://paperclip.test/api", "");
// A route is keyed by path, or by "METHOD path" when one path takes several methods.
const route = routes[`${method} ${path}`] ?? routes[path];
if (!route) throw new Error(`unexpected request ${path}`);
return new Response(JSON.stringify(route.body), { status: route.status ?? 200, headers: { "content-type": "application/json", ...route.headers } });
}) as typeof fetch;
return { calls, fetcher };
}
const ISSUE = "77777777-7777-4777-8777-777777777777";
const AGENT = "88888888-0000-4000-8000-000000000000";
const base = { apiUrl: "http://paperclip.test/api", token: "agent-token", companyId: COMPANY, issueId: ISSUE, agentId: AGENT, companyPrefix: "PAP" };
describe("responsibility tools", () => {
it("groups a person's responsibilities by area and reports uncovered work", async () => {
const proposed = responsibility({ id: "66666666-6666-4666-8666-666666666666", title: "Hiring", status: "proposed", areaId: null, evidence: "Owner said so", proposedByAgentId: "agent-1" });
const api = fakeApi({
[`/companies/${COMPANY}/responsibilities?includeLetGo=false`]: { body: {
ownerUserId: "owner",
areas: [{ id: AREA, title: "Money", description: null, status: "active", activeResponsibilities: 1, byHealth: {} }],
responsibilities: [responsibility()],
proposed: [proposed],
totals: { byHealth: { behind: 0, at_risk: 0, on_track: 1, not_measured: 0 }, openTasks: 3, agentTasks: 1, userTasks: 2, blockedTasks: 2, projects: 1, lateProjects: 0 },
loose: {
projectCount: 0, openTaskCount: 1, routineCount: 1, projects: [],
tasks: [{ id: TASK, identifier: "PAP-9", title: "Loose task", status: "todo", assigneeAgentId: null, assigneeUserId: null, projectId: null, updatedAt: "2026-11-01T00:00:00.000Z" }],
routines: [{ id: ROUTINE, title: "Weekly digest", status: "active", assigneeAgentId: "agent-1", projectId: null }],
},
} },
});
const result = await callResponsibilityTool({ ...base, name: "list_responsibilities", arguments: {} }, api.fetcher);
// The route picks the owner (the person the run works for); the tool sends none and authenticates as the run.
expect(api.calls).toEqual([{ url: `http://paperclip.test/api/companies/${COMPANY}/responsibilities?includeLetGo=false`, auth: "Bearer agent-token" }]);
expect(result).toMatchObject({
ownerUserId: "owner",
areas: [{ id: AREA, title: "Money", responsibilities: [{
id: RESPONSIBILITY, title: "Fundraising", health: "on_track", bar: { kind: "volume", name: "Investors contacted", target: 20, current: 12 },
counts: { projects: 1, routines: 2, openTasks: 3, blockedTasks: 2, doneTasks: 4 }, href: `/PAP/responsibilities/${RESPONSIBILITY}`,
}] }],
withoutArea: [{ title: "Hiring", status: "proposed", evidence: "Owner said so" }],
totals: { active: 1, proposed: 1, letGo: 0 },
uncoveredWork: { routineCount: 1, openTaskCount: 1, routines: [{ id: ROUTINE, title: "Weekly digest" }], tasks: [{ identifier: "PAP-9" }] },
});
expect(result).not.toHaveProperty("guidance");
});
it("says the list is empty rather than inventing responsibilities", async () => {
const api = fakeApi({
[`/companies/${COMPANY}/responsibilities?includeLetGo=false&ownerUserId=someone`]: { body: {
ownerUserId: "someone", areas: [], responsibilities: [], proposed: [],
totals: { byHealth: {}, openTasks: 0, agentTasks: 0, userTasks: 0, blockedTasks: 0, projects: 0, lateProjects: 0 },
loose: { projectCount: 0, openTaskCount: 0, routineCount: 0, projects: [], tasks: [], routines: [] },
} },
});
const result = await callResponsibilityTool({ ...base, name: "list_responsibilities", arguments: { ownerUserId: "someone" } }, api.fetcher);
expect(result).toMatchObject({ ownerUserId: "someone", areas: [], withoutArea: [], guidance: expect.stringContaining("no responsibilities yet") });
});
it("scopes totals to one area, hides archived areas unless asked, and notices hidden proposals", async () => {
const ARCHIVED = "99999999-0000-4000-8000-000000000001";
const overview = (overrides: Record<string, unknown> = {}) => ({
ownerUserId: "owner",
areas: [
{ id: AREA, title: "Money", description: null, status: "active" },
{ id: ARCHIVED, title: "Old", description: null, status: "archived" },
],
responsibilities: [
responsibility(),
responsibility({ id: "66666666-6666-4666-8666-666666666667", title: "Legacy", areaId: ARCHIVED, rollup: rollup({ health: "behind" }) }),
],
proposed: [],
totals: { byHealth: { behind: 1, at_risk: 0, on_track: 1, not_measured: 0 }, openTasks: 9, agentTasks: 0, userTasks: 0, blockedTasks: 2, projects: 4, lateProjects: 1 },
loose: { projectCount: 0, openTaskCount: 0, routineCount: 0, projects: [], tasks: [], routines: [] },
...overrides,
});
const api = fakeApi({ [`/companies/${COMPANY}/responsibilities?includeLetGo=false`]: { body: overview() } });
const all = await callResponsibilityTool({ ...base, name: "list_responsibilities", arguments: {} }, api.fetcher) as Record<string, any>;
expect(all.areas.map((area: { id: string }) => area.id)).toEqual([AREA]);
expect(all.withoutArea.map((row: { title: string }) => row.title)).toEqual(["Legacy"]);
expect(all.totals).toMatchObject({ scope: "person", active: 2, openTasks: 9 });
const one = await callResponsibilityTool({ ...base, name: "list_responsibilities", arguments: { areaId: AREA } }, api.fetcher) as Record<string, any>;
expect(one.totals).toEqual({ scope: "area", active: 1, proposed: 0, letGo: 0, activeByHealth: { behind: 0, at_risk: 0, on_track: 1, not_measured: 0 } });
expect(one).not.toHaveProperty("uncoveredWork");
const onlyProposals = fakeApi({ [`/companies/${COMPANY}/responsibilities?includeLetGo=false`]: {
body: overview({ responsibilities: [], proposed: [responsibility({ status: "proposed" })] }),
} });
const hidden = await callResponsibilityTool({ ...base, name: "list_responsibilities", arguments: { includeProposed: false } }, onlyProposals.fetcher);
expect(hidden).toMatchObject({ guidance: expect.stringContaining("1 proposed responsibilities, hidden") });
});
it("reads one responsibility with its filed items and latest status report", async () => {
const api = fakeApi({
[`/responsibilities/${RESPONSIBILITY}`]: { body: {
...responsibility(), area: { id: AREA, title: "Money", status: "active" },
skills: [{ id: "skill-1", key: "paperclipai/research", slug: "research", name: "Research", description: null, tagline: null, iconUrl: null, color: null, agentIds: ["agent-1"] }],
artifacts: [], artifactsTotal: 0, artifactsTruncated: false,
projects: [],
tasks: [{ linkId: "link-1", membership: "direct", id: TASK, identifier: "PAP-9", title: "Pitch deck", status: "todo", assigneeAgentId: null, assigneeUserId: null, projectId: null, updatedAt: "2026-11-01T00:00:00.000Z" }],
tasksTruncated: false,
routines: [{ linkId: "link-2", membership: "direct", id: ROUTINE, title: "Weekly digest", status: "active", assigneeAgentId: "agent-1", projectId: null, lastRun: null }],
} },
[`/responsibilities/${RESPONSIBILITY}/status-report`]: { body: { current: { status: "on_track", message: "Fine" }, reporterAgentId: "agent-1", updateRequested: false, history: [] } },
});
const result = await callResponsibilityTool({ ...base, name: "get_responsibility", arguments: { responsibilityId: RESPONSIBILITY } }, api.fetcher);
expect(result).toMatchObject({
id: RESPONSIBILITY, ownerUserId: "owner", area: { title: "Money" }, workSummary: ["2 tasks blocked"],
tasks: [{ linkId: "link-1", membership: "direct", identifier: "PAP-9" }],
routines: [{ linkId: "link-2", title: "Weekly digest" }],
skills: [{ id: "skill-1", name: "Research", agentIds: ["agent-1"] }],
statusReport: { current: { status: "on_track" }, reporterAgentId: "agent-1" },
});
});
it("finds where a task is filed by its identifier", async () => {
const api = fakeApi({
"/issues/PAP-9": { body: { id: TASK, identifier: "PAP-9" } },
[`/companies/${COMPANY}/responsibility-links/lookup?issueId=${TASK}`]: { body: { responsibilities: [
{ id: RESPONSIBILITY, title: "Fundraising", areaId: AREA, ownerUserId: "owner", via: "project" },
] } },
});
const result = await callResponsibilityTool({ ...base, name: "find_responsibilities_for", arguments: { kind: "task", id: "PAP-9" } }, api.fetcher);
expect(result).toEqual({
item: { kind: "task", id: TASK, identifier: "PAP-9" },
responsibilities: [{ id: RESPONSIBILITY, title: "Fundraising", areaId: AREA, ownerUserId: "owner", via: "project", href: `/PAP/responsibilities/${RESPONSIBILITY}` }],
});
});
it("reports the feature as turned off, not as an empty list", async () => {
const api = fakeApi({
[`/companies/${COMPANY}/responsibility-links/lookup?routineId=${ROUTINE}`]: { status: 404, body: { error: "Responsibilities are not enabled", code: "responsibilities_disabled" } },
});
await expect(callResponsibilityTool({ ...base, name: "find_responsibilities_for", arguments: { kind: "routine", id: ROUTINE } }, api.fetcher))
.rejects.toMatchObject({ status: 404, message: RESPONSIBILITIES_TURNED_OFF_MESSAGE, details: { code: "responsibilities_disabled" } });
});
it("passes route denials through and refuses malformed input before calling the API", async () => {
const api = fakeApi({
[`/responsibilities/${RESPONSIBILITY}`]: { status: 403, body: { error: "Responsibilities are outside this agent's authorization boundary" } },
[`/responsibilities/${RESPONSIBILITY}/status-report`]: { status: 403, body: { error: "denied" } },
});
await expect(callResponsibilityTool({ ...base, name: "get_responsibility", arguments: { responsibilityId: RESPONSIBILITY } }, api.fetcher))
.rejects.toMatchObject({ status: 403, message: "Responsibilities are outside this agent's authorization boundary" });
await expect(callResponsibilityTool({ ...base, name: "find_responsibilities_for", arguments: { kind: "routine", id: "weekly" } }, api.fetcher))
.rejects.toMatchObject({ status: 422 });
await expect(callResponsibilityTool({ ...base, name: "list_responsibilities", arguments: { owner: "x" } }, api.fetcher)).rejects.toThrow();
});
describe("changes", () => {
const emptyOverview = {
ownerUserId: "owner", areas: [], responsibilities: [responsibility()], proposed: [],
totals: { byHealth: {}, openTasks: 0, agentTasks: 0, userTasks: 0, blockedTasks: 0, projects: 0, lateProjects: 0 },
loose: { projectCount: 0, openTaskCount: 0, routineCount: 0, projects: [], tasks: [], routines: [] },
};
it("creates a responsibility under an area by title, leaving the area to the server's transaction", async () => {
const created = responsibility({ id: "88888888-8888-4888-8888-888888888888", title: "Hiring", areaId: "99999999-9999-4999-8999-999999999999", metricName: null });
const api = fakeApi({
[`/companies/${COMPANY}/responsibilities?includeLetGo=false`]: { body: emptyOverview },
[`POST /companies/${COMPANY}/responsibilities`]: { body: created, headers: { "x-paperclip-dashboard-version": "version-9" } },
});
const result = await callResponsibilityTool({ ...base, name: "create_responsibility", arguments: { title: "Hiring", areaTitle: "people" } }, api.fetcher);
expect(api.calls.filter((entry) => entry.method === "POST").map((entry) => entry.body)).toEqual([
{ title: "Hiring", areaTitle: "people" },
]);
expect(result).toMatchObject({ created: true, responsibility: { title: "Hiring", status: "active" }, undo: expect.stringContaining("can undo it"), dashboardVersionId: "version-9" });
});
it("reuses a live responsibility with the same title instead of making a copy, and files what a retry asks", async () => {
const api = fakeApi({ [`/companies/${COMPANY}/responsibilities?includeLetGo=false`]: { body: emptyOverview } });
const result = await callResponsibilityTool({ ...base, name: "create_responsibility", arguments: { title: " fundraising " } }, api.fetcher);
expect(result).toMatchObject({ created: false, responsibility: { id: RESPONSIBILITY } });
expect(api.calls.some((entry) => entry.method === "POST")).toBe(false);
// A retry after the filing step failed files the items into the one that was saved.
const retry = fakeApi({
[`/companies/${COMPANY}/responsibilities?includeLetGo=false`]: { body: emptyOverview },
[`POST /responsibilities/${RESPONSIBILITY}/file`]: { body: { filed: [{ link: { id: "l1" }, created: true }], unfiled: [] } },
});
expect(await callResponsibilityTool({ ...base, name: "create_responsibility", arguments: { title: "Fundraising", fileItems: [{ kind: "routine", id: ROUTINE }] } }, retry.fetcher))
.toMatchObject({ created: false, filedItems: 1, undo: expect.stringContaining("cannot be undone") });
});
it("names the area and its destination on a delete card", async () => {
const OTHER_AREA = "99999999-0000-4000-8000-000000000000";
const api = fakeApi({
[`/companies/${COMPANY}/responsibility-areas?includeArchived=true`]: { body: [{ id: AREA, title: "Money", status: "active" }, { id: OTHER_AREA, title: "Finance", status: "active" }] },
[`GET /issues/${ISSUE}/interactions`]: { body: [] },
[`POST /issues/${ISSUE}/interactions`]: { body: { id: "card-9" } },
});
await callResponsibilityTool({ ...base, name: "delete_area", arguments: { areaId: AREA, moveResponsibilitiesTo: OTHER_AREA } }, api.fetcher);
expect(api.calls.find((entry) => entry.method === "POST")?.body).toMatchObject({
title: 'Delete the area "Money"',
payload: { prompt: 'Delete the area "Money" permanently?', detailsMarkdown: expect.stringContaining('move to "Finance"') },
});
});
it("notes when a change is outside the Dashboard history and that a bar change is not undone there", async () => {
const api = fakeApi({ [`PATCH /responsibilities/${RESPONSIBILITY}`]: { body: responsibility({ status: "proposed" }) } });
const result = await callResponsibilityTool({ ...base, name: "update_responsibility", arguments: {
responsibilityId: RESPONSIBILITY, bar: { kind: "volume", name: "Calls", target: 5 },
} }, api.fetcher);
expect(result).toMatchObject({ undo: expect.stringContaining("cannot be undone"), barNote: expect.stringContaining("old bar") });
expect(result).not.toHaveProperty("dashboardVersionId");
});
it("maps a cleared bar to empty metric inputs and moves to an area by title", async () => {
const api = fakeApi({
[`PATCH /responsibilities/${RESPONSIBILITY}`]: { body: responsibility({ metricName: null }) },
});
await callResponsibilityTool({ ...base, name: "update_responsibility", arguments: { responsibilityId: RESPONSIBILITY, bar: null, areaTitle: "MONEY" } }, api.fetcher);
expect(api.calls.find((entry) => entry.method === "PATCH")?.body).toEqual({
areaTitle: "MONEY", metricName: null, metricUnit: null, metricTarget: null, metricLow: null, metricHigh: null, metricDirection: null, metricCurrent: null,
});
});
it("asks the person on a card before a permanent delete, and deletes once they accept", async () => {
const detail = { ...responsibility(), area: null, skills: [], artifacts: [], artifactsTotal: 0, artifactsTruncated: false, projects: [], tasks: [], tasksTruncated: false, routines: [] };
const key = `responsibility-delete:${RESPONSIBILITY}`;
const card = (status: string, id = "card-1", createdByAgentId = AGENT) => ({
id, kind: "request_confirmation", status, createdAt: "2026-11-18T00:00:00.000Z", createdByAgentId, payload: { target: { type: "custom", key } },
});
const first = fakeApi({
[`/responsibilities/${RESPONSIBILITY}`]: { body: detail },
[`GET /issues/${ISSUE}/interactions`]: { body: [] },
[`POST /issues/${ISSUE}/interactions`]: { body: { id: "card-1" } },
});
expect(await callResponsibilityTool({ ...base, name: "delete_responsibility", arguments: { responsibilityId: RESPONSIBILITY } }, first.fetcher))
.toMatchObject({ deleted: false, status: "awaiting_confirmation", confirmationId: "card-1" });
expect(first.calls.find((entry) => entry.method === "POST")?.body).toMatchObject({
kind: "request_confirmation", idempotencyKey: `${key}:1`, resolverPolicy: "human_only", continuationPolicy: "wake_assignee",
payload: { acceptLabel: "Delete", target: { type: "custom", key } },
});
const declined = fakeApi({ [`/responsibilities/${RESPONSIBILITY}`]: { body: detail }, [`GET /issues/${ISSUE}/interactions`]: { body: [card("rejected")] } });
expect(await callResponsibilityTool({ ...base, name: "delete_responsibility", arguments: { responsibilityId: RESPONSIBILITY } }, declined.fetcher))
.toMatchObject({ deleted: false, status: "declined" });
expect(declined.calls.some((entry) => entry.method)).toBe(false);
const accepted = fakeApi({
[`/responsibilities/${RESPONSIBILITY}`]: { body: detail },
// Another agent's accepted card does not count: the route accepts only this agent's own.
[`GET /issues/${ISSUE}/interactions`]: { body: [
card("rejected", "card-0"), { ...card("accepted"), createdAt: "2026-11-18T01:00:00.000Z" },
{ ...card("accepted", "card-other", "another-agent"), createdAt: "2026-11-18T02:00:00.000Z" },
] },
[`DELETE /responsibilities/${RESPONSIBILITY}?confirmationId=card-1`]: { body: responsibility() },
});
expect(await callResponsibilityTool({ ...base, name: "delete_responsibility", arguments: { responsibilityId: RESPONSIBILITY } }, accepted.fetcher))
.toMatchObject({ deleted: true, responsibility: { id: RESPONSIBILITY } });
});
it("files work by identifier and reports a move", async () => {
const api = fakeApi({
"/issues/PAP-9": { body: { id: TASK, identifier: "PAP-9" } },
[`POST /responsibilities/${RESPONSIBILITY}/file`]: { body: { filed: [{ link: { id: "l1" }, created: true }, { link: { id: "l2" }, created: false }], unfiled: [{ responsibilityId: "old" }] } },
});
const result = await callResponsibilityTool({ ...base, name: "file_under_responsibility", arguments: {
responsibilityId: RESPONSIBILITY, items: [{ kind: "task", id: "PAP-9" }, { kind: "routine", id: ROUTINE }], moveFrom: "all",
} }, api.fetcher);
expect(api.calls.find((entry) => entry.method === "POST")?.body).toEqual({
items: [{ kind: "task", id: TASK }, { kind: "routine", id: ROUTINE }], moveFrom: "all",
});
expect(result).toMatchObject({ filed: 1, alreadyFiled: 1, movedFrom: ["old"] });
});
});
});