Public: anyone can read this; the crew can change it.
Making a forge for a client first shows what it will create, then sends: a previewed, receipted step #15702
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15687-making-a-forge-for-a-client-first-shows → main 4 commits fork 7 threads · 7 unresolved
docs/features/client-forge.md +14 −6
| @@ -20,15 +20,24 @@ has the field "Mode of the forked apps" (`migration`), and `spawn` takes | ||
| 20 | 20 | with parity to its copy" and its origin row. The answer holds one claim link, |
| 21 | 21 | shown once. `/forges` and MCP tool `forges` list the forges sent. |
| 22 | 22 | |
| 23 | ## Preview, then send | |
| 24 | ||
| 25 | Before anything is made, the plan lists the apps, the starter budget, the admin | |
| 26 | account's name and the words "This sends one link." That is `/forges/new` with | |
| 27 | See the plan, the terminal's Ctrl+P, and `spawn` with `dryRun` left true. | |
| 28 | ||
| 29 | Confirming makes the forge once and answers a receipt (name, address, apps, | |
| 30 | admin, `linkShown`, and the budget when kept), read from what was made. | |
| 31 | Confirming again makes nothing: the same receipt, `linkShown: false`. | |
| 32 | ||
| 23 | 33 | ## Send the link |
| 24 | 34 | |
| 25 | The sender copies the claim link and sends it. The client opens `/claim` | |
| 26 | (the link carries a fragment that never reaches a log) and makes an account with a username and a password, or a passkey. | |
| 35 | The sender copies the claim link and sends it. The client opens `/claim` and makes an account with a | |
| 36 | username and a password, or a passkey. | |
| 27 | 37 | |
| 28 | 38 | ## First login |
| 29 | 39 | |
| 30 | The client lands on `/`. The page shows a card "Your next steps"; once the crew has a | |
| 31 | direction, the card says it is at work and lists its lines. The card has three steps: make an | |
| 40 | The client lands on `/`. The card "Your next steps" has three steps: make an | |
| 32 | 41 | everyday account, open your apps, tell the crew something. Each step is ticked |
| 33 | 42 | from what happened, never by hand. MCP tool `next_steps` reads the same three |
| 34 | 43 | steps. `/apps` lists the apps and `/feed` lists what the crew did. |
| @@ -42,8 +51,7 @@ same. The crew answers on the app's page; `/:owner/:name/runs` and MCP tool | ||
| 42 | 51 | |
| 43 | 52 | ## What the client never sees |
| 44 | 53 | |
| 45 | Settings, tokens, run logs and git words belong to the admin. The client sees | |
| 46 | apps, the crew's lines and the box to tell them something. | |
| 54 | Settings, tokens, run logs and git words belong to the admin. | |
| 47 | 55 | |
| 48 | 56 | - No door yet: a client account that hides settings and technical words. |
| 49 | 57 | Today the client is the forge's admin and sees every page. |
src/actions/spawn.ts +7 −1
| @@ -89,6 +89,11 @@ export interface Spawned { | ||
| 89 | 89 | readonly placement: PlacementKind; |
| 90 | 90 | /** True when this call found the child already made and changed nothing. */ |
| 91 | 91 | readonly existed: boolean; |
| 92 | /** | |
| 93 | * What was made, as made: from the plan when this call made it, from the ledger when it was | |
| 94 | * there already (which keeps no budget: `budgetUsd` is then absent). | |
| 95 | */ | |
| 96 | readonly recorded: { readonly apps: readonly string[]; readonly admin?: string; readonly budgetUsd?: number | null }; | |
| 92 | 97 | /** |
| 93 | 98 | * The link that hands the child to its person: shown once, here, when |
| 94 | 99 | * the child is made. Absent when the child already existed; the child |
| @@ -405,7 +410,7 @@ async function make( | ||
| 405 | 410 | }); |
| 406 | 411 | } |
| 407 | 412 | if (ledger.done) |
| 408 | return ok({ name: plan.name, org: plan.org, url: liveChildUrl(app, plan.name), bodyId: ledger.bodyId, placement: ledger.placement ?? "hosted", existed: true }); | |
| 413 | return ok({ name: plan.name, org: plan.org, url: liveChildUrl(app, plan.name), bodyId: ledger.bodyId, placement: ledger.placement ?? "hosted", existed: true, recorded: { apps: ledger.apps ?? [], ...(ledger.admin === undefined ? {} : { admin: ledger.admin }) } }); | |
| 409 | 414 | if (ledger.statusToken === undefined || ledger.beatKey === undefined) { |
| 410 | 415 | ledger.statusToken ??= secret(); |
| 411 | 416 | ledger.beatKey ??= secret(); |
| @@ -489,6 +494,7 @@ async function make( | ||
| 489 | 494 | bodyId: ledger.bodyId, |
| 490 | 495 | placement: ledger.placement ?? "hosted", |
| 491 | 496 | existed: false, |
| 497 | recorded: { apps: plan.apps.map((a) => a.ref), ...(plan.admin === undefined ? {} : { admin: plan.admin }), budgetUsd: plan.budgetUsd }, | |
| 492 | 498 | claimUrl, |
| 493 | 499 | ...(resumeKey === undefined ? {} : { resumeKey }), |
| 494 | 500 | }); |
src/http/mcp/tools/spawn.ts +5 −2
| @@ -78,10 +78,13 @@ export const tool: Tool = { | ||
| 78 | 78 | const reveal = args["reveal"] === true && typeof claimUrl === "string"; |
| 79 | 79 | const reach = door.body["reach"] as { ok?: boolean; says?: string } | undefined; |
| 80 | 80 | const reached = reach?.ok === false ? ` ${reach.says}` : ""; |
| 81 | const preview = door.body["preview"] as { says?: string } | undefined; | |
| 82 | const receipt = door.body["receipt"] as { says?: string; linkShown?: boolean } | undefined; | |
| 83 | const again = made && receipt?.linkShown === false ? " It was already made: nothing new was sent; its link was shown once." : ""; | |
| 81 | 84 | return good({ |
| 82 | 85 | says: !made |
| 83 | ? "This is the plan; nothing was made. Send dryRun: false to spawn." | |
| 84 | : `Spawned ${String(door.body["name"])} at ${String(door.body["url"])}. ${reveal ? LINK_REVEALED : LINK_KEPT}${reached}`, | |
| 86 | ? `This is the plan; nothing was made. ${preview?.says ?? ""} Send dryRun: false to spawn.` | |
| 87 | : `Spawned ${String(door.body["name"])} at ${String(door.body["url"])}. ${receipt?.says ?? ""}${again} ${reveal ? LINK_REVEALED : LINK_KEPT}${reached}`, | |
| 85 | 88 | ...rest, |
| 86 | 89 | ...(made ? {} : { where: WHERE_A_FORGE_LIVES }), |
| 87 | 90 | ...(reveal ? { claimUrl } : {}), |
src/spawn/door.ts +5
| @@ -44,6 +44,7 @@ import { | ||
| 44 | 44 | type Placement, |
| 45 | 45 | } from "./placement.ts"; |
| 46 | 46 | import { parseConfig, recipeNamed, type ForgeConfig } from "./recipes.ts"; |
| 47 | import { previewFacts, receiptOf } from "./send_words.ts"; | |
| 47 | 48 | import { appEntry, dryRun, planSpawn, KEY_BUDGET_NOTE, MAX_APPS, type CatalogApp, type CrewBrief, type SpawnSource } from "./plan.ts"; |
| 48 | 49 | import { bootHostedChild, wakeLimits } from "./host.ts"; |
| 49 | 50 | import { cellChildren, cellPlacement, ownsBody } from "./cell.ts"; |
| @@ -456,6 +457,7 @@ export async function spawnDoor( | ||
| 456 | 457 | plan: planned.value, |
| 457 | 458 | // Who the child's first admin will be: the caller, or whoever claims it. |
| 458 | 459 | firstAdmin: user?.username ?? null, |
| 460 | preview: previewFacts(planned.value, user?.username ?? null), | |
| 459 | 461 | ...(giftSeen === undefined ? {} : { gift: giftSeen }), |
| 460 | 462 | ...dryRun(planned.value, source), |
| 461 | 463 | ...(budgetWaits === undefined ? {} : { budgetNote: `the $${budgetWaits} budget applies when a model key is given with it; none is, so this forge gets no key` }), |
| @@ -566,11 +568,14 @@ export async function spawnDoor( | ||
| 566 | 568 | if (prove && up !== undefined && proves(ctx.app)) await Promise.race([up, Bun.sleep(Math.min(wakeLimits.waitMs, budget))]); |
| 567 | 569 | const proved = prove ? await firstProof(ctx.app, made.value.name, budget - (Date.now() - began)) : undefined; |
| 568 | 570 | if (proved !== undefined || (opts.page === true && !made.value.existed)) void settleChild(ctx.app, made.value.name); |
| 571 | // The receipt names what was made, never what this request asked for. | |
| 572 | const receipt = receiptOf(made.value, user?.username ?? null); | |
| 569 | 573 | return { |
outdated
High. This re-plans from the current request's input and builds the receipt from it. Confirming an existing name with different apps/admin/budget answers 200 with a receipt listing apps that were never made there. A receipt must come from what was made (made.value / the stored forge), not from the caller's input. Also planSpawn runs a second time here; reuse the plan already computed above. Add a test: second confirm with different apps must not claim them. |
||
| 570 | 574 | status: made.value.existed ? 200 : 201, |
| 571 | 575 | body: { |
| 572 | 576 | dryRun: false, |
| 573 | 577 | ...made.value, |
| 578 | ...(receipt === undefined ? {} : { receipt }), | |
| 574 | 579 | ...(proved === undefined |
| 575 | 580 | ? {} |
| 576 | 581 | : { |
src/spawn/send_words.ts added +53
| @@ -0,0 +1,53 @@ | ||
| 1 | /** | |
| 2 | * What making a forge for a client says before and after it sends: the preview (the chosen apps, | |
| 3 | * the starter budget, the admin's name, and that this sends one link) and the receipt (what was | |
| 4 | * made), in one place so the page and the MCP `spawn` tool speak the same words (#15687). | |
| 5 | * Plain data in, plain data out; nothing here reads or writes state. | |
| 6 | */ | |
| 7 | import type { SpawnPlan } from "./plan.ts"; | |
| 8 | ||
| 9 | /** The line under every preview: the confirm sends exactly one link. */ | |
| 10 | export const SENDS_ONE_LINK = "This sends one link."; | |
| 11 | ||
| 12 | export interface SendFacts { | |
| 13 | readonly apps: readonly string[]; | |
| 14 | /** | |
| 15 | * The starter budget in dollars, null when no model key (so no budget) goes with it, absent when | |
| 16 | * the forge was made earlier and the budget was not kept. | |
| 17 | */ | |
| 18 | readonly budgetUsd?: number | null; | |
| 19 | /** The admin account's name: who it is named for, else who opens the link, else null. */ | |
| 20 | readonly admin: string | null; | |
| 21 | readonly says: string; | |
| 22 | } | |
| 23 | ||
| 24 | export interface SendReceipt extends SendFacts { | |
| 25 | readonly name: string; | |
| 26 | readonly url: string; | |
| 27 | /** False when this confirm found the forge already made: the link was shown once, then. */ | |
| 28 | readonly linkShown: boolean; | |
| 29 | } | |
| 30 | ||
| 31 | /** One sentence naming the apps, the budget and the admin. */ | |
| 32 | export function sendSays(f: Omit<SendFacts, "says">): string { | |
| 33 | const apps = f.apps.length === 0 ? "no apps" : f.apps.join(", "); | |
| 34 | const budget = f.budgetUsd === undefined ? null : f.budgetUsd === null ? "no starter budget" : `a $${f.budgetUsd} starter budget`; | |
| 35 | const admin = f.admin === null ? "whoever opens the link as its admin" : `${f.admin} as its admin`; | |
| 36 | return `${[apps, budget, admin].filter((x) => x !== null).join("; ")}.`; | |
| 37 | } | |
| 38 | ||
| 39 | /** The plan's facts; its `says` ends with the one-link sentence. */ | |
| 40 | export function previewFacts(plan: SpawnPlan, firstAdmin: string | null): SendFacts { | |
| 41 | const facts = { apps: plan.apps.map((a) => a.ref), budgetUsd: plan.budgetUsd, admin: plan.admin ?? firstAdmin }; | |
| 42 | return { ...facts, says: `${sendSays(facts)} ${SENDS_ONE_LINK}` }; | |
| 43 | } | |
| 44 | ||
| 45 | /** What a made forge holds, as a receipt: from `recorded`, never from the request. */ | |
| 46 | export function receiptOf( | |
| 47 | made: { name: string; url: string; claimUrl?: unknown; existed: boolean; recorded: { apps: readonly string[]; admin?: string; budgetUsd?: number | null } }, | |
| 48 | firstAdmin: string | null, | |
| 49 | ): SendReceipt { | |
| 50 | const r = made.recorded; | |
| 51 | const facts = { apps: r.apps, admin: r.admin ?? (made.existed ? null : firstAdmin), ...(r.budgetUsd === undefined ? {} : { budgetUsd: r.budgetUsd }) }; | |
| 52 | return { ...facts, says: sendSays(facts), name: made.name, url: made.url, linkShown: typeof made.claimUrl === "string" && !made.existed }; | |
| 53 | } |
src/tui/screens/newforge.ts +2 −1
| @@ -179,11 +179,12 @@ export function newForgeScreen(f: Session, ctx: Ctx, initial: Record<string, str | ||
| 179 | 179 | const budget = (body["plan"] as { budgetUsd?: number | null } | undefined)?.budgetUsd ?? null; |
| 180 | 180 | const size = (body["plan"] as { size?: string } | undefined)?.size; |
| 181 | 181 | const template = (body["plan"] as { template?: string } | undefined)?.template; |
| 182 | const says = (body["preview"] as { says?: string } | undefined)?.says; | |
| 182 | 183 | const mode = val("followMode") === "" ? "take-updates" : val("followMode"); |
| 183 | 184 | plan = [ |
| 184 | 185 | `A forge at ${childUrlOf(f.app, val("name"))}.`, |
| 185 | 186 | `It follows this forge's code as ${mode}${isFollowMode(mode) ? `: it ${FOLLOW_WORDS[mode]}` : "."}`, |
| 186 | "Whoever opens the link becomes its admin.", | |
| 187 | ...(says === undefined ? ["Whoever opens the link becomes its admin."] : [says]), | |
outdated
Duplicated cast on one line and untested. Bind the sentence once, and add a TUI test that the plan screen shows 'This sends one link.' (and that the receipt/existed path is covered); the docs promise Ctrl+P, verify that it is the real key. |
||
| 187 | 188 | ...(val("saveAs") === "" || val("recipe") !== "" ? [] : [`Saved as the recipe ${val("saveAs")}.`]), |
| 188 | 189 | ...(budget === null ? [] : [`Its crew runs on your key, up to $${budget} for the key's whole life.`]), |
| 189 | 190 | "Copied into it:", |
src/web/pages/new-forge.ts +23 −4
| @@ -33,6 +33,7 @@ import { | ||
| 33 | 33 | } from "../../spawn/plan.ts"; |
| 34 | 34 | import { DEFAULT_SIZE, SIZES, sizesView } from "../../spawn/sizes.ts"; |
| 35 | 35 | import { DEFAULT_TEMPLATE, parseTemplate, TEMPLATES, templateOf } from "../../spawn/templates.ts"; |
| 36 | import { SENDS_ONE_LINK } from "../../spawn/send_words.ts"; | |
| 36 | 37 | import { FOLLOW_LABELS, FOLLOW_WORDS } from "../../spawn/follow_words.ts"; |
| 37 | 38 | import { dropGift, keepGift, keptGift } from "../gift_cookie.ts"; |
| 38 | 39 | import { notFoundPage, pageHead } from "../chrome.ts"; |
| @@ -525,9 +526,10 @@ function planView(ctx: Ctx, user: User | undefined, values: Values, body: Record | ||
| 525 | 526 | const address = childUrlOf(ctx.app, values.name); |
| 526 | 527 | return html`<section class="settings-block" id="plan"> |
| 527 | 528 | <h2>The plan</h2> |
| 529 | ${previewLines(body["preview"])} | |
| 530 | ${typeof (body["preview"] as { says?: unknown } | undefined)?.says === "string" ? html`<p class="mb"><b>${SENDS_ONE_LINK}</b></p>` : null} | |
| 528 | 531 | <ul class="mb"> |
| 529 | 532 | <li>A forge at <b>${address}</b>.</li> |
| 530 | <li>Whoever opens the link becomes its admin.</li> | |
| 531 | 533 | ${giftLine(body["gift"])} |
| 532 | 534 | ${user === undefined |
| 533 | 535 | ? null |
| @@ -582,11 +584,28 @@ export function claimLinkBody(link: string, isAdmin: boolean): Html { | ||
| 582 | 584 | return linkToSend(link, isAdmin ? html`<p>${sentLink()}</p>` : null); |
| 583 | 585 | } |
| 584 | 586 | |
Clean: the old docblock 'The answer when the forge was there already' is left orphaned above previewLines' docblock, and existedView lost its comment. Move it back onto existedView. |
||
| 587 | /** | |
| 588 | * The facts of a preview or a receipt, from `spawn/send_words.ts`; a budget that was not kept (a | |
| 589 | * forge made before it was) is not shown. | |
| 590 | */ | |
| 591 | export function previewLines(p: unknown): Html | null { | |
| 592 | const f = p as { apps?: string[]; budgetUsd?: number | null; admin?: string | null; says?: string } | undefined; | |
| 593 | if (f === undefined || typeof f.says !== "string") return null; | |
| 594 | const apps = f.apps ?? []; | |
| 595 | return html`<dl class="row-facts mb" data-preview> | |
Principle 8 / correctness: the budget prints as a bare number ('5') while the sentence says '$5'. Show '$5' and keep one wording. |
||
| 596 | <div><dt>Apps</dt><dd>${apps.length === 0 ? "none" : apps.join(", ")}</dd></div> | |
| 597 | ${f.budgetUsd === undefined ? null : html`<div><dt>Starter budget</dt><dd>${f.budgetUsd === null ? "none" : `$${f.budgetUsd}`}</dd></div>`} | |
| 598 | <div><dt>Admin account</dt><dd>${f.admin ?? "whoever opens the link"}</dd></div> | |
| 599 | </dl>`; | |
| 600 | } | |
| 601 | ||
| 585 | 602 | /** The answer when the forge was there already: its link is not shown twice. */ |
| 586 | function existedView(name: string): Html { | |
| 603 | function existedView(name: string, receipt: unknown): Html { | |
| 587 | 604 | return html`<div class="narrow-wide" data-forges> |
| 588 | 605 | ${pageHead(`${name} already exists`)} |
| 589 | 606 | <section class="settings-block"> |
Principle 1: previewLines also prints 'This sends one link.' on the already-exists page, where nothing was sent and no link is shown; it contradicts the paragraph below. Print the facts only here. Likewise on the plan page the admin line in the list below ('Whoever opens the link becomes its admin') now repeats the Admin account row: say it once. |
||
| 607 | <h2>Its receipt</h2> | |
| 608 | ${previewLines(receipt)} | |
| 590 | 609 | <h2>Its link</h2> |
| 591 | 610 | <p>It was made before, so its link is not shown again. Ask for a new one if it was lost.</p> |
| 592 | 611 | </section> |
| @@ -748,14 +767,14 @@ export async function newForgeSubmit(ctx: Ctx): Promise<Response> { | ||
| 748 | 767 | // A stranger made it for themselves and opens it; a signed-in person made it to send. |
| 749 | 768 | const body = |
| 750 | 769 | typeof link !== "string" |
| 751 | ? existedView(name) | |
| 770 | ? existedView(name, door.body["receipt"]) | |
| 752 | 771 | : user === undefined |
| 753 | 772 | ? madeBody({ name, link: link.replace(/\/[a-z]+#/, "/welcome#"), own: true }) |
| 754 | 773 | : madeBody({ |
| 755 | 774 | name, |
| 756 | 775 | link, |
| 757 | 776 | own: false, |
| 758 | after: html`${typeof note === "string" ? html`<p class="small">${note}</p>` : null}${user.isAdmin ? html`<p>${sentLink()}</p>` : null}`, | |
| 777 | after: html`<h2>Receipt</h2>${previewLines(door.body["receipt"])}${typeof note === "string" ? html`<p class="small">${note}</p>` : null}${user.isAdmin ? html`<p>${sentLink()}</p>` : null}`, | |
| 759 | 778 | }); |
| 760 | 779 | const response = page({ ctx, title: typeof link !== "string" ? "New forge" : user === undefined ? "Your new forge" : "A forge to send", body, ...(typeof link === "string" ? { scriptJs: madeJs } : {}) }, door.status); |
| 761 | 780 | // The link is in this body only: never kept by a cache. |
test/client-forge-send.test.ts added +182
| @@ -0,0 +1,182 @@ | ||
| 1 | /** | |
| 2 | * Making a forge for a client shows what it will create, then sends once (#15687): the preview | |
| 3 | * creates nothing, a confirm creates exactly one forge, a second confirm is the same receipt, and | |
| 4 | * the MCP `spawn` says the same words. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, 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 { createApp, type App } from "../src/app.ts"; | |
| 11 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { usePlacement, useProbe } from "../src/spawn/door.ts"; | |
| 13 | import { createToken } from "../src/core/tokens.ts"; | |
| 14 | import { createUser, type User } from "../src/core/users.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { ok } from "../src/kernel/result.ts"; | |
| 17 | import { previewLines } from "../src/web/pages/new-forge.ts"; | |
| 18 | import { newForgeScreen } from "../src/tui/screens/newforge.ts"; | |
| 19 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 20 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 21 | import { settleApp } from "./helpers/tui.ts"; | |
| 22 | import { SENDS_ONE_LINK } from "../src/spawn/send_words.ts"; | |
| 23 | ||
| 24 | describe("a forge for a client: preview, then send", () => { | |
| 25 | let dataDir: string; | |
| 26 | let app: App; | |
| 27 | let servers: Servers; | |
| 28 | let base: string; | |
| 29 | let rw: string; | |
| 30 | let placed = 0; | |
| 31 | let aliceUser: User; | |
| 32 | ||
| 33 | const post = (payload: unknown) => | |
| 34 | fetch(`${base}/api/v1/forges`, { | |
| 35 | method: "POST", | |
| 36 | headers: { "content-type": "application/json", authorization: `Bearer ${rw}` }, | |
| 37 | body: JSON.stringify(payload), | |
| 38 | }); | |
| 39 | const callSpawn = async (args: unknown) => { | |
| 40 | const res = await fetch(`${base}/mcp`, { | |
| 41 | method: "POST", | |
| 42 | headers: { "content-type": "application/json", authorization: `Bearer ${rw}` }, | |
| 43 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "spawn", arguments: args } }), | |
| 44 | }); | |
| 45 | const r = ((await res.json()) as any).result; | |
| 46 | return JSON.parse(r.content[0].text) as any; | |
| 47 | }; | |
| 48 | ||
| 49 | beforeAll(async () => { | |
| 50 | dataDir = await mkdtemp(join(tmpdir(), "forge-client-send-")); | |
| 51 | app = createApp({ dataDir, port: 0 }); | |
| 52 | servers = await serve(app); | |
| 53 | base = servers.url; | |
| 54 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 55 | if (!a.ok) throw new Error("user"); | |
| 56 | aliceUser = a.value; | |
| 57 | rw = createToken(app.db, a.value.id, "rw", "rw").token; | |
| 58 | const repo = await createRepo(app, a.value, { name: "notes" }); | |
| 59 | if (!repo.ok) throw new Error("repo"); | |
| 60 | await commitToBranch(app, a.value, repo.value, { message: "seed", files: [{ path: "a.txt", content: "a" }] }); | |
| 61 | useProbe(app, () => async () => true); | |
| 62 | usePlacement(app, { | |
| 63 | place: async (plan) => ok({ url: `https://${plan.name}.fake.test`, bodyId: `fake-${++placed}` }), | |
| 64 | retire: async () => ok(), | |
| 65 | }); | |
| 66 | }, 30_000); | |
| 67 | ||
| 68 | afterAll(async () => { | |
| 69 | servers.stop(); | |
| 70 | app.close(); | |
| 71 | await rm(dataDir, { recursive: true, force: true }); | |
| 72 | }); | |
| 73 | ||
| 74 | test("the preview names the apps, the budget and the admin, says it sends one link, and makes nothing", async () => { | |
| 75 | const res = await post({ name: "acme", apps: ["alice/notes"], admin: "carol" }); | |
| 76 | const body = (await res.json()) as any; | |
| 77 | expect(body.dryRun).toBe(true); | |
| 78 | expect(body.preview.apps).toEqual(["alice/notes"]); | |
| 79 | expect(body.preview.admin).toBe("carol"); | |
| 80 | expect(body.preview.says).toContain(SENDS_ONE_LINK); | |
| 81 | expect(placed).toBe(0); | |
| 82 | const viaMcp = await callSpawn({ name: "acme", apps: ["alice/notes"], admin: "carol" }); | |
| 83 | expect(viaMcp.says).toContain("nothing was made"); | |
| 84 | expect(viaMcp.says).toContain("alice/notes"); | |
| 85 | expect(viaMcp.says).toContain("carol as its admin"); | |
| 86 | expect(viaMcp.says).toContain(SENDS_ONE_LINK); | |
| 87 | expect(placed).toBe(0); | |
| 88 | }); | |
| 89 | ||
| 90 | test("a confirm makes one forge with a receipt; a second confirm makes none and keeps the receipt", async () => { | |
| 91 | const first = await post({ name: "acme", apps: ["alice/notes"], admin: "carol", dryRun: false }); | |
| 92 | expect(first.status).toBe(201); | |
| 93 | const made = (await first.json()) as any; | |
| 94 | expect(made.receipt).toMatchObject({ name: "acme", apps: ["alice/notes"], admin: "carol", linkShown: true }); | |
| 95 | expect(made.receipt.says).toContain("alice/notes"); | |
| 96 | expect(typeof made.claimUrl).toBe("string"); | |
| 97 | expect(placed).toBe(1); | |
| 98 | ||
| 99 | const second = await post({ name: "acme", apps: ["alice/notes"], admin: "carol", dryRun: false }); | |
| 100 | expect(second.status).toBe(200); | |
| 101 | const again = (await second.json()) as any; | |
| 102 | expect(again.existed).toBe(true); | |
| 103 | expect(again.claimUrl).toBeUndefined(); | |
| 104 | expect(again.receipt).toMatchObject({ name: "acme", apps: ["alice/notes"], admin: "carol", linkShown: false }); | |
outdated
Missing tests: the page (/forges/new plan shows the Apps, Starter budget, Admin account rows and the sentence; the made page shows Receipt; the already-exists page shows the receipt without a link), escaping of an app/admin name in previewLines, the TUI line, and a repeat confirm with different input. Only API and MCP are covered now. |
||
| 105 | expect(placed).toBe(1); | |
| 106 | ||
| 107 | const third = await callSpawn({ name: "acme", apps: ["alice/notes"], admin: "carol", dryRun: false }); | |
| 108 | expect(third.says).toContain("already made"); | |
| 109 | expect(placed).toBe(1); | |
| 110 | }); | |
| 111 | ||
| 112 | test("a repeat confirm with other input answers what was made, never what it asked for", async () => { | |
| 113 | await callSpawn({ name: "beta", apps: ["alice/notes"], admin: "carol", dryRun: false }); | |
| 114 | const other = await post({ name: "beta", apps: ["alice/notes", "alice/other"], admin: "mallory", dryRun: false }); | |
| 115 | const body = (await other.json()) as any; | |
| 116 | if (other.status === 200) { | |
| 117 | expect(body.receipt.apps).toEqual(["alice/notes"]); | |
| 118 | expect(body.receipt.admin).toBe("carol"); | |
| 119 | expect(body.receipt.says).not.toContain("mallory"); | |
| 120 | } else { | |
| 121 | expect(body.receipt).toBeUndefined(); | |
| 122 | } | |
| 123 | expect(placed).toBe(2); | |
| 124 | }); | |
| 125 | ||
| 126 | const cookieOf = async () => { | |
| 127 | const res = await fetch(`${base}/signin`, { method: "POST", body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), redirect: "manual" }); | |
| 128 | return (res.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 129 | }; | |
| 130 | const form = async (name: string, doIt: string) => | |
| 131 | ( | |
| 132 | await fetch(`${base}/forges/new`, { | |
| 133 | method: "POST", | |
| 134 | headers: { cookie: await cookieOf(), origin: base }, | |
| 135 | body: new URLSearchParams([["name", name], ["apps", "alice/notes"], ["do", doIt]]), | |
| 136 | redirect: "manual", | |
| 137 | }) | |
| 138 | ).text(); | |
| 139 | ||
| 140 | test("the page's plan lists Apps, Starter budget and Admin account, and says it once", async () => { | |
| 141 | const page = await form("gamma", "plan"); | |
| 142 | expect(page).toContain("<dt>Apps</dt>"); | |
| 143 | expect(page).toContain("alice/notes"); | |
| 144 | expect(page).toContain("<dt>Starter budget</dt><dd>none</dd>"); | |
| 145 | expect(page).toContain("<dt>Admin account</dt>"); | |
| 146 | expect(page.split(SENDS_ONE_LINK).length - 1).toBe(1); | |
| 147 | expect(page).not.toContain("Whoever opens the link becomes its admin"); | |
| 148 | }); | |
| 149 | ||
| 150 | test("the made page shows a Receipt; the same confirm again shows the receipt, no link and no one-link sentence", async () => { | |
| 151 | const made = await form("delta", "spawn"); | |
| 152 | expect(made).toContain("Receipt"); | |
| 153 | expect(made).toContain("alice/notes"); | |
| 154 | const again = await form("delta", "spawn"); | |
| 155 | expect(again).toContain("delta already exists"); | |
| 156 | expect(again).toContain("<dt>Apps</dt>"); | |
| 157 | expect(again).not.toContain(SENDS_ONE_LINK); | |
| 158 | expect(again).not.toContain("/claim"); | |
| 159 | }); | |
| 160 | ||
| 161 | test("a name in the facts is escaped", () => { | |
| 162 | const out = String(previewLines({ apps: ["<img src=x>"], budgetUsd: 3, admin: "<b>x</b>", says: "s" })); | |
| 163 | expect(out).not.toContain("<img"); | |
| 164 | expect(out).not.toContain("<b>x"); | |
| 165 | expect(out).toContain("$3"); | |
| 166 | }); | |
| 167 | ||
| 168 | test("the terminal's Ctrl+P plan says it sends one link", async () => { | |
| 169 | const terminal = headlessTerminal(120, 40); | |
| 170 | const { app: tui, session } = createForgeApp(app, { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: aliceUser }, { terminal, exitHooks: false }); | |
| 171 | tui.start(); | |
| 172 | tui.ctx.push(newForgeScreen(session, tui.ctx)); | |
| 173 | try { | |
| 174 | await settleApp(tui); | |
| 175 | terminal.feed("epsilon\x10"); | |
| 176 | await settleApp(tui); | |
| 177 | expect(tui.screen.toText()).toContain(SENDS_ONE_LINK); | |
| 178 | } finally { | |
| 179 | tui.stop?.(); | |
| 180 | } | |
| 181 | }); | |
| 182 | }); |
test/new-forge.test.ts +1 −1
| @@ -201,7 +201,7 @@ describe("+ New forge", () => { | ||
| 201 | 201 | ).text() |
| 202 | 202 | ).replace(/\s+/g, " "); |
| 203 | 203 | expect(left).toContain("https://kai--forge.test"); |
| 204 | expect(left).toContain("Whoever opens the link becomes its admin"); | |
| 204 | expect(left).toContain("Admin account"); | |
| 205 | 205 | expect(left).toContain("You leave once it is taken over"); |
| 206 | 206 | const kept = ( |
| 207 | 207 | await ( |
Drop 'The pull's source is ...' (it points at a pull, not a feature) and wrap the paragraph like the rest of the file; README is untouched, good.