Public: anyone can read this; the crew can change it.
An app's page says in one line who can see it (only you, your members, anyone with the link, the public) and the same words reach the MCP #15665
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15632-an-app-s-page-says-in-one-line-who-can-s → main 0 commits fork 2 threads · 2 unresolved
8 files
changed +327
−11
docs/features/app-seen-by.md added +29
| @@ -0,0 +1,29 @@ | ||
| 1 | --- | |
| 2 | topic: Every setting, by topic | |
| 3 | row: Who can open the app, in the same line | |
| 4 | --- | |
| 5 | # Who can open the app, in the same line | |
| 6 | ||
| 7 | A repository's audience sentence ([](visibility-line.md)) speaks | |
| 8 | for its app as well, and says the app only where the app reaches further than | |
| 9 | the code: private code behind a public app. | |
| 10 | ||
| 11 | text | |
| 12 | Private: only you; anyone with the link can open its app. | |
| 13 | ||
| 14 | ||
| 15 | In every other case the sentence already says it, so nothing is added: public | |
| 16 | code and a public app ("Public: anyone can read this; …"), public code and a | |
| 17 | private app ("The code is public; the app answers only to …"), and private code | |
| 18 | with a private app ("Private: only you."). | |
| 19 | ||
| 20 | - **Web**: the head of the repository and of its app's page shows it. | |
| 21 | - **Terminal**: the About card (`I`) prints the same sentence. | |
| 22 | - **API and MCP**: `GET /api/v1/repos/:owner/:name` and the `repo` tool carry | |
| 23 | it as `audience.sentence`, and add `audience.appLine` (`null` without an app): | |
| 24 | who can open the app on its own, for a client that reads only that. A private | |
| 25 | app lets in whoever can change the repository and the people the app names; | |
| 26 | the owner reads "you", anyone else the owner's name. | |
| 27 | ||
| 28 | The words live in `src/apps/visibility_words.ts`. Tried by | |
| 29 | `test/visibility-words.test.ts`. |
src/apps/visibility_words.ts added +49
| @@ -0,0 +1,49 @@ | ||
| 1 | /** | |
| 2 | * Who can open an app, in one line: the words the MCP and HTTP `repo` read | |
| 3 | * return as `audience.appLine` (#15632), and the clause the audience sentence | |
| 4 | * adds when the app reaches further than the code (`LINK_CLAUSE`). Pure: plain | |
| 5 | * facts in, one of four kinds and a sentence out, so each wording is a test. | |
| 6 | * | |
| 7 | * A private app lets in whoever can change the repository (and its crew) and | |
| 8 | * the people the app names (`canEnterApp` in `core/repos.ts`); the line says | |
| 9 | * exactly that, naming the owner — "you" only to the owner. | |
| 10 | * | |
| 11 | * - `you`: a private app on a person's repository. | |
| 12 | * - `members`: a private app on an organization's repository. | |
| 13 | * - `link`: a public app whose code is private — reachable by its URL. | |
| 14 | * - `public`: a public app on a public repository. | |
| 15 | */ | |
| 16 | ||
| 17 | export type AppSeenBy = "you" | "members" | "link" | "public"; | |
| 18 | ||
| 19 | export interface AppVisibilityFacts { | |
| 20 | readonly access: "public" | "private"; | |
| 21 | readonly visibility: "public" | "private"; | |
| 22 | readonly ownerKind: "user" | "org"; | |
| 23 | readonly ownerName: string; | |
| 24 | /** Whether the person looking owns the repository: "you" is said only to them. */ | |
| 25 | readonly viewerOwns: boolean; | |
| 26 | } | |
| 27 | ||
| 28 | /** What the audience sentence of private code adds when its app is public. */ | |
| 29 | export const LINK_CLAUSE = "anyone with the link can open its app"; | |
| 30 | ||
| 31 | export function appSeenBy(facts: Pick<AppVisibilityFacts, "access" | "visibility" | "ownerKind">): AppSeenBy { | |
| 32 | if (facts.access === "public") return facts.visibility === "public" ? "public" : "link"; | |
| 33 | return facts.ownerKind === "org" ? "members" : "you"; | |
| 34 | } | |
| 35 | ||
| 36 | const REST = "whoever can change the repository, and the people the app names can open it."; | |
| 37 | ||
| 38 | export function appVisibilityWords(facts: AppVisibilityFacts): { readonly seenBy: AppSeenBy; readonly line: string } { | |
| 39 | const seenBy = appSeenBy(facts); | |
| 40 | const line = | |
| 41 | seenBy === "public" | |
| 42 | ? "Anyone can open this app." | |
| 43 | : seenBy === "link" | |
| 44 | ? "Anyone with the link can open this app; its code stays private." | |
| 45 | : seenBy === "members" | |
| 46 | ? `Only whoever can change ${facts.ownerName}'s repository and the people the app names can open this app.` | |
| 47 | : `Only ${facts.viewerOwns ? "you" : facts.ownerName}, ${REST}`; | |
| 48 | return { seenBy, line }; | |
| 49 | } |
src/core/audience.ts +38 −1
| @@ -13,6 +13,7 @@ import type { Database } from "bun:sqlite"; | ||
| 13 | 13 | import type { Repo } from "./repos.ts"; |
| 14 | 14 | import type { User } from "./users.ts"; |
| 15 | 15 | import { REPO_VISIBLE, REPO_WRITABLE } from "./visibility.ts"; |
| 16 | import { LINK_CLAUSE, appVisibilityWords } from "../apps/visibility_words.ts"; | |
| 16 | 17 | |
| 17 | 18 | export interface AudienceFacts { |
| 18 | 19 | readonly visibility: "public" | "private"; |
| @@ -27,6 +28,8 @@ export interface AudienceFacts { | ||
| 27 | 28 | readonly viewerWrites: boolean; |
| 28 | 29 | /** Whether any of the crew works here. */ |
| 29 | 30 | readonly crew: boolean; |
| 31 | /** Whether the viewer owns the repository (an app's line says "you" only to them). */ | |
| 32 | readonly viewerOwns?: boolean; | |
| 30 | 33 | /** |
| 31 | 34 | * The app's access, when the repository has an app. People are counted |
| 32 | 35 | * once, never the viewer: `writers` may change the repository, `named` are |
| @@ -113,11 +116,15 @@ export function audienceOf(facts: AudienceFacts): Audience { | ||
| 113 | 116 | } |
| 114 | 117 | const alone = parts.length === 1 && you.length === 1; |
| 115 | 118 | parts.push(...crew); |
| 119 | // A public app on private code reaches further than the code: the one case | |
| 120 | // the sentence must go on to say who can open the app (#15632). Every other | |
| 121 | // case it already says, so it is said once. | |
| 122 | const linked = facts.app?.access === "public" ? `; ${LINK_CLAUSE}` : ""; | |
| 116 | 123 | return { |
| 117 | 124 | level: "private", |
| 118 | 125 | sentence: `Private: ${alone ? "only " : ""}${ |
| 119 | 126 | parts.length === 0 ? "nobody" : list(parts) |
| 120 | }.`, | |
| 127 | }${linked}.`, | |
| 121 | 128 | }; |
| 122 | 129 | } |
| 123 | 130 | |
| @@ -203,6 +210,7 @@ export function audienceFacts( | ||
| 203 | 210 | viewer === undefined ? "signed-out" : viewer.isAdmin ? "admin" : "person", |
| 204 | 211 | ownerKind: owner?.kind ?? "user", |
| 205 | 212 | ownerName: repo.ownerName, |
| 213 | viewerOwns: viewerId !== undefined && viewerId === repo.ownerId, | |
| 206 | 214 | readers: countPeople(db, repo.id, REPO_VISIBLE, viewerId), |
| 207 | 215 | writers: countPeople(db, repo.id, REPO_WRITABLE, undefined), |
| 208 | 216 | viewerWrites: writes, |
| @@ -225,6 +233,21 @@ export function audienceFacts( | ||
| 225 | 233 | }; |
| 226 | 234 | } |
| 227 | 235 | |
| 236 | /** | |
| 237 | * Who can open the repository's app, in the one line its page head shows | |
| 238 | * (`apps/visibility_words.ts`); `null` when the repository has no app. | |
| 239 | */ | |
| 240 | export function appLineOf(facts: AudienceFacts): string | null { | |
| 241 | if (facts.app === undefined) return null; | |
| 242 | return appVisibilityWords({ | |
| 243 | access: facts.app.access, | |
| 244 | visibility: facts.visibility, | |
| 245 | ownerKind: facts.ownerKind, | |
| 246 | ownerName: facts.ownerName, | |
| 247 | viewerOwns: facts.viewerOwns === true, | |
| 248 | }).line; | |
| 249 | } | |
| 250 | ||
| 228 | 251 | /** The audience of `repo` for `viewer`: the one call the API and the MCP share. */ |
| 229 | 252 | export function audienceFor( |
| 230 | 253 | db: Database, |
| @@ -234,3 +257,17 @@ export function audienceFor( | ||
| 234 | 257 | const facts = audienceFacts(db, repo, viewer); |
| 235 | 258 | return { ...audienceOf(facts), who: whoOf(facts) }; |
| 236 | 259 | } |
| 260 | ||
| 261 | /** | |
| 262 | * The audience as the repository read returns it (HTTP and MCP `repo`), with | |
| 263 | * `appLine`: who can open its app. Only that read carries it, so the page | |
| 264 | * manifest and the other callers stay their size. | |
| 265 | */ | |
| 266 | export function repoAudienceFor( | |
| 267 | db: Database, | |
| 268 | repo: Repo, | |
| 269 | viewer: User | undefined, | |
| 270 | ): Audience & { readonly who: Who; readonly appLine: string | null } { | |
| 271 | const facts = audienceFacts(db, repo, viewer); | |
| 272 | return { ...audienceOf(facts), who: whoOf(facts), appLine: appLineOf(facts) }; | |
| 273 | } |
src/http/api.ts +3 −3
| @@ -151,7 +151,7 @@ import { | ||
| 151 | 151 | } from "../actions/users.ts"; |
| 152 | 152 | import { OFFSET_LIMIT_MAX, offsetPage, offsetQuery } from "./offset_page.ts"; |
| 153 | 153 | import { EVENTS_LIMIT_MAX, eventsAfter, eventsLimit, eventsPage, validEventsCursor, validEventsKind } from "../core/events_page.ts"; |
| 154 | import { audienceFor } from "../core/audience.ts"; | |
| 154 | import { repoAudienceFor } from "../core/audience.ts"; | |
| 155 | 155 | import { repoFor, reposFor, writeAccess, type WriteAccess } from "../core/repo_fields.ts"; |
| 156 | 156 | import { creditFacts } from "../actions/credit_facts.ts"; |
| 157 | 157 | import { |
| @@ -1747,7 +1747,7 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo | ||
| 1747 | 1747 | const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx)); |
| 1748 | 1748 | if (!repo) return notFound(); |
| 1749 | 1749 | const facts = timePhase(ctx.request, "counts", () => repoJson(ctx, repo)); |
| 1750 | const audience = timePhase(ctx.request, "audience", () => audienceFor(ctx.app.db, repo, ctx.auth.user)); | |
| 1750 | const audience = timePhase(ctx.request, "audience", () => repoAudienceFor(ctx.app.db, repo, ctx.auth.user)); | |
| 1751 | 1751 | const credited = performance.now(); |
| 1752 | 1752 | const credit = await creditFacts(ctx.app, repo, ctx.auth.user); |
| 1753 | 1753 | notePhase(ctx.request, "credit", performance.now() - credited); |
| @@ -1863,7 +1863,7 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo | ||
| 1863 | 1863 | // The line about who can see it moves with the setting, in this answer. |
| 1864 | 1864 | return json({ |
| 1865 | 1865 | ...repoJson(ctx, updated.value), |
| 1866 | audience: audienceFor(ctx.app.db, updated.value, ctx.auth.user), | |
| 1866 | audience: repoAudienceFor(ctx.app.db, updated.value, ctx.auth.user), | |
| 1867 | 1867 | }); |
| 1868 | 1868 | }); |
| 1869 | 1869 |
src/http/mcp/tools/repo.ts +3 −3
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { provenanceFacts } from "../../../core/provenance.ts"; |
| 2 | 2 | import { forkParentFor } from "../../../core/repos.ts"; |
| 3 | import { audienceFor } from "../../../core/audience.ts"; | |
| 3 | import { repoAudienceFor } from "../../../core/audience.ts"; | |
| 4 | 4 | import { repoFor } from "../../../core/repo_fields.ts"; |
| 5 | 5 | import { upstreamFacts } from "../../../actions/upstream_follow.ts"; |
| 6 | 6 | import { creditFacts } from "../../../actions/credit_facts.ts"; |
| @@ -13,7 +13,7 @@ import { good, str, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../share | ||
| 13 | 13 | |
| 14 | 14 | export const tool: Tool = { |
| 15 | 15 | name: "repo", |
| 16 | doc: "`{ repo }`: one repository's description, visibility, autonomy (to a writer), `audience { level, who, sentence }` and `provenance` (where a migrated one came from, `null` when hidden), `credit` (a mirror's upstream, licence, authors; `null` otherwise), the same as `GET /api/v1/repos/:owner/:name`; `action` (`open|add|remove|close` with `chapter`, `number` for add/remove; a person who administers it, `rw` token) says what it would do, and with `confirm: true` does it, as the page; `view: \"chapters\"` lists its chapters with state, and with `chapter` names one's items (`done|building|left`) and `progress` (the page's sentence)", | |
| 16 | doc: "`{ repo }`: one repository's description, visibility, autonomy (to a writer), `audience { level, who, sentence, appLine }` and `provenance` (where a migrated one came from, `null` when hidden), `credit` (a mirror's upstream, licence, authors; `null` otherwise), the same as `GET /api/v1/repos/:owner/:name`; `action` (`open|add|remove|close` with `chapter`, `number` for add/remove; a person who administers it, `rw` token) says what it would do, and with `confirm: true` does it, as the page; `view: \"chapters\"` lists its chapters with state, and with `chapter` names one's items (`done|building|left`) and `progress` (the page's sentence)", | |
| 17 | 17 | description: |
| 18 | 18 | "One repository you can read, as GET /api/v1/repos/:owner/:name.", |
| 19 | 19 | inputSchema: { |
| @@ -73,7 +73,7 @@ export const tool: Tool = { | ||
| 73 | 73 | description: repo.description, |
| 74 | 74 | visibility: repo.visibility, |
| 75 | 75 | autonomy: repo.autonomy, |
| 76 | audience: audienceFor(ctx.app.db, repo, user), | |
| 76 | audience: repoAudienceFor(ctx.app.db, repo, user), | |
| 77 | 77 | provenance: provenanceFacts( |
| 78 | 78 | ctx.app.db, |
| 79 | 79 | repo, |
test/audience-surfaces.test.ts +2 −2
| @@ -9,7 +9,7 @@ import { tmpdir } from "node:os"; | ||
| 9 | 9 | import { join } from "node:path"; |
| 10 | 10 | import { createRepo } from "../src/actions/repos.ts"; |
| 11 | 11 | import { createApp, type App } from "../src/app.ts"; |
| 12 | import { audienceFor } from "../src/core/audience.ts"; | |
| 12 | import { repoAudienceFor } from "../src/core/audience.ts"; | |
| 13 | 13 | import { createApp as makeApp } from "../src/core/apps.ts"; |
| 14 | 14 | import { createToken } from "../src/core/tokens.ts"; |
| 15 | 15 | import { createUser, type User } from "../src/core/users.ts"; |
| @@ -60,7 +60,7 @@ describe("one sentence on every surface", () => { | ||
| 60 | 60 | const auth = { authorization: `Bearer ${token}` }; |
| 61 | 61 | const res = await fetch(`${servers.url}/api/v1/repos/olive/garden`, { headers: auth }); |
| 62 | 62 | const body = (await res.json()) as { audience: { level: string; sentence: string } }; |
| 63 | expect(body.audience).toEqual(audienceFor(app.db, made.value, olive)); | |
| 63 | expect(body.audience).toEqual(repoAudienceFor(app.db, made.value, olive)); | |
| 64 | 64 | expect(body.audience.sentence).toStartWith("The code is public; the app answers only to"); |
| 65 | 65 | |
| 66 | 66 | const mcp = await fetch(`${servers.url}/mcp`, { |
test/visibility-line.test.ts +2 −2
| @@ -14,7 +14,7 @@ import { AppsRuntime } from "../src/apps/runtime.ts"; | ||
| 14 | 14 | import { newApp } from "../src/actions/apps.ts"; |
| 15 | 15 | import { openPull } from "../src/actions/pulls.ts"; |
| 16 | 16 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; |
| 17 | import { audienceFor, whoOf } from "../src/core/audience.ts"; | |
| 17 | import { audienceFor, repoAudienceFor, whoOf } from "../src/core/audience.ts"; | |
| 18 | 18 | import { createApp as createAppRecord, getAppByRepo } from "../src/core/apps.ts"; |
| 19 | 19 | import { getRepo } from "../src/core/repos.ts"; |
| 20 | 20 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; |
| @@ -108,7 +108,7 @@ describe("who can see it, said once, everywhere", () => { | ||
| 108 | 108 | const body: any = await (await api("/repos/alice/notes", aliceRw)).json(); |
| 109 | 109 | expect(body.audience.who).toBe("owner"); |
| 110 | 110 | expect(body.audience.level).toBe("private"); |
| 111 | expect(body.audience).toEqual(audienceFor(app.db, made.value, alice)); | |
| 111 | expect(body.audience).toEqual(repoAudienceFor(app.db, made.value, alice)); | |
| 112 | 112 | }); |
| 113 | 113 | |
| 114 | 114 | test("a stranger asking about a private repository gets what a missing one gets", async () => { |
test/visibility-words.test.ts added +201
| @@ -0,0 +1,201 @@ | ||
| 1 | /** | |
| 2 | * Who can open an app (#15632): the four wordings the MCP `repo` read returns, | |
| 3 | * and the one audience sentence the page head and the terminal's About card | |
| 4 | * share, which adds the app only where it reaches further than the code. | |
| 5 | */ | |
| 6 | import { proveAll } from "./helpers/verified.ts"; | |
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { appVisibilityWords } from "../src/apps/visibility_words.ts"; | |
| 14 | import { repoAudienceFor } from "../src/core/audience.ts"; | |
| 15 | import { createApp as makeApp } from "../src/core/apps.ts"; | |
| 16 | import { createToken } from "../src/core/tokens.ts"; | |
| 17 | import { createUser, type User } from "../src/core/users.ts"; | |
| 18 | import { createOrg } from "../src/core/orgs.ts"; | |
| 19 | import { getRepoById, type Repo } from "../src/core/repos.ts"; | |
| 20 | import type { Ctx, Screen } from "../src/tui/app/app.ts"; | |
| 21 | import type { Session } from "../src/tui/session.ts"; | |
| 22 | import { aboutScreen } from "../src/tui/screens/about.ts"; | |
| 23 | import { Screen as Surface } from "../src/tui/term/screen.ts"; | |
| 24 | import { theme } from "../src/tui/ui/theme.ts"; | |
| 25 | import { localSource } from "../src/view/local.ts"; | |
| 26 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 27 | ||
| 28 | const base = { ownerKind: "user", ownerName: "olive", viewerOwns: true } as const; | |
| 29 | ||
| 30 | describe("the words, one per visibility", () => { | |
| 31 | test("only you: a private app on your own repository, and the owner named to anyone else", () => { | |
| 32 | expect(appVisibilityWords({ ...base, access: "private", visibility: "private" })).toEqual({ | |
| 33 | seenBy: "you", | |
| 34 | line: "Only you, whoever can change the repository, and the people the app names can open it.", | |
| 35 | }); | |
| 36 | expect( | |
| 37 | appVisibilityWords({ ...base, access: "private", visibility: "public", viewerOwns: false }).line, | |
| 38 | ).toBe("Only olive, whoever can change the repository, and the people the app names can open it."); | |
| 39 | }); | |
| 40 | ||
| 41 | test("your members: a private app on an organization's repository says exactly who gets in", () => { | |
| 42 | expect( | |
| 43 | appVisibilityWords({ ...base, ownerKind: "org", ownerName: "acme", access: "private", visibility: "private" }), | |
| 44 | ).toEqual({ | |
| 45 | seenBy: "members", | |
| 46 | line: "Only whoever can change acme's repository and the people the app names can open this app.", | |
| 47 | }); | |
| 48 | }); | |
| 49 | ||
| 50 | test("anyone with the link: a public app whose code is private", () => { | |
| 51 | expect(appVisibilityWords({ ...base, access: "public", visibility: "private" })).toEqual({ | |
| 52 | seenBy: "link", | |
| 53 | line: "Anyone with the link can open this app; its code stays private.", | |
| 54 | }); | |
| 55 | }); | |
| 56 | ||
| 57 | test("the public: a public app on a public repository", () => { | |
| 58 | expect(appVisibilityWords({ ...base, access: "public", visibility: "public" })).toEqual({ | |
| 59 | seenBy: "public", | |
| 60 | line: "Anyone can open this app.", | |
| 61 | }); | |
| 62 | }); | |
| 63 | }); | |
| 64 | ||
| 65 | describe("the page head, the terminal and the MCP say it once, the same way", () => { | |
| 66 | let dataDir: string; | |
| 67 | let app: App; | |
| 68 | let servers: Servers; | |
| 69 | let olive: User; | |
| 70 | let pia: User; | |
| 71 | ||
| 72 | const person = async (username: string, isAdmin = false): Promise<User> => { | |
| 73 | const made = await createUser(app.db, { | |
| 74 | origin: "seed", | |
| 75 | username, | |
| 76 | email: `${username}@f.dev`, | |
| 77 | password: "a-good-passphrase", | |
| 78 | isAdmin, | |
| 79 | }); | |
| 80 | if (!made.ok) throw new Error(made.error); | |
| 81 | return made.value; | |
| 82 | }; | |
| 83 | const repoWithApp = async ( | |
| 84 | name: string, | |
| 85 | visibility: "public" | "private", | |
| 86 | access: "public" | "private", | |
| 87 | owner?: string, | |
| 88 | ): Promise<Repo> => { | |
| 89 | const made = await createRepo(app, olive, { name, visibility, ...(owner ? { owner } : {}) }); | |
| 90 | if (!made.ok) throw new Error(String(made.error)); | |
| 91 | makeApp(app.db, { repoId: made.value.id, slug: name, access }); | |
| 92 | return made.value; | |
| 93 | }; | |
| 94 | const auth = (who: User) => ({ authorization: `Bearer ${createToken(app.db, who.id, "t", "ro").token}` }); | |
| 95 | /** The audience paragraph's sentence on a repository's page. */ | |
| 96 | const pageSentence = async (path: string, who: User): Promise<string> => { | |
| 97 | const page = await (await fetch(`${servers.url}${path}`, { headers: auth(who) })).text(); | |
| 98 | const m = /<p class="muted small"\s*>\s*(?:<span\s+class="badge"[^>]*>Split<\/span\s*>\s*)?(?:<a href="[^"]*"\s*>)?((?:Private|Public|The code is public)[^<]*)/.exec(page); | |
| 99 | if (m === null) throw new Error(`no audience line on ${path}`); | |
| 100 | return m[1]!.trim(); | |
| 101 | }; | |
| 102 | /** The terminal's About card, as text. */ | |
| 103 | const aboutText = (repo: Repo, who: User): string => { | |
| 104 | const ctx = { | |
| 105 | theme: theme("dark"), | |
| 106 | invalidate() {}, | |
| 107 | toast() {}, | |
| 108 | push() {}, | |
| 109 | pop() {}, | |
| 110 | copy() {}, | |
| 111 | hit() {}, | |
| 112 | } as unknown as Ctx; | |
| 113 | const f = { app, db: app.db, user: who } as unknown as Session; | |
| 114 | const src = localSource(app, getRepoById(app.db, repo.id)!, who); | |
| 115 | const screen = aboutScreen(f, ctx, { render() {} } as unknown as Screen, src, undefined, "main"); | |
| 116 | const s = new Surface(160, 30); | |
| 117 | screen.render({ x: 0, y: 0, w: 160, h: 30 }, s); | |
| 118 | return s.toText(); | |
| 119 | }; | |
| 120 | const mcpAppLine = async (repo: string, who: User): Promise<string> => { | |
| 121 | const res = await fetch(`${servers.url}/mcp`, { | |
| 122 | method: "POST", | |
| 123 | headers: { ...auth(who), "content-type": "application/json", accept: "application/json, text/event-stream" }, | |
| 124 | body: JSON.stringify({ | |
| 125 | jsonrpc: "2.0", | |
| 126 | id: 1, | |
| 127 | method: "tools/call", | |
| 128 | params: { name: "repo", arguments: { repo } }, | |
| 129 | }), | |
| 130 | }); | |
| 131 | const body = (await res.json()) as { result: { content: { text: string }[] } }; | |
| 132 | return (JSON.parse(body.result.content[0]!.text) as { audience: { appLine: string } }).audience.appLine; | |
| 133 | }; | |
| 134 | ||
| 135 | beforeAll(async () => { | |
| 136 | dataDir = await mkdtemp(join(tmpdir(), "forge-app-seen-")); | |
| 137 | app = createApp({ dataDir, port: 0 }); | |
| 138 | servers = await serve(app); | |
| 139 | olive = await person("olive", true); | |
| 140 | pia = await person("pia"); | |
| 141 | const org = createOrg(app.db, "acme", olive.id); | |
| 142 | if (!org.ok) throw new Error(String(org.error)); | |
| 143 | proveAll(app); | |
| 144 | }); | |
| 145 | afterAll(async () => { | |
| 146 | servers.stop(); | |
| 147 | app.close(); | |
| 148 | await rm(dataDir, { recursive: true, force: true }); | |
| 149 | }); | |
| 150 | ||
| 151 | test("anyone with the link: private code, public app — the one sentence goes on to say it", async () => { | |
| 152 | const repo = await repoWithApp("plot", "private", "public"); | |
| 153 | const sentence = "Private: only you; anyone with the link can open its app."; | |
| 154 | expect(await pageSentence("/olive/plot", olive)).toBe(sentence); | |
| 155 | expect(await pageSentence("/olive/plot/app", olive)).toBe(sentence); | |
| 156 | expect(aboutText(repo, olive)).toContain(sentence); | |
| 157 | expect(await mcpAppLine("olive/plot", olive)).toBe("Anyone with the link can open this app; its code stays private."); | |
| 158 | }); | |
| 159 | ||
| 160 | test("only you: private code, private app — the sentence already says it, so nothing is added", async () => { | |
| 161 | const repo = await repoWithApp("den", "private", "private"); | |
| 162 | expect(await pageSentence("/olive/den", olive)).toBe("Private: only you."); | |
| 163 | expect(aboutText(repo, olive)).toContain("Private: only you."); | |
| 164 | expect(aboutText(repo, olive)).not.toContain("open its app"); | |
| 165 | expect(await mcpAppLine("olive/den", olive)).toBe( | |
| 166 | "Only you, whoever can change the repository, and the people the app names can open it.", | |
| 167 | ); | |
| 168 | }); | |
| 169 | ||
| 170 | test("your members: an organization's private app — nothing added, and the MCP says who gets in", async () => { | |
| 171 | await repoWithApp("ops", "private", "private", "acme"); | |
| 172 | expect(await pageSentence("/acme/ops", olive)).not.toContain("open its app"); | |
| 173 | expect(await mcpAppLine("acme/ops", olive)).toBe( | |
| 174 | "Only whoever can change acme's repository and the people the app names can open this app.", | |
| 175 | ); | |
| 176 | }); | |
| 177 | ||
| 178 | test("the public: public code, public app — said once, by the repository sentence", async () => { | |
| 179 | const repo = await repoWithApp("park", "public", "public"); | |
| 180 | const sentence = await pageSentence("/olive/park", pia); | |
| 181 | expect(sentence).toStartWith("Public: anyone can read this;"); | |
| 182 | expect(sentence).not.toContain("open its app"); | |
| 183 | expect(aboutText(repo, pia)).toContain(sentence); | |
| 184 | expect(await mcpAppLine("olive/park", pia)).toBe("Anyone can open this app."); | |
| 185 | }); | |
| 186 | ||
| 187 | test("the owner is told \"you\"; anyone else is told the owner's name", async () => { | |
| 188 | await repoWithApp("shed", "public", "private"); | |
| 189 | expect(await mcpAppLine("olive/shed", olive)).toStartWith("Only you, "); | |
| 190 | expect(await mcpAppLine("olive/shed", pia)).toStartWith("Only olive, "); | |
| 191 | // The page's split sentence speaks for the app already, to each viewer in their words. | |
| 192 | expect(await pageSentence("/olive/shed", pia)).toStartWith("The code is public; the app answers only to"); | |
| 193 | }); | |
| 194 | ||
| 195 | test("a repository with no app has no app words, and appLine is null", async () => { | |
| 196 | const made = await createRepo(app, olive, { name: "notes", visibility: "public" }); | |
| 197 | if (!made.ok) throw new Error(String(made.error)); | |
| 198 | expect(repoAudienceFor(app.db, made.value, olive).appLine).toBeNull(); | |
| 199 | expect(await pageSentence("/olive/notes", olive)).not.toContain("open its app"); | |
| 200 | }); | |
| 201 | }); |
new above
offline
'Only members of X ... and anyone it names' is inexact: people who can change the repository and named people also get in. Say it plainly, and make the line shared with the terminal.