Public: anyone can read this; the crew can change it.
A fork that follows upstream shows what the last sync took, in one sentence #14093
scout/forge:scout/14067-a-fork-that-follows-upstream-shows-what → main 9 commits fork 4 threads · 4 unresolved
14 files
changed +247
−14
- docs/features/README.md
- docs/features/fork-last-sync.md
- src/actions/upstream_follow.ts
- src/actions/upstream_sync.ts
- src/core/following.ts
- src/core/fork_last_sync.ts
- src/core/migration-pins/20261116120000-fork-last-sync.pin
- src/core/migrations/20261116120000-fork-last-sync.ts
- src/tui/screens/forks.ts
- src/web/pages/following.ts
- src/web/pages/security.ts
- src/web/ui.ts
- test/follow-last-sync.test.ts
- test/tui-following.test.ts
docs/features/README.md +1
docs/features/fork-last-sync.md added +16
| @@ -0,0 +1,16 @@ | ||
| 1 | # What a fork's last sync took | |
| 2 | ||
| 3 | A fork's following card has a **Last sync** row: `3 changes from alice/app on | |
| 4 | 2026-11-16`. It is stored when the sync ran (table `fork_last_sync`, one row per | |
| 5 | fork) and read back as it was; the page never asks git. | |
| 6 | ||
| 7 | - Every path that moves the fork writes it: **Take updates**, an automatic | |
| 8 | follow of the parent's push, and a repository that follows an address. All go | |
| 9 | through `recordSync` in `src/core/fork_last_sync.ts`. | |
| 10 | - A merge counts the upstream's commits it brought, not the merge commit. | |
| 11 | - A take that found nothing new is stored too, and reads `Nothing new from | |
| 12 | alice/app on 2026-11-16`: whoever pressed Take updates gets an answer. A take | |
| 13 | that failed leaves the row alone. A fork that never synced has no row. | |
| 14 | - In the terminal, the fork's followed card (palette: the repository's forks | |
| 15 | screen) shows the same as `Took 3 changes from alice/app on 2026-11-16.` | |
| 16 | under the follow-mode sentence. |
src/actions/upstream_follow.ts +3
| @@ -84,6 +84,7 @@ import { providerForOrigin } from "../origins/credential.ts"; | ||
| 84 | 84 | import { basicHeader, gitAuthEnv, redact, secretsIn } from "../origins/credentials.ts"; |
| 85 | 85 | import { vettedEnv } from "../origins/git-mirror.ts"; |
| 86 | 86 | import { forkFollowMode } from "../core/fork_follow.ts"; |
| 87 | import { recordSync } from "../core/fork_last_sync.ts"; | |
| 87 | 88 | import { settleOntoFollowed } from "../core/upstream_settle.ts"; |
| 88 | 89 | import { openIssue } from "./issues.ts"; |
| 89 | 90 | import { migrateUrl } from "./migrate.ts"; |
| @@ -634,6 +635,7 @@ async function checkTarget(app: App, repo: Repo, follow: Target): Promise<Result | ||
| 634 | 635 | app, repo, dir, main, staged, upstreamLabel(follow.url), follow.byId, |
| 635 | 636 | forkFollowMode(app.db, repo.id) === "take-updates", |
| 636 | 637 | ); |
| 638 | if (settled.moved === "fast-forward") await recordSync(app, repo, upstreamLabel(follow.url), main, settled.tip); | |
| 637 | 639 | main = settled.tip; |
| 638 | 640 | } |
| 639 | 641 | const behind = await aheadCount(dir, main, staged); |
| @@ -751,6 +753,7 @@ async function forwardTo( | ||
| 751 | 753 | const ref = `refs/heads/${repo.defaultBranch}`; |
| 752 | 754 | if (!(await runGit(["update-ref", ref, staged, main], { cwd: dir })).ok) return false; |
| 753 | 755 | const upstream = upstreamShort(url); |
| 756 | await recordSync(app, repo, upstream, main, staged, behind); | |
| 754 | 757 | app.bus.append({ |
| 755 | 758 | kind: "push", |
| 756 | 759 | repoId: repo.id, |
src/actions/upstream_sync.ts +4
| @@ -20,6 +20,7 @@ import { listCrewRoles } from "../core/agents.ts"; | ||
| 20 | 20 | import { commitIdentity } from "../core/commit_identity.ts"; |
| 21 | 21 | import type { Repo } from "../core/repos.ts"; |
| 22 | 22 | import { getFollow, type UpstreamFollow } from "../core/upstream_follow.ts"; |
| 23 | import { recordSync } from "../core/fork_last_sync.ts"; | |
| 23 | 24 | import { settleOntoFollowed } from "../core/upstream_settle.ts"; |
| 24 | 25 | import type { User } from "../core/users.ts"; |
| 25 | 26 | import { merge, mergeable, resolveOid } from "../git/merge.ts"; |
| @@ -74,10 +75,12 @@ export async function takeFromFollowed( | ||
| 74 | 75 | const noted = (behind: number): void => target.note({ at, tip, behind, error: "" }); |
| 75 | 76 | if (settled.moved !== undefined) { |
| 76 | 77 | noted(0); |
| 78 | await recordSync(app, repo, label, main, tip); | |
| 77 | 79 | return ok({ updated: true, merged: false, from: main, to: tip }); |
| 78 | 80 | } |
| 79 | 81 | if (settled.standing?.kind !== "diverged") { |
| 80 | 82 | noted(0); |
| 83 | await recordSync(app, repo, label, main, main, 0); | |
| 81 | 84 | return ok({ updated: false, merged: false, from: main, to: main }); |
| 82 | 85 | } |
| 83 | 86 | const landed = await merge(dir, { |
| @@ -97,6 +100,7 @@ export async function takeFromFollowed( | ||
| 97 | 100 | return err(e.kind === "base_moved" ? { kind: "moved" } : { kind: "git", message: e.kind === "git" ? e.message : "unsafe" }); |
| 98 | 101 | } |
| 99 | 102 | noted(0); |
| 103 | await recordSync(app, repo, label, main, tip); | |
| 100 | 104 | app.bus.append({ |
| 101 | 105 | kind: "push", |
| 102 | 106 | repoId: repo.id, |
src/core/following.ts +6 −1
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | * so it is read here as the push it amounts to. |
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | import { recordSync } from "./fork_last_sync.ts"; | |
| 21 | 22 | import { carryApproval } from "./carry_approval.ts"; |
| 22 | 23 | import type { Database } from "bun:sqlite"; |
| 23 | 24 | import type { EventBus, ForgeEvent } from "./events.ts"; |
| @@ -402,13 +403,15 @@ export async function takeUpdates( | ||
| 402 | 403 | if (relation === undefined) return err({ kind: "git", message: "no parent" }); |
| 403 | 404 | if (expect !== undefined && relation.parentTip !== expect) |
| 404 | 405 | return err({ kind: "upstream_moved", tip: relation.parentTip, message: MOVED }); |
| 405 | if (relation.state === "synced" || relation.state === "ahead") | |
| 406 | if (relation.state === "synced" || relation.state === "ahead") { | |
| 407 | await recordSync(forge, fork, `${parent.ownerName}/${parent.name}`, relation.forkTip, relation.forkTip, 0); | |
| 406 | 408 | return ok({ |
| 407 | 409 | updated: false, |
| 408 | 410 | merged: false, |
| 409 | 411 | from: relation.forkTip, |
| 410 | 412 | to: relation.forkTip, |
| 411 | 413 | }); |
| 414 | } | |
| 412 | 415 | if (relation.state === "behind") { |
| 413 | 416 | const moved = await fastForwardFork(forge, fork, parent, author.id, expect); |
| 414 | 417 | if (moved.ok) return ok({ ...moved.value, merged: false }); |
| @@ -448,6 +451,7 @@ export async function takeUpdates( | ||
| 448 | 451 | message: landed.error.kind === "git" ? landed.error.message : "unsafe", |
| 449 | 452 | }); |
| 450 | 453 | } |
| 454 | await recordSync(forge, fork, `${parent.ownerName}/${parent.name}`, again.forkTip, tip); | |
| 451 | 455 | forge.bus.append({ |
| 452 | 456 | kind: "push", |
| 453 | 457 | repoId: fork.id, |
| @@ -625,6 +629,7 @@ export async function fastForwardFork( | ||
| 625 | 629 | ? ok({ updated: false, from: from ?? "", to }) |
| 626 | 630 | : err("diverged"); |
| 627 | 631 | const tip = synced.value.to; |
| 632 | await recordSync(forge, fork, `${parent.ownerName}/${parent.name}`, from ?? "", tip); | |
| 628 | 633 | forge.bus.append({ |
| 629 | 634 | kind: "push", |
| 630 | 635 | repoId: fork.id, |
src/core/fork_last_sync.ts added +55
| @@ -0,0 +1,55 @@ | ||
| 1 | /** What a fork's last sync with its parent took, stored when the sync ran and read as it was. */ | |
| 2 | ||
| 3 | import type { Database } from "bun:sqlite"; | |
| 4 | import { aheadCount } from "../git/merge.ts"; | |
| 5 | import { repoDir } from "../git/repos.ts"; | |
| 6 | import type { Repo } from "./repos.ts"; | |
| 7 | ||
| 8 | export interface LastSync { | |
| 9 | readonly changes: number; | |
| 10 | readonly upstream: string; | |
| 11 | readonly at: string; | |
| 12 | } | |
| 13 | ||
| 14 | export function noteLastSync(db: Database, repoId: string, s: LastSync): void { | |
| 15 | db.query( | |
| 16 | `INSERT INTO fork_last_sync (repo_id, changes, upstream, at) VALUES (?1, ?2, ?3, ?4) | |
| 17 | ON CONFLICT(repo_id) DO UPDATE SET changes = excluded.changes, upstream = excluded.upstream, at = excluded.at`, | |
| 18 | ).run(repoId, s.changes, s.upstream, s.at); | |
| 19 | } | |
| 20 | ||
| 21 | /** | |
| 22 | * A sync moved `fork`'s default branch from `from` to take everything up to `upTo`: store how many | |
| 23 | * commits that brought, once, so every path that moves a fork (a take, a followed push, a followed | |
| 24 | * address) says the same thing. A take that found nothing new is stored too (changes = 0), so the | |
| 25 | * person who pressed it reads "Nothing new" with the date they asked. | |
| 26 | */ | |
| 27 | export async function recordSync( | |
| 28 | forge: { readonly db: Database; readonly reposRoot: string }, | |
| 29 | fork: Repo, | |
| 30 | upstream: string, | |
| 31 | from: string, | |
| 32 | upTo: string, | |
| 33 | /** The count, when the caller already has it. */ | |
| 34 | known?: number, | |
| 35 | ): Promise<void> { | |
| 36 | const changes = known ?? (await aheadCount(repoDir(forge.reposRoot, fork.ownerName, fork.name), from, upTo)); | |
| 37 | noteLastSync(forge.db, fork.id, { changes, upstream, at: new Date().toISOString() }); | |
| 38 | } | |
| 39 | ||
| 40 | export function lastSyncOf(db: Database, repoId: string): LastSync | undefined { | |
| 41 | return ( | |
| 42 | db | |
| 43 | .query<LastSync, [string]>("SELECT changes, upstream, at FROM fork_last_sync WHERE repo_id = ?1") | |
| 44 | .get(repoId) ?? undefined | |
| 45 | ); | |
| 46 | } | |
| 47 | ||
| 48 | /** | |
| 49 | * What the last sync took, as a fact for a labelled row: "3 changes from alice/app on 2026-11-16". | |
| 50 | */ | |
| 51 | export const lastSyncFact = (s: LastSync): string => | |
| 52 | `${s.changes === 0 ? "Nothing new" : s.changes === 1 ? "1 change" : `${s.changes} changes`} from ${s.upstream} on ${s.at.slice(0, 10)}`; | |
| 53 | ||
| 54 | /** The same as one sentence, for the terminal: "Took 3 changes from alice/app on 2026-11-16." */ | |
| 55 | export const lastSyncWords = (s: LastSync): string => `${s.changes === 0 ? "" : "Took "}${lastSyncFact(s)}.`; |
src/core/migration-pins/20261116120000-fork-last-sync.pin added +1
| @@ -0,0 +1,1 @@ | ||
| 1 | 0a0ae72bd371f43ae6cdbd90c0d77a43a0708022b473177c4614eafdb9cb3f41 |
src/core/migrations/20261116120000-fork-last-sync.ts added +10
| @@ -0,0 +1,10 @@ | ||
| 1 | // What a fork's last update from its parent took (#14067): one row per fork, written when the sync | |
| 2 | // runs and replaced by the next. Additive. | |
| 3 | export default ` | |
| 4 | CREATE TABLE fork_last_sync ( | |
| 5 | repo_id TEXT PRIMARY KEY REFERENCES repo(id) ON DELETE CASCADE, | |
| 6 | changes INTEGER NOT NULL CHECK (changes >= 0), | |
| 7 | upstream TEXT NOT NULL, | |
| 8 | at TEXT NOT NULL | |
| 9 | ); | |
| 10 | `; |
src/tui/screens/forks.ts +9 −2
| @@ -25,6 +25,7 @@ import { FOLLOW_CHOICES, FOLLOW_PHRASE, FOLLOW_WORD, FOLLOWS_NOTHING, followChoi | ||
| 25 | 25 | import { FOLLOW_MODE_REFUSALS, convergeWords, followModeOf, followStanding, 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 | import { lastSyncOf, lastSyncWords } from "../../core/fork_last_sync.ts"; | |
| 28 | 29 | import { forkOffers } from "../../core/fork_offers.ts"; |
| 29 | 30 | import { agoWords } from "../../actions/follow_words.ts"; |
| 30 | 31 | import { STANDING_EVENTS } from "../../core/standing_events.ts"; |
| @@ -95,6 +96,8 @@ export function followingRows( | ||
| 95 | 96 | relation: ForkRelation | undefined, |
| 96 | 97 | converge: Converge | undefined, |
| 97 | 98 | mode?: ForkFollowMode, |
| 99 | /** What the last sync took (`lastSyncWords`), when one is stored. */ | |
| 100 | lastSync?: string, | |
| 98 | 101 | ): ForkRow[] { |
| 99 | 102 | if (relation === undefined) return []; |
| 100 | 103 | const { parent } = relation; |
| @@ -116,6 +119,7 @@ export function followingRows( | ||
| 116 | 119 | heading: "", |
| 117 | 120 | }, |
| 118 | 121 | ...(mode === undefined ? [] : [{ repo: parent, name: ` ${FOLLOW_CHOICES[mode].sentence}`, words: "", heading: "" }]), |
| 122 | ...(lastSync === undefined ? [] : [{ repo: parent, name: ` ${lastSync}`, words: "", heading: "" }]), | |
| 119 | 123 | ...(converge === undefined |
| 120 | 124 | ? [] |
| 121 | 125 | : [ |
| @@ -175,6 +179,7 @@ export function forksScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 175 | 179 | let followed: ReturnType<typeof followedAs> | undefined; |
| 176 | 180 | let open: Pull | undefined; |
| 177 | 181 | let mode: ForkFollowMode | undefined; |
| 182 | let synced: string | undefined; | |
| 178 | 183 | /** The one plain line the page and MCP say: how this fork follows, and when it last took. */ |
| 179 | 184 | let standing: string | undefined; |
| 180 | 185 | /** |
| @@ -247,7 +252,9 @@ export function forksScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 247 | 252 | standing = await followStanding(f.app, repo, f.user); |
| 248 | 253 | failed = getRepoById(f.db, repo.id)?.origin?.fetchError ?? ""; |
| 249 | 254 | mode = relation === undefined ? undefined : await followModeOf(f.app, repo); |
| 250 | following = followingRows(relation, converge, mode); | |
| 255 | const last = lastSyncOf(f.db, repo.id); | |
| 256 | synced = last === undefined ? undefined : lastSyncWords(last); | |
| 257 | following = followingRows(relation, converge, mode, synced); | |
| 251 | 258 | offered = forkOffers(f.db, repo, f.user).map((o) => ({ |
| 252 | 259 | repo, |
| 253 | 260 | name: `offered #${o.number} ${o.title}`, |
| @@ -275,7 +282,7 @@ export function forksScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 275 | 282 | // The converge issue just opened or found is the line Enter opens. |
| 276 | 283 | const e = took.ok ? undefined : took.error; |
| 277 | 284 | if (typeof e === "object" && e.kind === "conflict" && "converge" in e && relation !== undefined) { |
| 278 | following = followingRows(relation, e.converge, mode); | |
| 285 | following = followingRows(relation, e.converge, mode, synced); | |
| 279 | 286 | state.index = following.length - 1; |
| 280 | 287 | } |
| 281 | 288 | ctx.toast(words.message, words.tone === "danger" ? "danger" : "default"); |
src/web/pages/following.ts +7 −1
| @@ -29,6 +29,7 @@ import { | ||
| 29 | 29 | convergeState, |
| 30 | 30 | type Converge, |
| 31 | 31 | } from "../../crew/converge.ts"; |
| 32 | import { lastSyncFact, lastSyncOf } from "../../core/fork_last_sync.ts"; | |
| 32 | 33 | import { MINE_ANCHOR, type Lineage, type LineageNode } from "../../core/following.ts"; |
| 33 | 34 | import { |
| 34 | 35 | parentReleases, |
| @@ -49,7 +50,7 @@ import { proposesViaFork } from "../../origins/fork-route.ts"; | ||
| 49 | 50 | import { field, readForm } from "../form.ts"; |
| 50 | 51 | import { html, when, type Html } from "../html.ts"; |
| 51 | 52 | import { flashOrJson } from "../layout.ts"; |
| 52 | import { badge, btn, icon, row, time, type Tone } from "../ui.ts"; | |
| 53 | import { badge, btn, icon, row, statusRow, time, type Tone } from "../ui.ts"; | |
| 53 | 54 | import { disconnectedOn } from "./frozen.ts"; |
| 54 | 55 | |
| 55 | 56 | /** The first node (parents before children) the viewer owns and is not looking at. */ |
| @@ -421,6 +422,11 @@ export function followingCard( | ||
| 421 | 422 | } |
| 422 | 423 | if (parent.detached === null && relation.action !== "none") |
| 423 | 424 | prose.push(html`<p class="muted small">${relation.words}</p>`); |
| 425 | const lastSync = lastSyncOf(ctx.app.db, repo.id); | |
Both doors: this sentence is page-only. Add the matching terminal screen in src/tui/ and docs/features/<name>.md. The |
||
| 426 | if (lastSync !== undefined) | |
| 427 | prose.push( | |
| 428 | html`<dl class="status-rows" data-last-sync>${statusRow("Last sync", html`${lastSyncFact(lastSync)}`)}</dl>`, | |
| 429 | ); | |
| 424 | 430 | if (foot !== null) prose.push(html`<p class="muted small">${foot}</p>`); |
| 425 | 431 | const words = followModeWords(following.mode, parentName); |
| 426 | 432 | prose.push( |
src/web/pages/security.ts +3 −10
| @@ -26,7 +26,9 @@ import { notFoundPage, settingsLayout, signInFirst } from "../chrome.ts"; | ||
| 26 | 26 | import { field, readForm } from "../form.ts"; |
| 27 | 27 | import { html, type Html } from "../html.ts"; |
| 28 | 28 | import { flashTo, page } from "../layout.ts"; |
| 29 | import { badge, btn, time } from "../ui.ts"; | |
| 29 | import { badge, btn, statusRow, time } from "../ui.ts"; | |
| 30 | ||
| 31 | export { statusRow }; | |
| 30 | 32 | import { accountSections } from "./origins.ts"; |
| 31 | 33 | |
| 32 | 34 | const DAY_MS = 86_400_000; |
| @@ -107,15 +109,6 @@ function newAccountsRow(db: Database, nowMs: number): Html { | ||
| 107 | 109 | ); |
| 108 | 110 | } |
| 109 | 111 | |
| 110 | /** One line of the page: what it is, how it stands, what you can do. */ | |
| 111 | export function statusRow(label: string, state: Html, action: Html | null = null, id?: string): Html { | |
| 112 | return html`<div class="status-row" ${id === undefined ? null : html`id="${id}"`}> | |
| 113 | <dt>${label}</dt> | |
| 114 | <dd>${state}</dd> | |
| 115 | <dd class="status-act">${action}</dd> | |
| 116 | </div>`; | |
| 117 | } | |
| 118 | ||
| 119 | 112 | const shieldButton = (to: ShieldState, label: string, variant?: "primary"): Html => |
| 120 | 113 | html`<form method="post" action="/settings/security/shield" class="inline"> |
| 121 | 114 | <input type="hidden" name="state" value="${to}" /> |
src/web/ui.ts +9
| @@ -1488,3 +1488,12 @@ export function tlComment(body: Html): Html { | ||
| 1488 | 1488 | } |
| 1489 | 1489 | |
| 1490 | 1490 | export { when }; |
| 1491 | ||
| 1492 | /** One line of a `status-rows` list: what it is, how it stands, what you can do. */ | |
| 1493 | export function statusRow(label: string, state: Html, action: Html | null = null, id?: string): Html { | |
| 1494 | return html`<div class="status-row" ${id === undefined ? null : html`id="${id}"`}> | |
| 1495 | <dt>${label}</dt> | |
| 1496 | <dd>${state}</dd> | |
| 1497 | <dd class="status-act">${action}</dd> | |
| 1498 | </div>`; | |
| 1499 | } |
test/follow-last-sync.test.ts added +117
| @@ -0,0 +1,117 @@ | ||
| 1 | /** A fork that follows its parent says what the last sync took, stored when it ran (#14067). */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { takeUpdates } from "../src/actions/forks.ts"; | |
| 7 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; | |
| 8 | import { createApp, type App } from "../src/app.ts"; | |
| 9 | import { setForkFollowMode } from "../src/core/fork_follow.ts"; | |
| 10 | import { lastSyncOf, lastSyncWords } from "../src/core/fork_last_sync.ts"; | |
| 11 | import { getRepo, type Repo } from "../src/core/repos.ts"; | |
| 12 | import { createSession } from "../src/core/sessions.ts"; | |
| 13 | import { createUser, type User } from "../src/core/users.ts"; | |
| 14 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 15 | import { promote } from "./helpers/members.ts"; | |
| 16 | ||
| 17 | let dataDir: string; | |
| 18 | let app: App; | |
| 19 | let servers: Servers; | |
| 20 | let alice: User; | |
| 21 | let bob: User; | |
| 22 | let lib: Repo; | |
| 23 | let fork: Repo; | |
| 24 | let cookie: string; | |
| 25 | ||
| 26 | beforeAll(async () => { | |
| 27 | dataDir = await mkdtemp(join(tmpdir(), "forge-last-sync-")); | |
| 28 | app = createApp({ dataDir, port: 0 }); | |
| 29 | servers = await serve(app); | |
| 30 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 31 | const b = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }); | |
| 32 | if (!a.ok || !b.ok) throw new Error("user"); | |
| 33 | alice = a.value; | |
| 34 | bob = b.value; | |
| 35 | promote(app.db, bob); | |
| 36 | const r = await createRepo(app, alice, { name: "lib", visibility: "public" }); | |
| 37 | if (!r.ok) throw new Error("repo"); | |
| 38 | lib = r.value; | |
| 39 | await commitToBranch(app, alice, lib, { message: "Start", files: [{ path: "README.md", content: "# lib\n" }] }); | |
| 40 | const f = await forkRepo(app, bob, lib); | |
| 41 | if (!f.ok) throw new Error("fork"); | |
| 42 | fork = getRepo(app.db, "bob", "lib")!; | |
| 43 | // Pushes would move the fork on their own; hold that so the take is the sync. | |
| 44 | setForkFollowMode(app.db, fork.id, "dont-follow"); | |
| 45 | cookie = `forge_session=${createSession(app.db, bob.id).token}`; | |
| 46 | }, 60_000); | |
| 47 | ||
| 48 | afterAll(async () => { | |
| 49 | servers.stop(); | |
| 50 | app.close(); | |
| 51 | await rm(dataDir, { recursive: true, force: true }); | |
| 52 | }); | |
| 53 | ||
| 54 | const page = async () => (await (await fetch(`${servers.url}/bob/lib`, { headers: { cookie } })).text()); | |
| 55 | ||
| 56 | test("the words, one change and many", () => { | |
| 57 | expect(lastSyncWords({ changes: 3, upstream: "alice/lib", at: "2026-11-16T10:00:00.000Z" })).toBe("Took 3 changes from alice/lib on 2026-11-16."); | |
| 58 | expect(lastSyncWords({ changes: 1, upstream: "alice/lib", at: "2026-11-16T10:00:00.000Z" })).toBe("Took 1 change from alice/lib on 2026-11-16."); | |
| 59 | expect(lastSyncWords({ changes: 0, upstream: "alice/lib", at: "2026-11-16T10:00:00.000Z" })).toBe("Nothing new from alice/lib on 2026-11-16."); | |
| 60 | }); | |
| 61 | ||
| 62 | test("no row, no sentence: a fork that never synced says nothing", async () => { | |
| 63 | expect(lastSyncOf(app.db, fork.id)).toBeUndefined(); | |
| 64 | expect(await page()).not.toContain("data-last-sync"); | |
| 65 | }); | |
| 66 | ||
| 67 | test("a take that moved three commits is stored and shown as a Last sync row", async () => { | |
| 68 | for (const n of [1, 2, 3]) | |
| 69 | await commitToBranch(app, alice, lib, { message: `c${n}`, files: [{ path: `f${n}.txt`, content: `${n}\n` }] }); | |
| 70 | const took = await takeUpdates(app, bob, fork); | |
| 71 | expect(took.ok && took.value.updated).toBe(true); | |
| 72 | const stored = lastSyncOf(app.db, fork.id)!; | |
| 73 | expect(stored.changes).toBe(3); | |
| 74 | expect(stored.upstream).toBe("alice/lib"); | |
| 75 | const html = await page(); | |
| 76 | expect(html).toContain(`3 changes from alice/lib on ${stored.at.slice(0, 10)}`); | |
| 77 | expect(html).toContain("<dt>Last sync</dt>"); | |
| 78 | }, 60_000); | |
| 79 | ||
| 80 | test("a take that found nothing new is stored as Nothing new, with the date it ran", async () => { | |
| 81 | const before = lastSyncOf(app.db, fork.id)!; | |
| 82 | const again = await takeUpdates(app, bob, fork); | |
| 83 | expect(again.ok && again.value.updated).toBe(false); | |
| 84 | const after = lastSyncOf(app.db, fork.id)!; | |
| 85 | expect(after.changes).toBe(0); | |
| 86 | expect(after.at > before.at).toBe(true); | |
| 87 | expect(await page()).toContain(`Nothing new from alice/lib on ${after.at.slice(0, 10)}`); | |
| 88 | }, 60_000); | |
| 89 | ||
| 90 | test("a failed take leaves the row as it was", async () => { | |
| 91 | const before = lastSyncOf(app.db, fork.id)!; | |
| 92 | await commitToBranch(app, alice, lib, { message: "e1", files: [{ path: "e1.txt", content: "1\n" }] }); | |
| 93 | const refused = await takeUpdates(app, bob, fork, "0".repeat(40)); | |
| 94 | expect(refused.ok).toBe(false); | |
| 95 | expect(lastSyncOf(app.db, fork.id)).toEqual(before); | |
| 96 | await takeUpdates(app, bob, fork); | |
| 97 | }, 60_000); | |
| 98 | ||
| 99 | test("a merge counts the parent's commits, not the merge", async () => { | |
| 100 | await commitToBranch(app, bob, fork, { message: "mine", files: [{ path: "mine.txt", content: "m\n" }] }); | |
| 101 | for (const n of [1, 2]) | |
| 102 | await commitToBranch(app, alice, lib, { message: `d${n}`, files: [{ path: `g${n}.txt`, content: `${n}\n` }] }); | |
| 103 | const took = await takeUpdates(app, bob, fork); | |
| 104 | expect(took.ok && took.value.merged).toBe(true); | |
| 105 | expect(lastSyncOf(app.db, fork.id)!.changes).toBe(2); | |
| 106 | }, 60_000); | |
| 107 | ||
| 108 | test("a followed push that fast-forwards the fork writes the row too", async () => { | |
| 109 | setForkFollowMode(app.db, fork.id, "take-updates"); | |
| 110 | // recordSync runs before the fork's own push event, so that event is the signal. | |
| 111 | const moved = new Promise<void>((done) => { | |
| 112 | const off = app.bus.subscribe((e) => { if (e.kind === "push" && e.repoId === fork.id) { off(); done(); } }, "local"); | |
| 113 | }); | |
| 114 | await commitToBranch(app, alice, lib, { message: "auto", files: [{ path: "auto.txt", content: "a\n" }] }); | |
| 115 | await moved; | |
| 116 | expect(lastSyncOf(app.db, fork.id)!.changes).toBe(1); | |
| 117 | }, 60_000); |
test/tui-following.test.ts +6
| @@ -36,6 +36,12 @@ describe("followingRows", () => { | ||
| 36 | 36 | expect(rows[0]!.repo).toBe(parent); |
| 37 | 37 | }); |
| 38 | 38 | |
| 39 | test("the last sync's sentence is a row under the relation, and absent without one", () => { | |
| 40 | const sentence = "Took 3 changes from alice/app on 2026-11-16."; | |
| 41 | expect(followingRows(at("synced", 0, 0), undefined, undefined, sentence).map((r) => r.name)).toContain(` ${sentence}`); | |
| 42 | expect(followingRows(at("synced", 0, 0), undefined)).toHaveLength(1); | |
| 43 | }); | |
| 44 | ||
| 39 | 45 | test("in step says so; a frozen parent never claims it", () => { |
| 40 | 46 | expect(followingRows(at("synced", 0, 0), undefined)[0]!.words).toBe("in step"); |
| 41 | 47 | const frozen = { ...at("synced", 0, 0), parent: { ...parent, detached: { detachedAt: null } } } as ForkRelation; |
new above
offline
Principle 1/the issue: this guard is what drops the "Nothing new" sentence. Write the row for changes = 0 as well (the CHECK already allows 0) and have lastSyncFact/lastSyncWords say "Nothing new from X on DATE" for it; the no-op test then asserts the date moves and the words read Nothing new.