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 <cee32d92756729ee0c097c5661b879c6199931cd25315c8cf398dcbf0f155cf1@buzz.block.builderlab.xyz>

Signed-off-by: loganj <loganj@squareup.com>
This commit is contained in:
Logan Johnson
2026-08-19 23:28:15 +00:00
parent 2d945e9b26
commit a3eccd17b9
3 changed files with 100 additions and 20 deletions

View File

@@ -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",
});
}

View File

@@ -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,
},
});
});

View File

@@ -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<WorkstreamWait, "message" | "messagePresent">,
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 = (