From a3eccd17b9ea89a62fc69d6b469fae29961d9642 Mon Sep 17 00:00:00 2001 From: Logan Johnson Date: Wed, 19 Aug 2026 23:28:15 +0000 Subject: [PATCH] fix(desktop): preserve malformed blocker destinations Keep a present non-string blocker message distinct from an absent field so malformed canvas data cannot fall back to a same-key PR or entity reference. Cover null, object, and numeric destinations alongside valid-message precedence and absent-field fallback. Co-authored-by: Other Brother Darryl Signed-off-by: loganj --- .../workstream-board/lib/workstreamWaits.ts | 9 ++- .../ui/WorkstreamWaits.test.mjs | 60 ++++++++++++++++++- .../workstream-board/ui/WorkstreamWaits.tsx | 51 ++++++++++------ 3 files changed, 100 insertions(+), 20 deletions(-) diff --git a/desktop/src/features/workstream-board/lib/workstreamWaits.ts b/desktop/src/features/workstream-board/lib/workstreamWaits.ts index e4f3e66617..c92648bfe5 100644 --- a/desktop/src/features/workstream-board/lib/workstreamWaits.ts +++ b/desktop/src/features/workstream-board/lib/workstreamWaits.ts @@ -21,6 +21,8 @@ export type WorkstreamWait = { since?: string; /** Optional canonical `buzz://message?...` destination from the canvas. */ message?: string; + /** True when the canvas explicitly supplied a `message` field, even if malformed. */ + messagePresent?: boolean; source: "manual" | "derived"; }; @@ -114,12 +116,15 @@ export function parseManualWorkstreamWaits( for (const value of values) { if (!isWorkstreamWait(value) || keys.has(value.key)) continue; keys.add(value.key); + const messagePresent = Object.hasOwn(value, "message"); const message = typeof value.message === "string" ? value.message : undefined; waits.push({ - ...value, - ...(message === undefined ? { message: undefined } : { message }), + key: value.key, actor: { ...value.actor }, + reason: value.reason, + ...(value.since === undefined ? {} : { since: value.since }), + ...(messagePresent ? { message, messagePresent: true } : {}), source: "manual", }); } diff --git a/desktop/src/features/workstream-board/ui/WorkstreamWaits.test.mjs b/desktop/src/features/workstream-board/ui/WorkstreamWaits.test.mjs index 96e1045f30..eae2b5563d 100644 --- a/desktop/src/features/workstream-board/ui/WorkstreamWaits.test.mjs +++ b/desktop/src/features/workstream-board/ui/WorkstreamWaits.test.mjs @@ -1,7 +1,8 @@ import assert from "node:assert/strict"; import test from "node:test"; -import { waitAge } from "./WorkstreamWaits.tsx"; +import { parseManualWorkstreamWaits } from "../lib/workstreamWaits.ts"; +import { resolveWorkstreamWaitLink, waitAge } from "./WorkstreamWaits.tsx"; const now = Date.parse("2026-08-19T16:00:00Z"); @@ -14,3 +15,60 @@ test("waitAge reports elapsed age for a trustworthy timestamp", () => { assert.equal(waitAge("2026-08-19T15:59:30Z", now), "0m"); assert.equal(waitAge("2026-08-19T14:00:00Z", now), "2h"); }); + +const REFERENCE = { + kind: "github", + rawUrl: "https://github.com/block/buzz/pull/6357", + href: "https://github.com/block/buzz/pull/6357", + identity: "github:block/buzz#6357", + owner: "block", + repository: "buzz", + number: 6357, +}; + +test("malformed present message values stay non-clickable while absent values retain reference fallback", () => { + for (const message of [null, {}, 7]) { + const [malformed] = parseManualWorkstreamWaits([ + { + key: "github:block/buzz#6357", + actor: { kind: "person", name: "Logan" }, + reason: "Need a decision", + message, + }, + ]); + assert.equal(malformed.messagePresent, true); + assert.equal(resolveWorkstreamWaitLink(malformed, REFERENCE), null); + } + + const [absent] = parseManualWorkstreamWaits([ + { + key: "github:block/buzz#6357", + actor: { kind: "person", name: "Logan" }, + reason: "Need a decision", + }, + ]); + assert.deepEqual(resolveWorkstreamWaitLink(absent, REFERENCE), { + kind: "reference", + reference: REFERENCE, + }); +}); + +test("valid present message destination wins over a same-key reference", () => { + const message = `buzz://message?channel=123e4567-e89b-12d3-a456-426614174000&id=${"a".repeat(64)}`; + const [wait] = parseManualWorkstreamWaits([ + { + key: "github:block/buzz#6357", + actor: { kind: "person", name: "Logan" }, + reason: "Need a decision", + message, + }, + ]); + assert.deepEqual(resolveWorkstreamWaitLink(wait, REFERENCE), { + kind: "message", + destination: { + channelId: "123e4567-e89b-12d3-a456-426614174000", + messageId: "a".repeat(64), + threadRootId: null, + }, + }); +}); diff --git a/desktop/src/features/workstream-board/ui/WorkstreamWaits.tsx b/desktop/src/features/workstream-board/ui/WorkstreamWaits.tsx index 64a5bb75a4..8eb94b2494 100644 --- a/desktop/src/features/workstream-board/ui/WorkstreamWaits.tsx +++ b/desktop/src/features/workstream-board/ui/WorkstreamWaits.tsx @@ -2,10 +2,13 @@ import { ExternalLink } from "lucide-react"; import { openUrl } from "@tauri-apps/plugin-opener"; import { useAppNavigation } from "@/app/navigation/useAppNavigation"; -import { parseWorkstreamWaitMessageLink } from "@/features/workstream-board/lib/workstreamWaits"; +import { + parseWorkstreamWaitMessageLink, + type WorkstreamWait, +} from "@/features/workstream-board/lib/workstreamWaits"; import type { UserProfileLookup } from "@/features/profile/lib/identity"; import type { WorkstreamPullRequestReference } from "@/features/workstream-board/lib/workstreamPullRequestStatus"; -import type { WorkstreamWait } from "@/features/workstream-board/lib/workstreamWaits"; +import type { ParsedMessageLink } from "@/features/messages/lib/messageLink"; import { parseEntityLink } from "@/shared/lib/entityLink"; import { normalizePubkey } from "@/shared/lib/pubkey"; import { useNow } from "@/shared/lib/useNow"; @@ -23,6 +26,24 @@ export function waitAge(since: string | undefined, now: number): string { return `${Math.floor(hours / 24)}d`; } +type WorkstreamWaitLinkResolution = + | { kind: "message"; destination: ParsedMessageLink } + | { kind: "reference"; reference: WorkstreamPullRequestReference } + | null; + +/** Preserve the distinction between an absent message field and a malformed one. */ +export function resolveWorkstreamWaitLink( + wait: Pick, + reference: WorkstreamPullRequestReference | undefined, +): WorkstreamWaitLinkResolution { + const messagePresent = wait.messagePresent ?? wait.message !== undefined; + if (messagePresent) { + const destination = parseWorkstreamWaitMessageLink(wait.message); + return destination ? { kind: "message", destination } : null; + } + return reference ? { kind: "reference", reference } : null; +} + function WaitAvatar({ wait, profiles, @@ -91,26 +112,22 @@ export function WorkstreamWaits({ {orderedWaits.map((wait) => { const age = waitAge(wait.since, now); const reference = referencesByIdentity.get(wait.key); - const messageDestination = parseWorkstreamWaitMessageLink( - wait.message, - ); + const link = resolveWorkstreamWaitLink(wait, reference); const open = - wait.message !== undefined - ? messageDestination - ? () => - void goChannel(messageDestination.channelId, { - messageId: messageDestination.messageId, - threadRootId: messageDestination.threadRootId, - }) - : undefined - : reference + link?.kind === "message" + ? () => + void goChannel(link.destination.channelId, { + messageId: link.destination.messageId, + threadRootId: link.destination.threadRootId, + }) + : link?.kind === "reference" ? () => { const parsed = - reference.kind === "buzz" - ? parseEntityLink(reference.href) + link.reference.kind === "buzz" + ? parseEntityLink(link.reference.href) : null; if (parsed?.ok) openEntityLink(parsed.value); - else void openUrl(reference.href); + else void openUrl(link.reference.href); } : undefined; const content = (