Public: anyone can read this; the crew can change it.

The explorer lists every public app the search lists: a forge with one public app does not say "Nothing public yet" #14346

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/14271-the-explorer-lists-every-public-app-the → main 2 commits fork 2 threads · 2 unresolved

  • Merged. scout/14271-the-explorer-lists-every-public-app-the was merged into main as 239f5ef.

Review

Sign in to review this change.
2 files changed +95 −1
src/core/search.ts +16 −1
@@ -32,6 +32,7 @@ import { repoDir } from "../git/repos.ts";
3232 import { GREP_LIMITS, grepSlots, type GrepSlots } from "../search/grep_slots.ts";
3333 import { MAX_QUERY_CHARS } from "./query_limit.ts";
3434 import { appsForRepos } from "./apps.ts";
35 import { UNCLAIMED_OWNER } from "./offered.ts";
3536 import { likeEscape } from "./issues.ts";
3637 import { enterableApps, listReposVisibleTo, type Repo } from "./repos.ts";
3738 import type { User } from "./users.ts";
@@ -220,7 +221,9 @@ export function searchLocalRepos(
220221 seen.add(repo.id);
221222 repos.push(repo);
222223 }
223 const page = repos.slice(0, limit);
224 // A start account no person has claimed is not offered (core/offered.ts): search does not list
225 // what the explorer leaves out, except to the owner's own eyes.
226 const page = withoutUnclaimed(db, viewer, repos).slice(0, limit);
224227 // A private app is the writers' to know of; to anyone else the row is plain.
225228 const apps = appsForRepos(
226229 db,
@@ -241,6 +244,18 @@ export function searchLocalRepos(
241244 });
242245 }
243246
247 function withoutUnclaimed(db: Database, viewer: User | undefined, repos: Repo[]): Repo[] {
248 if (repos.length === 0) return repos;
249 const rows = db
250 .query<{ id: string }, string[]>(
251 `SELECT repo.id FROM repo WHERE ${UNCLAIMED_OWNER}
252 AND repo.id IN (${repos.map((_, n) => `?${n + 1}`).join(",")})`,
253 )
254 .all(...repos.map((r) => r.id));
255 const hidden = new Set(rows.map((r) => r.id));
256 return repos.filter((r) => !hidden.has(r.id) || r.ownerId === viewer?.id);
257 }
258
244259 /**
245260 * Exact name first, then names that begin with what was typed, then the
246261 * rest; within a tier the viewer's own repositories lead. Stable, so the
test/explore-quiet.test.ts added +79
@@ -0,0 +1,79 @@
1 /**
2 * One public app with no activity is on the explorer, ranked last: the same app search lists
3 * (#14271).
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { createRepo } from "../src/actions/repos.ts";
11 import { createApp as insertApp } from "../src/core/apps.ts";
12 import { recordStart } from "../src/core/starts.ts";
13 import { createUser } from "../src/core/users.ts";
14 import { serve, type Servers } from "../src/http/server.ts";
15 import { quietLogs } from "./helpers/globals.ts";
16 import { promote } from "./helpers/members.ts";
17 import { proveAll } from "./helpers/verified.ts";
18
19 quietLogs();
20 let dir: string;
21 let app: App;
22 let servers: Servers;
23
24 beforeAll(async () => {
25 dir = await mkdtemp(join(tmpdir(), "forge-explore-quiet-"));
26 app = createApp({ dataDir: dir, port: 0 });
27 servers = await serve(app);
28 const made = await createUser(app.db, {
29 origin: "seed",
30 username: "quinn",
31 email: "[email protected]",
32 password: "a-good-passphrase",
33 adminIfFirst: true,
34 });
35 if (!made.ok) throw new Error(String(made.error));
36 proveAll(app);
37 promote(app.db, made.value);
38 const repo = await createRepo(app, made.value, { name: "xq", visibility: "public", description: "quiet" });
39 if (!repo.ok) throw new Error(String(repo.error));
40 const rec = insertApp(app.db, { repoId: repo.value.id, slug: "quinn-xq", access: "public" });
41 if (!rec.ok) throw new Error(rec.error);
42 });
43 afterAll(async () => {
44 await servers.stop();
45 app.db.close();
46 await rm(dir, { recursive: true, force: true });
47 });
48
49 type Names = { repos?: { name: string; owner?: string; ownerName?: string }[] };
outdated

This passes on main, so it guards nothing new. Box 4 needs a test that is red without the change. Also JSON.stringify(search) containing "xq" is a weak assertion: check repos has an entry named quinn/xq.

50 const hits = async (q: string) => ((await (await fetch(`${servers.url}/api/v1/search?q=${q}`)).json()) as Names).repos ?? [];
51 const explored = async () =>
52 ((await (await fetch(`${servers.url}/api/v1/explore`)).json()) as { items: { name: string }[] }).items.map((i) => i.name);
53
54 test("a public app with no activity is in the search, the API and the page", async () => {
55 expect((await hits("xq")).some((r) => JSON.stringify(r).includes("quinn/xq") || r.name === "xq")).toBe(true);
56 expect(await explored()).toContain("quinn/xq");
57 const html = await (await fetch(`${servers.url}/explore`)).text();
58 expect(html).toContain("quinn/xq");
59 expect(html).not.toContain("Nothing public yet");
outdated

This test documents the search/explorer disagreement as intended. After the fix, search and the explorer should agree on x-6172/x, so assert that here (absent from both, or present in both) instead of asserting the explorer alone.

60 });
61
62 test("an unclaimed start's app is in neither the search nor the explorer", async () => {
63 const made = await createUser(app.db, {
64 origin: "seed",
65 username: "x-6172",
66 email: "[email protected]",
67 password: "a-good-passphrase",
68 });
69 if (!made.ok) throw new Error(String(made.error));
70 proveAll(app);
71 promote(app.db, made.value);
72 const repo = await createRepo(app, made.value, { name: "x6172", visibility: "public", description: "" });
73 if (!repo.ok) throw new Error(String(repo.error));
74 const rec = insertApp(app.db, { repoId: repo.value.id, slug: "x-6172-x6172", access: "public" });
75 if (!rec.ok) throw new Error(rec.error);
76 recordStart(app.db, made.value.id, "claim-token", "test");
77 expect(await explored()).not.toContain("x-6172/x6172");
78 expect(JSON.stringify(await hits("x6172"))).not.toContain("x6172");
79 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs