Files
threshing-atlas/site/qa/crawl.js
T
432e04c2c7 Refactor: lay the repo out by section (core, collection, analysis, planner, site) (#8)
Moves only; no behaviour changes. Every file now lives under the part of the project it
belongs to, each section has a README, and docs/PRIVACY.md collects the rules all parts follow.

  core/        engine.js, graph.js, solver.js, python/clean.py
  collection/  sources/ (form, register, PDF check, daily update), bot/ (importer)
  analysis/    stats/ (Python statistics), network/ (build-graph.js), reports/ (POLICY.md)
  planner/     build-policy.js, policy-report.js
  site/        atlas/ (the page), build.js, qa/
  tests/       core/ (unit), parity/ (JS vs Python), fixtures/

Checked against the previous layout: tests pass; coded runs, test outputs, graph.json and
policy.json are byte-identical; the built site differs only in comments that name file paths.
The published file names Ken's bot downloads (solver.js, graph.js, data/policy.json) are unchanged.

Also removes the undefined/ folder of QA screenshots committed by mistake (the QA scripts now
default to a temp folder) and test.txt, and drops the unused npm workspaces.


Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 19:46:33 +00:00

73 lines
4.5 KiB
JavaScript

// QA crawl: every tab, text dump, links, buttons, console errors. node crawl.js <outdir>
const { chromium } = require("playwright");
const fs = require("fs");
// screenshots and logs go to the folder given, or a temp folder (never a folder named "undefined" in the repo)
const OUT = process.argv[2] || require("path").join(require("os").tmpdir(), "atlas-qa");
require("fs").mkdirSync(OUT, { recursive: true });
const BASE = "http://localhost:8765/";
(async () => {
const b = await chromium.launch();
const log = { errors: [], links: [], buttons: [], tabs: {} };
for (const [vpName, vp] of [["desktop", { width: 1440, height: 1000 }], ["phone", { width: 390, height: 844 }]]) {
const p = await b.newPage({ viewport: vp });
p.on("pageerror", (e) => log.errors.push(`${vpName} pageerror: ${e.message}`));
p.on("console", (m) => { if (m.type() === "error" && !/net::ERR|Failed to load resource/.test(m.text())) log.errors.push(`${vpName} console: ${m.text()}`); });
for (const t of ["valley", "odds", "dragons", "deep", "data"]) {
await p.goto(BASE + "#" + t); await p.waitForTimeout(t === "valley" ? 2500 : 1800);
// open every <details> so hidden text is reviewed too
await p.$$eval(`#panel-${t} details`, (ds) => ds.forEach((d) => (d.open = true)));
await p.waitForTimeout(300);
await p.screenshot({ path: `${OUT}/${vpName}-${t}.png`, fullPage: true });
if (vpName === "desktop") {
log.tabs[t] = await p.evaluate((t) => document.querySelector("#panel-" + t).innerText, t);
const links = await p.$$eval(`#panel-${t} a[href], header a[href], footer a[href]`, (as) => as.map((a) => ({ text: a.innerText.trim().slice(0, 60), href: a.getAttribute("href") })));
links.forEach((l) => log.links.push({ tab: t, ...l }));
const btns = await p.$$eval(`#panel-${t} button`, (bs) => bs.map((x) => x.innerText.trim().replace(/\s+/g, " ").slice(0, 50)));
log.buttons.push({ tab: t, n: btns.length, sample: [...new Set(btns)].slice(0, 40) });
}
// overflow check
const sw = await p.evaluate(() => document.documentElement.scrollWidth);
if (sw > vp.width + 1) log.errors.push(`${vpName} ${t}: horizontal overflow ${sw}px`);
}
await p.close();
}
// click every button in every tab (desktop), checking for errors after each
const p = await b.newPage({ viewport: { width: 1440, height: 1000 } });
p.on("pageerror", (e) => log.errors.push(`click pageerror: ${e.message}`));
for (const t of ["valley", "odds", "dragons", "deep", "data"]) {
await p.goto(BASE + "#" + t); await p.waitForTimeout(2000);
const n = await p.$$eval(`#panel-${t} button`, (bs) => bs.length);
let clicked = 0;
for (let i = 0; i < Math.min(n, 120); i++) {
const bs = await p.$$(`#panel-${t} button`);
if (!bs[i]) continue;
const vis = await bs[i].isVisible();
if (!vis) continue;
const label = (await bs[i].innerText()).trim().slice(0, 40);
if (/download|copy/i.test(label)) continue;
try { await bs[i].click({ timeout: 1500 }); clicked++; await p.waitForTimeout(120); } catch (e) { log.errors.push(`${t}: could not click "${label}": ${e.message.split("\n")[0]}`); }
const cur = await p.evaluate(() => location.hash);
if (!cur.startsWith("#" + t)) { await p.goto(BASE + "#" + t); await p.waitForTimeout(1200); }
}
log.tabs[t + "_clicked"] = clicked;
}
// in-page links
await p.goto(BASE); await p.waitForTimeout(2000);
for (const l of log.links.filter((x) => x.href.startsWith("#"))) {
await p.goto(BASE + "#" + l.tab); await p.waitForTimeout(800);
const el = await p.$(`#panel-${l.tab} a[href="${l.href}"]`);
if (!el || !(await el.isVisible())) continue;
await el.click(); await p.waitForTimeout(800);
const sel = await p.evaluate(() => document.querySelector("[role=tab][aria-selected=true]").id);
const target = l.href.slice(1).split("/")[0];
const exists = await p.evaluate((id) => !!document.getElementById(id) || ["valley","odds","dragons","deep","data"].includes(id), target);
l.result = `${sel}${exists ? "" : " MISSING TARGET"}`;
}
fs.writeFileSync(`${OUT}/log.json`, JSON.stringify(log, null, 1));
for (const [t, txt] of Object.entries(log.tabs)) if (typeof txt === "string") fs.writeFileSync(`${OUT}/text-${t}.txt`, txt);
console.log("errors:", log.errors.length, log.errors.slice(0, 20));
console.log("clicked:", Object.entries(log.tabs).filter(([k]) => k.endsWith("_clicked")));
console.log("links:"); log.links.forEach((l) => console.log(" ", l.tab, "|", l.text, "|", l.href, "|", l.result || ""));
await b.close();
})();