// Controlled synthetic capture matching the pre-change baseline; no author data. const { chromium } = require("playwright"), assert = require("node:assert/strict"), fs = require("node:fs"), path = require("node:path"); const base = process.env.PD_BROWSER_BASE || "http://127.0.0.1:5238"; (async () => { const b = await chromium.launch(); let step = "setup"; try { const c = await b.newContext({ viewport: { width: 1366, height: 900 } }); await c.route("**/cdn.jsdelivr.net/**signalr*", (r) => r.fulfill({ contentType: "application/javascript", body: fs.readFileSync( path.join( __dirname, "node_modules/@microsoft/signalr/dist/browser/signalr.min.js", ), ), }), ); for (const url of [ "**/native-companion/status", "**/native-companion/connection-state", "**/Writing/Context/Position?*", ]) await c.route(url, (r) => r.fulfill({ json: url.endsWith("status") ? [] : { known: false, connected: false }, }), ); await c.route("**/Writing/Context/Tabs/*", async (r) => { const u = new URL(r.request().url()); await r.fulfill({ response: await r.fetch({ url: base + "/context-tab-fixture/" + u.pathname.split("/").at(-1) + u.search, }), }); }); let graphReads = 0, large = false, readOnly = false, editQuery; await c.route("**/Writing/Context/Relationships/Graph?*", async (r) => { graphReads++; const u = new URL(r.request().url()); await r.fulfill({ response: await r.fetch({ url: base + "/context-lenses-fixture" + u.search + "&large=" + large + "&readonly=" + readOnly, }), }); }); await c.route("**/Writing/Context/Relationships/Lookup?*", async (r) => r.fulfill({ response: await r.fetch({ url: base + "/context-lenses-lookup-fixture", }), }), ); await c.route("**/Writing/Context/EditRelationship?*", async (r) => { editQuery = new URL(r.request().url()).searchParams; await r.fulfill({ response: await r.fetch({ url: base + "/context-relationship-edit-fixture", }), }); }); for (const [route, fixture] of [ ["FamilyIndex", "index"], ["FamilyTree", "tree"], ]) await c.route( "**/Writing/Context/Relationships/" + route + "?*", async (r) => { const u = new URL(r.request().url()); graphReads++; await r.fulfill({ response: await r.fetch({ url: base + "/context-family-" + fixture + "-fixture" + u.search + "&large=" + large + "&readonly=" + readOnly, }), }); }, ); const p = await c.newPage(), errors = []; p.on("pageerror", (e) => errors.push(e.message)); await p.goto(base + "/Writing/Context"); await p.selectOption("[data-context-tab]", "relationships"); await p.waitForSelector('[data-graph-node="5"]'); assert.equal( await p.locator('script[src*="/relationship-main"]').count(), 0, "protected view must not load main enhancement code", ); const output = process.env.PD_CAPTURE_OUTPUT; fs.mkdirSync(output, { recursive: true }); await p.evaluate(() => { document.documentElement.dataset.appTheme = "modern-light"; document.documentElement.dataset.bsTheme = "light"; }); await p.evaluate(() => document.fonts.ready); await p.waitForTimeout(300); for (const lens of ["family", "story"]) { await p.locator('[data-relationship-lens="' + lens + '"]').click(); await p.waitForTimeout(300); await p .locator('[data-context-pane="0"]') .screenshot({ path: output + "/context-" + lens + ".png", animations: "disabled", }); fs.writeFileSync( output + "/context-" + lens + ".svg", await p .locator('[data-context-pane="0"] [data-relationship-svg]') .evaluate((n) => n.outerHTML), ); } console.log("PASS captured protected Context Family/Story baseline"); } catch (e) { console.error(e.name + ": " + e.message.split("Call log:")[0]); process.exitCode = 1; } finally { await b.close(); } })();