|
| 1 | +import { readFile, stat } from "node:fs/promises"; |
| 2 | +import { join } from "node:path"; |
| 3 | + |
| 4 | +const root = process.cwd(); |
| 5 | +const website = join(root, "website"); |
| 6 | +const failures = []; |
| 7 | + |
| 8 | +function fail(message) { |
| 9 | + failures.push(message); |
| 10 | +} |
| 11 | + |
| 12 | +async function mustRead(relativePath) { |
| 13 | + try { |
| 14 | + return await readFile(join(root, relativePath), "utf8"); |
| 15 | + } catch { |
| 16 | + fail(`missing ${relativePath}`); |
| 17 | + return ""; |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +function stripTags(value) { |
| 22 | + return value |
| 23 | + .replace(/<br\s*\/?>/giu, " ") |
| 24 | + .replace(/<[^>]+>/gu, "") |
| 25 | + .replace(/\s+/gu, " ") |
| 26 | + .trim(); |
| 27 | +} |
| 28 | + |
| 29 | +function extractFirst(html, pattern, label) { |
| 30 | + const match = html.match(pattern); |
| 31 | + if (!match) { |
| 32 | + fail(`missing ${label}`); |
| 33 | + return ""; |
| 34 | + } |
| 35 | + return match[1] || ""; |
| 36 | +} |
| 37 | + |
| 38 | +const html = await mustRead("website/index.html"); |
| 39 | +const robots = await mustRead("website/robots.txt"); |
| 40 | +const sitemap = await mustRead("website/sitemap.xml"); |
| 41 | + |
| 42 | +const title = stripTags(extractFirst(html, /<title>([\s\S]*?)<\/title>/iu, "title")); |
| 43 | +if (title !== "Clawpatch — Automated Code Review") { |
| 44 | + fail(`unexpected title: ${title}`); |
| 45 | +} |
| 46 | + |
| 47 | +const description = html.match(/<meta\s+name="description"\s+content="([^"]+)"/iu)?.[1] || ""; |
| 48 | +if (!description.includes("Automated code review that lands fixes")) { |
| 49 | + fail("meta description does not contain the product promise"); |
| 50 | +} |
| 51 | + |
| 52 | +const h1 = stripTags(extractFirst(html, /<h1>([\s\S]*?)<\/h1>/iu, "h1")); |
| 53 | +if (h1 !== "Code review with explicit fixes") { |
| 54 | + fail(`unexpected h1 text: ${h1}`); |
| 55 | +} |
| 56 | + |
| 57 | +const ids = new Set([...html.matchAll(/\sid="([^"]+)"/giu)].map((match) => match[1])); |
| 58 | +const anchorLinks = [...html.matchAll(/href="#([^"]+)"/giu)].map((match) => match[1]); |
| 59 | +for (const id of anchorLinks) { |
| 60 | + if (!ids.has(id)) fail(`missing anchor target: #${id}`); |
| 61 | +} |
| 62 | + |
| 63 | +if (!robots.includes("Sitemap: https://clawpatch.ai/sitemap.xml")) { |
| 64 | + fail("robots.txt missing sitemap reference"); |
| 65 | +} |
| 66 | + |
| 67 | +if (!sitemap.includes("<loc>https://clawpatch.ai/</loc>")) { |
| 68 | + fail("sitemap.xml missing canonical homepage loc"); |
| 69 | +} |
| 70 | + |
| 71 | +const socialCard = await readFile(join(website, "social-card.png")); |
| 72 | +if (socialCard.toString("ascii", 1, 4) !== "PNG") { |
| 73 | + fail("social-card.png is not a PNG"); |
| 74 | +} else { |
| 75 | + const width = socialCard.readUInt32BE(16); |
| 76 | + const height = socialCard.readUInt32BE(20); |
| 77 | + if (width !== 1200 || height !== 630) { |
| 78 | + fail(`social-card.png dimensions are ${width}x${height}, expected 1200x630`); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +for (const file of ["website/favicon.svg", "website/CNAME", "website/.nojekyll"]) { |
| 83 | + try { |
| 84 | + await stat(join(root, file)); |
| 85 | + } catch { |
| 86 | + fail(`missing ${file}`); |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +if (failures.length) { |
| 91 | + console.error(failures.join("\n")); |
| 92 | + process.exit(1); |
| 93 | +} |
| 94 | + |
| 95 | +console.log("Website smoke checks passed."); |
0 commit comments