mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-23 17:33:51 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Task conversations show requests in the feed and above the message composer. > - Earlier fixes kept dismissed questions in history, but excluded completion reviews and other request kinds. > - Closing those forms left a pending badge, and the server could still demand a response. > - This pull request saves human dismissal and removes the request from composer reminders and ordinary completion gates. > - People can continue the conversation and reopen the request from history. ## Linked Issues or Issue Description Related work: #15229 and #15392. **What happened?** Dismissing a completion review closed its form but left it counted as pending. It could return after reload, block a retry, or cause the agent to demand another response. Raw runtime requests could also lose their only usable control when dismissed. **Expected behavior** Dismissal leaves an accessible request in the feed and clears the composer form and pending count. It persists after reload. It does not submit an answer, approve an action, or wake the agent. **Steps to reproduce** 1. Open a task with a pending completion review or another composer request. 2. Dismiss the request, then reload the task. 3. Check that the composer stays clear and the feed entry can reopen the request. ## What Changed - Add nullable dismissal fields and a human-only dismissal endpoint with company, private-task access, resolver, and locked review-policy checks. - Persist saved-request dismissal on the server. Keep browser persistence for raw runtime requests and existing question dismissals. - Keep confirmations, choices, item verdicts, suggested tasks, and runtime requests accessible in the feed. - Exclude dismissed ordinary requests from completion and retry gates. Tell agents not to repeat deferred requests. - Preserve tool, secret, connection, plan, company-policy, and configured review authorization gates. Expire deferred non-question requests when their task completes. - Preserve the selected form when another dismissal finishes saving. Keep reopened reviews visible through delayed comment refreshes. - Add a completion-review Storybook test drive and update design, API, database, and capability documentation. ## Verification - `pnpm -r typecheck`: passed. The final UI changes also passed the UI typecheck. - `pnpm build`: passed. The final UI changes also passed the UI production build. - Focused UI and transcript tests: 550 passed across nine files after merging the current base branch. - Focused database, completion, and prompt tests: 105 passed across three files, including two review-policy regressions that failed before the fix. The tests reject a review requester excluded by current policy, preserve the pending gate on denial, and permit an independent reviewer to defer the request. - Route regression suite: 81 passed, including denial before reading or mutating a private-task request. - `pnpm check:token-gates`: passed. - Map and Storybook structural checks: passed; 30 map/catalog script tests passed. - Browser: used the production task-thread components in the completion-review fixture. Dismissed, reloaded, reopened from the feed, and dismissed again. No pending badge or composer takeover remained. Story callbacks simulate API saves; separate server tests cover persistence and permissions. - `pnpm test:run`: stopped after the general-server group reported one failure in `workspace-runtime.test.ts`: "returns a bounded structured conflict and exposes only same-company workspace references". The same test passed in isolation (1 passed, 178 skipped). The cause of the full-suite failure is not established. The full PR CI suite subsequently passed on e243cbb001; its two authorization review findings are fixed in9e1b4478b3. Fresh [full CI](https://github.com/paperclipai/paperclip/actions/runs/39871944846) passes on9e1b4478b3, including the previously failing server and browser shards. All 54 executed checks passed; two optional Storybook deployment/visual jobs were skipped. The legacy security status also passed. Fresh Greptile review is 5/5, the security scan passes, and no review threads remain open. This full CI run settles the merge gate; the earlier local workspace-suite failure remains recorded above because its cause was not established. - Additional verification: the original failing browser journey passed locally after the delayed-refresh fix. The expanded page-reload case also passes on9e1b4478b3(52.7s): dismiss, reload, reopen, approve, and receive the actual tool failure in the continuing task. It exposed a fixture reading an accepted request before tool execution finished; the fixture now waits for a stored execution result. The first reload attempt stopped on a still-loading page at the default five-second assertion; the reload now uses the suite’s navigation allowance. A controlled server-restart run timed out waiting for server health before the UI assertions. Local route-suite runs timed out during concurrent module loading; sequential imports passed all 81 tests, including the privacy regression. - Initial verification failures: a missing SDK build and a story fixture type error were fixed. PostgreSQL bootstrap then failed because the host had exhausted its semaphore allowance. After explicit operator approval, 64 verified abandoned PostgreSQL semaphore sets were reclaimed; no live process was stopped. The database regressions then passed. The raw-runtime regression exposed a missing feed control; the implementation now preserves that entry and the regression passes. ## Risks - Apply the additive database migration before the new server code. It adds two nullable columns and does not change existing decisions. - A dismissal is shared task attention state. Only a human with task read access and current resolver/review authority can persist it. Review policy is checked under the task lock. The operation is idempotent and records the dismissing user. - Raw runtime dismissal remains specific to a browser. Saved interaction dismissal persists across browsers. - A deferred review is not an approval. Tests retain protected-action and configured review gates. - The browser walkthrough uses a fixture. This branch has not been deployed to a live instance. ## Model Used OpenAI Codex, GPT-6, with code execution and browser tools. The exact backend model ID and context-window size are not exposed in this session. ## 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 - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge
741 lines
25 KiB
TypeScript
741 lines
25 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { pendingRequestConfirmationInteraction } from "../fixtures/issueThreadInteractionFixtures";
|
|
import {
|
|
buildAnsweredQuestionsDeliveryText,
|
|
buildIssueThreadInteractionSummary,
|
|
buildSuggestedTaskTree,
|
|
collectSuggestedTaskClientKeys,
|
|
countSuggestedTaskNodes,
|
|
getCheckboxConfirmationSelectedLabels,
|
|
getItemVerdictProgress,
|
|
getRequestConfirmationTargetHref,
|
|
getQuestionAnswerLabels,
|
|
interactionReplacesComposerSkip,
|
|
interactionReadinessRefetchInterval,
|
|
isDegenerateAskUserQuestions,
|
|
isDeferredConversationInteraction,
|
|
isSupersededByNewerSiblingInteraction,
|
|
shouldHideInteractionCard,
|
|
normalizeRequestConfirmationTargetHref,
|
|
} from "./issue-thread-interactions";
|
|
import type {
|
|
AskUserQuestionsInteraction,
|
|
AskUserQuestionsQuestion,
|
|
IssueThreadInteraction,
|
|
RequestItemVerdictsInteraction,
|
|
} from "./issue-thread-interactions";
|
|
|
|
// The open default every interaction now inherits when its creator omits
|
|
// `resolverPolicy` (PAP-17277 contract).
|
|
const resolverPolicyFields = {
|
|
resolverPolicy: "anyone",
|
|
requestedResolverPolicy: "anyone",
|
|
effectiveResolverPolicy: "anyone",
|
|
resolverPolicyProvenance: "inherited",
|
|
effectiveResolverPolicySource: "requested",
|
|
legacyResolverPolicyAliases: { requested: "board_or_agents", effective: "board_or_agents" },
|
|
} as const;
|
|
|
|
describe("buildSuggestedTaskTree", () => {
|
|
it("preserves parent-child relationships from client keys", () => {
|
|
const roots = buildSuggestedTaskTree([
|
|
{
|
|
clientKey: "root",
|
|
title: "Root",
|
|
},
|
|
{
|
|
clientKey: "child",
|
|
parentClientKey: "root",
|
|
title: "Child",
|
|
},
|
|
{
|
|
clientKey: "grandchild",
|
|
parentClientKey: "child",
|
|
title: "Grandchild",
|
|
},
|
|
]);
|
|
|
|
expect(roots).toHaveLength(1);
|
|
expect(roots[0]?.task.clientKey).toBe("root");
|
|
expect(roots[0]?.children[0]?.task.clientKey).toBe("child");
|
|
expect(countSuggestedTaskNodes(roots[0]!)).toBe(3);
|
|
expect(collectSuggestedTaskClientKeys(roots[0]!)).toEqual(["root", "child", "grandchild"]);
|
|
});
|
|
});
|
|
|
|
describe("issue thread interaction helpers", () => {
|
|
it("allows recovery past dismissed ordinary reviews but retains protected action gates", () => {
|
|
const review = { ...pendingRequestConfirmationInteraction, dismissedAt: new Date(),
|
|
payload: { version: 1 as const, prompt: "Review completed work", target: { type: "custom" as const, key: "native_completion_review" } } };
|
|
expect(isDeferredConversationInteraction(review)).toBe(true);
|
|
expect(isDeferredConversationInteraction({ ...review, dismissedAt: null })).toBe(false);
|
|
expect(isDeferredConversationInteraction({ ...review, effectiveResolverPolicySource: "company_cap" })).toBe(false);
|
|
expect(isDeferredConversationInteraction({ ...pendingRequestConfirmationInteraction, dismissedAt: new Date() })).toBe(false);
|
|
expect(isDeferredConversationInteraction({ ...review, payload: { ...review.payload, toolAction: {} as never } })).toBe(false);
|
|
expect(isDeferredConversationInteraction({ ...review, payload: { ...review.payload, secretProposal: {} as never } })).toBe(false);
|
|
});
|
|
|
|
it("replaces composer Skip only when the durable form has its own alternative path", () => {
|
|
const base = {
|
|
id: "interaction-1",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
status: "pending",
|
|
continuationPolicy: "wake_assignee",
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:00:00.000Z",
|
|
result: null,
|
|
} as const;
|
|
expect(interactionReplacesComposerSkip({
|
|
...base,
|
|
kind: "request_confirmation",
|
|
payload: { version: 1, prompt: "Proceed?" },
|
|
} as IssueThreadInteraction)).toBe(true);
|
|
expect(interactionReplacesComposerSkip({
|
|
...base,
|
|
kind: "request_checkbox_confirmation",
|
|
payload: { version: 1, prompt: "Select", options: [] },
|
|
} as IssueThreadInteraction)).toBe(true);
|
|
expect(interactionReplacesComposerSkip({
|
|
...base,
|
|
kind: "suggest_tasks",
|
|
payload: { version: 1, tasks: [] },
|
|
} as IssueThreadInteraction)).toBe(true);
|
|
expect(interactionReplacesComposerSkip({
|
|
...base,
|
|
kind: "ask_user_questions",
|
|
payload: { version: 1, questions: [] },
|
|
} as IssueThreadInteraction)).toBe(false);
|
|
expect(interactionReplacesComposerSkip({
|
|
...base,
|
|
kind: "request_item_verdicts",
|
|
payload: { version: 1, prompt: "Review", items: [] },
|
|
} as IssueThreadInteraction)).toBe(false);
|
|
});
|
|
|
|
it("formats successor-turn answer delivery with canonical prompts and labels", () => {
|
|
const interaction = {
|
|
id: "interaction-answers",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "ask_user_questions",
|
|
status: "answered",
|
|
continuationPolicy: "wake_assignee",
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:01:00.000Z",
|
|
payload: {
|
|
version: 1,
|
|
questions: [
|
|
{ id: "purpose", prompt: "What is it for?", selectionMode: "single", options: [] },
|
|
{ id: "runtime", prompt: "Which runtime?", selectionMode: "single", options: [{ id: "node", label: "Node.js" }] },
|
|
{ id: "features", prompt: "Which features?", selectionMode: "multi", options: [{ id: "logs", label: "Request logs" }] },
|
|
],
|
|
questionSet: {
|
|
schema: "paperclip.question_set.v1",
|
|
questions: [
|
|
{ id: "purpose", header: "Purpose", prompt: "What is it for?", required: true, answerMode: "text" },
|
|
{ id: "runtime", header: "Runtime", prompt: "Which runtime?", required: true, answerMode: "single_select", options: [{ id: "node", label: "Node.js" }] },
|
|
{ id: "features", header: "Features", prompt: "Which features?", required: false, answerMode: "multi_select", options: [{ id: "logs", label: "Request logs" }], customAnswer: { enabled: true, label: "Other" } },
|
|
],
|
|
},
|
|
},
|
|
result: {
|
|
version: 1,
|
|
answers: [
|
|
{ questionId: "purpose", optionIds: [], otherText: "Internal API" },
|
|
{ questionId: "runtime", optionIds: ["node"] },
|
|
{ questionId: "features", optionIds: ["logs"], otherText: "Metrics" },
|
|
],
|
|
},
|
|
} satisfies AskUserQuestionsInteraction;
|
|
|
|
expect(buildAnsweredQuestionsDeliveryText(interaction)).toBe([
|
|
"Answered questions",
|
|
"",
|
|
"- Purpose — What is it for?: Internal API",
|
|
"- Runtime — Which runtime?: Node.js",
|
|
"- Features — Which features?: Request logs, Metrics",
|
|
].join("\n"));
|
|
});
|
|
|
|
it("summarizes task and question interactions", () => {
|
|
expect(buildIssueThreadInteractionSummary({
|
|
id: "interaction-1",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "suggest_tasks",
|
|
status: "pending",
|
|
continuationPolicy: "wake_assignee",
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:00:00.000Z",
|
|
payload: {
|
|
version: 1,
|
|
tasks: [
|
|
{ clientKey: "task-1", title: "One" },
|
|
{ clientKey: "task-2", title: "Two" },
|
|
],
|
|
},
|
|
})).toBe("Suggested 2 tasks");
|
|
|
|
expect(buildIssueThreadInteractionSummary({
|
|
id: "interaction-accepted",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "suggest_tasks",
|
|
status: "accepted",
|
|
continuationPolicy: "wake_assignee",
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:00:00.000Z",
|
|
payload: {
|
|
version: 1,
|
|
tasks: [
|
|
{ clientKey: "task-1", title: "One" },
|
|
{ clientKey: "task-2", title: "Two" },
|
|
],
|
|
},
|
|
result: {
|
|
version: 1,
|
|
createdTasks: [{ clientKey: "task-1", issueId: "child-1" }],
|
|
skippedClientKeys: ["task-2"],
|
|
},
|
|
})).toBe("Accepted 1 of 2 tasks");
|
|
|
|
expect(buildIssueThreadInteractionSummary({
|
|
id: "interaction-2",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "ask_user_questions",
|
|
status: "pending",
|
|
continuationPolicy: "wake_assignee",
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:00:00.000Z",
|
|
payload: {
|
|
version: 1,
|
|
questions: [
|
|
{
|
|
id: "question-1",
|
|
prompt: "Pick one",
|
|
selectionMode: "single",
|
|
options: [{ id: "option-1", label: "Option 1" }],
|
|
},
|
|
],
|
|
},
|
|
})).toBe("Asked 1 question");
|
|
|
|
expect(buildIssueThreadInteractionSummary({
|
|
id: "interaction-answered",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "ask_user_questions",
|
|
status: "answered",
|
|
continuationPolicy: "wake_assignee",
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:00:00.000Z",
|
|
payload: {
|
|
version: 1,
|
|
questions: [
|
|
{
|
|
id: "question-1",
|
|
prompt: "Pick one",
|
|
selectionMode: "single",
|
|
options: [{ id: "option-1", label: "Option 1" }],
|
|
},
|
|
],
|
|
},
|
|
result: {
|
|
version: 1,
|
|
answers: [{ questionId: "question-1", optionIds: ["option-1"] }],
|
|
},
|
|
})).toBe("Answered 1 question");
|
|
|
|
expect(buildIssueThreadInteractionSummary({
|
|
id: "interaction-expired",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "ask_user_questions",
|
|
status: "expired",
|
|
continuationPolicy: "wake_assignee",
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:05:00.000Z",
|
|
payload: {
|
|
version: 1,
|
|
questions: [
|
|
{
|
|
id: "question-1",
|
|
prompt: "Pick one",
|
|
selectionMode: "single",
|
|
options: [{ id: "option-1", label: "Option 1" }],
|
|
},
|
|
],
|
|
},
|
|
result: {
|
|
version: 1,
|
|
answers: [],
|
|
expirationReason: "superseded_by_comment",
|
|
commentId: "11111111-1111-4111-8111-111111111111",
|
|
},
|
|
})).toBe("Question expired after comment");
|
|
});
|
|
|
|
it("summarizes checkbox confirmation interactions by count", () => {
|
|
const base = {
|
|
id: "interaction-checkbox",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "request_checkbox_confirmation" as const,
|
|
continuationPolicy: "wake_assignee" as const,
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:00:00.000Z",
|
|
payload: {
|
|
version: 1 as const,
|
|
prompt: "Pick items",
|
|
options: [
|
|
{ id: "a", label: "A" },
|
|
{ id: "b", label: "B" },
|
|
{ id: "c", label: "C" },
|
|
],
|
|
},
|
|
};
|
|
|
|
expect(buildIssueThreadInteractionSummary({ ...base, status: "pending" }))
|
|
.toBe("Requested a selection from 3 options");
|
|
|
|
expect(buildIssueThreadInteractionSummary({
|
|
...base,
|
|
status: "accepted",
|
|
result: { version: 1, outcome: "accepted", selectedOptionIds: ["a", "c"] },
|
|
})).toBe("Confirmed 2 of 3 options");
|
|
|
|
expect(buildIssueThreadInteractionSummary({
|
|
...base,
|
|
status: "accepted",
|
|
result: { version: 1, outcome: "accepted", selectedOptionIds: [] },
|
|
})).toBe("Confirmed with no options selected");
|
|
|
|
expect(buildIssueThreadInteractionSummary({
|
|
...base,
|
|
status: "expired",
|
|
result: { version: 1, outcome: "stale_target" },
|
|
})).toBe("Selection expired after target changed");
|
|
});
|
|
|
|
it("uses a confirmation's explicit rejection action in its receipt", () => {
|
|
const base = {
|
|
id: "interaction-confirmation",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "request_confirmation" as const,
|
|
status: "rejected" as const,
|
|
continuationPolicy: "wake_assignee" as const,
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:01:00.000Z",
|
|
result: { version: 1 as const, outcome: "rejected" as const },
|
|
};
|
|
|
|
expect(buildIssueThreadInteractionSummary({
|
|
...base,
|
|
payload: {
|
|
version: 1 as const,
|
|
prompt: "Is this task ready to complete?",
|
|
rejectLabel: "Continue work",
|
|
},
|
|
})).toBe("Selected “Continue work”");
|
|
|
|
expect(buildIssueThreadInteractionSummary({
|
|
...base,
|
|
payload: {
|
|
version: 1 as const,
|
|
prompt: "Proceed?",
|
|
},
|
|
})).toBe("Declined request");
|
|
});
|
|
|
|
it("maps selected checkbox option ids back to labels", () => {
|
|
const labels = getCheckboxConfirmationSelectedLabels({
|
|
payload: {
|
|
version: 1,
|
|
prompt: "Pick items",
|
|
options: [
|
|
{ id: "a", label: "Alpha" },
|
|
{ id: "b", label: "Bravo" },
|
|
{ id: "c", label: "Charlie" },
|
|
],
|
|
},
|
|
result: { version: 1, outcome: "accepted", selectedOptionIds: ["c", "a", "missing"] },
|
|
});
|
|
|
|
expect(labels).toEqual(["Charlie", "Alpha"]);
|
|
});
|
|
|
|
it("allows only safe confirmation target hrefs for rendering", () => {
|
|
for (const href of [
|
|
"https://example.com/checklist",
|
|
"http://example.com/checklist",
|
|
"/PAP/issues/PAP-123#document-plan",
|
|
"#document-plan",
|
|
]) {
|
|
expect(normalizeRequestConfirmationTargetHref(href)).toBe(href);
|
|
}
|
|
|
|
for (const href of [
|
|
"file:///tmp/x",
|
|
"mailto:user@example.com",
|
|
"slack://channel?id=1",
|
|
"vscode://file/tmp/x",
|
|
"ftp://example.com/file",
|
|
"//evil.example/path",
|
|
]) {
|
|
expect(normalizeRequestConfirmationTargetHref(href)).toBeNull();
|
|
}
|
|
});
|
|
|
|
it("does not return unsafe custom target hrefs from accepted payloads", () => {
|
|
expect(getRequestConfirmationTargetHref({
|
|
issueId: "issue-1",
|
|
target: {
|
|
type: "custom",
|
|
key: "unsafe-target",
|
|
label: "Unsafe target",
|
|
href: "file:///tmp/x",
|
|
},
|
|
})).toBeNull();
|
|
|
|
expect(getRequestConfirmationTargetHref({
|
|
issueId: "issue-1",
|
|
target: {
|
|
type: "issue_document",
|
|
issueId: "issue-2",
|
|
key: "plan",
|
|
revisionId: "11111111-1111-4111-8111-111111111111",
|
|
href: "slack://channel?id=1",
|
|
},
|
|
})).toBe("/issues/issue-2#document-plan");
|
|
});
|
|
|
|
it("maps stored option ids back to labels for answered summaries", () => {
|
|
const labels = getQuestionAnswerLabels({
|
|
question: {
|
|
id: "question-1",
|
|
prompt: "Pick options",
|
|
selectionMode: "multi",
|
|
options: [
|
|
{ id: "option-1", label: "Option 1" },
|
|
{ id: "option-2", label: "Option 2" },
|
|
],
|
|
},
|
|
answers: [
|
|
{
|
|
questionId: "question-1",
|
|
optionIds: ["option-2", "option-1"],
|
|
otherText: "A written answer",
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(labels).toEqual(["Option 2", "Option 1", "Other: A written answer"]);
|
|
});
|
|
});
|
|
|
|
describe("per-item verdict helpers", () => {
|
|
function verdictInteraction(
|
|
overrides: Partial<RequestItemVerdictsInteraction> = {},
|
|
): RequestItemVerdictsInteraction {
|
|
return {
|
|
id: "interaction-verdicts",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "request_item_verdicts",
|
|
status: "pending",
|
|
continuationPolicy: "wake_assignee",
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:00:00.000Z",
|
|
payload: {
|
|
version: 1,
|
|
prompt: "Review the posts.",
|
|
items: [
|
|
{ id: "a", label: "A" },
|
|
{ id: "b", label: "B" },
|
|
{ id: "c", label: "C" },
|
|
],
|
|
verdicts: ["approve", "reject"],
|
|
requireReasonOn: ["reject"],
|
|
},
|
|
...overrides,
|
|
} as RequestItemVerdictsInteraction;
|
|
}
|
|
|
|
it("counts decided items and lists still-pending ids in payload order", () => {
|
|
const progress = getItemVerdictProgress({
|
|
payload: verdictInteraction().payload,
|
|
result: {
|
|
version: 1,
|
|
outcome: "resolved",
|
|
complete: false,
|
|
items: [
|
|
{ id: "a", verdict: "approve", resolvedByUserId: "u", resolvedAt: "2026-04-06T12:01:00.000Z" },
|
|
{ id: "c", verdict: "reject", reason: "no", resolvedByUserId: "u", resolvedAt: "2026-04-06T12:01:00.000Z" },
|
|
],
|
|
},
|
|
});
|
|
expect(progress).toMatchObject({ total: 3, decided: 2, approved: 1, rejected: 1, deferred: 0 });
|
|
expect(progress.pendingItemIds).toEqual(["b"]);
|
|
});
|
|
|
|
it("summarizes pending, complete, and superseded verdict cards", () => {
|
|
expect(buildIssueThreadInteractionSummary(verdictInteraction())).toBe("0 of 3 decided");
|
|
|
|
expect(buildIssueThreadInteractionSummary(verdictInteraction({
|
|
status: "answered",
|
|
result: {
|
|
version: 1,
|
|
outcome: "resolved",
|
|
complete: true,
|
|
items: [
|
|
{ id: "a", verdict: "approve", resolvedByUserId: "u", resolvedAt: "2026-04-06T12:01:00.000Z" },
|
|
{ id: "b", verdict: "approve", resolvedByUserId: "u", resolvedAt: "2026-04-06T12:01:00.000Z" },
|
|
{ id: "c", verdict: "reject", reason: "no", resolvedByUserId: "u", resolvedAt: "2026-04-06T12:01:00.000Z" },
|
|
],
|
|
},
|
|
}))).toBe("3 decided · 2 approved · 1 rejected");
|
|
|
|
expect(buildIssueThreadInteractionSummary(verdictInteraction({
|
|
status: "expired",
|
|
result: {
|
|
version: 1,
|
|
outcome: "superseded_by_comment",
|
|
complete: false,
|
|
items: [],
|
|
},
|
|
}))).toBe("Verdicts expired after comment");
|
|
});
|
|
});
|
|
|
|
describe("isDegenerateAskUserQuestions", () => {
|
|
function askInteraction(
|
|
questions: AskUserQuestionsQuestion[],
|
|
): AskUserQuestionsInteraction {
|
|
return {
|
|
id: "interaction-ask",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "ask_user_questions",
|
|
status: "pending",
|
|
continuationPolicy: "wake_assignee",
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:00:00.000Z",
|
|
payload: { version: 1, questions },
|
|
} as AskUserQuestionsInteraction;
|
|
}
|
|
|
|
it("flags a card with zero questions", () => {
|
|
expect(isDegenerateAskUserQuestions(askInteraction([]))).toBe(true);
|
|
});
|
|
|
|
it("flags a question with a blank / whitespace-only prompt", () => {
|
|
expect(isDegenerateAskUserQuestions(askInteraction([
|
|
{
|
|
id: "q1",
|
|
prompt: " ",
|
|
selectionMode: "single",
|
|
options: [
|
|
{ id: "a", label: "A" },
|
|
{ id: "b", label: "B" },
|
|
],
|
|
},
|
|
]))).toBe(true);
|
|
});
|
|
|
|
it("keeps a single fixed-option question: it is answerable (select + submit)", () => {
|
|
// A lone fixed option is still resolvable — the user selects it and submits —
|
|
// so it must render. Hiding it would strand a pending interaction the
|
|
// assignee is waiting on.
|
|
expect(isDegenerateAskUserQuestions(askInteraction([
|
|
{
|
|
id: "q1",
|
|
prompt: "Test",
|
|
selectionMode: "single",
|
|
options: [{ id: "a", label: "A" }],
|
|
},
|
|
]))).toBe(false);
|
|
});
|
|
|
|
it("flags a question with no options at all", () => {
|
|
expect(isDegenerateAskUserQuestions(askInteraction([
|
|
{ id: "q1", prompt: "Anything?", selectionMode: "single", options: [] },
|
|
]))).toBe(true);
|
|
});
|
|
|
|
it("keeps a legitimate yes/no question (2 options)", () => {
|
|
expect(isDegenerateAskUserQuestions(askInteraction([
|
|
{
|
|
id: "q1",
|
|
prompt: "Ship it?",
|
|
selectionMode: "single",
|
|
options: [
|
|
{ id: "yes", label: "Yes" },
|
|
{ id: "no", label: "No" },
|
|
],
|
|
},
|
|
]))).toBe(false);
|
|
});
|
|
|
|
it("keeps a multi-select question (>= 2 options)", () => {
|
|
expect(isDegenerateAskUserQuestions(askInteraction([
|
|
{
|
|
id: "q1",
|
|
prompt: "Pick platforms",
|
|
selectionMode: "multi",
|
|
options: [
|
|
{ id: "web", label: "Web" },
|
|
{ id: "ios", label: "iOS" },
|
|
{ id: "android", label: "Android" },
|
|
],
|
|
},
|
|
]))).toBe(false);
|
|
});
|
|
|
|
it("keeps a question whose only choice is a first-class free-text option (PAP-419)", () => {
|
|
expect(isDegenerateAskUserQuestions(askInteraction([
|
|
{
|
|
id: "q1",
|
|
prompt: "Describe your goal",
|
|
selectionMode: "single",
|
|
options: [{ id: "other", label: "I'll describe it", freeText: true }],
|
|
},
|
|
]))).toBe(false);
|
|
});
|
|
|
|
it("is degenerate only when EVERY question is degenerate", () => {
|
|
// One real question keeps the whole card, even next to a degenerate one
|
|
// (here: a question with no options and no free-text).
|
|
expect(isDegenerateAskUserQuestions(askInteraction([
|
|
{ id: "q1", prompt: "Anything?", selectionMode: "single", options: [] },
|
|
{
|
|
id: "q2",
|
|
prompt: "Ship it?",
|
|
selectionMode: "single",
|
|
options: [
|
|
{ id: "yes", label: "Yes" },
|
|
{ id: "no", label: "No" },
|
|
],
|
|
},
|
|
]))).toBe(false);
|
|
});
|
|
|
|
it("ignores non-ask_user_questions interactions", () => {
|
|
const confirmation = {
|
|
id: "interaction-confirm",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "request_confirmation",
|
|
status: "pending",
|
|
continuationPolicy: "wake_assignee",
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:00:00.000Z",
|
|
payload: { version: 1 },
|
|
} as unknown as IssueThreadInteraction;
|
|
expect(isDegenerateAskUserQuestions(confirmation)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("isSupersededByNewerSiblingInteraction", () => {
|
|
function askInteraction(overrides: Partial<AskUserQuestionsInteraction>): AskUserQuestionsInteraction {
|
|
return {
|
|
id: "interaction-ask",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "ask_user_questions",
|
|
status: "expired",
|
|
continuationPolicy: "wake_assignee",
|
|
...resolverPolicyFields,
|
|
createdAt: "2026-04-06T12:00:00.000Z",
|
|
updatedAt: "2026-04-06T12:00:00.000Z",
|
|
payload: {
|
|
version: 1,
|
|
questions: [{ id: "q", prompt: "t", selectionMode: "single", options: [{ id: "L", label: "L" }] }],
|
|
},
|
|
...overrides,
|
|
} as AskUserQuestionsInteraction;
|
|
}
|
|
|
|
it("hides an expired card superseded by a newer sibling question", () => {
|
|
const interaction = askInteraction({
|
|
status: "expired",
|
|
result: {
|
|
version: 1,
|
|
answers: [],
|
|
expirationReason: "superseded_by_newer_interaction",
|
|
supersededByInteractionId: "interaction-newer",
|
|
summaryMarkdown: null,
|
|
},
|
|
});
|
|
expect(isSupersededByNewerSiblingInteraction(interaction)).toBe(true);
|
|
expect(shouldHideInteractionCard(interaction)).toBe(true);
|
|
});
|
|
|
|
it("never hides a still-pending card (would strand the assignee)", () => {
|
|
// Guards the PAP-424 / 00b136f45 invariant: a pending question must always
|
|
// render even if the result somehow already names a superseding sibling.
|
|
const interaction = askInteraction({
|
|
status: "pending",
|
|
result: {
|
|
version: 1,
|
|
answers: [],
|
|
expirationReason: "superseded_by_newer_interaction",
|
|
supersededByInteractionId: "interaction-newer",
|
|
summaryMarkdown: null,
|
|
},
|
|
});
|
|
expect(isSupersededByNewerSiblingInteraction(interaction)).toBe(false);
|
|
expect(shouldHideInteractionCard(interaction)).toBe(false);
|
|
});
|
|
|
|
it("keeps the stale notice for a comment-superseded card (does not hide it)", () => {
|
|
const interaction = askInteraction({
|
|
status: "expired",
|
|
result: {
|
|
version: 1,
|
|
answers: [],
|
|
expirationReason: "superseded_by_comment",
|
|
commentId: "11111111-1111-1111-1111-111111111111",
|
|
summaryMarkdown: null,
|
|
},
|
|
});
|
|
expect(isSupersededByNewerSiblingInteraction(interaction)).toBe(false);
|
|
expect(shouldHideInteractionCard(interaction)).toBe(false);
|
|
});
|
|
|
|
it("still hides a degenerate card through the combined predicate", () => {
|
|
const degenerate = askInteraction({
|
|
status: "pending",
|
|
result: null,
|
|
payload: { version: 1, questions: [] },
|
|
});
|
|
expect(isSupersededByNewerSiblingInteraction(degenerate)).toBe(false);
|
|
expect(shouldHideInteractionCard(degenerate)).toBe(true);
|
|
});
|
|
});
|
|
|
|
|
|
describe("interaction readiness polling", () => {
|
|
it("uses a fast cadence only for pending preparation and preserves the idle fallback", () => {
|
|
const preparing = { ...pendingRequestConfirmationInteraction, acceptanceBlocker: "workspace_sync_pending" as const };
|
|
expect(interactionReadinessRefetchInterval([preparing], 20_000)).toBe(2_000);
|
|
expect(interactionReadinessRefetchInterval([pendingRequestConfirmationInteraction], 20_000)).toBe(20_000);
|
|
expect(interactionReadinessRefetchInterval([{ ...preparing, status: "expired" }])).toBe(false);
|
|
expect(interactionReadinessRefetchInterval(undefined)).toBe(false);
|
|
});
|
|
});
|