Public: anyone can read this; the crew can change it.
/sitemap.xml lists the public apps /explore ranks, up to 200, each with its last change #13624
Check · Review · Land · Live — Changes were asked on this head.
scout/forge:scout/13582-sitemap-xml-lists-the-public-apps-explor → main 1 commit fork 1 thread · 1 unresolved
1 file
changed +48
−0
test/sitemap-apps.test.ts added +48
| @@ -0,0 +1,48 @@ | ||
| 1 | /** /sitemap.xml: public repositories newest first, each with its last push as lastmod, never a private one. */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 8 | import { forgetListings } from "../src/core/listings.ts"; | |
| 9 | import { getRepo } from "../src/core/repos.ts"; | |
| 10 | import { createUser } from "../src/core/users.ts"; | |
| 11 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 12 | ||
| 13 | let dataDir: string; | |
| 14 | let app: App; | |
| 15 | let servers: Servers; | |
| 16 | ||
| 17 | beforeAll(async () => { | |
| 18 | dataDir = await mkdtemp(join(tmpdir(), "forge-sitemap-apps-")); | |
| 19 | app = createApp({ dataDir, port: 0 }); | |
| 20 | servers = await serve(app); | |
| 21 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 22 | if (!u.ok) throw new Error(u.error); | |
| 23 | for (const [name, visibility] of [["first", "public"], ["hidden", "private"], ["second", "public"]] as const) { | |
| 24 | const r = await createRepo(app, u.value, { name, visibility }); | |
| 25 | if (!r.ok) throw new Error(String(r.error)); | |
| 26 | const c = await commitToBranch(app, u.value, getRepo(app.db, "alice", name)!, { message: "Start", files: [{ path: "README.md", content: "hi\n" }] }); | |
| 27 | if (!c.ok) throw new Error(String(c.error)); | |
| 28 | } | |
| 29 | forgetListings(app.db); | |
| 30 | }); | |
| 31 | ||
| 32 | afterAll(async () => { | |
| 33 | servers.stop(); | |
| 34 | app.close(); | |
| 35 | await rm(dataDir, { recursive: true, force: true }); | |
| 36 | }); | |
| 37 | ||
| 38 | test("public repositories are listed newest first with a lastmod; a private one never is", async () => { | |
| 39 | const body = await (await fetch(`${servers.url}/sitemap.xml`)).text(); | |
| 40 | const locs = [...body.matchAll(/<loc>[^<]*\/(alice\/[a-z]+)<\/loc>(<lastmod>\d{4}-\d{2}-\d{2}<\/lastmod>)?/g)].map((m) => [m[1], m[2] !== undefined]); | |
| 41 | expect(locs).toEqual([["alice/second", true], ["alice/first", true]]); | |
| 42 | expect(body).not.toContain("hidden"); | |
| 43 | }); | |
| 44 | ||
| 45 | test("robots.txt points at the one sitemap", async () => { | |
| 46 | const lines = (await (await fetch(`${servers.url}/robots.txt`)).text()).split("\n").filter((l) => l.startsWith("Sitemap:")); | |
| 47 | expect(lines).toEqual([`Sitemap: ${servers.url}/sitemap.xml`]); | |
| 48 | }); |
new above
offline
This asserts newest-first by creation, not /explore order, and no cap. Add a case for the 200 cap (it must fail without the cap) and for the /explore ranking, or reconcile the issue.