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

An archived app leaves every list and stays reachable by its link #15118

Merged opened this

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

Merged

torque/forge:torque/15072-an-archived-app-leaves-every-list-and-st → main 2 commits fork 1 thread · 1 unresolved

  • Merged. torque/15072-an-archived-app-leaves-every-list-and-st was merged into main as 585bc06.

Review

Sign in to review this change.
4 files changed +126 −4
src/core/access_fingerprint.ts +2 −2
@@ -3,7 +3,7 @@
33 * repositories `REPO_VISIBLE` lets them read, the one rule every listing and
44 * the feed share. Memory of what they were shown is only reused while this
55 * is unchanged, so being removed from a team, losing admin, a repository
6 * turning private or its owner being suspended each end it at once, with no
6 * turning private, being archived or its owner being suspended each end it at once, with no

Comment line is over 100 columns; rewrap.

77 * list of writes to remember to watch.
88 */
99 import type { Database } from "bun:sqlite";
@@ -13,7 +13,7 @@ import { REPO_VISIBLE } from "./visibility.ts";
1313 export function accessFingerprint(db: Database, user: User): string {
1414 const row = db
1515 .query<{ ids: string | null }, [string]>(
16 `SELECT group_concat(id) AS ids FROM (SELECT repo.id AS id FROM repo WHERE ${REPO_VISIBLE} ORDER BY repo.id)`,
16 `SELECT group_concat(id) AS ids FROM (SELECT repo.id || CASE WHEN repo.archived_at IS NULL THEN '' ELSE '~' END AS id FROM repo WHERE ${REPO_VISIBLE} ORDER BY repo.id)`,
1717 )
1818 .get(user.id);
1919 return `${user.isAdmin ? "a" : "m"}${user.kind}.${Bun.hash(row?.ids ?? "").toString(36)}`;
src/feed/timeline.ts +3 −1
@@ -80,7 +80,9 @@ export function readTimeline(
8080 const heard = batch.filter(audienceFilter(db, viewer, batch));
8181 const repos = getReposByIds(db, heard.map((e) => e.repoId!));
8282 const own = options.show === undefined ? undefined : showFilter(db, viewer, options.show, heard, repos);
83 const kept = own === undefined ? heard : heard.filter(own);
83 // An archived app is put away (#1838): what it did stays out of the feed until it is restored.
84 const awake = heard.filter((e) => repos.get(e.repoId!)?.archivedAt == null);
85 const kept = own === undefined ? awake : awake.filter(own);
8486 for (const c of eventCandidates(db, viewer, now, kept, repos)) {
8587 if (chipHides(chips, c) || dismissed.has(c.id) || muted.has(c.repoId)) continue;
8688 picked.push({
src/flow/lanes.ts +3 −1
@@ -420,7 +420,9 @@ export function viewFor(
420420 const r = repos.get(id);
421421 readable.set(
422422 id,
423 r !== undefined && canRead(db, r, viewer) ? r : undefined,
423 // An archived app is put away: it leaves the lanes and the filter, its own link still
424 // opens.
425 r !== undefined && r.archivedAt === null && canRead(db, r, viewer) ? r : undefined,
424426 );
425427 }
426428 return readable.get(id);
test/archived-hidden-everywhere.test.ts added +118
@@ -0,0 +1,118 @@
1 /**
2 * An archived app is hidden everywhere and reachable by its link (#15072):
3 * it leaves /, /apps, /explore, the feed, the sitemap and the MCP lists, while
4 * its own address answers with the archived banner and, for its owner, Restore.
5 */
6 import { afterAll, beforeAll, expect, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp, type App } from "../src/app.ts";
11 import { newApp } from "../src/actions/apps.ts";
12 import { setArchived } from "../src/actions/repos.ts";
13 import { forgetListings } from "../src/core/listings.ts";
14 import { openIssue } from "../src/actions/issues.ts";
15 import { createIssue } from "../src/core/issues.ts";
16 import { getRepo } from "../src/core/repos.ts";
17 import { getUserByName } from "../src/core/users.ts";
18 import { serve, type Servers } from "../src/http/server.ts";
19 import { seedAdmin } from "./helpers/admin.ts";
20 import { mcpTool } from "./helpers/mcp.ts";
21 import { tokenFor } from "./helpers/tokens.ts";
22
23 let dataDir: string;
24 let app: App;
25 let servers: Servers;
26 let token = "";
27 const NAME = "zebrashed";
28
29 beforeAll(async () => {
30 dataDir = await mkdtemp(join(tmpdir(), "forge-hidden-everywhere-"));
31 app = createApp({ dataDir, port: 0 });
32 servers = await serve(app);
33 await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-good-passphrase" });
34 const alice = getUserByName(app.db, "alice")!;
35 for (const name of [NAME, "kept"]) {
36 const made = await newApp(app, alice, { name, visibility: "public" });
37 if (!made.ok) throw new Error(String(made.error));
38 createIssue(app.db, { repoId: getRepo(app.db, "alice", name)!.id, authorId: alice.id, title: `work on ${name}` });
39 // A shipped change: the public feed lists merged pulls.
40 const opened = openIssue(app, alice, getRepo(app.db, "alice", name)!, { title: `shipped on ${name}` });
41 if (!opened.ok) throw new Error(String(opened.error));
42 const shipped = opened.value;
43 app.db
44 .query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES (?1, 'main', 'b', '', '', ?2)")
45 .run(shipped.id, new Date().toISOString().replace("T", " ").replace(/\.\d+Z$/, ""));
46 }
47 token = tokenFor(app, "alice", "rw");
48 }, 30_000);
49
50 afterAll(async () => {
51 servers.stop();
52 app.close();
53 await rm(dataDir, { recursive: true, force: true });
54 });
55
56 const mcp = async (name: string, args: unknown): Promise<string> => {
57 const r = await mcpTool(servers.url, token, name, args);
58 return JSON.stringify(r.value ?? r.error);
59 };
60
61 const SURFACES: readonly [string, (anon: boolean) => Promise<string>][] = [
62 ["/", async (anon) => page("/", anon)],
63 ["/apps", async (anon) => page("/apps", anon)],
64 ["/explore", async (anon) => page("/explore", anon)],
65 ["/explore.atom", async (anon) => page("/explore.atom", anon)],
66 ["/feed", async (anon) => page("/feed", anon)],
67 ["/feed?show=mine", async (anon) => page("/feed?show=mine", anon)],
68 ["/feed.json", async (anon) => page("/feed.json", anon)],
69 ["/sitemap.xml", async (anon) => page("/sitemap.xml", anon)],
70 ["mcp apps", () => mcp("apps", {})],
71 ["mcp explore", () => mcp("explore", {})],
72 ["mcp explore q", () => mcp("explore", { q: NAME })],
73 ];
74 let cookie = "";
75 const page = async (path: string, anon: boolean): Promise<string> => {
76 const res = await fetch(`${servers.url}${path}`, { headers: anon || cookie === "" ? {} : { cookie } });
77 return await res.text();
78 };
79
80 test("an archived app is absent from every list and its live sibling is not", async () => {
81 const signin = await fetch(`${servers.url}/signin`, {
82 method: "POST",
83 headers: { origin: servers.url },
84 body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }),
85 redirect: "manual",
86 });
87 cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!;
88 forgetListings(app.db);
89 // Control: before archiving, the app shows on the surfaces that list apps.
90 for (const [where, read] of SURFACES) {
91 if (["/explore.atom", "mcp explore q"].includes(where)) continue;
92 expect([where, (await read(false)).includes(where === "/feed.json" ? `on ${NAME}` : `alice/${NAME}`)]).toEqual([where, true]);
93 }
94 const r = await setArchived(app, getUserByName(app.db, "alice")!, getRepo(app.db, "alice", NAME)!, true, false);
95 expect(r.ok).toBe(true);
96 forgetListings(app.db);
97 for (const anon of [true, false])
98 for (const [where, read] of SURFACES) {
99 const body = await read(anon);
100 if ((body.includes(`alice/${NAME}`) || body.includes(`on ${NAME}`))) throw new Error(`${where} anon=${anon} still lists it: ${body.slice(Math.max(0, body.indexOf(`alice/${NAME}`) - 150), body.indexOf(`alice/${NAME}`) + 100)}`);
101 }
102 // The sibling still shows: the hiding is not a blanket.
103 expect(await page("/explore", true)).toContain("kept");
104 expect(await page("/sitemap.xml", true)).toContain("/alice/kept");
105 });
106
107 test("its own link answers with the archived page, and Restore only for its owner", async () => {
108 const guest = await fetch(`${servers.url}/alice/${NAME}`, { redirect: "manual" });
109 const guestBody = await guest.text();
110 expect(guest.status).toBe(200);
111 expect(guestBody).toContain("Archived on");
112 expect(guestBody).not.toContain(`${NAME}%2Frestore`);
113 const owner = await fetch(`${servers.url}/alice/${NAME}`, { headers: { cookie }, redirect: "manual" });
114 const ownerBody = await owner.text();
115 expect(owner.status).toBe(200);
116 expect(ownerBody).toContain("Archived on");
117 expect(ownerBody).toContain(`href="/-/confirm?to=%2Falice%2F${NAME}%2Frestore"`);
118 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs