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

The bets list is keyboard-first: j/k move between rows, enter opens one #10423

Parked opened this
Closed without merging

torque/forge:torque/10403-the-bets-list-is-keyboard-first-j-k-move → main 4 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +80 −66
src/kernel/why_now.ts deleted −37
@@ -1,37 +0,0 @@
1 /**
2 * Retired 2026-11-09: the direction no longer puts the pipeline first —
3 * order is set by the pillars and the captain's ranking — so the gate no
4 * longer asks (`scripts/gate.ts`). A finished, approved pull closed unmerged
5 * on this rule (#10317); nothing reads it now. Kept with its test until the
6 * next sweep of unused modules.
7 *
8 * The direction issue put the pipeline first (#8839), so a new feature
9 * said why it went ahead of it. A feature is a file a pull adds, at any
10 * depth, under an action, a page, an API route, an MCP tool or a terminal
11 * screen; the pull's commits must then say either `Pipeline: #N` (it is
12 * pipeline work) or `Why now: <reason>` (it goes ahead, and why). The check
13 * cannot read the pull description, so the answer lives in a commit
14 * message. It is a nudge, not a proof: it checks a reason was written, not
15 * that it is a good one.
16 */
17
18 import type { Change } from "./pin_edits.ts";
19
20 const FEATURE = /^src\/(actions|web\/pages|http\/api|http\/mcp\/tools|tui)\/.+\.ts$/;
21 const PIPELINE = /^Pipeline:\s*#\d+/im;
22 const WHY_NOW = /^Why now:\s*\S[^\n]{14,}/im;
23
24 /** The files a pull adds that make a new feature. */
25 export function featuresAdded(changes: readonly Change[]): string[] {
26 return changes.filter((c) => c.status.startsWith("A") && FEATURE.test(c.path)).map((c) => c.path);
27 }
28
29 /** One line per problem: none when no feature is added or a commit answers the direction. */
30 export function whyNowProblems(changes: readonly Change[], messages: readonly string[]): string[] {
31 const added = featuresAdded(changes);
32 if (added.length === 0) return [];
33 if (messages.some((m) => PIPELINE.test(m) || WHY_NOW.test(m))) return [];
34 return [
35 `rule "say why it goes ahead of the pipeline": this pull adds ${added.join(", ")} but no commit message has a "Why now: <reason>" line (15+ characters) or a "Pipeline: #N" line`,
36 ];
37 }
src/web/pages/bets.ts +4 −1
@@ -46,12 +46,13 @@ function useWords(ctx: Ctx, repo: Repo, b: Bet, now: Date): string {
4646
4747 function betRow(ctx: Ctx, repo: Repo, b: Bet, now: Date, owner: boolean): Html {
4848 // The plan — shares, what is left — is for those who administer; a reader sees names and states.
49 if (!owner) return row({ href: betHref(repo, b.id), title: html`${b.name}`, trail: badge(STATE_WORDS[b.state]) });
49 if (!owner) return row({ href: betHref(repo, b.id), title: html`${b.name}`, trail: badge(STATE_WORDS[b.state]), nav: true });
5050 const meta = [b.state === "backed" ? useWords(ctx, repo, b, now) : "", whoBacked(b), b.state === "stopped" ? b.leftLine : ""]
5151 .filter((x) => x !== "")
5252 .join(" · ");
5353 return row({
5454 href: betHref(repo, b.id),
55 nav: true,
5556 title: html`${b.name}`,
5657 meta: html`${meta}`,
5758 trail: badge(`${STATE_WORDS[b.state]} · ${b.appetite}% of the week`, { tone: b.state === "backed" ? "success" : b.state === "stopped" ? "attn" : "default" }),
@@ -93,6 +94,7 @@ function proposedRow(ctx: Ctx, repo: Repo, b: Bet, backed: readonly Bet[]): Html
9394 </details>`;
9495 return row({
9596 href: betHref(repo, b.id),
97 nav: true,
9698 title: html`${b.name}`,
9799 meta: html`${b.appetite}% of the week · next: ${why === null ? "back it or cut it" : "cut it"}`,
98100 trail: badge(STATE_WORDS[b.state]),
@@ -168,6 +170,7 @@ export function betPage(ctx: Ctx): Response {
168170 const state = scopeState(s, now);
169171 return row({
170172 href: `${repoBase(repo)}/issues/${s.number}`,
173 nav: true,
171174 title: html`#${s.number} ${s.title}`,
172175 trail: badge(state, { tone: state === "raised hand" ? "attn" : state === "done" ? "success" : "default" }),
173176 });
test/keys-bets.test.ts added +76
@@ -0,0 +1,76 @@
1 /** The bets page joins the shell's j/k row traversal (#10403): one data-nav per linked row, none on the empty page. */
2 import { afterAll, beforeAll, expect, test } from "bun:test";
3 import { mkdtemp, rm } from "node:fs/promises";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp, type App } from "../src/app.ts";
7 import { openIssue } from "../src/actions/issues.ts";
8 import { createRepo } from "../src/actions/repos.ts";
9 import { insertBet, markBacked } from "../src/core/bets.ts";
10 import { createUser } from "../src/core/users.ts";
11 import { serve, type Servers } from "../src/http/server.ts";
12
13 let dataDir: string;
14 let app: App;
15 let servers: Servers;
16 let cookie = "";
17 const NOW = new Date("2026-11-03T12:00:00Z");
18 const NAV = /class="row"[^>]*data-nav tabindex="-1"/;
19
20 beforeAll(async () => {
21 dataDir = await mkdtemp(join(tmpdir(), "forge-keys-bets-"));
22 app = createApp({ dataDir, port: 0, forgeRepo: "acme/forge" });
23 servers = await serve(app);
24 const made = await createUser(app.db, {
25 origin: "seed", trusted: true, username: "alice", email: "[email protected]",
26 password: "a-good-passphrase", adminIfFirst: true,
27 });
28 if (!made.ok) throw new Error(made.error);
29 const res = await fetch(`${servers.url}/signin`, {
30 method: "POST",
31 redirect: "manual",
32 headers: { "content-type": "application/x-www-form-urlencoded", origin: servers.url },
33 body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }),
34 });
35 cookie = (res.headers.get("set-cookie") ?? "").split(";")[0] ?? "";
36 });
37
38 afterAll(async () => {
39 await servers.stop();
40 app.close();
41 await rm(dataDir, { recursive: true, force: true });
42 });
43
44 const get = async (path: string) => (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text();
45 const navRows = (text: string) => text.split("<li").filter((li) => NAV.test(li));
46
47 test("each bet row, proposed or running, and each scope row is one data-nav row with a link", async () => {
48 const alice = app.db.query("SELECT id FROM user WHERE username = 'alice'").get() as { id: string };
49 const user = (await import("../src/core/users.ts")).getUserById(app.db, alice.id)!;
50 const made = await createRepo(app, user, { name: "tagged", visibility: "public" });
51 if (!made.ok) throw new Error(String(made.error));
52 const repo = made.value;
53 const issue = openIssue(app, user, repo, { title: "Tag a note" });
54 if (!issue.ok) throw new Error(String(issue.error));
55 insertBet(app.db, { repoId: repo.id, name: "Proposed one", journeys: "j", appetite: 10, leadId: null, issueIds: [] }, NOW);
56 const running = insertBet(app.db, { repoId: repo.id, name: "Running one", journeys: "j", appetite: 10, leadId: null, issueIds: [issue.value.id] }, NOW);
57 markBacked(app.db, running.id, 10, "owner", NOW);
58
59 const list = await get("/alice/tagged/bets");
60 const rows = navRows(list);
61 expect(rows.length).toBe(2);
62 for (const r of rows) expect(r).toMatch(/<a href="\/alice\/tagged\/bets\/[^"]+"/);
63
64 const one = navRows(await get(`/alice/tagged/bets/${running.id}`));
65 expect(one.length).toBe(1);
66 expect(one[0]).toContain('href="/alice/tagged/issues/');
67 });
68
69 test("the empty bets page draws no data-nav row", async () => {
70 const user = (await import("../src/core/users.ts")).getUserById(app.db, (app.db.query("SELECT id FROM user WHERE username = 'alice'").get() as { id: string }).id)!;
71 const made = await createRepo(app, user, { name: "empty", visibility: "public" });
72 if (!made.ok) throw new Error(String(made.error));
73 const text = await get("/alice/empty/bets");
74 expect(text).toContain("No bets yet.");
75 expect(text).not.toMatch(NAV);
76 });
test/why-now.test.ts deleted −28
@@ -1,28 +0,0 @@
1 /** Retired 2026-11-09 with the pipeline-first direction: the gate no longer asks (`scripts/gate.ts`); the pure rule keeps its tests until the module goes. */
2 import { expect, test } from "bun:test";
3 import { featuresAdded, whyNowProblems } from "../src/kernel/why_now.ts";
4
5 const add = (path: string) => ({ status: "A", path });
6
7 test("a new action, page or route is a feature; edits, tests and other files are not", () => {
8 expect(featuresAdded([add("src/actions/x.ts"), add("src/web/pages/y.ts"), add("src/http/api/z.ts")])).toHaveLength(3);
9 expect(featuresAdded([add("src/http/mcp/tools/x.ts"), add("src/tui/app/screen.ts"), add("src/http/api/v1/y.ts")])).toHaveLength(3);
10 expect(featuresAdded([{ status: "M", path: "src/actions/x.ts" }, add("test/x.test.ts"), add("src/core/x.ts")])).toEqual([]);
11 });
12
13 test("a feature with no answer to the direction is refused, naming the rule and the file", () => {
14 const [p] = whyNowProblems([add("src/actions/x.ts")], ["Add x\n\nIt does x."]);
15 expect(p).toContain("say why it goes ahead of the pipeline");
16 expect(p).toContain("src/actions/x.ts");
17 });
18
19 test("a Why now line or a Pipeline line answers it; a thin reason does not", () => {
20 const changes = [add("src/actions/x.ts")];
21 expect(whyNowProblems(changes, ["Add x\n\nWhy now: the owner asked for it in #1234 this week"])).toEqual([]);
22 expect(whyNowProblems(changes, ["Add x\n\nPipeline: #6534"])).toEqual([]);
23 expect(whyNowProblems(changes, ["Add x\n\nWhy now: soon"])).toHaveLength(1);
24 });
25
26 test("a pull that adds no feature is never asked", () => {
27 expect(whyNowProblems([add("test/a.test.ts")], ["Fix a"])).toEqual([]);
28 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs