Public: anyone can read this; the crew can change it.
A card with no picture says why, and never shows a question mark #16794
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16257-a-card-with-no-picture-says-why-and-neve → main 0 commits fork 3 threads · 3 unresolved
14 files
changed +272
−8
- docs/design/areas/look-none.md
- src/actions/front.ts
- src/contract/openapi/routes/getApiV1Front.ts
- src/looks/retries.ts
- src/looks/service.ts
- src/looks/why.ts
- src/tui/screens/front.ts
- src/web/look_none.ts
- src/web/pages/looks.ts
- src/web/studio/home.ts
- src/web/style/components.ts
- test/front.test.ts
- test/look-none.test.ts
- test/tui-front.test.ts
docs/design/areas/look-none.md added +5
| @@ -0,0 +1,5 @@ | ||
| 1 | # A card with no picture | |
| 2 | ||
| 3 | Where an app's card (the home's tile, the app head's "now") has no picture, `noPicture` (`src/web/look_none.ts`) fills the picture's own box (`.look.look-none`, 8:5 like a thumb, so nothing shifts when one arrives) with the app's name (`.look-none-name`) and, when the forge has one, the one line why (`.look-none-why`, from `src/looks/why.ts`): "not serving", "failed under load; retrying at HH:MM UTC" or "pictures are the writers' on this private app". With no reason it is the name alone. It never draws an image or a question mark. | |
| 4 | ||
| 5 | The terminal says the same: a row of the front page (`src/tui/screens/front.ts`) leads its meta with the reason (`why` in `GET /api/v1/front` and MCP `front_page`) when there is one. |
src/actions/front.ts +28
| @@ -47,6 +47,8 @@ import { | ||
| 47 | 47 | type Look, |
| 48 | 48 | } from "../core/looks.ts"; |
| 49 | 49 | import { keepLook } from "../looks/service.ts"; |
| 50 | import { retryAt } from "../looks/retries.ts"; | |
| 51 | import { whyNoPicture } from "../looks/why.ts"; | |
| 50 | 52 | import { canReadMany, getRepo, getReposByIds, type Repo } from "../core/repos.ts"; |
| 51 | 53 | import { listActiveRuns } from "../core/runs.ts"; |
| 52 | 54 | import { getUsersByIds, isActive, type User } from "../core/users.ts"; |
| @@ -91,6 +93,8 @@ export interface FrontEntry { | ||
| 91 | 93 | readonly state: EnvState | undefined; |
| 92 | 94 | /** The thumb of production's home page, as a stranger sees it. */ |
| 93 | 95 | readonly picture: string | undefined; |
| 96 | /** The one line why there is no picture, when the forge has a reason (`looks/why.ts`). */ | |
| 97 | readonly why: string | undefined; | |
| 94 | 98 | readonly pinned: boolean; |
| 95 | 99 | readonly signals: FrontSignals; |
| 96 | 100 | readonly score: number; |
| @@ -371,10 +375,31 @@ function buildFrontPage(app: App, now: number): FrontPage { | ||
| 371 | 375 | // name a public repository whose app is private). |
| 372 | 376 | const open = record?.access === "public"; |
| 373 | 377 | const signals = open ? scored.s : { ...scored.s, awakeHours: 0 }; |
| 378 | const failedLook = | |
| 379 | record === undefined || thumb !== undefined | |
| 380 | ? undefined | |
| 381 | : looks.find( | |
| 382 | (l) => | |
| 383 | l.appId === record.id && | |
| 384 | l.env === "production" && | |
| 385 | l.commitOid === production?.commitOid && | |
| 386 | l.page === DEFAULT_PAGE && | |
| 387 | l.kind === "thumb" && | |
| 388 | l.error !== null, | |
| 389 | ); | |
| 374 | 390 | return { |
| 375 | 391 | repo, |
| 376 | 392 | app: record, |
| 377 | 393 | state: open ? production?.state : undefined, |
| 394 | why: | |
| 395 | record === undefined || thumb !== undefined | |
| 396 | ? undefined | |
| 397 | : whyNoPicture({ | |
| 398 | readable: open, | |
| 399 | error: failedLook?.error, | |
| 400 | retryAt: retryAt(app, record.id, "production", now), | |
| 401 | state: open ? production?.state : undefined, | |
| 402 | }), | |
| 378 | 403 | picture: |
| 379 | 404 | thumb === undefined |
| 380 | 405 | ? undefined |
| @@ -660,6 +685,8 @@ export type FrontRowJson = { | ||
| 660 | 685 | readonly url: string; |
| 661 | 686 | readonly state: EnvState | null; |
| 662 | 687 | readonly picture: string | null; |
| 688 | /** Why there is no picture, when the forge has a reason (#16257). */ | |
| 689 | readonly why: string | null; | |
| 663 | 690 | readonly pinned: boolean; |
| 664 | 691 | readonly score: number; |
| 665 | 692 | readonly signals: FrontSignals; |
| @@ -682,6 +709,7 @@ export function frontJson(app: App, viewer: User | undefined): FrontJson { | ||
| 682 | 709 | url: `/${e.repo.ownerName}/${e.repo.name}`, |
| 683 | 710 | state: e.state ?? null, |
| 684 | 711 | picture: e.picture ?? null, |
| 712 | why: e.why ?? null, | |
| 685 | 713 | pinned: e.pinned, |
| 686 | 714 | score: Math.round(e.score * 100) / 100, |
| 687 | 715 | signals: e.signals, |
src/contract/openapi/routes/getApiV1Front.ts +1 −1
| @@ -1,3 +1,3 @@ | ||
| 1 | 1 | import type { Route } from "../shared.ts"; |
| 2 | 2 | |
| 3 | export const route: Route = { method: "get", path: "/api/v1/front", summary: "The front page a stranger is shown", detail: "The front page a stranger is shown: { featured, apps, total }, each entry { repo, description, url, state, picture, pinned, score, signals }; a site admin also gets `picks`", auth: false, role: "anonymous" }; | |
| 3 | export const route: Route = { method: "get", path: "/api/v1/front", summary: "The front page a stranger is shown", detail: "The front page a stranger is shown: { featured, apps, total }, each entry { repo, description, url, state, picture, why, pinned, score, signals }; a site admin also gets `picks`", auth: false, role: "anonymous" }; |
src/looks/retries.ts added +44
| @@ -0,0 +1,44 @@ | ||
| 1 | /** | |
| 2 | * When a failed look is next tried: the backoff's next step, noted by the looks service as it | |
| 3 | * schedules it and read by the cards that have no picture to say why (#16257). One instant per app | |
| 4 | * and environment, the latest failure's; gone on restart, and nothing is lost with it: the next | |
| 5 | * failure notes it again. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { App } from "../app.ts"; | |
| 9 | ||
| 10 | const MAX = 2_000; | |
| 11 | /** Held per app, like the apps runtime: a second forge in one process (a test) has its own. */ | |
| 12 | const held = new WeakMap<App, Map<string, number>>(); | |
| 13 | ||
| 14 | const of = (app: App): Map<string, number> => { | |
| 15 | let next = held.get(app); | |
| 16 | if (next === undefined) held.set(app, (next = new Map())); | |
| 17 | return next; | |
| 18 | }; | |
| 19 | ||
| 20 | const keyOf = (appId: string, env: string): string => `${appId}/${env}`; | |
| 21 | ||
| 22 | /** A look of this environment failed and will be tried again at `at` (ms since the epoch). */ | |
| 23 | export function noteRetry(app: App, appId: string, env: string, at: number): void { | |
| 24 | const next = of(app); | |
| 25 | const key = keyOf(appId, env); | |
| 26 | next.delete(key); | |
| 27 | next.set(key, at); | |
| 28 | while (next.size > MAX) { | |
| 29 | const oldest = next.keys().next().value; | |
| 30 | if (oldest === undefined) break; | |
| 31 | next.delete(oldest); | |
| 32 | } | |
| 33 | } | |
| 34 | ||
| 35 | /** The look's success or its end: nothing waits for it any more. */ | |
| 36 | export function clearRetry(app: App, appId: string, env: string): void { | |
| 37 | of(app).delete(keyOf(appId, env)); | |
| 38 | } | |
| 39 | ||
| 40 | /** When the next try is due, or undefined when none waits (a past time is none). */ | |
| 41 | export function retryAt(app: App, appId: string, env: string, now: number = Date.now()): number | undefined { | |
| 42 | const at = of(app).get(keyOf(appId, env)); | |
| 43 | return at !== undefined && at > now ? at : undefined; | |
| 44 | } |
src/looks/service.ts +9 −2
| @@ -83,6 +83,7 @@ import { keepAsMain } from "./main_looks.ts"; | ||
| 83 | 83 | import { closeBrowsers, findChromium, isNoBrowser, lookLanes, takeLook, type Capture } from "./capture.ts"; |
| 84 | 84 | import { browserRefusal } from "./chromium.ts"; |
| 85 | 85 | import { backoff, realClock, type BackoffClock } from "./backoff.ts"; |
| 86 | import { clearRetry, noteRetry } from "./retries.ts"; | |
| 86 | 87 | import { reduceToThumb } from "./thumb.ts"; |
| 87 | 88 | import { during } from "../perf/jobs.ts"; |
| 88 | 89 | |
| @@ -347,12 +348,15 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle { | ||
| 347 | 348 | const verdict = failures.failed(failKey(item), () => { |
| 348 | 349 | if (!stopped) enqueue({ ...item, at: Date.now() }); |
| 349 | 350 | }); |
| 350 | if (!verdict.retry) | |
| 351 | if (verdict.retry) noteRetry(app, item.appId, item.env, Date.now() + verdict.waitMs); | |
| 352 | else { | |
| 353 | clearRetry(app, item.appId, item.env); | |
| 351 | 354 | log.warn("look given up: the picture failed every time", { |
| 352 | 355 | app: item.appId, |
| 353 | 356 | env: item.env, |
| 354 | 357 | tries: verdict.tries, |
| 355 | 358 | }); |
| 359 | } | |
| 356 | 360 | } |
| 357 | 361 | |
| 358 | 362 | prune(); |
| @@ -773,7 +777,10 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle { | ||
| 773 | 777 | if (options.capture === undefined) await closeBrowsers(host); |
| 774 | 778 | } |
| 775 | 779 | if (failedHere) failed(item); |
| 776 | else failures.succeeded(failKey(item)); | |
| 780 | else { | |
| 781 | failures.succeeded(failKey(item)); | |
| 782 | clearRetry(app, item.appId, item.env); | |
| 783 | } | |
| 777 | 784 | // A full set at this head is the environment's look now; the pictures |
| 778 | 785 | // of heads before it have nothing left to say. |
| 779 | 786 | if (allOk) |
src/looks/why.ts added +34
| @@ -0,0 +1,34 @@ | ||
| 1 | /** | |
| 2 | * Why a card has no picture, in one line (#16257), from what the forge knows: whether this viewer | |
| 3 | * may be shown one, the look's recorded error, the backoff's next try and the app's state. Plain | |
| 4 | * data in, one line or nothing out; nothing is made up (no "taking a picture": the forge does not | |
| 5 | * know a capture is queued), so with no reason the card says none. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { EnvState } from "../apps/runtime.ts"; | |
| 9 | import { NOT_SERVING } from "./service.ts"; | |
| 10 | ||
| 11 | export interface NoPicture { | |
| 12 | /** Whether this viewer may be shown the app's pictures (`mayFetchLook`; a public app's: yes). */ | |
| 13 | readonly readable: boolean; | |
| 14 | /** The recorded error of production's newest look at its head, if it failed. */ | |
| 15 | readonly error: string | null | undefined; | |
| 16 | /** When the backoff tries again, if one waits. */ | |
| 17 | readonly retryAt: number | undefined; | |
| 18 | readonly state: EnvState | undefined; | |
| 19 | } | |
| 20 | ||
| 21 | const PRIVATE = "pictures are the writers' on this private app"; | |
| 22 | const UP: ReadonlySet<EnvState> = new Set<EnvState>(["running", "asleep", "deploying"]); | |
| 23 | ||
| 24 | const pad = (n: number): string => String(n).padStart(2, "0"); | |
| 25 | /** HH:MM, UTC: the same on every viewer's page, and honest about it. */ | |
| 26 | export const clock = (at: number): string => `${pad(new Date(at).getUTCHours())}:${pad(new Date(at).getUTCMinutes())} UTC`; | |
| 27 | ||
| 28 | export function whyNoPicture(of: NoPicture): string | undefined { | |
| 29 | if (!of.readable) return PRIVATE; | |
| 30 | if (of.error === NOT_SERVING) return NOT_SERVING; | |
| 31 | if (of.retryAt !== undefined) return `failed under load; retrying at ${clock(of.retryAt)}`; | |
| 32 | if (of.state !== undefined && !UP.has(of.state)) return NOT_SERVING; | |
| 33 | return undefined; | |
| 34 | } |
src/tui/screens/front.ts +5 −3
| @@ -23,12 +23,14 @@ interface FrontRow { | ||
| 23 | 23 | mark: "featured" | "pinned" | "hidden" | ""; |
| 24 | 24 | score: number | undefined; |
| 25 | 25 | signals: Signals | undefined; |
| 26 | /** Why the page shows no picture of it (#16257). */ | |
| 27 | why?: string | null; | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | 30 | const meta = (r: FrontRow): string => |
| 29 | 31 | r.signals === undefined || r.score === undefined |
| 30 | 32 | ? "kept off the page" |
| 31 | : `score ${r.score} · forks ${r.signals.forks} · ships ${r.signals.ships} · use ${Math.round(r.signals.awakeHours)}h · fresh ${r.signals.shippedAt?.slice(0, 10) ?? "never"}`; | |
| 33 | : `${r.why ? `${r.why} · ` : ""}score ${r.score} · forks ${r.signals.forks} · ships ${r.signals.ships} · use ${Math.round(r.signals.awakeHours)}h · fresh ${r.signals.shippedAt?.slice(0, 10) ?? "never"}`; | |
| 32 | 34 | |
| 33 | 35 | export function frontScreen(f: Session, ctx: Ctx): Screen { |
| 34 | 36 | const state = new ListState(); |
| @@ -45,9 +47,9 @@ export function frontScreen(f: Session, ctx: Ctx): Screen { | ||
| 45 | 47 | const page = frontJson(f.app, undefined); |
| 46 | 48 | const shown: FrontRow[] = []; |
| 47 | 49 | if (page.featured !== null) |
| 48 | shown.push({ repo: page.featured.repo, mark: "featured", score: page.featured.score, signals: page.featured.signals }); | |
| 50 | shown.push({ repo: page.featured.repo, mark: "featured", score: page.featured.score, signals: page.featured.signals, why: page.featured.why }); | |
| 49 | 51 | for (const a of page.apps) |
| 50 | shown.push({ repo: a.repo, mark: a.pinned ? "pinned" : "", score: a.score, signals: a.signals }); | |
| 52 | shown.push({ repo: a.repo, mark: a.pinned ? "pinned" : "", score: a.score, signals: a.signals, why: a.why }); | |
| 51 | 53 | if (mayEdit()) { |
| 52 | 54 | const picks = frontPicksJson(f.app); |
| 53 | 55 | pinned = [...picks.pinned]; |
src/web/look_none.ts added +12
| @@ -0,0 +1,12 @@ | ||
| 1 | /** | |
| 2 | * The slot of a card whose app has no picture to show (#16257): the picture's own size, so nothing | |
| 3 | * shifts when one arrives, holding the app's name set well on a calm ground and, when the forge has | |
| 4 | * one, the one line why. Never a broken image, never a question mark. Both words are escaped by | |
| 5 | * `html`. | |
| 6 | */ | |
| 7 | ||
| 8 | import { html, type Html } from "./html.ts"; | |
| 9 | ||
| 10 | export function noPicture(name: string, why: string | undefined, slot: string): Html { | |
| 11 | return html`<span class="look look-none" data-slot="${slot}" data-no-picture>${name === "" ? null : html`<span class="look-none-name">${name}</span>`}${why === undefined ? null : html`<span class="look-none-why muted small">${why}</span>`}</span>`; | |
| 12 | } |
src/web/pages/looks.ts +19 −1
| @@ -34,6 +34,10 @@ import { blobKey, keyFacts, lookStore, serveBlob } from "../../looks/archive.ts" | ||
| 34 | 34 | import { pairCounts, pairsLine } from "../../looks/pairs.ts"; |
| 35 | 35 | import { mayFetchLook as mayFetchLookFor } from "../../looks/readable.ts"; |
| 36 | 36 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| 37 | import { retryAt } from "../../looks/retries.ts"; | |
| 38 | import { whyNoPicture } from "../../looks/why.ts"; | |
| 39 | import { appsRuntime } from "../../apps/runtime.ts"; | |
| 40 | import { noPicture } from "../look_none.ts"; | |
| 37 | 41 | import { loadRepo, repoBase } from "../chrome.ts"; |
| 38 | 42 | import { html, when, type Html } from "../html.ts"; |
| 39 | 43 | import { disclosure, sha, time } from "../ui.ts"; |
| @@ -373,7 +377,21 @@ export function lookNow(ctx: Ctx, repo: Repo, record: AppRecord): Html { | ||
| 373 | 377 | const look = [pictured(looks, "thumb"), pictured(looks, "desktop")].find( |
| 374 | 378 | (l) => l !== undefined && mayFetchLook(ctx, repo, record, l), |
| 375 | 379 | ); |
| 376 | if (look === undefined) return html``; | |
| 380 | if (look === undefined) { | |
| 381 | // No picture to show: the card says why when the forge knows (#16257), in the picture's box. | |
| 382 | const head = looks.find((l) => l.kind === "thumb" && l.error !== null); | |
| 383 | const state = appsRuntime(ctx.app)?.status(record).find((e) => e.env === "production")?.state; | |
| 384 | return noPicture( | |
| 385 | repo.name, | |
| 386 | whyNoPicture({ | |
| 387 | readable: record.access === "public" || canSeeOwnerFacts(ctx.app.db, repo, ctx.auth.user), | |
| 388 | error: head?.error, | |
| 389 | retryAt: retryAt(ctx.app, record.id, "production"), | |
| 390 | state, | |
| 391 | }), | |
| 392 | "now", | |
| 393 | ); | |
| 394 | } | |
| 377 | 395 | const base = repoBase(repo); |
| 378 | 396 | const size = LOOK_SIZES[look.kind]; |
| 379 | 397 | return html`<a |
src/web/studio/home.ts +4
| @@ -31,6 +31,7 @@ import { GET_A_FORGE_PATH } from "../../billing/plan_words.ts"; | ||
| 31 | 31 | import { appsForRepos } from "../../core/apps.ts"; |
| 32 | 32 | import { WEIGHT_MAX, WEIGHT_NAMES } from "../../core/front.ts"; |
| 33 | 33 | import { LOOK_SIZES } from "../../core/looks.ts"; |
| 34 | import { noPicture } from "../look_none.ts"; | |
| 34 | 35 | import { canRead, getRepo } from "../../core/repos.ts"; |
| 35 | 36 | import { type User } from "../../core/users.ts"; |
| 36 | 37 | import type { Ctx } from "../../http/context.ts"; |
| @@ -573,6 +574,9 @@ function tile(entry: FrontEntry, at: number, accounts: boolean, attrs?: Html): H | ||
| 573 | 574 | picture, |
| 574 | 575 | (src) => |
| 575 | 576 | html`<a class="look" href="${open ?? href}" tabindex="-1" aria-hidden="true"${open === undefined ? null : html` rel="nofollow"`}><img src="${src}" width="${LOOK_SIZES.thumb.width}" height="${LOOK_SIZES.thumb.height}" alt="" loading="lazy" decoding="async"></a>`, |
| 577 | )}${when( | |
| 578 | picture === undefined, | |
| 579 | () => noPicture(repo.name, entry.why, "tile"), | |
| 576 | 580 | )}<div class="card-body stack stack-tight"><a href="${href}"><strong>${repo.name}</strong></a><span class="muted door-line" title="${repo.description}">${repo.description !== "" ? repo.description : `By ${repo.ownerName}`}</span>${when(entry.importedFrom, (from) => html`<span class="muted small" data-imported>Imported from ${from}</span>`)}<p class="door-verbs">${when( |
| 577 | 581 | open, |
| 578 | 582 | (to) => html`<a class="door-verb-first" href="${to}" rel="nofollow" aria-label="Open ${repo.name}">Open</a>`, |
src/web/style/components.ts +4
| @@ -477,6 +477,10 @@ kbd { | ||
| 477 | 477 | .look[data-slot="feed"] { width: 160px; height: 100px; margin-top: 6px; } |
| 478 | 478 | .look[data-slot="feed"] img { height: 100%; object-fit: cover; object-position: top; } |
| 479 | 479 | .look[data-slot="now"] { flex: none; width: 168px; } |
| 480 | /* A card with no picture: the thumb's own box (8:5), the app's name on the calm ground and, when the forge has one, why. */ | |
| 481 | .look-none { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; aspect-ratio: 8 / 5; padding: 8px; text-align: center; overflow-wrap: anywhere; } | |
| 482 | .look-none-name { font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; } | |
| 483 | .look[data-slot="now"].look-none { flex: none; width: 168px; } | |
| 480 | 484 | .looks { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; } |
| 481 | 485 | .looks > [data-slot="phone"] { flex: 0 0 200px; } |
| 482 | 486 | .looks > [data-slot="desktop"] { flex: 1 1 320px; min-width: 0; max-width: 1280px; } |
test/front.test.ts +31
| @@ -11,6 +11,8 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 11 | 11 | import { tmpdir } from "node:os"; |
| 12 | 12 | import { join } from "node:path"; |
| 13 | 13 | import { createApp, type App } from "../src/app.ts"; |
| 14 | import { lookNow } from "../src/web/pages/looks.ts"; | |
| 15 | import type { Ctx } from "../src/http/context.ts"; | |
| 14 | 16 | import { suspendAccount } from "../src/actions/accounts.ts"; |
| 15 | 17 | import { forgetFrontScores, frontPage } from "../src/actions/front.ts"; |
| 16 | 18 | import * as lookService from "../src/looks/service.ts"; |
| @@ -692,6 +694,35 @@ describe("the front page", () => { | ||
| 692 | 694 | } |
| 693 | 695 | }, 60_000); |
| 694 | 696 | |
| 697 | test("a pinned card with no picture is a named box, with the reason when the forge has one, never an image (#16257)", async () => { | |
| 698 | const bare = await make(admin, "card-bare", { picture: false }); | |
| 699 | expect((await put(adminToken, { pinned: ["owner/card-bare"], hidden: [] })).status).toBe(200); | |
| 700 | const card = (html: string): string => html.slice(html.indexOf("data-no-picture"), html.indexOf("data-no-picture") + 400); | |
| 701 | let body = await door(); | |
| 702 | expect(body).toContain("data-no-picture"); | |
| 703 | expect(card(body)).toContain("card-bare"); | |
| 704 | expect(card(body)).not.toContain("look-none-why"); | |
| 705 | expect(card(body)).not.toContain("<img"); | |
| 706 | expect(body).not.toContain("taking a picture"); | |
| 707 | recordLook(app.db, { appId: bare.record.id, env: "production", commitOid: HEAD, kind: "thumb", path: "looks/none.png", error: "not serving" }); | |
| 708 | body = await door(); | |
| 709 | expect(card(body)).toContain("not serving"); | |
| 710 | expect(card(body)).not.toContain("<img"); | |
| 711 | }); | |
| 712 | ||
| 713 | test("the app head's card for a private app says the pictures are the writers', to a stranger; with no reason it holds the name (#16257)", async () => { | |
| 714 | const priv = await make(other, "head-private", { visibility: "private", picture: false }); | |
| 715 | app.db.query(`UPDATE app SET access = 'private' WHERE id = ?1`).run(priv.record.id); | |
| 716 | const ctxOf = (user: User | undefined) => ({ app, auth: { user } }) as unknown as Ctx; | |
| 717 | const seen = String(lookNow(ctxOf(undefined), priv.repo, { ...priv.record, access: "private" })); | |
| 718 | expect(seen).toContain("pictures are the writers' on this private app"); | |
| 719 | expect(seen).not.toContain("<img"); | |
| 720 | const open = await make(admin, "head-open", { picture: false }); | |
| 721 | const named = String(lookNow(ctxOf(admin), open.repo, open.record)); | |
| 722 | expect(named).toContain("head-open"); | |
| 723 | expect(named).not.toContain("look-none-why"); | |
| 724 | }); | |
| 725 | ||
| 695 | 726 | test("a pinned repository whose app is private tells a stranger neither the app's state nor its hours awake, on the API and MCP, and is featured whatever its state", async () => { |
| 696 | 727 | const gated = await make(other, "gated-pin"); |
| 697 | 728 | app.db.query(`UPDATE app SET access = 'private' WHERE id = ?1`).run(gated.record.id); |
test/look-none.test.ts added +58
| @@ -0,0 +1,58 @@ | ||
| 1 | import { afterAll, expect, test } from "bun:test"; | |
| 2 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { createApp, type App } from "../src/app.ts"; | |
| 6 | import { clearRetry, noteRetry, retryAt } from "../src/looks/retries.ts"; | |
| 7 | import { NOT_SERVING } from "../src/looks/service.ts"; | |
| 8 | import { whyNoPicture } from "../src/looks/why.ts"; | |
| 9 | import { noPicture } from "../src/web/look_none.ts"; | |
| 10 | ||
| 11 | const dir = mkdtempSync(join(tmpdir(), "look-none-")); | |
| 12 | const app: App = createApp({ dataDir: dir, port: 0 }); | |
| 13 | afterAll(() => { | |
| 14 | app.close(); | |
| 15 | rmSync(dir, { recursive: true, force: true }); | |
| 16 | }); | |
| 17 | const base = { readable: true, error: null, retryAt: undefined, state: undefined } as const; | |
| 18 | ||
| 19 | test("each reason the forge has is one line", () => { | |
| 20 | expect(whyNoPicture({ ...base, state: "failed" })).toBe("not serving"); | |
| 21 | expect(whyNoPicture({ ...base, state: "running", error: NOT_SERVING })).toBe("not serving"); | |
| 22 | expect(whyNoPicture({ ...base, state: "running", retryAt: Date.UTC(2026, 0, 1, 9, 5) })).toBe( | |
| 23 | "failed under load; retrying at 09:05 UTC", | |
| 24 | ); | |
| 25 | expect(whyNoPicture({ ...base, readable: false, state: "running" })).toBe( | |
| 26 | "pictures are the writers' on this private app", | |
| 27 | ); | |
| 28 | }); | |
| 29 | ||
| 30 | test("with no reason there is none, even for an app that is up", () => { | |
| 31 | expect(whyNoPicture(base)).toBeUndefined(); | |
| 32 | expect(whyNoPicture({ ...base, state: "running" })).toBeUndefined(); | |
| 33 | }); | |
| 34 | ||
| 35 | test("a retry is read until it is due, then it is not", () => { | |
| 36 | noteRetry(app, "a1", "production", 5_000); | |
| 37 | expect(retryAt(app, "a1", "production", 1_000)).toBe(5_000); | |
| 38 | expect(retryAt(app, "a1", "production", 5_000)).toBeUndefined(); | |
| 39 | noteRetry(app, "a1", "production", 9_000); | |
| 40 | clearRetry(app, "a1", "production"); | |
| 41 | expect(retryAt(app, "a1", "production", 1_000)).toBeUndefined(); | |
| 42 | }); | |
| 43 | ||
| 44 | test("the card without a picture escapes the name and the reason, and has no image", () => { | |
| 45 | const out = String(noPicture(`<b>x</b>`, `<script>alert(1)</script>`, "tile")); | |
| 46 | expect(out).not.toContain("<script>"); | |
| 47 | expect(out).not.toContain("<b>x"); | |
| 48 | expect(out).toContain("<script>"); | |
| 49 | expect(out).not.toContain("<img"); | |
| 50 | expect(out).not.toContain("?"); | |
| 51 | expect(out).toContain("data-no-picture"); | |
| 52 | }); | |
| 53 | ||
| 54 | test("without a reason the card holds only the name", () => { | |
| 55 | const out = String(noPicture("Notes", undefined, "now")); | |
| 56 | expect(out).toContain("Notes"); | |
| 57 | expect(out).not.toContain("look-none-why"); | |
| 58 | }); |
test/tui-front.test.ts +18 −1
| @@ -9,7 +9,7 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 9 | 9 | import { tmpdir } from "node:os"; |
| 10 | 10 | import { join } from "node:path"; |
| 11 | 11 | import { createApp, type App as Forge } from "../src/app.ts"; |
| 12 | import { frontJson, forgetFrontScores } from "../src/actions/front.ts"; | |
| 12 | import { frontJson, forgetFrontScores, setFront } from "../src/actions/front.ts"; | |
| 13 | 13 | import { createRepo } from "../src/actions/repos.ts"; |
| 14 | 14 | import { AppsRuntime, type EnvStatus } from "../src/apps/runtime.ts"; |
| 15 | 15 | import { createApp as insertApp, type AppRecord } from "../src/core/apps.ts"; |
| @@ -235,4 +235,21 @@ describe("the front page in the terminal", () => { | ||
| 235 | 235 | expect(mcpOrder()).toContain(first); |
| 236 | 236 | t.stop(); |
| 237 | 237 | }); |
| 238 | ||
| 239 | test("an app with no picture says why on its row (#16257)", async () => { | |
| 240 | const made = await createRepo(forge, getUserByName(forge.db, "bob")!, { name: "bare", visibility: "public", description: "bare" }); | |
| 241 | if (!made.ok) throw new Error(String(made.error)); | |
| 242 | const record = insertApp(forge.db, { repoId: made.value.id, slug: "bare", access: "public" }); | |
| 243 | if (!record.ok) throw new Error(record.error); | |
| 244 | recordLook(forge.db, { appId: record.value.id, env: "production", commitOid: HEAD, kind: "thumb", path: "looks/none.png", error: "not serving" }); | |
| 245 | // Only a first pin may lack a picture: it is featured as a card. | |
| 246 | const set = setFront(forge, getUserByName(forge.db, "alice")!, { pinned: ["bob/bare"], hidden: [] }); | |
| 247 | expect(set.ok).toBe(true); | |
| 248 | forgetFrontScores(forge); | |
| 249 | const t = boot("alice"); | |
| 250 | await t.open(); | |
| 251 | expect(t.text()).toContain("bob/bare"); | |
| 252 | expect(t.text()).toContain("not serving"); | |
| 253 | t.stop(); | |
| 254 | }); | |
| 238 | 255 | }); |
new above
offline
'taking a picture' is the fallback for any up app with no error and no pending retry. After a give-up or a restart that is untrue. Say it only when a capture is queued or running; otherwise return undefined so the name shows.