Add dev/: training and export scripts, GPAI rule tests, browser tests, workspace map
28e3615 verified Download dev/browser-tests/uitest.mjs from Devseis/Caveat: direct link, hf CLI and curl.
- Browser
- Download file 4.91 kB
-
https://huggingface.co/spaces/Devseis/Caveat/resolve/main/dev/browser-tests/uitest.mjs
- Command line
-
hf download hf://spaces/Devseis/Caveat/dev/browser-tests/uitest.mjs
-
curl -L -o uitest.mjs https://huggingface.co/spaces/Devseis/Caveat/resolve/main/dev/browser-tests/uitest.mjs
4.91 kB
| import { JSDOM } from "jsdom"; | |
| import fs from "fs"; | |
| const html = fs.readFileSync("/Users/umer/Documents/hf/Caveat-space/index.html", "utf8"); | |
| const errors = []; | |
| const dom = new JSDOM(html.replace(/<script type="module">[\s\S]*?<\/script>/, "").replace(/<script type="text\/javascript">[\s\S]*?<\/script>/, ""), | |
| { url: "https://devseis-caveat.static.hf.space/", pretendToBeVisual: true, runScripts: "outside-only" }); | |
| const w = dom.window; | |
| w.scrollTo = () => {}; w.HTMLElement.prototype.scrollIntoView = () => {}; | |
| w.matchMedia = () => ({ matches: true }); w.requestAnimationFrame = (f) => setTimeout(f, 0); | |
| w.addEventListener("error", (e) => errors.push("window error: " + e.message)); | |
| let mod = html.match(/<script type="module">([\s\S]*?)<\/script>/)[1]; | |
| mod = mod.replace(/import \{ pipeline, env \} from [^\n]+\n/, "") | |
| .replace(/import \{ gpaiCheck \} from [^\n]+\n/, ""); | |
| const stubs = ` | |
| const env = { backends: { onnx: { wasm: {} } } }; | |
| const pipeline = async () => async (text) => [{ label: "high_risk", score: 0.91 }]; | |
| const gpaiCheck = (t) => /10\\^25/.test(t) ? { tier: "gpai_systemic_risk", citation: "Art 51", confidence: "high", reasons: ["r1"] } : null; | |
| window.fetch = async () => ({ ok: true, json: async () => ({ tier: "limited_risk", rationale: "because" }) }); | |
| `; | |
| const run = { call: () => w.eval("(() => {" + stubs + mod + "})()") }; | |
| try { run.call(w); } catch (e) { errors.push("init: " + e.stack.split("\n")[0]); } | |
| const d = w.document, $ = (id) => d.getElementById(id); | |
| const tick = () => new Promise((r) => setTimeout(r, 20)); | |
| const hash = async (h) => { w.location.hash = h; w.dispatchEvent(new w.HashChangeEvent("hashchange")); await tick(); }; | |
| const report = []; | |
| await tick(); await tick(); | |
| report.push("run button: " + $("runBtn").textContent + " disabled=" + $("runBtn").disabled); | |
| // check flow | |
| d.querySelector('.chip[data-ex="1"]').click(); $("runBtn").click(); await tick(); await tick(); | |
| report.push(`check: p1=${$("p1pill").textContent} p2=${$("p2pill").textContent} agree="${$("agree").textContent}"`); | |
| d.querySelector('.chip[data-ex="4"]').click(); $("runBtn").click(); await tick(); await tick(); | |
| report.push(`gpai: p1=${$("p1pill").textContent}`); | |
| // tabs | |
| for (const t of ["results", "story", "check"]) { d.querySelector(`[data-tab="${t}"]`).click(); await tick(); | |
| report.push(`tab ${t}: visible=${!$("panel-" + t).hidden}`); } | |
| report.push("tier bars: " + d.querySelectorAll("#tierBars .bar-row").length + ", story chapters: " + d.querySelectorAll(".chapter").length); | |
| // glossary popovers: every term on the page resolves | |
| const terms = [...d.querySelectorAll(".term")].map((b) => b.dataset.term); | |
| // lessons | |
| const n = d.querySelectorAll("#lessonList li").length; | |
| for (let i = 0; i < n; i++) { | |
| await hash("learn-" + i); | |
| const title = d.querySelector("#lesson h2")?.textContent; | |
| const q = d.querySelector(".quiz-opts button"); q?.click(); await tick(); | |
| const fbEl = d.querySelector(".quiz .fb"); const fbOk = fbEl ? !fbEl.hidden : "no-quiz(final step)"; | |
| const widgets = [...d.querySelectorAll("#lesson [data-widget]")].map((x) => x.dataset.widget + ":" + (x.innerHTML.length > 50 ? "ok" : "EMPTY")); | |
| d.querySelectorAll("#lesson .term").forEach((b) => terms.push(b.dataset.term)); | |
| report.push(`lesson ${i} "${title}" quiz-feedback=${fbOk} ${widgets.join(" ")}`); | |
| // exercise widgets | |
| const sb = d.querySelector('#lesson [data-widget="sort"] .sort-btns button'); if (sb) { sb.click(); await tick(); report.push(" sort feedback: " + d.querySelector(".sort-fb").textContent.slice(0, 50)); } | |
| const seg = d.querySelector('#lesson [data-widget="accuracy"] .seg button[data-k="careful"]'); if (seg) { seg.click(); await tick(); report.push(" accuracy widget careful: " + d.querySelector(".w-stats").textContent.replace(/\s+/g, " ")); } | |
| const cb = d.querySelector("#lesson .checklist input"); if (cb) { cb.click(); report.push(" checklist saved: " + w.localStorage.getItem("caveat-checklist")); } | |
| const gs = d.getElementById("glossSearch"); if (gs) { report.push(" glossary items: " + d.querySelectorAll("#glossList .kw").length); gs.value = "recall"; gs.dispatchEvent(new w.Event("input")); report.push(" search 'recall': " + d.querySelectorAll("#glossList .kw").length); } | |
| } | |
| report.push("progress: " + $("progressTxt").textContent); | |
| // popover on every distinct term | |
| const G = [...new Set(terms)]; | |
| let bad = []; | |
| for (const t of G) { const b = d.querySelector(`.term[data-term="${t}"]`); if (!b) continue; b.click(); const p = d.querySelector(".popover"); if (!p) bad.push(t); d.body.click(); } | |
| report.push(`distinct glossary terms used: ${G.length}; without a definition: ${bad.length ? bad.join(", ") : "none"}`); | |
| // story deep link | |
| await hash("story-3"); report.push("story-3 route: story visible=" + !$("panel-story").hidden); | |
| console.log(report.join("\n")); console.log("ERRORS:", errors.length ? errors.join("\n") : "none"); | |