Wiki: drop the unused lookup, search and section routes

Nothing in the page or the link scanner called /api/wiki/lookup,
/api/wiki/search or /api/wiki/section. Remove the routes and what
existed only for them: readTitles and the POST allowance,
WikiClient.search and SearchHit, TTL.search, snippet(), the mock's
search/page answer, WikiClient.section and Section. WikiClient.lookup
stays (the scanner uses it), as do suggest and article.

Tests of the removed code go; input validation and off mode are now
checked on remaining routes. The mock's Eukaryote fixture gets its own
page id instead of sharing Hostile article's. README and
docs/wikipedia.md list what exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
thalladaandClaude Opus 5.5 committed 2026-11-17 18:04:16 -05:00
1 parent 60d26908d6
commit 5c867b2eef
9 files changed
+24 -190

No files matched your search

+4 -11
View File
@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { WikiClient, batches, parseRetryAfter, prepareTitle, userAgent, validContact } from "../server/wiki";
import { sanitizeWikiHtml, snippet, splitArticle } from "../server/wikiHtml";
import { sanitizeWikiHtml, splitArticle } from "../server/wikiHtml";
// A tiny fake Wikipedia: pages, redirects, disambiguation pages.
const PAGES: Record<string, { id: number; description?: string; disambiguation?: boolean }> = {
@@ -324,13 +324,6 @@ describe("sanitiser", () => {
expect(sanitizeWikiHtml(html, o)).toBe("<p>t</p>");
});
it("marks search matches and escapes the rest", () => {
expect(snippet(`a <span class="searchmatch">fixed</span> point &lt;b&gt;`)).toEqual({
text: "a fixed point <b>",
html: "a <mark>fixed</mark> point &lt;b&gt;",
});
});
it("splits an article at its headings into a section tree", () => {
const page =
`<div class="mw-content-ltr mw-parser-output"><p>Lead.</p>` +
@@ -348,7 +341,7 @@ describe("sanitiser", () => {
});
});
describe("article and section", () => {
describe("article", () => {
const page =
`<div class="mw-parser-output"><p>Lead <a href="/wiki/Octopus">octopus</a>.</p>` +
`<div class="mw-heading mw-heading2"><h2 id="A">A</h2></div><p>Alpha<script>x</script></p>` +
@@ -379,8 +372,8 @@ describe("article and section", () => {
]);
expect(a.ok && a.value.attribution.text).toContain("CC BY-SA 4.0");
expect(a.ok && a.value.attribution.revisionUrl).toBe("https://en.wikipedia.org/w/index.php?title=Thing&oldid=777");
const s = await w.section("thing", 1);
expect(s.ok && s.value.html).toBe("<p>Alpha</p>");
const full = await w.article("thing", { sections: true });
expect(full.ok && full.value.sections[0].html).toBe("<p>Alpha</p>");
expect(calls.length).toBe(1);
expect(calls[0].url.searchParams.get("prop")).toBe("text|tocdata|revid|displaytitle|properties");
});
+1 -4
View File
@@ -61,7 +61,7 @@ describe("mock Wikipedia", () => {
expect((await w.lookup(["No such page"]))[0]).toMatchObject({ status: "missing" });
});
it("suggests case-insensitively by title or word prefix, and searches with marked excerpts", async () => {
it("suggests case-insensitively by title or word prefix", async () => {
const w = client();
const s = await w.suggest("LAMB");
expect(s.ok && s.value.map((x) => x.title)).toEqual(["Lambda calculus"]);
@@ -70,9 +70,6 @@ describe("mock Wikipedia", () => {
const merc = await w.suggest("mercury");
expect(merc.ok && merc.value[0].title).toBe("Mercury");
expect(merc.ok && merc.value.map((x) => x.title)).toContain("Freddie Mercury");
const q = await w.search("nervous system");
expect(q.ok && q.value.map((x) => x.title)).toEqual(["Octopus", "Cephalopod"]);
expect(q.ok && q.value[0].snippetHtml).toMatch(/<mark>nervous<\/mark> <mark>system<\/mark>/);
});
it("misbehaves on purpose for the offline and rate-limited titles, without poisoning later calls", async () => {
+4 -13
View File
@@ -58,27 +58,18 @@ describe("/api/wiki", () => {
it("validates input", async () => {
expect((await fetch(`${base}/api/wiki/suggest`)).status).toBe(400);
expect((await fetch(`${base}/api/wiki/suggest?q=a&limit=999`)).status).toBe(400);
expect((await fetch(`${base}/api/wiki/search?q=${"x".repeat(301)}`)).status).toBe(400);
const many = Array.from({ length: 201 }, (_, i) => `t${i}`);
expect((await fetch(`${base}/api/wiki/lookup`, { method: "POST", body: JSON.stringify({ titles: many }) })).status).toBe(400);
expect((await fetch(`${base}/api/wiki/lookup`, { method: "POST", body: "{nope" })).status).toBe(400);
expect((await fetch(`${base}/api/wiki/suggest?q=${"x".repeat(201)}`)).status).toBe(400);
expect((await fetch(`${base}/api/wiki/summary?title=${"x".repeat(256)}`)).status).toBe(400);
expect((await fetch(`${base}/api/wiki/summary`, { method: "POST" })).status).toBe(405);
expect((await fetch(`${base}/api/wiki/nothing`)).status).toBe(404);
});
it("answers lookups by GET and POST", async () => {
const g = await (await fetch(`${base}/api/wiki/lookup?titles=Foo|Bar`)).json();
expect(g.results.map((r: { status: string }) => r.status)).toEqual(["missing", "missing"]);
const p = await (await fetch(`${base}/api/wiki/lookup`, { method: "POST", body: JSON.stringify({ titles: ["Baz"] }) })).json();
expect(p).toMatchObject({ ok: true, results: [{ input: "Baz", status: "missing" }] });
});
it("serves suggestions, 404 for missing pages, 503 when offline", async () => {
const s = await (await fetch(`${base}/api/wiki/suggest?q=Brou`)).json();
expect(s).toMatchObject({ ok: true, suggestions: [{ title: "Brouwer fixed-point theorem" }] });
expect((await fetch(`${base}/api/wiki/summary?title=Nothing%20here`)).status).toBe(404);
online = false;
const r = await fetch(`${base}/api/wiki/search?q=fixed`);
const r = await fetch(`${base}/api/wiki/suggest?q=fixed`);
expect(r.status).toBe(503);
expect(await r.json()).toMatchObject({ ok: false, reason: "offline" });
online = true;
@@ -136,7 +127,7 @@ describe("/api/wiki over the mock provider", () => {
});
it("answers every route with 503 off when turned off, and leaves other paths alone", async () => {
for (const path of ["/api/wiki/summary?title=Octopus", "/api/wiki/lookup", "/api/wiki/anything"]) {
for (const path of ["/api/wiki/summary?title=Octopus", "/api/wiki/suggest?q=Oct", "/api/wiki/anything"]) {
expect(await get(off.base, path)).toEqual({
status: 503,
body: { ok: false, reason: "off", message: "Wikipedia is turned off on this server (EX_WIKI=off)." },