Public: anyone can read this; the crew can change it.

A fork's standing card updates when a sync lands, with no reload and no polling #15308

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/15305-a-fork-s-standing-card-updates-when-a-sy → main 6 commits fork 2 threads · 2 unresolved

  • Merged. mason/15305-a-fork-s-standing-card-updates-when-a-sy was merged into main as f3b56c1.

Review

Sign in to review this change.
11 files changed +270 −45
docs/features/forge-origin.md +1 −1
@@ -59,7 +59,7 @@ One contract written for every shape a network takes: a follower, a fork, a mirr
5959
6060 **Where you meet it.** A fork's standing against its parent now names the one action that reconciles it (`none`, `fast-forward`, `offer`, `merge`, `keep-both`) and says it in words: in the `following` API read (`action`, `words`), on the fork's home card, in the terminal's forks screen (`Forks` → the follows row), and in MCP `following`. Taking the parent's work (`fastForwardFork`, which every push to the parent triggers) goes through `syncLink`, so it is compare-and-swap, stages the parent's tip at `refs/following/<branch>`, and refuses a divergence. `source` is always a repository path computed from rows, never text a person typed. Syncs into the same repository's stage ref take turns, so a push's follow-on and a person's click at once never race on that ref (test: "syncs at once into one stage ref take turns").
6161
62 `test/sync-shapes.test.ts` walks each shape with real git between bare repositories on one machine. `scripts/forge-compat-lab/shapes.ts` holds the same shapes as lab cells between two real forges, but **they have not run yet**: they run only when asked for (`LAB_ONLY=shapes scripts/forge-compat-lab.sh`) and are not proven until a docker host has walked them. Not shown either: that a sync at one door reaches a web viewer live (the card reads the standing on each load; nothing pushes it). Each fork's link to its parent wears one word on the flows view (`linkWord`, `src/flows/view.ts`): following, behind N, conflicted, severed, or quiet (not read lately, or taking but not taken within the period; never green). It reads the standing the card already kept, with no git and no polling (test: `test/flows-link-word.test.ts`). Not yet wired: the schedule probe, and the crew taking the action on autonomous repositories (the rest of #9451).
62 `test/sync-shapes.test.ts` walks each shape with real git between bare repositories on one machine. `scripts/forge-compat-lab/shapes.ts` holds the same shapes as lab cells between two real forges, but **they have not run yet**: they run only when asked for (`LAB_ONLY=shapes scripts/forge-compat-lab.sh`) and are not proven until a docker host has walked them. A sync at one door reaches a web viewer live: a sync that moves a fork's branch, or is refused, appends one `fork.linked` event on the fork (`announceLink`, `src/core/following.ts`) carrying the link word and its count, and nothing else. It travels the page's one `/events` stream to those who may read the fork, and the fork's home card and the flows view (`/flows/map`) swap the word in place from what the server renders (test: `test/fork-linked-event.test.ts`). Each fork's link to its parent wears one word on the flows view (`linkWord`, `src/flows/view.ts`): following, behind N, conflicted, severed, or quiet (not read lately, or taking but not taken within the period; never green). It reads the standing the card already kept, with no git and no polling (test: `test/flows-link-word.test.ts`). Not yet wired: the schedule probe, and the crew taking the action on autonomous repositories (the rest of #9451).
6363
6464 ## A downstream forge as a peer (#9451)
6565
src/core/event_audience.ts +2
@@ -80,6 +80,8 @@ const READER_KINDS: ReadonlySet<string> = new Set([
8080 "fork.diverged",
8181 // A fork's follow of upstream took or met a conflict: counts and a pull number, as its page says.
8282 "fork.followed",
83 // A fork's new link word and its count: what its card says, to those who may read the fork.
84 "fork.linked",
8385 "push",
8486 "account.parent_linked",
8587 "account.parent_unlinked",
src/core/following.ts +42 −2
@@ -44,7 +44,8 @@ import { readTips } from "../git/tips.ts";
4444 import { repoDir } from "../git/repos.ts";
4545 import { combine } from "../git/combined.ts";
4646 import { fromKeptFork } from "./landing_kind.ts";
47 import { forkFollowMode, forkFollowModes, FORK_DEFAULT_MODE, type ForkFollowMode } from "./fork_follow.ts";
47 import { forkFollowMode, forkFollowModes, lastTookAt, FORK_DEFAULT_MODE, type ForkFollowMode } from "./fork_follow.ts";
48 import { linkWord, sayLink } from "../flows/link_word.ts";
4849 import { coveredByParent } from "./fork_reach.ts";
4950 import { createLog } from "../kernel/log.ts";
5051 import { err, ok, type Result } from "../kernel/result.ts";
@@ -418,7 +419,10 @@ export async function takeUpdates(
418419 const again = await forkRelation(forge, fork, parent);
419420 if (again === undefined || again.state !== "diverged")
420421 return err({ kind: "moved" });
421 if (!again.clean) return err({ kind: "conflict", files: again.conflicts });
422 if (!again.clean) {
423 await announceLink(forge, fork, parent);
424 return err({ kind: "conflict", files: again.conflicts });
425 }
422426 const parentDir = repoDir(forge.reposRoot, parent.ownerName, parent.name);
423427 const forkDir = repoDir(forge.reposRoot, fork.ownerName, fork.name);
424428 // The parent's objects are visible through the alternates already; the
@@ -458,6 +462,7 @@ export async function takeUpdates(
458462 merged: true,
459463 },
460464 });
465 await announceLink(forge, fork, parent);
461466 return ok({
462467 updated: true,
463468 merged: true,
@@ -599,6 +604,41 @@ export async function fastForwardFork(
599604 actorId: string | undefined,
600605 /** The parent tip the caller was shown: the fetch that lands any other moves nothing. */
601606 expect?: string,
607 ): Promise<Result<ForkSync, "diverged" | "upstream_moved">> {
608 const synced = await fastForwardOnce(forge, fork, parent, actorId, expect);
609 // Moved, offered, merge-able or refused: the fork's link word may have changed. A level fork's
610 // has not, and a sync that never reached the parent says nothing.
611 // A fast-forward that moved the branch left the fork level: nothing to compare again.
612 if (synced.ok && synced.value.updated) await announceLink(forge, fork, parent, ["synced", 0, 0, true, []]);
613 else if (synced.ok ? synced.value.to !== synced.value.from : synced.error === "diverged")
614 await announceLink(forge, fork, parent);
615 return synced;
616 }
617
618 /**
619 * One small event on the fork naming its new link word (`linkWord`), for the page's one stream:
620 * the fork's home card and the flows view swap the word where it stands. It carries the word and
621 * the count and nothing else, so what a viewer may learn from it is what the card already says;
622 * the stream sends it only to those who may read the fork.
623 */
624 export async function announceLink(forge: Following, fork: Repo, parent: Repo, known?: Standing): Promise<void> {
625 let standing = known;
626 if (standing === undefined) {
627 const relation = await forkRelation(forge, fork, parent);
628 if (relation === undefined) return;
629 standing = [relation.state, relation.behind, relation.ahead, relation.clean, relation.conflicts];
630 }
631 const { word, behind } = linkWord(forkFollowMode(forge.db, fork.id), standing, lastTookAt(forge.db, fork.id), Date.now());
632 forge.bus.append({ kind: "fork.linked", repoId: fork.id, actorId: undefined, payload: { word, behind, says: sayLink(word, behind) } });
633 }
634
635 async function fastForwardOnce(
636 forge: Following,
637 fork: Repo,
638 parent: Repo,
639 actorId: string | undefined,
640 /** The parent tip the caller was shown: the fetch that lands any other moves nothing. */
641 expect?: string,
602642 ): Promise<Result<ForkSync, "diverged" | "upstream_moved">> {
603643 const parentDir = repoDir(forge.reposRoot, parent.ownerName, parent.name);
604644 const forkDir = repoDir(forge.reposRoot, fork.ownerName, fork.name);
src/core/standing_events.ts +1 −1
@@ -3,4 +3,4 @@
33 * terminal's forks screen. `repo.synced` is a mirror's sync that ended in failure or recovered
44 * from one.
55 */
6 export const STANDING_EVENTS: readonly string[] = ["push", "repo.synced", "repo.following", "repo.upstream_checked", "fork.followed"];
6 export const STANDING_EVENTS: readonly string[] = ["push", "repo.synced", "repo.following", "repo.upstream_checked", "fork.followed", "fork.linked"];
src/flows/view.ts +4 −29
@@ -12,47 +12,22 @@ import { canAdmin, canRead, canWrite, getRepoById, repoDatesFor, visibleForks, t
1212 import type { User } from "../core/users.ts";
1313 import { aheadWords, parseAhead } from "../origins/ahead.ts";
1414 import { keptStanding } from "../core/following.ts";
15 import { linkWord, sayLink, STALE_MS, type LinkWord } from "./link_word.ts";
1516 import { counts, lastScanAt } from "../checks/scan_store.ts";
1617
17 /**
18 * A followed link is stale when its last head comparison is older than this (three follow periods).
19 */
20 export const STALE_MS = 3 * 30 * 60_000;
21
2218 /**
2319 * How a link stands: `ok` level, `behind` has news, `diverged` both moved, `unread` could not be
2420 * read, `stale` not read lately, `off` not following, `none` nothing to compare.
2521 */
2622 export type Health = "ok" | "behind" | "diverged" | "unread" | "stale" | "off" | "none";
2723
28 /** The one word a fork's upstream link wears on the flows view. */
29 export type LinkWord = "following" | "behind" | "conflicted" | "severed" | "quiet";
30
3124 /**
32 * A fork's link to its parent, from the standing already kept (no git, no polling). `standing` is
33 * undefined when nothing has counted the two tips lately, and a link nobody has read is `quiet`,
34 * never green; so is a taking fork that is behind and has not taken within the period.
25 * A followed link is stale when its last head comparison is older than this (three follow periods).
3526 */
36 export function linkWord(
37 mode: string,
38 standing: readonly [string, number, number, boolean, readonly string[]] | undefined,
39 tookAt: string | null,
40 now: number,
41 ): { word: LinkWord; behind: number } {
42 if (mode === "dont-follow") return { word: "severed", behind: 0 };
43 if (standing === undefined) return { word: "quiet", behind: 0 };
44 const [state, behind, , clean] = standing;
45 if (state === "diverged" && !clean) return { word: "conflicted", behind };
46 if (behind > 0) {
47 const idle = mode === "take-updates" && (tookAt === null || now - Date.parse(tookAt) > STALE_MS);
48 return { word: idle ? "quiet" : "behind", behind };
49 }
50 return { word: "following", behind: 0 };
51 }
27 export { STALE_MS, linkWord, type LinkWord };
5228
5329 /** The word as said: `following`, `behind 3`, `conflicted`, `severed`, `quiet`. */
54 export const linkText = (l: Pick<FlowLine, "link" | "behindBy">): string =>
55 l.link === undefined ? "" : l.link === "behind" ? `behind ${l.behindBy ?? 0}` : l.link;
30 export const linkText = (l: Pick<FlowLine, "link" | "behindBy">): string => (l.link === undefined ? "" : sayLink(l.link, l.behindBy ?? 0));
5631
5732 const LINK_HEALTH: Record<LinkWord, Health> = { following: "ok", behind: "behind", conflicted: "diverged", severed: "off", quiet: "stale" };
5833
src/http/server.ts +2 −1
@@ -206,7 +206,7 @@ import { reconnectSubmit } from "../web/pages/frozen.ts";
206206 import { activityAtom, changelogAtom, exploreAtom, feedJson } from "../web/feeds.ts";
207207 import { auditCsv, auditPage, auditProbeSubmit } from "../web/pages/audit.ts";
208208 import { apiPage, appApiPage } from "../web/pages/api.ts";
209 import { flowsCheck, flowsPage, flowsProbe, flowsUpdate } from "../web/pages/flows.ts";
209 import { flowsCheck, flowsMap, flowsPage, flowsProbe, flowsUpdate } from "../web/pages/flows.ts";
210210 import { findingAccept, findingsPage } from "../web/pages/findings.ts";
211211 import { queueCeiling, queueDefer, queuePage, queueSwitch } from "../web/pages/queue.ts";
212212 import { chapterAct, chapterPage, chaptersPage } from "../web/pages/chapters.ts";
@@ -1499,6 +1499,7 @@ export function buildRouter(): Router<Handler> {
14991499 router.add("POST", "/:owner/:name/week", weekSubmit);
15001500 router.add("POST", "/:owner/:name/issues/:number/first", firstSubmit);
15011501 router.add("GET", "/:owner/:name/flows", flowsPage);
1502 router.add("GET", "/:owner/:name/flows/map", flowsMap);
15021503 router.add("POST", "/:owner/:name/flows/check", flowsCheck);
15031504 router.add("POST", "/:owner/:name/flows/probe", flowsProbe);
15041505 router.add("POST", "/:owner/:name/flows/update", flowsUpdate);
src/web/pages/flows.ts +36 −9
@@ -22,6 +22,9 @@ import { field, readForm } from "../form.ts";
2222 import { html, type Html } from "../html.ts";
2323 import { flashTo, page } from "../layout.ts";
2424 import { badge, btn, type Tone, row, time } from "../ui.ts";
25 import { liveRegionsJs } from "../client.ts";
26 import { fragment, missingFragment } from "../layout.ts";
27 import type { Repo } from "../../core/repos.ts";
2528
2629 export const lineRow = (l: FlowLine): Html =>
2730 row({
@@ -62,15 +65,17 @@ export function flowMap(name: string, inbound: readonly Html[], packages: readon
6265 </div>`;
6366 }
6467
65 // GET /:owner/:name/flows
66 export async function flowsPage(ctx: Ctx): Promise<Response> {
67 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
68 const repo = loadRepo(ctx);
69 if (!repo) return notFoundPage(ctx);
70 const rendering = performance.now();
68 /** The kinds that move a link word: a sync that landed or was refused, and a check of the heads. */
69 const LINK_LIVE = "fork.linked,push,repo.following,repo.links_probed";
70
71 /**
72 * The picture as a live region of the page's one stream: it answers for itself at `/flows/map`, and
73 * watches this repository's own events: the word is on the fork's own flows page, and `fork.linked`
74 * is appended on the fork.
75 */
76 async function flowRegion(ctx: Ctx, repo: Repo): Promise<Html> {
7177 const flows = readFlows(ctx.app.db, repo, ctx.auth.user, Date.now(), ctx.app.reposRoot);
7278 const deps = readRadar(ctx.app.db, repo.id, await pinsOf(ctx.app, repo));
73 const admin = mayStartRadar(ctx.app, repo, ctx.auth.user);
7479 const writer = ctx.auth.user !== undefined && ctx.auth.user.kind !== "agent" && canWrite(ctx.app.db, repo, ctx.auth.user);
7580 const depRows = deps.map((d) =>
7681 row({
@@ -82,14 +87,36 @@ export async function flowsPage(ctx: Ctx): Promise<Response> {
8287 : {}),
8388 }),
8489 );
90 return html`<div id="flow-links" data-live="${LINK_LIVE}" data-live-repo="${repo.ownerName}/${repo.name}" data-live-src="${repoBase(repo)}/flows/map">${flowMap(repo.name, flows.inbound.map(lineRow), depRows, flows.outbound.map(lineRow))}</div>`;
91 }
92
93 // GET /:owner/:name/flows
94 export async function flowsPage(ctx: Ctx): Promise<Response> {
95 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
96 const repo = loadRepo(ctx);
97 if (!repo) return notFoundPage(ctx);
98 const rendering = performance.now();
99 const admin = mayStartRadar(ctx.app, repo, ctx.auth.user);
85100 const body = html`${repoHeader(ctx, repo, "flows", { compact: true, ownTitle: true })}
86101 ${pageHead("Flows", { sub: "What comes in on the left, what goes out on the right." })}
87 ${flowMap(repo.name, flows.inbound.map(lineRow), depRows, flows.outbound.map(lineRow))}
102 ${await flowRegion(ctx, repo)}
88103 ${admin
89104 ? html`<form method="post" action="${repoBase(repo)}/flows/probe" class="mt">${btn("Compare heads now", { variant: "secondary" })}</form>
90105 <form method="post" action="${repoBase(repo)}/flows/check" class="mt">${btn("Read upstream releases now", { variant: "secondary" })}</form>`
91106 : null}`;
92 const response = page({ ctx, title: `Flows · ${repo.name}`, crumbs: crumbsFor(repo), palette: repoPalette(ctx, repo), body });
107 const response = page({ ctx, title: `Flows · ${repo.name}`, crumbs: crumbsFor(repo), palette: repoPalette(ctx, repo), body, scriptJs: liveRegionsJs });
108 notePhase(ctx.request, "render", performance.now() - rendering);
109 return response;
110 }
111
112 // GET /:owner/:name/flows/map — the region alone, for the page's live stream; 404 to a viewer who
113 // cannot read the repository.
114 export async function flowsMap(ctx: Ctx): Promise<Response> {
115 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
116 const repo = loadRepo(ctx);
117 if (!repo) return missingFragment(ctx.request);
118 const rendering = performance.now();
119 const response = fragment(await flowRegion(ctx, repo), { request: ctx.request });
93120 notePhase(ctx.request, "render", performance.now() - rendering);
94121 return response;
95122 }
src/web/pages/fork-standing.ts +16 −1
@@ -9,6 +9,10 @@
99 */
1010
1111 import { followWords } from "../../actions/follow.ts";
12 import { keptStanding } from "../../core/following.ts";
13 import { forkFollowMode, lastTookAt } from "../../core/fork_follow.ts";
14 import { linkWord, sayLink } from "../../flows/link_word.ts";
15 import { getRepoById } from "../../core/repos.ts";
1216 import type { Repo } from "../../core/repos.ts";
1317 import { STANDING_EVENTS } from "../../core/standing_events.ts";
1418 import { getFollow } from "../../core/upstream_follow.ts";
@@ -41,6 +45,17 @@ function failedLine(repo: Repo): Html | null {
4145 return html`<div class="small" data-sync-failed role="status">${icon("alert")} The last sync failed: ${error}</div>`;
4246 }
4347
48 /**
49 * The fork's link word (`linkWord`), read from the standing already kept, then a separator; the
50 * event `fork.linked` makes the region ask for it again. Nothing for a repository with no parent.
51 */
52 function wordOf(ctx: Ctx, repo: Repo): Html | null {
53 const parent = repo.forkParentId === null ? undefined : getRepoById(ctx.app.db, repo.forkParentId);
54 if (parent === undefined) return null;
55 const { word, behind } = linkWord(forkFollowMode(ctx.app.db, repo.id), keptStanding(ctx.app, repo, parent), lastTookAt(ctx.app.db, repo.id), Date.now());
56 return html`<strong data-link-word="${word}">${sayLink(word, behind)}</strong> · `;

Principle 1: this word is printed and then followed by words that say the same thing. One sentence, not two.

57 }
58
4459 /**
4560 * The block's lines: the sync failure, then the checks' own words, and the plain standing where
4661 * they are silent.
@@ -52,7 +67,7 @@ async function lines(ctx: Ctx, repo: Repo): Promise<Html> {
5267 const plain =
5368 words === undefined
5469 ? null
55 : html`<div class="small muted" data-follow-standing>${icon("sync")} <a href="${repoBase(repo)}/forks#following">${words}</a></div>`;
70 : html`<div class="small muted" data-follow-standing>${icon("sync")} ${wordOf(ctx, repo)}<a href="${repoBase(repo)}/forks#following">${words}</a></div>`;
5671 return html`${failedLine(repo)}${behind}${ahead}${behind === null && ahead === null ? plain : null}`;
5772 }
5873
test/fork-linked-event.test.ts added +130
@@ -0,0 +1,130 @@
1 /**

No test covers the takeUpdates merge and conflict announcements (keep-both, conflict). Remove those calls and the suite stays green; add tests that fail without them.

2 * A sync that lands (or is refused) tells the page's one stream the fork's new link word, so the
3 * card and the flows view swap it in place. Real git between real repositories, as
4 * test/sync-shapes.test.ts walks it; and a viewer who may not read the fork hears nothing of it.
5 */
6 import { afterAll, beforeAll, expect, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts";
11 import { createApp, type App } from "../src/app.ts";
12 import { announceLink, fastForwardFork } from "../src/core/following.ts";
13 import { listEvents } from "../src/core/events.ts";
14 import { getRepo, type Repo } from "../src/core/repos.ts";
15 import { createUser, type User } from "../src/core/users.ts";
16 import { viewerStream } from "../src/http/sse.ts";
17 import { flowsMap } from "../src/web/pages/flows.ts";
18 import { promote } from "./helpers/members.ts";
19
20 let dataDir: string;
21 let app: App;
22 let alice: User;
23 let bob: User;
24 let carol: User;
25 let lib: Repo;
26 let fork: Repo;
27
28 const mk = async (username: string, first = false): Promise<User> => {
29 const u = await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first });
30 if (!u.ok) throw new Error(u.error);
31 promote(app.db, u.value);
32 return u.value;
33 };
34 const commit = async (who: User, repo: Repo, path: string): Promise<void> => {
35 const r = await commitToBranch(app, who, repo, { message: path, files: [{ path, content: `${path}\n` }] });
36 if (!r.ok) throw new Error(JSON.stringify(r.error));
37 };
38 const linked = (repo: Repo) => listEvents(app.db, { repoId: repo.id, limit: 50 }).filter((e) => e.kind === "fork.linked");
39 /** Resolves when the next `fork.linked` on this fork is appended. */
40 const nextLinked = (repo: Repo): Promise<void> =>
41 new Promise((resolve) => {
42 const off = app.bus.subscribe((e) => {
43 if (e.kind !== "fork.linked" || e.repoId !== repo.id) return;
44 off();
45 resolve();
46 }, "local");
47 });
48 /** What a viewer's stream carries for a moment, as the frames' text. */
49 async function heard(viewer: User, during: () => Promise<void>): Promise<string> {
50 const res = viewerStream(app, viewer, new Request("http://forge.test/events"));
51 const reader = res.body!.getReader();
52 const decoder = new TextDecoder();
53 let text = "";
54 let markerId = "";
55 let heardMarker = (): void => {};
56 const marked = new Promise<void>((resolve) => (heardMarker = resolve));
57 const reading = (async () => {
58 for (;;) {
59 const { value, done } = await reader.read();
60 if (done) return;
61 text += decoder.decode(value);
62 if (markerId !== "" && text.includes(`"id":"${markerId}"`)) heardMarker();
63 }
64 })();
65 await during();
66 // A public event after it: once the viewer has heard this, anything meant for them has come.
67 const marker = app.bus.append({ kind: "push", repoId: lib.id, actorId: alice.id, payload: { updates: [] } });
68 markerId = marker.id;
69 if (text.includes(`"id":"${markerId}"`)) heardMarker();
70 await marked;
71 await reader.cancel();
72 await reading.catch(() => undefined);
73 return text;
74 }
75
76 beforeAll(async () => {
77 dataDir = await mkdtemp(join(tmpdir(), "forge-fork-linked-"));
78 app = createApp({ dataDir, port: 0 });
79 alice = await mk("alice", true);
80 bob = await mk("bob");
81 carol = await mk("carol");
82 const made = await createRepo(app, alice, { name: "lib", visibility: "public" });
83 if (!made.ok) throw new Error(String(made.error));
84 lib = made.value;
85 await commit(alice, lib, "README.md");
86 const forked = await forkRepo(app, bob, lib);
87 if (!forked.ok) throw new Error(String(forked.error));
88 fork = getRepo(app.db, "bob", "lib")!;
89 }, 60_000);
90
91 afterAll(async () => {
92 app.close();
93 await rm(dataDir, { recursive: true, force: true });
94 });
95
96 test("a sync that moves the fork's branch emits its new word; the flows map says the same word", async () => {
97 // The forge's own follow takes the push; wait for what it announces.
98 const told = nextLinked(fork);
99 await commit(alice, lib, "a.txt");
100 await told;
101 const last = linked(fork)[0]!;
102 expect(last.payload).toEqual({ word: "following", behind: 0, says: "following" });
103 const page = await (await flowsMap({ app, request: new Request("http://forge.test/bob/lib/flows/map"), url: new URL("http://forge.test/bob/lib/flows/map"), params: { owner: "bob", name: "lib" }, auth: { user: bob, scope: undefined, via: "session" }, theme: undefined })).text();
104 expect(page).toContain('id="flow-links"');
105 expect(page).toContain('data-live-repo="bob/lib"');
106 expect(page.replace(/\s+/g, " ")).toContain("forked from · following");
107 });
108
109 test("a refused sync (both sides moved) emits one event naming the word and the count", async () => {
110 await commit(bob, fork, "mine.txt");
111 const before = linked(fork).length;
112 const told = nextLinked(fork);
113 await commit(alice, lib, "theirs.txt");
114 await told;
115 expect((await fastForwardFork(app, fork, lib, alice.id)).ok).toBe(false);
116 const made = linked(fork);
117 expect(made.length).toBeGreaterThan(before);
118 expect(made[0]!.payload).toMatchObject({ word: "behind", behind: 1, says: "behind 1" });
119 });
120
121 test("the stream carries it to a viewer who may read the fork, and to no one who may not", async () => {
122 app.db.query("UPDATE repo SET visibility = 'private' WHERE id = ?1").run(fork.id);
123 const priv = getRepo(app.db, "bob", "lib")!;
124 const stranger = await heard(carol, () => announceLink(app, priv, lib));
125 expect(stranger).not.toContain("fork.linked");
126 expect(stranger).not.toContain("bob/lib");
127 const owner = await heard(bob, () => announceLink(app, priv, lib));
128 expect(owner).toContain("fork.linked");
129 expect(owner).toContain('"repo":"bob/lib"');
130 });
test/fork-standing-line.test.ts +1 −1
@@ -55,7 +55,7 @@ afterAll(async () => {
5555
5656 const lineOf = async (path: string): Promise<string | null> => {
5757 const page = await (await fetch(`${servers.url}${path}`)).text();
58 return page.match(/<div class="small muted" data-follow-standing>[^<]*<svg.*?<\/svg> <a href="([^"]*)">([^<]*)<\/a><\/div>/)?.[2] ?? null;
58 return page.match(/<div class="small muted" data-follow-standing>[^<]*<svg.*?<\/svg> (?:<strong data-link-word="[^"]*">[^<]*<\/strong> · )?<a href="([^"]*)">([^<]*)<\/a><\/div>/)?.[2] ?? null;
5959 };
6060
6161 test("the words: each mode, with and without a last take", () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs