graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(native): link bare IPv6 browser targets (#1098)
yxlyxe0c91d39989d
diff --git a/apps/native/electron/link-destination-visual.cjs b/apps/native/electron/link-destination-visual.cjsindex 9c3bb21e..e63f0691 100644--- a/apps/native/electron/link-destination-visual.cjs+++ b/apps/native/electron/link-destination-visual.cjs@@ -111,6 +111,19 @@ async function runLinkDestinationVisuals({ origin, output }) {await wait(`!document.querySelector('[aria-label="Close browser"]')`);await wait(() => browser.visible === null, 'browser closed');};+ const routeRenderedUserLink = async () => {+ const url = `${destination}/rendered-user-bubble`, before = routed.length, opened = system.length, appURL = wc.getURL();+ const selector = `[data-user-bubble] a[href="${url}"][target="_blank"]`;+ await js(`(()=>{const e=document.querySelector('textarea[aria-label="Prompt"]');e.focus();Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,'value').set.call(e,${JSON.stringify(`Open ${url}`)});e.dispatchEvent(new Event('input',{bubbles:true}));e.dispatchEvent(new KeyboardEvent('keydown',{key:'Enter',bubbles:true,cancelable:true}));})()`);+ await wait(`!!document.querySelector(${JSON.stringify(selector)})`, 'real UserBubble rendered its browser link');+ await click(selector);+ await wait(() => routed.length === before + 1, 'rendered user link intercepted exactly once');+ assert.deepEqual(routed[before], { choice: 'system', url });+ await wait(() => system.length === opened + 1, 'rendered user link reached the fake system opener');+ assert.equal(system.at(-1), url);+ assert.equal(wc.getURL(), appURL, 'rendered user link preserves the main app URL');+ await wait(`!document.querySelector('article[aria-busy="true"]')`, 'rendered user link prompt completed');+ };const route = async (choice, target, suffix) => {const url = `${destination}/${suffix}`, before = routed.length, opened = system.length, appURL = wc.getURL();await link(url, target);@@ -141,6 +154,7 @@ async function runLinkDestinationVisuals({ origin, output }) {assert.equal(await store.load(), 'system');await screenshot('link-destination-default.png');await closeSettings();+ await routeRenderedUserLink();await route('system', '', 'default-normal'); await route('system', '_blank', 'default-blank');await openSettings(); await choose('graff'); await closeSettings();await route('graff', '', 'graff-normal');@@ -199,7 +213,7 @@ async function runLinkDestinationVisuals({ origin, output }) {await require('./browser-address-visual.cjs').runBrowserAddress({ wc, browser, destination, guard, wait, delayOpenReply: () => { delayNextOpen = true; }, openReplySent: () => delayedReplySent });await require('./inline-reference-visual.cjs').inlineReferenceVisual({ wc, js, wait, browser, destination, closeBrowser, screenshot });assert.deepEqual(blocked, [], 'no external network or engine/model requests attempted');- console.log('Link destination visuals passed: default/save/switch, reload and fresh-store persistence, normal/blank links, closed-browser reveal, overlays, unsafe/same-origin links, split focus and preserved app.');+ console.log('Link destination visuals passed: real UserBubble click, default/save/switch, reload and fresh-store persistence, normal/blank links, closed-browser reveal, overlays, unsafe/same-origin links, split focus and preserved app.');} finally {ipcMain.removeHandler('link-settings'); ipcMain.removeHandler('browser'); ipcMain.removeListener('browser-overlay', overlay);browser.closeAll(); win.destroy(); browser.session.webRequest.onBeforeRequest(null);diff --git a/apps/native/lib/browser-links.test.ts b/apps/native/lib/browser-links.test.tsindex c88df7bf..3730afe9 100644--- a/apps/native/lib/browser-links.test.ts+++ b/apps/native/lib/browser-links.test.ts@@ -10,6 +10,7 @@ describe("normalizeBrowserTarget", () => {assert.equal(normalizeBrowserTarget("example.com"), "https://example.com/");assert.equal(normalizeBrowserTarget("localhost:3000"), "http://localhost:3000/");assert.equal(normalizeBrowserTarget("192.168.1.20:8080/health"), "http://192.168.1.20:8080/health");+ assert.equal(normalizeBrowserTarget("[2001:db8::1]:8080/health"), "http://[2001:db8::1]:8080/health");});it("rejects unsafe, credential-bearing, and file-like lookalikes", () => {@@ -64,8 +65,13 @@ describe("browserLinkSegments", () => {]) assert.deepEqual(browserLinkSegments(text), [{ kind: "text", value: text }]);});- it("recognizes the reported local preview URL exactly", () => {+ it("recognizes the reported local preview URL and bare IPv6 destinations exactly", () => {const url = "http://localhost:3090/visual-tests/radius-preview";assert.deepEqual(browserLinkSegments(url), [{ kind: "link", label: url, href: url }]);+ assert.deepEqual(browserLinkSegments("Open [2001:db8::1]:8080/health."), [+ { kind: "text", value: "Open " },+ { kind: "link", label: "[2001:db8::1]:8080/health", href: "http://[2001:db8::1]:8080/health" },+ { kind: "text", value: "." },+ ]);});});diff --git a/apps/native/lib/browser-links.ts b/apps/native/lib/browser-links.tsindex b627b8bf..85d0f28d 100644--- a/apps/native/lib/browser-links.ts+++ b/apps/native/lib/browser-links.ts@@ -3,7 +3,7 @@ export type BrowserLinkSegment =| { kind: "link"; label: string; href: string };const EXPLICIT_HTTP = /^https?:\/\//i;-const LOCAL_HOST = /^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\]|\d{1,3}(?:\.\d{1,3}){3})(?::\d{1,5})?(?:[/?#]|$)/i;+const LOCAL_HOST = /^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[[0-9a-f:.]+\]|\d{1,3}(?:\.\d{1,3}){3})(?::\d{1,5})?(?:[/?#]|$)/i;const FILELIKE_SUFFIXES = new Set(["7z", "avif", "avi", "bak", "bmp", "bz2", "c", "cc", "cfg", "conf", "cpp", "css","csv", "dmg", "doc", "docx", "eot", "exe", "flac", "gif", "go", "gz", "h", "hpp",@@ -13,7 +13,7 @@ const FILELIKE_SUFFIXES = new Set(["tgz", "toml", "ts", "tsx", "ttf", "txt", "wasm", "wav", "webm", "webmanifest", "webp","woff", "woff2", "xls", "xlsx", "xml", "xz", "yaml", "yml", "zig", "zip",]);-const CANDIDATE = /https?:\/\/[^\s<>"'`]+|www\.(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9-]{2,63}(?::\d{1,5})?(?:[/?#][^\s<>"'`]*)?|(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\]|\d{1,3}(?:\.\d{1,3}){3})(?::\d{1,5})?(?:[/?#][^\s<>"'`]*)?|(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+(?:[a-z]{2,63}|xn--[a-z0-9-]{2,59})(?::\d{1,5})?(?:[/?#][^\s<>"'`]*)?/giu;+const CANDIDATE = /https?:\/\/[^\s<>"'`]+|www\.(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9-]{2,63}(?::\d{1,5})?(?:[/?#][^\s<>"'`]*)?|(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[[0-9a-f:.]+\]|\d{1,3}(?:\.\d{1,3}){3})(?::\d{1,5})?(?:[/?#][^\s<>"'`]*)?|(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+(?:[a-z]{2,63}|xn--[a-z0-9-]{2,59})(?::\d{1,5})?(?:[/?#][^\s<>"'`]*)?/giu;const TRAILING_PUNCTUATION = /[.,;:!?]+$/u;const CLOSERS: Record<string, string> = { ")": "(", "]": "[", "}": "{" };