Skip to content

Commit 1aed1c0

Browse files
TMHSDigitalclaude
andcommitted
tests: filter and sort tie branches, reserved v4 ranges, schema refs, guide page (#266)
Regression guards for branches coverage showed never ran: perspective and licence-family rejects, licence/verified ties by name, 198.18/15 and 198.51.100/24 (also v4-mapped), refusalFor on a non-URL, remote and missing $ref, and the guide page (escaping, dateModified, description clip, h1 id, edit link). plainText strips Markdown link and emphasis syntax (it takes Markdown, not HTML), and that is what is tested. Closes #266 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpkeXQPaUhxjgqdqnk6BrJ
1 parent e814b27 commit 1aed1c0

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎site/lib/lib.test.mjs‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,50 @@ eq("search: q from the URL is capped", readState(`?q=${"a".repeat(5000)}`, { q:
20762076
eq("listed: deprecated is not", isListed({ status: "deprecated" }), false);
20772077
}
20782078

2079+
/* reject branches and the guide page (#266) -------------------------------- */
2080+
{
2081+
const { passesFilters, SORTS } = await import("./search.mjs");
2082+
const open = { active: true, review: true, deprecated: true, commercialOnly: false, noAttr: false, perspective: "any", license: "any", engine: "any", format: "any" };
2083+
eq("filters: a perspective mismatch is rejected", passesFilters({ status: "active", camera_perspective: "side" }, { ...open, perspective: "top-down" }), false);
2084+
eq("filters: a licence-family mismatch is rejected", passesFilters({ status: "active", licenseFamily: "cc0" }, { ...open, license: "cc-by" }), false);
2085+
eq("filters: matching perspective and family pass", passesFilters({ status: "active", camera_perspective: "side", licenseFamily: "cc0" }, { ...open, perspective: "side", license: "cc0" }), true);
2086+
const b = { name: "B", license: "CC0", licenseRank: 0, verified: "2026-10-01" };
2087+
const a = { name: "A", license: "CC0", licenseRank: 0, verified: "2026-10-01" };
2088+
eq("sorts: licence ties break by name", [b, a].sort(SORTS.license).map((e) => e.name).join(), "A,B");
2089+
eq("sorts: verified ties break by name", [b, a].sort(SORTS.verified).map((e) => e.name).join(), "A,B");
2090+
2091+
const { isPrivateAddress, refusalFor } = await import("./safe-fetch.mjs");
2092+
for (const ip of ["198.18.0.1", "198.19.255.255", "198.51.100.7", "::ffff:198.18.0.1"]) eq(`private: ${ip}`, isPrivateAddress(ip), true);
2093+
eq("private: 198.20.0.1 is public", isPrivateAddress("198.20.0.1"), false);
2094+
eq("refusal: not a URL", refusalFor("not a url"), "not a valid URL");
2095+
2096+
const { schemaErrors } = await import("./schema-check.mjs");
2097+
const throws = (fn) => { try { fn(); return ""; } catch (e) { return e.message; } };
2098+
has("schema: a remote $ref is refused by name", throws(() => schemaErrors({ $ref: "http://x" }, 1)), "http://x");
2099+
has("schema: a missing local $ref is named", throws(() => schemaErrors({ $ref: "#/$defs/y", $defs: {} }, 1)), "#/$defs/y");
2100+
2101+
const { guidePageHtml } = await import("./guide-page.mjs");
2102+
const site = { title: "Site", siteUrl: "https://x.test/s/", repo: "https://github.com/o/r" };
2103+
const page = (over = {}) => guidePageHtml({
2104+
guide: { id: "g", title: "A <&\"> guide", path: "docs/g.md" },
2105+
rendered: { title: "A <&\"> guide", titleId: "a-guide", firstParagraph: "word ".repeat(80), html: "<p>x</p>" },
2106+
site, stamp: "2026-11-06", total: 1, hasCard: false, modified: "2026-11-01", ...over,
2107+
});
2108+
const html = page();
2109+
has("guide page: title escaped in <title>", html, "<title>A &lt;&amp;&quot;&gt; guide");
2110+
has("guide page: title escaped in the breadcrumb", html, '<span aria-current="page">A &lt;&amp;&quot;&gt; guide</span>');
2111+
has("guide page: title escaped in h1", html, '<h1 id="a-guide">A &lt;&amp;&quot;&gt; guide</h1>');
2112+
has("guide page: dateModified from the last commit", html, '"dateModified":"2026-11-01"');
2113+
eq("guide page: no modified date, no dateModified", page({ modified: null }).includes("dateModified"), false);
2114+
const desc = html.match(/<meta name="description" content="([^"]*)"/)[1];
2115+
eq("guide page: description clipped to 160", desc.length <= 160, true);
2116+
has("guide page: edit link", html, 'href="https://github.com/o/r/blob/main/docs/g.md"');
2117+
has("guide page: h1 without titleId has no id", page({ rendered: { title: "T", firstParagraph: "p", html: "" } }), "<h1>T</h1>");
2118+
2119+
const { plainText } = await import("./guide-render.mjs");
2120+
eq("plainText: links and emphasis stripped", plainText("See **[the guide](a.md)** and `code`\n now"), "See the guide and code now");
2121+
}
2122+
20792123
/* report (keep last) ------------------------------------------------------ */
20802124
if (failures.length) {
20812125
console.error(`lib.test failed (${failures.length}):`);

0 commit comments

Comments
 (0)