mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 22:49:00 +01:00
Show useful task notification content (#22441)
Task notifications repeated identifiers and omitted useful activity details. Use task titles, actor and comment previews, and concrete field changes. Share bounded secret redaction per event after viewer access checks. Suppress updates without useful details. Verified with focused regression tests, package typechecks and server build, and the full green CI run. Greptile scored the final head 5/5 with no unresolved review threads. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
1ced68c636
commit
9bc90cb189
14 files changed
+636
-128
No files matched your search
@@ -204,9 +204,15 @@ describe("LiveUpdatesProvider socket run notification scope", () => {
|
||||
await reactAct(async () => sockets[0]!.onmessage!(new MessageEvent("message", {
|
||||
data: JSON.stringify({ id: 99, companyId: "company-1", type: "activity.logged",
|
||||
createdAt: "2026-09-09T18:00:00.000Z", toastEligible: eligibility,
|
||||
payload: { entityType: "issue", entityId: "other-task", action: "issue.comment_added", actorType: "user", actorId: "another-user" } }),
|
||||
payload: { entityType: "issue", entityId: "other-task", action: "issue.comment_added", actorType: "user", actorId: "another-user",
|
||||
actorName: "Nibbler", issueTitle: "Fix task notifications", issueIdentifier: "PAP-1234",
|
||||
notificationDetails: { commentId: "comment-1", bodySnippet: "Ready **for review**" } } }),
|
||||
})));
|
||||
expect(pushToast).toHaveBeenCalledTimes(eligibility === true ? 1 : 0);
|
||||
if (eligibility === true) expect(pushToast).toHaveBeenCalledWith(expect.objectContaining({
|
||||
title: "Fix task notifications", body: "Nibbler: Ready for review",
|
||||
action: { label: "View task", href: "/issues/PAP-1234" },
|
||||
}));
|
||||
});
|
||||
|
||||
it("keeps generic agent errors quiet even with eligibility metadata", async () => {
|
||||
|
||||
@@ -2230,30 +2230,74 @@ describe("task subtree notification context", () => {
|
||||
|
||||
describe("activity toast attribution", () => {
|
||||
const build = __liveUpdatesTestUtils.buildActivityToast;
|
||||
const payload = { action: "issue.created", entityType: "issue", entityId: "task-1", issueIdentifier: "PAP-1234", actorType: "user", actorId: "user-1", actorName: "Alex Example", actorImage: "/alex.png" };
|
||||
const payload = { action: "issue.created", entityType: "issue", entityId: "task-1", issueIdentifier: "PAP-1234", issueTitle: "Fix task notifications", actorType: "user", actorId: "user-1", actorName: "Alex Example", actorImage: "/alex.png" };
|
||||
const viewer = { userId: "other-user", agentId: null };
|
||||
it.each([
|
||||
["issue.created", "Alex Example created PAP-1234"],
|
||||
["issue.updated", "Alex Example updated PAP-1234"],
|
||||
["issue.comment_added", "Alex Example commented on PAP-1234"],
|
||||
])("uses the server task identifier for %s with an empty cache and no activity details", (action, title) => {
|
||||
const toast = build(new QueryClient(), "company", { ...payload, action }, { userId: "other-user", agentId: null });
|
||||
expect(toast?.title).toBe(title);
|
||||
expect(toast?.action).toEqual({ label: "View PAP-1234", href: "/issues/PAP-1234" });
|
||||
if (action === "issue.updated") expect(toast?.body).toBe("PAP-1234");
|
||||
expect(JSON.stringify(toast)).not.toContain("Task task-1");
|
||||
["issue.created", {}, "Alex Example created the task"],
|
||||
["issue.updated", { status: "in_review", statusFrom: "in_progress" }, "Alex Example changed status from in progress to in review"],
|
||||
["issue.comment_added", { commentId: "c", bodySnippet: "## Ready **for review**\nSee [the plan](/plan)." }, "Alex Example: Ready for review See the plan."],
|
||||
])("shows the task title and useful content for %s with an empty cache", (action, notificationDetails, body) => {
|
||||
const toast = build(new QueryClient(), "company", { ...payload, action, notificationDetails }, viewer);
|
||||
expect(toast?.title).toBe("Fix task notifications");
|
||||
expect(toast?.body).toBe(body);
|
||||
expect(toast?.action).toEqual({ label: "View task", href: "/issues/PAP-1234" });
|
||||
});
|
||||
it("uses a generic task label when the identifier is unavailable", () => {
|
||||
const toast = build(new QueryClient(), "company", { ...payload, action: "issue.updated", issueIdentifier: undefined }, { userId: "other-user", agentId: null });
|
||||
expect(toast?.title).toBe("Alex Example updated Task");
|
||||
expect(toast?.body).toBe("Task");
|
||||
expect(toast?.action).toEqual({ label: "View Task", href: "/issues/task-1" });
|
||||
it("uses a generic task title when the title and identifier are unavailable", () => {
|
||||
const toast = build(new QueryClient(), "company", { ...payload, issueTitle: undefined, issueIdentifier: undefined }, viewer);
|
||||
expect(toast?.title).toBe("Task");
|
||||
expect(toast?.body).toBe("Alex Example created the task");
|
||||
expect(toast?.action).toEqual({ label: "View task", href: "/issues/task-1" });
|
||||
});
|
||||
it("resolves cached task titles by the server identifier", () => {
|
||||
it("resolves cached task titles for older servers, and prefers a fresh server title", () => {
|
||||
const queryClient = new QueryClient();
|
||||
queryClient.setQueryData(queryKeys.issues.detail("PAP-1234"), { id: "task-1", identifier: "PAP-1234", title: "Fix task toasts" });
|
||||
const toast = build(queryClient, "company", { ...payload, action: "issue.updated" }, { userId: "other-user", agentId: null });
|
||||
expect(toast?.title).toBe("Alex Example updated PAP-1234");
|
||||
expect(toast?.body).toBe("Fix task toasts");
|
||||
queryClient.setQueryData(queryKeys.issues.detail("PAP-1234"), { id: "task-1", identifier: "PAP-1234", title: "Cached title" });
|
||||
expect(build(queryClient, "company", { ...payload, issueTitle: undefined }, viewer)?.title).toBe("Cached title");
|
||||
expect(build(queryClient, "company", payload, viewer)?.title).toBe("Fix task notifications");
|
||||
});
|
||||
it("keeps routine or unspecified updates quiet, even with a cached title", () => {
|
||||
for (const details of [undefined, {}, { executionRunId: "run" }, { source: "comment", status: "done" }]) {
|
||||
expect(build(new QueryClient(), "company", { ...payload, action: "issue.updated", notificationDetails: details }, viewer)).toBeNull();
|
||||
}
|
||||
});
|
||||
it("does not fall back to raw details when the server projected an empty update", () => {
|
||||
expect(build(new QueryClient(), "company", { ...payload, action: "issue.updated", notificationDetails: {}, details: { status: "done" } }, viewer)).toBeNull();
|
||||
});
|
||||
it("keeps actor names, priority and description changes in the body", () => {
|
||||
const toast = build(new QueryClient(), "company", { ...payload, action: "issue.updated", notificationDetails: { priority: "high", descriptionChanged: true } }, viewer);
|
||||
expect(toast?.body).toBe("Alex Example set priority to high, changed the description");
|
||||
});
|
||||
it("combines a comment with its status change without repeating the task title", () => {
|
||||
const toast = build(new QueryClient(), "company", { ...payload, action: "issue.comment_added", notificationDetails: { commentId: "c", bodySnippet: "Finished the fix", status: "done", statusFrom: "in_progress" } }, viewer);
|
||||
expect(toast?.title).toBe("Fix task notifications");
|
||||
expect(toast?.body).toBe("Alex Example changed status from in progress to done: Finished the fix");
|
||||
});
|
||||
it("reports a projected reopen once and retains other changes and the comment", () => {
|
||||
const toast = build(new QueryClient(), "company", { ...payload, action: "issue.comment_added", notificationDetails: {
|
||||
commentId: "reopen-comment", bodySnippet: "One more fix", reopened: true, reopenedFrom: "done",
|
||||
status: "todo", statusFrom: "done", priority: "high", descriptionChanged: true,
|
||||
} }, viewer);
|
||||
expect(toast?.body).toBe("Alex Example reopened from done to to do, set priority to high, changed the description: One more fix");
|
||||
expect(toast?.body).not.toContain("changed status");
|
||||
});
|
||||
it("includes reopen context and uses a clear fallback when the comment is unavailable", () => {
|
||||
expect(build(new QueryClient(), "company", { ...payload, action: "issue.comment_added", notificationDetails: { reopened: true, reopenedFrom: "done", bodySnippet: "One more fix" } }, viewer)?.body)
|
||||
.toBe("Alex Example reopened from done: One more fix");
|
||||
expect(build(new QueryClient(), "company", { ...payload, action: "issue.comment_added" }, viewer)?.body).toBe("Alex Example added a comment");
|
||||
});
|
||||
it("retains legacy comment snippets and change details", () => {
|
||||
expect(build(new QueryClient(), "company", { ...payload, action: "issue.comment_added", details: { bodySnippet: "Ready" } }, viewer)?.body).toBe("Alex Example: Ready");
|
||||
expect(build(new QueryClient(), "company", { ...payload, action: "issue.updated", details: { status: "blocked" } }, viewer)?.body).toBe("Alex Example changed status to blocked");
|
||||
});
|
||||
it("bounds long titles and comments while retaining the actor", () => {
|
||||
const toast = build(new QueryClient(), "company", { ...payload, issueTitle: "Title ".repeat(100), action: "issue.comment_added", notificationDetails: { bodySnippet: "Comment ".repeat(100) } }, viewer);
|
||||
expect(toast?.title.length).toBeLessThanOrEqual(120);
|
||||
expect(toast?.body?.length).toBeLessThanOrEqual(240);
|
||||
expect(toast?.body).toMatch(/^Alex Example: Comment/);
|
||||
expect(toast?.body).toMatch(/…$/);
|
||||
});
|
||||
it("deduplicates by comment ID rather than the task", () => {
|
||||
const make = (id: string) => build(new QueryClient(), "company", { ...payload, action: "issue.comment_added", notificationDetails: { commentId: id } }, viewer);
|
||||
expect(make("first")?.dedupeKey).not.toBe(make("second")?.dedupeKey);
|
||||
});
|
||||
it.each(["issue.created", "issue.updated", "issue.comment_added"])("hides the viewer's own %s", (action) => {
|
||||
expect(build(new QueryClient(), "company", { ...payload, action }, { userId: "user-1", agentId: null })).toBeNull();
|
||||
@@ -2262,19 +2306,18 @@ describe("activity toast attribution", () => {
|
||||
expect(build(new QueryClient(), "company", { ...payload, actorType: "agent", actorId: "agent-1" }, { userId: null, agentId: "agent-1" })).toBeNull();
|
||||
});
|
||||
it("uses the real name and photo with an empty directory cache", () => {
|
||||
const toast = build(new QueryClient(), "company", payload, { userId: "other-user", agentId: null });
|
||||
expect(toast?.title).toBe("Alex Example created PAP-1234");
|
||||
expect(toast?.actor).toMatchObject({ type: "user", name: "Alex Example", image: "/alex.png" });
|
||||
expect(build(new QueryClient(), "company", payload, viewer)?.actor).toMatchObject({ type: "user", name: "Alex Example", image: "/alex.png" });
|
||||
});
|
||||
it("uses the agent's custom avatar with an empty agent cache", () => {
|
||||
const appearance = { schemaVersion: 1, characterVersion: "cap-v1", paletteId: "bubblegum-sky", customAvatarAssetId: "11111111-1111-4111-8111-111111111111" };
|
||||
const toast = build(new QueryClient(), "company", { ...payload, actorType: "agent", actorId: "agent-1", actorName: "Coder", actorAppearance: appearance }, { userId: "user-1", agentId: null });
|
||||
expect(toast?.title).toBe("Coder created PAP-1234");
|
||||
const toast = build(new QueryClient(), "company", { ...payload, actorType: "agent", actorId: "agent-1", actorName: "Coder", actorAppearance: appearance }, viewer);
|
||||
expect(toast?.body).toBe("Coder created the task");
|
||||
expect(toast?.actor?.appearance).toEqual(appearance);
|
||||
});
|
||||
it("keeps system activity distinct from people", () => {
|
||||
const toast = build(new QueryClient(), "company", { ...payload, actorType: "system", actorName: undefined }, { userId: "user-1", agentId: null });
|
||||
expect(toast?.title).toBe("System created PAP-1234");
|
||||
it("keeps system activity distinct from people and explains the change", () => {
|
||||
const toast = build(new QueryClient(), "company", { ...payload, action: "issue.updated", actorType: "system", actorName: undefined, notificationDetails: { status: "blocked" } }, viewer);
|
||||
expect(toast?.title).toBe("Fix task notifications");
|
||||
expect(toast?.body).toBe("System changed status to blocked");
|
||||
expect(toast?.actor).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -63,6 +63,7 @@ import { queryKeys } from "../lib/queryKeys";
|
||||
import { extractCompanyPrefixFromPath, toCompanyRelativePath } from "../lib/company-routes";
|
||||
import { useLocation } from "../lib/router";
|
||||
import { agentRouteRef } from "../lib/utils";
|
||||
import { markdownToPlainText } from "../lib/markdown-plain-text";
|
||||
import { buildSameOriginWebSocketUrl } from "../lib/websocket-url";
|
||||
import { tryCreateWebSocket } from "../lib/websocket";
|
||||
|
||||
@@ -1143,32 +1144,25 @@ function describeIssueUpdate(
|
||||
): string | null {
|
||||
if (!details) return null;
|
||||
const changes: string[] = [];
|
||||
if (typeof details.status === "string")
|
||||
changes.push(`status -> ${details.status.replace(/_/g, " ")}`);
|
||||
if (typeof details.priority === "string")
|
||||
changes.push(`priority -> ${details.priority}`);
|
||||
if (
|
||||
typeof details.assigneeAgentId === "string" ||
|
||||
typeof details.assigneeUserId === "string"
|
||||
) {
|
||||
changes.push("reassigned");
|
||||
} else if (
|
||||
details.assigneeAgentId === null ||
|
||||
details.assigneeUserId === null
|
||||
) {
|
||||
changes.push("unassigned");
|
||||
}
|
||||
const statusLabel = (status: string) => status === "todo" ? "to do" : status.replace(/_/g, " ");
|
||||
if (details.reopened === true) {
|
||||
const from = readString(details.reopenedFrom);
|
||||
changes.push(
|
||||
from ? `reopened from ${from.replace(/_/g, " ")}` : "reopened",
|
||||
);
|
||||
const from = readString(details.reopenedFrom) ?? readString(details.statusFrom);
|
||||
const to = readString(details.status);
|
||||
changes.push(`reopened${from ? ` from ${statusLabel(from)}` : " the task"}${to ? ` to ${statusLabel(to)}` : ""}`);
|
||||
} else if (typeof details.status === "string") {
|
||||
changes.push(typeof details.statusFrom === "string"
|
||||
? `changed status from ${statusLabel(details.statusFrom)} to ${statusLabel(details.status)}`
|
||||
: `changed status to ${statusLabel(details.status)}`);
|
||||
}
|
||||
if (typeof details.title === "string") changes.push("title changed");
|
||||
if (typeof details.description === "string")
|
||||
changes.push("description changed");
|
||||
if (changes.length > 0) return changes.join(", ");
|
||||
return null;
|
||||
if (typeof details.priority === "string") changes.push(`set priority to ${details.priority}`);
|
||||
if (details.assignment === "reassigned" || typeof details.assigneeAgentId === "string" || typeof details.assigneeUserId === "string") {
|
||||
changes.push("reassigned the task");
|
||||
} else if (details.assignment === "unassigned" || details.assigneeAgentId === null || details.assigneeUserId === null) {
|
||||
changes.push("unassigned the task");
|
||||
}
|
||||
if (details.titleChanged === true || typeof details.title === "string") changes.push("changed the title");
|
||||
if (details.descriptionChanged === true || typeof details.description === "string") changes.push("changed the description");
|
||||
return changes.length > 0 ? changes.join(", ") : null;
|
||||
}
|
||||
|
||||
function buildActivityToast(
|
||||
@@ -1180,7 +1174,8 @@ function buildActivityToast(
|
||||
const entityType = readString(payload.entityType);
|
||||
const entityId = readString(payload.entityId);
|
||||
const action = readString(payload.action);
|
||||
const details = readRecord(payload.details);
|
||||
const activityDetails = readRecord(payload.details);
|
||||
const details = readRecord(payload.notificationDetails) ?? activityDetails;
|
||||
const actorId = readString(payload.actorId);
|
||||
const actorType = readString(payload.actorType);
|
||||
|
||||
@@ -1198,8 +1193,9 @@ function buildActivityToast(
|
||||
companyId,
|
||||
entityId,
|
||||
{
|
||||
...details,
|
||||
identifier: readString(payload.issueIdentifier) ?? readString(details?.identifier),
|
||||
...activityDetails,
|
||||
title: readString(payload.issueTitle) ?? readString(activityDetails?.title),
|
||||
identifier: readString(payload.issueIdentifier) ?? readString(activityDetails?.identifier),
|
||||
},
|
||||
);
|
||||
const actor = readString(readString(payload.actorName)?.trim()) ?? resolveActorLabel(queryClient, companyId, actorType, actorId);
|
||||
@@ -1226,70 +1222,41 @@ function buildActivityToast(
|
||||
actorId === currentActor.agentId);
|
||||
if (isSelfActivity) return null;
|
||||
|
||||
const title = truncate((issue.title?.trim() || "Task").replace(/\s+/g, " "), 120);
|
||||
const actionLink = { label: "View task", href: issue.href };
|
||||
if (action === "issue.created") {
|
||||
return {
|
||||
actor: toastActor,
|
||||
title: `${actor} created ${issue.ref}`,
|
||||
body: issue.title ? truncate(issue.title, 96) : undefined,
|
||||
title,
|
||||
body: truncate(`${actor} created the task`, 240),
|
||||
tone: "success",
|
||||
action: { label: `View ${issue.ref}`, href: issue.href },
|
||||
action: actionLink,
|
||||
dedupeKey: `activity:${action}:${entityId}`,
|
||||
};
|
||||
}
|
||||
|
||||
const changeDesc = describeIssueUpdate(details);
|
||||
if (action === "issue.updated") {
|
||||
if (readString(details?.source) === "comment") {
|
||||
// Comment-driven updates emit a paired comment event; show one combined toast on the comment event.
|
||||
return null;
|
||||
}
|
||||
const changeDesc = describeIssueUpdate(details);
|
||||
const body = changeDesc
|
||||
? issue.title
|
||||
? `${truncate(issue.title, 64)} - ${changeDesc}`
|
||||
: changeDesc
|
||||
: issue.title
|
||||
? truncate(issue.title, 96)
|
||||
: issue.label;
|
||||
if (details?.source === "comment" || !changeDesc) return null;
|
||||
return {
|
||||
actor: toastActor,
|
||||
title: `${actor} updated ${issue.ref}`,
|
||||
body: truncate(body, 100),
|
||||
title,
|
||||
body: truncate(`${actor} ${changeDesc}`, 240),
|
||||
tone: "info",
|
||||
action: { label: `View ${issue.ref}`, href: issue.href },
|
||||
action: actionLink,
|
||||
dedupeKey: `activity:${action}:${entityId}`,
|
||||
};
|
||||
}
|
||||
|
||||
const commentId = readString(details?.commentId);
|
||||
const bodySnippet = readString(details?.bodySnippet);
|
||||
const reopened = details?.reopened === true;
|
||||
const updated = details?.updated === true;
|
||||
const reopenedFrom = readString(details?.reopenedFrom);
|
||||
const reopenedLabel = reopened
|
||||
? reopenedFrom
|
||||
? `reopened from ${reopenedFrom.replace(/_/g, " ")}`
|
||||
: "reopened"
|
||||
: null;
|
||||
const title = reopened
|
||||
? `${actor} reopened and commented on ${issue.ref}`
|
||||
: updated
|
||||
? `${actor} commented and updated ${issue.ref}`
|
||||
: `${actor} commented on ${issue.ref}`;
|
||||
const body = bodySnippet
|
||||
? reopenedLabel
|
||||
? `${reopenedLabel} - ${bodySnippet.replace(/^#+\s*/m, "").replace(/\n/g, " ")}`
|
||||
: bodySnippet.replace(/^#+\s*/m, "").replace(/\n/g, " ")
|
||||
: reopenedLabel
|
||||
? issue.title
|
||||
? `${reopenedLabel} - ${issue.title}`
|
||||
: reopenedLabel
|
||||
: (issue.title ?? undefined);
|
||||
const snippet = markdownToPlainText(readString(details?.bodySnippet) ?? "");
|
||||
const summary = changeDesc ? `${actor} ${changeDesc}` : actor;
|
||||
return {
|
||||
actor: toastActor,
|
||||
title,
|
||||
body: body ? truncate(body, 96) : undefined,
|
||||
body: truncate(snippet ? `${summary}: ${snippet}` : changeDesc ? summary : `${actor} added a comment`, 240),
|
||||
tone: "info",
|
||||
action: { label: `View ${issue.ref}`, href: issue.href },
|
||||
action: actionLink,
|
||||
dedupeKey: `activity:${action}:${entityId}:${commentId ?? "na"}`,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user