Files
PaperClipAI/ui/src/pages/ResponsibilityDetail.test.tsx
T
575ef12575 feat(responsibilities): file company skills under responsibilities (#22275)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - A responsibility shows the skills of the agents doing its work.
People cannot say which skills a responsibility needs.
> - The maintainer chose to file skills under responsibilities like
projects, tasks and routines.
> - Agents also need to set a skill's catalog details without rewriting
its SKILL.md.
> - This pull request lets people and agents file, move and remove
company skills under a responsibility, and adds `update_skill_details`.
> - The benefit is that a responsibility lists the skills it needs,
beside the skills its agents already hold.

## Linked Issues or Issue Description

Refs #22253, #22261 and #22274; this pull request is stacked on them.

**Subsystem affected**

Database (`responsibility_links`), shared types and validators, server
responsibility service and routes, Dashboard versions, native runner
tools, and the responsibility page UI.

**Problem or motivation**

Skills under a responsibility are only computed from the agents doing
its work. A person cannot record that "Hiring needs interviewing", and
an agent cannot file a skill when it maps work for a person.

**Proposed solution**

Add a nullable `skill_id` to `responsibility_links` and allow it as the
one target of a link. Show filed and computed skills together. Let the
file, unfile, lookup and link routes and tools take skills. Keep filed
skills in Dashboard versions so undo covers them. Add a small live tool
for a skill's tagline and categories.

**Alternatives considered**

Keeping skills computed only, and giving the skill to the agent that
runs the responsibility, was the other option. It was not chosen.
Extending `update_skill` would change its scenario contract, whose mock
needs `markdown`, so the details tool is separate.

## What Changed

- Review fixes: the default responsibility view's Skills "+" adds an
existing skill, removes a filed one, or opens an agent's skills page. A
newest Dashboard version without a skill list is upgraded in place, so
the first skill filed after it is undone. Undo files again, or removes,
only skills the restoring person can see. A read scope without a skill
condition sees no filed skill. `update_skill_details` with only
`skillId` is a no-op, as its schema allows.

- Migration `0499`: add `responsibility_links.skill_id` (FK to
`company_skills`, on delete cascade). Widen the single-target check to
four targets. Add a unique `(responsibility_id, skill_id)` index and a
`skill_id` index. The migration is idempotent and online-compatible (NOT
VALID then VALIDATE, and the indexes are built CONCURRENTLY). It is
listed in `MIGRATIONS_WITH_TOP_LEVEL_STATEMENTS`.
- Shared: `ResponsibilityLink.skillId`;
`ResponsibilitySkillSummary.linkId` and `computed`; `skillId` in the
link and lookup schemas; `skill` in `RESPONSIBILITY_FILE_ITEM_KINDS`;
optional `skillIds` in Dashboard snapshot links.
- Server: filing checks the reader's skill visibility
(`skillAccessService`). The detail merges filed and computed skills into
one card each. Lookup accepts `skillId`. Dashboard capture, restore and
summary include filed skills. A version without `skillIds` leaves filed
skills as they are when it is restored.
- Tools: `file_under_responsibility`, `remove_from_responsibility` and
`find_responsibilities_for` accept `kind: "skill"`. `get_responsibility`
returns `linkId` and `computed` for each skill. Add
`update_skill_details` (tagline and categories).
- UI: the responsibility page has "Add existing skill". A filed skill
shows "Filed here" and a remove button. Computed skills keep their
holders.

## Verification

- Server: the `responsibilit*` tests (new: file, find, move and unfile a
skill; one card for a skill that is both filed and computed; undo of a
filed skill from the Dashboard history), `skill-tools.test.ts` (new
`update_skill_details` cases), `responsibility-tools`, `routine-tools`,
`routines-routes`, `paperclip-runner-tool-authority`, `runner-api` and
`openapi-routes`: 24 files, 2723 tests passed.
- UI: responsibility page and component tests (16 files, 158 tests,
including a new filed-skill test) pass. `pnpm --filter @paperclipai/ui
typecheck` passed.
- `@paperclipai/db` `check:migrations` passes and reports the override.
The snapshot drift test passes. `tsc` passes for `db`, `shared` and the
server layers.
- Runner: catalog and semantic-tool tests (317) pass. All generator
checks pass.

## Risks

- The migration changes a check constraint on `responsibility_links`.
The replacement accepts every row that the old check accepted. It is
swapped as NOT VALID and then validated. The previous release never sets
`skill_id`.
- Deleting a company skill removes its links (cascade).
- Filed skills follow the reader's skill visibility. A skill the reader
may not see is not listed.

## 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>
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-19 09:30:49 -06:00

467 lines
25 KiB
TypeScript

// @vitest-environment jsdom
import { act, type ReactNode } from "react";
import { createRoot, type Root } from "react-dom/client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { ApiError } from "@/api/client";
import { describeLinkError } from "@/components/responsibilities/AddExistingWorkPicker";
import { artifactsTruncationNote } from "@/components/responsibilities/ResponsibilitySkillsAndArtifacts";
import { TooltipProvider } from "@/components/ui/tooltip";
import {
areaFundraising,
areaPortfolio,
boardReportingDetail,
fundraisingDetail,
hiringDetail,
lpUpdatesDetail,
RESPONSIBILITY_DETAIL_FIXTURES,
RESPONSIBILITY_FIXTURE_GUIDE_AGENT_ID,
RESPONSIBILITY_FIXTURE_NOW,
} from "../../storybook/fixtures/responsibilities";
import { METRIC_SET_FIXTURES, statusReportFixture } from "../../storybook/fixtures/responsibility-metrics";
import { ResponsibilityDetail } from "./ResponsibilityDetail";
const mocks = vi.hoisted(() => ({
responsibilityId: "resp-fundraising",
api: { get: vi.fn(), update: vi.fn(), unlink: vi.fn(), remove: vi.fn(), link: vi.fn(), statusReport: vi.fn(), requestStatusUpdate: vi.fn() },
areas: { list: vi.fn() },
agents: { list: vi.fn() },
activity: { list: vi.fn() },
auth: { getSession: vi.fn() },
settings: { getExperimental: vi.fn() },
issues: { update: vi.fn() },
routines: { update: vi.fn() },
projects: { update: vi.fn() },
bars: { conversation: vi.fn(), start: vi.fn(), accept: vi.fn(), decline: vi.fn() },
metrics: { metrics: vi.fn(), removeMetric: vi.fn() },
navigate: vi.fn(),
}));
const breadcrumbs = vi.hoisted(() => vi.fn());
vi.mock("@/api/responsibilities", () => ({ responsibilitiesApi: mocks.api, responsibilityAreasApi: mocks.areas }));
vi.mock("@/api/agents", () => ({ agentsApi: mocks.agents }));
vi.mock("@/api/activity", () => ({ activityApi: mocks.activity }));
vi.mock("@/api/auth", () => ({ authApi: mocks.auth }));
vi.mock("@/api/instanceSettings", () => ({ instanceSettingsApi: mocks.settings }));
vi.mock("@/api/issues", () => ({ issuesApi: mocks.issues }));
vi.mock("@/api/routines", () => ({ routinesApi: mocks.routines }));
vi.mock("@/api/projects", () => ({ projectsApi: mocks.projects }));
vi.mock("@/api/responsibility-bars", () => ({ responsibilityBarsApi: mocks.bars }));
vi.mock("@/api/responsibility-metrics", () => ({ responsibilityMetricsApi: mocks.metrics }));
vi.mock("@/context/CompanyContext", () => ({ useCompany: () => ({ selectedCompanyId: "company-storybook" }) }));
vi.mock("@/context/BreadcrumbContext", () => ({ useBreadcrumbs: () => ({ setBreadcrumbs: breadcrumbs }) }));
vi.mock("@/components/InlineEditor", () => ({
InlineEditor: ({ value, as: Tag = "p", placeholder }: { value: string; as?: "h1" | "p"; placeholder?: string }) => (
<Tag data-inline-editor>{value || placeholder}</Tag>
),
}));
vi.mock("@/lib/router", () => ({
Link: ({ to, children, disableIssueQuicklook: _skip, ...props }: { to: string; children: ReactNode; disableIssueQuicklook?: boolean }) => (
<a href={to} {...props}>{children}</a>
),
useNavigate: () => mocks.navigate,
useParams: () => ({ responsibilityId: mocks.responsibilityId }),
useLocation: () => ({ pathname: "/responsibilities", search: "?view=full", hash: "", state: null, key: "default" }),
}));
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
let root: Root;
let host: HTMLDivElement;
let client: QueryClient;
const flush = () => act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)); });
const section = (heading: string) =>
[...host.querySelectorAll("section")].find((node) => node.querySelector("h2")?.textContent?.startsWith(heading))!;
const bar = () => host.querySelector<HTMLElement>("#responsibility-bar")!;
const buttonByText = (label: string, scope: ParentNode = host) =>
[...scope.querySelectorAll("button")].find((button) => button.textContent?.trim() === label) as HTMLButtonElement | undefined;
function setInputValue(input: HTMLInputElement, value: string) {
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set?.call(input, value);
input.dispatchEvent(new Event("input", { bubbles: true }));
}
async function render(id = "resp-fundraising") {
mocks.responsibilityId = id;
await act(async () => {
root.render(
<QueryClientProvider client={client}>
<TooltipProvider>
<ResponsibilityDetail />
</TooltipProvider>
</QueryClientProvider>,
);
});
await flush();
await flush();
}
beforeEach(() => {
vi.useFakeTimers({ toFake: ["Date"] });
vi.setSystemTime(RESPONSIBILITY_FIXTURE_NOW);
vi.clearAllMocks();
// These tests cover the full layout, which the page shows only when the address names it.
mocks.api.get.mockImplementation(async (id: string) => RESPONSIBILITY_DETAIL_FIXTURES[id]);
mocks.api.unlink.mockResolvedValue({ id: "link-task-intro" });
mocks.api.link.mockResolvedValue({ link: { id: "link-task-intro-2" } });
mocks.api.update.mockImplementation(async (id: string, patch: Record<string, unknown>) => ({ ...RESPONSIBILITY_DETAIL_FIXTURES[id], ...patch }));
mocks.areas.list.mockResolvedValue([areaFundraising, areaPortfolio]);
mocks.agents.list.mockResolvedValue([
{ id: "agent-codex", companyId: "company-storybook", name: "CodexCoder", status: "idle" },
{ id: RESPONSIBILITY_FIXTURE_GUIDE_AGENT_ID, companyId: "company-storybook", name: "CTO", status: "idle" },
]);
mocks.activity.list.mockResolvedValue([
{ action: "responsibility.metric_updated", actorType: "agent", actorId: "agent-codex", createdAt: "2026-11-12T08:00:00.500Z" },
]);
mocks.auth.getSession.mockResolvedValue({ user: { id: "user-storybook" } });
mocks.settings.getExperimental.mockResolvedValue({ enableArtifactsV1: false, managedKeys: { enableArtifactsV1: true } });
// No agent can talk the bar through unless a test says so: the bar is edited by hand.
mocks.bars.conversation.mockImplementation(async (responsibilityId: string) => ({
responsibilityId, state: "none", defaultAgentId: null, conversation: null, proposal: null,
}));
// The metric set and the written status load beside the page; until a test says so they are not there.
mocks.metrics.metrics.mockRejectedValue(new Error("Not found"));
mocks.api.statusReport.mockRejectedValue(new Error("Not found"));
host = document.createElement("div");
document.body.append(host);
root = createRoot(host);
client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
});
afterEach(async () => {
await act(async () => root.unmount());
host.remove();
client.clear();
vi.useRealTimers();
});
describe("ResponsibilityDetail: setting the bar with an agent", () => {
const openConversation = {
issueId: "issue-bar-conversation", identifier: "PAP-42", title: "Edit the bar for Seed extension",
status: "todo", agentId: RESPONSIBILITY_FIXTURE_GUIDE_AGENT_ID, createdAt: new Date("2026-11-13T10:00:00Z"),
};
it("talks the bar through with an agent first, and keeps editing by hand as the second way", async () => {
mocks.bars.conversation.mockResolvedValue({
responsibilityId: "resp-fundraising", state: "none", defaultAgentId: RESPONSIBILITY_FIXTURE_GUIDE_AGENT_ID, conversation: null, proposal: null,
});
mocks.bars.start.mockResolvedValue({
responsibilityId: "resp-fundraising", state: "discussing", defaultAgentId: RESPONSIBILITY_FIXTURE_GUIDE_AGENT_ID,
conversation: openConversation, proposal: null,
});
await render();
expect(buttonByText("Edit by hand", bar())).toBeDefined();
await act(async () => buttonByText("Edit the bar", bar())!.click());
await flush();
expect(mocks.bars.start).toHaveBeenCalledExactlyOnceWith("resp-fundraising");
expect(mocks.navigate).toHaveBeenCalledWith("/issues/PAP-42");
expect(document.body.querySelector('[role="dialog"]')).toBeNull();
await act(async () => buttonByText("Edit by hand", bar())!.click());
expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain("Kind of measure");
});
it("shows that a bar is being discussed, with a way into the conversation", async () => {
mocks.bars.conversation.mockResolvedValue({
responsibilityId: "resp-fundraising", state: "discussing", defaultAgentId: RESPONSIBILITY_FIXTURE_GUIDE_AGENT_ID,
conversation: openConversation, proposal: null,
});
await render();
const notice = bar().querySelector('[data-testid="bar-conversation-open"]')!;
expect(notice.textContent).toContain("You are talking the bar through with CTO.");
expect(notice.querySelector("a")?.getAttribute("href")).toBe("/issues/PAP-42");
expect(buttonByText("Continue the conversation", bar())).toBeDefined();
});
it("puts a waiting proposal on the page to accept in one tap", async () => {
const { barProposalFixture } = await import("../../storybook/fixtures/responsibility-bars");
mocks.bars.conversation.mockResolvedValue({
responsibilityId: "resp-fundraising", state: "proposal_waiting", defaultAgentId: RESPONSIBILITY_FIXTURE_GUIDE_AGENT_ID,
conversation: openConversation, proposal: barProposalFixture("range"),
});
mocks.bars.accept.mockResolvedValue({ interaction: barProposalFixture("range", { status: "accepted" }), responsibility: fundraisingDetail });
await render();
const card = bar().querySelector<HTMLElement>('[data-testid="bar-proposal"]')!;
expect(card.textContent).toContain("We always have between 12 and 24 months of runway.");
expect(card.querySelector('a[href="/issues/issue-bar-conversation"]')?.textContent).toBe("Open the conversation");
await act(async () => buttonByText("Use this bar", card)!.click());
await flush();
expect(mocks.bars.accept).toHaveBeenCalledExactlyOnceWith("issue-bar-conversation", "bar-proposal-range");
});
it("offers the hand edit directly when no agent can hold the conversation", async () => {
await render();
expect(buttonByText("Edit by hand", bar())).toBeUndefined();
await act(async () => buttonByText("Edit the bar", bar())!.click());
expect(mocks.bars.start).not.toHaveBeenCalled();
expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain("Edit the bar");
});
});
describe("ResponsibilityDetail: the bar", () => {
it("names it in the page and breadcrumbs, with its area and the agents working on it", async () => {
await render();
expect(host.querySelector("h1")?.textContent).toBe("Seed extension");
expect(breadcrumbs).toHaveBeenLastCalledWith([
{ label: "Dashboard", href: "/responsibilities" },
{ label: "Seed extension" },
]);
expect(host.querySelector('button[aria-label="Area: Fundraising. Move to another area"]')).not.toBeNull();
const header = host.querySelector("header")!;
expect(header.textContent).toContain("Agents on this");
expect(header.textContent).toContain("CodexCoder");
expect(header.textContent).toContain("1 task, 1 routine, leads 1 project");
// No control hands the whole responsibility to an agent; a new task is offered instead.
expect(header.textContent).not.toContain("Give to an agent");
expect(header.textContent).toContain("New task for an agent");
});
it("gives a task, a routine or a project to an agent with each one's own call", async () => {
mocks.issues.update.mockResolvedValue({});
mocks.routines.update.mockResolvedValue({});
mocks.projects.update.mockResolvedValue({});
await render();
const pick = async (label: string, agent: string) => {
const trigger = host.querySelector<HTMLButtonElement>(`button[aria-label="Give ${label} to an agent"]`)!;
await act(async () => trigger.dispatchEvent(new MouseEvent("pointerdown", { bubbles: true, button: 0 })));
const item = [...document.body.querySelectorAll('[role="menuitemradio"]')].find((candidate) => candidate.textContent === agent)!;
await act(async () => item.dispatchEvent(new MouseEvent("click", { bubbles: true })));
await flush();
};
await pick("Ask Dana for an intro to the lead", "CTO");
expect(mocks.issues.update).toHaveBeenCalledExactlyOnceWith("task-intro", { assigneeAgentId: RESPONSIBILITY_FIXTURE_GUIDE_AGENT_ID, assigneeUserId: null });
await pick("Weekly investor pipeline review", "CTO");
expect(mocks.routines.update).toHaveBeenCalledExactlyOnceWith("routine-weekly", { assigneeAgentId: RESPONSIBILITY_FIXTURE_GUIDE_AGENT_ID });
await pick("Lead investor pipeline", "CodexCoder");
expect(mocks.projects.update).toHaveBeenCalledExactlyOnceWith("project-pipeline", { leadAgentId: "agent-codex" }, "company-storybook");
// Done tasks are not offered.
await act(async () => buttonByText("Show 1 done", section("Tasks"))!.click());
expect(host.querySelector('button[aria-label="Give Send the October update to an agent"]')).toBeNull();
});
it("comes first: the sentence, the number against its target, who updated it, and the status", async () => {
await render();
const card = bar();
expect(card.compareDocumentPosition(section("Across the work")) & Node.DOCUMENT_POSITION_FOLLOWING).not.toBe(0);
expect(card.textContent).toContain("Twenty qualified investors contacted before the partner meeting in December.");
expect(card.querySelector('[aria-label="9 of 20 investors contacted"]')?.textContent).toBe("9of 20");
expect(card.querySelector('[role="meter"]')?.getAttribute("aria-valuenow")).toBe("45");
expect(card.textContent).toContain("Updated yesterday by CodexCoder.");
expect(card.textContent).toContain("Behind");
expect(card.textContent).toContain("9 of 20 investors contacted, 45% of target");
expect(card.textContent).not.toContain("Not updated in");
});
it("puts routines and skills first, then projects and tasks, then artifacts", async () => {
await render();
const order = [...host.querySelectorAll("section h2")].map((heading) => heading.textContent?.replace(/\s*\d+$/, ""))
.filter((title) => ["Routines", "Skills", "Projects", "Tasks", "Artifacts"].includes(title ?? ""));
expect(order).toEqual(["Routines", "Skills", "Projects", "Tasks", "Artifacts"]);
});
it("shows up to three metrics in the bar, each in its form, once the set loads", async () => {
mocks.metrics.metrics.mockResolvedValue(METRIC_SET_FIXTURES.chosen);
await render();
await flush();
const tiles = [...bar().querySelectorAll<HTMLElement>("[data-bar-metrics] [data-metric-key]")];
expect(tiles.map((tile) => tile.dataset.metricDisplay)).toEqual(["line", "bar", "percent"]);
expect(tiles[0]!.querySelector("[data-metric-value]")?.textContent).toBe("9of 20");
expect(tiles[1]!.querySelectorAll("[data-bar]")).toHaveLength(8);
expect(tiles[2]!.querySelector("[data-metric-ring]")).not.toBeNull();
// The owner can remove a supporting metric, not the bar's own.
expect(tiles[0]!.querySelector("button[aria-label^='Remove']")).toBeNull();
expect(tiles[1]!.querySelector("button[aria-label^='Remove']")).not.toBeNull();
});
it("labels starter metrics plainly", async () => {
mocks.metrics.metrics.mockResolvedValue(METRIC_SET_FIXTURES.starter);
await render();
await flush();
expect(bar().querySelector("[data-metric-set-label]")?.textContent).toBe("Starter metrics from your work so far");
});
it("leads the status with the agent's written status when there is one", async () => {
mocks.api.statusReport.mockResolvedValue(statusReportFixture());
await render();
await flush();
const status = bar().querySelector<HTMLElement>("[data-bar-status]")!;
expect(status.querySelector("[data-agent-status]")?.textContent).toContain("Written by CodexCoder · 2 days ago");
expect(status.querySelector("[data-derived-status]")?.textContent).toContain("9 of 20 investors contacted, 45% of target");
expect(status.querySelector("[data-ask-for-update]")?.textContent).toBe("Ask CodexCoder for an update");
});
it("records a new reading in one step", async () => {
await render();
const form = bar().querySelector<HTMLFormElement>('form[aria-label="Record a new reading"]')!;
await act(async () => setInputValue(form.querySelector("input")!, "11"));
await act(async () => buttonByText("Record", form)!.click());
await flush();
expect(mocks.api.update).toHaveBeenCalledExactlyOnceWith("resp-fundraising", { metricCurrent: 11 });
expect(form.textContent).toContain("Recorded.");
});
it("edits the bar in a dialog", async () => {
await render();
await act(async () => buttonByText("Edit the bar", bar())!.click());
const dialog = document.body.querySelector<HTMLElement>('[role="dialog"]')!;
expect(dialog.textContent).toContain("Edit the bar");
await act(async () => buttonByText("Save the bar", dialog)!.click());
await flush();
expect(mocks.api.update).toHaveBeenCalledExactlyOnceWith("resp-fundraising", {
standard: "Twenty qualified investors contacted before the partner meeting in December.",
metricKind: "volume",
metricName: "Investors contacted",
metricTarget: 20,
metricDirection: "at_least",
metricUnit: null,
metricLow: null,
metricHigh: null,
});
});
it("flags a stale number and points its signal at the bar", async () => {
await render(lpUpdatesDetail.id);
const card = bar();
expect(card.textContent).toContain("36 days");
expect(card.textContent).toContain("vs. at most 30 days");
expect(card.textContent).toContain("Not updated in 19 days");
expect(card.textContent).toContain("At risk");
const stale = section("Across the work").querySelector('a[href="#responsibility-bar"]');
expect(stale?.textContent).toContain("Days since the last LP letter was last updated 19 days ago");
});
it("shows the owner's override with its note, secondary to the number", async () => {
await render(boardReportingDetail.id);
const card = bar();
expect(card.querySelector('[title="Set by hand"]')?.textContent).toContain("At risk");
expect(card.textContent).toContain("Set by hand. From the number alone it is on track.");
expect(card.textContent).toContain("The Q4 deck depends on numbers finance has not closed yet.");
expect(buttonByText("Change or clear", card)).toBeDefined();
});
it("says when there is no reading yet", async () => {
await render(hiringDetail.id);
expect(bar().textContent).toContain("No reading yet");
expect(bar().textContent).toContain("The agents working on this keep the number current; you can record one too.");
});
});
describe("ResponsibilityDetail: the work, skills and artifacts", () => {
it("lists the bubbled-up signals, each opening what it refers to", async () => {
await render();
const summary = section("Across the work");
expect(summary.querySelector('a[href="/projects/project-deck"]')?.textContent).toContain("Investor update deck is 3 days past its target date");
expect(summary.querySelector('a[href="/issues/task-blocked"]')?.textContent).toContain("Get the cap table from counsel is blocked");
expect(summary.querySelector('a[href="/routines/routine-weekly"]')).not.toBeNull();
expect(summary.querySelector('button[aria-label="Give Get the cap table from counsel is blocked to an agent"]')).not.toBeNull();
expect(summary.querySelector('button[aria-label="Give Investor update deck is 3 days past its target date to an agent"]')).not.toBeNull();
});
it("lists projects with their target dates and links", async () => {
await render();
const projects = section("Projects");
expect(projects.querySelector('a[href^="/projects/"]')?.textContent).toContain("Investor update deck");
expect(projects.textContent).toContain("Late · Nov 10");
expect(projects.querySelector('button[aria-label="Remove Investor update deck from this responsibility"]')).not.toBeNull();
});
it("calls out blocked tasks first, explains project membership, and collapses done work", async () => {
await render();
const tasks = section("Tasks");
expect(tasks.textContent).toContain("1 task is blocked.");
const titles = [...tasks.querySelectorAll("ul a[href^='/issues/']")].map((link) => link.textContent);
expect(titles[0]).toContain("Get the cap table from counsel");
expect(tasks.textContent).toContain("Here through Investor update deck");
expect(tasks.querySelector('button[aria-label="Remove Get the cap table from counsel from this responsibility"]')).toBeNull();
expect(tasks.querySelector('button[aria-label="Remove Ask Dana for an intro to the lead from this responsibility"]')).not.toBeNull();
expect(tasks.textContent).not.toContain("Send the October update");
await act(async () => buttonByText("Show 1 done", tasks)!.click());
expect(tasks.textContent).toContain("Send the October update");
});
it("removes a link without deleting the task, and can undo it", async () => {
await render();
const remove = host.querySelector<HTMLButtonElement>('button[aria-label="Remove Ask Dana for an intro to the lead from this responsibility"]')!;
await act(async () => remove.click());
await flush();
expect(mocks.api.unlink).toHaveBeenCalledExactlyOnceWith("resp-fundraising", "link-task-intro");
const notice = host.querySelector('[role="status"]')!;
expect(notice.textContent).toContain("Removed “Ask Dana for an intro to the lead” from this responsibility. It still exists");
await act(async () => buttonByText("Undo", notice)!.click());
await flush();
expect(mocks.api.link).toHaveBeenCalledExactlyOnceWith("resp-fundraising", { issueId: "task-intro" });
});
it("lists routines", async () => {
await render();
expect(section("Routines").querySelector('a[href="/routines/routine-weekly"]')?.textContent).toContain("Weekly investor pipeline review");
});
it("lists the skills of the agents doing the work as cards, with who holds each", async () => {
await render();
const skills = section("Skills");
expect(skills.querySelectorAll('[data-testid="responsibility-skills"] > li [data-slot="card"]')).toHaveLength(2);
expect(skills.querySelector('a[href="/skills/investor-research"]')?.textContent).toContain("Investor research");
expect(skills.querySelector('[aria-label="Held by CodexCoder, CTO"]')).not.toBeNull();
expect(skills.querySelector('a[href="/skills/deck-builder"]')).not.toBeNull();
});
it("shows a skill filed by hand, lets the person remove it, and offers to add one", async () => {
const filed = {
linkId: "link-skill-pitch", computed: false, id: "skill-pitch", key: "paperclip/pitch", slug: "pitch",
name: "Pitch coach", description: "Rehearses a pitch.", tagline: null, iconUrl: null, color: null, agentIds: [],
};
mocks.api.get.mockImplementation(async (id: string) => ({
...RESPONSIBILITY_DETAIL_FIXTURES[id], skills: [...RESPONSIBILITY_DETAIL_FIXTURES[id]!.skills, filed],
}));
await render();
const skills = section("Skills");
expect(skills.querySelectorAll('[data-testid="responsibility-skills"] > li [data-slot="card"]')).toHaveLength(3);
expect(skills.textContent).toContain("Filed here");
expect(buttonByText("Add existing skill", skills)).not.toBeNull();
// Only the skill filed by hand can be removed; the computed ones come from the agents.
expect(skills.querySelectorAll('button[aria-label$="from this responsibility"]')).toHaveLength(1);
await act(async () => skills.querySelector<HTMLButtonElement>('button[aria-label="Remove Pitch coach from this responsibility"]')!.click());
await flush();
expect(mocks.api.unlink).toHaveBeenCalledExactlyOnceWith("resp-fundraising", "link-skill-pitch");
});
it("lists artifacts newest first, each opening in its task, and says the list is cut short", async () => {
await render();
const artifacts = section("Artifacts");
expect(artifacts.querySelector("h2")?.textContent).toContain("63");
const cards = [...artifacts.querySelectorAll('[data-testid="artifact-card"]')];
expect(cards.map((card) => card.getAttribute("href"))).toEqual([
"/issues/PAP-42#document-update",
"/issues/PAP-43#attachment-pipeline",
"/issues/PAP-30#document-terms",
]);
expect(artifacts.querySelector('a[href="/issues/PAP-43"]')?.textContent).toContain("Ask Dana for an intro to the lead");
expect(artifacts.textContent).toContain("Showing the newest 3 of 63.");
});
it("says what belongs in each empty section", async () => {
await render(hiringDetail.id);
expect(section("Across the work").textContent).toContain("Nothing to report yet.");
expect(section("Projects").textContent).toContain("No projects yet. A project groups the tasks that move this number");
expect(section("Tasks").textContent).toContain("No open tasks. Create one for an agent, or add a task you already have.");
expect(section("Routines").textContent).toContain("A routine is work that repeats");
expect(section("Skills").textContent).toContain("No skills yet.");
expect(section("Artifacts").textContent).toContain("Nothing produced yet.");
expect(host.querySelector("header")?.textContent).toContain("No agent is working on this yet.");
});
});
describe("artifactsTruncationNote", () => {
it("says how many there are, or that the count stopped", () => {
expect(artifactsTruncationNote(50, 312)).toBe("Showing the newest 50 of 312.");
expect(artifactsTruncationNote(50, 1000)).toBe("Showing the newest 50 of 1,000 or more.");
});
});
describe("describeLinkError", () => {
it("explains an item that is gone or out of reach", () => {
expect(describeLinkError(new ApiError("not found", 404, { error: "Task not found" }), "task")).toBe(
"That task is no longer available to you. It may have been deleted or made private.",
);
});
});