Files
paperclip/ui/src/lib/issue-timeline-events.test.ts
T
Dotta 68f69975a4 Harden control-plane safety and issue identifiers (#5292)
## Thinking Path

> - Paperclip relies on issue identifiers, execution policies, and agent
heartbeat rules to keep autonomous work auditable.
> - Safety checks need to reject ambiguous agent handoffs, and
identifier parsing needs to support Cloud tenant prefixes.
> - Agent instructions also need to make final-disposition rules
explicit so work does not stall in vague states.
> - This pull request isolates backend correctness and governance
hardening from the UI and recovery-system-notice branches.
> - The benefit is safer in-review transitions, better identifier
compatibility, and clearer agent operating contracts.

## What Changed

- Fixed run-aware confirmation ordering and interrupted-run state
cleanup.
- Added Cloud tenant identity bootstrap and alphanumeric issue
identifier support across shared parsing and server routes.
- Guarded agent-authored `in_review` updates unless a real review path
exists.
- Tightened heartbeat disposition instructions in adapter
utilities/default AGENTS/Paperclip skill.

## Verification

- `pnpm install --frozen-lockfile`
- `pnpm exec vitest run packages/shared/src/issue-references.test.ts
server/src/__tests__/issue-identifier-routes.test.ts
server/src/__tests__/issue-execution-policy-routes.test.ts
packages/adapter-utils/src/server-utils.test.ts` initially had the first
execution-policy test hit Vitest's 5s timeout under the parallel bundle
while the rest passed.
- `pnpm exec vitest run
server/src/__tests__/issue-execution-policy-routes.test.ts
--testTimeout=20000` passed with 10/10 tests.

- Follow-up: `pnpm run typecheck:build-gaps` passed.
- Follow-up: `pnpm --filter @paperclipai/ui typecheck` passed.
- Follow-up: `pnpm vitest run
server/src/__tests__/issue-comment-reopen-routes.test.ts
server/src/__tests__/company-portability.test.ts
server/src/__tests__/costs-service.test.ts` passed.
- Follow-up: `pnpm vitest run ui/src/context/LiveUpdatesProvider.test.ts
ui/src/lib/issue-chat-messages.test.ts
ui/src/lib/issue-reference.test.ts
ui/src/lib/issue-timeline-events.test.ts` passed.

## Risks

- Medium control-plane risk: in-review update validation changes agent
behavior. The error message is explicit and tests cover allowed review
paths.

## 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 07:49:47 -05:00

233 lines
5.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { ActivityEvent } from "@paperclipai/shared";
import { extractIssueTimelineEvents } from "./issue-timeline-events";
describe("extractIssueTimelineEvents", () => {
it("extracts and sorts status and assignee changes from issue updates", () => {
const events = extractIssueTimelineEvents([
{
id: "evt-2",
companyId: "company-1",
actorType: "user",
actorId: "local-board",
action: "issue.updated",
entityType: "issue",
entityId: "issue-1",
agentId: null,
runId: null,
createdAt: new Date("2026-03-31T12:02:00.000Z"),
details: {
assigneeAgentId: "agent-2",
assigneeUserId: null,
_previous: {
assigneeAgentId: "agent-1",
assigneeUserId: null,
},
},
},
{
id: "evt-1",
companyId: "company-1",
actorType: "user",
actorId: "local-board",
action: "issue.updated",
entityType: "issue",
entityId: "issue-1",
agentId: null,
runId: null,
createdAt: new Date("2026-03-31T12:01:00.000Z"),
details: {
status: "in_progress",
_previous: {
status: "todo",
},
},
},
{
id: "evt-ignored",
companyId: "company-1",
actorType: "user",
actorId: "local-board",
action: "issue.comment_added",
entityType: "issue",
entityId: "issue-1",
agentId: null,
runId: null,
createdAt: new Date("2026-03-31T12:03:00.000Z"),
details: {
commentId: "comment-1",
},
},
] satisfies ActivityEvent[]);
expect(events).toEqual([
{
id: "evt-1",
createdAt: new Date("2026-03-31T12:01:00.000Z"),
actorType: "user",
actorId: "local-board",
runId: null,
statusChange: {
from: "todo",
to: "in_progress",
},
},
{
id: "evt-2",
createdAt: new Date("2026-03-31T12:02:00.000Z"),
actorType: "user",
actorId: "local-board",
runId: null,
assigneeChange: {
from: {
agentId: "agent-1",
userId: null,
},
to: {
agentId: "agent-2",
userId: null,
},
},
},
]);
});
it("uses reopenedFrom when a reopen update omits _previous", () => {
const events = extractIssueTimelineEvents([
{
id: "evt-reopen",
companyId: "company-1",
actorType: "agent",
actorId: "agent-1",
action: "issue.updated",
entityType: "issue",
entityId: "issue-1",
agentId: "agent-1",
runId: "run-1",
createdAt: new Date("2026-03-31T12:01:00.000Z"),
details: {
status: "todo",
reopened: true,
reopenedFrom: "done",
source: "comment",
},
},
] satisfies ActivityEvent[]);
expect(events).toEqual([
{
id: "evt-reopen",
createdAt: new Date("2026-03-31T12:01:00.000Z"),
actorType: "agent",
actorId: "agent-1",
runId: "run-1",
statusChange: {
from: "done",
to: "todo",
},
},
]);
});
it("marks explicit follow-up timeline updates", () => {
const events = extractIssueTimelineEvents([
{
id: "evt-follow-up",
companyId: "company-1",
actorType: "agent",
actorId: "agent-1",
action: "issue.updated",
entityType: "issue",
entityId: "issue-1",
agentId: "agent-1",
runId: "run-1",
createdAt: new Date("2026-03-31T12:01:00.000Z"),
details: {
status: "todo",
reopened: true,
reopenedFrom: "done",
source: "comment",
commentId: "comment-1",
resumeIntent: true,
followUpRequested: true,
},
},
] satisfies ActivityEvent[]);
expect(events).toEqual([
{
id: "evt-follow-up",
createdAt: new Date("2026-03-31T12:01:00.000Z"),
actorType: "agent",
actorId: "agent-1",
runId: "run-1",
commentId: "comment-1",
followUpRequested: true,
statusChange: {
from: "done",
to: "todo",
},
},
]);
});
it("synthesizes non-status follow-up rows from comment activity", () => {
const events = extractIssueTimelineEvents([
{
id: "evt-comment-follow-up",
companyId: "company-1",
actorType: "agent",
actorId: "agent-1",
action: "issue.comment_added",
entityType: "issue",
entityId: "issue-1",
agentId: "agent-1",
runId: "run-1",
createdAt: new Date("2026-03-31T12:01:00.000Z"),
details: {
commentId: "comment-1",
resumeIntent: true,
followUpRequested: true,
},
},
] satisfies ActivityEvent[]);
expect(events).toEqual([
{
id: "evt-comment-follow-up",
createdAt: new Date("2026-03-31T12:01:00.000Z"),
actorType: "agent",
actorId: "agent-1",
runId: "run-1",
commentId: "comment-1",
followUpRequested: true,
},
]);
});
it("ignores issue updates without visible status or assignee transitions", () => {
const events = extractIssueTimelineEvents([
{
id: "evt-title",
companyId: "company-1",
actorType: "user",
actorId: "local-board",
action: "issue.updated",
entityType: "issue",
entityId: "issue-1",
agentId: null,
runId: null,
createdAt: new Date("2026-03-31T12:01:00.000Z"),
details: {
title: "New title",
_previous: {
title: "Old title",
},
},
},
] satisfies ActivityEvent[]);
expect(events).toEqual([]);
});
});