Public: anyone can read this; the crew can change it.
Fork offers, following upstream and detaching can be done from the terminal, with the same words as the pages #15357
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15354-fork-offers-following-upstream-and-detac → main 0 commits fork
3 files
changed +121
−4
docs/features/fork-tree-terminal.md added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | --- | |
| 2 | topic: Your apps | |
| 3 | row: Fork offers, following and detaching, from the page or the terminal | |
| 4 | --- | |
| 5 | # Fork offers, following and detaching: two doors | |
| 6 | ||
| 7 | The same four actions are on a page and in the terminal. Each calls one function in `src/actions`, so the words match. | |
| 8 | ||
| 9 | - **See offers.** On an upstream, the page (`src/web/pages/fork-offers.ts`, "Offered by forks") and the terminal's Forks screen (`src/tui/screens/forks.ts`, rows "offered #N …") list the open pulls its forks sent, with the fork, how long ago and the size. A fork's own page and screen list what it sent, with where each stands; `Withdraw` is on the waiting ones. | |
| 10 | - **Offer a change upstream.** On a fork, the page (`src/web/pages/offer-upstream.ts`) has "Offer N commits upstream" and the per-commit and per-pull buttons; the terminal has `o` on a commit (`src/tui/screens/commits.ts`) and on a merged pull (`src/tui/screens/pull.ts`), and `u` on the Forks screen to propose the fork's branch. All go through `offerCommit` and `offerPull`. | |
| 11 | - **Follow or propose.** On the page, Settings › Follow upstream (`src/web/pages/upstream-follow.ts`) and the Following page; in the terminal, `m` on the Forks screen (`setFollowMode`) cycles "Follow and merge", "Follow and ask" and "Stay as is", and `z` undoes the last change. The About card (`src/tui/screens/about.ts`) sets an address to follow. | |
| 12 | - **Detach.** On the page, Settings › Danger zone › Sever from upstream (`src/web/pages/detach.ts`); in the terminal, `x` on a fork's About card. Both go through `/-/confirm` or a confirm dialog first, which states the plan (`detachPlanWords`). Dismissed, nothing changes; there is no undo once it runs. | |
| 13 | ||
| 14 | Tested in `test/tui-fork-offers.test.ts`. |
scripts/doorless-allow.json −4
| @@ -26,7 +26,6 @@ | ||
| 26 | 26 | "src/web/pages/crew-settings.ts", |
| 27 | 27 | "src/web/pages/danger.ts", |
| 28 | 28 | "src/web/pages/dep_chain.ts", |
| 29 | "src/web/pages/detach.ts", | |
| 30 | 29 | "src/web/pages/edit.ts", |
| 31 | 30 | "src/web/pages/everyday.ts", |
| 32 | 31 | "src/web/pages/explorer.ts", |
| @@ -37,7 +36,6 @@ | ||
| 37 | 36 | "src/web/pages/flow-estimates.ts", |
| 38 | 37 | "src/web/pages/flow-panel.ts", |
| 39 | 38 | "src/web/pages/forges-refused.ts", |
| 40 | "src/web/pages/fork-offers.ts", | |
| 41 | 39 | "src/web/pages/frozen.ts", |
| 42 | 40 | "src/web/pages/gate.ts", |
| 43 | 41 | "src/web/pages/global-map.ts", |
| @@ -61,7 +59,6 @@ | ||
| 61 | 59 | "src/web/pages/now.ts", |
| 62 | 60 | "src/web/pages/oauth.ts", |
| 63 | 61 | "src/web/pages/offer-receipt.ts", |
| 64 | "src/web/pages/offer-upstream.ts", | |
| 65 | 62 | "src/web/pages/offline.ts", |
| 66 | 63 | "src/web/pages/og.ts", |
| 67 | 64 | "src/web/pages/org.ts", |
| @@ -92,7 +89,6 @@ | ||
| 92 | 89 | "src/web/pages/talk_client.ts", |
| 93 | 90 | "src/web/pages/talk_preview.ts", |
| 94 | 91 | "src/web/pages/tree_cache.ts", |
| 95 | "src/web/pages/upstream-follow.ts", | |
| 96 | 92 | "src/web/pages/usage-tabs.ts", |
| 97 | 93 | "src/web/pages/visitors.ts", |
| 98 | 94 | "src/web/pages/waking.ts" |
test/tui-fork-offers.test.ts added +107
| @@ -0,0 +1,107 @@ | ||
| 1 | /** | |
| 2 | * The fork tree from the terminal (#15354): the upstream's Forks screen lists an offer a fork sent, | |
| 3 | * and the About card's detach asks first — dismissed, it changes nothing. | |
| 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 { detachJob } from "../src/actions/detach.ts"; | |
| 10 | import { openPull } from "../src/actions/pulls.ts"; | |
| 11 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { getRepoById, type Repo } from "../src/core/repos.ts"; | |
| 14 | import { createUser, type User } from "../src/core/users.ts"; | |
| 15 | import { localSource } from "../src/view/local.ts"; | |
| 16 | import type { Ctx, Screen } from "../src/tui/app/app.ts"; | |
| 17 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 18 | import { aboutScreen } from "../src/tui/screens/about.ts"; | |
| 19 | import { forksScreen } from "../src/tui/screens/forks.ts"; | |
| 20 | import type { Session } from "../src/tui/session.ts"; | |
| 21 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 22 | import type { KeyEvent } from "../src/tui/term/input.ts"; | |
| 23 | import { settleApp } from "./helpers/tui.ts"; | |
| 24 | import { promote } from "./helpers/members.ts"; | |
| 25 | ||
| 26 | const must = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => { | |
| 27 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 28 | return r.value; | |
| 29 | }; | |
| 30 | ||
| 31 | const press = (key: string): KeyEvent => ({ type: "key", key, ctrl: false, alt: false, shift: false }); | |
| 32 | ||
| 33 | let dir: string; | |
| 34 | let app: App; | |
| 35 | let alice: User; | |
| 36 | let bob: User; | |
| 37 | let up: Repo; | |
| 38 | let fork: Repo; | |
| 39 | ||
| 40 | beforeAll(async () => { | |
| 41 | dir = await mkdtemp(join(tmpdir(), "forge-tui-fork-offers-")); | |
| 42 | app = createApp({ dataDir: dir, port: 0 }); | |
| 43 | const mk = async (username: string, first = false) => | |
| 44 | must( | |
| 45 | await createUser(app.db, { | |
| 46 | origin: "seed", trusted: true, username, email: `${username}@f.dev`, | |
| 47 | password: "a-good-passphrase", adminIfFirst: first, | |
| 48 | }), | |
| 49 | ); | |
| 50 | alice = await mk("alice", true); | |
| 51 | promote(app.db, alice); | |
| 52 | bob = await mk("bob"); | |
| 53 | promote(app.db, bob); | |
| 54 | up = must(await createRepo(app, alice, { name: "lib", visibility: "public" })); | |
| 55 | must(await commitToBranch(app, alice, up, { message: "Start", files: [{ path: "README.md", content: "# x\n" }] })); | |
| 56 | fork = must(await forkRepo(app, bob, up)); | |
| 57 | must(await commitToBranch(app, bob, fork, { branch: "tweak", message: "Tweak", files: [{ path: "t.txt", content: "t\n" }] })); | |
| 58 | must(await openPull(app, bob, up, { title: "Sharper edges", baseBranch: "main", headBranch: "tweak", headRepo: fork })); | |
| 59 | }, 60_000); | |
| 60 | ||
| 61 | afterAll(async () => { | |
| 62 | app.close(); | |
| 63 | await rm(dir, { recursive: true, force: true }); | |
| 64 | }); | |
| 65 | ||
| 66 | describe("fork offers and detach in the terminal", () => { | |
| 67 | test("the upstream's Forks screen lists an offer from a fork", async () => { | |
| 68 | const terminal = headlessTerminal(120, 30); | |
| 69 | const { app: tui, session } = createForgeApp( | |
| 70 | app, | |
| 71 | { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: alice }, | |
| 72 | { terminal, exitHooks: false }, | |
| 73 | ); | |
| 74 | tui.start(); | |
| 75 | tui.ctx.push(forksScreen(session, tui.ctx, up)); | |
| 76 | await settleApp(tui); | |
| 77 | const text = tui.screen.toText(); | |
| 78 | tui.stop?.(); | |
| 79 | expect(text).toContain("Sharper edges"); | |
| 80 | expect(text).toContain("bob/lib"); | |
| 81 | }); | |
| 82 | ||
| 83 | test("detach shows its plan first and, dismissed, changes nothing", async () => { | |
| 84 | const pushed: Screen[] = []; | |
| 85 | let shown!: () => void; | |
| 86 | const asked = new Promise<void>((r) => (shown = r)); | |
| 87 | const ctx = { invalidate() {}, toast() {}, push: (s: Screen) => (pushed.push(s), shown()), pop: () => pushed.pop(), copy() {} } as unknown as Ctx; | |
| 88 | const f = { app, db: app.db, user: bob } as unknown as Session; | |
| 89 | const screen = aboutScreen(f, ctx, {} as Screen, localSource(app, fork, bob), undefined, "main"); | |
| 90 | expect(screen.keys.some((b) => b.keys.includes("x"))).toBe(true); | |
| 91 | screen.key!(press("x")); | |
| 92 | await asked; | |
| 93 | expect(pushed).toHaveLength(1); | |
| 94 | expect(pushed[0]!.title).toBe("Sever from upstream"); | |
| 95 | expect(detachJob(fork.id)).toBeUndefined(); | |
| 96 | pushed[0]!.key!(press("esc")); | |
| 97 | expect(detachJob(fork.id)).toBeUndefined(); | |
| 98 | expect(getRepoById(app.db, fork.id)?.forkParentId).toBe(up.id); | |
| 99 | }); | |
| 100 | ||
| 101 | test("someone who does not own the fork is not offered detach", () => { | |
| 102 | const f = { app, db: app.db, user: undefined } as unknown as Session; | |
| 103 | const ctx = { invalidate() {}, toast() {}, push() {}, pop() {}, copy() {} } as unknown as Ctx; | |
| 104 | const screen = aboutScreen(f, ctx, {} as Screen, localSource(app, fork, undefined), undefined, "main"); | |
| 105 | expect(screen.keys.some((b) => b.keys.includes("x"))).toBe(false); | |
| 106 | }); | |
| 107 | }); |
new above
offline