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

The terminal lists a repository's labels, makes one and deletes one with a confirm, as MCP `repo_labels` does #7458

Parked opened this
Closed without merging

torque/forge:torque/7255-the-terminal-lists-a-repository-s-labels → main 5 commits fork 3 threads · 3 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
8 files changed +527 −1
README.md +4
@@ -295,6 +295,10 @@ opened with it says "proposed by child … from …" on every tab of the pull's
295295 page, in the terminal's pull view, and as `proposal` in the pull's JSON
296296 (`GET …/pulls/:number`, and MCP's `pull` tool). `GET …/pulls/:number?diff=0` reads the pull without its diff (and skips computing it); `diff` is `0` or `1`, default `1`, and anything else answers 422. `GET …/issues?fields=brief` lists issues with only number, kind, title, state, labels, assignee, author, originAuthor, authorIsAgent, createdAt and updatedAt (and `untrusted` where it applies); no bodies or comments. `fields` is `brief` or left out, and anything else answers 422 `invalid_fields`. `GET …/repos/:owner/:name/events` answers `{ items, next_cursor }`, newest first, `limit` 1 to 200 (default 50) and `cursor` from `next_cursor` (anything else is a 422); it used to answer a bare array of every event, so a client that read the array reads `items` now. A request reads at most 1,000 events, so when most of them are hidden from the reader a page can come back short with a `next_cursor`: keep following it until it is null. MCP's `events` tool answers the same. `GET …/repos/:owner/:name/branches` answers `{ items, next_cursor }` in the order it always had, `limit` 1 to 200 (default 50) and `cursor` the `next_cursor` of the page before (the name of the last branch on it); anything else is a 422, and a cursor naming a branch deleted between two requests is `invalid_cursor`, so start over. It used to answer a bare array, so a client that read the array reads `items` now. `GET …/repos/:owner/:name/forks`, `…/labels` and `…/hooks` answer `{ items, next_cursor }` too, in the order they always had, `limit` 1 to 200 (default 50) and `cursor` the `next_cursor` of the page before (the id of the last row on it); anything else is a 422, and a cursor naming a row deleted between two requests is `invalid_cursor`, so start over. They used to answer a bare array, so a client that read the array reads `items` now.
297297
298 ### Labels in the terminal
299
300 `:` → "Labels in a repository" (or "Labels" in a repository's own palette) lists the labels with their colour chips and how many open issues and pulls you may see carry each (a sealed report counts only for those who may read it); it follows changes made on the web or through MCP. For a repository's admin, `n` takes "name hex" (for example `bug d73a4a`) and `d` deletes the selected label after a confirm naming how many issues and pulls lose it; a reader sees the list alone. Same actions as `repo_labels`.
301
298302 ### Proposing to a parent forge
299303
300304 A spawned forge can offer its change to its parent with a proposal token, and an admin sets how it follows the parent. Details, API, MCP and terminal doors: [`docs/FOLLOWING.md`](docs/FOLLOWING.md#proposing-to-a-parent-forge).
src/core/issues.ts +29
@@ -860,6 +860,35 @@ export function listLabels(db: Database, repoId: string): Label[] {
860860 .all(repoId);
861861 }
outdated

Counts every linked issue regardless of who is looking. Filter to what the viewer may see, and add a core test for open vs all.

862862
863 /**
864 * How many issues and pulls carry each label of a repo, `open` of them still
865 * open, counting only what the viewer may see: `scope` is `sealedScope`'s
866 * answer (`sealed.ts`), and without it sealed rows are left out, as lists do.
867 */
868 export function labelUse(
869 db: Database,
870 repoId: string,
871 scope: { sealed?: true; sealedBy?: string } = {},
872 ): Map<string, { open: number; all: number }> {
873 // The rule sits in the join, so a label whose every issue is hidden still answers 0.
874 const seen =
875 scope.sealed === true
876 ? ""
877 : scope.sealedBy === undefined
878 ? " AND issue.sealed = 0"
879 : " AND (issue.sealed = 0 OR issue.author_id = ?2)";
880 const rows = db
881 .query<{ id: string; open: number; all: number }, string[]>(
882 `SELECT label.id AS id, COALESCE(SUM(issue.state = 'open'), 0) AS open, COUNT(issue.id) AS "all"
883 FROM label LEFT JOIN issue_label ON issue_label.label_id = label.id
884 LEFT JOIN issue ON issue.id = issue_label.issue_id${seen}
885 WHERE label.repo_id = ?1 GROUP BY label.id`,
886 )
887 // SQLite refuses a bound value the statement never names, so ?2 goes only with the clause that reads it.
888 .all(...(seen.includes("?2") ? [repoId, scope.sealedBy!] : [repoId]));
889 return new Map(rows.map((r) => [r.id, { open: r.open, all: r.all }]));
890 }
891
863892 export function setIssueLabels(
864893 db: Database,
865894 issueId: string,
src/tui/forge.ts +6
@@ -66,6 +66,7 @@ import { releasesScreen } from "./screens/releases.ts";
6666 import { mayRead } from "../release/gate.ts";
6767 import { fileHoldsPrompt } from "./screens/fileholds.ts";
6868 import { stalledScreen } from "./screens/stalled.ts";
69 import { labelsScreen } from "./screens/labels.ts";
6970 import { issuesScreen, newIssueScreen } from "./screens/issues.ts";
7071 import { limbsScreen } from "./screens/limbs.ts";
7172 import { newPullScreen } from "./screens/newpull.ts";
@@ -110,6 +111,11 @@ const REPO_VERBS: readonly {
110111 title: "Milestones in a repository",
111112 open: (f, ctx, repo) => limbsScreen(f, ctx, repo),
112113 },
114 {
115 id: "labels",
116 title: "Labels in a repository",
117 open: (f, ctx, repo) => labelsScreen(f, ctx, repo),
118 },
113119 {
114120 // What the crew's tokens bought on one app, as MCP `returns` with `repo` (#7271).
115121 id: "repo-usage",
src/tui/screens/labels.ts added +166
@@ -0,0 +1,166 @@
1 /**
2 * A repository's labels, the terminal's door to the labels page and MCP
3 * `repo_labels`: each label as its chip with how many open issues carry it.
4 * `n` makes one and `d` deletes the selected one after a confirm, both through
5 * the actions, so who may and what a bad one is told are theirs. Only an admin
6 * of the repository is offered the two keys; someone who cannot read it is
7 * offered no door and, handed the screen anyway, sees nothing of it.
8 */
9
10 import { LABEL_WORDS } from "../../actions/label_words.ts";
11 import { createLabel, deleteLabel } from "../../actions/repos.ts";
12 import { labelUse, listLabels, type Label } from "../../core/issues.ts";
13 import { canAdmin, canRead, type Repo } from "../../core/repos.ts";
14 import { sealedScope } from "../../core/sealed.ts";
15 import type { Ctx, Screen } from "../app/app.ts";
16 import { binding } from "../app/keys.ts";
17 import type { Command } from "../app/palette.ts";
18 import type { Session } from "../session.ts";
19 import { style } from "../term/style.ts";
20 import { truncate } from "../term/width.ts";
21 import { fill, len, split } from "../ui/layout.ts";
22 import { emptyState, labelChip } from "../ui/widgets.ts";
23 import { ListState, confirmScreen, live, plural, promptScreen } from "./common.ts";
24
25 /** "name ffcc00": the colour is the last word, the name is the rest. */
26 export function parseLabel(text: string): { name: string; color: string } | undefined {
27 const m = /^(.+?)\s+#?([0-9a-fA-F]{6})$/.exec(text.trim());
28 return m === null ? undefined : { name: m[1]!, color: m[2]! };
29 }
30
31 export function labelsCommands(f: Session, ctx: Ctx, repo: Repo | undefined): Command[] {
32 if (repo === undefined || !canRead(f.db, repo, f.user)) return [];
33 return [
34 {
35 id: "labels",
36 title: `${repo.ownerName}/${repo.name} — Labels`,
37 hint: "list, make, delete",
38 run: () => ctx.push(labelsScreen(f, ctx, repo)),
39 },
40 ];
41 }
42
43 export function labelsScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
outdated

No read check here: a viewer who cannot read the repo still gets labels and counts. Gate on the same read rule the page uses and test it with a guest.

44 const state = new ListState();
45 let labels: Label[] = [];
46 let use = new Map<string, { open: number; all: number }>();
47 // Asked on every read, as the page asks on every request: access can change while the screen is open.
48 let may = false;
49 const admin = () => f.user !== undefined && canAdmin(f.db, repo, f.user);
50 const read = (): void => {
51 may = canRead(f.db, repo, f.user);
52 labels = may ? listLabels(f.db, repo.id) : [];
53 // Counts only what this viewer may see, so a sealed report is not betrayed by a number.
54 use = may ? labelUse(f.db, repo.id, sealedScope(f.db, repo, f.user)) : new Map();
55 state.clamp(labels.length);
56 ctx.invalidate();
57 };
58 read();
59 const self: Screen = {
60 title: "Labels",
61 get keys() {
62 return [
63 binding(["j", "k"], "move"),
64 ...(admin() ? [binding(["n"], "new label"), binding(["d"], "delete")] : []),
65 binding(["esc", "q"], "close"),
66 ];
67 },
68 load(signal) {
69 live(f, signal, { repoId: repo.id, kinds: ["label.created", "label.updated", "label.deleted"] }, read);
70 read();
71 return Promise.resolve();
72 },
73 render(area, s) {
74 const c = ctx.theme.c;
75 if (!may) {
76 emptyState(s, area, c, { title: "No such repository" });
77 return;
78 }
79 const [head, body] = split(area, "v", [len(1), fill(1)]);
80 s.text(
81 head!.x,
82 head!.y,
83 truncate(`${repo.ownerName}/${repo.name} · ${plural(labels.length, "label")}`, head!.w),
84 style(c.mutedFg, c.bg),
85 head!.x + head!.w,
86 );
87 if (labels.length === 0) {
88 emptyState(s, body!, c, {
89 title: "No labels yet",
90 ...(admin() ? { body: "Press n to make one." } : {}),
91 });
92 return;
93 }
94 const from = state.window(body!.h, labels.length);
95 labels.slice(from, from + body!.h).forEach((l, i) => {
96 const y = body!.y + i;
97 const right = body!.x + body!.w;
98 const sel = from + i === state.index;
99 s.text(body!.x, y, sel ? "▸" : " ", style(c.fg, c.bg), right);
100 const end = labelChip(s, body!.x + 2, y, c, { text: truncate(l.name, 30), color: l.color }, right);
101 s.text(end + 2, y, `#${l.color} ${use.get(l.id)?.open ?? 0} open`, style(c.mutedFg, c.bg), right);
102 });
103 },
104 key(e) {
105 if (e.key === "esc" || e.key === "q") {
106 ctx.pop();
107 return true;
108 }
109 if (e.key === "n" && admin()) {
110 ctx.push(
111 promptScreen(ctx, self, {
112 title: "New label",
113 label: "Name, then six hex digits",
114 placeholder: "bug d73a4a",
115 onSubmit: (text) => {
116 const parsed = parseLabel(text);
117 if (parsed === undefined) return LABEL_WORDS.shape;
118 const made = createLabel(f.app, f.user, repo, parsed.name, parsed.color);
119 if (!made.ok)
120 return made.error === "taken"
121 ? "A label with that name already exists."
122 : made.error === "invalid"
123 ? LABEL_WORDS.shape
124 : "You cannot change this repository's labels.";
125 read();
126 ctx.toast(`Created the label ${made.value.name}.`);
127 return undefined;
128 },
129 }),
130 );
131 return true;
132 }
133 if (e.key === "d" && admin()) {
134 const label = labels[state.index];
135 if (label === undefined) return true;
136 const n = use.get(label.id)?.all ?? 0;
137 ctx.push(
outdated

not_found and forbidden share one message; say which.

138 confirmScreen(ctx, self, {
139 title: "Delete label",
140 body: [`Delete ${label.name}? ${n === 0 ? "No issue carries it." : `${n} ${n === 1 ? "issue or pull loses" : "issues and pulls lose"} it.`}`],
141 actions: [{ label: "Delete", variant: "danger" }, { label: "Cancel" }],
142 selected: 1,
143 onChoose: (choice) => {
144 if (choice !== 0) return;
145 const gone = deleteLabel(f.app, f.user, repo, label.id);
146 read();
147 // deleteLabel answers not_found for both causes; the admin check now tells them apart.
148 ctx.toast(
149 gone.ok
150 ? `Deleted the label ${label.name}.`
151 : admin()
152 ? `The label ${label.name} is already gone.`
153 : "You are no longer this repository's admin.",
154 gone.ok ? "default" : "danger",
155 );
156 },
157 }),
158 );
159 return true;
160 }
161 state.key(e, labels.length);
162 return true;
163 },
164 };
165 return self;
166 }
src/tui/screens/workspace.ts +2
@@ -128,6 +128,7 @@ import { reportCommands } from "./report.ts";
128128 import { reportsCommands } from "./reports.ts";
129129 import { tellCommands } from "./tell.ts";
130130 import { workingCommands } from "./working.ts";
131 import { labelsCommands } from "./labels.ts";
131132 import { forgeItCommands } from "./forge_it.ts";
132133 import { makeItYoursScreen, yoursCommands } from "./yours.ts";
133134 import { visionCommands } from "./vision.ts";
@@ -1443,6 +1444,7 @@ export function workspaceScreen(
14431444 ...hooksCommands(f, ctx, repo),
14441445 ...visionCommands(f, ctx, repo),
14451446 ...appEnvCommands(f, ctx, repo),
1447 ...labelsCommands(f, ctx, repo),
14461448 ],
14471449 get title() {
14481450 return sourceName(src);
test/label-use.test.ts added +86
@@ -0,0 +1,86 @@
1 /**
2 * `labelUse`: per label, how many issues and pulls carry it (`all`) and how
3 * many of those are open (`open`), counting a sealed report only for a viewer
4 * whose `sealedScope` admits it.
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 { createRepo } from "../src/actions/repos.ts";
11 import { createApp, type App as Forge } from "../src/app.ts";
12 import { createIssue, createLabel, labelUse, setIssueLabels, setIssueState } from "../src/core/issues.ts";
13 import type { Repo } from "../src/core/repos.ts";
14 import { createUser, type User } from "../src/core/users.ts";
15 import { quietLogs } from "./helpers/globals.ts";
16
17 quietLogs();
18
19 describe("labelUse", () => {
20 let dir: string;
21 let forge: Forge;
22 let alice: User;
23 let repo: Repo;
24 let used: string;
25 let idle: string;
26 let secret: string;
27
28 function issue(title: string, opts: { kind?: "issue" | "pull"; sealed?: boolean; labels: string[]; closed?: boolean }) {
29 const made = createIssue(forge.db, { repoId: repo.id, authorId: alice.id, title, kind: opts.kind ?? "issue", sealed: opts.sealed ?? false });
30 if (!made.ok) throw new Error(made.error);
31 setIssueLabels(forge.db, made.value.id, opts.labels);
32 if (opts.closed === true) setIssueState(forge.db, made.value.id, "closed");
33 }
34
35 beforeAll(async () => {
36 dir = await mkdtemp(join(tmpdir(), "forge-label-use-"));
37 forge = createApp({ dataDir: dir, port: 0 });
38 const made = await createUser(forge.db, {
39 origin: "seed",
40 trusted: true,
41 username: "alice",
42 email: "[email protected]",
43 password: "a-good-passphrase",
44 adminIfFirst: true,
45 });
46 if (!made.ok) throw new Error(made.error);
47 alice = made.value;
48 const r = await createRepo(forge, alice, { name: "site", visibility: "public" });
49 if (!r.ok) throw new Error(r.error);
50 repo = r.value;
51 const label = (name: string, color: string) => {
52 const l = createLabel(forge.db, repo.id, name, color);
53 if (!l.ok) throw new Error(l.error);
54 return l.value.id;
55 };
56 used = label("bug", "d73a4a");
57 idle = label("idle", "112233");
58 secret = label("security", "ff0000");
59 // bug: two open (an issue and a pull) and one closed issue, so open 2 of all 3.
60 issue("open issue", { labels: [used] });
61 issue("open pull", { kind: "pull", labels: [used] });
62 issue("closed issue", { labels: [used], closed: true });
63 // security: one sealed open report and nothing else.
64 issue("the hole", { sealed: true, labels: [secret] });
65 });
66
67 afterAll(async () => {
68 forge.db.close();
69 await rm(dir, { recursive: true, force: true });
70 });
71
72 test("open counts the open issues and pulls, all counts every one", () => {
73 expect(labelUse(forge.db, repo.id).get(used)).toEqual({ open: 2, all: 3 });
74 });
75
76 test("a label nothing carries answers zero, not absent", () => {
77 expect(labelUse(forge.db, repo.id).get(idle)).toEqual({ open: 0, all: 0 });
78 });
79
80 test("a sealed report counts only for a viewer who may see it", () => {
81 expect(labelUse(forge.db, repo.id).get(secret)).toEqual({ open: 0, all: 0 });
82 expect(labelUse(forge.db, repo.id, { sealedBy: "someone-else" }).get(secret)).toEqual({ open: 0, all: 0 });
83 expect(labelUse(forge.db, repo.id, { sealedBy: alice.id }).get(secret)).toEqual({ open: 1, all: 1 });
84 expect(labelUse(forge.db, repo.id, { sealed: true }).get(secret)).toEqual({ open: 1, all: 1 });
85 });
86 });
test/tui-labels.test.ts added +229
@@ -0,0 +1,229 @@
1 /**
2 * A repository's labels in the terminal: the list with its chips and open
3 * counts, `n` makes one through createLabel, `d` deletes after a confirm that
4 * names the issues that lose it, and a reader is offered neither key. Reads
5 * are gated as the page gates them: someone who cannot read a private
6 * repository sees nothing of it, and nobody counts a sealed report they may
7 * not see.
8 */
9 import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
10 import { mkdtemp, rm } from "node:fs/promises";
11 import { tmpdir } from "node:os";
12 import { join } from "node:path";
13 import { openIssue } from "../src/actions/issues.ts";
14 import { createLabel, createRepo, deleteLabel } from "../src/actions/repos.ts";
15 import { createApp, type App as Forge } from "../src/app.ts";
16 import { createIssue, listLabels, setIssueLabels } from "../src/core/issues.ts";
17 import type { Repo } from "../src/core/repos.ts";
18 import { createUser, type User } from "../src/core/users.ts";
19 import { createForgeApp } from "../src/tui/forge.ts";
20 import { labelsCommands, labelsScreen, parseLabel } from "../src/tui/screens/labels.ts";
21 import { headlessTerminal } from "../src/tui/term/terminal.ts";
22 import { quietLogs } from "./helpers/globals.ts";
23 import { settleApp } from "./helpers/tui.ts";
24
25 quietLogs();
26
27 describe("labels in the terminal", () => {
28 let dir: string;
29 let forge: Forge;
30 let alice: User;
31 let bob: User;
32 let carol: User;
33 let repo: Repo;
34 let vault: Repo;
35 let issueId: string;
36
37 function open(user: User | undefined, at: Repo = repo) {
38 const terminal = headlessTerminal(110, 24);
39 const { app, session } = createForgeApp(
40 forge,
41 { sshUsername: "t", remoteAddress: "127.0.0.1", user },
42 { terminal, exitHooks: false },
43 );
44 app.start();
45 app.ctx.push(labelsScreen(session, app.ctx, at));
46 const type = async (text: string) => {
47 for (const ch of text) {
48 app.dispatch({ type: "key", key: ch, ctrl: false, alt: false, shift: false });
49 await settleApp(app);
50 }
51 };
52 const esc = async () => {
53 app.dispatch({ type: "key", key: "esc", ctrl: false, alt: false, shift: false });
54 await settleApp(app);
55 };
56 const enter = async () => {
57 app.dispatch({ type: "key", key: "enter", ctrl: false, alt: false, shift: false });
58 await settleApp(app);
59 };
60 const ready = () => settleApp(app);
61 return { session, ctx: app.ctx, ready, text: () => app.screen.toText(), type, enter, esc, stop: () => app.stop() };
62 }
63
64 beforeAll(async () => {
65 dir = await mkdtemp(join(tmpdir(), "forge-tui-labels-"));
66 forge = createApp({ dataDir: dir, port: 0 });
67 const users: User[] = [];
68 for (const [username, adminIfFirst] of [["alice", true], ["bob", false], ["carol", false]] as const) {
69 const made = await createUser(forge.db, {
70 origin: "seed",
71 trusted: true,
72 username,
73 email: `${username}@forge.local`,
74 password: "a-good-passphrase",
75 adminIfFirst,
76 });
77 if (!made.ok) throw new Error(made.error);
78 users.push(made.value);
79 }
80 [alice, bob, carol] = users as [User, User, User];
81 const made = await createRepo(forge, alice, { name: "site", visibility: "public" });
82 if (!made.ok) throw new Error(made.error);
83 repo = made.value;
84 const issue = openIssue(forge, alice, repo, { title: "It breaks" });
85 if (!issue.ok) throw new Error(issue.error);
86 issueId = issue.value.id;
87 const priv = await createRepo(forge, alice, { name: "vault", visibility: "private" });
88 if (!priv.ok) throw new Error(priv.error);
89 vault = priv.value;
90 const plan = createLabel(forge, alice, vault, "secret-plan", "123456");
91 if (!plan.ok) throw new Error(plan.error);
92 });
93
94 // Each test starts from the same one label, "bug", carried by one issue.
95 beforeEach(() => {
96 for (const l of listLabels(forge.db, repo.id)) deleteLabel(forge, alice, repo, l.id);
97 const bug = createLabel(forge, alice, repo, "bug", "d73a4a");
98 if (!bug.ok) throw new Error(bug.error);
99 setIssueLabels(forge.db, issueId, [bug.value.id]);
100 });
101
102 afterAll(async () => {
103 forge.db.close();
104 await rm(dir, { recursive: true, force: true });
105 });
106
107 test("parseLabel takes the colour from the last word", () => {
108 expect(parseLabel("good first issue #00FF00")).toEqual({ name: "good first issue", color: "00FF00" });
109 expect(parseLabel("bug")).toBeUndefined();
110 expect(parseLabel("bug 12345")).toBeUndefined();
111 });
112
113 test("lists each label with its open count", async () => {
114 const t = open(alice);
115 await t.ready();
116 const text = t.text();
117 expect(text).toContain("bug");
118 expect(text).toContain("1 open");
119 expect(text).toContain("n new label");
120 t.stop();
121 });
122
123 test("a bad colour says the words and makes nothing; a good one makes the label", async () => {
124 const t = open(alice);
125 await t.type("n");
126 await t.type("urgent zzz");
127 await t.enter();
128 expect(t.text()).toContain("A label needs a name and a six-digit hex color.");
129 expect(listLabels(forge.db, repo.id).map((l) => l.name)).toEqual(["bug"]);
130 await t.esc();
131 await t.type("n");
132 await t.type("bug aabbcc");
133 await t.enter();
134 expect(t.text()).toContain("already exists");
135 await t.esc();
136 t.stop();
137 const u = open(alice);
138 await u.type("n");
139 await u.type("urgent 00ff00");
140 await u.enter();
141 expect(listLabels(forge.db, repo.id).map((l) => l.name)).toEqual(["bug", "urgent"]);
142 expect(u.text()).toContain("urgent");
143 u.stop();
144 });
145
146 test("d confirms with the issues that lose the label, then deletes", async () => {
147 const t = open(alice);
148 await t.type("d");
149 expect(t.text()).toContain("1 issue or pull loses it");
150 await t.enter(); // Cancel is the default
151 expect(listLabels(forge.db, repo.id).map((l) => l.name)).toContain("bug");
152 await t.type("d");
153 await t.type("h");
154 await t.enter();
155 expect(listLabels(forge.db, repo.id).map((l) => l.name)).toEqual([]);
156 t.stop();
157 });
158
159 test("a label made elsewhere appears, and the cursor never leaves the screen", async () => {
160 const t = open(alice);
161 await t.ready();
162 for (let i = 0; i < 30; i++) createLabel(forge, alice, repo, `extra-${String(i).padStart(2, "0")}`, "112233");
163 await Bun.sleep(150);
164 await t.ready();
165 expect(t.text()).toContain("extra-00");
166 for (let i = 0; i < 31; i++) await t.type("j");
167 const names = listLabels(forge.db, repo.id).map((l) => l.name);
168 const last = names[names.length - 1]!;
169 expect(t.text()).toContain(last);
170 await t.type("d");
171 expect(t.text()).toContain(`Delete ${last}?`);
172 t.stop();
173 });
174
175 test("a reader sees the list alone", async () => {
176 const t = open(bob);
177 await t.ready();
178 expect(t.text()).toContain("bug");
179 expect(t.text()).not.toContain("new label");
180 await t.type("n");
181 await t.type("d");
182 expect(t.text()).not.toContain("New label");
183 expect(t.text()).not.toContain("Delete label");
184 expect(listLabels(forge.db, repo.id).length).toBe(1);
185 t.stop();
186 });
187
188 test("a private repository shows a guest and a non-member nothing, and offers them no door", async () => {
189 for (const who of [undefined, carol]) {
190 const t = open(who, vault);
191 await t.ready();
192 expect(t.text()).toContain("No such repository");
193 expect(t.text()).not.toContain("secret-plan");
194 expect(labelsCommands(t.session, t.ctx, vault)).toEqual([]);
195 t.stop();
196 }
197 const owner = open(alice, vault);
198 await owner.ready();
199 expect(owner.text()).toContain("secret-plan");
200 expect(labelsCommands(owner.session, owner.ctx, vault).map((c) => c.id)).toEqual(["labels"]);
201 owner.stop();
202 });
203
204 test("a sealed report is counted for a writer and not for a reader", async () => {
205 const bug = listLabels(forge.db, repo.id).find((l) => l.name === "bug")!;
206 const hole = createIssue(forge.db, { repoId: repo.id, authorId: alice.id, title: "the hole", sealed: true });
207 if (!hole.ok) throw new Error(hole.error);
208 setIssueLabels(forge.db, hole.value.id, [bug.id]);
209 const reader = open(bob);
210 await reader.ready();
211 expect(reader.text()).toContain("1 open");
212 reader.stop();
213 const writer = open(alice);
214 await writer.ready();
215 expect(writer.text()).toContain("2 open");
216 writer.stop();
217 });
218
219 test("a delete that finds the label gone says so, not that you lost the right", async () => {
220 const t = open(alice);
221 await t.type("d");
222 deleteLabel(forge, alice, repo, listLabels(forge.db, repo.id)[0]!.id);
223 await t.type("h");
224 await t.enter();
225 expect(t.text()).toContain("The label bug is already gone.");
226 expect(t.text()).not.toContain("no longer this repository's admin");
227 t.stop();
228 });
229 });
test/tui-notes.test.ts +5 −1
@@ -86,6 +86,10 @@ describe("notes from the app, in the terminal", () => {
8686 expect(await palette(bob, plain, [":", "Tell the"])).not.toContain("Tell the builders");
8787 });
8888
89 test("the repository palette offers its labels", async () => {
90 expect(await palette(bob, notes, [":", "Labels"])).toContain("alice/notes — Labels");
91 });
92
8993 test("a note files a from-app issue as the person", async () => {
9094 const text = await palette(bob, notes, [":", "Tell the", "\r", ..."the logo is blurry".split(""), "\r"]);
9195 expect(text).toContain("Sent");
@@ -112,7 +116,7 @@ describe("notes from the app, in the terminal", () => {
112116 test("the admin lists the banned senders and unbans one; a reader has no such row", async () => {
113117 const record = getAppBySlug(app.db, "notes")!;
114118 expect(isBanned(app.db, record.id, `u:${bob.id}`)).toBe(true);
115 expect(await palette(bob, notes, [":"])).not.toContain("Banned senders");
119 expect(await palette(bob, notes, [":", "Banned"])).not.toContain("Banned senders");
116120 const listed = await palette(alice, notes, [":", "Banned", "\r"]);
117121 expect(listed).toContain("@bob");
118122 expect(await palette(bob, notes, [":", "Banned", "\r"])).not.toContain("Unban");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs