Public: anyone can read this; the crew can change it.

Archive, part 1: an admin archives or wakes one repository from Settings and the API, and its page says "archived on <date>" with a Wake button #1844

Parked opened this
Closed without merging

scout/forge:scout/1838-archive-part-1-an-admin-archives-or-wake → main 10 commits fork 4 threads · 4 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
13 files changed +410 −11
README.md +10
@@ -193,6 +193,16 @@ taking a release is not done here. This forge publishes its own
193193 `/releases.json` (the version names, each linking to that document), so any
194194 forge can be a parent. The terminal shows the count, not the release names.
195195
196 ## Archive
197
198 An admin puts a repository away from **Settings → Archive**, with
199 `PATCH /api/v1/repos/:owner/:name {"archived":true|false}` (admins only; anyone
200 else gets 403), or in the terminal with `a` on the About card (`I`). The
201 repository page and the card then say when it was archived, and an admin gets
202 a Wake button or the same key to undo it. Archiving twice keeps the first date.
203 It does not yet block anything: clone, push and links keep working, and the
204 repository stays in every list.
205
196206 ## Health
197207
198208 `GET /api/v1/health` (and the MCP `health` tool) answer a site admin with
scripts/gate.ts +2
@@ -27,6 +27,8 @@ export type Exclusion = {
2727 };
2828
2929 export const GATE: readonly string[] = [
30 "test/archive.test.ts",
31 "test/tui-archive.test.ts",
3032 "test/domain-drill.test.ts",
3133 "test/accounts-retire.test.ts",
3234 "test/client-home.test.ts",
src/actions/repos.ts +3 −1
@@ -266,7 +266,7 @@ export async function updateRepoSettings(
266266 if (!moved.ok) return err("unknown_branch");
267267 }
268268 const updated = writeSettings(app.db, repo, settings);
269 const changed = (
269 const changed: string[] = (
270270 [
271271 "visibility",
272272 "description",
@@ -278,6 +278,8 @@ export async function updateRepoSettings(
278278 "decisionsBy",
279279 ] as const
280280 ).filter((k) => settings[k] !== undefined && settings[k] !== repo[k]);
281 if (settings.archived !== undefined && settings.archived !== (repo.archivedAt !== null))
282 changed.push("archived");
281283 app.bus.append({
282284 kind: "repo.settings_updated",
283285 repoId: repo.id,
src/core/migrations/20261015090000-a-repository-put-away.ts added +5
@@ -0,0 +1,5 @@
1 // Archive (#1838): when an admin put a repository away. Null is the
2 // ordinary state; nothing is deleted and clone and push go on working.
3 export default `
4 ALTER TABLE repo ADD COLUMN archived_at TEXT;
5 `;
src/core/releases.json +5 −1
@@ -3,7 +3,11 @@
33 "releases": [
44 {
55 "version": "0.7.123",
6 "migrations": 93
6 "migrations": 93,
7 "ids": [
outdated

Drop this. It rewrites the record of a release that has already shipped, from a guess, and that record belongs to the release flow, not to an archive feature.

8 "20261015090000-feed-chips",
9 "20261015230000-a-domain-drill"
10 ]
711 },
812 {
913 "version": "0.7.122",
src/core/repos.ts +13 −1
@@ -128,6 +128,8 @@ export interface Repo {
128128 * read only by the base's writers and crew. Null for every other one.
129129 */
130130 readonly sealedFor: string | null;
131 /** When an admin archived it (ISO time), or null: put away, not deleted. */
132 readonly archivedAt: string | null;
131133 /** The origin this mirrors, or null for a native repo. */
132134 readonly origin: RepoOrigin | null;
133135 /**
@@ -166,6 +168,7 @@ interface RepoRow {
166168 direction_issue_id: string | null;
167169 fork_parent_id: string | null;
168170 sealed_for: string | null;
171 archived_at: string | null;
169172 origin_id: string | null;
170173 origin_kind: "github" | "forgejo" | "gitea" | null;
171174 origin_full_name: string | null;
@@ -204,6 +207,7 @@ function toRepo(row: RepoRow): Repo {
204207 directionIssueId: row.direction_issue_id,
205208 forkParentId: row.fork_parent_id,
206209 sealedFor: row.sealed_for,
210 archivedAt: row.archived_at,
207211 origin:
208212 row.origin_id !== null && row.origin_kind !== null
209213 ? {
@@ -1036,6 +1040,8 @@ export interface RepoSettings {
10361040 /** Whether someone who cannot write here may start or steer a run. */
10371041 crewOutsiders?: boolean;
10381042 decisionsBy?: DecisionsBy;
1043 /** Archive (true) or wake (false); the time is stamped here. */
1044 archived?: boolean;
10391045 }
10401046
10411047 /** Update the mutable repo fields, leaving unspecified ones untouched. */
@@ -1048,7 +1054,8 @@ export function updateRepoSettings(
10481054 `UPDATE repo SET visibility = ?1, description = ?2, protect_default = ?3,
10491055 default_branch = ?4, require_review = ?5, require_checks = ?7,
10501056 autonomy = ?8, autonomy_direction = ?9, autonomy_ceiling_usd = ?10,
1051 autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13, decisions_by = ?14
1057 autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13, decisions_by = ?14,
1058 archived_at = ?15
10521059 WHERE id = ?6`,
10531060 ).run(
10541061 settings.visibility ?? repo.visibility,
@@ -1065,6 +1072,11 @@ export function updateRepoSettings(
10651072 settings.autonomyBy === undefined ? repo.autonomyBy : settings.autonomyBy,
10661073 (settings.crewOutsiders ?? repo.crewOutsiders) ? 1 : 0,
10671074 settings.decisionsBy ?? repo.decisionsBy,
1075 settings.archived === undefined
1076 ? repo.archivedAt
1077 : settings.archived
1078 ? (repo.archivedAt ?? new Date().toISOString())
1079 : null,
10681080 );
10691081 return getRepoById(db, repo.id)!;
10701082 }
src/http/api.ts +7
@@ -1814,6 +1814,9 @@ export function apiRoutes(router: Router<Handler>): void {
18141814 const repo = loadRepo(ctx);
18151815 if (!repo) return notFound();
18161816 const input = await body(ctx.request);
1817 // The caller can already read this repository, so saying no is no leak.
1818 if (input.archived !== undefined && !canAdmin(ctx.app.db, repo, ctx.auth.user))
1819 return apiError("forbidden", 403, "only an admin archives or wakes");
18171820 if (input.decisionsBy !== undefined && !isDecisionsBy(input.decisionsBy))
18181821 return apiError(
18191822 "bad_decisions_by",
@@ -1847,6 +1850,10 @@ export function apiRoutes(router: Router<Handler>): void {
18471850 ...(isDecisionsBy(input.decisionsBy)
18481851 ? { decisionsBy: input.decisionsBy }
18491852 : {}),
1853 // Archive or wake (#1838): any admin's call, and only a real boolean.
1854 ...(typeof input.archived === "boolean"
1855 ? { archived: input.archived }
1856 : {}),
18501857 });
18511858 if (!updated.ok) return respondAccess(updated.error, 422);
18521859 return json(repoJson(ctx, updated.value));
src/http/server.ts +2
@@ -326,6 +326,7 @@ import {
326326 settingsPage,
327327 settingsUpdate,
328328 waveCut,
329 archiveSubmit,
329330 webhookCreate,
330331 webhookDelete,
331332 } from "../web/pages/settings.ts";
@@ -1139,6 +1140,7 @@ export function buildRouter(): Router<Handler> {
11391140 router.add("GET", "/:owner/:name/settings", settingsPage);
11401141 router.add("POST", "/:owner/:name/settings", settingsUpdate);
11411142 router.add("POST", "/:owner/:name/settings/wave", waveCut);
1143 router.add("POST", "/:owner/:name/settings/archive", archiveSubmit);
11421144 router.add("GET", "/:owner/:name/settings/app", appSettingsPage);
11431145 router.add("POST", "/:owner/:name/settings/app", appSettingsUpdate);
11441146 router.add("POST", "/:owner/:name/settings/app/disable", appDisable);
src/tui/screens/about.ts +48 −5
@@ -18,7 +18,8 @@
1818 import { isPinned } from "../../core/pins.ts";
1919 import { parentReleases, releasesSentence } from "../../core/parent_releases.ts";
2020 import { running } from "../../kernel/version.ts";
21 import type { Repo } from "../../core/repos.ts";
21 import { updateRepoSettings } from "../../actions/repos.ts";
22 import { canAdmin, getRepoById, type Repo } from "../../core/repos.ts";
2223 import type { RepoFacts, RepoSource } from "../../view/source.ts";
2324 import type { Ctx, Screen } from "../app/app.ts";
2425 import { binding } from "../app/keys.ts";
@@ -43,15 +44,37 @@ export function aboutScreen(
4344 facts: RepoFacts | undefined,
4445 ref: string,
4546 ): Screen {
46 const repo = localRepo(src);
47 const rows = aboutFacts(f, src, facts, ref);
47 const held = localRepo(src);
48 // Archiving changes the row under this card, so read it at use.
49 let repo = held;
50 const may = (): boolean =>
51 repo !== undefined &&
52 f.user !== undefined &&
53 f.user.kind === "user" &&
54 canAdmin(f.db, repo, f.user);
55 const factRows = (): [string, string][] => [
56 ...archivedRow(repo),
57 ...aboutFacts(f, src, facts, ref),
58 ];
59 let rows = factRows();
4860 const cloneUrl = rows.find(([label]) => label.startsWith("clone"))?.[1] ?? "";
4961 return {
5062 title: "About",
51 keys: [
63 get keys() {
64 return [
5265 binding(["y"], "copy the clone URL", { disabled: cloneUrl === "" }),
66 // Only an admin is offered the key, and only an admin's press counts.
67 ...(may()
68 ? [
69 binding(
70 ["a"],
71 repo?.archivedAt === null ? "archive" : "wake",
72 ),
73 ]
74 : []),
5375 binding(["esc"], "close"),
54 ],
76 ];
77 },
5578 render(area, s) {
5679 parent.render(area, s);
5780 const c = ctx.theme.c;
@@ -128,6 +151,20 @@ export function aboutScreen(
128151 ctx.toast("copied the clone URL", "success");
129152 return true;
130153 }
154 if (e.key === "a" && repo !== undefined && may()) {
155 const waking = repo.archivedAt !== null;
156 void updateRepoSettings(f.app, f.user, repo, {
157 archived: !waking,
158 }).then((done) => {
159 if (done.ok) {
160 repo = getRepoById(f.db, done.value.id) ?? done.value;
161 rows = factRows();
162 ctx.toast(waking ? "awake again" : "archived", "success");
163 } else ctx.toast("that could not be changed", "danger");
164 ctx.invalidate();
165 });
166 return true;
167 }
131168 if (e.key === "esc" || e.key === "q" || e.key === "I") {
132169 ctx.pop();
133170 return true;
@@ -137,6 +174,12 @@ export function aboutScreen(
137174 };
138175 }
139176
177 /** One line when an admin has put the repository away. */
178 function archivedRow(repo: Repo | undefined): [string, string][] {
179 if (repo === undefined || repo.archivedAt === null) return [];
180 return [["archived", repo.archivedAt.slice(0, 10)]];
181 }
182
140183 /**
141184 * The web following card's releases sentence, for a fork on a forge that
142185 * names a parent forge: the same words, from the same cache.
src/web/pages/repo.ts +24 −2
@@ -920,6 +920,28 @@ export async function repoFiles(ctx: Ctx): Promise<Response> {
920920 return await codeHome(ctx, repo);
921921 }
922922
923 /**
924 * "Archived on <date>" with, for an admin, the Wake button. A repository put
925 * away still clones, pushes and links as before; this only says so.
926 */
927 function archivedLine(ctx: Ctx, repo: Repo): Html | null {

Fine on the page. The terminal needs the same thing: the About screen should show the archived line, and an admin should get a key that wakes the repository through updateRepoSettings. A guest sees the line without the key. Without it the terminal door is missing (this is the high finding).

928 if (repo.archivedAt === null) return null;
929 return html`<div class="mt archived">
930 <p>
931 Archived on
932 <time datetime="${repo.archivedAt}">${repo.archivedAt.slice(0, 10)}</time>
933 </p>
934 ${when(
935 canAdmin(ctx.app.db, repo, ctx.auth.user),
936 () => html`<form method="post" action="${repoBase(repo)}/settings/archive">
937 <input type="hidden" name="archived" value="0" />
938 <input type="hidden" name="to" value="repo" />
939 ${btn("Wake", { size: "sm" })}
940 </form>`,
941 )}
942 </div>`
943 }
944
923945 /** The code at a ref: the tree, the README and the About rail — with, in
924946 * the studio, the offer to make a repository that is not an app one. */
925947 async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> {
@@ -930,7 +952,7 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> {
930952 const refs = await refSetFrom(scope.source);
931953
932954 if (refs.branches.length === 0) {
933 const body = html`${scopeHeader(ctx, scope, "code")}${noApp}
955 const body = html`${scopeHeader(ctx, scope, "code")}${archivedLine(ctx, repo)}${noApp}
934956 <div class="mt">
935957 ${empty({
936958 icon: "repo",
@@ -989,7 +1011,7 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> {
9891011 const following = await followingOf(ctx, repo);
9901012 const body = html`${scopeHeader(ctx, scope, "code", {
9911013 branchCount: refs.branches.length,
992 })}${noApp}
1014 })}${archivedLine(ctx, repo)}${noApp}
9931015 ${frozenBlock(ctx, repo)} ${appStrip(ctx, repo)}
9941016 ${following === undefined
9951017 ? forkBar(ctx, repo)
src/web/pages/settings.ts +45 −1
@@ -320,12 +320,28 @@ export async function settingsPage(ctx: Ctx): Promise<Response> {
320320 </form>`,
321321 { head: html`${icon("rocket")}<h2>Cut a wave</h2>` },
322322 );
323 const archive = card(
324 html`<form method="post" action="${base}/settings/archive">
325 <input type="hidden" name="archived" value="${repo.archivedAt === null ? "1" : "0"}" />
326 <p class="muted">
327 ${repo.archivedAt === null
328 ? "Put a finished repository away without deleting it. Its page says when it was archived; links, clone and push keep working."
329 : html`Archived on ${repo.archivedAt.slice(0, 10)}. Wake it to take the label off.`}
330 </p>
331 <div class="form-actions">
332 ${btn(repo.archivedAt === null ? "Archive" : "Wake", {
333 variant: "primary",
334 })}
335 </div>
336 </form>`,
337 { head: html`${icon("alert")}<h2>Archive</h2>` },
338 );
323339 return settingsPageResponse(
324340 ctx,
325341 repo,
326342 "general",
327343 "Settings",
328 html`${lead}<div class="mt">${body}</div><div class="mt">${wave}</div>${secrets
344 html`${lead}<div class="mt">${body}</div><div class="mt">${wave}</div><div class="mt">${archive}</div>${secrets
329345 ? html`<div class="mt">${secrets}</div>`
330346 : null}`,
331347 );
@@ -381,6 +397,34 @@ export async function settingsUpdate(ctx: Ctx): Promise<Response> {
381397 return flashTo(ctx, `${base}/settings`, flash);
382398 }
383399
400 /**
401 * POST /:owner/:name/settings/archive — archive or wake. The state asked
402 * for travels in the form, so a double submit is idempotent.
403 */
404 export async function archiveSubmit(ctx: Ctx): Promise<Response> {
405 const gate = await adminForm(ctx);
406 if (gate instanceof Response) return gate;
407 const { repo, form } = gate;
408 const asked = field(form, "archived");
outdated

Any value other than "1" counts as a wake. That works because the form only ever sends "0" or "1". Validating at the boundary means refusing anything else, as the API does with its boolean check: const v = field(form, "archived"); if (v !== "0" && v !== "1") return flashTo(... danger). Low.

409 if (asked !== "0" && asked !== "1")
410 return flashTo(ctx, `${repoBase(repo)}/settings`, {
411 tone: "danger",
412 message: "That could not be changed.",
413 });
414 const archived = asked === "1";
415 const updated = await updateRepoSettings(ctx.app, ctx.auth.user, repo, {
416 archived,
417 });
418 const back = field(form, "to") === "repo" ? repoBase(repo) : `${repoBase(repo)}/settings`;
419 return flashTo(
420 ctx,
421 back,
422 updated.ok
423 ? { message: archived ? "Archived." : "Awake again." }
424 : { tone: "danger", message: "That could not be changed." },
425 );
426 }
427
384428 /** POST /:owner/:name/settings/wave — open the draft of the next wave. */
385429 export async function waveCut(ctx: Ctx): Promise<Response> {
386430 const gate = await adminForm(ctx);
test/archive.test.ts added +132
@@ -0,0 +1,132 @@
1 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2 import { mkdtemp, rm } from "node:fs/promises";
3 import { tmpdir } from "node:os";
4 import { join } from "node:path";
5 import { createApp, type App } from "../src/app.ts";
6 import { getRepo } from "../src/core/repos.ts";
7 import { serve, type Servers } from "../src/http/server.ts";
8
9 type Row = { archivedAt: string | null };
10
11 describe("archive and wake", () => {
12 let dataDir: string;
13 let app: App;
14 let servers: Servers;
15 let base: string;
16 let owner = "";
17 let stranger = "";
18
19 const form = (fields: Record<string, string>) => new URLSearchParams(fields);
20
21 async function signup(username: string): Promise<string> {
22 const res = await fetch(`${base}/signup`, {
23 method: "POST",
24 body: form({
25 username,
26 email: `${username}@f.dev`,
27 password: "archive-password",
28 }),
29 redirect: "manual",
30 });
31 return (res.headers.get("set-cookie") ?? "").split(";")[0]!;
32 }
33
34 const patch = (cookie: string, archived: boolean) =>
35 fetch(`${base}/api/v1/repos/ada/old`, {
36 method: "PATCH",
37 headers: { cookie, "content-type": "application/json", origin: base },
38 body: JSON.stringify({ archived }),
39 });
40
41 beforeAll(async () => {
42 dataDir = await mkdtemp(join(tmpdir(), "forge-archive-"));
43 app = createApp({ dataDir, port: 0 });
44 servers = await serve(app);
45 base = servers.url;
46 owner = await signup("ada");
47 stranger = await signup("bob");
48 await fetch(`${base}/new`, {
49 method: "POST",
50 headers: { cookie: owner },
51 body: form({ name: "old", visibility: "public", description: "done" }),
52 redirect: "manual",
53 });
54 });
55
56 afterAll(async () => {
57 servers.stop();
58 app.close();
59 await rm(dataDir, { recursive: true, force: true });
60 });
61
62 test("a repository starts unarchived, and the JSON says so", async () => {
63 const res = await fetch(`${base}/api/v1/repos/ada/old`, {
64 headers: { cookie: owner },
65 });
66 expect(((await res.json()) as Row).archivedAt).toBeNull();
67 });
68
69 test("the API archives and wakes it", async () => {
70 const archived = await patch(owner, true);
71 expect(archived.status).toBe(200);
72 const stamp = ((await archived.json()) as Row).archivedAt;
73 expect(Date.parse(stamp ?? "")).not.toBeNaN();
74 expect(getRepo(app.db, "ada", "old")?.archivedAt).toBe(stamp);
75
76 // Archiving again keeps the first date.
77 expect(((await (await patch(owner, true)).json()) as Row).archivedAt).toBe(stamp);
78
79 const woke = await patch(owner, false);
80 expect(((await woke.json()) as Row).archivedAt).toBeNull();
81 expect(getRepo(app.db, "ada", "old")?.archivedAt).toBeNull();
82 });
83
84 test("a non-admin is refused with 403 and nothing changes", async () => {
85 const res = await patch(stranger, true);
86 expect(res.status).toBe(403);
87 expect(getRepo(app.db, "ada", "old")?.archivedAt).toBeNull();
88 });
89
90 test("the Settings form archives, the page says so, and Wake clears it", async () => {
91 const post = (cookie: string, fields: Record<string, string>, origin = base) =>
92 fetch(`${base}/ada/old/settings/archive`, {
93 method: "POST",
94 headers: { cookie, origin },
95 body: form(fields),
96 redirect: "manual",
97 });
98
99 // Cross-origin: refused, unchanged.
100 const cross = await post(owner, { archived: "1" }, "http://evil.example");
101 expect(cross.status).toBe(403);
102 expect(getRepo(app.db, "ada", "old")?.archivedAt).toBeNull();
103
104 // A stranger's form is not an admin's.
105 expect((await post(stranger, { archived: "1" })).status).toBeGreaterThanOrEqual(400);
106 expect(getRepo(app.db, "ada", "old")?.archivedAt).toBeNull();
107
108 expect((await post(owner, { archived: "1" })).status).toBe(303);
109 const at = getRepo(app.db, "ada", "old")!.archivedAt!;
110 const day = at.slice(0, 10);
111
112 const asOwner = await (
113 await fetch(`${base}/ada/old`, { headers: { cookie: owner } })
114 ).text();
115 expect(asOwner).toContain(`Archived on`);
116 expect(asOwner).toContain(day);
117 expect(asOwner).toContain("Wake");
118
119 const asStranger = await (
120 await fetch(`${base}/ada/old`, { headers: { cookie: stranger } })
121 ).text();
122 expect(asStranger).toContain("Archived on");
123 expect(asStranger).not.toContain("/settings/archive");
124
125 expect((await post(owner, { archived: "0", to: "repo" })).status).toBe(303);
126 expect(getRepo(app.db, "ada", "old")?.archivedAt).toBeNull();
127 const woken = await (
128 await fetch(`${base}/ada/old`, { headers: { cookie: owner } })
129 ).text();
130 expect(woken).not.toContain("Archived on");
131 });
132 });
test/tui-archive.test.ts added +114
@@ -0,0 +1,114 @@
1 /** Archive in the terminal (#1838): About shows it, an admin's `a` flips it. */
2
3 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
4 import { mkdtemp, rm } from "node:fs/promises";
5 import { tmpdir } from "node:os";
6 import { join } from "node:path";
7 import { updateRepoSettings } from "../src/actions/repos.ts";
8 import { createRepo } from "../src/actions/repos.ts";
9 import { signUp } from "../src/actions/users.ts";
10 import { createApp, type App as Forge } from "../src/app.ts";
11 import { getRepo, type Repo } from "../src/core/repos.ts";
12 import type { User } from "../src/core/users.ts";
13 import { createForgeApp } from "../src/tui/forge.ts";
14 import type { TuiIdentity } from "../src/tui/session.ts";
15 import { headlessTerminal } from "../src/tui/term/terminal.ts";
16 import { quietLogs } from "./helpers/globals.ts";
17 import { settleApp, settleUntil } from "./helpers/tui.ts";
18
19 quietLogs();
20
21 describe("archive in the terminal", () => {
22 let dataDir: string;
23 let forge: Forge;
24 let alice: User;
25 let repo: Repo;
26
27 function boot(identity: TuiIdentity) {
28 const terminal = headlessTerminal(120, 40);
29 const { app } = createForgeApp(forge, identity, {
30 terminal,
31 exitHooks: false,
32 });
33 app.start();
34 const press = async (...keys: string[]): Promise<void> => {
35 for (const key of keys)
36 app.dispatch({ type: "key", key, ctrl: false, alt: false, shift: false });
37 await settleApp(app);
38 };
39 return { app, press, text: () => app.screen.toText() };
40 }
41
42 async function openAbout(h: ReturnType<typeof boot>): Promise<void> {
43 await settleApp(h.app);
44 await h.press("/");
45 for (const ch of "beacon") await h.press(ch);
46 await h.press("enter");
47 await h.press("enter");
48 await settleUntil(h.app, "alice/beacon");
49 await h.press("I");
50 await settleUntil(h.app, "clone (http)");
51 }
52
53 beforeAll(async () => {
54 dataDir = await mkdtemp(join(tmpdir(), "forge-tui-archive-"));
55 forge = createApp({ dataDir, port: 0 });
56 const a = await signUp(forge, {
57 username: "alice",
58 email: "[email protected]",
59 password: "a-long-passphrase",
60 });
61 if (!a.ok) throw new Error("signup failed");
62 alice = a.value;
63 const made = await createRepo(forge, alice, {
64 name: "beacon",
65 visibility: "public",
66 });
67 if (!made.ok) throw new Error("repo failed");
68 repo = made.value;
69 });
70
71 afterAll(async () => {
72 await rm(dataDir, { recursive: true, force: true });
73 });
74
75 test("an admin archives and wakes from About with `a`", async () => {
76 const h = boot({
77 sshUsername: "alice",
78 remoteAddress: "127.0.0.1",
79 fingerprint: "SHA256:test",
80 user: alice,
81 });
82 try {
83 await openAbout(h);
84 expect(h.text()).not.toContain("archived");
85 await h.press("a");
86 expect(getRepo(forge.db, "alice", "beacon")?.archivedAt).not.toBeNull();
87 expect(h.text()).toMatch(/archived +20\d\d-/);
88 await h.press("a");
89 expect(getRepo(forge.db, "alice", "beacon")?.archivedAt).toBeNull();
90 expect(h.text()).not.toMatch(/archived +20\d\d-/);
91 } finally {
92 h.app.stop();
93 }
94 });
95
96 test("a guest sees the archived line but `a` does nothing", async () => {
97 const done = await updateRepoSettings(forge, alice, repo, { archived: true });
98 expect(done.ok).toBe(true);
99 const h = boot({
100 sshUsername: "git",
101 remoteAddress: "127.0.0.1",
102 fingerprint: "SHA256:unknown",
103 });
104 try {
105 await openAbout(h);
106 expect(h.text()).toMatch(/archived +20\d\d-/);
107 expect(h.text()).not.toMatch(/\ba +(wake|archive)\b/);
108 await h.press("a");
109 expect(getRepo(forge.db, "alice", "beacon")?.archivedAt).not.toBeNull();
110 } finally {
111 h.app.stop();
112 }
113 });
114 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs