Public: anyone can read this; the crew can change it.
Bringing an app from another forge brings how it runs, so the origin card stops saying "how the app runs (not yet)" #16090
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16070-bringing-an-app-from-another-forge-bring → main 0 commits fork 5 threads · 5 unresolved
17 files
changed +275
−11
docs/features/forge-origin.md +2 −2
| @@ -9,7 +9,7 @@ Connect another forge at `/settings/origins`: type its address and press "Sign i | ||
| 9 | 9 | |
| 10 | 10 | - **Picker:** `GET /api/v1/user/repos` lists the token's account's repositories, private ones included, in the Gitea shape. Only that route speaks the Gitea shape; a repository's own JSON is unchanged. |
| 11 | 11 | - **Credential:** the token travels as `Authorization: Bearer …` for the API, the one scheme every release of a forge reads (read in any case, `bearer` too, as RFC 7235 says, #14778) (one older than `/api/v1/version` answers `token …` with 401), and as Basic through `GIT_CONFIG_*` for git — never argv, never config. |
| 12 | - **Mirror:** brings the code and its history, and the issues, pulls, comments and labels, read in the forge's own JSON (`src/origins/providers/forge-work.ts`) with the real author kept. A bring whose first fetch failed is finished by asking again. The origin's card and `GET /api/v1/user/origins` (`carries`) say what did not come: how the app runs (not yet), and its data and secrets (never by default). | |
| 12 | - **Mirror:** brings the code and its history, and the issues, pulls, comments and labels, read in the forge's own JSON (`src/origins/providers/forge-work.ts`) with the real author kept. A bring whose first fetch failed is finished by asking again. The origin's card and `GET /api/v1/user/origins` (`carries`) say what came and what did not: how the app runs comes when the brought repository has a valid `forge.json` at its head (judged by the same manifest check a push gets), and then it is an app here, private and asleep until its owner starts it (`src/origins/carry_run.ts`); otherwise no app is made and the card says why (no forge.json, or one that does not validate). The words are kept on the origin (`run_note`) from its last bring. Its data and secrets never come by default, and are never asked of the other forge. Test: `test/forge-origin-run.test.ts`. | |
| 13 | 13 | - **Write-through:** a comment, an issue or a state change here goes to the other forge first, with the connecting person's token (`rw` needed), and is refused with nothing changed here when the forge is down or says no. A pull is opened there with `createPull` (the contribute path); its merge comes back with the next sync. |
| 14 | 14 | |
| 15 | 15 | Measured against an older forge and itself, in containers: [](forge-origin-compat.md), `scripts/forge-compat-lab.sh`. |
| @@ -24,7 +24,7 @@ Type the friend's address at `/settings/origins` and press "Sign in there". If t | ||
| 24 | 24 | |
| 25 | 25 | Not yet: review and check state coming back live, guest rules for a crew on the receiving side, following upstream with one action. |
| 26 | 26 | |
| 27 | Not yet, in order: migrate an app whole with its run and build, follow upstream between forges with a pull back, and the one-page paste-a-link path. Test: `test/forge-origin.test.ts` runs two forges against each other. | |
| 27 | Not yet, in order: follow upstream between forges with a pull back, and the one-page paste-a-link path. Test: `test/forge-origin.test.ts` runs two forges against each other. | |
| 28 | 28 | |
| 29 | 29 | ## Issues and comments both ways (#8967) |
| 30 | 30 |
src/actions/bring.ts +1 −1
| @@ -66,7 +66,7 @@ export interface Brought { | ||
| 66 | 66 | readonly needs: readonly { readonly name: string; readonly set: boolean }[]; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | function freeSlug(app: App, name: string, owner: string): string { | |
| 69 | export function freeSlug(app: App, name: string, owner: string): string { | |
| 70 | 70 | const base = slugFor(`${name}-${owner}`).slice(0, SLUG_MAX - 3).replace(/-+$/, ""); |
| 71 | 71 | for (let n = 1; n < 100; n++) { |
| 72 | 72 | const candidate = n === 1 ? base : `${base}-${n}`; |
src/core/migration-pins/20261123130000-origin-run-note.pin added +1
| @@ -0,0 +1,1 @@ | ||
| 1 | 8dc7c3343d8e83bfe6ea11c2d966f68c425d5d0ffebf8d1178ad805f196506a1 |
src/core/migrations/20261123130000-origin-run-note.ts added +5
| @@ -0,0 +1,5 @@ | ||
| 1 | // What the last bring from a forge did with how the app runs (#16070): the words, as the origin's | |
| 2 | // card and `carries` say them. Empty before any bring. | |
| 3 | export default ` | |
| 4 | ALTER TABLE origin ADD COLUMN run_note TEXT NOT NULL DEFAULT ''; | |
| 5 | `; |
src/core/origins.ts +7
| @@ -37,6 +37,7 @@ interface OriginRow { | ||
| 37 | 37 | needs_reauth: number; |
| 38 | 38 | software: string; |
| 39 | 39 | read_only: number; |
| 40 | run_note: string; | |
| 40 | 41 | } |
| 41 | 42 | |
| 42 | 43 | function toOrigin(row: OriginRow): Origin { |
| @@ -55,9 +56,15 @@ function toOrigin(row: OriginRow): Origin { | ||
| 55 | 56 | needsReauth: row.needs_reauth === 1, |
| 56 | 57 | software: row.software, |
| 57 | 58 | readOnly: row.read_only === 1, |
| 59 | runNote: row.run_note, | |
| 58 | 60 | }; |
| 59 | 61 | } |
| 60 | 62 | |
| 63 | /** Remember what the last bring did with how the app runs, in words. */ | |
| 64 | export function setRunNote(db: Database, originId: string, note: string): void { | |
| 65 | db.query("UPDATE origin SET run_note = ?2 WHERE id = ?1").run(originId, note); | |
| 66 | } | |
| 67 | ||
| 61 | 68 | export interface CreateOriginInput { |
| 62 | 69 | userId: string; |
| 63 | 70 | kind: OriginKind; |
src/http/api.ts +2 −2
| @@ -346,7 +346,7 @@ import { flagsRoutes } from "./api/flags.ts"; | ||
| 346 | 346 | import { appTemplateRoutes } from "./api/app_templates.ts"; |
| 347 | 347 | import { issueRoutes, labelsHandler } from "./api/issues.ts"; |
| 348 | 348 | import { chapterRoutes } from "./api/chapters.ts"; |
| 349 | import { FORGE_NOT_CARRIED } from "../origins/words.ts"; | |
| 349 | import { forgeCarries } from "../origins/words.ts"; | |
| 350 | 350 | import { forgeOriginRoutes } from "./api/forge_origin.ts"; |
| 351 | 351 | import { userRoutes } from "./api/user.ts"; |
| 352 | 352 | import { appRoutes } from "./api/app.ts"; |
| @@ -588,7 +588,7 @@ export function originJson(origin: Origin) { | ||
| 588 | 588 | expiresAt: origin.expiresAt, |
| 589 | 589 | software: origin.software, |
| 590 | 590 | // What a forge origin does not bring, said where a client reads the origin. |
| 591 | carries: origin.software === "forge" ? FORGE_NOT_CARRIED : null, | |
| 591 | carries: origin.software === "forge" ? forgeCarries(origin.runNote) : null, | |
| 592 | 592 | }; |
| 593 | 593 | } |
| 594 | 594 |
src/origins/bring.ts +21
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * it ships. Nothing here touches the network, the database or a value. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { parseManifest } from "../apps/manifest.ts"; | |
| 8 | 9 | import type { Origin } from "./types.ts"; |
| 9 | 10 | |
| 10 | 11 | export interface BringLink { |
| @@ -90,3 +91,23 @@ export function connectSite( | ||
| 90 | 91 | } |
| 91 | 92 | return { ok: true, value: `https://${host}` }; |
| 92 | 93 | } |
| 94 | ||
| 95 | /** The longest reason a bring keeps about a forge.json that did not validate. */ | |
| 96 | const WHY_MAX = 200; | |
| 97 | ||
| 98 | /** | |
| 99 | * Whether a brought repository's `forge.json` (the text at its head, or | |
| 100 | * undefined when it has none) says how it runs. A file from elsewhere is | |
| 101 | * untrusted: it is judged by the same manifest check a push gets, and its | |
| 102 | * refusal is kept in words, clamped. | |
| 103 | */ | |
| 104 | export function runOfBrought(forgeJson: string | undefined): { ok: true } | { ok: false; why: string } { | |
| 105 | if (forgeJson === undefined) return { ok: false, why: "it has no forge.json" }; | |
| 106 | const parsed = parseManifest(forgeJson, undefined); | |
| 107 | if (parsed.ok) return { ok: true }; | |
| 108 | const why = | |
| 109 | parsed.error.kind === "not_an_app" | |
| 110 | ? "its forge.json does not declare an app" | |
| 111 | : `its forge.json is not valid (${parsed.error.message.replace(/[\p{Cc}\p{Cf}\s]+/gu, " ").slice(0, WHY_MAX)})`; | |
| 112 | return { ok: false, why }; | |
| 113 | } |
src/origins/carry_run.ts added +49
| @@ -0,0 +1,49 @@ | ||
| 1 | /** | |
| 2 | * Carry how the app runs (#16070). After a bring from another forge lands | |
| 3 | * whole, a repository whose head holds a valid `forge.json` becomes an app | |
| 4 | * here, as a pushed new app does: private and asleep until its owner starts | |
| 5 | * it. Otherwise nothing is made and the reason is kept. Either way the words | |
| 6 | * land on the origin, for its card and `carries`. Data and secrets are never | |
| 7 | * asked of the other forge: this reads one file of the repository already here. | |
| 8 | */ | |
| 9 | ||
| 10 | import { enableApp } from "../actions/apps.ts"; | |
| 11 | import { appLimitWords } from "../actions/app_limit.ts"; | |
| 12 | import { freeSlug } from "../actions/bring.ts"; | |
| 13 | import { readFileAt } from "../apps/checkout.ts"; | |
| 14 | import type { App } from "../app.ts"; | |
| 15 | import { getAppByRepo } from "../core/apps.ts"; | |
| 16 | import { setRunNote } from "../core/origins.ts"; | |
| 17 | import type { Repo } from "../core/repos.ts"; | |
| 18 | import type { User } from "../core/users.ts"; | |
| 19 | import { resolveOid } from "../git/merge.ts"; | |
| 20 | import { repoDir } from "../git/repos.ts"; | |
| 21 | import { runOfBrought } from "./bring.ts"; | |
| 22 | import type { Origin } from "./types.ts"; | |
| 23 | ||
| 24 | /** The most of a forge.json worth reading: a manifest is small. */ | |
| 25 | const FORGE_JSON_MAX = 65_536; | |
| 26 | ||
| 27 | export async function carryRun(app: App, actor: User, origin: Origin, repo: Repo): Promise<string> { | |
| 28 | const note = await judge(app, actor, repo); | |
| 29 | const words = `${repo.ownerName}/${repo.name} ${note}`; | |
| 30 | setRunNote(app.db, origin.id, words); | |
MED: the note is stored per origin, so each bring overwrites the previous repository's outcome. |
||
| 31 | return words; | |
| 32 | } | |
| 33 | ||
| 34 | async function judge(app: App, actor: User, repo: Repo): Promise<string> { | |
| 35 | const dir = repoDir(app.reposRoot, repo.ownerName, repo.name); | |
| 36 | const tip = await resolveOid(dir, `refs/heads/${repo.defaultBranch}`); | |
| 37 | if (!tip) return "was not carried: it has no commits"; | |
| 38 | const run = runOfBrought(await readFileAt(dir, tip, "forge.json", FORGE_JSON_MAX)); | |
| 39 | if (!run.ok) return `was not carried: ${run.why}`; | |
| 40 | if (getAppByRepo(app.db, repo.id) !== undefined) | |
| 41 | return "was carried: its forge.json is valid and it is already an app here"; | |
| 42 | const enabled = enableApp(app, actor, repo, { | |
| 43 | slug: freeSlug(app, repo.name, actor.username), | |
| 44 | access: "private", | |
| 45 | }); | |
| 46 | if (!enabled.ok) | |
| 47 | return `was not carried: ${enabled.error === "app_limit" ? appLimitWords(app, actor.id) : `the app could not be registered (${enabled.error})`}`; | |
| 48 | return "was carried: its forge.json is valid, so it is an app here, private and asleep until you start it"; | |
| 49 | } |
src/origins/mirror.ts +10
| @@ -31,6 +31,7 @@ import { repositoryLimitMessage, repositoryLimitRefusal } from "../actions/repos | ||
| 31 | 31 | import { redact, safeRemoteUrl } from "./credentials.ts"; |
| 32 | 32 | import { adoptDefaultBranch, configureMirror } from "./git-mirror.ts"; |
| 33 | 33 | import { advance, createJob, runningJob, type MirrorJob } from "./jobs.ts"; |
| 34 | import { carryRun } from "./carry_run.ts"; | |
| 34 | 35 | import { syncOrigin } from "./sync.ts"; |
| 35 | 36 | import type { RemoteRepo } from "./types.ts"; |
| 36 | 37 | |
| @@ -283,6 +284,15 @@ export function startMirror( | ||
| 283 | 284 | }); |
| 284 | 285 | return; |
| 285 | 286 | } |
| 287 | // How the app runs comes with a forge's own forge.json, never from a | |
| 288 | // plain git host's. | |
| 289 | if (origin.software === "forge") { | |
| 290 | try { | |
outdated
MED: an exception from carryRun is not handled here; guard it so a bring that landed does not fail on the run note. |
||
| 291 | await carryRun(app, actor, origin, result.value.repo); | |
| 292 | } catch { | |
| 293 | // The bring landed; only the note about how it runs is lost. | |
| 294 | } | |
| 295 | } | |
| 286 | 296 | advance(job.id, { |
| 287 | 297 | stage: "done", |
| 288 | 298 | detail: `mirrored as ${result.value.repo.ownerName}/${result.value.repo.name}`, |
src/origins/types.ts +2
| @@ -49,6 +49,8 @@ export interface Origin { | ||
| 49 | 49 | readonly software: string; |
| 50 | 50 | /** Connected read-only: nothing is ever written through it (`origin_read_only`). */ |
| 51 | 51 | readonly readOnly: boolean; |
| 52 | /** What the last bring from this origin did with how the app runs, in words; "" before one. */ | |
| 53 | readonly runNote: string; | |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | 56 | /** A repository as the origin describes it — the import picker's rows. */ |
src/origins/words.ts +11 −1
| @@ -24,7 +24,17 @@ export const PATH_IS_DIRECTORY = "that path is a directory, not a file"; | ||
| 24 | 24 | * and in the API, so a mirror of a friend's app never reads as the whole of it. |
| 25 | 25 | */ |
| 26 | 26 | export const FORGE_NOT_CARRIED = |
| 27 | "Code comes across, and the repository's history. Issues, pulls, comments and labels come too, and issues, pulls and comments write through. Not yet: how the app runs. Never by default: its data and its secrets."; | |
| 27 | "Code comes across, and the repository's history. Issues, pulls, comments and labels come too, and issues, pulls and comments write through. How the app runs comes when the repository has a valid forge.json. Never by default: its data and its secrets."; | |
| 28 | ||
| 29 | /** FORGE_NOT_CARRIED, and what the last bring did with how the app runs. */ | |
| 30 | export function forgeCarries(runNote: string): string { | |
| 31 | return runNote === "" | |
| 32 | ? FORGE_NOT_CARRIED | |
| 33 | : FORGE_NOT_CARRIED.replace( | |
outdated
Principle 1 and 8: the card says how the app runs twice (comes when valid forge.json, and last bring: ...). Say it once. |
||
| 34 | "How the app runs comes when the repository has a valid forge.json.", | |
| 35 | `How the app runs, from the last bring: ${runNote}.`, | |
| 36 | ); | |
| 37 | } | |
| 28 | 38 | |
| 29 | 39 | /** |
| 30 | 40 | * Signing in to another forge by OAuth needs a browser to approve in, and a |
src/tui/screens/connections.ts +2 −2
| @@ -8,7 +8,7 @@ import { connectOrigin, checkOriginAgain, connectRefusal, disconnectOrigin, list | ||
| 8 | 8 | import { CHECK_TOO_SOON, CHECK_WORDS, DISCONNECT_DETAIL, NO_SUCH_ORIGIN, connectWords, disconnectedWords, syncedWords } from "../../actions/origin_words.ts"; |
| 9 | 9 | import { mirrorsByOrigin } from "../../core/origins.ts"; |
| 10 | 10 | import { writesPaused } from "../../origins/credential.ts"; |
| 11 | import { FORGE_NOT_CARRIED, FORGE_SIGN_IN_ON_PAGE } from "../../origins/words.ts"; | |
| 11 | import { forgeCarries, FORGE_SIGN_IN_ON_PAGE } from "../../origins/words.ts"; | |
| 12 | 12 | import type { Ctx, Screen } from "../app/app.ts"; |
| 13 | 13 | import { binding } from "../app/keys.ts"; |
| 14 | 14 | import { style } from "../term/style.ts"; |
| @@ -38,7 +38,7 @@ export function connectionsScreen(f: Session, ctx: Ctx): Screen { | ||
| 38 | 38 | const pausedNote = picked !== undefined && writesPaused(f.app, picked.id) !== undefined; |
| 39 | 39 | const text = |
| 40 | 40 | picked?.software === "forge" |
| 41 | ? `Another forge. ${FORGE_NOT_CARRIED}` | |
| 41 | ? `Another forge. ${forgeCarries(picked.runNote)}` | |
| 42 | 42 | : pausedNote |
| 43 | 43 | ? "Couldn't verify this connection; writes paused. Reading and syncing go on. Press v to check again." |
| 44 | 44 | : all.length === 0 |
src/web/pages/origins.ts +2 −2
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | import { sshOn } from "../../settings/ssh.ts"; |
| 21 | 21 | import type { Database } from "bun:sqlite"; |
| 22 | 22 | import { upstreamBlob } from "../../core/upstream.ts"; |
| 23 | import { FORGE_NOT_CARRIED } from "../../origins/words.ts"; | |
| 23 | import { forgeCarries } from "../../origins/words.ts"; | |
| 24 | 24 | import { |
| 25 | 25 | checkOriginAgain, |
| 26 | 26 | connectOrigin, |
| @@ -337,7 +337,7 @@ function originCard(origin: Origin, mirrors: number, paused = false): Html { | ||
| 337 | 337 | ${when(origin.needsReauth, () => reauthNote(origin, mirrors))} |
| 338 | 338 | ${when( |
| 339 | 339 | origin.software === "forge", |
| 340 | () => html`<p class="small mt">Another forge. ${FORGE_NOT_CARRIED}</p>`, | |
| 340 | () => html`<p class="small mt">Another forge. ${forgeCarries(origin.runNote)}</p>`, | |
| 341 | 341 | )} |
| 342 | 342 | ${when(paused, () => pausedNote(origin))} |
| 343 | 343 | <div class="bar mt"> |
test/forge-origin-run.test.ts added +154
| @@ -0,0 +1,154 @@ | ||
| 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 2 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { createApp, type App } from "../src/app.ts"; | |
| 6 | import { getAppByRepo } from "../src/core/apps.ts"; | |
| 7 | import { listOrigins } from "../src/core/origins.ts"; | |
| 8 | import { createToken } from "../src/core/tokens.ts"; | |
| 9 | import { getRepo } from "../src/core/repos.ts"; | |
| 10 | import { getUserByName } from "../src/core/users.ts"; | |
| 11 | import { originJson } from "../src/http/api.ts"; | |
| 12 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 13 | import { runOfBrought } from "../src/origins/bring.ts"; | |
| 14 | import { settled } from "../src/origins/jobs.ts"; | |
| 15 | import { startMirror } from "../src/origins/mirror.ts"; | |
| 16 | import { syncsSettled } from "../src/origins/sync.ts"; | |
| 17 | import { forgeCarries } from "../src/origins/words.ts"; | |
| 18 | import { proveAll } from "./helpers/verified.ts"; | |
| 19 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 20 | ||
| 21 | ||
| 22 | const LOGIN = "octo"; | |
| 23 | const TOKEN = "octo-secret-7089"; | |
| 24 | const PASSWORD = "alice-secret-7089"; | |
| 25 | const basic = (user: string, secret: string): string => | |
| 26 | `Basic ${Buffer.from(`${user}:${secret}`).toString("base64")}`; | |
| 27 | ||
| 28 | describe("what a forge.json from elsewhere says", () => { | |
| 29 | test("valid, absent, empty of an app, and broken are told apart in words", () => { | |
| 30 | expect(runOfBrought('{"app":{"run":"bun run index.ts"}}')).toEqual({ ok: true }); | |
| 31 | expect(runOfBrought(undefined)).toEqual({ ok: false, why: "it has no forge.json" }); | |
| 32 | expect(runOfBrought("{}")).toEqual({ ok: false, why: "its forge.json does not declare an app" }); | |
| 33 | const broken = runOfBrought("{nope"); | |
| 34 | expect(broken.ok).toBe(false); | |
| 35 | expect(!broken.ok && broken.why).toContain("its forge.json is not valid"); | |
| 36 | }); | |
| 37 | ||
| 38 | test("the words never claim the run is carried before a bring says so", () => { | |
| 39 | expect(forgeCarries("")).not.toContain("last bring"); | |
| 40 | expect(forgeCarries("a/b was carried")).toContain("How the app runs, from the last bring: a/b was carried."); | |
| 41 | expect(forgeCarries("")).toContain("its data and its secrets"); | |
| 42 | }); | |
| 43 | }); | |
| 44 | ||
| 45 | describe("bringing a repository from another forge brings how it runs", () => { | |
| 46 | let dirs: string[] = []; | |
| 47 | let app: App; | |
| 48 | let gitApp: App; | |
| 49 | let servers: Servers; | |
| 50 | let gitServers: Servers; | |
| 51 | let friendToken = ""; | |
| 52 | ||
| 53 | const put = async (repo: string, files: { path: string; content: string }[]) => { | |
| 54 | const auth = { "content-type": "application/json", authorization: basic(LOGIN, TOKEN) }; | |
| 55 | await fetch(`${gitServers.url}/api/v1/repos`, { | |
| 56 | method: "POST", | |
| 57 | headers: auth, | |
| 58 | body: JSON.stringify({ name: repo, visibility: "public" }), | |
| 59 | }); | |
| 60 | const made = await fetch(`${gitServers.url}/api/v1/repos/octo/${repo}/contents`, { | |
| 61 | method: "POST", | |
| 62 | headers: auth, | |
| 63 | body: JSON.stringify({ branch: "main", message: "start", files }), | |
| 64 | }); | |
| 65 | expect(made.status).toBeLessThan(300); | |
| 66 | }; | |
| 67 | ||
| 68 | beforeAll(async () => { | |
| 69 | dirs = [await mkdtemp(join(tmpdir(), "forge-run-")), await mkdtemp(join(tmpdir(), "forge-run-git-"))]; | |
| 70 | gitApp = createApp({ dataDir: dirs[1]!, port: 0 }); | |
| 71 | gitServers = await serve(gitApp); | |
| 72 | await seedAdmin(gitApp, { username: LOGIN, email: "[email protected]", password: TOKEN }); | |
| 73 | proveAll(gitApp); | |
| 74 | await put("runs", [ | |
| 75 | { path: "forge.json", content: '{"app":{"run":"bun run index.ts"}}\n' }, | |
| 76 | { path: ".env", content: "API_KEY=real-secret\n" }, | |
| 77 | ]); | |
| 78 | await put("plain", [{ path: "README.md", content: "just code\n" }]); | |
| 79 | await put("broken", [{ path: "forge.json", content: "{not json" }]); | |
| 80 | ||
| 81 | friendToken = createToken(gitApp.db, getUserByName(gitApp.db, LOGIN)!.id, "alice", "rw").token; | |
| 82 | app = createApp({ dataDir: dirs[0]!, port: 0 }); | |
| 83 | servers = await serve(app); | |
| 84 | await seedAdmin(app, { username: "alice", email: "[email protected]", password: PASSWORD }); | |
| 85 | proveAll(app); | |
| 86 | }); | |
| 87 | ||
| 88 | afterAll(async () => { | |
| 89 | await syncsSettled(); | |
| 90 | servers.stop(); | |
| 91 | gitServers.stop(); | |
| 92 | app.close(); | |
| 93 | gitApp.close(); | |
| 94 | for (const d of dirs) await rm(d, { recursive: true, force: true, maxRetries: 5 }); | |
| 95 | }); | |
| 96 | ||
| 97 | test("a valid forge.json makes the app, private and asleep; the card and carries say so; secrets stay out", async () => { | |
| 98 | const alice = getUserByName(app.db, "alice")!; | |
| 99 | const connected = await fetch(`${servers.url}/api/v1/user/origins`, { | |
| 100 | method: "POST", | |
| 101 | headers: { authorization: basic("alice", PASSWORD), "content-type": "application/json" }, | |
| 102 | body: JSON.stringify({ host: gitServers.url, token: friendToken }), | |
| 103 | }); | |
| 104 | expect(connected.status).toBe(201); | |
| 105 | const origin = listOrigins(app.db, alice.id)[0]!; | |
| 106 | expect(origin.software).toBe("forge"); | |
| 107 | expect(origin.runNote).toBe(""); | |
| 108 | expect(originJson(origin).carries).not.toContain("last bring"); | |
| 109 | ||
| 110 | const job = startMirror(app, alice, origin, "octo/runs"); | |
| 111 | const j = await settled(job.id); expect(j?.error).toBe(undefined); expect(j?.stage).toBe("done"); | |
| 112 | const repo = getRepo(app.db, "alice", "runs")!; | |
| 113 | const record = getAppByRepo(app.db, repo.id); | |
| 114 | expect(record?.access).toBe("private"); | |
| 115 | // Asleep: nothing deployed or started by the bring. | |
| 116 | expect(app.db.query("SELECT COUNT(*) AS n FROM run WHERE repo_id = ?1").get(repo.id)).toEqual({ n: 0 }); | |
| 117 | ||
| 118 | const after = listOrigins(app.db, alice.id)[0]!; | |
| 119 | expect(after.runNote).toContain("alice/runs was carried"); | |
| 120 | const carries = originJson(after).carries!; | |
| 121 | expect(carries).toContain("How the app runs, from the last bring: alice/runs was carried"); | |
| 122 | expect(carries).toContain("its data and its secrets"); | |
| 123 | const card = await fetch(`${servers.url}/settings/origins`, { headers: { authorization: basic("alice", PASSWORD) } }); | |
| 124 | const text = await card.text(); | |
| 125 | expect(text).toContain("alice/runs was carried"); | |
| 126 | expect(text).toContain("its data and its secrets"); | |
| 127 | expect(text).not.toContain("real-secret"); | |
| 128 | }); | |
| 129 | ||
| 130 | test("no forge.json, or one that does not validate, makes no app and says why", async () => { | |
| 131 | const alice = getUserByName(app.db, "alice")!; | |
| 132 | const origin = listOrigins(app.db, alice.id)[0]!; | |
| 133 | ||
| 134 | const plain = startMirror(app, alice, origin, "octo/plain"); | |
| 135 | expect((await settled(plain.id))?.stage).toBe("done"); | |
| 136 | expect(getAppByRepo(app.db, getRepo(app.db, "alice", "plain")!.id)).toBeUndefined(); | |
| 137 | expect(originJson(listOrigins(app.db, alice.id)[0]!).carries).toContain( | |
| 138 | "alice/plain was not carried: it has no forge.json", | |
| 139 | ); | |
| 140 | ||
| 141 | const broken = startMirror(app, alice, origin, "octo/broken"); | |
| 142 | expect((await settled(broken.id))?.stage).toBe("done"); | |
| 143 | expect(getAppByRepo(app.db, getRepo(app.db, "alice", "broken")!.id)).toBeUndefined(); | |
| 144 | expect(originJson(listOrigins(app.db, alice.id)[0]!).carries).toContain( | |
| 145 | "alice/broken was not carried: its forge.json is not valid", | |
| 146 | ); | |
| 147 | }); | |
| 148 | }); | |
| 149 | ||
| 150 | test("a parser message with control characters is stripped before it is kept", () => { | |
| 151 | const run = runOfBrought('{"run":"\u001b[31mred\u0007"'); | |
| 152 | expect(run.ok).toBe(false); | |
| 153 | if (!run.ok) expect(run.why).not.toMatch(/[\u0000-\u001f\u007f]/); | |
| 154 | }); |
test/origin-words.test.ts +3 −1
| @@ -12,7 +12,9 @@ const PROVIDERS = [ | ||
| 12 | 12 | "src/origins/providers/github.ts", |
| 13 | 13 | ]; |
| 14 | 14 | |
| 15 | const sentences = Object.entries(words) as [string, string][]; | |
| 15 | const sentences = Object.entries(words).filter( | |
| 16 | ([, v]) => typeof v === "string", | |
| 17 | ) as [string, string][]; | |
| 16 | 18 | |
| 17 | 19 | test("each sentence is non-empty", () => { |
| 18 | 20 | expect(sentences.length).toBe(8); |
test/tui-waves.test.ts +1
| @@ -56,6 +56,7 @@ const remoteOf = (src: RepoSource): RepoSource => ({ | ||
| 56 | 56 | authKind: "pat", |
| 57 | 57 | expiresAt: null, |
| 58 | 58 | needsReauth: false, |
outdated
Clean: put runNote on its own line like the other fields. |
||
| 59 | runNote: "", | |
| 59 | 60 | readOnly: false, |
| 60 | 61 | software: "", |
| 61 | 62 | }, |
test/web-apps.test.ts +2
| @@ -1084,6 +1084,8 @@ describe("apps, runs and the crew on the web", () => { | ||
| 1084 | 1084 | }); |
| 1085 | 1085 | |
| 1086 | 1086 | test("the app page says in a sentence that production is not running, and what to do", async () => { |
| 1087 | // Production's environment is made by the first deploy: wait for its run. | |
| 1088 | await runsOf(hello, (r) => r.state !== "queued" && r.state !== "running", 30_000); | |
| 1087 | 1089 | const stop = await web(alice, "/alice/hello/app/production/stop", { form: {} }); |
| 1088 | 1090 | expect(stop.status).toBeLessThan(400); |
| 1089 | 1091 | try { |
new above
offline
HIGH: untrusted parser message is echoed into run_note and shown in the terminal. Only whitespace is collapsed; ESC and other control characters pass. Strip control characters or drop the message.