Files
PaperClipAI/ui/src/lib/responsibility-views.test.ts
T
43b2d8be22 feat(dashboard): add an experimental areas and responsibilities dashboard (#22069)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The dashboard is the first page a person sees in a company
> - The classic dashboard shows agents, runs, costs and recent tasks
> - It does not show what the person is responsible for, or if that work
goes well
> - People think in areas, such as Fundraising or Customers, and in the
things they own in each area
> - This pull request adds a dashboard built on areas and
responsibilities, behind an experimental setting that is off by default
> - The benefit is that a person sees what they own, how it is going,
and what agents do for it, on one page

## Linked Issues or Issue Description

No public issue exists for this work. The description follows the
feature request template.

**Subsystem affected**

Dashboard, navigation, the task conversation, routines, and the instance
experimental settings.

**Problem or motivation**

The classic dashboard counts agents and tasks. It does not say what a
person owns or if it goes well. People who run a company with agents
want to see their areas, the responsibilities in each area, the bar each
one must meet, and the agents and routines that serve it.

**Proposed solution**

A person owns responsibilities. Each responsibility belongs to an area
and has a bar, a number to reach. Projects, tasks and routines link to a
responsibility, and the page shows its status from those links. An agent
can interview the person and draft the dashboard. The person accepts or
declines each change, and any change can be undone from a saved version.

**Alternatives considered**

Add the same data to the classic dashboard. That page is a fixed set of
cards for company activity, so a second, person-centred page is clearer.
The setting lets a person pick one of the two.

**Roadmap alignment**

This is an experimental feature behind `enableResponsibilities`. It is
off by default and changes nothing for a person who leaves it off.

## What Changed

- Add the setting "Areas & Responsibilities dashboard"
(`enableResponsibilities`, off by default). On, Dashboard in the sidebar
opens the new page, and the classic dashboard link is not shown in the
sidebars or the command palette. Off, nothing changes.
- Add tables and migrations 0492 to 0497 for areas, responsibilities,
links to work, metrics, status reports, saved dashboard versions, and
model-call records for summaries.
- Add the API: areas, responsibilities, links, bars, metrics, status
reports, summaries, runs, automation, and the dashboard conversation
with versions and undo. Each route checks company access and writes to
the activity log.
- Add four task conversations with an agent: about a bar, about an
automation, about a routine, and about the whole dashboard. The agent
proposes a change. Nothing applies until a person accepts it.
- Add standing checks: routines that an agent carries out on its
heartbeat and reports.
- Add the Dashboard page: search, counts, areas that open and close, a
primary New area button, and a message box at the bottom of the page.
Add the responsibility page with its bar, metrics, work and routines.
- Add the Paperclip skill sections and runner API entries that let an
agent use these routes. The runner skill inventory is regenerated (166
to 174 rows).
- Keep the new runner API tests in their own file so
`runner-api.test.ts` stays at 985 lines.
- Onboarding is not changed. The onboarding changes that build on this
work are a separate pull request.

## Verification

- Type checks pass for `packages/db`, `packages/shared`, `server` (all
layers) and `ui`.
- `pnpm --filter @paperclipai/db check:migrations` passes. A new
`drizzle-kit generate` run produces no further change.
- Tests for every changed file pass: 26 server test files (3,009 tests),
116 UI test files (1,991 tests) and 28 shared test files (432 tests).
- The runner capability inventory checks pass.
- I started the app on a local database that already held earlier data.
Master's new migrations and these migrations applied without error. With
the setting on, the Dashboard and a responsibility page loaded with no
console or server errors. The More menu and the command palette show one
Dashboard.
- I did not run `pnpm verify`, the full local suite, or the browser
suites. Required CI covers them.
- The agent conversations are tested with simulated agents. No real
model has run them.

## Risks

- Medium. The change is large, and the setting is off by default. With
it off, the new routes refuse requests and the UI is unchanged.
- Migrations only add tables and columns. Two replace a CHECK
constraint, and one builds an index `CONCURRENTLY`. These two have the
`online_compatible` override with a reason in the file, and the second
one is listed in `MIGRATIONS_WITH_TOP_LEVEL_STATEMENTS`.
- Master can add migrations before this merges. The migrations then need
new numbers.
- `responsibilities.ts` (1,663 lines), `responsibility-summaries.ts`
(1,239 lines) and one Storybook fixture file (1,305 lines) are new files
over 1,000 lines. They each keep one cohesive unit together: the service
for one table family, the model-call path for summaries, and the
fixtures that the stories share. No existing file crosses 1,000 lines.

> 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`.

## Model Used

- Anthropic Claude: Claude Fable 5.2 (`claude-fable-5-2`) wrote most of
the change, with Claude Sonnet 5.5 (`claude-sonnet-5-5`) for the final
steps. Both used tool use, code execution and browser checks.

## 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
- [ ] 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
- [ ] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Scott Tong <scott@scottsmbpm5max.lan>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-17 20:45:44 -08:00

464 lines
24 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from "vitest";
import {
allOnTrackOverviewFixture,
boardReportingOverridden,
fundraisingBehind,
fundraisingDetail,
hiringDetail,
hiringNotMeasured,
homeOverviewFixture,
lpUpdatesStale,
metricFixture,
nothingMeasuredOverviewFixture,
portfolioOnTrack,
responsibilityDetailFixture,
responsibilityFixture,
responsibilityOverviewFixture,
RESPONSIBILITY_FIXTURE_NOW,
} from "../../storybook/fixtures/responsibilities";
import {
boardAreaRows,
capList,
dashboardSnapshot,
DASHBOARD_DEFAULT_VIEW,
DASHBOARD_VIEW_OPTIONS,
describeMetricGap,
describeMissingMeasure,
describeReadingValue,
describeTargetPhrase,
explainResponsibilityStatus,
RESPONSIBILITY_PAGE_DEFAULT_VIEW,
RESPONSIBILITY_PAGE_VIEW_OPTIONS,
workBearings,
exceptionReason,
onTrackShare,
outlineAreaGroups,
overallStanding,
readStoredView,
responsibilityExceptions,
responsibilityWorkCounts,
responsibilityWorkList,
writeStoredView,
} from "./responsibility-views";
const counts = (behind: number, atRisk: number, onTrack: number, notMeasured: number) => ({
behind,
at_risk: atRisk,
on_track: onTrack,
not_measured: notMeasured,
});
describe("overallStanding", () => {
it("is behind when anything is behind, naming what is at risk too", () => {
expect(overallStanding(counts(1, 3, 5, 0))).toEqual({
health: "behind",
sentence: "1 responsibility is behind and 3 are at risk.",
total: 9,
});
expect(overallStanding(counts(2, 1, 0, 0)).sentence).toBe("2 responsibilities are behind and 1 is at risk.");
expect(overallStanding(counts(2, 0, 4, 1)).sentence).toBe("2 responsibilities are behind.");
});
it("is at risk only when more are at risk than on track", () => {
expect(overallStanding(counts(0, 3, 1, 0))).toMatchObject({ health: "at_risk", sentence: "Nothing is behind. 3 responsibilities are at risk." });
expect(overallStanding(counts(0, 1, 1, 0))).toMatchObject({ health: "on_track", sentence: "Nothing is behind. 1 responsibility is at risk." });
expect(overallStanding(counts(0, 1, 3, 0)).health).toBe("on_track");
});
it("is on track when nothing is behind or at risk", () => {
expect(overallStanding(counts(0, 0, 4, 0))).toMatchObject({ health: "on_track", sentence: "Everything you own is on track." });
expect(overallStanding(counts(0, 0, 4, 2)).sentence).toBe("Nothing is behind or at risk. 2 responsibilities are not measured yet.");
expect(overallStanding(counts(0, 0, 1, 1)).sentence).toBe("Nothing is behind or at risk. 1 responsibility is not measured yet.");
});
it("is not measured when nothing is, and says when there is nothing at all", () => {
expect(overallStanding(counts(0, 0, 0, 2))).toMatchObject({ health: "not_measured", sentence: "Nothing you own is measured yet." });
expect(overallStanding(counts(0, 0, 0, 0))).toEqual({ health: "not_measured", sentence: "You do not own any responsibilities yet.", total: 0 });
});
it("reads the overview fixtures", () => {
expect(overallStanding(homeOverviewFixture.totals.byHealth).sentence).toBe("1 responsibility is behind and 2 are at risk.");
expect(overallStanding(allOnTrackOverviewFixture.totals.byHealth).sentence).toBe("Everything you own is on track.");
expect(overallStanding(nothingMeasuredOverviewFixture.totals.byHealth).health).toBe("not_measured");
});
});
describe("the Dashboard's derivations", () => {
it("states the share on track as a rounded percentage", () => {
expect(onTrackShare(2, 3)).toEqual({ percent: 67, label: "67% on track" });
expect(onTrackShare(0, 2)?.label).toBe("0% on track");
expect(onTrackShare(0, 0)).toBeNull();
});
it("groups the Outline by area, behind first, with the share on track and only active responsibilities", () => {
const letGo = responsibilityFixture({ id: "resp-old", areaId: "area-portfolio", status: "let_go", rollup: { health: "on_track" } });
const groups = outlineAreaGroups(homeOverviewFixture.areas, [...homeOverviewFixture.responsibilities, letGo]);
expect(groups.map((group) => [group.area?.title ?? null, group.items.map((item) => item.id), group.ownedLabel, group.share?.label])).toEqual([
["Fundraising", [fundraisingBehind.id, lpUpdatesStale.id], "2 responsibilities you own", "0% on track"],
["Portfolio", [portfolioOnTrack.id], "1 responsibility you own", "100% on track"],
["Team", [hiringNotMeasured.id], "1 responsibility you own", "0% on track"],
[null, [boardReportingOverridden.id], "1 responsibility you own", "0% on track"],
]);
const kept = outlineAreaGroups(homeOverviewFixture.areas, homeOverviewFixture.responsibilities, new Set(["area-legal"]));
expect(kept.find((group) => group.area?.id === "area-legal")).toMatchObject({ items: [], ownedLabel: "0 responsibilities you own", share: null });
});
it("counts the four numbers with one exception each, from the real totals", () => {
expect(dashboardSnapshot(homeOverviewFixture)).toEqual({
areas: { value: 3, line: "1 with something behind", alert: true },
responsibilities: { value: 5, line: "1 behind", alert: true },
projects: { value: 4, line: "1 late", alert: true },
tasks: { value: 10, line: "1 blocked", alert: true },
});
expect(dashboardSnapshot(allOnTrackOverviewFixture)).toEqual({
areas: { value: 2, line: "None with anything behind", alert: false },
responsibilities: { value: 3, line: "None behind", alert: false },
projects: { value: 2, line: "None late", alert: false },
tasks: { value: 4, line: "None blocked", alert: false },
});
});
it("lists only what needs a look, behind first, each with its first attention signal", () => {
const { exceptions, onTrack } = responsibilityExceptions(homeOverviewFixture.areas, homeOverviewFixture.responsibilities);
expect(exceptions.map((entry) => [entry.responsibility.id, entry.reason, entry.signal?.text ?? null])).toEqual([
[fundraisingBehind.id, "behind", "Investor update deck is 3 days past its target date"],
[lpUpdatesStale.id, "at_risk", "Days since the last LP letter was last updated 19 days ago"],
[boardReportingOverridden.id, "at_risk", null],
[hiringNotMeasured.id, "not_measured", null],
]);
expect(onTrack.map((line) => [line.label, line.responsibilities.map((item) => item.id)])).toEqual([
["Portfolio: 1 of 1 on track", [portfolioOnTrack.id]],
]);
});
it("collapses everything on track to one line per area", () => {
const { exceptions, onTrack } = responsibilityExceptions(allOnTrackOverviewFixture.areas, allOnTrackOverviewFixture.responsibilities);
expect(exceptions).toEqual([]);
expect(onTrack.map((line) => line.label)).toEqual(["Fundraising: 2 of 2 on track", "Portfolio: 1 of 1 on track"]);
});
it("counts an on-track number that has gone stale as an exception", () => {
const stale = responsibilityFixture({
...portfolioOnTrack,
rollup: { ...portfolioOnTrack.rollup, metric: metricFixture({ ...portfolioOnTrack.rollup.metric!, stale: true }) },
});
expect(exceptionReason(stale)).toBe("stale");
const overview = responsibilityOverviewFixture([stale]);
const { exceptions, onTrack } = responsibilityExceptions(overview.areas, overview.responsibilities);
expect(exceptions.map((entry) => entry.reason)).toEqual(["stale"]);
expect(onTrack).toEqual([{ areaId: "area-portfolio", label: "Portfolio: 1 of 1 on track", responsibilities: [] }]);
});
});
describe("the responsibility page's derivations", () => {
it("merges projects, tasks and routines, anything needing attention first, finished ones counted", () => {
const { items, finished } = responsibilityWorkList(fundraisingDetail, RESPONSIBILITY_FIXTURE_NOW);
expect(items.map((item) => [item.kind, item.id, item.attention, item.note])).toEqual([
["project", "project-deck", "Late · Nov 10", null],
["task", "task-blocked", "Blocked", null],
["project", "project-pipeline", null, "Due Dec 15"],
["task", "task-draft", null, null],
["task", "task-intro", null, null],
["routine", "routine-weekly", null, null],
]);
expect(items.map((item) => item.href)).toEqual([
"/projects/investor-update-deck",
"/issues/PAP-41",
"/projects/lead-investor-pipeline",
"/issues/PAP-42",
"/issues/PAP-43",
"/routines/routine-weekly",
]);
expect(finished).toBe(1);
});
it("puts a routine that failed first and marks a paused one", () => {
const detail = responsibilityDetailFixture(
responsibilityFixture({
rollup: {
workSummary: [
{ kind: "routine_failed", tone: "attention", text: "Weekly digest failed on its last run", refType: "routine", refId: "routine-digest", count: 1 },
{ kind: "routine_failed", tone: "attention", text: "2 more routines failed on the last run", refType: null, refId: null, count: 2 },
],
routines: 2,
},
}),
{
routines: [
{ linkId: "l1", membership: "direct", id: "routine-paused", title: "Monthly close", status: "paused", assigneeAgentId: null, projectId: null, lastRun: null },
{ linkId: "l2", membership: "direct", id: "routine-digest", title: "Weekly digest", status: "active", assigneeAgentId: null, projectId: null, lastRun: null },
{ linkId: "l3", membership: "direct", id: "routine-old", title: "Old report", status: "archived", assigneeAgentId: null, projectId: null, lastRun: null },
],
},
);
const list = responsibilityWorkList(detail, RESPONSIBILITY_FIXTURE_NOW);
expect(list.items.map((item) => [item.id, item.attention, item.note])).toEqual([
["routine-digest", "Failed on its last run", null],
["routine-paused", null, "Paused"],
]);
expect(list.finished).toBe(1);
expect(responsibilityWorkCounts(detail).routines).toEqual({ value: 2, line: "3 failed, 1 paused", alert: true });
});
it("counts the work with one exception line each", () => {
expect(responsibilityWorkCounts(fundraisingDetail)).toEqual({
projects: { value: 2, line: "1 late", alert: true },
tasks: { value: 4, line: "1 blocked, 2 with agents", alert: true },
routines: { value: 1, line: "None failed or paused", alert: false },
});
expect(responsibilityWorkCounts(hiringDetail)).toEqual({
projects: { value: 0, line: "None late", alert: false },
tasks: { value: 0, line: "None blocked, none with agents", alert: false },
routines: { value: 0, line: "None failed or paused", alert: false },
});
});
it("caps a list and says how many more", () => {
expect(capList([1, 2, 3, 4], 3)).toEqual({ shown: [1, 2, 3], more: 1 });
expect(capList([1], 3)).toEqual({ shown: [1], more: 0 });
});
});
describe("remembering the view", () => {
afterEach(() => {
vi.restoreAllMocks();
localStorage.clear();
});
it("reads back a stored choice and ignores anything it does not know", () => {
expect(readStoredView("view-test", DASHBOARD_VIEW_OPTIONS)).toBe("full");
writeStoredView("view-test", "board");
expect(readStoredView("view-test", DASHBOARD_VIEW_OPTIONS)).toBe("board");
writeStoredView("view-test", "spreadsheet");
expect(readStoredView("view-test", DASHBOARD_VIEW_OPTIONS)).toBe("full");
});
it("opens on Outline v2 and on One screen v2 when nothing usable is stored", () => {
expect(DASHBOARD_DEFAULT_VIEW).toBe("outline_v2");
expect(RESPONSIBILITY_PAGE_DEFAULT_VIEW).toBe("one_screen_v2");
expect(readStoredView("view-test", DASHBOARD_VIEW_OPTIONS, DASHBOARD_DEFAULT_VIEW)).toBe("outline_v2");
writeStoredView("view-test", "spreadsheet");
expect(readStoredView("view-test", DASHBOARD_VIEW_OPTIONS, DASHBOARD_DEFAULT_VIEW)).toBe("outline_v2");
writeStoredView("view-test", "outline");
expect(readStoredView("view-test", DASHBOARD_VIEW_OPTIONS, DASHBOARD_DEFAULT_VIEW)).toBe("outline");
expect(readStoredView("page-test", RESPONSIBILITY_PAGE_VIEW_OPTIONS, RESPONSIBILITY_PAGE_DEFAULT_VIEW)).toBe("one_screen_v2");
});
it("falls back to the full view when storage throws", () => {
vi.spyOn(Storage.prototype, "getItem").mockImplementation(() => {
throw new Error("blocked");
});
vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => {
throw new Error("blocked");
});
expect(() => writeStoredView("view-test", "board")).not.toThrow();
expect(readStoredView("view-test", DASHBOARD_VIEW_OPTIONS)).toBe("full");
});
});
// ---------------------------------------------------------------------------
// Board: why each responsibility has its status
// ---------------------------------------------------------------------------
describe("describeMetricGap", () => {
const metric = (overrides: Parameters<typeof metricFixture>[0]) => metricFixture(overrides);
it("says how far a higher-is-better number is from its target, in its own unit", () => {
expect(describeMetricGap(metric({ current: 9, target: 20 }))).toBe("11 short of 20");
expect(describeMetricGap(metric({ current: 4, target: 10, unit: "accounts" }))).toBe("6 accounts short of 10 accounts");
expect(describeMetricGap(metric({ current: 12000, target: 20000, unit: "$" }))).toBe("$8,000 short of $20,000");
expect(describeMetricGap(metric({ current: 45, target: 60, unit: "%" }))).toBe("15 points short of 60%");
expect(describeMetricGap(metric({ current: 21, target: 20 }))).toBe("1 past the target of 20");
expect(describeMetricGap(metric({ current: 4, target: 4 }))).toBe("Right at the target of 4");
expect(describeMetricGap(metric({ current: 0.3, target: 0.1 + 0.2 }))).toBe("Right at the target of 0.3");
});
it("says how far a lower-is-better number is over or inside its limit", () => {
expect(describeMetricGap(metric({ current: 36, target: 30, unit: "days", direction: "at_most" }))).toBe("6 days over the limit of 30 days");
expect(describeMetricGap(metric({ current: 20, target: 24, unit: "hours", direction: "at_most" }))).toBe("4 hours inside the limit of 24 hours");
expect(describeMetricGap(metric({ current: 30, target: 30, unit: "days", direction: "at_most" }))).toBe("Right at the limit of 30 days");
});
it("reads a yes-or-no bar and a range", () => {
expect(describeMetricGap(metric({ kind: "yes_no", current: 1, target: null, unit: null, direction: null }))).toBe("Yes");
expect(describeMetricGap(metric({ kind: "yes_no", current: 0, target: null, unit: null, direction: null }))).toBe("Not yet");
const range = { kind: "range" as const, target: null, low: 10, high: 20, direction: null };
expect(describeMetricGap(metric({ ...range, current: 8 }))).toBe("2 below the range 10–20");
expect(describeMetricGap(metric({ ...range, current: 25, unit: "days" }))).toBe("5 days above the range 10–20 days");
expect(describeMetricGap(metric({ ...range, current: 12 }))).toBe("Inside the range 10–20");
});
it("is null without a reading or a target", () => {
expect(describeMetricGap(metric({ current: null }))).toBeNull();
expect(describeMetricGap(metric({ current: 3, target: null }))).toBeNull();
});
});
describe("the number on a card", () => {
it("keeps the value and its unit together and phrases the bar beneath it", () => {
const hours = metricFixture({ current: 20, target: 24, unit: "hours", direction: "at_most" });
expect(describeReadingValue(hours)).toBe("20 hours");
expect(describeTargetPhrase(hours)).toBe("limit 24 hours");
expect(describeTargetPhrase(metricFixture({ current: 9, target: 20 }))).toBe("of 20");
expect(describeTargetPhrase(metricFixture({ current: null, target: 20 }))).toBe("target 20");
expect(describeTargetPhrase(metricFixture({ target: null }))).toBe("no target set");
expect(describeTargetPhrase(metricFixture({ kind: "range", target: null, low: 1, high: 3 }))).toBe("range 1–3");
expect(describeTargetPhrase(metricFixture({ kind: "range", target: null, low: 18, high: 24, unit: "months" }))).toBe("range 18–24 months");
expect(describeTargetPhrase(metricFixture({ kind: "range", target: null, low: 10, high: 20, unit: "$" }))).toBe("range $10–$20");
expect(describeTargetPhrase(metricFixture({ kind: "yes_no", target: null }))).toBeNull();
expect(describeReadingValue(metricFixture({ kind: "yes_no", current: 1 }))).toBe("Yes");
expect(describeReadingValue(metricFixture({ current: null }))).toBeNull();
});
it("says what is missing to measure it", () => {
expect(describeMissingMeasure(null)).toBe("No number set: add what you measure and a target.");
expect(describeMissingMeasure(metricFixture({ name: "Offers accepted", target: null }))).toBe("No target set for offers accepted.");
expect(describeMissingMeasure(metricFixture({ name: "Offers accepted", target: 2 }))).toBe("No reading of offers accepted yet.");
expect(describeMissingMeasure(metricFixture({ kind: "yes_no", target: null, current: null }))).toBe("No answer yet.");
expect(describeMissingMeasure(metricFixture({ name: "Runway", kind: "range", target: null, low: null, high: 18 }))).toBe("No range set for runway.");
expect(describeMissingMeasure(metricFixture({ current: 3 }))).toBeNull();
});
});
describe("explainResponsibilityStatus", () => {
it("behind: the gap, then what in the work holds it back, by name", () => {
expect(explainResponsibilityStatus(fundraisingBehind)).toEqual({
gap: "11 short of 20",
missing: null,
lines: [
{ kind: "project_late", role: "holding", text: "Investor update deck is 3 days past its target date" },
{ kind: "task_blocked", role: "holding", text: "Get the cap table from counsel is blocked" },
],
more: 0,
});
});
it("at risk: a stale reading and an unassigned task both hold it back; the rest is counted", () => {
const why = explainResponsibilityStatus(lpUpdatesStale, 1);
expect(why.gap).toBe("6 days over the limit of 30 days");
expect(why.lines).toEqual([{ kind: "metric_stale", role: "holding", text: "Days since the last LP letter was last updated 19 days ago" }]);
expect(why.more).toBe(1);
});
it("behind with nothing flagged: says what work there is and who has it", () => {
const quiet = responsibilityFixture({
rollup: {
health: "behind",
metric: metricFixture({ current: 2, target: 10, attainment: 0.2 }),
workSummary: [
{ kind: "tasks_open_agent", tone: "neutral", text: "2 open tasks with Chief of staff", refType: "agent", refId: "agent-cos", count: 2 },
],
openTasks: 2,
agentTasks: 2,
},
});
expect(explainResponsibilityStatus(quiet).lines).toEqual([
{ kind: "tasks_open_agent", role: "note", text: "2 open tasks with Chief of staff" },
]);
});
it("behind with nothing filed under it: that is the reason", () => {
const empty = responsibilityFixture({ rollup: { health: "at_risk", metric: metricFixture({ current: 16, target: 20, attainment: 0.8 }) } });
expect(explainResponsibilityStatus(empty).lines).toEqual([
{ kind: "no_work", role: "holding", text: "No work is filed under this yet." },
]);
});
it("not measured: what is missing, and that no work is filed under it", () => {
expect(explainResponsibilityStatus(hiringNotMeasured)).toEqual({
gap: null,
missing: "No reading of offers accepted yet.",
lines: [{ kind: "no_work", role: "holding", text: "No work is filed under this yet." }],
more: 0,
});
});
it("on track: how far past the target, and what keeps it there", () => {
expect(explainResponsibilityStatus(portfolioOnTrack)).toEqual({
gap: "1 past the target of 8",
missing: null,
lines: [{ kind: "tasks_completed_recently", role: "keeping", text: "5 tasks completed in the last 7 days" }],
more: 0,
});
});
it("a status set by hand leads with the owner's note", () => {
const why = explainResponsibilityStatus(boardReportingOverridden);
expect(why.gap).toBe("Right at the target of 4");
expect(why.lines[0]).toEqual({
kind: "override",
role: "note",
text: "You marked it at risk: The Q4 deck depends on numbers finance has not closed yet.",
});
});
});
describe("boardAreaRows", () => {
it("splits each area's responsibilities into the four status columns, keeping the share on track", () => {
const rows = boardAreaRows(homeOverviewFixture.areas, homeOverviewFixture.responsibilities);
expect(rows.map((row) => [row.area?.id ?? null, row.ownedLabel, row.share?.label ?? null])).toEqual([
["area-fundraising", "2 responsibilities you own", "0% on track"],
["area-portfolio", "1 responsibility you own", "100% on track"],
["area-team", "1 responsibility you own", "0% on track"],
[null, "1 responsibility you own", "0% on track"],
]);
expect(Object.fromEntries(Object.entries(rows[0]!.byHealth).map(([health, items]) => [health, items.map((item) => item.id)]))).toEqual({
behind: ["resp-fundraising"],
at_risk: ["resp-lp-updates"],
on_track: [],
not_measured: [],
});
});
});
describe("workBearings", () => {
const names = (id: string) => ({ "agent-codex": "CodexCoder" })[id];
it("marks what holds the number back first, then what moves it, then the rest", () => {
const marked = workBearings(fundraisingDetail, RESPONSIBILITY_FIXTURE_NOW, names);
expect(marked.map((entry) => [entry.item.id, entry.bearing, entry.reason])).toEqual([
["project-deck", "holding", "3 days late (due Nov 10)"],
["task-blocked", "holding", "Blocked"],
["task-draft", "moving", "In progress with CodexCoder"],
["routine-weekly", "moving", "Active, last run succeeded on 2026-11-10, next run 2026-11-17"],
["project-pipeline", "neutral", "Not started, due Dec 15"],
["task-intro", "neutral", "With you"],
]);
});
it("holds back unassigned tasks, paused routines and routines no agent runs; lists recent completions last", () => {
const quiet = { ...fundraisingBehind, rollup: { ...fundraisingBehind.rollup, workSummary: [], overdueProjects: [] } };
const detail = responsibilityDetailFixture(quiet, {
projects: [
{ linkId: "l1", id: "p-soon", name: "Partner meeting prep", status: "in_progress", targetDate: "2026-11-18", leadAgentId: null, archivedAt: null, progress: null },
],
tasks: [
{ id: "t-nobody", identifier: "PAP-1", title: "Book the room", status: "todo", assigneeAgentId: null, assigneeUserId: null, projectId: null, membership: "direct", linkId: "l2", updatedAt: new Date("2026-11-12T08:00:00Z") },
{ id: "t-done", identifier: "PAP-2", title: "Send the teaser", status: "done", assigneeAgentId: "agent-codex", assigneeUserId: null, projectId: null, membership: "direct", linkId: "l3", updatedAt: new Date("2026-11-11T08:00:00Z") },
{ id: "t-old", identifier: "PAP-3", title: "Old work", status: "done", assigneeAgentId: null, assigneeUserId: null, projectId: null, membership: "direct", linkId: "l4", updatedAt: new Date("2026-10-01T08:00:00Z") },
{ id: "t-review", identifier: "PAP-4", title: "Check the numbers", status: "in_review", assigneeAgentId: null, assigneeUserId: "someone-else", projectId: null, membership: "direct", linkId: "l5", updatedAt: new Date("2026-11-12T08:00:00Z") },
],
routines: [
{ linkId: "l6", membership: "direct", id: "r-paused", title: "Weekly digest", status: "paused", assigneeAgentId: "agent-codex", projectId: null, lastRun: null },
{ linkId: "l7", membership: "direct", id: "r-nobody", title: "Monthly close", status: "active", assigneeAgentId: null, projectId: null, lastRun: null },
{ linkId: "l8", membership: "direct", id: "r-new", title: "Daily scan", status: "active", assigneeAgentId: "agent-codex", projectId: null, lastRun: null },
],
});
const marked = workBearings(detail, RESPONSIBILITY_FIXTURE_NOW, names);
expect(marked.map((entry) => [entry.item.id, entry.bearing, entry.reason, entry.finished])).toEqual([
["t-nobody", "holding", "Not assigned to anyone", false],
["r-paused", "holding", "Paused", false],
["r-nobody", "holding", "No agent runs it", false],
["p-soon", "moving", "Due Nov 18, in progress", false],
["t-review", "neutral", "In review with a person", false],
["r-new", "neutral", "Active", false],
["t-done", "moving", "Completed 2 days ago", true],
]);
});
it("has nothing to mark when nothing is filed", () => {
expect(workBearings(hiringDetail, RESPONSIBILITY_FIXTURE_NOW)).toEqual([]);
});
});