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

Revoking a proposal token in the terminal asks first: `x` names the child, `y` revokes, `n` or esc keeps it #7958

Parked opened this
Closed without merging

scout/forge:scout/7949-revoking-a-proposal-token-in-the-termina → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +58 −7
src/tui/screens/proposal_tokens.ts +17 −5
@@ -1,7 +1,7 @@
11 /**
22 * Proposal tokens in the terminal: the ones you minted for a repository, with
33 * `n` to mint (a child's name, then where it lives) and `x` to revoke the one
4 * under the cursor. The secret is shown once, on a screen of its own. Every
4 * under the cursor, after a yes/no question. The secret is shown once, on a screen of its own. Every
55 * rule is the action's (`actions/proposal_tokens.ts`), the same as the API's
66 * and MCP's: a repository you do not write is "not visible to you", and
77 * nothing is listed or changed.
@@ -20,7 +20,7 @@ import { style } from "../term/style.ts";
2020 import { truncate } from "../term/width.ts";
2121 import type { Session } from "../session.ts";
2222 import { fill, len, split } from "../ui/layout.ts";
23 import { ListState, drawList, later, promptScreen, type ListRow } from "./common.ts";
23 import { ListState, confirmScreen, drawList, later, promptScreen, type ListRow } from "./common.ts";
2424
2525 /** Ask for `owner/name`, then show its proposal tokens. */
2626 export function proposalTokensPrompt(f: Session, ctx: Ctx, parent: Screen): Screen {
@@ -91,9 +91,21 @@ export function proposalTokensScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
9191 if (e.key === "x") {
9292 const t = items()[state.index];
9393 if (t === undefined) return false;
94 const done = revokeProposal(f.app, f.user, repo, t.id);
95 note = done.ok ? `${t.child}: revoked.` : done.error.message;
96 ctx.invalidate();
94 // A revoke cuts the child off until it is handed a new token: ask first.
95 ctx.push(
96 confirmScreen(ctx, screen, {
97 title: `Revoke the token for ${t.child}?`,
98 body: [`${t.child} can no longer propose here until it is handed a new token.`],
99 actions: [{ label: "Revoke", variant: "danger" }, { label: "Keep", variant: "ghost" }],
100 yesNo: true,
101 onChoose: (choice) => {
102 if (choice !== 0) return;
103 const done = revokeProposal(f.app, f.user, repo, t.id);
104 note = done.ok ? `${t.child}: revoked.` : done.error.message;
105 ctx.invalidate();
106 },
107 }),
108 );
97109 return true;
98110 }
99111 if (e.key === "n") {
test/proposal-token-doors.test.ts +6 −2
@@ -198,6 +198,7 @@ describe("proposal tokens through MCP and the terminal", () => {
198198 // The earlier "mine" token is first; the new one is under the second row.
199199 await h.press("j");
200200 await h.press("x");
201 await h.press("y");
201202 expect(proposalOf(app.db, row.token_id)).toBeUndefined();
202203 expect(h.text()).toContain("terminal-kid: revoked.");
203204 h.stop();
@@ -212,8 +213,11 @@ describe("proposal tokens through MCP and the terminal", () => {
212213 await h.press("enter");
213214 const rows = app.db.query<{ child: string }, []>("SELECT child FROM proposal_token ORDER BY token_id").all();
214215 expect(rows.length).toBeGreaterThan(0);
215 // Revoke every row: the cursor stays on the first.
216 for (let i = 0; i < rows.length; i++) await h.press("x");
216 // Revoke every row, saying yes each time: the cursor stays on the first.
217 for (let i = 0; i < rows.length; i++) {
218 await h.press("x");
219 await h.press("y");
220 }
217221 expect(h.text()).toContain("revoked");
218222 expect(app.db.query("SELECT 1 FROM proposal_token").all()).toEqual([]);
219223 h.stop();
test/tui-proposal-tokens.test.ts +35
@@ -6,6 +6,7 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
66 import { mkdtemp, rm } from "node:fs/promises";
77 import { tmpdir } from "node:os";
88 import { join } from "node:path";
9 import { listProposals, repoByName } from "../src/actions/proposal_tokens.ts";
910 import { createRepo } from "../src/actions/repos.ts";
1011 import { createApp, type App } from "../src/app.ts";
1112 import { createUser, getUserByName } from "../src/core/users.ts";
@@ -113,6 +114,9 @@ describe("proposal tokens in the terminal", () => {
113114 expect(h.text()).not.toContain("Shown once");
114115
115116 await h.press("x");
117 expect(h.text()).toContain("Revoke the token for kid-one?");
118 expect(count(app)).toBe(1);
119 await h.press("y");
116120 expect(h.text()).toContain("kid-one: revoked.");
117121 expect(h.text()).not.toContain(secret);
118122 expect(count(app)).toBe(0);
@@ -120,6 +124,37 @@ describe("proposal tokens in the terminal", () => {
120124 h.stop();
121125 });
122126
127 test("x asks first: n or esc keeps the token", async () => {
128 const h = boot("alice");
129 await h.open();
130 await h.press("n");
131 await h.type("kid-two");
132 await h.press("enter");
133 await h.type("https://kid2.example.com/");
134 await h.press("enter");
135 await h.press("esc");
136
137 const alice = getUserByName(app.db, "alice")!;
138 const listed = () => {
139 const r = listProposals(app, alice, repoByName(app, "alice/lib"));
140 return r.ok ? r.value.map((t) => t.child) : [];
141 };
142 await h.press("x");
143 expect(h.text()).toContain("Revoke the token for kid-two?");
144 expect(h.text()).toContain("kid-two can no longer propose here");
145 await h.press("n");
146 expect(h.text()).not.toContain("revoked.");
147 expect(listed()).toEqual(["kid-two"]);
148
149 await h.press("x");
150 await h.press("esc");
151 expect(listed()).toEqual(["kid-two"]);
152
153 await h.press("x", "y");
154 expect(listed()).toEqual([]);
155 h.stop();
156 });
157
123158 test("bad input mints nothing", async () => {
124159 const h = boot("alice");
125160 await h.open();

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs