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

An unclaimed one-click start is reachable by its link but not listed on /explore, the explore API or llms.txt until it is claimed #12562

Merged opened this

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

Merged

mason/forge:mason/12559-an-unclaimed-one-click-start-is-reachabl → main 3 commits fork

  • Merged. mason/12559-an-unclaimed-one-click-start-is-reachabl was merged into main as a25da9e.

Review

Sign in to review this change.
5 files changed +84 −2
src/actions/claim.ts +4
@@ -10,6 +10,7 @@
1010 */
1111 import type { App } from "../app.ts";
1212 import { setSuspended } from "../core/accounts.ts";
13 import { forgetListings } from "../core/listings.ts";
1314 import { addTeamMember, createOrg, createTeam } from "../core/orgs.ts";
1415 import { listReposOwnedBy, moveArchived, type Repo } from "../core/repos.ts";
1516 import { markClaimed, startByClaim } from "../core/starts.ts";
@@ -81,6 +82,9 @@ export async function claimStart(
8182 return err("failed");
8283 }
8384 setSuspended(app.db, agent.id, null);
85 // Claimed, its repositories are listed again (explore, llms.txt, the sitemap)
86 // with no further step.
87 forgetListings(app.db);
8488 app.bus.append({
8589 kind: "start.claimed",
8690 actorId: claimer.id,
src/actions/explore.ts +3 −1
@@ -7,7 +7,8 @@
77 *
88 * - Only what the viewer may read: repositories by `listReposVisibleTo`; an
99 * agent's working fork is how the crew builds, not something to explore,
10 * so a repository an agent owns is left out.
10 * so a repository an agent owns is left out, and so is one an unclaimed
11 * start owns (`core/starts.ts`) until a person claims it.
1112 * - A private app's hours awake are told only to those who may enter it,
1213 * as on the front page.
1314 * - People are the owners of the apps shown, their numbers summed and
@@ -610,6 +611,7 @@ function rank(
610611 const repos = listReposVisibleTo(db, viewer, {
611612 limit: READ,
612613 withoutArchived: !query.archived,
614 withoutUnclaimed: true,
613615 });
614616 const records = appsForRepos(
615617 db,
src/core/listings.ts +4 −1
@@ -52,7 +52,8 @@ export interface SitemapRepo {
5252 /**
5353 * The newest public repositories, at most `SITEMAP_ROWS`, each with the time
5454 * of its last push. Who may be listed is `listReposVisibleTo`'s answer, so a
55 * private, archived or suspended owner's repository is never here.
55 * private, archived or suspended owner's repository is never here, nor an
56 * unclaimed start's.
5657 */
5758 export function sitemapRepos(db: Database): readonly SitemapRepo[] {
5859 return holders(db).sitemap.get("", () => {
@@ -60,6 +61,7 @@ export function sitemapRepos(db: Database): readonly SitemapRepo[] {
6061 const repos = listReposVisibleTo(db, undefined, {
6162 limit: SITEMAP_ROWS,
6263 withoutArchived: true,
64 withoutUnclaimed: true,
6365 });
6466 const pushed = new Map(
6567 db
@@ -100,6 +102,7 @@ export function llmsRepos(db: Database): LlmsListing {
100102 const repos = listReposVisibleTo(db, undefined, {
101103 limit: LLMS_ROWS,
102104 withoutArchived: true,
105 withoutUnclaimed: true,
103106 });
104107 const ids = new Set(repos.map((r) => r.id));
105108 const forks = new Map<string, number>();
src/core/repos.ts +8
@@ -865,6 +865,12 @@ export interface ListReposOptions {
865865 archivedOnly?: boolean;
866866 /** Only this owner's repositories (a username, any case). */
867867 owner?: string;
868 /**
869 * Leave out what an unclaimed start owns (`core/starts.ts`): a listing the
870 * forge offers strangers (explore, llms.txt, the sitemap) names it only once
871 * a person has claimed it. Its own URL still answers. @default false
872 */
873 withoutUnclaimed?: boolean;
868874 }
869875
870876 // Visibility in SQL: public, owned, or owned by an org the viewer is on a
@@ -901,6 +907,8 @@ function visibleClause(
901907 }
902908 if (options.withoutArchived === true) where += " AND repo.archived_at IS NULL";
903909 if (options.archivedOnly === true) where += " AND repo.archived_at IS NOT NULL";
910 if (options.withoutUnclaimed === true)
911 where += " AND NOT EXISTS (SELECT 1 FROM start_account WHERE start_account.user_id = repo.owner_id AND start_account.claimed_at IS NULL)";
904912 params.push(pageLimit(options.limit));
905913 return { where, params };
906914 }
test/start-unlisted.test.ts added +65
@@ -0,0 +1,65 @@
1 /**
2 * An unclaimed start is not on the front door's lists (#12559): its app
3 * answers at its own URL, but /explore, /api/v1/explore, /explore.atom,
4 * /llms.txt and /sitemap.xml leave it out until a person claims it, and the
5 * claim lists it again with no further step.
6 */
7 import { afterAll, beforeAll, expect, test } from "bun:test";
8 import { mkdtempSync, rmSync } from "node:fs";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { claimStart } from "../src/actions/claim.ts";
12 import { startBuilding } from "../src/actions/start.ts";
13 import { createApp, type App } from "../src/app.ts";
14 import { createUser, type User } from "../src/core/users.ts";
15 import { serve, type Servers } from "../src/http/server.ts";
16 import { quietLogs } from "./helpers/globals.ts";
17
18 quietLogs();
19
20 let root = "";
21 let app: App;
22 let servers: Servers;
23 let alice: User;
24
25 beforeAll(async () => {
26 root = mkdtempSync(join(tmpdir(), "forge-start-unlisted-"));
27 app = createApp({ dataDir: root, port: 0 });
28 const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
29 if (!made.ok) throw new Error(made.error);
30 alice = made.value;
31 servers = await serve(app);
32 }, 30_000);
33 afterAll(() => {
34 servers.stop();
35 app.close();
36 rmSync(root, { recursive: true, force: true });
37 });
38
39 const body = async (path: string): Promise<string> => {
40 const res = await fetch(`${servers.url}${path}`);
41 expect(res.status).toBe(200);
42 return res.text();
43 };
44
45 const LISTS = ["/explore", "/api/v1/explore", "/explore.atom", "/llms.txt", "/sitemap.xml"];
46
47 test("an unclaimed start answers at its URL but no list names it; a claim lists it again", async () => {
48 const made = await startBuilding(app, { name: "unlisted-garden" }, "203.0.113.9", servers.url);
49 if (!made.ok) throw new Error(made.error.error);
50 const repo = made.value.repo;
51 const owner = made.value.user.username;
52
53 // Reachable by its link: the repository page answers to a stranger.
54 expect(await body(`/${repo}`)).toContain("unlisted-garden");
55
56 for (const path of LISTS) expect(await body(path), path).not.toContain(owner);
57
58 const token = made.value.claim.url.split("/").pop()!;
59 const claimed = await claimStart(app, alice, token);
60 if (!claimed.ok) throw new Error(claimed.error);
61 const listed = claimed.value.repos[0]!;
62 expect(listed).toEndWith("/unlisted-garden");
63
64 for (const path of LISTS) expect(await body(path), path).toContain(listed);
65 }, 30_000);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs