Public: anyone can read this; the crew can change it.
A template's page lists the apps it brings and the model and budget defaults, in plain words #13495
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13466-a-template-s-page-lists-the-apps-it-brin → main 4 commits fork 3 threads · 3 unresolved
12 files
changed +293
−6
docs/features/README.md +1
| @@ -40,6 +40,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md). | ||
| 40 | 40 | - [](home-plans.md) |
| 41 | 41 | - [](returning-visitors.md) |
| 42 | 42 | - [](repo-template.md) |
| 43 | - [](template-page-gets.md) | |
| 43 | 44 | - [](setting-history.md) |
| 44 | 45 | - [](new-forge-template.md) |
| 45 | 46 | - [](spawn-recipes.md) |
docs/features/template-page-gets.md added +7
| @@ -0,0 +1,7 @@ | ||
| 1 | # What a template gives | |
| 2 | ||
| 3 | A template repository's page has a "What you get" card: the apps it brings (name and one line each), the starter budget and the model default, so choosing a template tells what you get. A template that says none of these says so in a sentence of its own ("It brings no apps of its own.", "It sets no starter budget.", "It sets no model default."); no line is blank. The terminal's App templates screen shows the same lines for the template under the cursor. | |
| 4 | ||
| 5 | They are read from the default branch's `forge.json`: `"template": { "apps": [{ "name": "notes", "says": "A notes app" }], "budgetUsd": 5, "model": "claude-sonnet-5-5" }`. A field that is missing or wrong counts as unsaid. | |
| 6 | ||
| 7 | Code: `src/spawn/template_facts.ts` (parse, wording), `src/web/template_card.ts` (the card). Test: `test/template-page-gets.test.ts`. |
src/checks/looks.ts +1 −1
| @@ -31,7 +31,7 @@ const SAFE = /^[0-9A-Za-z]{1,64}$/; | ||
| 31 | 31 | |
| 32 | 32 | const MAX_BYTES = 1024 * 1024; |
| 33 | 33 | // The forge's own preview takes ~55 looks (`PREVIEW_OWNER_LOOKS`); every one must fit. |
| 34 | const MAX_LOOKS = 76; | |
| 34 | const MAX_LOOKS = 80; | |
| 35 | 35 | const MAX_WORDS = 80; |
| 36 | 36 | |
| 37 | 37 | const words = (v: unknown): string | null => |
src/spawn/preview-looks.ts +9
| @@ -49,6 +49,14 @@ export const PREVIEW_MOVED = "moved"; | ||
| 49 | 49 | export const PREVIEW_MOVED_OWNER = "preview-ada"; |
| 50 | 50 | export const PREVIEW_MOVED_PAGE = `/${PREVIEW_MOVED_OWNER}/${PREVIEW_MOVED}`; |
| 51 | 51 | |
| 52 | /** | |
| 53 | * A template repository (#13466): marked, with a forge.json whose template block names two apps, | |
| 54 | * a starter budget and a model default, so its head draws the "What you get" card. The seed | |
| 55 | * refuses to finish unless the page answers 200 and holds `id="template-gets"`. | |
| 56 | */ | |
| 57 | export const PREVIEW_TEMPLATE = "kit"; | |
| 58 | export const PREVIEW_TEMPLATE_PAGE = `/${PREVIEW_ADMIN}/${PREVIEW_TEMPLATE}`; | |
| 59 | ||
| 52 | 60 | /** |
| 53 | 61 | * The sample's Settings scrolled to "Move to another owner" by the fragment |
| 54 | 62 | * (#10194): the owner field, button and refusal sentences must fit a 390 px |
| @@ -209,6 +217,7 @@ export const PREVIEW_OWNER_LOOKS: readonly OwnerLook[] = [ | ||
| 209 | 217 | PREVIEW_APP_PAGE, |
| 210 | 218 | PREVIEW_DROP_PAGE, |
| 211 | 219 | PREVIEW_MOVED_PAGE, |
| 220 | PREVIEW_TEMPLATE_PAGE, | |
| 212 | 221 | PREVIEW_MOVE_LOOK, |
| 213 | 222 | PREVIEW_PULL_PAGE, |
| 214 | 223 | PREVIEW_PULL_FILES, |
src/spawn/preview-seed.ts +42 −1
| @@ -32,7 +32,7 @@ import { backBet } from "../actions/bets.ts"; | ||
| 32 | 32 | import { openIssue, setIssueState } from "../actions/issues.ts"; |
| 33 | 33 | import { pinBuild } from "../actions/builds.ts"; |
| 34 | 34 | import { addReview, mergePull, openPull } from "../actions/pulls.ts"; |
| 35 | import { commitToBranch, createRepo, forkRepo } from "../actions/repos.ts"; | |
| 35 | import { commitToBranch, createRepo, forkRepo, updateRepoSettings } from "../actions/repos.ts"; | |
| 36 | 36 | import { reviewGate } from "../actions/gate_review.ts"; |
| 37 | 37 | import { forgeHttp } from "../http/server.ts"; |
| 38 | 38 | import { transferRepository } from "../actions/transfer.ts"; |
| @@ -83,6 +83,8 @@ import { | ||
| 83 | 83 | PREVIEW_NEWCOMER_ORG, |
| 84 | 84 | PREVIEW_REPO, |
| 85 | 85 | PREVIEW_SETTINGS_PAGES, |
| 86 | PREVIEW_TEMPLATE, | |
| 87 | PREVIEW_TEMPLATE_PAGE, | |
| 86 | 88 | } from "./preview-looks.ts"; |
| 87 | 89 | |
| 88 | 90 | export { |
| @@ -132,6 +134,43 @@ async function seedMoved(app: App, admin: User): Promise<Result<void, string>> { | ||
| 132 | 134 | return ok(); |
| 133 | 135 | } |
| 134 | 136 | |
| 137 | /** | |
| 138 | * A marked template whose head draws "What you get" (#13466); refused unless the page holds the | |
| 139 | * card. | |
| 140 | */ | |
| 141 | async function seedTemplate(app: App, admin: User): Promise<Result<void, string>> { | |
| 142 | const made = await createRepo(app, admin, { name: PREVIEW_TEMPLATE, visibility: "public", description: "A starter kit" }); | |
| 143 | if (!made.ok) return err(`the template repository: ${String(made.error)}`); | |
| 144 | const forgeJson = JSON.stringify({ | |
| 145 | app: { run: "bun run README.md" }, | |
| 146 | template: { | |
| 147 | apps: [{ name: "notes", says: "A page of notes that saves as you type" }, { name: "board" }], | |
| 148 | budgetUsd: 5, | |
| 149 | model: "claude-sonnet-5-5", | |
| 150 | }, | |
| 151 | }); | |
| 152 | const first = await commitToBranch(app, admin, made.value, { | |
| 153 | message: "Start", | |
| 154 | files: [{ path: "README.md", content: "# kit\n" }, { path: "forge.json", content: forgeJson }], | |
| 155 | }); | |
| 156 | if (!first.ok) return err(`the template's commit: ${JSON.stringify(first.error)}`); | |
| 157 | const marked = await updateRepoSettings(app, admin, made.value, { template: true }); | |
| 158 | if (!marked.ok) return err(`marking the template: ${JSON.stringify(marked.error)}`); | |
| 159 | const http = forgeHttp(app); | |
| 160 | const session = createSession(app.db, admin.id); | |
| 161 | try { | |
| 162 | const res = await http.handle( | |
| 163 | new Request(`http://localhost${PREVIEW_TEMPLATE_PAGE}`, { headers: { cookie: `forge_session=${session.token}` } }), | |
| 164 | ); | |
| 165 | if (res.status !== 200) return err(`${PREVIEW_TEMPLATE_PAGE} answers ${String(res.status)}, not 200`); | |
| 166 | if (!(await res.text()).includes('id="template-gets"')) return err(`${PREVIEW_TEMPLATE_PAGE} holds no template card`); | |
| 167 | } finally { | |
| 168 | destroySession(app.db, session.token); | |
| 169 | http.close(); | |
| 170 | } | |
| 171 | return ok(); | |
| 172 | } | |
| 173 | ||
| 135 | 174 | /** |
| 136 | 175 | * The sample's Settings, asked for as the admin through `ask`, must answer |
| 137 | 176 | * 200 and hold `id="move"`: the section its phone look scrolls to (#10194). |
| @@ -616,6 +655,8 @@ async function seedWorld(app: App, admin: User): Promise<Result<void, string>> { | ||
| 616 | 655 | if (!hosted.ok) return hosted; |
| 617 | 656 | const moved = await seedMoved(app, admin); |
| 618 | 657 | if (!moved.ok) return moved; |
| 658 | const template = await seedTemplate(app, admin); | |
| 659 | if (!template.ok) return template; | |
| 619 | 660 | const valve = turnValveFor(app, admin, `${PREVIEW_ADMIN}/${PREVIEW_REPO}`, 60); |
| 620 | 661 | if (!valve.ok) return err(`the valve: ${valve.error}`); |
| 621 | 662 |
src/spawn/template_facts.ts added +65
| @@ -0,0 +1,65 @@ | ||
| 1 | /** | |
| 2 | * What a forge made from a template repository gets, in plain words (#13466): the apps it brings, | |
| 3 | * the starter budget and the model default, read from the `template` block of the repository's | |
| 4 | * `forge.json`: `{ "template": { "apps": [{ "name", "says" }], "budgetUsd": 5, "model": "…" } }`. | |
| 5 | * A thing the file does not say, or says wrongly, has a sentence of its own; nothing is blank and | |
| 6 | * nothing is guessed. Pure: text in, lines out. | |
| 7 | */ | |
| 8 | ||
| 9 | export interface TemplateApp { | |
| 10 | readonly name: string; | |
| 11 | /** Empty when the file says nothing: no filler sentence stands in for it. */ | |
| 12 | readonly says: string; | |
| 13 | } | |
| 14 | ||
| 15 | export interface TemplateFacts { | |
| 16 | readonly apps: readonly TemplateApp[]; | |
| 17 | readonly budgetUsd: number | undefined; | |
| 18 | readonly model: string | undefined; | |
| 19 | } | |
| 20 | ||
| 21 | export const NO_APPS = "None of its own"; | |
| 22 | export const NO_BUDGET = "Not set"; | |
| 23 | export const NO_MODEL = "Not set"; | |
| 24 | ||
| 25 | const MAX_APPS = 20; | |
| 26 | const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/; | |
| 27 | const text = (v: unknown, max: number): string | undefined => | |
| 28 | typeof v === "string" && v.trim() !== "" && v.length <= max && !/[\u0000-\u001f\u007f]/.test(v) ? v.trim() : undefined; | |
| 29 | ||
| 30 | /** The facts a `forge.json` text declares; every field optional, a bad one counts as unsaid. */ | |
| 31 | export function templateFacts(forgeJson: string | undefined): TemplateFacts { | |
| 32 | let raw: unknown; | |
| 33 | try { | |
| 34 | raw = forgeJson === undefined ? undefined : JSON.parse(forgeJson); | |
| 35 | } catch { | |
| 36 | raw = undefined; | |
| 37 | } | |
| 38 | const block = typeof raw === "object" && raw !== null ? (raw as Record<string, unknown>)["template"] : undefined; | |
| 39 | const t = typeof block === "object" && block !== null && !Array.isArray(block) ? (block as Record<string, unknown>) : {}; | |
| 40 | const apps: TemplateApp[] = []; | |
| 41 | if (Array.isArray(t["apps"])) { | |
| 42 | for (const a of t["apps"].slice(0, MAX_APPS) as unknown[]) { | |
| 43 | const r = typeof a === "object" && a !== null ? (a as Record<string, unknown>) : {}; | |
| 44 | const name = typeof r["name"] === "string" && NAME.test(r["name"]) ? r["name"] : undefined; | |
| 45 | if (name === undefined || apps.some((x) => x.name === name)) continue; | |
| 46 | apps.push({ name, says: text(r["says"], 200) ?? "" }); | |
| 47 | } | |
| 48 | } | |
| 49 | const b = t["budgetUsd"]; | |
| 50 | const budgetUsd = typeof b === "number" && Number.isFinite(b) && b >= 0 && b <= 1000 ? b : undefined; | |
| 51 | return { apps, budgetUsd, model: text(t["model"], 80) }; | |
| 52 | } | |
| 53 | ||
| 54 | const dollars = (n: number): string => `$${Number.isInteger(n) ? n : n.toFixed(2)}`; | |
| 55 | ||
| 56 | /** The facts as label/value rows, in order: each app, then the budget, then the model. */ | |
| 57 | export function templateRows(f: TemplateFacts): { label: string; value: string }[] { | |
| 58 | return [ | |
| 59 | ...(f.apps.length === 0 | |
| 60 | ? [{ label: "Apps", value: NO_APPS }] | |
| 61 | : f.apps.map((a) => ({ label: "App", value: a.says === "" ? a.name : `${a.name}: ${a.says}` }))), | |
| 62 | { label: "Starter budget", value: f.budgetUsd === undefined ? NO_BUDGET : dollars(f.budgetUsd) }, | |
| 63 | { label: "Model default", value: f.model === undefined ? NO_MODEL : f.model }, | |
| 64 | ]; | |
| 65 | } |
src/tui/screens/app_templates.ts +18 −1
| @@ -8,6 +8,8 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | import { MARK_TEMPLATE_ERRORS, markTemplate } from "../../actions/app_templates.ts"; |
| 11 | import { templateFactsOf } from "../../web/template_card.ts"; | |
| 12 | import { templateRows, type TemplateFacts } from "../../spawn/template_facts.ts"; | |
| 11 | 13 | import { DEFAULT_TEMPLATE, markedTemplates } from "../../core/app_templates.ts"; |
| 12 | 14 | import type { Ctx, Screen } from "../app/app.ts"; |
| 13 | 15 | import type { PaletteEntry } from "./entries.ts"; |
| @@ -24,6 +26,18 @@ export function appTemplatesScreen(f: Session, ctx: Ctx): Screen { | ||
| 24 | 26 | const state = new ListState(); |
| 25 | 27 | let rows: { name: string; visibility: string }[] = []; |
| 26 | 28 | let note = ""; |
| 29 | // What each marked template brings, read once per row as the cursor reaches it. | |
This behaviour (learn/gets and the lines under the header) has no test. Add one in test/tui-app-templates.test.ts. |
||
| 30 | const gets = new Map<string, string[]>(); | |
| 31 | const learn = (name: string): void => { | |
| 32 | if (gets.has(name)) return; | |
| 33 | const repo = markedTemplates(f.db).find((r) => `${r.ownerName}/${r.name}` === name); | |
| 34 | if (repo === undefined) return; | |
| 35 | gets.set(name, []); | |
| 36 | void templateFactsOf(f.app, repo).then((facts: TemplateFacts) => { | |
| 37 | gets.set(name, templateRows(facts).map((r) => `${r.label}: ${r.value}`)); | |
| 38 | ctx.invalidate(); | |
| 39 | }, () => gets.delete(name)); | |
| 40 | }; | |
| 27 | 41 | const reload = (): void => { |
| 28 | 42 | rows = mayMark(f) |
| 29 | 43 | ? markedTemplates(f.db).map((r) => ({ name: `${r.ownerName}/${r.name}`, visibility: r.visibility })) |
| @@ -68,7 +82,10 @@ export function appTemplatesScreen(f: Session, ctx: Ctx): Screen { | ||
| 68 | 82 | render(area, s) { |
| 69 | 83 | const c = ctx.theme.c; |
| 70 | 84 | const text = note !== "" ? note : mayMark(f) ? `${rows.length} offered by New app.` : MARK_TEMPLATE_ERRORS.forbidden; |
| 71 | const said = wrap(text, Math.max(1, area.w)).slice(0, 3); | |
| 85 | const at = rows[state.index]; | |
| 86 | if (at !== undefined && mayMark(f)) learn(at.name); | |
| 87 | const detail = at === undefined ? [] : (gets.get(at.name) ?? []); | |
| 88 | const said = [...wrap(text, Math.max(1, area.w)).slice(0, 3), ...detail.flatMap((l) => wrap(l, Math.max(1, area.w))).slice(0, 8)]; | |
| 72 | 89 | const [head, list] = split(area, "v", [len(said.length), fill(1)]); |
| 73 | 90 | said.forEach((line, i) => s.text(head!.x, head!.y + i, line, style(c.mutedFg, c.bg), head!.x + head!.w)); |
| 74 | 91 | drawList(s, list!, c, state, lines()); |
src/web/pages/repo.ts +3 −1
| @@ -85,6 +85,7 @@ import { declaresFeature } from "../../actions/features.ts"; | ||
| 85 | 85 | import { getAppByRepo } from "../../core/apps.ts"; |
| 86 | 86 | import { field, readForm } from "../form.ts"; |
| 87 | 87 | import { html, raw, when, type Html } from "../html.ts"; |
| 88 | import { templateCard } from "../template_card.ts"; | |
| 88 | 89 | import { creditLine } from "../credit_line.ts"; |
| 89 | 90 | import { type CodeRows, rowsMarkup } from "../code_rows.ts"; |
| 90 | 91 | import { gcodeOffThread, rowsOffThread } from "../code_rows_pool.ts"; |
| @@ -1521,10 +1522,11 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 1521 | 1522 | creditLine(ctx, repo, scope.source, ref), |
| 1522 | 1523 | ); |
| 1523 | 1524 | const standing = await timePhaseAsync(ctx.request, "behind", () => standingRegion(ctx, repo)); |
| 1525 | const gets = repo.template ? await timePhaseAsync(ctx.request, "template", () => templateCard(ctx.app, repo)) : null; | |
| 1524 | 1526 | const rendering = performance.now(); |
| 1525 | 1527 | const body = html`${scopeHeader(ctx, scope, "code", { |
| 1526 | 1528 | branchCount: refs.branches.length, |
| 1527 | })}${credit}${standing}${archivedLine(ctx, repo)}${walletLine(ctx, repo)}${reportLine(ctx, repo)}${movedLine(ctx, repo)}${noApp} | |
| 1529 | })}${credit}${standing}${archivedLine(ctx, repo)}${walletLine(ctx, repo)}${reportLine(ctx, repo)}${movedLine(ctx, repo)}${noApp}${gets} | |
| 1528 | 1530 | ${offerUpstream(repo, parent, offer)} |
| 1529 | 1531 | ${latest === null |
| 1530 | 1532 | ? "" |
src/web/template_card.ts added +34
| @@ -0,0 +1,34 @@ | ||
| 1 | /** | |
| 2 | * "What you get" on a template repository's page (#13466): the apps it brings, one line each, the | |
| 3 | * starter budget and the model default, from the default branch's `forge.json`. Only for a | |
| 4 | * repository marked as a template, as the About rail's dl rows; a fact the file is silent on says | |
| 5 | * so. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { App } from "../app.ts"; | |
| 9 | import { readFileAt } from "../apps/checkout.ts"; | |
| 10 | import type { Repo } from "../core/repos.ts"; | |
| 11 | import { resolveOid } from "../git/merge.ts"; | |
| 12 | import { repoDir } from "../git/repos.ts"; | |
| 13 | import { templateFacts, templateRows, type TemplateFacts } from "../spawn/template_facts.ts"; | |
| 14 | import { html, type Html } from "./html.ts"; | |
| 15 | ||
| 16 | /** The facts at the default branch's tip; all unsaid when there is no commit or no file. */ | |
| 17 | export async function templateFactsOf(app: App, repo: Repo): Promise<TemplateFacts> { | |
| 18 | const dir = repoDir(app.reposRoot, repo.ownerName, repo.name); | |
| 19 | const oid = await resolveOid(dir, `refs/heads/${repo.defaultBranch}`); | |
| 20 | return templateFacts(oid ? await readFileAt(dir, oid, "forge.json") : undefined); | |
| 21 | } | |
| 22 | ||
| 23 | export function templateCardHtml(facts: TemplateFacts): Html { | |
| 24 | return html`<section class="settings-block mt" id="template-gets"> | |
| 25 | <h2>What you get</h2> | |
Principle 7: budget and model are facts and should be dl rows (rail-facts), not <p> lines. The apps are a list, so rows, not a bare <ul> inside a settings-block. Principle 1: 'What you get' plus 'It brings 2 apps:' says the same thing twice; drop the lead sentence when there are apps. |
||
| 26 | <dl class="rail-facts"> | |
| 27 | ${templateRows(facts).map((r) => html`<div class="rail-fact"><dt>${r.label}</dt><dd>${r.value}</dd></div>`)} | |
| 28 | </dl> | |
| 29 | </section>`; | |
| 30 | } | |
| 31 | ||
| 32 | export async function templateCard(app: App, repo: Repo): Promise<Html | null> { | |
| 33 | return repo.template ? templateCardHtml(await templateFactsOf(app, repo)) : null; | |
| 34 | } |
test/preview-moved.test.ts +12 −1
| @@ -8,7 +8,7 @@ import { serve, type Servers } from "../src/http/server.ts"; | ||
| 8 | 8 | import { createSession } from "../src/core/sessions.ts"; |
| 9 | 9 | import { recentMove } from "../src/core/transfer.ts"; |
| 10 | 10 | import { getRepo } from "../src/core/repos.ts"; |
| 11 | import { PREVIEW_ADMIN, PREVIEW_MOVED, PREVIEW_MOVED_PAGE, PREVIEW_OWNER_LOOKS } from "../src/spawn/preview-looks.ts"; | |
| 11 | import { PREVIEW_ADMIN, PREVIEW_MOVED, PREVIEW_MOVED_PAGE, PREVIEW_OWNER_LOOKS, PREVIEW_TEMPLATE_PAGE } from "../src/spawn/preview-looks.ts"; | |
| 12 | 12 | import { checkMoveSection, previewAdmin, seedPreview } from "../src/spawn/preview-seed.ts"; |
| 13 | 13 | |
| 14 | 14 | let dir: string; |
| @@ -60,3 +60,14 @@ test("the seed refuses a Settings that is not 200 or lacks the move section", as | ||
| 60 | 60 | const bare = await checkMoveSection(answer(200, "<h2>Move to another owner</h2>")); |
| 61 | 61 | expect(!bare.ok && bare.error).toContain('id="move"'); |
| 62 | 62 | }); |
| 63 | ||
| 64 | test("the template repository's head draws What you get, and is looked at on desktop and phone", async () => { | |
| 65 | for (const kind of ["desktop", "phone"] as const) | |
| 66 | expect(PREVIEW_OWNER_LOOKS).toContainEqual({ page: PREVIEW_TEMPLATE_PAGE, kind }); | |
| 67 | const cookie = `forge_session=${createSession(app.db, previewAdmin(app)!.id).token}`; | |
| 68 | const res = await fetch(`${servers.url}${PREVIEW_TEMPLATE_PAGE}`, { headers: { cookie } }); | |
| 69 | expect(res.status).toBe(200); | |
| 70 | const html = await res.text(); | |
| 71 | expect(html).toContain('id="template-gets"'); | |
| 72 | expect(html).toContain("<dt>Starter budget</dt><dd>$5</dd>"); | |
| 73 | }); |
test/template-page-gets.test.ts added +76
| @@ -0,0 +1,76 @@ | ||
| 1 | /** A template's page says what you get: its apps, starter budget and model default (#13466). */ | |
| 2 | import { afterAll, beforeAll, describe, 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 { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; | |
| 7 | import { createApp, type App } from "../src/app.ts"; | |
| 8 | import { createToken } from "../src/core/tokens.ts"; | |
| 9 | import { createUser } from "../src/core/users.ts"; | |
| 10 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 11 | import { NO_APPS, NO_BUDGET, NO_MODEL, templateFacts, templateRows } from "../src/spawn/template_facts.ts"; | |
| 12 | import { quietLogs } from "./helpers/globals.ts"; | |
| 13 | ||
| 14 | quietLogs(); | |
| 15 | ||
| 16 | describe("what a template gives", () => { | |
| 17 | let dir: string; | |
| 18 | let app: App; | |
| 19 | let servers: Servers; | |
| 20 | let auth = ""; | |
| 21 | ||
| 22 | const make = async (name: string, forgeJson: string | undefined) => { | |
| 23 | const made = await createRepo(app, user, { name, visibility: "public", description: "" }); | |
| 24 | if (!made.ok) throw new Error("repo"); | |
| 25 | const files = [{ path: "a.txt", content: "a" }, ...(forgeJson === undefined ? [] : [{ path: "forge.json", content: forgeJson }])]; | |
| 26 | await commitToBranch(app, user, made.value, { message: "seed", files }); | |
| 27 | const marked = await updateRepoSettings(app, user, made.value, { template: true }); | |
| 28 | if (!marked.ok) throw new Error("mark"); | |
| 29 | }; | |
| 30 | const get = async (name: string) => | |
| 31 | (await fetch(`${servers.url}/alice/${name}`, { headers: { authorization: auth } })).text(); | |
| 32 | let user: Awaited<ReturnType<typeof createUser>> extends infer R ? (R extends { ok: true; value: infer V } ? V : never) : never; | |
| 33 | ||
| 34 | beforeAll(async () => { | |
| 35 | dir = await mkdtemp(join(tmpdir(), "forge-template-gets-")); | |
| 36 | app = createApp({ dataDir: dir, port: 0 }); | |
| 37 | servers = await serve(app); | |
| 38 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 39 | if (!a.ok) throw new Error("user"); | |
| 40 | user = a.value; | |
| 41 | auth = `Bearer ${createToken(app.db, user.id, "rw", "rw").token}`; | |
| 42 | await make( | |
| 43 | "full", | |
| 44 | JSON.stringify({ app: { run: "x" }, template: { apps: [{ name: "notes", says: "A <b>notes</b> app" }, { name: "board" }], budgetUsd: 5, model: "claude-sonnet-5-5" } }), | |
| 45 | ); | |
| 46 | await make("bare", JSON.stringify({ app: { run: "x" } })); | |
| 47 | }, 30_000); | |
| 48 | ||
| 49 | afterAll(async () => { | |
| 50 | servers.stop(); | |
| 51 | app.close(); | |
| 52 | await rm(dir, { recursive: true, force: true }); | |
| 53 | }); | |
| 54 | ||
| 55 | test("the page lists apps, the starter budget and the model default as dl rows", async () => { | |
| 56 | const page = await get("full"); | |
| 57 | expect(page).toContain('id="template-gets"'); | |
| 58 | expect(page).toContain('<dl class="rail-facts">'); | |
| 59 | expect(page).toContain("<dt>App</dt><dd>notes: A <b>notes</b> app</dd>"); | |
| 60 | expect(page).toContain("<dt>App</dt><dd>board</dd>"); | |
| 61 | expect(page).not.toContain("No description"); | |
| 62 | expect(page).toContain("<dt>Starter budget</dt><dd>$5</dd>"); | |
| 63 | expect(page).toContain("<dt>Model default</dt><dd>claude-sonnet-5-5</dd>"); | |
| 64 | }); | |
| 65 | ||
| 66 | test("a template that says none of it says so on each row", async () => { | |
| 67 | const page = await get("bare"); | |
| 68 | for (const v of [NO_APPS, NO_BUDGET, NO_MODEL]) expect(page).toContain(`<dd>${v}</dd>`); | |
| 69 | }); | |
| 70 | ||
| 71 | test("a malformed block falls back, never throws", () => { | |
| 72 | for (const text of [undefined, "not json", "[]", '{"template":5}', '{"template":{"apps":"x","budgetUsd":-1,"model":""}}']) { | |
| 73 | expect(templateRows(templateFacts(text)).map((r) => r.value)).toEqual([NO_APPS, NO_BUDGET, NO_MODEL]); | |
| 74 | } | |
| 75 | }); | |
| 76 | }); |
test/tui-app-templates.test.ts +25 −1
| @@ -8,11 +8,12 @@ import { afterAll, beforeAll, describe, expect, setDefaultTimeout, test } from " | ||
| 8 | 8 | import { mkdtemp, rm } from "node:fs/promises"; |
| 9 | 9 | import { tmpdir } from "node:os"; |
| 10 | 10 | import { join } from "node:path"; |
| 11 | import { markTemplate } from "../src/actions/app_templates.ts"; | |
| 11 | 12 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 12 | 13 | import { setRole } from "../src/actions/roles.ts"; |
| 13 | 14 | import { createApp, type App } from "../src/app.ts"; |
| 14 | 15 | import { offeredTemplates } from "../src/core/app_templates.ts"; |
| 15 | import { listReposOwnedBy } from "../src/core/repos.ts"; | |
| 16 | import { getRepo, listReposOwnedBy } from "../src/core/repos.ts"; | |
| 16 | 17 | import { createUser, type User } from "../src/core/users.ts"; |
| 17 | 18 | import { createForgeApp, forgeCommands, Session } from "../src/tui/forge.ts"; |
| 18 | 19 | import { blank } from "../src/tui/screens/common.ts"; |
| @@ -173,3 +174,26 @@ describe("the New app picker", () => { | ||
| 173 | 174 | expect(listReposOwnedBy(app.db, taker.id)).toEqual([]); |
| 174 | 175 | })); |
| 175 | 176 | }); |
| 177 | ||
| 178 | describe("what a template gets, under the cursor", () => { | |
| 179 | test("the lines for the budget and the model default appear for the marked template", async () => { | |
| 180 | const kit = getRepo(app.db, "giver", "kit")!; | |
| 181 | const done = await commitToBranch(app, admin, kit, { | |
| 182 | message: "forge.json", | |
| 183 | files: [{ | |
| 184 | path: "forge.json", | |
| 185 | content: JSON.stringify({ app: { run: "x" }, template: { apps: [{ name: "notes", says: "Notes" }, { name: "board" }], budgetUsd: 5, model: "claude-sonnet-5-5" } }), | |
| 186 | }], | |
| 187 | }); | |
| 188 | if (!done.ok) throw new Error(String(done.error)); | |
| 189 | expect(markTemplate(app, admin, "giver/kit", true).ok).toBe(true); | |
| 190 | await withScreen(admin, markScreen, async ({ text, feed }) => { | |
| 191 | await feed("j"); // the cursor on giver/kit | |
| 192 | await until(() => text().includes("Model default: claude-sonnet-5-5")); | |
| 193 | expect(text()).toContain("App: notes: Notes"); | |
| 194 | expect(text()).toContain("App: board"); | |
| 195 | expect(text()).toContain("Starter budget: $5"); | |
| 196 | }); | |
| 197 | markTemplate(app, admin, "giver/kit", false); | |
| 198 | }); | |
| 199 | }); |
new above
offline
Principle 8/attention rule 2: 'No description.' is a filler line per app. Omit it when the app says nothing.