Public: anyone can read this; the crew can change it.
Each app a pack deploys shows a link back to its source on its page and in the terminal #16092
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16068-each-app-a-pack-deploys-shows-a-link-bac → main 0 commits fork 4 threads · 4 unresolved
docs/features/packs.md +3 −1
| @@ -18,7 +18,9 @@ A pack is a public forge repo with a `pack.json` at its root, named like the pac | ||
| 18 | 18 | - Code: `src/packs/`, `src/web/pages/packs.ts`, `scripts/pack.ts`. Tests: `test/packs.test.ts`, `test/packs-up.test.ts` (the whole path against a fake source for both packs, `up()` itself with a real child forge on a free port, the owner reused on a second run, a stored credential, a partial deploy finished, a new upstream commit showing as drift), `test/packs-hands.test.ts` (the git credential is scoped to the forge and never sent to a pack's source; only 409 means "exists"; the terminal screen; an `owner/name` source is forked with lineage, kept on 409, a 422 or 429 refusal failing that step with the forge's message, an unreachable forge, and `absorb` absorbing the fork as its owner). |
| 19 | 19 | - **A source on a forge (`owner/name`).** Deploying forks it with lineage (`POST /forks`) instead of pushing history: nothing is carried over the network and nothing is followed (no follow is set; the fork's lineage is the link). The fork keeps the app's name. `owner/name` is resolved on whichever forge the deploy targets, not on the pack author's forge. An existing fork (409 `already_forked`) counts as kept; a name already taken by something else fails that step. Non-admins are held to the fork limit (`FORKS_PER_DAY`, 5 a day), so a pack with more than five forge apps fails the rest with "at most 5 forks a day"; run it again the next day. Mirroring (below) is for https sources only: a forge-form source is reported as failed ("not an address a mirror may follow"). |
| 20 | 20 | |
| 21 | Not done yet: a hosted "deploy this pack" press, a stable follow link from each app back to its source, the guest sign-up gate and the crew filtering guest pulls on automode (owner decisions on #9428). | |
| 21 | Not done yet: a hosted "deploy this pack" press, the guest sign-up gate and the crew filtering guest pulls on automode (owner decisions on #9428). | |
| 22 | ||
| 23 | - **Where an app came from (#16068).** `up` and `deploy` record each app's `source` (an https address, or `owner/name` of a forge repo) when the app is made, through `PUT /api/v1/repos/:owner/:name/source` (admin scope, the repository's admin). The app's page shows one muted line, "From <source>", linking to it (an address opens in the same tab and carries `rel="noopener noreferrer"`; `owner/name` links to that repo here), and the terminal's About screen has a `from` row. An app with no recorded source shows nothing. `sourceText` (`src/packs/source_guard.ts`) is the one validator: http(s) or `owner/name`, at most 300 characters, no whitespace or control character, no query or fragment, and an address carrying a user or password is refused, never stripped; an address is kept as parsed (`url.href`), so what is stored is what was checked, and the check runs again when the row is read. The source rides the repository row itself (a LEFT JOIN in `core/repos.ts`), so no repository page pays a statement for the line. A failure to record is its own failed step and never hides that the app is made. Code: `src/core/repo_source.ts` (table `repo_made_from`), `src/http/api/repo_source.ts`. Test: `test/packs-source-link.test.ts`. | |
| 22 | 24 | |
| 23 | 25 | ## The upstream mirrors (#10530) |
| 24 | 26 |
scripts/pack.ts +11
| @@ -207,6 +207,17 @@ export function realHands(url: string, token: string, options: HandsOptions = {} | ||
| 207 | 207 | if (r.status === 403) return { ok: false, why: "the forge refused (403): absorbing needs a site admin's token with admin scope, and this token is not one" }; |
| 208 | 208 | return { ok: false, why: `the forge answered ${r.status}` }; |
| 209 | 209 | }, |
| 210 | async recordSource(owner, name, source) { | |
| 211 | const r = await fetch(`${url}/api/v1/repos/${owner}/${name}/source`, { | |
| 212 | method: "PUT", | |
| 213 | headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, | |
| 214 | body: JSON.stringify({ source }), | |
| 215 | }).catch(() => null); | |
| 216 | if (r === null) return { ok: false, why: `cannot reach ${url}` }; | |
| 217 | if (r.ok) return { ok: true }; | |
| 218 | const said = (await r.json().catch(() => null)) as { message?: unknown } | null; | |
| 219 | return { ok: false, why: typeof said?.message === "string" ? said.message : `the forge answered ${r.status}` }; | |
| 220 | }, | |
| 210 | 221 | async makeAgent(a) { |
| 211 | 222 | const r = await fetch(`${url}/api/v1/agents`, { |
| 212 | 223 | method: "POST", |
src/contract/openapi/routes/index.ts +1
| @@ -482,6 +482,7 @@ export { route as putApiV1ReposOwnerNamePullsNumberAssignee } from "./putApiV1Re | ||
| 482 | 482 | export { route as putApiV1ReposOwnerNamePullsNumberHold } from "./putApiV1ReposOwnerNamePullsNumberHold.ts"; |
| 483 | 483 | export { route as putApiV1ReposOwnerNamePullsNumberLabels } from "./putApiV1ReposOwnerNamePullsNumberLabels.ts"; |
| 484 | 484 | export { route as putApiV1ReposOwnerNamePullsNumberReview } from "./putApiV1ReposOwnerNamePullsNumberReview.ts"; |
| 485 | export { route as putApiV1ReposOwnerNameSource } from "./putApiV1ReposOwnerNameSource.ts"; | |
| 485 | 486 | export { route as putApiV1ReposOwnerNameUpstream } from "./putApiV1ReposOwnerNameUpstream.ts"; |
| 486 | 487 | export { route as putApiV1SecretsScopeName } from "./putApiV1SecretsScopeName.ts"; |
| 487 | 488 | export { route as putApiV1UserNotify } from "./putApiV1UserNotify.ts"; |
src/contract/openapi/routes/putApiV1ReposOwnerNameSource.ts added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | import { REPO, type Route } from "../shared.ts"; | |
| 2 | ||
| 3 | export const route: Route = { | |
| 4 | method: "put", | |
| 5 | path: `${REPO}/source`, | |
| 6 | summary: "Record where a pack's app came from", | |
| 7 | detail: "Record where a pack's app came from (admin scope): an owner/name on a forge or an http(s) address with no credential, shown as the From line on its page and in the terminal; answers the source kept", | |
| 8 | auth: true, | |
| 9 | role: "admin", | |
| 10 | body: { source: "string" }, | |
| 11 | refusals: { bad_source: "`source` is not an owner/name or a plain http(s) address" }, | |
| 12 | refuses: [401, 404], | |
| 13 | }; |
src/contract/tags.ts +1
| @@ -35,6 +35,7 @@ const ALIAS: Readonly<Record<string, string>> = { | ||
| 35 | 35 | branches: "repos", |
| 36 | 36 | commits: "repos", |
| 37 | 37 | contents: "repos", |
| 38 | source: "repos", | |
| 38 | 39 | statement: "plan", |
| 39 | 40 | vision: "plan", |
| 40 | 41 | roadmap: "plan", |
src/core/migration-pins/20261123130000-repo-made-from.pin added +1
| @@ -0,0 +1,1 @@ | ||
| 1 | 3b3bc0616f309e9d760a14322a07f403f1a8673dde55912024a20a6cddad86e6 |
src/core/migrations/20261123130000-repo-made-from.ts added +9
| @@ -0,0 +1,9 @@ | ||
| 1 | // Where a pack's app came from (#16068): the address it was made from, or `owner/name` on a forge. | |
| 2 | // One row per app; none means nothing is said. Additive: the release before never reads it. | |
| 3 | export default ` | |
| 4 | CREATE TABLE IF NOT EXISTS repo_made_from ( | |
| 5 | repo_id TEXT PRIMARY KEY REFERENCES repo(id) ON DELETE CASCADE, | |
| 6 | source TEXT NOT NULL, | |
| 7 | created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) | |
| 8 | ); | |
| 9 | `; |
src/core/repo_fields.ts +1
| @@ -74,6 +74,7 @@ const CREW_FIELDS = { | ||
| 74 | 74 | directionIssueId: "string|null", |
| 75 | 75 | sealedFor: "string|null", |
| 76 | 76 | severedAt: "string|null", |
| 77 | madeFrom: "string|null", | |
| 77 | 78 | } as const satisfies Readonly<Record<string, string>>; |
| 78 | 79 | |
| 79 | 80 | /** A list item as a writer gets it: the stored row whole, `detached` included. */ |
src/core/repo_source.ts added +39
| @@ -0,0 +1,39 @@ | ||
| 1 | /** | |
| 2 | * Where a pack's app came from (#16068): one address kept per repository, read | |
| 3 | * back as the muted "From …" line on its page and in the terminal. Pure data, | |
| 4 | * no authz; the address is judged by `packs/source_guard.ts` before it is kept | |
| 5 | * and again when it is read, so a stale row is never drawn. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { Database } from "bun:sqlite"; | |
| 9 | import { sourceText } from "../packs/source_guard.ts"; | |
| 10 | import type { Repo } from "./repos.ts"; | |
| 11 | ||
| 12 | export interface RepoSource { | |
| 13 | /** `owner/name` of a repository on a forge, or an http(s) address with no credential. */ | |
| 14 | readonly source: string; | |
| 15 | /** Where the words link: this forge's page for `owner/name`, else the address. */ | |
| 16 | readonly href: string; | |
| 17 | } | |
| 18 | ||
| 19 | const linked = (source: string): RepoSource => ({ source, href: source.includes("://") ? source : `/${source}` }); | |
| 20 | ||
| 21 | /** | |
| 22 | * The source kept for a repository, or undefined when none or no longer fit to show. Read off | |
| 23 | * the repository row (`Repo.madeFrom`, joined in `core/repos.ts`), so it costs no statement. | |
| 24 | */ | |
| 25 | export function repoSource(repo: Pick<Repo, "madeFrom">): RepoSource | undefined { | |
| 26 | if (repo.madeFrom === null) return undefined; | |
| 27 | const checked = sourceText(repo.madeFrom); | |
| 28 | return checked.ok ? linked(checked.value) : undefined; | |
| 29 | } | |
| 30 | ||
| 31 | /** Keep the source, replacing an earlier one; the refusal's words when it is not fit to keep. */ | |
| 32 | export function setRepoSource(db: Database, repoId: string, raw: string): { ok: true; source: string } | { ok: false; error: string } { | |
| 33 | const checked = sourceText(raw); | |
| 34 | if (!checked.ok) return { ok: false, error: checked.error }; | |
| 35 | db.query( | |
| 36 | "INSERT INTO repo_made_from (repo_id, source) VALUES (?1, ?2) ON CONFLICT (repo_id) DO UPDATE SET source = excluded.source", | |
| 37 | ).run(repoId, checked.value); | |
| 38 | return { ok: true, source: checked.value }; | |
| 39 | } |
src/core/repos.ts +11 −2
| @@ -196,6 +196,12 @@ export interface Repo { | ||
| 196 | 196 | readonly detached: RepoDetached | null; |
| 197 | 197 | /** When a fork's owner cut it loose from its parent; null when it never was (#14855). */ |
| 198 | 198 | readonly severedAt: string | null; |
| 199 | /** | |
| 200 | * Where a pack's app came from, as kept (#16068), or null. Read on the same row as the rest | |
| 201 | * (a LEFT JOIN on its primary key) so the header's "From …" line costs no statement of its | |
| 202 | * own; `core/repo_source.ts` judges it again before anything draws it. | |
| 203 | */ | |
| 204 | readonly madeFrom: string | null; | |
| 199 | 205 | /** |
| 200 | 206 | * Open issue and pull counts. Absent from a bare `getRepo` — a single |
| 201 | 207 | * fetch on a hot path should not pay for a count nobody asked for — and |
| @@ -239,15 +245,17 @@ interface RepoRow { | ||
| 239 | 245 | last_fetch_at: string | null; |
| 240 | 246 | fetch_error: string; |
| 241 | 247 | origin_detached_at: string | null; |
| 248 | made_from: string | null; | |
| 242 | 249 | } |
| 243 | 250 | |
| 244 | 251 | // LEFT JOIN, because the origin may have been disconnected out from under a |
| 245 | 252 | // mirror — the repo survives, the link does not. |
| 246 | 253 | const SELECT = ` |
| 247 | SELECT repo.*, user.username AS owner_name, origin.kind AS origin_kind, | |
| 254 | SELECT repo.*, user.username AS owner_name, origin.kind AS origin_kind, made.source AS made_from, | |
| 248 | 255 | origin.software AS origin_software |
| 249 | 256 | FROM repo JOIN user ON user.id = repo.owner_id |
| 250 | LEFT JOIN origin ON origin.id = repo.origin_id`; | |
| 257 | LEFT JOIN origin ON origin.id = repo.origin_id | |
| 258 | LEFT JOIN repo_made_from made ON made.repo_id = repo.id`; | |
| 251 | 259 | |
| 252 | 260 | /** The by-name match `getRepo` and `repoVisibility` share, so the two cannot drift. */ |
| 253 | 261 | const BY_NAME = "user.username = ?1 COLLATE NOCASE AND repo.name = ?2 COLLATE NOCASE"; |
| @@ -293,6 +301,7 @@ function toRepo(row: RepoRow): Repo { | ||
| 293 | 301 | } |
| 294 | 302 | : null, |
| 295 | 303 | severedAt: row.origin_id === null && row.origin_full_name === null ? row.origin_detached_at : null, |
| 304 | madeFrom: row.made_from, | |
| 296 | 305 | detached: |
| 297 | 306 | row.origin_id === null && |
| 298 | 307 | row.origin_full_name !== null && |
src/http/api.ts +2
| @@ -373,6 +373,7 @@ import { secretRoutes } from "./api/secrets.ts"; | ||
| 373 | 373 | import { drillRoutes } from "./api/drills.ts"; |
| 374 | 374 | import { featureRoutes } from "./api/features.ts"; |
| 375 | 375 | import { upstreamRoutes } from "./api/upstream.ts"; |
| 376 | import { repoSourceRoutes } from "./api/repo_source.ts"; | |
| 376 | 377 | import { pullRoutes } from "./api/pulls.ts"; |
| 377 | 378 | import type { Router } from "./router.ts"; |
| 378 | 379 | import { clientAddress } from "./peer.ts"; |
| @@ -1654,6 +1655,7 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo | ||
| 1654 | 1655 | }); |
| 1655 | 1656 | |
| 1656 | 1657 | upstreamRoutes(router); |
| 1658 | repoSourceRoutes(router); | |
| 1657 | 1659 | |
| 1658 | 1660 | router.add("PATCH", "/api/v1/repos/:owner/:name", async (ctx) => { |
| 1659 | 1661 | const denied = requireScope(ctx, "admin"); |
src/http/api/repo_source.ts added +25
| @@ -0,0 +1,25 @@ | ||
| 1 | /** | |
| 2 | * `PUT /api/v1/repos/:owner/:name/source` with `{source}` (#16068): a pack's | |
| 3 | * deploy records where an app came from. The repository's admin only; the | |
| 4 | * address is judged by `sourceText` before anything is kept. | |
| 5 | */ | |
| 6 | ||
| 7 | import { canAdmin } from "../../core/repos.ts"; | |
| 8 | import { setRepoSource } from "../../core/repo_source.ts"; | |
| 9 | import { loadRepo } from "../api.ts"; | |
| 10 | import type { Handler } from "../context.ts"; | |
| 11 | import { apiError, body, json, notFound, requireScope, str } from "../respond.ts"; | |
| 12 | import type { Router } from "../router.ts"; | |
| 13 | ||
| 14 | export function repoSourceRoutes(router: Router<Handler>): void { | |
| 15 | router.add("PUT", "/api/v1/repos/:owner/:name/source", async (ctx) => { | |
| 16 | const denied = requireScope(ctx, "admin"); | |
| 17 | if (denied) return denied; | |
| 18 | const repo = loadRepo(ctx); | |
| 19 | if (!repo || !canAdmin(ctx.app.db, repo, ctx.auth.user)) return notFound(); | |
| 20 | const input = await body(ctx.request); | |
| 21 | const saved = setRepoSource(ctx.app.db, repo.id, str(input.source)); | |
| 22 | if (!saved.ok) return apiError("bad_source", 422, saved.error); | |
| 23 | return json({ source: saved.source }); | |
| 24 | }); | |
| 25 | } |
src/packs/deploy.ts +18
| @@ -24,6 +24,11 @@ export interface Hands { | ||
| 24 | 24 | follow(owner: string, name: string, source: string, branch: string | undefined): Promise<{ ok: true } | { ok: false; why: string }>; |
| 25 | 25 | /** Absorb the app as a feature, as the deploying admin. Refused when the app declares no feature: a repository cannot promote itself. */ |
| 26 | 26 | absorb(owner: string, name: string): Promise<{ ok: true } | { ok: false; why: string }>; |
| 27 | /** | |
| 28 | * Keep where the app came from, so its page and the terminal say so. Optional: a hand that cannot | |
| 29 | * is left out, not failed. | |
| 30 | */ | |
| 31 | recordSource?(owner: string, name: string, source: string): Promise<{ ok: true } | { ok: false; why: string }>; | |
| 27 | 32 | makeAgent(a: Pack["crew"][number]): Promise<{ ok: true } | { ok: false; exists: boolean; why: string }>; |
| 28 | 33 | } |
| 29 | 34 | |
| @@ -39,6 +44,16 @@ async function absorbStep(hands: Hands, owner: string, name: string): Promise<St | ||
| 39 | 44 | return r.ok ? { what: `absorb ${name}`, state: "done", note: "a feature in the menu" } : { what: `absorb ${name}`, state: "failed", note: r.why }; |
| 40 | 45 | } |
| 41 | 46 | |
| 47 | /** | |
| 48 | * The source is recorded after the app is made; only a refusal is a step, so it is reported and | |
| 49 | * never hides that the app is made. | |
| 50 | */ | |
| 51 | async function sourceStep(hands: Hands, owner: string, name: string, source: string): Promise<Step[]> { | |
| 52 | if (hands.recordSource === undefined) return []; | |
| 53 | const r = await hands.recordSource(owner, name, source); | |
| 54 | return r.ok ? [] : [{ what: `source ${name}`, state: "failed", note: r.why }]; | |
| 55 | } | |
| 56 | ||
| 42 | 57 | /** A forge-repo source is forked, not copied: the fork's lineage is the follow, so nothing is carried or followed over the network. */ |
| 43 | 58 | async function forkStep(hands: Hands, app: Pack["apps"][number]): Promise<Step[]> { |
| 44 | 59 | const forked = await hands.forkFrom(app.source, app.name); |
| @@ -47,6 +62,7 @@ async function forkStep(hands: Hands, app: Pack["apps"][number]): Promise<Step[] | ||
| 47 | 62 | return [{ what: `app ${app.name}`, state: "kept", note: "already here" }]; |
| 48 | 63 | } |
| 49 | 64 | const steps: Step[] = [{ what: `app ${app.name}`, state: "done", note: `forked from ${app.source}` }]; |
| 65 | steps.push(...(await sourceStep(hands, forked.owner, app.name, app.source))); | |
| 50 | 66 | if (app.absorb === true) steps.push(await absorbStep(hands, forked.owner, app.name)); |
| 51 | 67 | return steps; |
| 52 | 68 | } |
| @@ -78,6 +94,7 @@ export async function deployPack(pack: Pack, hands: Hands): Promise<readonly Ste | ||
| 78 | 94 | ? { what: `app ${app.name}`, state: "kept", note: "already here" } |
| 79 | 95 | : { what: `app ${app.name}`, state: "failed", note: `already here, not followed: ${followed.why}` }, |
| 80 | 96 | ); |
| 97 | steps.push(...(await sourceStep(hands, owner, app.name, app.source))); | |
| 81 | 98 | if (followed.ok && app.absorb === true) steps.push(await absorbStep(hands, owner, app.name)); |
| 82 | 99 | continue; |
| 83 | 100 | } |
| @@ -92,6 +109,7 @@ export async function deployPack(pack: Pack, hands: Hands): Promise<readonly Ste | ||
| 92 | 109 | ? { what: `app ${app.name}`, state: "done", note: `history from ${app.source}, following it` } |
| 93 | 110 | : { what: `app ${app.name}`, state: "failed", note: `history carried, not followed: ${followed.why}` }, |
| 94 | 111 | ); |
| 112 | steps.push(...(await sourceStep(hands, made.owner, app.name, app.source))); | |
| 95 | 113 | if (followed.ok && app.absorb === true) steps.push(await absorbStep(hands, made.owner, app.name)); |
| 96 | 114 | } |
| 97 | 115 | for (const member of pack.crew) { |
src/packs/source_guard.ts +25
| @@ -47,3 +47,28 @@ export async function guardSource( | ||
| 47 | 47 | return err(refusal(bare, vetted.error === "refused" ? "is, or resolves to, an internal address" : "could not be resolved")); |
| 48 | 48 | return ok(remoteGitEnv(base, pinFor(address, vetted.value))); |
| 49 | 49 | } |
| 50 | ||
| 51 | const SOURCE_FORGE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}\/[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/; | |
| 52 | ||
| 53 | /** | |
| 54 | * A source fit to keep and show (#16068): `owner/name` on a forge, or an http | |
| 55 | * or https address with a host and no credential, query or fragment. An | |
| 56 | * address carrying a user or password is refused, never stripped, so a secret | |
| 57 | * is not kept in a field that is drawn on a page. Whitespace or a control | |
| 58 | * character inside is refused (`URL.parse` would silently drop a tab or a | |
| 59 | * newline), and an address is kept as parsed, `url.href`, so what is stored is | |
| 60 | * exactly what was checked. | |
| 61 | */ | |
| 62 | export function sourceText(raw: string): Result<string, string> { | |
| 63 | const text = raw.trim(); | |
| 64 | if (text === "" || text.length > 300) return err("the source is an address or owner/name, at most 300 characters."); | |
| 65 | if (/[\s\p{Cc}]/u.test(text)) return err("the source is one address or owner/name, without spaces or control characters."); | |
| 66 | if (SOURCE_FORGE.test(text) && !text.split("/").some((s) => /^\.+$/.test(s))) return ok(text); | |
| 67 | const url = URL.parse(text); | |
| 68 | if (url === null || (url.protocol !== "https:" && url.protocol !== "http:") || url.hostname === "") | |
outdated
Medium. Return |
||
| 69 | return err("the source is an http(s) address or owner/name."); | |
| 70 | if (url.username !== "" || url.password !== "") return err("the source carries a credential, so the forge will not keep it."); | |
| 71 | if (url.search !== "" || url.hash !== "" || url.href.includes("?") || url.href.includes("#")) | |
| 72 | return err("the source is an address without a query or fragment."); | |
| 73 | return ok(url.href); | |
| 74 | } |
src/tui/screens/about.ts +10
| @@ -61,6 +61,7 @@ import { | ||
| 61 | 61 | upstreamLabel, |
| 62 | 62 | } from "../../actions/upstream_follow.ts"; |
| 63 | 63 | import { getFollow, listChecks } from "../../core/upstream_follow.ts"; |
| 64 | import { repoSource } from "../../core/repo_source.ts"; | |
| 64 | 65 | import { |
| 65 | 66 | getProvenance, |
| 66 | 67 | shownTrail, |
| @@ -155,6 +156,7 @@ export function aboutScreen( | ||
| 155 | 156 | ...aboutFacts(f, src, facts, ref, repo), |
| 156 | 157 | ...paceRows(f, repo), |
| 157 | 158 | ...trailRows(f, repo), |
| 159 | ...sourceRows(f, repo), | |
| 158 | 160 | ...upstreamRows(f, repo), |
| 159 | 161 | ...behindRows(f, repo), |
| 160 | 162 | ...offerRows(offered), |
| @@ -747,6 +749,14 @@ export function trailRows( | ||
| 747 | 749 | ]; |
| 748 | 750 | } |
| 749 | 751 | |
| 752 | /** | |
| 753 | * "From <source>" for an app a pack made (#16068), the web header's words; nothing for any other. | |
| 754 | */ | |
| 755 | export function sourceRows(f: Pick<Session, "db">, repo: Repo | undefined): [string, string][] { | |
| 756 | const kept = repo === undefined ? undefined : repoSource(repo); | |
| 757 | return kept === undefined ? [] : [["from", kept.source]]; | |
| 758 | } | |
| 759 | ||
| 750 | 760 | /** |
| 751 | 761 | * How long an app's golden path took, in the apps page's words (#7488): |
| 752 | 762 | * nothing on a repository that is not an app, or before either figure exists. |
src/web/chrome.ts +14
| @@ -20,6 +20,7 @@ import { | ||
| 20 | 20 | } from "../core/repos.ts"; |
| 21 | 21 | import { nearRepos as nearTo } from "../core/near_repos.ts"; |
| 22 | 22 | import { type Repo, visibleForks } from "../core/repos.ts"; |
| 23 | import { repoSource } from "../core/repo_source.ts"; | |
| 23 | 24 | import { parentUrl, shownTrail, sourceLabel } from "../core/provenance.ts"; |
| 24 | 25 | import type { App } from "../app.ts"; |
| 25 | 26 | import type { Ctx } from "../http/context.ts"; |
| @@ -333,6 +334,7 @@ export function scopeHeader( | ||
| 333 | 334 | () => html`<p class="muted small">${facts.description}</p>`, |
| 334 | 335 | )} |
| 335 | 336 | ${repo === undefined ? null : lineageLine(ctx.app, repo, parent, family, parent !== undefined && canAdmin(ctx.app.db, repo, ctx.auth.user) ? `${base}/settings#follow-choice` : undefined)} |
| 337 | ${repo === undefined ? null : sourceLine(repo)} | |
| 336 | 338 | ${when( |
| 337 | 339 | scope.upstream !== undefined && upstreamHref(scope) === undefined, |
| 338 | 340 | // The where strip carries "fork of octo/widgets" and links it, which |
| @@ -417,6 +419,18 @@ export function lineageLine( | ||
| 417 | 419 | </p>`; |
| 418 | 420 | } |
| 419 | 421 | |
| 422 | /** | |
| 423 | * The one muted "From <source>" line of an app a pack made (#16068); nothing for any other. | |
| 424 | * Read off the repository row already in hand, so no repository page pays a statement for it. | |
outdated
Medium. This reads the database on every repo header, which is why two query budgets had to rise. Fold it into an existing read or skip it unless the repo is an app. Principle 8 / the direction's speed bar. |
||
| 425 | */ | |
| 426 | function sourceLine(repo: Repo): Html | null { | |
| 427 | const kept = repoSource(repo); | |
outdated
Principle 8 and the docs: the link has |
||
| 428 | if (kept === undefined) return null; | |
| 429 | const external = kept.href.includes("://"); | |
| 430 | return html`<p class="muted small break" data-pack-source>From | |
| 431 | <a href="${kept.href}"${external ? html` rel="noopener noreferrer"` : html``}>${kept.source}</a></p>`; | |
| 432 | } | |
| 433 | ||
| 420 | 434 | /** |
| 421 | 435 | * How a fork follows its parent, in the one plain sentence every door says (`followLineWords`, |
| 422 | 436 | * #15767), linked to the setting for whoever may change it, then how far behind it is when the |
test/packs-hands.test.ts +1
| @@ -354,6 +354,7 @@ describe("forge-repo sources", () => { | ||
| 354 | 354 | ]); |
| 355 | 355 | expect(posts).toEqual([ |
| 356 | 356 | 'POST /api/v1/repos/trevato/radar/forks {"name":"radar"}', |
| 357 | 'PUT /api/v1/repos/me/radar/source {"source":"trevato/radar"}', | |
| 357 | 358 | 'POST /api/v1/repos/trevato/notes/forks {"name":"notes"}', |
| 358 | 359 | "GET /api/v1/user ", |
| 359 | 360 | ]); |
test/packs-source-link.test.ts added +111
| @@ -0,0 +1,111 @@ | ||
| 1 | /** | |
| 2 | * Each app a pack deploys says where it came from: a muted "From <source>" line on its page and in | |
| 3 | * the terminal (#16068). | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, describe, 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 { getRepo } from "../src/core/repos.ts"; | |
| 11 | import { repoSource } from "../src/core/repo_source.ts"; | |
| 12 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 13 | import { deployPack } from "../src/packs/deploy.ts"; | |
| 14 | import { sourceText } from "../src/packs/source_guard.ts"; | |
| 15 | import { OWNER, prepareOwner } from "../src/packs/up.ts"; | |
| 16 | import { sourceRows } from "../src/tui/screens/about.ts"; | |
| 17 | import { realHands } from "../scripts/pack.ts"; | |
| 18 | import { quietLogs } from "./helpers/globals.ts"; | |
| 19 | import { fixturePacks } from "./helpers/packs.ts"; | |
| 20 | import { git } from "./helpers/plain-git.ts"; | |
| 21 | ||
| 22 | quietLogs(); | |
| 23 | ||
| 24 | let root: string; | |
| 25 | let app: App; | |
| 26 | let servers: Servers; | |
| 27 | let token: string; | |
| 28 | const fake = new Map<string, string>(); | |
| 29 | const pack = fixturePacks()[0]!; | |
| 30 | const PUBLIC = { resolve: async () => ["93.184.216.34"] }; | |
| 31 | ||
| 32 | beforeAll(async () => { | |
| 33 | root = await mkdtemp(join(tmpdir(), "packs-source-")); | |
| 34 | const dataDir = join(root, "data"); | |
| 35 | token = (await prepareOwner(dataDir)).token; | |
| 36 | let n = 0; | |
| 37 | for (const a of pack.apps) { | |
| 38 | const dir = join(root, `src-${n++}`); | |
| 39 | git(root, "init", "-q", "-b", "main", dir); | |
| 40 | await Bun.write(join(dir, "f.txt"), `${a.name}\n`); | |
| 41 | git(dir, "add", "."); | |
| 42 | git(dir, "commit", "-q", "-m", "one"); | |
| 43 | fake.set(a.source, dir); | |
| 44 | } | |
| 45 | app = createApp({ dataDir, port: 0 }); | |
| 46 | servers = await serve(app); | |
| 47 | }); | |
| 48 | afterAll(async () => { | |
| 49 | await servers.stop(); | |
| 50 | app.close(); | |
| 51 | await rm(root, { recursive: true, force: true }); | |
| 52 | }); | |
| 53 | ||
| 54 | describe("the source of a deployed app", () => { | |
| 55 | test("every app records its source, the page says From <source> and the terminal the same", async () => { | |
| 56 | const steps = await deployPack({ ...pack, crew: [] }, realHands(servers.url, token, { cloneFrom: (s) => fake.get(s)!, guard: PUBLIC })); | |
| 57 | expect(steps.filter((s) => s.state !== "done")).toEqual([]); | |
| 58 | for (const a of pack.apps) { | |
| 59 | const repo = getRepo(app.db, OWNER, a.name)!; | |
| 60 | expect(repoSource(repo)?.source).toBe(a.source); | |
| 61 | const page = await (await fetch(`${servers.url}/${OWNER}/${a.name}`)).text(); | |
| 62 | expect(page).toMatch(new RegExp(`data-pack-source>From\\s+<a href="${a.source.replace(/[.]/g, "\\.")}" rel="noopener noreferrer">${a.source.replace(/[.]/g, "\\.")}</a>`)); | |
| 63 | expect(sourceRows({ db: app.db }, repo)).toEqual([["from", a.source]]); | |
| 64 | } | |
| 65 | }); | |
| 66 | ||
| 67 | test("an app with no recorded source says nothing", async () => { | |
| 68 | const res = await fetch(`${servers.url}/api/v1/apps`, { | |
| 69 | method: "POST", | |
| 70 | headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, | |
| 71 | body: JSON.stringify({ name: "plain-app", visibility: "public" }), | |
| 72 | }); | |
| 73 | expect(res.ok).toBe(true); | |
| 74 | const repo = getRepo(app.db, OWNER, "plain-app")!; | |
| 75 | expect(sourceRows({ db: app.db }, repo)).toEqual([]); | |
| 76 | expect(await (await fetch(`${servers.url}/${OWNER}/plain-app`)).text()).not.toContain("data-pack-source"); | |
| 77 | }); | |
| 78 | ||
| 79 | test("the source is held to the boundary: a credential, a script or a query is refused, and the page escapes what it keeps", async () => { | |
| 80 | for (const bad of ["https://u:[email protected]/x", "javascript:alert(1)", "ftp://example.com/x", "https://example.com/x?token=1", "a/b/c", "", "x".repeat(400)]) | |
| 81 | expect(sourceText(bad).ok).toBe(false); | |
| 82 | for (const good of ["https://example.com/x/y", "packs/2048"]) expect(sourceText(good).ok).toBe(true); | |
| 83 | // URL.parse drops a tab or newline inside an address; the check refuses it, so the kept value | |
| 84 | // is the checked one. | |
| 85 | for (const hidden of ["https://exa\nmple.com/x", "https://example.com/a\tb", "https://example.com/a b", "packs/20\u000048", "https://example.com/x?"]) | |
| 86 | expect(sourceText(hidden).ok).toBe(false); | |
| 87 | expect(sourceText("https://EXAMPLE.com/x/../y")).toEqual({ ok: true, value: "https://example.com/y" }); | |
| 88 | const put = (source: string) => | |
| 89 | fetch(`${servers.url}/api/v1/repos/${OWNER}/plain-app/source`, { | |
| 90 | method: "PUT", | |
| 91 | headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, | |
| 92 | body: JSON.stringify({ source }), | |
| 93 | }); | |
| 94 | expect((await put("https://user:[email protected]/x")).status).toBe(422); | |
| 95 | expect((await put("https://example.com/a\"><b>")).status).toBe(200); | |
| 96 | const page = await (await fetch(`${servers.url}/${OWNER}/plain-app`)).text(); | |
| 97 | expect(page).not.toContain("<b>"); | |
| 98 | expect(page).not.toContain("secret"); | |
| 99 | }); | |
| 100 | ||
| 101 | test("a forge source links to its page on this forge", async () => { | |
| 102 | const res = await fetch(`${servers.url}/api/v1/repos/${OWNER}/plain-app/source`, { | |
| 103 | method: "PUT", | |
| 104 | headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, | |
| 105 | body: JSON.stringify({ source: "packs/2048" }), | |
| 106 | }); | |
| 107 | expect(res.status).toBe(200); | |
| 108 | expect(repoSource(getRepo(app.db, OWNER, "plain-app")!)).toEqual({ source: "packs/2048", href: "/packs/2048" }); | |
| 109 | expect(await (await fetch(`${servers.url}/${OWNER}/plain-app`)).text()).toMatch(/data-pack-source>From\s+<a href="\/packs\/2048">packs\/2048<\/a>/); | |
| 110 | }); | |
| 111 | }); |
Says an address 'opens in a new context'; the anchor does not set a target. Fix the sentence or the anchor.