From da6f0ff2f6340043e95942963cfe06ca58bd527f Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Tue, 8 Sep 2026 17:31:30 +0000 Subject: [PATCH] fix(design): run the DOM dump in the page on both engines; align doctrine with the catalog The DOM-dump script is an arrow function, not a self-calling IIFE: Aside's `pg.evaluate($_DUMP)` receives the function and runs it in the page (the IIFE form executed in the repl sandbox, where `document` does not exist), and the fallback engine calls it with `$B js "($_DUMP)()" --out --raw`. Hygiene widens to every URL-bearing attribute (src, srcset per candidate, poster, action, formaction, data, ping, cite lose their query strings and fragments) and to data: URLs inside existing +
x
+ +`); + const url = `http://127.0.0.1:${server.port}/index.html`; + // Own daemon: BROWSE_STATE_FILE scopes the state dir, lock, port file, and + // profile to this test, so it never shares (or stops) another session's daemon. + fs.mkdirSync(path.join(tmp, '.gstack'), { recursive: true }); + const env = { ...process.env, BROWSE_STATE_FILE: path.join(tmp, '.gstack', 'browse.json') }; + const browse = (args: string[]) => spawnSync(BROWSE!, args, { encoding: 'utf-8', timeout: 90_000, env }); + try { + // A cold daemon start can miss the CLI's ~8 s health window on a loaded + // machine (CI shards, a concurrent eval run). Bounded retries, then fail loud. + let go = browse(['goto', url]); + for (let attempt = 0; attempt < 6 && go.status !== 0; attempt++) { + Bun.sleepSync(10_000); + go = browse(['goto', url]); + } + expect(go.status, go.stderr + go.stdout).toBe(0); + // The same invocation the skill renders for the fallback engine: the arrow + // function spliced from lib/dom-dump.js and called in the page. + const dump = fs.readFileSync(path.join(ROOT, 'lib', 'dom-dump.js'), 'utf-8'); + const out = path.join(tmp, 'index.dom.html'); + const ev = browse(['js', `(${dump})()`, '--out', out, '--raw']); + expect(ev.status, ev.stderr + ev.stdout).toBe(0); + const html = fs.readFileSync(out, 'utf-8'); + expect(html.startsWith('')).toBe(true); + expect(html).toContain(`