Public: anyone can read this; the crew can change it.
A fork's page says in one sentence how far it is from its upstream and what following would do #14477
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/14462-a-fork-s-page-says-in-one-sentence-how-f → main 8 commits fork 7 threads · 7 unresolved
docs/FOLLOWING.md +6
| @@ -203,6 +203,12 @@ page, `POST /api/v1/repos/:owner/:name/following/take` (409, naming the | ||
| 203 | 203 | converge issue), and the MCP `take_updates` tool, so the same press does the |
| 204 | 204 | same thing at every door. |
| 205 | 205 | |
| 206 | ## The one sentence | |
| 207 | ||
| 208 | A fork's page, MCP `forks` and `GET /api/v1/repos/:owner/:name/forks` say how far it is from its parent | |
| 209 | and what its follow mode will do in one sentence (`driftWords`, `words` in the answers): "3 changes behind | |
| 210 | a/b; following will apply 3 changes.", "Up to date with a/b; …". It reads the cached drift, never a new walk. | |
| 211 | ||
| 206 | 212 | ## Ranked forks |
| 207 | 213 | |
| 208 | 214 | `/:owner/:name/forks` and the terminal's forks screen (`f` in a repository) |
docs/features/fork-standing.md added +16
| @@ -0,0 +1,16 @@ | ||
| 1 | --- | |
| 2 | topic: Your apps | |
| 3 | row: How far a fork is from its upstream, in one sentence | |
| 4 | --- | |
| 5 | # How far a fork is from its upstream, in one sentence | |
| 6 | ||
| 7 | A fork's page says under its head how far it is from its parent and what its | |
| 8 | follow mode will do about it, for example "3 changes behind a/b; following will | |
| 9 | apply 3 changes." or "Up to date with a/b; following has nothing to apply." | |
| 10 | ||
| 11 | - `driftWords` (`src/actions/follow_words.ts`) builds the sentence from the | |
| 12 | ahead and behind counts and the mode; `followWords` (`src/actions/follow.ts`) | |
| 13 | reads the cached drift, never a new git walk. | |
| 14 | - The page's standing line, the terminal's forks screen (`f` in a repository) | |
| 15 | and the `words` field of MCP `forks` and `GET /api/v1/repos/:owner/:name/forks` | |
| 16 | all say that one string. A parent the reader cannot read is not named. |
src/actions/follow.ts +24 −2
| @@ -14,13 +14,13 @@ import type { User } from "../core/users.ts"; | ||
| 14 | 14 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 15 | 15 | import { chainOfRepo, forgeLinkOf, FOLLOW_MODES, isFollowMode, setChainMode, severChain } from "../spawn/chain.ts"; |
| 16 | 16 | import { FAMILY_WORDS } from "./family_words.ts"; |
| 17 | import { FOLLOWS_NOTHING, followModeWords, followStandingLine } from "./follow_words.ts"; | |
| 17 | import { FOLLOWS_NOTHING, agoWords, driftWords, followModeWords, followStandingLine } from "./follow_words.ts"; | |
| 18 | 18 | import { FORK_FOLLOW_MODES, forkFollowMode, lastTookAt, isForkFollowMode, setForkFollowMode, type ForkFollowMode } from "../core/fork_follow.ts"; |
| 19 | 19 | import { requireUser } from "./access.ts"; |
| 20 | 20 | import { getFollow, setFollowTaking } from "../core/upstream_follow.ts"; |
| 21 | 21 | import { isChecking, severUpstream } from "./upstream_follow.ts"; |
| 22 | 22 | import { takeFromParent, type Taken } from "../spawn/take.ts"; |
| 23 | import { takeUpdates, type ForkSync, type TakeUpdatesError } from "./forks.ts"; | |
| 23 | import { driftOfForks, takeUpdates, type ForkSync, type TakeUpdatesError } from "./forks.ts"; | |
| 24 | 24 | import { convergeFollowed } from "./upstream_sync.ts"; |
| 25 | 25 | |
| 26 | 26 | /** |
| @@ -148,6 +148,28 @@ export async function followStanding(app: App, repo: Repo, viewer: User | undefi | ||
| 148 | 148 | ); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | /** | |
| 152 | * The one sentence on how far a fork is from its parent and what following will do (#14462); the | |
| 153 | * drift is the cached reading (`driftOfForks`), never a new walk. Undefined for a repository that | |
| 154 | * is no fork. | |
| 155 | */ | |
| 156 | export async function followWords(app: App, repo: Repo, viewer: User | undefined): Promise<string | undefined> { | |
| 157 | if (repo.forkParentId === null) return undefined; | |
| 158 | const parent = forkParentFor(app.db, repo, viewer); | |
| 159 | const drift = | |
| 160 | parent === undefined || repo.archivedAt !== null | |
| 161 | ? { ahead: null, behind: null } | |
| 162 | : (await driftOfForks(app, parent, [repo]))[0]!.drift; | |
| 163 | const sentence = driftWords( | |
| 164 | await followModeOf(app, repo), | |
| 165 | parent === undefined ? undefined : `${parent.ownerName}/${parent.name}`, | |
| 166 | drift.ahead, | |
| 167 | drift.behind, | |
| 168 | ); | |
| 169 | const took = lastTookAt(app.db, repo.id); | |
| 170 | return took === null ? sentence : `${sentence} Last took ${agoWords(took)}.`; | |
| 171 | } | |
| 172 | ||
| 151 | 173 | export type FollowModeError = SeverError | "invalid_mode" | "severed" | "updating"; |
| 152 | 174 | |
| 153 | 175 | /** The one answer every door gives a refused mode change, with the status an HTTP door sends. */ |
src/actions/follow_words.ts +38
| @@ -130,6 +130,44 @@ export function followStandingLine( | ||
| 130 | 130 | return tookAt === null ? line : `${line} · last took ${agoWords(tookAt, now)}`; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | const changes = (n: number): string => `${n} change${n === 1 ? "" : "s"}`; | |
| 134 | ||
| 135 | /** | |
| 136 | * How far a fork is from its upstream and what its follow mode will do about it, in one plain | |
| 137 | * sentence (#14462): the fork's page and the forks answers (MCP and API) say this one string. | |
| 138 | * `ahead` and `behind` are the cached drift; null (git could not say) leaves the distance unsaid. | |
| 139 | */ | |
| 140 | export function driftWords( | |
| 141 | mode: ForkFollowMode, | |
| 142 | upstream: string | undefined, | |
| 143 | ahead: number | null, | |
| 144 | behind: number | null, | |
| 145 | ): string { | |
| 146 | const name = upstream ?? "its upstream"; | |
| 147 | const none = mode === "dont-follow" ? "not following, so nothing will be applied" : "following has nothing to apply"; | |
| 148 | if (ahead === null || behind === null) { | |
| 149 | const will = | |
| 150 | mode === "take-updates" | |
| 151 | ? "following will take what it can" | |
| 152 | : mode === "tell-me" | |
| 153 | ? "following will wait for you to take it" | |
| 154 | : none; | |
| 155 | return `Not known how far this is from ${name}; ${will}.`; | |
| 156 | } | |
| 157 | if (ahead === 0 && behind === 0) return `Up to date with ${name}; ${none}.`; | |
| 158 | const apart = | |
| 159 | behind > 0 && ahead > 0 | |
| 160 | ? `${changes(behind)} behind and ${ahead} ahead of ${name}` | |
| 161 | : behind > 0 | |
| 162 | ? `${changes(behind)} behind ${name}` | |
| 163 | : `${changes(ahead)} ahead of ${name}`; | |
outdated
Principle 8: 'a conflict goes to the crew' and 'offered up' are jargon; say plainly what happens (e.g. 'a conflict is sent for review'). Also long: the sentence reaches ~110 characters. |
||
| 164 | if (mode === "dont-follow" || behind === 0) return `${apart}; ${none}.`; | |
| 165 | if (mode === "tell-me") return `${apart}; following will apply nothing until you take ${behind === 1 ? "it" : `the ${behind}`}.`; | |
| 166 | return ahead === 0 | |
| 167 | ? `${apart}; following will apply ${changes(behind)}.` | |
| 168 | : `${apart}; following will merge ${changes(behind)}, or open an issue on a conflict.`; | |
| 169 | } | |
| 170 | ||
| 133 | 171 | /** |
| 134 | 172 | * How a fork follows its upstream in one word, for a tree node; a severed fork says so rather than |
| 135 | 173 | * saying nothing. |
src/http/api/upstream.ts +3
| @@ -16,6 +16,7 @@ import { | ||
| 16 | 16 | setFollowUpstream, |
| 17 | 17 | } from "../../actions/upstream_follow.ts"; |
| 18 | 18 | import { ENABLED_WORDS } from "../../core/arg_words.ts"; |
| 19 | import { followWords } from "../../actions/follow.ts"; | |
| 19 | 20 | import { driftOfForks, MAX_RANKED_FORKS, type RankedFork } from "../../actions/forks.ts"; |
| 20 | 21 | import { canAdmin, forkParentFor, visibleForks } from "../../core/repos.ts"; |
| 21 | 22 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; |
| @@ -123,9 +124,11 @@ export function upstreamRoutes(router: Router<Handler>): void { | ||
| 123 | 124 | const parent = forkParentFor(ctx.app.db, repo, ctx.auth.user); |
| 124 | 125 | // The tag is of the exact bytes sent: a fork made, pushed or hidden, or a parent that moved, changes |
| 125 | 126 | // the body; limit and cursor choose the page. A 404 or bad page returned above carries none. |
| 127 | const words = (await followWords(ctx.app, repo, ctx.auth.user)) ?? null; | |
| 126 | 128 | return timePhase(ctx.request, "render", () => { |
| 127 | 129 | const text = JSON.stringify({ |
| 128 | 130 | parent: parent === undefined ? null : `${parent.ownerName}/${parent.name}`, |
| 131 | words, | |
| 129 | 132 | items: drifts.map(({ fork, drift, pushedAt }) => ({ |
| 130 | 133 | ...fork, |
| 131 | 134 | ahead: drift.ahead, |
src/http/mcp/tools/forks.ts +3 −1
| @@ -1,12 +1,13 @@ | ||
| 1 | 1 | import { driftOfForks, MAX_RANKED_FORKS, type RankedFork } from "../../../actions/forks.ts"; |
| 2 | 2 | import { forkParentFor, visibleForks, type Repo } from "../../../core/repos.ts"; |
| 3 | import { followWords } from "../../../actions/follow.ts"; | |
| 3 | 4 | import { forkChain } from "../../../actions/fork_chain.ts"; |
| 4 | 5 | import { pageRows } from "../page.ts"; |
| 5 | 6 | import { good, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts"; |
| 6 | 7 | |
| 7 | 8 | export const tool: Tool = { |
| 8 | 9 | name: "forks", |
| 9 | doc: "`{ repo, kind: chain }`: `{ chain: [{ role, repo, follows, page }], severed, truncated }`, its grandparent, parent, itself and children in the fork tree page's words, a severed link stops it, unreadable forks are left out; else `{ repo, limit?, cursor? }`: `{ parent, forks: [{ repo, ahead, behind, updatedAt }], next_cursor }`, the forks the caller may see in the order `/:owner/:name/forks` lists them, each with its commits ahead of and behind this one (`null` when git cannot say); `limit` 1-200 (default 50), `cursor` the last `next_cursor` (null on the last page); drift is read for the page only; draws the `ui://forge/forks` card", | |
| 10 | doc: "`{ repo, kind: chain }`: `{ chain: [{ role, repo, follows, page }], severed, truncated }`, its grandparent, parent, itself and children in the fork tree page's words, a severed link stops it, unreadable forks are left out; else `{ repo, limit?, cursor? }`: `{ parent, words, forks: [{ repo, ahead, behind, updatedAt }], next_cursor }`, the forks the caller may see in the order `/:owner/:name/forks` lists them, each with its commits ahead of and behind this one (`null` when git cannot say); `limit` 1-200 (default 50), `cursor` the last `next_cursor` (null on the last page); `words` is the one sentence on how far this fork is from its parent and what following will do (`null` when it is no fork); drift is read for the page only; draws the `ui://forge/forks` card", | |
| 10 | 11 | description: "A repo's forks you may see, paged by limit and cursor (next_cursor), each with commits ahead and behind.", |
| 11 | 12 | inputSchema: { |
| 12 | 13 | type: "object", |
| @@ -39,6 +40,7 @@ export const tool: Tool = { | ||
| 39 | 40 | })); |
| 40 | 41 | return good({ |
| 41 | 42 | parent: parent === undefined ? null : `${parent.ownerName}/${parent.name}`, |
| 43 | words: (await followWords(ctx.app, repo, user)) ?? null, | |
| 42 | 44 | forks: rows, |
| 43 | 45 | next_cursor, |
| 44 | 46 | }); |
src/tui/screens/forks.ts +10 −9
| @@ -21,8 +21,8 @@ import { | ||
| 21 | 21 | type ForkRanking, |
| 22 | 22 | type ForkRelation, |
| 23 | 23 | } from "../../actions/forks.ts"; |
| 24 | import { FOLLOW_CHOICES, FOLLOW_PHRASE, FOLLOW_WORD, FOLLOWS_NOTHING, followChoiceLine, proposeRefusalWords } from "../../actions/follow_words.ts"; | |
| 25 | import { FOLLOW_MODE_REFUSALS, convergeWords, followModeOf, followStanding, setFollowMode, takeOrTell, takeWords } from "../../actions/follow.ts"; | |
| 24 | import { FOLLOW_CHOICES, FOLLOW_PHRASE, FOLLOWS_NOTHING, followChoiceLine, proposeRefusalWords } from "../../actions/follow_words.ts"; | |
| 25 | import { FOLLOW_MODE_REFUSALS, convergeWords, followModeOf, followStanding, followWords, setFollowMode, takeOrTell, takeWords } from "../../actions/follow.ts"; | |
| 26 | 26 | import { incomingOf, type Incoming } from "../../actions/follow_incoming.ts"; |
| 27 | 27 | import { convergeFollowed, followedAs, followedOf } from "../../actions/upstream_sync.ts"; |
| 28 | 28 | import { forkOffers } from "../../core/fork_offers.ts"; |
| @@ -36,7 +36,7 @@ import { canAdmin, canRead, canWrite, forkTree, getRepoById, listForks, type For | ||
| 36 | 36 | import type { Ctx, Screen } from "../app/app.ts"; |
| 37 | 37 | import { binding } from "../app/keys.ts"; |
| 38 | 38 | import { style } from "../term/style.ts"; |
| 39 | import { truncate } from "../term/width.ts"; | |
| 39 | import { truncate, wrap } from "../term/width.ts"; | |
| 40 | 40 | import { fill, len, split } from "../ui/layout.ts"; |
| 41 | 41 | import { emptyState } from "../ui/widgets.ts"; |
| 42 | 42 | import type { Session } from "../session.ts"; |
| @@ -244,7 +244,8 @@ export function forksScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 244 | 244 | relation !== undefined && relation.state === "diverged" && !relation.clean |
| 245 | 245 | ? convergeState(f.app, repo, relation.parent) |
| 246 | 246 | : undefined; |
| 247 | standing = await followStanding(f.app, repo, f.user); | |
| 247 | // The sentence the page's standing line says (#14462); the plain line where it is silent. | |
| 248 | standing = (await followWords(f.app, repo, f.user)) ?? (await followStanding(f.app, repo, f.user)); | |
The terminal now omits 'last took', which |
||
| 248 | 249 | failed = getRepoById(f.db, repo.id)?.origin?.fetchError ?? ""; |
| 249 | 250 | mode = relation === undefined ? undefined : await followModeOf(f.app, repo); |
| 250 | 251 | following = followingRows(relation, converge, mode); |
| @@ -336,7 +337,7 @@ export function forksScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 336 | 337 | }, |
| 337 | 338 | render(area, s) { |
| 338 | 339 | const c = ctx.theme.c; |
| 339 | const [head, line, body] = split(area, "v", [len(1), len(standing === undefined && failed === "" ? 0 : 1), fill(1)]); | |
| 340 | const [head, line, body] = split(area, "v", [len(1), len(failed !== "" ? 1 : standing === undefined ? 0 : wrap(standing, area.w).slice(0, 2).length), fill(1)]); | |
| 340 | 341 | const list = rows(); |
| 341 | 342 | s.text( |
| 342 | 343 | head!.x, |
| @@ -351,10 +352,10 @@ export function forksScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 351 | 352 | if (failed !== "") { |
| 352 | 353 | s.text(line!.x, line!.y, truncate(`The last sync failed: ${failed}`, line!.w), style(c.danger, c.bg), line!.x + line!.w); |
| 353 | 354 | } else if (standing !== undefined) { |
| 354 | // The same word the web header says, then how far behind when the relation was read. | |
| 355 | const word = mode === undefined ? "" : `${FOLLOW_WORD[mode]} · `; | |
| 356 | const behind = relation === undefined ? "" : ` · ${relation.behind} behind`; | |
| 357 | s.text(line!.x, line!.y, truncate(`${word}${standing}${behind}`, line!.w), style(c.mutedFg, c.bg), line!.x + line!.w); | |
| 355 | // The sentence the page says, wrapped on a narrow screen so the follow effect is not cut. | |
| 356 | wrap(standing, line!.w).slice(0, 2).forEach((row, i) => { | |
| 357 | s.text(line!.x, line!.y + i, row, style(c.mutedFg, c.bg), line!.x + line!.w); | |
outdated
|
||
| 358 | }); | |
| 358 | 359 | } |
| 359 | 360 | if (list.length === 0) { |
| 360 | 361 | emptyState(s, body!, c, { |
src/web/pages/fork-standing.ts +4 −4
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | * leave a line that still says the fork is level. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { followStanding } from "../../actions/follow.ts"; | |
| 11 | import { followWords } from "../../actions/follow.ts"; | |
| 12 | 12 | import type { Repo } from "../../core/repos.ts"; |
| 13 | 13 | import { STANDING_EVENTS } from "../../core/standing_events.ts"; |
| 14 | 14 | import { getFollow } from "../../core/upstream_follow.ts"; |
| @@ -46,13 +46,13 @@ function failedLine(repo: Repo): Html | null { | ||
| 46 | 46 | * they are silent. |
| 47 | 47 | */ |
| 48 | 48 | async function lines(ctx: Ctx, repo: Repo): Promise<Html> { |
| 49 | const standing = await followStanding(ctx.app, repo, ctx.auth.user); | |
| 50 | 49 | const behind = behindLine(ctx, repo); |
| 51 | 50 | const ahead = originAheadLine(ctx, repo); |
| 51 | const words = await followWords(ctx.app, repo, ctx.auth.user); | |
| 52 | 52 | const plain = |
| 53 | standing === undefined | |
| 53 | words === undefined | |
| 54 | 54 | ? null |
| 55 | : html`<div class="small muted" data-follow-standing>${icon("sync")} <a href="${repoBase(repo)}/forks#following">${standing}</a></div>`; | |
| 55 | : html`<div class="small muted" data-follow-standing>${icon("sync")} <a href="${repoBase(repo)}/forks#following">${words}</a></div>`; | |
outdated
The 'last took' suffix is built here, in the page, from |
||
| 56 | 56 | return html`${failedLine(repo)}${behind}${ahead}${behind === null && ahead === null ? plain : null}`; |
| 57 | 57 | } |
| 58 | 58 |
test/fork-counts.test.ts +1 −1
| @@ -112,7 +112,7 @@ describe("fork counts hold only the forks the viewer may read", () => { | ||
| 112 | 112 | const api = await fetch(`${base}/api/v1/repos/alice/lib/forks`, { |
| 113 | 113 | headers: { cookie: cookies[who]! }, |
| 114 | 114 | }); |
| 115 | expect(await api.json()).toEqual({ parent: null, items: [], next_cursor: null }); | |
| 115 | expect(await api.json()).toEqual({ parent: null, words: null, items: [], next_cursor: null }); | |
| 116 | 116 | } |
| 117 | 117 | const owners = await page("/alice/lib/forks", "bob"); |
| 118 | 118 | expect(owners).toContain("1 fork"); |
test/fork-follow-word.test.ts +1 −1
| @@ -124,7 +124,7 @@ test("the terminal's forks screen says the same word and how far behind", async | ||
| 124 | 124 | await settleApp(tui); |
| 125 | 125 | const frame = tui.screen.toText(); |
| 126 | 126 | tui.stop?.(); |
| 127 | expect(frame).toContain("proposes · Sends offers to alice/lib · 1 behind"); | |
| 127 | expect(frame).toContain("1 change behind and 1 ahead of alice/lib; following will apply nothing until you take it."); | |
| 128 | 128 | }); |
| 129 | 129 | |
| 130 | 130 | const behindOf = async (path: string): Promise<string | null> => |
test/fork-standing-line.test.ts +74 −8
| @@ -7,8 +7,8 @@ import { afterAll, beforeAll, expect, test } from "bun:test"; | ||
| 7 | 7 | import { mkdtemp, rm } from "node:fs/promises"; |
| 8 | 8 | import { tmpdir } from "node:os"; |
| 9 | 9 | import { join } from "node:path"; |
| 10 | import { followStanding } from "../src/actions/follow.ts"; | |
| 11 | import { agoWords, followStandingLine } from "../src/actions/follow_words.ts"; | |
| 10 | import { followStanding, followWords } from "../src/actions/follow.ts"; | |
| 11 | import { agoWords, driftWords, followStandingLine } from "../src/actions/follow_words.ts"; | |
| 12 | 12 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; |
| 13 | 13 | import { createApp, type App } from "../src/app.ts"; |
| 14 | 14 | import { setForkFollowMode } from "../src/core/fork_follow.ts"; |
| @@ -70,13 +70,13 @@ test("the words: each mode, with and without a last take", () => { | ||
| 70 | 70 | |
| 71 | 71 | test("a fork's page says its mode, links to the following card, and a root says nothing", async () => { |
| 72 | 72 | const bob = getRepo(app.db, "bob", "lib")!; |
| 73 | expect(await lineOf("/bob/lib")).toBe("Sends offers to alice/lib"); | |
| 73 | expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; following has nothing to apply."); | |
| 74 | 74 | const page = await (await fetch(`${servers.url}/bob/lib`)).text(); |
| 75 | 75 | expect(page).toContain('href="/bob/lib/forks#following"'); |
| 76 | 76 | setForkFollowMode(app.db, bob.id, "take-updates"); |
Principle of a test that would fail without the change: all three modes now expect the identical 'Up to date' string, so they no longer test the modes. Create drift (a commit on alice/lib) and assert the distinct sentence per mode on the page. |
||
| 77 | expect(await lineOf("/bob/lib")).toBe("Takes updates from alice/lib"); | |
| 77 | expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; following has nothing to apply."); | |
| 78 | 78 | setForkFollowMode(app.db, bob.id, "dont-follow"); |
| 79 | expect(await lineOf("/bob/lib")).toBe("Not following alice/lib"); | |
| 79 | expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; not following, so nothing will be applied."); | |
| 80 | 80 | expect(await lineOf("/alice/lib")).toBeNull(); |
| 81 | 81 | }); |
| 82 | 82 | |
| @@ -86,7 +86,7 @@ test("the last take is told, and the MCP's words are the page's", async () => { | ||
| 86 | 86 | kind: "push", repoId: bob.id, actorId: bob.ownerId, |
| 87 | 87 | payload: { updates: [], followed: "alice/lib" }, |
| 88 | 88 | }); |
| 89 | expect(await lineOf("/bob/lib")).toBe("Not following alice/lib · last took just now"); | |
| 89 | expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; not following, so nothing will be applied. Last took just now."); | |
| 90 | 90 | expect(await followStanding(app, bob, undefined)).toBe("Not following alice/lib · last took just now"); |
| 91 | 91 | expect(await followStanding(app, getRepo(app.db, "alice", "lib")!, undefined)).toBeUndefined(); |
| 92 | 92 | }); |
| @@ -95,7 +95,7 @@ test("a private upstream is not named to a reader who cannot read it", async () | ||
| 95 | 95 | const bob = getRepo(app.db, "bob", "lib")!; |
| 96 | 96 | app.db.query("UPDATE repo SET visibility = 'private' WHERE owner_id = (SELECT id FROM user WHERE username = 'alice') AND name = 'lib'").run(); |
| 97 | 97 | const seen = await lineOf("/bob/lib"); |
| 98 | expect(seen).toContain("Not following its upstream"); | |
| 98 | expect(seen).toContain("its upstream"); | |
| 99 | 99 | expect(seen).not.toContain("alice"); |
| 100 | 100 | expect(await followStanding(app, bob, undefined)).not.toContain("alice"); |
| 101 | 101 | }); |
| @@ -174,5 +174,71 @@ test("the terminal's forks screen says the line", async () => { | ||
| 174 | 174 | await settleApp(tui); |
| 175 | 175 | const text = tui.screen.toText(); |
| 176 | 176 | tui.stop?.(); |
| 177 | expect(text).toContain("Takes updates from alice/lib"); | |
| 177 | expect(text).toContain("2 changes ahead of alice/lib"); | |
| 178 | }); | |
| 179 | ||
| 180 | test("one sentence: ahead, behind and what each follow mode will do (#14462)", () => { | |
| 181 | const w = driftWords; | |
| 182 | expect(w("take-updates", "a/b", 0, 0)).toBe("Up to date with a/b; following has nothing to apply."); | |
| 183 | expect(w("take-updates", "a/b", 0, 3)).toBe("3 changes behind a/b; following will apply 3 changes."); | |
| 184 | expect(w("take-updates", "a/b", 0, 1)).toBe("1 change behind a/b; following will apply 1 change."); | |
| 185 | expect(w("take-updates", "a/b", 2, 0)).toBe("2 changes ahead of a/b; following has nothing to apply."); | |
| 186 | expect(w("take-updates", "a/b", 2, 3)).toBe("3 changes behind and 2 ahead of a/b; following will merge 3 changes, or open an issue on a conflict."); | |
| 187 | expect(w("tell-me", "a/b", 0, 3)).toBe("3 changes behind a/b; following will apply nothing until you take the 3."); | |
| 188 | expect(w("tell-me", "a/b", 2, 1)).toBe("1 change behind and 2 ahead of a/b; following will apply nothing until you take it."); | |
| 189 | expect(w("dont-follow", "a/b", 0, 3)).toBe("3 changes behind a/b; not following, so nothing will be applied."); | |
| 190 | expect(w("dont-follow", "a/b", 1, 0)).toBe("1 change ahead of a/b; not following, so nothing will be applied."); | |
| 191 | expect(w("tell-me", undefined, 0, 0)).toBe("Up to date with its upstream; following has nothing to apply."); | |
| 192 | expect(w("dont-follow", "a/b", 0, 0)).toBe("Up to date with a/b; not following, so nothing will be applied."); | |
| 193 | expect(w("tell-me", "a/b", null, null)).toBe("Not known how far this is from a/b; following will wait for you to take it."); | |
| 194 | expect(w("take-updates", "a/b", null, null)).toBe("Not known how far this is from a/b; following will take what it can."); | |
| 195 | expect(w("dont-follow", undefined, null, null)).toBe("Not known how far this is from its upstream; not following, so nothing will be applied."); | |
| 196 | }); | |
| 197 | ||
| 198 | test("the page, the MCP forks answer, the API and the terminal say one exact sentence for real drift", async () => { | |
| 199 | const { createToken } = await import("../src/core/tokens.ts"); | |
| 200 | const { mcpTool } = await import("./helpers/mcp.ts"); | |
| 201 | const { getUserByName } = await import("../src/core/users.ts"); | |
| 202 | const { createForgeApp } = await import("../src/tui/forge.ts"); | |
| 203 | const { forksScreen } = await import("../src/tui/screens/forks.ts"); | |
outdated
This regex accepts almost any sentence, and the fork is probably 'up to date' so the behind/ahead path is not exercised through the doors. Assert the exact string against real drift. |
||
| 204 | const { headlessTerminal } = await import("../src/tui/term/terminal.ts"); | |
| 205 | const { settleApp } = await import("./helpers/tui.ts"); | |
| 206 | app.db.query("UPDATE repo SET visibility = 'public' WHERE name = 'lib'").run(); | |
| 207 | const alice = getUserByName(app.db, "alice")!; | |
| 208 | const bob = getRepo(app.db, "bob", "lib")!; | |
| 209 | // Not following, so the parent's push is not taken in the background; bob is 2 ahead, 1 behind. | |
| 210 | setForkFollowMode(app.db, bob.id, "dont-follow"); | |
| 211 | const more = await commitToBranch(app, alice, getRepo(app.db, "alice", "lib")!, { message: "Three", files: [{ path: "three.txt", content: "3\n" }] }); | |
| 212 | expect(more.ok).toBe(true); | |
| 213 | const apart = "1 change behind and 2 ahead of alice/lib"; | |
| 214 | const tail = " Last took just now."; | |
| 215 | const want: Record<"take-updates" | "tell-me" | "dont-follow", string> = { | |
| 216 | "take-updates": `${apart}; following will merge 1 change, or open an issue on a conflict.${tail}`, | |
| 217 | "tell-me": `${apart}; following will apply nothing until you take it.${tail}`, | |
| 218 | "dont-follow": `${apart}; not following, so nothing will be applied.${tail}`, | |
| 219 | }; | |
| 220 | const token = createToken(app.db, getUserByName(app.db, "bob")!.id, "bob", "admin").token; | |
| 221 | for (const mode of ["take-updates", "tell-me", "dont-follow"] as const) { | |
| 222 | setForkFollowMode(app.db, bob.id, mode); | |
| 223 | expect(await followWords(app, bob, undefined)).toBe(want[mode]); | |
| 224 | expect(await lineOf("/bob/lib")).toBe(want[mode]); | |
| 225 | expect((await mcpTool(servers.url, token, "forks", { repo: "bob/lib" })).value.words).toBe(want[mode]); | |
| 226 | const api = await (await fetch(`${servers.url}/api/v1/repos/bob/lib/forks`, { headers: { authorization: `Bearer ${token}` } })).json() as { words: string }; | |
| 227 | expect(api.words).toBe(want[mode]); | |
| 228 | } | |
| 229 | // The terminal, 80 columns: the sentence wraps over two rows, its effect and last take intact. | |
| 230 | setForkFollowMode(app.db, bob.id, "tell-me"); | |
| 231 | const terminal = headlessTerminal(80, 30); | |
| 232 | const { app: tui, session } = createForgeApp( | |
| 233 | app, | |
| 234 | { sshUsername: "bob", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: getUserByName(app.db, "bob")! }, | |
| 235 | { terminal, exitHooks: false }, | |
| 236 | ); | |
| 237 | tui.start(); | |
| 238 | tui.ctx.push(forksScreen(session, tui.ctx, getRepo(app.db, "bob", "lib")!)); | |
| 239 | await settleApp(tui); | |
| 240 | const flat = tui.screen.toText().replace(/\s+/g, " "); | |
| 241 | tui.stop?.(); | |
| 242 | expect(flat).toContain(want["tell-me"].replace(/\s+/g, " ")); | |
| 243 | expect(await followWords(app, getRepo(app.db, "alice", "lib")!, undefined)).toBeUndefined(); | |
| 178 | 244 | }); |
test/standing-live.test.ts +3 −3
| @@ -61,7 +61,7 @@ const line = async (path: string): Promise<string> => | ||
| 61 | 61 | test("the card's line is a live region of the page's own stream, with no script of its own", async () => { |
| 62 | 62 | const page = await (await fetch(`${servers.url}/bob/lib`)).text(); |
| 63 | 63 | expect(page).toMatch(/<div id="fork-standing" data-live="push,repo\.synced[^"]*" data-live-repo="bob\/lib" data-live-src="\/bob\/lib\/standing-line">/); |
| 64 | expect(page).toContain("Sends offers to alice/lib"); | |
| 64 | expect(page).toContain("Up to date with alice/lib"); | |
| 65 | 65 | expect(page).not.toContain("/standing-line.js"); |
| 66 | 66 | // A repository that stands against nothing carries no region. |
| 67 | 67 | expect(await (await fetch(`${servers.url}/alice/lib`)).text()).not.toContain('id="fork-standing"'); |
| @@ -69,9 +69,9 @@ test("the card's line is a live region of the page's own stream, with no script | ||
| 69 | 69 | |
| 70 | 70 | test("a take appended to the stream changes what the region's address answers", async () => { |
| 71 | 71 | const bob = getRepo(app.db, "bob", "lib")!; |
| 72 | expect(await line("/bob/lib")).not.toContain("last took"); | |
| 72 | expect(await line("/bob/lib")).not.toContain("Last took"); | |
| 73 | 73 | app.bus.append({ kind: "push", repoId: bob.id, actorId: bob.ownerId, payload: { updates: [], followed: "alice/lib" } }); |
| 74 | expect(await line("/bob/lib")).toContain("Sends offers to alice/lib · last took just now"); | |
| 74 | expect(await line("/bob/lib")).toContain("Up to date with alice/lib; following has nothing to apply. Last took just now."); | |
| 75 | 75 | }); |
| 76 | 76 | |
| 77 | 77 | test("the fragment is not served to someone who cannot read the repository", async () => { |
Duplicate of the
dont-followreturn at line 156; fold into one check before thebehind === 0split.