// Scratch driver for issue 38165: open a replay thread, cite text, start dictation. import { createRequire } from "node:module"; import { mkdirSync } from "node:fs"; const require = createRequire("/home/user/wt/factory-issue-38165-triage/apps/web/package.json"); const { chromium } = require("playwright"); const out = `/tmp/factory-issue-38165-triage/run-${Date.now()}`; mkdirSync(out, { recursive: true }); const [pairUrl, step = "explore"] = process.argv.slice(2); const context = await chromium.launchPersistentContext("/tmp/factory-issue-38165-triage/profile", { viewport: { width: 1400, height: 900 }, args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream", ...(process.env.AUDIO ? [`--use-file-for-fake-audio-capture=${process.env.AUDIO}`] : [])], }); const browser = context; await context.grantPermissions(["microphone"], { origin: "http://localhost:6979" }); const page = await context.newPage(); page.on("console", (m) => m.type() === "error" && console.log("console:", m.text().slice(0, 200))); let n = 0; const shot = async (name) => { const p = `${out}/${String(++n).padStart(2, "0")}-${name}.png`; await page.screenshot({ path: p }); console.log("shot", p); }; globalThis.page = page; globalThis.shot = shot; await page.goto(pairUrl); await page.waitForTimeout(4000); await shot("after-pair"); const mod = await import(`/tmp/factory-issue-38165-triage/${step}.mjs?${Date.now()}`); await mod.default({ page, shot, out }); await browser.close(); console.log("out", out); export default async ({ page, shot, out }) => { if (process.env.SELECT_MODEL) { await page.goto("http://localhost:6979/settings/voice"); await page.waitForTimeout(3000); await page.getByPlaceholder(/search/i).last().fill("moonshine streaming small"); await page.waitForTimeout(800); await page.getByRole("button", { name: "Use model" }).first().click(); await page.waitForTimeout(3000); } await page.goto("http://localhost:6979/"); await page.waitForTimeout(2500); await page.getByText("go", { exact: true }).first().click(); await page.waitForTimeout(1500); const para = page.getByText("This turn is a replay").first(); const box = await para.boundingBox(); await page.mouse.move(box.x + 2, box.y + box.height / 2); await page.mouse.down(); await page.mouse.move(box.x + 200, box.y + box.height / 2, { steps: 10 }); await page.mouse.up(); await page.waitForTimeout(600); await page.getByRole("button", { name: /cite/i }).first().click(); await page.waitForTimeout(1200); const editor = page.locator("[data-citation-comment-editor]"); const popup = editor.locator("xpath=ancestor::*[@data-slot='popover-popup' or @role='dialog'][1]"); const target = (await popup.count()) ? popup : editor; const layout = async (label) => { const r = await editor.evaluate((el) => { const pick = (name) => { const b = [...el.querySelectorAll("button")].find((x) => x.textContent.trim() === name); if (!b) return null; const r = b.getBoundingClientRect(); return { x: Math.round(r.x), y: Math.round(r.y), w: Math.round(r.width), h: Math.round(r.height) }; }; const status = el.querySelector("p[role=status]"); return { editorWidth: Math.round(el.getBoundingClientRect().width), cancel: pick("Cancel"), save: pick("Save"), transcript: status ? status.textContent.slice(0, 80) : null, transcriptH: status ? Math.round(status.getBoundingClientRect().height) : 0, }; }); console.log(label, JSON.stringify(r)); return r; }; await layout("idle"); await target.screenshot({ path: `${out}/idle.png` }); console.log("editor buttons:", await editor.locator("button").evaluateAll((b) => b.map((x) => x.getAttribute("aria-label") ?? x.textContent))); await editor.locator("button").first().click(); let saveAtStart = null; for (let k = 0; k < 30; k++) { await page.waitForTimeout(1000); const r = await layout(`t+${k + 1}s`); if (k === 1) saveAtStart = r.save; if ([2, 8, 14, 20].includes(k)) await target.screenshot({ path: `${out}/rec-${k + 1}s.png` }); if (saveAtStart && r.cancel && Math.abs(r.cancel.y - saveAtStart.y) < 6 && r.cancel.x <= saveAtStart.x + saveAtStart.w && r.cancel.x + r.cancel.w >= saveAtStart.x) console.log(" -> Cancel now overlaps Save's position from t+2s"); } await shot("end"); };