Files
PaperClipAI/ui/src/lib/interaction-audience.test.ts
T
Dotta 39206c0096 feat(ui): complete the task workspace (#12640)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The task page is the main place where people guide and review agent
work.
> - Native runner events already project into the existing task chat on
the lower stack.
> - The larger task workspace must support those events without breaking
direct adapters.
> - Legacy questions, final replies, empty transcripts, and classic
controls must keep their behavior.
> - This pull request completes the provider-neutral task workspace
experience.
> - The benefit is one coherent task surface for native and direct
execution paths.

## Linked Issues or Issue Description

Refs #12639.
Refs #12617.
Refs #12352.

**Subsystem affected**

Task chat, task detail, side panels, interaction forms, and transcript
presentation.

**Problem or motivation**

The task page does not provide one complete workspace for live activity,
plans, questions, queued guidance, files, and documents. Earlier native
UI work also exposed compatibility risks in legacy question and reply
paths.

**Proposed solution**

Add the task workspace components and provider-neutral protocol
presentation. Keep runner-only controls behind runtime facts. Preserve
all direct-adapter composer, transcript, interaction, and finalization
behavior.

**Alternatives considered**

A separate runner page would duplicate task behavior. Replacing legacy
transcript logic would create unnecessary adapter regressions.

**Roadmap alignment**

This work supports the unified task experience and the Cloud and Sandbox
agents milestone.

## Stack

- Base PR: #12639.
- Lower PR: #12638.
- This PR contains only its 119-file UI delta against
`runner/remote-wss-transport`.
- The next stack PR adds administrator and observability controls.

## What Changed

- Added a reusable task workspace side panel for files and documents.
- Added provider-neutral cards for tools, plans, questions, protocol
activity, and progress.
- Added queued guidance and richer composer state.
- Added compact and expanded interaction presentation.
- Added live activity, thinking, usage, recovery, and final reply
presentation.
- Added document annotations and task deep links.
- Added bounded question validation and response handling.
- Preserved native runner event projection from master.
- Preserved legacy channel-less replies and explicit final reply
precedence.
- Preserved direct-adapter and classic-interface controls.
- Did not change server execution selection, Rust code, migrations,
workflows, or `pnpm-lock.yaml`.

## Verification

- GitHub Actions will run UI tests, repository tests, typecheck, build,
browser tests, security, and policy gates.
- Tests cover active, settled, empty-transcript, interaction,
queued-message, plan, question, file, document, and classic-interface
states.
- Compatibility tests cover direct adapters and native runner projection
together.
- Local tests were not run. The requested verification policy uses
GitHub Actions for this series.
- `git diff --check runner/remote-wss-transport...HEAD` passes.
- The delta contains 119 UI-only files.

## Risks

- This is a large task-page change.
- Most files are new focused components and tests.
- Shared transcript code keeps the lower native projection and legacy
direct-adapter fallbacks.
- Runner-only controls use adapter and runtime facts.
- No execution path or rollout flag changes in this PR.

> 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

OpenAI Codex with GPT-5.6. The work used high-reasoning agent mode,
repository tools, GitHub tools, and parallel code-audit agents.

## 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 or instance-local Paperclip issues
or links
- [x] My branch name describes the change and contains no internal
Paperclip ticket id
- [ ] 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 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
2026-09-01 02:44:19 -05:00

347 lines
14 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { AttentionItem, AttentionResolverAudience } from "@paperclipai/shared";
import type { RequestConfirmationInteraction } from "./issue-thread-interactions";
import {
DEFAULT_RESOLVER_POLICY,
RESOLVER_POLICY_CHOICES,
describeAttentionResolverAudience,
describeInteractionAudience,
resolverPolicyEffect,
resolverPolicyLabel,
} from "./interaction-audience";
function confirmation(
overrides: Partial<RequestConfirmationInteraction> = {},
): RequestConfirmationInteraction {
return {
id: "interaction-1",
companyId: "company-1",
issueId: "issue-1",
kind: "request_confirmation",
status: "pending",
continuationPolicy: "wake_assignee",
createdByAgentId: "agent-creator",
createdByUserId: null,
createdAt: "2026-08-14T12:00:00.000Z",
updatedAt: "2026-08-14T12:00:00.000Z",
payload: { version: 1, prompt: "Ship it?" },
result: null,
// Open default with inherited provenance — what an omitted `resolverPolicy`
// produces under the PAP-17277 contract.
resolverPolicy: "anyone",
requestedResolverPolicy: "anyone",
effectiveResolverPolicy: "anyone",
resolverPolicyProvenance: "inherited",
effectiveResolverPolicySource: "requested",
legacyResolverPolicyAliases: { requested: "board_or_agents", effective: "board_or_agents" },
...overrides,
};
}
describe("resolver policy vocabulary", () => {
it("defaults to the open audience", () => {
expect(DEFAULT_RESOLVER_POLICY).toBe("anyone");
expect(RESOLVER_POLICY_CHOICES[0]).toMatchObject({ value: "anyone", isDefault: true });
expect(RESOLVER_POLICY_CHOICES.map((choice) => choice.value)).toEqual([
"anyone",
"not_creator",
"human_only",
]);
expect(RESOLVER_POLICY_CHOICES.filter((choice) => choice.isDefault)).toHaveLength(1);
});
it("labels each canonical policy in plain language", () => {
expect(resolverPolicyLabel("anyone")).toBe("Anyone");
expect(resolverPolicyLabel("not_creator")).toBe("Anyone except creator");
expect(resolverPolicyLabel("human_only")).toBe("Human only");
});
it("maps deprecated board aliases onto canonical copy", () => {
expect(resolverPolicyLabel("board_or_agents")).toBe("Anyone");
expect(resolverPolicyLabel("board_only")).toBe("Human only");
expect(resolverPolicyEffect("board_only")).toBe(resolverPolicyEffect("human_only"));
});
it("previews an effect for every choice without naming a raw policy value", () => {
for (const choice of RESOLVER_POLICY_CHOICES) {
expect(choice.effect.length).toBeGreaterThan(0);
expect(choice.effect).not.toContain(choice.value);
}
});
});
describe("describeInteractionAudience", () => {
it("reads an omitted policy as open company attention", () => {
const audience = describeInteractionAudience({ interaction: confirmation() });
expect(audience.policy).toBe("anyone");
expect(audience.isOpen).toBe(true);
expect(audience.label).toBe("Anyone");
expect(audience.narrowedBy).toBeNull();
expect(audience.narrowedNote).toBeNull();
expect(audience.summary).toBe(
"Anyone in the organization can respond — the board or any agent, including the one that asked.",
);
});
it("does not present an open card as board-required", () => {
const audience = describeInteractionAudience({ interaction: confirmation() });
expect(audience.summary).not.toMatch(/only .*board/i);
expect(audience.summary).toMatch(/anyone in the organization/i);
});
it("names the excluded creator for an explicit not_creator restriction", () => {
const audience = describeInteractionAudience({
interaction: confirmation({
requestedResolverPolicy: "not_creator",
effectiveResolverPolicy: "not_creator",
resolverPolicyProvenance: "explicit",
legacyResolverPolicyAliases: { requested: null, effective: null },
}),
creatorLabel: "ClaudeCoder",
});
expect(audience.isOpen).toBe(false);
expect(audience.label).toBe("Anyone except creator");
expect(audience.narrowedBy).toBe("requested");
expect(audience.summary).toBe("Anyone in the organization except ClaudeCoder can respond.");
// An explicitly requested restriction needs no extra explanation.
expect(audience.narrowedNote).toBeNull();
});
/**
* PAP-17859, caught by rendering the card rather than reading it:
* `formatAssigneeUserLabel` returns the display-cased "You" for the signed-in
* reader, which is correct in a badge and wrong inside a sentence.
*/
it("lowercases a self-referring label inside the summary sentence", () => {
const addressed = describeInteractionAudience({
interaction: confirmation({ addresseeUserId: "user-me" }),
addresseeLabel: "You",
});
expect(addressed.summary).toBe("Only you can respond.");
expect(addressed.shortSummary).toBe("Only you can respond");
const excluded = describeInteractionAudience({
interaction: confirmation({
requestedResolverPolicy: "not_creator",
effectiveResolverPolicy: "not_creator",
resolverPolicyProvenance: "explicit",
}),
creatorLabel: "You",
});
expect(excluded.summary).toBe("Anyone in the organization except you can respond.");
});
it("falls back to a generic creator phrase when the creator label is unknown", () => {
const audience = describeInteractionAudience({
interaction: confirmation({
requestedResolverPolicy: "not_creator",
effectiveResolverPolicy: "not_creator",
resolverPolicyProvenance: "explicit",
}),
});
expect(audience.summary).toBe(
"Anyone in the organization except the agent that created it can respond.",
);
});
it("keeps human-only ownership copy explicit", () => {
const audience = describeInteractionAudience({
interaction: confirmation({
requestedResolverPolicy: "human_only",
effectiveResolverPolicy: "human_only",
resolverPolicyProvenance: "explicit",
legacyResolverPolicyAliases: { requested: "board_only", effective: "board_only" },
}),
});
expect(audience.label).toBe("Human only");
expect(audience.isOpen).toBe(false);
expect(audience.summary).toBe(
"Only a person on the board can respond — agents cannot resolve this card.",
);
});
it("keeps addressee ownership copy when a named agent owns the card", () => {
const audience = describeInteractionAudience({
interaction: confirmation({ addresseeAgentId: "agent-release" }),
addresseeLabel: "ReleaseBot",
});
expect(audience.isOpen).toBe(false);
expect(audience.narrowedBy).toBe("addressee");
expect(audience.summary).toBe("Only ReleaseBot or a person on the board can respond.");
// The label must not claim "Anyone" next to a sentence naming one agent.
expect(audience.label).toBe("Addressed");
});
it("keeps named ownership visible while human_only controls authorization", () => {
const audience = describeInteractionAudience({
interaction: confirmation({
addresseeAgentId: "agent-release",
requestedResolverPolicy: "human_only",
effectiveResolverPolicy: "human_only",
}),
addresseeLabel: "ReleaseBot",
});
expect(audience.summary).toBe(
"Assigned to ReleaseBot. Only a person on the board can respond — agents cannot resolve this card.",
);
expect(audience.shortSummary).toBe("Assigned to ReleaseBot · board only");
expect(audience.label).toBe("Human only");
});
it("names one addressed user instead of the whole board", () => {
const audience = describeInteractionAudience({
interaction: confirmation({
addresseeUserId: "user-alice",
requestedResolverPolicy: "human_only",
effectiveResolverPolicy: "human_only",
}),
addresseeLabel: "Alice",
});
expect(audience.summary).toBe("Only Alice can respond.");
expect(audience.shortSummary).toBe("Only Alice can respond");
expect(audience.label).toBe("Addressed");
});
it("explains a governed-action clamp", () => {
const audience = describeInteractionAudience({
interaction: confirmation({
requestedResolverPolicy: "anyone",
effectiveResolverPolicy: "human_only",
effectiveResolverPolicySource: "governed_action",
}),
});
expect(audience.policy).toBe("human_only");
expect(audience.requestedPolicy).toBe("anyone");
expect(audience.narrowedBy).toBe("governed_action");
expect(audience.narrowedNote).toBe(
"This card runs a governed action, so it stays human-only whatever audience was requested.",
);
});
it("explains a company cap using both audience labels", () => {
const audience = describeInteractionAudience({
interaction: confirmation({
requestedResolverPolicy: "anyone",
effectiveResolverPolicy: "human_only",
effectiveResolverPolicySource: "company_cap",
}),
});
expect(audience.narrowedBy).toBe("company_cap");
expect(audience.narrowedNote).toBe(
"Organization interaction governance narrowed this from Anyone to Human only.",
);
});
it("explains a legacy restricted card that predates the open default", () => {
const audience = describeInteractionAudience({
interaction: confirmation({
requestedResolverPolicy: "not_creator",
effectiveResolverPolicy: "not_creator",
resolverPolicyProvenance: "legacy_inherited_restriction",
}),
creatorLabel: "ClaudeCoder",
});
expect(audience.narrowedBy).toBe("legacy_restriction");
expect(audience.narrowedNote).toBe(
"Created before Anyone became the default, so it stays restricted. A new card would be open.",
);
expect(audience.summary).toBe("Anyone in the organization except ClaudeCoder can respond.");
});
});
/** The `resolverAudience` metadata the attention feed ships with an interaction row. */
function attentionAudience(
overrides: Partial<AttentionResolverAudience> = {},
): AttentionResolverAudience {
return {
requestedResolverPolicy: "anyone",
effectiveResolverPolicy: "anyone",
effectiveResolverPolicySource: "requested",
resolverPolicyProvenance: "inherited",
addresseeAgentId: null,
addresseeName: null,
createdByAgentId: "agent-creator",
createdByAgentName: "Watchdog",
...overrides,
};
}
function attentionItem(
audience: AttentionResolverAudience | null,
sourceKind: AttentionItem["sourceKind"] = "issue_thread_interaction",
): Pick<AttentionItem, "sourceKind" | "resolverAudience"> {
return { sourceKind, resolverAudience: audience };
}
describe("glanceable audience copy", () => {
it("states the open default in one clause", () => {
expect(describeInteractionAudience({ interaction: confirmation() }).shortSummary)
.toBe("Anyone can respond");
});
it("names the excluded creator", () => {
expect(describeInteractionAudience({
interaction: confirmation({ requestedResolverPolicy: "not_creator", effectiveResolverPolicy: "not_creator" }),
creatorLabel: "Watchdog",
}).shortSummary).toBe("Anyone except Watchdog can respond");
});
it("names the addressed responder", () => {
expect(describeInteractionAudience({
interaction: confirmation({ addresseeAgentId: "agent-codex" }),
addresseeLabel: "CodexCoder",
}).shortSummary).toBe("Only CodexCoder or the board can respond");
});
it("keeps human-only ownership with the board", () => {
expect(describeInteractionAudience({
interaction: confirmation({ requestedResolverPolicy: "human_only", effectiveResolverPolicy: "human_only" }),
}).shortSummary).toBe("Only the board can respond");
});
});
describe("describeAttentionResolverAudience", () => {
it("describes an open interaction row from server metadata alone", () => {
const audience = describeAttentionResolverAudience(attentionItem(attentionAudience()));
expect(audience?.policy).toBe("anyone");
expect(audience?.isOpen).toBe(true);
expect(audience?.label).toBe("Anyone");
expect(audience?.shortSummary).toBe("Anyone can respond");
});
it("names the addressed agent the server recorded", () => {
const audience = describeAttentionResolverAudience(attentionItem(attentionAudience({
addresseeAgentId: "agent-codex",
addresseeName: "CodexCoder",
})));
expect(audience?.label).toBe("Addressed");
expect(audience?.shortSummary).toBe("Only CodexCoder or the board can respond");
});
it("names the excluded creator the server recorded", () => {
const audience = describeAttentionResolverAudience(attentionItem(attentionAudience({
requestedResolverPolicy: "not_creator",
effectiveResolverPolicy: "not_creator",
})));
expect(audience?.shortSummary).toBe("Anyone except Watchdog can respond");
});
it("carries the narrowing explanation for a company cap", () => {
const audience = describeAttentionResolverAudience(attentionItem(attentionAudience({
effectiveResolverPolicy: "human_only",
effectiveResolverPolicySource: "company_cap",
})));
expect(audience?.narrowedBy).toBe("company_cap");
expect(audience?.narrowedNote).toBe(
"Organization interaction governance narrowed this from Anyone to Human only.",
);
});
it("stays silent rather than guessing a policy client-side", () => {
// No metadata (an older feed) and non-interaction rows must render nothing.
expect(describeAttentionResolverAudience(attentionItem(null))).toBeNull();
expect(describeAttentionResolverAudience({ sourceKind: "issue_thread_interaction" })).toBeNull();
expect(describeAttentionResolverAudience(attentionItem(attentionAudience(), "approval"))).toBeNull();
});
});