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:
1 parent
60d26908d6
commit
5c867b2eef
9 files changed
+24
-190
No files matched your search
@@ -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)." },
|
||||
|
||||
Reference in new issue
Block a user