Files
paperclip/ui/src/lib/activity-format.test.ts
T
Dotta 454edfe81e Add recovery handoff system notices (#5289)
## Thinking Path

> - Paperclip orchestrates AI agents for zero-human companies.
> - Agent runs can end productively while the source issue still lacks a
durable final disposition.
> - That leaves the control plane unsure whether to resume, escalate, or
close the work.
> - Issue comments also need a presentation contract so system-authored
recovery notices can render as first-class thread messages without
overloading normal comments.
> - This pull request adds successful-run handoff recovery, comment
presentation metadata, and system notice rendering.
> - The benefit is stricter task liveness with clearer operator-facing
recovery state.

## What Changed

- Added successful-run handoff decisions, wake payloads, escalation
behavior, and recovery tests.
- Added issue comment presentation metadata with migration
`0078_white_darwin.sql` and shared/server/company portability support.
- Rendered recovery/system notices in issue chat with dedicated UI
components, fixtures, tests, and storybook/lab coverage.
- Included the current recovery model-profile hint patch so automatic
recovery follow-ups use the cheap profile.

## Verification

- `pnpm install --frozen-lockfile`
- `pnpm exec vitest run
server/src/services/recovery/successful-run-handoff.test.ts
ui/src/components/SystemNotice.test.tsx
ui/src/lib/system-notice-comment.test.ts
ui/src/components/IssueChatThreadSystemNotice.test.tsx`

## Risks

- Migration-bearing PR: merge this before any other branch that might
later add a migration.
- The branch touches both recovery services and issue-thread rendering,
so review should pay attention to recovery wake idempotency and comment
metadata compatibility.

## Model Used

- OpenAI GPT-5 Codex via Paperclip `codex_local` adapter, with
shell/git/GitHub CLI tool use.

## 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 run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-05-06 06:05:58 -05:00

78 lines
3.4 KiB
TypeScript

import type { Agent } from "@paperclipai/shared";
import { describe, expect, it } from "vitest";
import { formatActivityVerb, formatIssueActivityAction } from "./activity-format";
describe("activity formatting", () => {
const agentMap = new Map<string, Agent>([
["agent-reviewer", { id: "agent-reviewer", name: "Reviewer Bot" } as Agent],
["agent-approver", { id: "agent-approver", name: "Approver Bot" } as Agent],
]);
it("formats blocker activity using linked issue identifiers", () => {
const details = {
addedBlockedByIssues: [
{ id: "issue-2", identifier: "PAP-22", title: "Blocked task" },
],
removedBlockedByIssues: [],
};
expect(formatActivityVerb("issue.blockers_updated", details)).toBe("added blocker PAP-22 to");
expect(formatIssueActivityAction("issue.blockers_updated", details)).toBe("added blocker PAP-22");
});
it("formats reviewer activity using agent names", () => {
const details = {
addedParticipants: [
{ type: "agent", agentId: "agent-reviewer", userId: null },
],
removedParticipants: [],
};
expect(formatActivityVerb("issue.reviewers_updated", details, { agentMap })).toBe("added reviewer Reviewer Bot to");
expect(formatIssueActivityAction("issue.reviewers_updated", details, { agentMap })).toBe("added reviewer Reviewer Bot");
});
it("formats approver removals using user-aware labels", () => {
const details = {
addedParticipants: [],
removedParticipants: [
{ type: "user", agentId: null, userId: "local-board" },
],
};
expect(formatActivityVerb("issue.approvers_updated", details)).toBe("removed approver Board from");
expect(formatIssueActivityAction("issue.approvers_updated", details)).toBe("removed approver Board");
});
it("falls back to updated wording when reviewers are both added and removed", () => {
const details = {
addedParticipants: [
{ type: "agent", agentId: "agent-reviewer", userId: null },
],
removedParticipants: [
{ type: "agent", agentId: "agent-approver", userId: null },
],
};
expect(formatActivityVerb("issue.reviewers_updated", details, { agentMap })).toBe("updated reviewers on");
expect(formatIssueActivityAction("issue.reviewers_updated", details, { agentMap })).toBe("updated reviewers");
});
it("formats monitor activity with direct verbs", () => {
expect(formatActivityVerb("issue.monitor_scheduled")).toBe("scheduled monitor on");
expect(formatActivityVerb("issue.monitor_exhausted")).toBe("exhausted monitor on");
expect(formatIssueActivityAction("issue.monitor_triggered")).toBe("triggered a monitor");
expect(formatIssueActivityAction("issue.monitor_cleared")).toBe("cleared a monitor");
expect(formatIssueActivityAction("issue.monitor_recovery_issue_created")).toBe("created a monitor recovery issue");
});
it("uses plain next-step copy for successful-run handoff activity", () => {
expect(formatActivityVerb("issue.successful_run_handoff_required")).toBe("flagged missing next step on");
expect(formatIssueActivityAction("issue.successful_run_handoff_required")).toBe("Run finished without a clear next step");
expect(formatIssueActivityAction("issue.successful_run_handoff_resolved")).toBe("Next step chosen");
expect(formatIssueActivityAction("issue.successful_run_handoff_escalated")).toBe(
"Run finished without a next step - recovery escalated",
);
});
});