Public: anyone can read this; the crew can change it.
An owner can archive an app from its settings: it spins down, hides from lists and stays reachable by link #14131
Check · Review · Land · Live — Its check is queued.
torque/forge:torque/14085-an-owner-can-archive-an-app-from-its-set → main 3 commits fork
9 files
changed +170
−34
docs/features/README.md +1
| @@ -255,6 +255,7 @@ Read with the guide page [Your apps](../guide-your-apps.md). | ||
| 255 | 255 | - [](app-templates.md) |
| 256 | 256 | - [](template-page.md) |
| 257 | 257 | - [](archive-listing.md) |
| 258 | - [](app-archive.md) | |
| 258 | 259 | - [](binary-file.md) |
| 259 | 260 | - [](feed-xml.md) |
| 260 | 261 | - [](log-tail.md) |
docs/features/app-archive.md added +12
| @@ -0,0 +1,12 @@ | ||
| 1 | # Archive an app | |
| 2 | ||
| 3 | An owner archives an app from its settings (Settings → Archive) or the app page's Archive link. The button opens the confirm page first, which says what will happen; nothing changes until its second button is pressed (a same-origin POST to `/:owner/:name/archive`). | |
| 4 | ||
| 5 | Receipt: the next page says the app is stopped, hidden from home and `/apps`, and still opens by its address. | |
| 6 | ||
| 7 | - **Stops:** production and every preview spin down (`moveArchive`, `src/actions/repos.ts`). | |
| 8 | - **Hidden:** home and `/apps` leave it out; `/apps?archived=1` lists it, and `/apps` says how many are archived. | |
| 9 | - **Reachable:** its URL, clone and push keep working. The page carries an "Archived on <date>" banner (`archivedLine`, `src/web/pages/following.ts`), with Restore for an admin. | |
| 10 | - **Restore:** Settings, the banner or the archived list posts `archived=0` to `/:owner/:name/settings/archive`; the app is listed again and wakes on its next visit. | |
| 11 | ||
| 12 | Terminal: the Archived repositories screen (`src/tui/screens/archived.ts`); MCP: the `archive` tool. Test: `test/app-archive.test.ts`. |
src/tui/screens/archived.ts +1 −1
| @@ -51,7 +51,7 @@ export function archivedScreen(f: Session, ctx: Ctx): Screen { | ||
| 51 | 51 | const rows: ListRow[] = repos.map((r) => ({ |
| 52 | 52 | title: `${r.ownerName}/${r.name}`, |
| 53 | 53 | secondary: (r.archivedAt ?? "").slice(0, 10), |
| 54 | meta: withApp.has(r.id) ? "app spun down" : "", | |
| 54 | meta: withApp.has(r.id) ? "app spun down, still at its address" : "", | |
| 55 | 55 | })); |
| 56 | 56 | const line = mayRestore(selected()) ? "enter opens it · a restores it" : "enter opens it"; |
| 57 | 57 | s.text(head!.x, head!.y, truncate(line, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); |
src/web/pages/following.ts +22
| @@ -180,6 +180,28 @@ export function archivedParentLine(ctx: Ctx, repo: Repo): Html | null { | ||
| 180 | 180 | </p>`; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | /** | |
| 184 | * "Archived on <date>" with, for an admin, the Restore button. A repository put | |
| 185 | * away still clones, pushes and links as before; this only says so. | |
| 186 | */ | |
| 187 | export function archivedLine(ctx: Ctx, repo: Repo): Html | null { | |
| 188 | if (repo.archivedAt === null) return null; | |
| 189 | return html`<div class="mt archived"> | |
| 190 | <p> | |
| 191 | Archived on | |
| 192 | <time datetime="${repo.archivedAt}">${repo.archivedAt.slice(0, 10)}</time> | |
| 193 | </p> | |
| 194 | ${when( | |
| 195 | canAdmin(ctx.app.db, repo, ctx.auth.user), | |
| 196 | () => html`<form method="post" action="${repoBase(repo)}/settings/archive"> | |
| 197 | <input type="hidden" name="archived" value="0" /> | |
| 198 | <input type="hidden" name="to" value="repo" /> | |
| 199 | ${btn("Restore", { size: "sm" })} | |
| 200 | </form>`, | |
| 201 | )} | |
| 202 | </div>`; | |
| 203 | } | |
| 204 | ||
| 183 | 205 | /** |
| 184 | 206 | * "N releases behind <parent>", each with its name and link; or, when the |
| 185 | 207 | * parent cannot be read, that it cannot and how old the last copy is. |
src/web/pages/repo.ts +1 −22
| @@ -46,6 +46,7 @@ import { FORK_DEFAULT_MODE, forkFollowModes, type ForkFollowMode } from "../../c | ||
| 46 | 46 | import { FOLLOW_PHRASE, isSevered } from "../../actions/follow_words.ts"; |
| 47 | 47 | import { lineageOf, MINE_ANCHOR, ownsInTree } from "../../core/following.ts"; |
| 48 | 48 | import { |
| 49 | archivedLine, | |
| 49 | 50 | archivedParentLine, |
| 50 | 51 | followingCard, |
| 51 | 52 | followingOf, |
| @@ -1453,28 +1454,6 @@ function reportLine(ctx: Ctx, repo: Repo): Html | null { | ||
| 1453 | 1454 | </p>`; |
| 1454 | 1455 | } |
| 1455 | 1456 | |
| 1456 | /** | |
| 1457 | * "Archived on <date>" with, for an admin, the Restore button. A repository put | |
| 1458 | * away still clones, pushes and links as before; this only says so. | |
| 1459 | */ | |
| 1460 | function archivedLine(ctx: Ctx, repo: Repo): Html | null { | |
| 1461 | if (repo.archivedAt === null) return null; | |
| 1462 | return html`<div class="mt archived"> | |
| 1463 | <p> | |
| 1464 | Archived on | |
| 1465 | <time datetime="${repo.archivedAt}">${repo.archivedAt.slice(0, 10)}</time> | |
| 1466 | </p> | |
| 1467 | ${when( | |
| 1468 | canAdmin(ctx.app.db, repo, ctx.auth.user), | |
| 1469 | () => html`<form method="post" action="${repoBase(repo)}/settings/archive"> | |
| 1470 | <input type="hidden" name="archived" value="0" /> | |
| 1471 | <input type="hidden" name="to" value="repo" /> | |
| 1472 | ${btn("Restore", { size: "sm" })} | |
| 1473 | </form>`, | |
| 1474 | )} | |
| 1475 | </div>`; | |
| 1476 | } | |
| 1477 | ||
| 1478 | 1457 | /** The code at a ref: the tree, the README and the About rail — with, in |
| 1479 | 1458 | * the studio, the offer to make a repository that is not an app one. */ |
| 1480 | 1459 | async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { |
src/web/pages/settings.ts +15 −10
| @@ -351,15 +351,16 @@ export async function settingsPage( | ||
| 351 | 351 | const trail = provenanceCard(ctx, repo); |
| 352 | 352 | const archive = html`<section class="settings-block"> |
| 353 | 353 | <h2>Archive</h2> |
| 354 | <form method="post" action="${base}/settings/archive"> | |
| 355 | <input type="hidden" name="archived" value="${repo.archivedAt === null ? "1" : "0"}" /> | |
| 356 | ${repo.archivedAt === null ? null : html`<p class="muted small">Archived on ${repo.archivedAt.slice(0, 10)}.</p>`} | |
| 357 | <div class="form-actions"> | |
| 358 | ${btn(repo.archivedAt === null ? "Archive" : "Restore", { | |
| 359 | variant: "primary", | |
| 360 | })} | |
| 361 | </div> | |
| 362 | </form> | |
| 354 | ${repo.archivedAt === null | |
| 355 | ? html`<form method="get" action="/-/confirm"> | |
| 356 | <input type="hidden" name="to" value="${base}/archive" /> | |
| 357 | <div class="form-actions">${btn("Archive", { variant: "primary" })}</div> | |
| 358 | </form>` | |
| 359 | : html`<form method="post" action="${base}/settings/archive"> | |
| 360 | <input type="hidden" name="archived" value="0" /> | |
| 361 | <p class="muted small">Archived on ${repo.archivedAt.slice(0, 10)}.</p> | |
| 362 | <div class="form-actions">${btn("Restore", { variant: "primary" })}</div> | |
| 363 | </form>`} | |
| 363 | 364 | </section>`; |
| 364 | 365 | const rename = html`<form id="rename" method="post" action="${base}/settings/rename"> |
| 365 | 366 | ${formField({ |
| @@ -564,7 +565,11 @@ async function archiveWith(ctx: Ctx, fixed: "1" | undefined): Promise<Response> | ||
| 564 | 565 | ctx, |
| 565 | 566 | back, |
| 566 | 567 | updated.ok |
| 567 | ? { message: archived ? "Archived." : "Restored." } | |
| 568 | ? { | |
| 569 | message: archived | |
| 570 | ? "Archived: it is stopped and hidden from home and the apps list; its address still opens, with a banner. Restore it from its page or Settings." | |
| 571 | : "Restored: it is back on home and the apps list, and wakes on its next visit.", | |
| 572 | } | |
| 568 | 573 | : { tone: "danger", message: NOT_CHANGED }, |
| 569 | 574 | ); |
| 570 | 575 | } |
src/web/studio/app.ts +3
| @@ -38,6 +38,7 @@ import { appLine } from "../describe.ts"; | ||
| 38 | 38 | import { page } from "../layout.ts"; |
| 39 | 39 | import { liveClientJs, liveMount } from "../live.ts"; |
| 40 | 40 | import { |
| 41 | archivedLine, | |
| 41 | 42 | archivedParentLine, |
| 42 | 43 | followingCard, |
| 43 | 44 | followingOf, |
| @@ -518,6 +519,7 @@ export async function studioApp( | ||
| 518 | 519 | ${following === undefined |
| 519 | 520 | ? archivedParentLine(ctx, repo) |
| 520 | 521 | : followingCard(ctx, repo, following)} |
| 522 | ${archivedLine(ctx, repo)} | |
| 521 | 523 | <div id="app-head">${head}</div> |
| 522 | 524 | ${ownerFacts ? crewKeyCard(ctx, true) : null} |
| 523 | 525 | ${ownerFacts ? landOnApp(ctx, repo) : null} |
| @@ -543,6 +545,7 @@ export async function studioApp( | ||
| 543 | 545 | ${following === undefined |
| 544 | 546 | ? archivedParentLine(ctx, repo) |
| 545 | 547 | : followingCard(ctx, repo, following)} |
| 548 | ${archivedLine(ctx, repo)} | |
| 546 | 549 | <div id="app-head">${head}</div> |
| 547 | 550 | ${askingLine(ctx, repo)} |
| 548 | 551 | ${policy} |
test/app-archive.test.ts added +112
| @@ -0,0 +1,112 @@ | ||
| 1 | /** | |
| 2 | * Archive from settings (#14085): the button previews on the confirm page, the | |
| 3 | * receipt says what happened, an archived app leaves home and /apps but opens | |
| 4 | * by its address with a banner, and Restore brings it back. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { createApp as makeAppRecord } from "../src/core/apps.ts"; | |
| 13 | import { getRepo } from "../src/core/repos.ts"; | |
| 14 | import { createUser } from "../src/core/users.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { quietLogs } from "./helpers/globals.ts"; | |
| 17 | import { proveAll } from "./helpers/verified.ts"; | |
| 18 | ||
| 19 | quietLogs(); | |
| 20 | ||
| 21 | let root = ""; | |
| 22 | let app: App; | |
| 23 | let servers: Servers; | |
| 24 | let cookie = ""; | |
| 25 | const ROW = '<a href="/alice/attic" class="row"'; | |
| 26 | ||
| 27 | beforeAll(async () => { | |
| 28 | root = mkdtempSync(join(tmpdir(), "forge-app-archive-")); | |
| 29 | app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" }); | |
| 30 | const u = await createUser(app.db, { | |
| 31 | origin: "seed", | |
| 32 | trusted: true, | |
| 33 | username: "alice", | |
| 34 | email: "[email protected]", | |
| 35 | password: "a-good-passphrase", | |
| 36 | adminIfFirst: true, | |
| 37 | }); | |
| 38 | if (!u.ok) throw new Error(u.error); | |
| 39 | proveAll(app); | |
| 40 | const made = await createRepo(app, u.value, { name: "attic" }); | |
| 41 | if (!made.ok) throw new Error(made.error); | |
| 42 | const rec = makeAppRecord(app.db, { repoId: made.value.id, slug: "attic", access: "public" }); | |
| 43 | if (!rec.ok) throw new Error(rec.error); | |
| 44 | servers = await serve(app); | |
| 45 | const signin = await fetch(`${servers.url}/signin`, { | |
| 46 | method: "POST", | |
| 47 | headers: { origin: servers.url }, | |
| 48 | body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), | |
| 49 | redirect: "manual", | |
| 50 | }); | |
| 51 | cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 52 | }); | |
| 53 | afterAll(() => { | |
| 54 | servers.stop(); | |
| 55 | app.close(); | |
| 56 | rmSync(root, { recursive: true, force: true }); | |
| 57 | }); | |
| 58 | ||
| 59 | const get = async (path: string, extra = "") => { | |
| 60 | const res = await fetch(`${servers.url}${path}`, { headers: { cookie: cookie + extra }, redirect: "manual" }); | |
| 61 | return { status: res.status, body: await res.text(), headers: res.headers }; | |
| 62 | }; | |
| 63 | const post = (path: string, body: Record<string, string>, origin = servers.url) => | |
| 64 | fetch(`${servers.url}${path}`, { | |
| 65 | method: "POST", | |
| 66 | headers: { cookie, origin }, | |
| 67 | body: new URLSearchParams(body), | |
| 68 | redirect: "manual", | |
| 69 | }); | |
| 70 | ||
| 71 | // The receipt rides a cookie set on the redirect; carry it to the next page. | |
| 72 | const flashOf = (res: Response): string => | |
| 73 | res.headers.getSetCookie().map((c) => `; ${c.split(";")[0]!}`).join(""); | |
| 74 | ||
| 75 | test("hide, reach and restore, from settings", async () => { | |
| 76 | // Preview: the settings button asks the confirm page; it changes nothing. | |
| 77 | const settings = await get("/alice/attic/settings"); | |
| 78 | expect(settings.body).toContain('action="/-/confirm"'); | |
| 79 | expect(settings.body).toContain('value="/alice/attic/archive"'); | |
| 80 | expect(settings.body).not.toContain('action="/alice/attic/settings/archive"'); | |
| 81 | const preview = await get("/-/confirm?to=%2Falice%2Fattic%2Farchive"); | |
| 82 | expect(preview.body).toContain("Archive alice/attic?"); | |
| 83 | expect(getRepo(app.db, "alice", "attic")!.archivedAt).toBeNull(); | |
| 84 | expect((await get("/apps")).body).toContain(ROW); | |
| 85 | ||
| 86 | // Do it: a cross-origin post is refused, the same-origin one archives. | |
| 87 | expect((await post("/alice/attic/archive", {}, "https://evil.example")).status).toBeGreaterThanOrEqual(400); | |
| 88 | expect(getRepo(app.db, "alice", "attic")!.archivedAt).toBeNull(); | |
| 89 | const done = await post("/alice/attic/archive", {}); | |
| 90 | expect(done.status).toBe(303); | |
| 91 | expect(getRepo(app.db, "alice", "attic")!.archivedAt).not.toBeNull(); | |
| 92 | ||
| 93 | // Receipt: the next page says what happened. | |
| 94 | const after = await get(new URL(done.headers.get("location")!, servers.url).pathname, flashOf(done)); | |
| 95 | expect(after.body).toContain("Archived: it is stopped and hidden"); | |
| 96 | ||
| 97 | // Hidden from the lists, reachable by address, with a banner. | |
| 98 | expect((await get("/apps")).body).not.toContain(ROW); | |
| 99 | const direct = await get("/alice/attic"); | |
| 100 | expect(direct.status).toBe(200); | |
| 101 | expect(direct.body).toContain("Archived on"); | |
| 102 | expect((await get("/alice/attic/settings")).body).toContain("Restore"); | |
| 103 | ||
| 104 | // Restore: one post, a receipt, and back on the list. | |
| 105 | const back = await post("/alice/attic/settings/archive", { archived: "0" }); | |
| 106 | expect(back.status).toBe(303); | |
| 107 | expect(getRepo(app.db, "alice", "attic")!.archivedAt).toBeNull(); | |
| 108 | expect((await get("/apps")).body).toContain(ROW); | |
| 109 | expect((await get("/alice/attic/settings")).body).not.toContain("Archived on"); | |
| 110 | const receipt = await get(new URL(back.headers.get("location")!, servers.url).pathname, flashOf(back)); | |
| 111 | expect(receipt.body).toContain("Restored: it is back on home"); | |
| 112 | }); |
test/settings.test.ts +3 −1
| @@ -73,10 +73,12 @@ describe("repo settings", () => { | ||
| 73 | 73 | for (const path of [ |
| 74 | 74 | "/settings", |
| 75 | 75 | "/settings/wave", |
| 76 | "/settings/archive", | |
| 77 | 76 | "/settings/provenance", |
| 78 | 77 | ]) |
| 79 | 78 | expect(page).toContain(posts(path)); |
| 79 | // Archive asks first too (#14085): the button is a GET to the confirm page. | |
| 80 | expect(page).toContain('action="/-/confirm"'); | |
| 81 | expect(page).toContain('value="/olive/proj/archive"'); | |
| 80 | 82 | // Stopping the mirror asks first: the page links to the confirm, which posts. |
| 81 | 83 | expect(page).toContain(`/-/confirm?to=${encodeURIComponent("/olive/proj/settings/mirror/stop")}`); |
| 82 | 84 | for (const h of [ |
new above
offline