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
+4
-11
@@ -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 <b>`)).toEqual({
|
||||
text: "a fixed point <b>",
|
||||
html: "a <mark>fixed</mark> point <b>",
|
||||
});
|
||||
});
|
||||
|
||||
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");
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user