Caveat / dev /browser-tests /unsure.mjs
umer-wasim's picture
Add dev/: training and export scripts, GPAI rule tests, browser tests, workspace map
28e3615 verified
Raw History Blame Contribute Delete
2.27 kB
import puppeteer from "puppeteer-core";
const b = await puppeteer.launch({ executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", headless: true });
const p = await b.newPage(); const errs = []; p.on("pageerror", (e) => errs.push(e.message));
await p.setRequestInterception(true);
const cors = { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Headers": "Content-Type", "Access-Control-Allow-Methods": "POST, OPTIONS" };
p.on("request", (r) => {
const u = r.url();
if (u.includes("/vendor/transformers-3.0.0/transformers.min.js")) return r.respond({ status: 200, contentType: "application/javascript", headers: cors,
body: "export const env={backends:{onnx:{wasm:{}}}}; export async function pipeline(){ return async()=>[{label:'high_risk',score:.46},{label:'limited_risk',score:.41},{label:'minimal_risk',score:.1},{label:'prohibited',score:.03}]; }" });
if (u.includes("workers.dev") && r.method() === "OPTIONS") return r.respond({ status: 204, headers: cors, body: "" });
if (u.includes("workers.dev")) return r.respond({ status: 200, contentType: "application/json", headers: cors, body: JSON.stringify({ tier: "high_risk", rationale: "stub" }) });
if (/clarity/.test(u)) return r.abort(); r.continue();
});
await p.goto("http://localhost:8766/", { waitUntil: "networkidle2" });
await p.click("#consentDecline"); await p.click('.chip[data-ex="1"]'); await p.click("#runBtn"); await new Promise((r) => setTimeout(r, 1500));
const r = await p.evaluate(() => ({ pill: document.getElementById("p1pill").textContent, cls: document.getElementById("p1pill").className, meaning: document.getElementById("p1meaning").textContent,
why: document.getElementById("p1rationale").textContent, agree: document.getElementById("agree").textContent, cta: document.getElementById("ctaLead").textContent }));
console.log(JSON.stringify(r, null, 1));
await p.evaluate(() => { window.print = () => {}; }); await p.click("#printBtn"); await new Promise((r) => setTimeout(r, 300));
console.log("print sheet mentions:", await p.evaluate(() => (document.getElementById("printSheet").innerText.match(/Uncertain[^\n]*|If Uncertain[^\n]*/g) || []).join(" | ")));
console.log("errors:", errs.length ? errs.join(" | ") : "none"); await b.close();