Public: anyone can read this; the crew can change it.
A client list row for a forge link shows sent, opened and first-ask times, each from a recorded event #13704
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13682-a-client-list-row-for-a-forge-link-shows → main 5 commits fork
10 files
changed +191
−33
docs/features/README.md +1
| @@ -316,6 +316,7 @@ Read with the guide page [Hosting forges for others, and getting paid](../guide- | ||
| 316 | 316 | - [](child-filesystem.md) |
| 317 | 317 | - [](forge-bill.md) |
| 318 | 318 | - [](client-forge.md) |
| 319 | - [](client-link-times.md) | |
| 319 | 320 | - [](lapsed-forge.md) |
| 320 | 321 | - [](forge-link-qr.md) |
| 321 | 322 | - [](own-forge-budgets.md) |
docs/features/client-link-times.md added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | # The client list's three times (#13682) | |
| 2 | ||
| 3 | Each forge row for a link says **sent**, **opened** and **first tell**, each from a time that was recorded, never guessed. The line is built once, in `seenParts` (`src/spawn/clients.ts`); the web list, the terminal and the MCP rows all reuse it. | |
| 4 | ||
| 5 | - **sent**: when this forge made the child (`createdAt` in its ledger). | |
| 6 | - **opened**: the first time a browser opened the claim page, written once by the child (`noteOpened`, `spawn/claim.ts`). A link spent before opens were noted reads "opened (time not noted)". Not opened reads "opened: not yet". | |
| 7 | - **first tell**: the earliest issue its person wrote, read by the child (`progress().firstTellAt`, `core/next-steps.ts`) and carried on its heartbeat. No tell reads "first tell: not yet". | |
| 8 | ||
| 9 | ## Until a child has beaten since the update | |
| 10 | ||
| 11 | A child that has not sent a heartbeat carrying `firstTellAt` is unknown, not empty, so its row says nothing about first tell rather than a false "not yet". The line appears at its next heartbeat. Only a beat that says `firstTellAt: null` reads "not yet". | |
| 12 | ||
| 13 | Tests: `test/client-list-events.test.ts` (the line, the parse, the earliest issue) and `test/client-list.test.ts` (a beat through `clientRows` onto the page). |
src/core/next-steps.ts +20 −8
| @@ -26,14 +26,20 @@ export interface NextStep { | ||
| 26 | 26 | |
| 27 | 27 | const STEP_KEYS: readonly StepKey[] = ["everyday", "apps", "tell"]; |
| 28 | 28 | |
| 29 | /** The three steps' words, the one source for the first-login card and the client list's line about it. */ | |
| 29 | /** | |
| 30 | * The three steps' words, the one source for the first-login card and the client list's line about | |
| 31 | * it. | |
| 32 | */ | |
| 30 | 33 | export const STEP_TITLES: Record<StepKey, string> = { |
| 31 | 34 | everyday: "Make your everyday account", |
| 32 | 35 | apps: "Open your apps", |
| 33 | 36 | tell: "Tell the crew something", |
| 34 | 37 | }; |
| 35 | 38 | |
| 36 | /** What the recipient of a sent forge sees first, in one line: the apps chosen, that the crew is working, the three steps. */ | |
| 39 | /** | |
| 40 | * What the recipient of a sent forge sees first, in one line: the apps chosen, that the crew is | |
| 41 | * working, the three steps. | |
| 42 | */ | |
| 37 | 43 | export function firstScreenLine(apps: readonly string[]): string { |
| 38 | 44 | const chosen = apps.length === 0 ? "the apps you pick" : apps.join(", "); |
| 39 | 45 | return `They will see ${chosen}, their crew working, and three next steps: ${STEP_KEYS.map((k) => STEP_TITLES[k]).join("; ")}.`; |
| @@ -41,7 +47,10 @@ export function firstScreenLine(apps: readonly string[]): string { | ||
| 41 | 47 | |
| 42 | 48 | const OPENED_APP = "first_step_opened_app"; |
| 43 | 49 | |
| 44 | /** The admin whose forge this is, as seen by `user`: themselves, or the admin of their everyday account. */ | |
| 50 | /** | |
| 51 | * The admin whose forge this is, as seen by `user`: themselves, or the admin of their everyday | |
| 52 | * account. | |
| 53 | */ | |
| 45 | 54 | function ownerFor(app: App, user: User): User | undefined { |
| 46 | 55 | if (user.kind !== "user") return undefined; |
| 47 | 56 | if (user.isAdmin) return user; |
| @@ -93,19 +102,19 @@ export async function nextStepsFor( | ||
| 93 | 102 | * have an everyday account (or chose to keep working as admin), and when |
| 94 | 103 | * they last told the crew something (null before the first tell). |
| 95 | 104 | */ |
| 96 | export function progress(app: App): { claimed: boolean; everyday: boolean; lastTellAt: string | null } { | |
| 105 | export function progress(app: App): { claimed: boolean; everyday: boolean; lastTellAt: string | null; firstTellAt: string | null } { | |
| 97 | 106 | const owner = app.db |
| 98 | 107 | .query<{ id: string }, []>( |
| 99 | 108 | "SELECT id FROM user WHERE is_admin = 1 AND is_agent = 0 AND kind = 'user' ORDER BY created_at LIMIT 1", |
| 100 | 109 | ) |
| 101 | 110 | .get(); |
| 102 | 111 | const admin = owner === null ? undefined : getUserById(app.db, owner.id); |
| 103 | if (admin === undefined) return { claimed: false, everyday: false, lastTellAt: null }; | |
| 112 | if (admin === undefined) return { claimed: false, everyday: false, lastTellAt: null, firstTellAt: null }; | |
| 104 | 113 | const daily = everydayOf(app.db, admin); |
| 105 | 114 | const people = [admin.id, ...(daily ? [daily.id] : [])]; |
| 106 | 115 | const last = app.db |
| 107 | .query<{ at: string | null }, string[]>( | |
| 108 | `SELECT MAX(i.created_at) AS at FROM issue i | |
| 116 | .query<{ at: string | null; first: string | null }, string[]>( | |
| 117 | `SELECT MAX(i.created_at) AS at, MIN(i.created_at) AS first FROM issue i | |
| 109 | 118 | WHERE i.kind = 'issue' AND i.author_id IN (${people.map((_, n) => `?${n + 1}`).join(",")}) |
| 110 | 119 | AND i.id NOT IN (SELECT direction_issue_id FROM repo WHERE direction_issue_id IS NOT NULL)`, |
| 111 | 120 | ) |
| @@ -114,10 +123,13 @@ export function progress(app: App): { claimed: boolean; everyday: boolean; lastT | ||
| 114 | 123 | claimed: true, |
| 115 | 124 | everyday: daily !== undefined || keptAdmin(app.db, admin), |
| 116 | 125 | lastTellAt: last?.at ?? null, |
| 126 | firstTellAt: last?.first ?? null, | |
| 117 | 127 | }; |
| 118 | 128 | } |
| 119 | 129 | |
| 120 | /** The owner (or their everyday account) opened an app on a spawned forge: the second step is done. */ | |
| 130 | /** | |
| 131 | * The owner (or their everyday account) opened an app on a spawned forge: the second step is done. | |
| 132 | */ | |
| 121 | 133 | export async function noteAppOpened(app: App, user: User | undefined): Promise<void> { |
| 122 | 134 | if (!user) return; |
| 123 | 135 | const owner = ownerFor(app, user); |
src/spawn/clients.ts +13 −3
| @@ -64,6 +64,8 @@ export interface ClientRow { | ||
| 64 | 64 | */ |
| 65 | 65 | readonly appLinks?: readonly AppLinkLine[]; |
| 66 | 66 | readonly sentAt: string | null; |
| 67 | /** When its person first told the crew something, from its last beat; null until then. */ | |
| 68 | readonly firstTellAt?: string | null | undefined; | |
| 67 | 69 | /** False while the child is still being made (a resumed spawn finishes it). */ |
| 68 | 70 | readonly made: boolean; |
| 69 | 71 | readonly claimed: boolean | null; |
| @@ -337,6 +339,8 @@ export async function clientRows(app: App, options: { probe?: boolean } = {}): P | ||
| 337 | 339 | apps: c.apps, |
| 338 | 340 | appLinks: links[i] ?? [], |
| 339 | 341 | sentAt: c.createdAt, |
| 342 | // Undefined until the child has beaten with the field: unknown is not "not yet". | |
| 343 | firstTellAt: beats[i]?.beat.firstTellAt, | |
| 340 | 344 | made: c.done, |
| 341 | 345 | claimed: states[i]?.claimed ?? null, |
| 342 | 346 | lastActivityAt: people[i]?.lastAt ?? null, |
| @@ -618,6 +622,10 @@ export interface Seen { | ||
| 618 | 622 | readonly openedAt: string | null; |
| 619 | 623 | /** ISO of a person's last action there; null until they signed in. */ |
| 620 | 624 | readonly lastSeenAt: string | null; |
| 625 | /** | |
| 626 | * ISO of the first tell there, from a recorded issue; null until the person has told the crew. | |
| 627 | */ | |
| 628 | readonly firstTellAt?: string | null | undefined; | |
| 621 | 629 | /** |
| 622 | 630 | * ISO of the last "send again", which ended the earlier link; null once claimed or when never. |
| 623 | 631 | */ |
| @@ -625,17 +633,19 @@ export interface Seen { | ||
| 625 | 633 | } |
| 626 | 634 | |
| 627 | 635 | /** Null while the forge is still being made or did not answer: nothing is claimed unknown. */ |
| 628 | export function seenOf(r: Pick<ClientRow, "made" | "claimed" | "sentAt" | "link" | "lastActivityAt" | "replacedAt">): Seen | null { | |
| 636 | export function seenOf(r: Pick<ClientRow, "made" | "claimed" | "sentAt" | "firstTellAt" | "link" | "lastActivityAt" | "replacedAt">): Seen | null { | |
| 629 | 637 | if (!r.made || r.claimed === null || r.link === null) return null; |
| 630 | 638 | const openedAt = r.link.openedAt ?? null; |
| 631 | return { sentAt: r.sentAt, opened: openedAt !== null || r.link.usedAt != null || r.link.state === "used", openedAt, lastSeenAt: r.claimed ? r.lastActivityAt : null, replacedAt: r.claimed ? null : r.replacedAt ?? null }; | |
| 639 | return { sentAt: r.sentAt, opened: openedAt !== null || r.link.usedAt != null || r.link.state === "used", openedAt, lastSeenAt: r.claimed ? r.lastActivityAt : null, firstTellAt: r.firstTellAt, replacedAt: r.claimed ? null : r.replacedAt ?? null }; | |
| 632 | 640 | } |
| 633 | 641 | |
| 634 | 642 | /** The one line as parts to join with " · ": the words, and the instant to say beside them. */ |
| 635 | 643 | export function seenParts(s: Seen): { words: string; at: string | null }[] { |
| 636 | 644 | return [ |
| 637 | 645 | ...(s.sentAt === null ? [] : [{ words: "sent", at: s.sentAt }]), |
| 638 | s.opened ? { words: s.openedAt === null ? "opened (time not noted)" : "opened", at: s.openedAt } : { words: "not opened yet", at: null }, | |
| 646 | s.opened ? { words: s.openedAt === null ? "opened (time not noted)" : "opened", at: s.openedAt } : { words: "opened: not yet", at: null }, | |
| 647 | // Nothing while unknown (undefined); "not yet" only once the child has said there is none. | |
| 648 | ...(s.firstTellAt === undefined ? [] : [s.firstTellAt === null ? { words: "first tell: not yet", at: null } : { words: "first tell", at: s.firstTellAt }]), | |
| 639 | 649 | ...(s.replacedAt == null ? [] : [{ words: "link replaced", at: s.replacedAt }]), |
| 640 | 650 | ...(s.lastSeenAt === null ? [] : [{ words: "last seen", at: s.lastSeenAt }]), |
| 641 | 651 | ]; |
src/spawn/heartbeat.ts +42 −12
| @@ -52,19 +52,30 @@ export interface Beat { | ||
| 52 | 52 | readonly version: string; |
| 53 | 53 | readonly openProposals: number; |
| 54 | 54 | readonly children: number; |
| 55 | /** The tip of the child's own forge code; absent from an older child, null when it carries none. */ | |
| 55 | /** | |
| 56 | * The tip of the child's own forge code; absent from an older child, null when it carries none. | |
| 57 | */ | |
| 56 | 58 | readonly forgeTip?: string | null; |
| 57 | 59 | /** When the child cut its upstream link; null while it follows. */ |
| 58 | 60 | readonly severedAt?: string | null; |
| 59 | 61 | /** How the child follows its parent's code (`parent.json`); absent from an older child. */ |
| 60 | 62 | readonly mode?: FollowMode; |
| 61 | /** Commits behind the parent's code (`upstream.json`); null when unknown, absent from an older child. */ | |
| 63 | /** | |
| 64 | * Commits behind the parent's code (`upstream.json`); null when unknown, absent from an older | |
| 65 | * child. | |
| 66 | */ | |
| 62 | 67 | readonly upstreamBehind?: number | null; |
| 63 | 68 | /** True while a converge issue is open on the child; absent from an older child. */ |
| 64 | 69 | readonly conflict?: boolean; |
| 65 | /** Dollars the child's crew spent since 00:00 UTC; absent from an older child or when it sent a bad value. */ | |
| 70 | /** | |
| 71 | * Dollars the child's crew spent since 00:00 UTC; absent from an older child or when it sent a | |
| 72 | * bad value. | |
| 73 | */ | |
| 66 | 74 | readonly spendTodayUsd?: number; |
| 67 | /** The child's forge cap in dollars (the daily ceiling that pauses its crew), null when it has none; absent when unsaid or bad. */ | |
| 75 | /** | |
| 76 | * The child's forge cap in dollars (the daily ceiling that pauses its crew), null when it has | |
| 77 | * none; absent when unsaid or bad. | |
| 78 | */ | |
| 68 | 79 | readonly ceilingUsd?: number | null; |
| 69 | 80 | /** Why its crew cannot start ("no_model_key" today); absent when it can or from an old child. */ |
| 70 | 81 | readonly crewHeld?: typeof NO_KEY_HELD; |
| @@ -74,6 +85,8 @@ export interface Beat { | ||
| 74 | 85 | readonly everyday?: boolean; |
| 75 | 86 | /** When its person last told the crew something; null before the first, absent likewise. */ |
| 76 | 87 | readonly lastTellAt?: string | null; |
| 88 | /** When its person first told the crew something; null before the first, absent likewise. */ | |
| 89 | readonly firstTellAt?: string | null; | |
| 77 | 90 | /** |
| 78 | 91 | * When a stranger last asked this forge's sender for a new forge link, and when that link expired |
| 79 | 92 | * (ISO); absent when none. |
| @@ -83,7 +96,7 @@ export interface Beat { | ||
| 83 | 96 | } |
| 84 | 97 | |
| 85 | 98 | const OPTIONAL = new Set([ |
| 86 | "forgeTip", "severedAt", "mode", "upstreamBehind", "conflict", "spendTodayUsd", "ceilingUsd", "crewHeld", "claimed", "everyday", "lastTellAt", "linkAskedAt", "linkExpiredAt", | |
| 99 | "forgeTip", "severedAt", "mode", "upstreamBehind", "conflict", "spendTodayUsd", "ceilingUsd", "crewHeld", "claimed", "everyday", "lastTellAt", "firstTellAt", "linkAskedAt", "linkExpiredAt", | |
| 87 | 100 | ]); |
| 88 | 101 | const USD_MAX = 1_000_000; |
| 89 | 102 | |
| @@ -133,9 +146,13 @@ export function parseBeat(raw: string): Beat | undefined { | ||
| 133 | 146 | const claimed = d["claimed"]; |
| 134 | 147 | const everyday = d["everyday"]; |
| 135 | 148 | const told = d["lastTellAt"]; |
| 149 | const first = d["firstTellAt"]; | |
| 150 | const firstOk = | |
| 151 | first === null || (typeof first === "string" && ISO_TIME.test(first) && !Number.isNaN(Date.parse(first))); | |
| 136 | 152 | const claimedOk = typeof claimed === "boolean"; |
| 137 | 153 | const everydayOk = typeof everyday === "boolean"; |
| 138 | // Strict ISO: it is printed into the parent admin's terminal, so nothing but digits and punctuation. | |
| 154 | // Strict ISO: it is printed into the parent admin's terminal, so nothing but digits and | |
| 155 | // punctuation. | |
| 139 | 156 | const toldOk = |
| 140 | 157 | told === null || (typeof told === "string" && ISO_TIME.test(told) && !Number.isNaN(Date.parse(told))); |
| 141 | 158 | // Both or neither, strict ISO: they become words on the sender's page. |
| @@ -168,6 +185,7 @@ export function parseBeat(raw: string): Beat | undefined { | ||
| 168 | 185 | ...(claimedOk ? { claimed } : {}), |
| 169 | 186 | ...(everydayOk ? { everyday } : {}), |
| 170 | 187 | ...(told !== undefined && toldOk ? { lastTellAt: told as string | null } : {}), |
| 188 | ...(first !== undefined && firstOk ? { firstTellAt: first as string | null } : {}), | |
| 171 | 189 | ...(askedAt === undefined ? {} : { linkAskedAt: askedAt as string, linkExpiredAt: expiredAt as string }), |
| 172 | 190 | }; |
| 173 | 191 | } |
| @@ -258,7 +276,8 @@ async function takeBeat( | ||
| 258 | 276 | |
| 259 | 277 | /** |
| 260 | 278 | * A child's stranger asked for a new forge link: one note, for the account that made the child, |
| 261 | * once per ask (a beat is repeated every ten minutes) and at most one an hour per child. It names the forge and when the link ended. | |
| 279 | * once per ask (a beat is repeated every ten minutes) and at most one an hour per child. It names | |
| 280 | * the forge and when the link ended. | |
| 262 | 281 | */ |
| 263 | 282 | async function noteTheAsk(app: App, name: string, asked: string, expired: string): Promise<void> { |
| 264 | 283 | const { childNamed } = await import("../actions/spawn.ts"); |
| @@ -320,7 +339,9 @@ export function standing(app: App, name: string, at = Date.now()): Beat { | ||
| 320 | 339 | }; |
| 321 | 340 | } |
| 322 | 341 | |
| 323 | /** What the crew spent today, and the daily ceiling that pauses it (null when the forge sets none). */ | |
| 342 | /** | |
| 343 | * What the crew spent today, and the daily ceiling that pauses it (null when the forge sets none). | |
| 344 | */ | |
| 324 | 345 | export function spendReport(app: App, now = new Date()): { spendTodayUsd: number; ceilingUsd: number | null } { |
| 325 | 346 | const cap = forgeCeiling(app.config); |
| 326 | 347 | return { |
| @@ -329,7 +350,9 @@ export function spendReport(app: App, now = new Date()): { spendTodayUsd: number | ||
| 329 | 350 | }; |
| 330 | 351 | } |
| 331 | 352 | |
| 332 | /** What a fork says of how it follows: its tip, whether it cut the link, and how far behind it is. */ | |
| 353 | /** | |
| 354 | * What a fork says of how it follows: its tip, whether it cut the link, and how far behind it is. | |
| 355 | */ | |
| 333 | 356 | async function forkReport(app: App, forge: ForgeLink) { |
| 334 | 357 | const up = await upstreamState(app); |
| 335 | 358 | const behind = up?.behind ?? null; |
| @@ -342,7 +365,10 @@ async function forkReport(app: App, forge: ForgeLink) { | ||
| 342 | 365 | }; |
| 343 | 366 | } |
| 344 | 367 | |
| 345 | /** In a cell the parent's public address is out of reach; its relayed loopback port (`FORGE_PARENT_LOCAL`) is not. */ | |
| 368 | /** | |
| 369 | * In a cell the parent's public address is out of reach; its relayed loopback port | |
| 370 | * (`FORGE_PARENT_LOCAL`) is not. | |
| 371 | */ | |
| 346 | 372 | export function beatBase(upstream: string): string { |
| 347 | 373 | const local = process.env["FORGE_PARENT_LOCAL"] ?? ""; |
| 348 | 374 | return isParentLocal(local) ? local : upstream; |
| @@ -351,7 +377,10 @@ export function beatBase(upstream: string): string { | ||
| 351 | 377 | type FetchLike = (url: string, init?: RequestInit) => Promise<Response>; |
| 352 | 378 | let lastAt = 0; |
| 353 | 379 | |
| 354 | /** A spawned child's one report to its parent; false when it has no parent or the try failed. Never throws. */ | |
| 380 | /** | |
| 381 | * A spawned child's one report to its parent; false when it has no parent or the try failed. Never | |
| 382 | * throws. | |
| 383 | */ | |
| 355 | 384 | export async function sendBeat( |
| 356 | 385 | app: App, |
| 357 | 386 | fetcher: FetchLike = fetch, |
| @@ -389,7 +418,8 @@ export async function sendBeat( | ||
| 389 | 418 | const said = (await res.json().catch(() => undefined)) as { follow?: unknown } | undefined; |
| 390 | 419 | const { hearLandings, parseHints } = await import("./app_follow.ts"); |
| 391 | 420 | await hearLandings(app, parseHints(said?.follow)).catch(() => {}); |
| 392 | // What this forge asked its host to let it reach is looked at with every beat, so an answer is heard with no page open (`actions/ask_host.ts`). | |
| 421 | // What this forge asked its host to let it reach is looked at with every beat, so an answer | |
| 422 | // is heard with no page open (`actions/ask_host.ts`). | |
| 393 | 423 | const { refreshAsks } = await import("../actions/ask_host.ts"); |
| 394 | 424 | await refreshAsks(app); |
| 395 | 425 | } |
test/client-link-seen.test.ts +9 −9
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | * Whether the client has looked (#12694): the child notes when a person's |
| 3 | 3 | * browser first opened its claim page (a link prefetcher or chat unfurl does |
| 4 | 4 | * not count), and the sender's client list says "sent <day>", "opened <day>" |
| 5 | * or "not opened yet", and "last seen" once they signed in. | |
| 5 | * or "opened: not yet", and "last seen" once they signed in. | |
| 6 | 6 | */ |
| 7 | 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 8 | 8 | import { mkdtempSync, rmSync } from "node:fs"; |
| @@ -37,14 +37,14 @@ describe("the client list says whether the link was looked at", () => { | ||
| 37 | 37 | test("unopened", () => { |
| 38 | 38 | const h = html(row({})); |
| 39 | 39 | expect(h).toContain("sent 3d ago"); |
| 40 | expect(h).toContain("not opened yet"); | |
| 40 | expect(h).toContain("opened: not yet"); | |
| 41 | 41 | expect(h).not.toContain("last seen"); |
| 42 | 42 | }); |
| 43 | 43 | |
| 44 | 44 | test("opened", () => { |
| 45 | 45 | const h = html(row({ link: { state: "open", revokedAt: null, usedAt: null, openedAt: ago(DAY) } })); |
| 46 | 46 | expect(h).toContain("opened 1d ago"); |
| 47 | expect(h).not.toContain("not opened yet"); | |
| 47 | expect(h).not.toContain("opened: not yet"); | |
| 48 | 48 | expect(h).not.toContain("last seen"); |
| 49 | 49 | }); |
| 50 | 50 | |
| @@ -72,17 +72,17 @@ describe("the client list says whether the link was looked at", () => { | ||
| 72 | 72 | }); |
| 73 | 73 | |
| 74 | 74 | test("the terminal says it to the sender, and nothing to a guest", () => { |
| 75 | const r = row({ claimed: true, lastActivityAt: ago(2 * 3600_000), link: { state: "used", usedAt: ago(DAY), openedAt: ago(DAY) } }); | |
| 75 | const r = row({ claimed: true, firstTellAt: null, lastActivityAt: ago(2 * 3600_000), link: { state: "used", usedAt: ago(DAY), openedAt: ago(DAY) } }); | |
| 76 | 76 | const line = forgeLines([r], true)[0]![1]; |
| 77 | expect(line).toContain("sent 3d ago · opened 1d ago · last seen 2h ago"); | |
| 77 | expect(line).toContain("sent 3d ago · opened 1d ago · first tell: not yet · last seen 2h ago"); | |
| 78 | 78 | expect(forgeLines([r], false)[0]![1]).not.toContain("opened"); |
| 79 | expect(forgeLines([row({})], true)[0]![1]).toContain("sent 3d ago · not opened yet"); | |
| 80 | expect(forgeLines([row({})])[0]![1]).not.toContain("not opened yet"); | |
| 79 | expect(forgeLines([row({})], true)[0]![1]).toContain("sent 3d ago · opened: not yet"); | |
| 80 | expect(forgeLines([row({})])[0]![1]).not.toContain("opened: not yet"); | |
| 81 | 81 | }); |
| 82 | 82 | |
| 83 | 83 | test("nothing is said while the child did not answer", () => { |
| 84 | 84 | expect(seenOf(row({ claimed: null }))).toBeNull(); |
| 85 | expect(html(row({ claimed: null }))).not.toContain("not opened yet"); | |
| 85 | expect(html(row({ claimed: null }))).not.toContain("opened: not yet"); | |
| 86 | 86 | }); |
| 87 | 87 | }); |
| 88 | 88 | |
| @@ -145,7 +145,7 @@ describe("only a person's browser counts as opening", () => { | ||
| 145 | 145 | await res.text(); |
| 146 | 146 | expect(linkOf(app.db)!.openedAt).toBeNull(); |
| 147 | 147 | const body = await (await fetch(`${servers.url}/`, { headers: html5 })).text(); |
| 148 | for (const w of ["not opened yet", "opened (time not noted)", "last seen"]) expect(body).not.toContain(w); | |
| 148 | for (const w of ["opened: not yet", "opened (time not noted)", "last seen"]) expect(body).not.toContain(w); | |
| 149 | 149 | expect(await (await fetch(`${servers.url}/forges`, { headers: html5, redirect: "manual" })).text()).not.toContain("data-seen"); |
| 150 | 150 | }); |
| 151 | 151 | }); |
test/client-list-events.test.ts added +82
| @@ -0,0 +1,82 @@ | ||
| 1 | /** | |
| 2 | * The client list's three times for a link (#13682): sent, opened, first tell. Opened is the | |
| 3 | * child's once-written claim note; first tell is the earliest issue its person wrote, carried on | |
| 4 | * the heartbeat. An empty one says "not yet". | |
| 5 | */ | |
| 6 | import { describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtempSync } from "node:fs"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp } from "../src/app.ts"; | |
| 11 | import { progress } from "../src/core/next-steps.ts"; | |
| 12 | import { createRepo } from "../src/actions/repos.ts"; | |
| 13 | import { createUser } from "../src/core/users.ts"; | |
| 14 | import { parseBeat } from "../src/spawn/heartbeat.ts"; | |
| 15 | import { mintClaim, noteOpened, linkOf } from "../src/spawn/claim.ts"; | |
| 16 | import { createOrg } from "../src/core/orgs.ts"; | |
| 17 | import { seenOf, seenParts, type ClientRow } from "../src/spawn/clients.ts"; | |
| 18 | import { quietLogs } from "./helpers/globals.ts"; | |
| 19 | ||
| 20 | quietLogs(); | |
| 21 | ||
| 22 | const row = (over: Record<string, unknown>) => | |
| 23 | ({ made: true, claimed: true, sentAt: "2026-11-01T00:00:00.000Z", lastActivityAt: null, replacedAt: null, | |
| 24 | link: { state: "used", revokedAt: null, usedAt: null, openedAt: null }, ...over }) as unknown as ClientRow; | |
| 25 | const words = (r: ClientRow) => seenParts(seenOf(r)!).map((p) => `${p.words}${p.at ? " " + p.at : ""}`); | |
| 26 | ||
| 27 | describe("the client list's three times", () => { | |
| 28 | test("empty ones say not yet", () => { | |
| 29 | const w = words(row({ claimed: false, firstTellAt: null, link: { state: "open", revokedAt: null, usedAt: null, openedAt: null } })); | |
| 30 | expect(w).toEqual(["sent 2026-11-01T00:00:00.000Z", "opened: not yet", "first tell: not yet"]); | |
| 31 | }); | |
| 32 | ||
| 33 | test("a first tell not yet reported says nothing, not \"not yet\"", () => { | |
| 34 | expect(words(row({ claimed: false, link: { state: "open", revokedAt: null, usedAt: null, openedAt: null } })).join("|")).not.toContain("first tell"); | |
| 35 | }); | |
| 36 | ||
| 37 | test("each shows its recorded time", () => { | |
| 38 | const w = words(row({ firstTellAt: "2026-11-03T00:00:00.000Z", link: { state: "used", revokedAt: null, usedAt: null, openedAt: "2026-11-02T00:00:00.000Z" } })); | |
| 39 | expect(w).toContain("opened 2026-11-02T00:00:00.000Z"); | |
| 40 | expect(w).toContain("first tell 2026-11-03T00:00:00.000Z"); | |
| 41 | }); | |
| 42 | ||
| 43 | test("opening writes once", async () => { | |
| 44 | const app = createApp({ dataDir: mkdtempSync(join(tmpdir(), "cle-")) }); | |
| 45 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 46 | if (!u.ok) throw new Error(u.error); | |
| 47 | const org = createOrg(app.db, "kin", u.value.id); | |
| 48 | if (!org.ok) throw new Error(org.error); | |
| 49 | mintClaim(app.db, org.value.id); | |
| 50 | expect(noteOpened(app.db, Date.now())).toBe(true); | |
| 51 | const first = linkOf(app.db)!.openedAt; | |
| 52 | expect(first).not.toBeNull(); | |
| 53 | expect(noteOpened(app.db, Date.now() + 5000)).toBe(false); | |
| 54 | expect(linkOf(app.db)!.openedAt).toBe(first); | |
| 55 | app.close(); | |
| 56 | }); | |
| 57 | ||
| 58 | test("a first tell is the earliest issue and does not move with later ones", async () => { | |
| 59 | const app = createApp({ dataDir: mkdtempSync(join(tmpdir(), "cle-")) }); | |
| 60 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 61 | if (!u.ok) throw new Error(u.error); | |
| 62 | expect(progress(app).firstTellAt).toBeNull(); | |
| 63 | const repo = await createRepo(app, u.value, { name: "bakery" }); | |
| 64 | if (!repo.ok) throw new Error("repo"); | |
| 65 | const put = (n: number, at: string) => | |
| 66 | app.db | |
| 67 | .query("INSERT INTO issue (id, repo_id, number, title, author_id, created_at) VALUES (?1, ?2, ?3, 'hi', ?4, ?5)") | |
| 68 | .run(`t${n}`, repo.value.id, 9000 + n, u.value.id, at); | |
| 69 | put(1, "2030-02-03T04:05:06.000Z"); | |
| 70 | put(2, "2030-03-03T04:05:06.000Z"); | |
| 71 | expect(progress(app)).toMatchObject({ firstTellAt: "2030-02-03T04:05:06.000Z", lastTellAt: "2030-03-03T04:05:06.000Z" }); | |
| 72 | app.close(); | |
| 73 | }); | |
| 74 | ||
| 75 | test("the beat carries first tell only when it is a time", () => { | |
| 76 | const beat = (o: Record<string, unknown>) => parseBeat(JSON.stringify({ name: "maria", at: 1, version: "1.0.0", openProposals: 0, children: 0, ...o })); | |
| 77 | expect(beat({ firstTellAt: "2030-01-01T00:00:00Z" })?.firstTellAt).toBe("2030-01-01T00:00:00Z"); | |
| 78 | expect(beat({ firstTellAt: null })?.firstTellAt).toBeNull(); | |
| 79 | expect(beat({ firstTellAt: "soon" })?.firstTellAt).toBeUndefined(); | |
| 80 | expect(beat({ firstTellAt: "soon" })?.name).toBe("maria"); | |
| 81 | }); | |
| 82 | }); |
test/client-list.test.ts +9
| @@ -313,8 +313,15 @@ describe("the client list", () => { | ||
| 313 | 313 | return JSON.parse(tool.result.content[0].text).forges.find((f: any) => f.name === "maria").nextStep; |
| 314 | 314 | }; |
| 315 | 315 | // The claim made the child's person an admin; nothing else yet. |
| 316 | // clientRows copies the beat's firstTellAt onto the row: none told yet reads "not yet". | |
| 317 | const seen = async () => { | |
| 318 | const html = (await (await list(admin)).text()).replace(/\s+/g, " "); | |
| 319 | const at = html.indexOf('data-forge="maria"'); | |
| 320 | return /first tell[^<]*/.exec(html.slice(at, html.indexOf("</li>", at)))?.[0]; | |
| 321 | }; | |
| 316 | 322 | expect(await beatTo()).toBe(true); |
| 317 | 323 | expect(await words()).toBe("no everyday account yet"); |
| 324 | expect(await seen()).toContain("first tell: not yet"); | |
| 318 | 325 | expect((await mariaStep()).words).toBe("no everyday account yet"); |
| 319 | 326 | const person = child.db.query<{ id: string }, []>("SELECT id FROM user WHERE is_admin = 1 AND kind = 'user' AND is_agent = 0").get()!; |
| 320 | 327 | keepAdmin(child.db, getUserById(child.db, person.id)!); |
| @@ -327,6 +334,8 @@ describe("the client list", () => { | ||
| 327 | 334 | .run(repo.id, person.id); |
| 328 | 335 | expect(await beatTo()).toBe(true); |
| 329 | 336 | expect(await words()).toBe("going: last tell"); |
| 337 | expect(await seen()).toMatch(/^first tell\s*(?!: not yet)/); | |
| 338 | expect(await seen()).not.toContain("not yet"); | |
| 330 | 339 | const step = await mariaStep(); |
| 331 | 340 | expect(step).toMatchObject({ key: "going", lastTellAt: "2030-02-03T04:05:06.000Z" }); |
| 332 | 341 | expect(step.words).toBe("going: last tell 2030-02-03T04:05:06.000Z"); |
test/family-heartbeat.test.ts +1
| @@ -354,6 +354,7 @@ describe("family heartbeats", () => { | ||
| 354 | 354 | "claimed", |
| 355 | 355 | "crewHeld", |
| 356 | 356 | "everyday", |
| 357 | "firstTellAt", | |
| 357 | 358 | "lastTellAt", |
| 358 | 359 | "name", |
| 359 | 360 | "openProposals", |
test/mcp-clients.test.ts +1 −1
| @@ -56,7 +56,7 @@ test("the owner reads each client in the page's words", async () => { | ||
| 56 | 56 | expect(c[0].name).toBe("alpha"); |
| 57 | 57 | expect(c[0].for).toBe("Ann"); |
| 58 | 58 | expect(c[0].claimed).toBe("Not claimed yet"); |
| 59 | expect(c[0].seen).toContain("not opened yet"); | |
| 59 | expect(c[0].seen).toContain("opened: not yet"); | |
| 60 | 60 | }); |
| 61 | 61 | |
| 62 | 62 | test("anyone else gets the usual refusal", async () => { |
new above
offline