Compare commits

..
Author SHA1 Message Date
bcf52f93b1 fix(app): draw Mermaid flowcharts whose labels contain an @ (#10165)
Mermaid 11's lexer reads an edge id (`e1@-->`) from any run of
non-space characters ending in "@". In `F[@mention] --> G` that run
starts at the node id and crosses the label's opening bracket, so the
parse fails and the card falls back to the source. Backport the lexer
half of mermaid-js/mermaid#8459, which stops the edge id at the node
shape characters, onto the pinned mermaid 11.16.0 and rebuild the
runtime. Moving to mermaid 12 instead changes the default layout and
look of every diagram and raises the browser floor, so it stays a
separate decision.

Closes #10157

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: monarchmaisuriya <37824914+monarchmaisuriya@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 21:52:18 +00:00
9 changed files with 65 additions and 58 deletions
File diff suppressed because one or more lines are too long
@@ -215,6 +215,32 @@ describe("Mermaid sandbox runtime", () => {
expect(widths).toEqual([240, 350, 900]);
});
/**
* Agents often write a label that starts with a mention or holds an email address. Mermaid 11
* read the text up to the "@" as an edge id, so these diagrams failed to parse.
*/
it.each([
"flowchart LR\n F[@mention in any workspace] --> G[Look up token]",
"flowchart LR\n A[ops@example.com] --> B",
"flowchart LR\n A -->|@user approves| B",
"graph TD\n A(@x) --> B{@x?}",
])("renders a flowchart whose label contains an @: %s", async (source) => {
const frame = await mountRuntime();
const result = await render(frame, { revision: 1, source });
expect(result).toMatchObject({ type: "rendered", revision: 1, source });
});
it("still renders a flowchart edge id", async () => {
const frame = await mountRuntime();
const source = "flowchart LR\n A[Start] e1@--> B[End]";
const result = await render(frame, { revision: 1, source });
expect(result).toMatchObject({ type: "rendered", revision: 1, source });
});
it("coalesces queued input and never reports an obsolete result", async () => {
const frame = await mountRuntime();
const obsoleteSource = `flowchart TD\n${Array.from({ length: 250 }, (_, index) => `A${index} --> A${index + 1}`).join("\n")}`;
-24
View File
@@ -368,29 +368,6 @@ async function waitForGuestActiveElement(client, browserId, elementId) {
return false;
}
// A wait whose condition never matches must say which condition expired, not blame the host.
async function verifyExpiredWaitNamesItsCondition(client, targetUrl) {
const created = await callBrowserTool(client, "browser_new_tab", { url: targetUrl });
const browserId = created.browserId;
assert(typeof browserId === "string", "browser_new_tab returned no browserId for the wait page");
try {
await callBrowserTool(client, "browser_wait", { browserId, text: "Bridge target" });
// The page title is not body text, so this wait expires.
const response = await client.callTool({
name: "browser_wait",
args: { browserId, text: "Desktop browser target", timeoutMs: 1_000 },
});
const text = response.content?.[0]?.text;
assert(
response.structuredContent?.ok === false &&
text === "Timed out waiting for browser text: Desktop browser target",
`browser_wait did not name its expired condition: ${JSON.stringify(response.content)}`,
);
} finally {
await callBrowserTool(client, "browser_close_tab", { browserId });
}
}
// A page whose Content Security Policy omits 'unsafe-eval' refuses eval(); the tools must still work.
async function verifyEvaluateOnPageWithoutUnsafeEval(client, targetUrl) {
const created = await callBrowserTool(client, "browser_new_tab", {
@@ -814,7 +791,6 @@ async function runRegression({
await verifyReactFormFill((name, args) => callBrowserTool(client, name, args), targetUrl);
await verifyEvaluateOnPageWithoutUnsafeEval(client, targetUrl);
await verifyExpiredWaitNamesItsCondition(client, targetUrl);
const created = await callBrowserTool(client, "browser_new_tab", { url: targetUrl });
const browserId = created.browserId;
@@ -800,8 +800,7 @@ describe("BrowserToolsBroker", () => {
ok: false,
error: {
code: "browser_timeout",
message:
"The browser host did not respond within 50ms. Try again or check the browser host.",
message: "Browser automation timed out after 50ms.",
retryable: true,
},
});
@@ -422,7 +422,7 @@ export class BrowserToolsBroker {
browserToolsFailure({
requestId: request.requestId,
code: "browser_timeout",
message: `The browser host did not respond within ${timeoutMs}ms. Try again or check the browser host.`,
message: `Browser automation timed out after ${timeoutMs}ms.`,
retryable: true,
}),
);
@@ -481,41 +481,14 @@ const brokerErrorCases = [
ok: false,
error: {
code: "browser_timeout",
message:
"The browser host did not respond within 15000ms. Try again or check the browser host.",
message: "Browser automation timed out after 15000ms.",
retryable: true,
},
},
content: [
{
type: "text",
text: "The browser host did not respond within 15000ms. Try again or check the browser host.",
},
],
context: {
agentId: "agent-1",
cwd: "/repo",
workspaceId: "wks_workspace_a",
browserId: BROWSER_ID,
},
},
{
name: "expired wait conditions",
toolName: "browser_wait",
input: { browserId: BROWSER_ID, text: "Example Domain" },
payload: {
requestId: "req-wait",
ok: false,
error: {
code: "browser_timeout",
message: "Timed out waiting for browser text: Example Domain",
retryable: true,
},
},
content: [
{
type: "text",
text: "Timed out waiting for browser text: Example Domain",
text: "The browser did not respond before the timeout. Try again or check the browser host.",
},
],
context: {
@@ -924,7 +897,7 @@ describe("registerBrowserTools", () => {
expect(response.content).toEqual([
{
type: "text",
text: 'Timed out waiting for browser URL: /next\nHandled browser dialog: dismissed beforeunload "Leave site?".',
text: 'The browser did not respond before the timeout. Try again or check the browser host.\nHandled browser dialog: dismissed beforeunload "Leave site?".',
},
]);
expect(response.structuredContent).toEqual({
@@ -1039,6 +1039,14 @@ function summarizeBrowserError(
switch (error.code) {
case "browser_disabled":
return "Browser tools are disabled. Enable browser tools on the host, then try again.";
case "browser_no_host":
return error.message;
case "browser_timeout":
return "The browser did not respond before the timeout. Try again or check the browser host.";
case "screenshot_no_frame":
return error.message;
case "browser_unsupported":
return error.message;
case "browser_stale_ref":
return "That browser element reference is stale. Take a new browser snapshot and try again.";
default:
File diff suppressed because one or more lines are too long
+6
View File
@@ -86,6 +86,12 @@ const patchedPackages = [
nodeModulesPath: "node_modules/@mattermost/react-native-paste-input",
patchPrefix: "@mattermost+react-native-paste-input+",
},
// Backport of https://github.com/mermaid-js/mermaid/pull/8459 (lexer half): a flowchart label
// with an "@" parses. The patch header has the details. Remove when the app uses mermaid 12.
{
nodeModulesPath: "node_modules/mermaid",
patchPrefix: "mermaid+",
},
{
nodeModulesPath: "packages/server/node_modules/@opencode-ai/sdk",
patchPrefix: "@opencode-ai+sdk+",