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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/12559-an-unclaimed-one-click-start-is-reachabl → main 3 commits fork
5 files
changed +84
−2
src/actions/claim.ts +4
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | */ |
| 11 | 11 | import type { App } from "../app.ts"; |
| 12 | 12 | import { setSuspended } from "../core/accounts.ts"; |
| 13 | import { forgetListings } from "../core/listings.ts"; | |
| 13 | 14 | import { addTeamMember, createOrg, createTeam } from "../core/orgs.ts"; |
| 14 | 15 | import { listReposOwnedBy, moveArchived, type Repo } from "../core/repos.ts"; |
| 15 | 16 | import { markClaimed, startByClaim } from "../core/starts.ts"; |
| @@ -81,6 +82,9 @@ export async function claimStart( | ||
| 81 | 82 | return err("failed"); |
| 82 | 83 | } |
| 83 | 84 | 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); | |
| 84 | 88 | app.bus.append({ |
| 85 | 89 | kind: "start.claimed", |
| 86 | 90 | actorId: claimer.id, |
src/actions/explore.ts +3 −1
| @@ -7,7 +7,8 @@ | ||
| 7 | 7 | * |
| 8 | 8 | * - Only what the viewer may read: repositories by `listReposVisibleTo`; an |
| 9 | 9 | * 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. | |
| 11 | 12 | * - A private app's hours awake are told only to those who may enter it, |
| 12 | 13 | * as on the front page. |
| 13 | 14 | * - People are the owners of the apps shown, their numbers summed and |
| @@ -610,6 +611,7 @@ function rank( | ||
| 610 | 611 | const repos = listReposVisibleTo(db, viewer, { |
| 611 | 612 | limit: READ, |
| 612 | 613 | withoutArchived: !query.archived, |
| 614 | withoutUnclaimed: true, | |
| 613 | 615 | }); |
| 614 | 616 | const records = appsForRepos( |
| 615 | 617 | db, |
src/core/listings.ts +4 −1
| @@ -52,7 +52,8 @@ export interface SitemapRepo { | ||
| 52 | 52 | /** |
| 53 | 53 | * The newest public repositories, at most `SITEMAP_ROWS`, each with the time |
| 54 | 54 | * 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. | |
| 56 | 57 | */ |
| 57 | 58 | export function sitemapRepos(db: Database): readonly SitemapRepo[] { |
| 58 | 59 | return holders(db).sitemap.get("", () => { |
| @@ -60,6 +61,7 @@ export function sitemapRepos(db: Database): readonly SitemapRepo[] { | ||
| 60 | 61 | const repos = listReposVisibleTo(db, undefined, { |
| 61 | 62 | limit: SITEMAP_ROWS, |
| 62 | 63 | withoutArchived: true, |
| 64 | withoutUnclaimed: true, | |
| 63 | 65 | }); |
| 64 | 66 | const pushed = new Map( |
| 65 | 67 | db |
| @@ -100,6 +102,7 @@ export function llmsRepos(db: Database): LlmsListing { | ||
| 100 | 102 | const repos = listReposVisibleTo(db, undefined, { |
| 101 | 103 | limit: LLMS_ROWS, |
| 102 | 104 | withoutArchived: true, |
| 105 | withoutUnclaimed: true, | |
| 103 | 106 | }); |
| 104 | 107 | const ids = new Set(repos.map((r) => r.id)); |
| 105 | 108 | const forks = new Map<string, number>(); |
src/core/repos.ts +8
| @@ -865,6 +865,12 @@ export interface ListReposOptions { | ||
| 865 | 865 | archivedOnly?: boolean; |
| 866 | 866 | /** Only this owner's repositories (a username, any case). */ |
| 867 | 867 | 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; | |
| 868 | 874 | } |
| 869 | 875 | |
| 870 | 876 | // Visibility in SQL: public, owned, or owned by an org the viewer is on a |
| @@ -901,6 +907,8 @@ function visibleClause( | ||
| 901 | 907 | } |
| 902 | 908 | if (options.withoutArchived === true) where += " AND repo.archived_at IS NULL"; |
| 903 | 909 | 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)"; | |
| 904 | 912 | params.push(pageLimit(options.limit)); |
| 905 | 913 | return { where, params }; |
| 906 | 914 | } |
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); |
new above
offline