graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
test(native): isolate rendered link interaction (#1098)
yxlyxc97191a0f5ef
diff --git a/apps/native/app/visual-tests/links/link-fixture.tsx b/apps/native/app/visual-tests/links/link-fixture.tsxnew file mode 100644index 00000000..be41203a--- /dev/null+++ b/apps/native/app/visual-tests/links/link-fixture.tsx@@ -0,0 +1,12 @@+"use client";++import { useEffect, useState } from "react";+import { UserBubble } from "@/components/site/ChatBubbles";++export default function LinkFixture() {+ const [target, setTarget] = useState("");+ useEffect(() => setTarget(new URLSearchParams(window.location.search).get("target") ?? ""), []);+ return <main data-link-message-fixture data-ready={target ? "true" : "false"} className="p-6">+ {target && <UserBubble text={`Open ${target}`} />}+ </main>;+}diff --git a/apps/native/app/visual-tests/links/page.tsx b/apps/native/app/visual-tests/links/page.tsxnew file mode 100644index 00000000..cc2e1827--- /dev/null+++ b/apps/native/app/visual-tests/links/page.tsx@@ -0,0 +1,9 @@+import { notFound } from "next/navigation";+import LinkFixture from "./link-fixture";++export const dynamic = "force-dynamic";++export default function LinksPage() {+ if (process.env.GRAFF_VISUAL_TESTS !== "1") notFound();+ return <LinkFixture />;+}diff --git a/apps/native/electron/link-destination-visual.cjs b/apps/native/electron/link-destination-visual.cjsindex e63f0691..fec758e4 100644--- a/apps/native/electron/link-destination-visual.cjs+++ b/apps/native/electron/link-destination-visual.cjs@@ -113,16 +113,18 @@ async function runLinkDestinationVisuals({ origin, output }) {};const routeRenderedUserLink = async () => {const url = `${destination}/rendered-user-bubble`, before = routed.length, opened = system.length, appURL = wc.getURL();+ const fixtureURL = `${origin}/visual-tests/links?target=${encodeURIComponent(url)}`;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 wc.loadURL(fixtureURL);+ await wait(`document.querySelector('[data-link-message-fixture]')?.dataset.ready==='true' && !!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');+ assert.equal(wc.getURL(), fixtureURL, 'rendered user link preserves its fixture page');+ await wc.loadURL(appURL);+ await wait(`!!document.querySelector('[data-workspace-ready="true"] textarea[aria-label="Prompt"]')`, 'main app restored after rendered link fixture');};const route = async (choice, target, suffix) => {const url = `${destination}/${suffix}`, before = routed.length, opened = system.length, appURL = wc.getURL();