From 0618785386dd0caa1e965f76490bfbfc8ad330a3 Mon Sep 17 00:00:00 2001
From: "Nick T." <73005126+tiliakoos@users.noreply.github.com>
Date: Mon, 23 Nov 2026 22:48:22 -0500
Subject: [PATCH 1/2] fix(web): a copied issue or pull request error no longer
ends in a broken character
The error in an action's failure toast is cut at 320 units, which could
leave half of an emoji. The cut now stops one unit earlier then.
---
.../pullRequestDetail.logic.test.ts | 3 +
.../pullRequest/pullRequestDetail.logic.ts | 4 +-
...-issue-error-keeps-whole-characters.e2e.ts | 121 ++++++++++++++++++
3 files changed, 127 insertions(+), 1 deletion(-)
create mode 100644 scripts/scenarios/copied-issue-error-keeps-whole-characters.e2e.ts
diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
index a71bc0d2db367..4fd39e8169bda 100644
--- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
+++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
@@ -989,6 +989,9 @@ describe("what to say when an action fails", () => {
const reason = "The worktree directory already exists. Choose another directory.";
expect(checkoutFailureDescription(diagnostic(reason))).toBe(reason);
expect(checkoutFailureDescription(diagnostic("x".repeat(900)))).toBe(`${"x".repeat(319)}…`);
+ expect(checkoutFailureDescription(diagnostic(`${"x".repeat(318)}😀 tail`))).toBe(
+ `${"x".repeat(318)}…`,
+ );
for (const failure of [undefined, diagnostic(""), diagnostic("exited with code 1")]) {
expect(checkoutFailureDescription(failure)).toBe(
"Check that the branch still exists and is not checked out elsewhere, then try again.",
diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
index ad9285f6fc322..076917abee877 100644
--- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
+++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
@@ -4,6 +4,7 @@ import {
pullRequestLinkCommit,
resolvePullRequestReviewAnchor,
} from "@t3tools/shared/pullRequestAnchor";
+import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
import { stripInlineContextReferences } from "~/lib/composerContextReferences";
import type { Nodes } from "hast";
@@ -1569,10 +1570,11 @@ export function readableFailure(failure: unknown, hint: string): string {
failure instanceof Error ? failure.message : typeof failure === "string" ? failure : "";
const detail = raw.replace(OPERATION_PREFIX, "").trim();
if (detail.length === 0 || TOOL_NOISE.some((pattern) => pattern.test(detail))) return hint;
+ const end = FAILURE_DETAIL_MAX_LENGTH - 1;
const bounded =
detail.length <= FAILURE_DETAIL_MAX_LENGTH
? detail
- : `${detail.slice(0, FAILURE_DETAIL_MAX_LENGTH - 1)}…`;
+ : `${detail.slice(0, splitsSurrogatePair(detail, end) ? end - 1 : end)}…`;
return bounded;
}
diff --git a/scripts/scenarios/copied-issue-error-keeps-whole-characters.e2e.ts b/scripts/scenarios/copied-issue-error-keeps-whole-characters.e2e.ts
new file mode 100644
index 0000000000000..168d95794cdd9
--- /dev/null
+++ b/scripts/scenarios/copied-issue-error-keeps-whole-characters.e2e.ts
@@ -0,0 +1,121 @@
+///
+import type { IssueCandidates, IssueDetail, IssueRef } from "@t3tools/contracts";
+import { expect } from "e2e";
+
+import { test, WEB } from "./t3.ts";
+
+const PREFIX = "Issue operation update failed: ";
+const KEPT = `${PREFIX}${"The tracker refused this label. ".repeat(10)}`.slice(0, 318);
+// The emoji's two UTF-16 units straddle unit 319, where the toast's error is cut.
+const DETAIL = `${KEPT.slice(PREFIX.length)}😀 and the rest of the error`;
+
+test(
+ "A long issue error copied from its toast ends without a broken character",
+ WEB,
+ async ({ t3, app, browser, screen }) => {
+ await t3.project("demo");
+ await browser.addInitScript((failureDetail) => {
+ const send = WebSocket.prototype.send;
+ WebSocket.prototype.send = function (data) {
+ const request: { _tag: string; id: string; tag: string; payload: IssueRef } | null =
+ typeof data === "string" ? JSON.parse(data) : null;
+ if (request?._tag !== "Request") return send.call(this, data);
+ const reply = (exit: unknown) =>
+ queueMicrotask(() =>
+ this.dispatchEvent(
+ new MessageEvent("message", {
+ data: JSON.stringify({ _tag: "Exit", requestId: request.id, exit }),
+ }),
+ ),
+ );
+ if (request.tag === "issues.detail") {
+ const { projectId, tracker, scope, key } = request.payload;
+ const detail: IssueDetail = {
+ projectId,
+ tracker,
+ scope,
+ key,
+ host: "github.com",
+ displayKey: "#42",
+ projectTitle: "demo",
+ title: "Issue with a label to change",
+ body: "",
+ url: "https://github.com/example/demo/issues/42",
+ author: null,
+ state: { category: "open", name: "Open" },
+ createdAt: "2026-10-01T00:00:00.000Z",
+ updatedAt: "2026-10-01T00:00:00.000Z",
+ closedAt: null,
+ assignees: [],
+ labels: [],
+ commentCount: 0,
+ writable: true,
+ capabilities: {
+ create: false,
+ edit: false,
+ comment: false,
+ labels: true,
+ assignees: false,
+ reactions: false,
+ templates: false,
+ linkedPullRequests: false,
+ events: false,
+ search: true,
+ },
+ viewerPermissions: {
+ setState: false,
+ comment: false,
+ edit: false,
+ labels: true,
+ assignees: false,
+ },
+ states: [],
+ viewer: null,
+ comments: [],
+ commentsCursor: null,
+ events: [],
+ linkedPullRequests: [],
+ };
+ reply({ _tag: "Success", value: detail });
+ return;
+ }
+ if (request.tag === "issues.candidates") {
+ const value: IssueCandidates = {
+ labels: [{ name: "bug", color: "d73a4a", description: null }],
+ assignees: [],
+ truncated: false,
+ };
+ reply({ _tag: "Success", value });
+ return;
+ }
+ if (request.tag === "issues.update") {
+ reply({
+ _tag: "Failure",
+ cause: [
+ {
+ _tag: "Fail",
+ error: { _tag: "IssueOperationError", operation: "update", detail: failureDetail },
+ },
+ ],
+ });
+ return;
+ }
+ return send.call(this, data);
+ };
+ }, DETAIL);
+
+ await t3.open("/issues?selectedProjectId=demo&tracker=github&scope=example/demo&key=42");
+ await screen.getByRole("combobox", "Change labels", { exact: true }).tap();
+ await screen.getByRole("option", "bug").tap();
+ await browser.keyboard.press("Escape");
+
+ // The toast shows four lines of a long error, so its end is read from what Copy error copies.
+ await screen.getByRole("button", "Copy error", { exact: true }).tap();
+ await screen.getByRole("button", "Copied error", { exact: true }).waitFor();
+ const search = screen.getByRole("searchbox", "Search issues");
+ await search.tap();
+ await browser.keyboard.press("ControlOrMeta+v");
+ await app.screenshot("pasted-error");
+ await expect(search).toHaveValue(`${KEPT}…`);
+ },
+);
From c0b155535e5e464879e2fc547cc219857e3e6d30 Mon Sep 17 00:00:00 2001
From: Julius Marminge
Date: Tue, 24 Nov 2026 04:17:40 +0000
Subject: [PATCH 2/2] refactor(web): match the file's surrogate guard and drop
the scenario
readableFailure now uses the same inline high-surrogate check as the other
truncations in pullRequestDetail.logic.ts instead of importing a helper from
assistantCitations. The unit assertion already fails without the fix, so the
WebSocket-mocking scenario is removed.
Co-Authored-By: Claude Opus 5.5
---
.../pullRequest/pullRequestDetail.logic.ts | 12 +-
...-issue-error-keeps-whole-characters.e2e.ts | 121 ------------------
2 files changed, 5 insertions(+), 128 deletions(-)
delete mode 100644 scripts/scenarios/copied-issue-error-keeps-whole-characters.e2e.ts
diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
index 076917abee877..e69fd93773e89 100644
--- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
+++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
@@ -4,7 +4,6 @@ import {
pullRequestLinkCommit,
resolvePullRequestReviewAnchor,
} from "@t3tools/shared/pullRequestAnchor";
-import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
import { stripInlineContextReferences } from "~/lib/composerContextReferences";
import type { Nodes } from "hast";
@@ -1570,12 +1569,11 @@ export function readableFailure(failure: unknown, hint: string): string {
failure instanceof Error ? failure.message : typeof failure === "string" ? failure : "";
const detail = raw.replace(OPERATION_PREFIX, "").trim();
if (detail.length === 0 || TOOL_NOISE.some((pattern) => pattern.test(detail))) return hint;
- const end = FAILURE_DETAIL_MAX_LENGTH - 1;
- const bounded =
- detail.length <= FAILURE_DETAIL_MAX_LENGTH
- ? detail
- : `${detail.slice(0, splitsSurrogatePair(detail, end) ? end - 1 : end)}…`;
- return bounded;
+ if (detail.length <= FAILURE_DETAIL_MAX_LENGTH) return detail;
+ let end = FAILURE_DETAIL_MAX_LENGTH - 1;
+ const last = detail.charCodeAt(end - 1);
+ if (last >= 0xd800 && last <= 0xdbff) end -= 1;
+ return `${detail.slice(0, end)}…`;
}
const isGitCommandError = Schema.is(GitCommandError);
diff --git a/scripts/scenarios/copied-issue-error-keeps-whole-characters.e2e.ts b/scripts/scenarios/copied-issue-error-keeps-whole-characters.e2e.ts
deleted file mode 100644
index 168d95794cdd9..0000000000000
--- a/scripts/scenarios/copied-issue-error-keeps-whole-characters.e2e.ts
+++ /dev/null
@@ -1,121 +0,0 @@
-///
-import type { IssueCandidates, IssueDetail, IssueRef } from "@t3tools/contracts";
-import { expect } from "e2e";
-
-import { test, WEB } from "./t3.ts";
-
-const PREFIX = "Issue operation update failed: ";
-const KEPT = `${PREFIX}${"The tracker refused this label. ".repeat(10)}`.slice(0, 318);
-// The emoji's two UTF-16 units straddle unit 319, where the toast's error is cut.
-const DETAIL = `${KEPT.slice(PREFIX.length)}😀 and the rest of the error`;
-
-test(
- "A long issue error copied from its toast ends without a broken character",
- WEB,
- async ({ t3, app, browser, screen }) => {
- await t3.project("demo");
- await browser.addInitScript((failureDetail) => {
- const send = WebSocket.prototype.send;
- WebSocket.prototype.send = function (data) {
- const request: { _tag: string; id: string; tag: string; payload: IssueRef } | null =
- typeof data === "string" ? JSON.parse(data) : null;
- if (request?._tag !== "Request") return send.call(this, data);
- const reply = (exit: unknown) =>
- queueMicrotask(() =>
- this.dispatchEvent(
- new MessageEvent("message", {
- data: JSON.stringify({ _tag: "Exit", requestId: request.id, exit }),
- }),
- ),
- );
- if (request.tag === "issues.detail") {
- const { projectId, tracker, scope, key } = request.payload;
- const detail: IssueDetail = {
- projectId,
- tracker,
- scope,
- key,
- host: "github.com",
- displayKey: "#42",
- projectTitle: "demo",
- title: "Issue with a label to change",
- body: "",
- url: "https://github.com/example/demo/issues/42",
- author: null,
- state: { category: "open", name: "Open" },
- createdAt: "2026-10-01T00:00:00.000Z",
- updatedAt: "2026-10-01T00:00:00.000Z",
- closedAt: null,
- assignees: [],
- labels: [],
- commentCount: 0,
- writable: true,
- capabilities: {
- create: false,
- edit: false,
- comment: false,
- labels: true,
- assignees: false,
- reactions: false,
- templates: false,
- linkedPullRequests: false,
- events: false,
- search: true,
- },
- viewerPermissions: {
- setState: false,
- comment: false,
- edit: false,
- labels: true,
- assignees: false,
- },
- states: [],
- viewer: null,
- comments: [],
- commentsCursor: null,
- events: [],
- linkedPullRequests: [],
- };
- reply({ _tag: "Success", value: detail });
- return;
- }
- if (request.tag === "issues.candidates") {
- const value: IssueCandidates = {
- labels: [{ name: "bug", color: "d73a4a", description: null }],
- assignees: [],
- truncated: false,
- };
- reply({ _tag: "Success", value });
- return;
- }
- if (request.tag === "issues.update") {
- reply({
- _tag: "Failure",
- cause: [
- {
- _tag: "Fail",
- error: { _tag: "IssueOperationError", operation: "update", detail: failureDetail },
- },
- ],
- });
- return;
- }
- return send.call(this, data);
- };
- }, DETAIL);
-
- await t3.open("/issues?selectedProjectId=demo&tracker=github&scope=example/demo&key=42");
- await screen.getByRole("combobox", "Change labels", { exact: true }).tap();
- await screen.getByRole("option", "bug").tap();
- await browser.keyboard.press("Escape");
-
- // The toast shows four lines of a long error, so its end is read from what Copy error copies.
- await screen.getByRole("button", "Copy error", { exact: true }).tap();
- await screen.getByRole("button", "Copied error", { exact: true }).waitFor();
- const search = screen.getByRole("searchbox", "Search issues");
- await search.tap();
- await browser.keyboard.press("ControlOrMeta+v");
- await app.screenshot("pasted-error");
- await expect(search).toHaveValue(`${KEPT}…`);
- },
-);