Public: anyone can read this; the crew can change it.
One keymap (b): pulls, the review page and a repository's tabs take their keys from the map; a moved key says where it went for two weeks #16992
Check · Review · Land · Live done — Landed and live in production.
keymap-b → main 0 commits 3 threads · 3 unresolved
12 files
changed +305
−43
docs/features/keymap.md +5 −1
| @@ -13,6 +13,10 @@ The owner, after the bridge: "tying together all the keybinds is really what im | ||
| 13 | 13 | - **One source:** pages take a key with `keyOf(id)`, the bridge's script is handed the verbs from the map, `?` and Cmd/Ctrl K list what a page carries, and the shell's own keys are held to the map's moves. `test/keymap.test.ts` refuses a key literal outside the map, one key with two meanings on one kind of thing, and a key that fires while typing; the files not yet moved are listed there with the pull that moves them. |
| 14 | 14 | - **In the terminal** (`src/tui`) the same acts are meant to answer the same keys. Where the terminal still answers another key, the map says which and why (the run list's `x` stop, `a` queue again and `S` steer, which move with the runs pull). |
| 15 | 15 | |
| 16 | Coming, one pull each: the pull lists, the pull page and the review page (where `c` and `r` become `x` and `b`, and the verdicts `v a`, `v r`, `v c` become `a`, `b`, `x`, with a two-week hint on the old key); issues and runs (and the terminal's run list); /boards, /flow and Talk. | |
| 16 | - **Keys that moved** say where they went for two weeks, until 2026-12-15 (`OLD_KEYS` in the map), then the hints are gone: /review's `c` and `r` are now `x` (close) and `b` (send back), and a pull's verdicts `v a`, `v r`, `v c` are now `a` (approve), `b` (send back) and `c` (comment, the page's write key). Pressing the old key shows one line at the top of the page, "x is close now". | |
| 17 | - **A repository's tabs** are its own `g` jumps (`REPO_TABS`): `g c` code, `g i` issues, `g p` pulls, `g a` map, `g m` commits, `g b` branches, `g f` forks, `g r` runs, `g s` settings. Inside a repository `g f` and `g s` are its own, by design; the forge-wide Front page and Settings are a step away through `:` and Cmd/Ctrl K. A file's Propose a change is `e`. | |
| 18 | - **A quick second key** finds its button: `j` then `m` within a second merges, as `m` alone does (never after `g`, whose letter is a jump). | |
| 19 | ||
| 20 | Coming, one pull each: issues and runs (and the terminal's run list, where `x`, `a` and `S` become `s`, `r` and `i`); /boards, /flow and Talk. | |
| 17 | 21 | |
| 18 | 22 | Proof: `test/keymap.test.ts`, `test/bridge.test.ts`. |
scripts/unused-exports-allow.json +1
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | "src/cloud/ovh_sign.ts resetOvhClock", |
| 28 | 28 | "src/core/accounts.ts edgeOnlyAccounts", |
| 29 | 29 | "src/core/capacity.ts provideCpusForTest", |
| 30 | "src/web/keymap.ts provideOldKeysClockForTest", | |
| 30 | 31 | "src/core/credit.ts clearCreditCache", |
| 31 | 32 | "src/core/device_grants.ts grantedSlugs", |
| 32 | 33 | "src/core/feed_chips.ts noChips", |
src/web/client.ts +24 −1
| @@ -1549,6 +1549,23 @@ const shellCore = /* js */ ` | ||
| 1549 | 1549 | }); |
| 1550 | 1550 | }); |
| 1551 | 1551 | |
| 1552 | // One line at the top of the page that says something about a key (a key that moved: "x is close | |
| 1553 | // now"), in the flash's own classes; the next key takes it away. | |
| 1554 | function sayKey(text) { | |
| 1555 | var main = doc.getElementById('main'); | |
| 1556 | if (!main) return; | |
| 1557 | var old = main.querySelector('.toast[data-key-says]'); | |
| 1558 | if (old) old.remove(); | |
| 1559 | var t = doc.createElement('div'); | |
| 1560 | t.className = 'toast'; t.setAttribute('data-key-says', ''); t.setAttribute('role', 'status'); | |
| 1561 | var b = doc.createElement('div'); | |
| 1562 | b.className = 'toast-body'; b.textContent = text; | |
| 1563 | t.appendChild(b); | |
| 1564 | main.insertBefore(t, main.firstChild); | |
| 1565 | } | |
| 1566 | window.forgeSay = sayKey; | |
| 1567 | doc.addEventListener('keydown', function () { var old = doc.querySelector('.toast[data-key-says]'); if (old) old.remove(); }, true); | |
| 1568 | ||
| 1552 | 1569 | // ---- keyboard: sequences from the DOM, so the help can never drift ---- |
| 1553 | 1570 | ${keyDecisionJs} |
| 1554 | 1571 | var seq = []; var last = 0; |
| @@ -1661,7 +1678,13 @@ const shellCore = /* js */ ` | ||
| 1661 | 1678 | seq.push(e.key); |
| 1662 | 1679 | if (seq.length > 2) seq.splice(0, seq.length - 2); |
| 1663 | 1680 | var joined = seq.join(' '); |
| 1664 | var target = doc.querySelector('[data-shortcut="' + (window.CSS && CSS.escape ? CSS.escape(joined) : joined) + '"]'); | |
| 1681 | var esc = function (k) { return window.CSS && CSS.escape ? CSS.escape(k) : k; }; | |
| 1682 | // A key that moved (keymap.ts OLD_KEYS, drawn only for two weeks) says where it went. | |
| 1683 | var was = doc.querySelector('[data-was="' + esc(joined) + '"]'); | |
| 1684 | if (was) { seq.length = 0; e.preventDefault(); sayKey(was.getAttribute('data-was-says') || ''); return; } | |
| 1685 | // The sequence first ("g h"), then the key alone, so a quick j then m still merges (never after | |
| 1686 | // a g, whose letter is a jump). | |
| 1687 | var target = doc.querySelector('[data-shortcut="' + esc(joined) + '"]') || (seq.length === 2 && seq[0] !== 'g' ? doc.querySelector('[data-shortcut="' + esc(e.key) + '"]') : null); | |
| 1665 | 1688 | if (target) { |
| 1666 | 1689 | seq.length = 0; e.preventDefault(); target.click(); |
| 1667 | 1690 | // A chord that picks a radio leaves the caret in that form's box: the |
src/web/keymap.ts +59 −1
| @@ -16,7 +16,7 @@ import { GO_PAGES } from "./go_pages.ts"; | ||
| 16 | 16 | const go = (href: string): string => `g ${GO_PAGES.find((p) => p.href === href)?.key ?? ""}`; |
| 17 | 17 | |
| 18 | 18 | /** What a key acts on: a verb means one thing per kind, and a move works anywhere. */ |
| 19 | export type KeyKind = "any" | "pull" | "issue" | "run" | "figure" | "card"; | |
| 19 | export type KeyKind = "any" | "pull" | "issue" | "run" | "figure" | "card" | "file"; | |
| 20 | 20 | |
| 21 | 21 | export interface KeyDef { |
| 22 | 22 | /** The `KeyboardEvent.key` it answers; a sequence is written with a space ("g h"). */ |
| @@ -90,8 +90,66 @@ export const VERBS = { | ||
| 90 | 90 | more: { key: "+", label: "More", what: "Turn the figure up", kinds: ["figure"] }, |
| 91 | 91 | set: { key: "Enter", label: "Set", what: "Set the figure to what it shows", kinds: ["figure"] }, |
| 92 | 92 | undo: { key: "z", label: "Undo", what: "Put back what was just done", kinds: ["any"] }, |
| 93 | edit: { key: "e", label: "Propose a change", what: "Propose a change to the file", kinds: ["file"] }, | |
| 93 | 94 | } as const satisfies Record<string, KeyDef>; |
| 94 | 95 | |
| 96 | /** | |
| 97 | * A repository's tabs, each a `g` jump on its pages. Two shadow a forge-wide jump there, by design: | |
| 98 | * inside a repository `g f` is its Forks and `g s` its Settings (go_pages.ts's Front page and | |
| 99 | * Settings stay a step away through `:` and Cmd/Ctrl K). | |
| 100 | */ | |
| 101 | export const REPO_TABS = { | |
| 102 | code: "g c", | |
| 103 | issues: "g i", | |
| 104 | pulls: "g p", | |
| 105 | map: "g a", | |
| 106 | commits: "g m", | |
| 107 | branches: "g b", | |
| 108 | forks: "g f", | |
| 109 | runs: "g r", | |
| 110 | settings: "g s", | |
| 111 | } as const; | |
| 112 | ||
| 113 | /** | |
| 114 | * Keys that moved when the map took over, and what they say now. For two weeks the old key shows a | |
| 115 | * one-line hint instead of doing nothing; after {@link OLD_KEYS_UNTIL} no page draws them and the | |
| 116 | * hints are gone. This list and its date are deleted then, not kept as an alias. | |
| 117 | */ | |
| 118 | export const OLD_KEYS_UNTIL = "2026-12-15T00:00:00Z"; | |
| 119 | export interface OldKey { | |
| 120 | /** Where it was: "pull" for the Files page's verdicts, "review" for /review's rows. */ | |
| 121 | readonly page: "pull" | "review"; | |
| 122 | readonly was: string; | |
| 123 | readonly now: KeyId; | |
| 124 | /** The word a person reads for what the key does there, when the map's label is not it. */ | |
| 125 | readonly word?: string; | |
| 126 | } | |
| 127 | export const OLD_KEYS: readonly OldKey[] = [ | |
| 128 | { page: "pull", was: "v a", now: "approve" }, | |
| 129 | { page: "pull", was: "v r", now: "sendBack" }, | |
| 130 | { page: "pull", was: "v c", now: "create", word: "comment" }, | |
| 131 | { page: "review", was: "c", now: "close" }, | |
| 132 | { page: "review", was: "r", now: "sendBack" }, | |
| 133 | ]; | |
| 134 | ||
| 135 | /** | |
| 136 | * The old keys still hinted at `now`, with the hint each says ("x closes now"); none after the | |
| 137 | * date. | |
| 138 | */ | |
| 139 | export function oldKeys(page: OldKey["page"], now: Date = oldKeysClock ?? new Date()): { was: string; key: string; says: string }[] { | |
| 140 | if (now.getTime() >= Date.parse(OLD_KEYS_UNTIL)) return []; | |
| 141 | return OLD_KEYS.filter((o) => o.page === page).map((o) => ({ was: o.was, key: keyOf(o.now), says: `${keyOf(o.now)} is ${o.word ?? KEYMAP[o.now].label.toLowerCase()} now` })); | |
| 142 | } | |
| 143 | ||
| 144 | let oldKeysClock: Date | undefined; | |
| 145 | /** | |
| 146 | * A test's clock for {@link oldKeys} on served pages, so a hint test means the same on any date; | |
| 147 | * undefined reads the clock again. | |
| 148 | */ | |
| 149 | export function provideOldKeysClockForTest(now: Date | undefined): void { | |
| 150 | oldKeysClock = now; | |
| 151 | } | |
| 152 | ||
| 95 | 153 | export const KEYMAP = { ...MOVES, ...VERBS } as const; |
| 96 | 154 | export type KeyId = keyof typeof KEYMAP; |
| 97 | 155 |
src/web/pages/pull.ts +12 −3
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | import { pullProposalAt } from "../../core/proposal_token.ts"; |
| 12 | import { keyOf, oldKeys } from "../keymap.ts"; | |
| 12 | 13 | import { returnTo, withReturn } from "../return_to.ts"; |
| 13 | 14 | import { pullRoster } from "../studio/pull_roster.ts"; |
| 14 | 15 | import { originCheckLead, originCheckOf } from "../../origins/pull-check.ts"; |
| @@ -927,6 +928,13 @@ function reviewCard(ctx: Ctx, repo: Repo, pull: Pull, action: string): Html { | ||
| 927 | 928 | if (pull.mergedAt !== null || pull.state === "closed") return html``; |
| 928 | 929 | // A team reviewer passes a verdict without write access (`canVerdict`); |
| 929 | 930 | // the merge box says they do not land it. |
| 931 | // The verdicts' old v chords, hinted for two weeks (keymap.ts OLD_KEYS): pressing one says the | |
| 932 | // new key. | |
| 933 | const was = new Map(oldKeys("pull").map((o) => [o.key, o])); | |
| 934 | const wasFor = (key: string) => { | |
| 935 | const o = was.get(key); | |
| 936 | return o === undefined ? null : html`data-was="${o.was}" data-was-says="${o.says}"`; | |
| 937 | }; | |
| 930 | 938 | const judge = canVerdict(ctx.app.db, repo, user); |
| 931 | 939 | const isAuthor = pull.authorId === user.id; |
| 932 | 940 | const options: { value: string; label: string; hint: string; key: string }[] = |
| @@ -941,20 +949,20 @@ function reviewCard(ctx: Ctx, repo: Repo, pull: Pull, action: string): Html { | ||
| 941 | 949 | hint: runsOnApproval |
| 942 | 950 | ? "This is good to merge — and its check and preview then run this code here, holding the repository owner's app token." |
| 943 | 951 | : "This is good to merge.", |
| 944 | key: "v a", | |
| 952 | key: keyOf("approve"), | |
| 945 | 953 | }); |
| 946 | 954 | if (judge) |
| 947 | 955 | options.push({ |
| 948 | 956 | value: "changes_requested", |
| 949 | 957 | label: "Request changes", |
| 950 | 958 | hint: "Blocks the merge until it is withdrawn.", |
| 951 | key: "v r", | |
| 959 | key: keyOf("sendBack"), | |
| 952 | 960 | }); |
| 953 | 961 | options.push({ |
| 954 | 962 | value: "commented", |
| 955 | 963 | label: "Comment", |
| 956 | 964 | hint: "A note on the change as a whole, with no verdict.", |
| 957 | key: "v c", | |
| 965 | key: keyOf("create"), | |
| 958 | 966 | }); |
| 959 | 967 | |
| 960 | 968 | return card( |
| @@ -969,6 +977,7 @@ function reviewCard(ctx: Ctx, repo: Repo, pull: Pull, action: string): Html { | ||
| 969 | 977 | name="state" |
| 970 | 978 | value="${option.value}" |
| 971 | 979 | data-shortcut="${option.key}" |
| 980 | ${wasFor(option.key)} | |
| 972 | 981 | title="${option.label}" |
| 973 | 982 | ${i === options.length - 1 ? raw("checked") : null} |
| 974 | 983 | /> |
src/web/pages/repo.ts +3 −2
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | import { reviewCard } from "./review.ts"; |
| 12 | import { keyOf } from "../keymap.ts"; | |
| 12 | 13 | import { DELETING_SAYS } from "../../core/repo_deleting.ts"; |
| 13 | 14 | import { downloadHeaders } from "../../drop/store.ts"; |
| 14 | 15 | import type { BlobForRender } from "../../git/read.ts"; |
| @@ -1208,7 +1209,7 @@ export function editAction(scope: RepoScope, ref: string, path: string): Html { | ||
| 1208 | 1209 | size: "sm", |
| 1209 | 1210 | variant: "outline", |
| 1210 | 1211 | icon: "fork", |
| 1211 | shortcut: "e", | |
| 1212 | shortcut: keyOf("edit"), | |
| 1212 | 1213 | title: `You cannot push to ${scope.propose.upstream} — this lands on your fork and opens a pull there`, |
| 1213 | 1214 | }); |
| 1214 | 1215 | } |
| @@ -1234,7 +1235,7 @@ export function editAction(scope: RepoScope, ref: string, path: string): Html { | ||
| 1234 | 1235 | size: "sm", |
| 1235 | 1236 | variant: "outline", |
| 1236 | 1237 | icon: "pencil", |
| 1237 | shortcut: "e", | |
| 1238 | shortcut: keyOf("edit"), | |
| 1238 | 1239 | }); |
| 1239 | 1240 | } |
| 1240 | 1241 |
src/web/repo_steps.ts +11 −10
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | import { mayReadRuns, workingNowCount } from "../actions/runs.ts"; |
| 10 | import { REPO_TABS } from "./keymap.ts"; | |
| 10 | 11 | import { appsRuntime } from "../apps/runtime.ts"; |
| 11 | 12 | import { knownSpec, warmSpec } from "../apps/api_spec.ts"; |
| 12 | 13 | import { getAppByRepo } from "../core/apps.ts"; |
| @@ -77,18 +78,18 @@ function work(ctx: Ctx, base: string, repo: Repo | undefined): Steps { | ||
| 77 | 78 | ...(studio |
| 78 | 79 | ? [ |
| 79 | 80 | { key: "app" as const, label: "Studio", href: base }, |
| 80 | { key: "code" as const, label: "Files", href: `${base}/files`, shortcut: "g c" }, | |
| 81 | { key: "code" as const, label: "Files", href: `${base}/files`, shortcut: REPO_TABS.code }, | |
| 81 | 82 | ] |
| 82 | : [{ key: "code" as const, label: "Code", href: base, shortcut: "g c" }]), | |
| 83 | : [{ key: "code" as const, label: "Code", href: base, shortcut: REPO_TABS.code }]), | |
| 83 | 84 | // Issues and pull requests are called that in every mode (#3241). |
| 84 | { key: "issues", label: "Issues", href: tellsHref(base), shortcut: "g i" }, | |
| 85 | { key: "pulls", label: "Pulls", href: changesHref(base), shortcut: "g p" }, | |
| 86 | { key: "map", label: "Map", href: `${base}/map`, shortcut: "g a" }, | |
| 85 | { key: "issues", label: "Issues", href: tellsHref(base), shortcut: REPO_TABS.issues }, | |
| 86 | { key: "pulls", label: "Pulls", href: changesHref(base), shortcut: REPO_TABS.pulls }, | |
| 87 | { key: "map", label: "Map", href: `${base}/map`, shortcut: REPO_TABS.map }, | |
| 87 | 88 | ...(studio |
| 88 | 89 | ? [] |
| 89 | 90 | : [ |
| 90 | { key: "commits" as const, label: "Commits", href: `${base}/commits`, shortcut: "g m" }, | |
| 91 | { key: "branches" as const, label: "Branches", href: `${base}/branches`, shortcut: "g b" }, | |
| 91 | { key: "commits" as const, label: "Commits", href: `${base}/commits`, shortcut: REPO_TABS.commits }, | |
| 92 | { key: "branches" as const, label: "Branches", href: `${base}/branches`, shortcut: REPO_TABS.branches }, | |
| 92 | 93 | ]), |
| 93 | 94 | ]; |
| 94 | 95 | if (repo !== undefined) { |
| @@ -100,7 +101,7 @@ function work(ctx: Ctx, base: string, repo: Repo | undefined): Steps { | ||
| 100 | 101 | key: "forks", |
| 101 | 102 | label: "Forks", |
| 102 | 103 | href: `${base}/forks`, |
| 103 | shortcut: "g f", | |
| 104 | shortcut: REPO_TABS.forks, | |
| 104 | 105 | ...(forks > 0 ? { count: forks } : {}), |
| 105 | 106 | }); |
| 106 | 107 | // The runs, for who may read them (a private app's are for those who may enter it). |
| @@ -111,7 +112,7 @@ function work(ctx: Ctx, base: string, repo: Repo | undefined): Steps { | ||
| 111 | 112 | key: "runs", |
| 112 | 113 | label: "Runs", |
| 113 | 114 | href: `${base}/runs`, |
| 114 | shortcut: "g r", | |
| 115 | shortcut: REPO_TABS.runs, | |
| 115 | 116 | ...(running > 0 ? { count: running } : {}), |
| 116 | 117 | }); |
| 117 | 118 | } |
| @@ -131,6 +132,6 @@ function work(ctx: Ctx, base: string, repo: Repo | undefined): Steps { | ||
| 131 | 132 | // How to open the terminal (the TUI over SSH), for whoever has keys. |
| 132 | 133 | if (ctx.auth.user !== undefined && sshCommand(ctx.app) !== undefined) |
| 133 | 134 | steps.push({ key: "none", label: "Terminal", href: "/settings/keys#terminal" }); |
| 134 | if (admin) steps.push({ key: "settings", label: "Settings", href: `${base}/settings`, shortcut: "g s" }); | |
| 135 | if (admin) steps.push({ key: "settings", label: "Settings", href: `${base}/settings`, shortcut: REPO_TABS.settings }); | |
| 135 | 136 | return { steps, admin, studio }; |
| 136 | 137 | } |
src/web/studio/review_page.ts +13 −9
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| 9 | import { keyOf, oldKeys } from "../keymap.ts"; | |
| 9 | 10 | import { previewEnv } from "../../apps/data.ts"; |
| 10 | 11 | import { recommendationsFor } from "../../core/pull_wait.ts"; |
| 11 | 12 | import { appsForRepos } from "../../core/apps.ts"; |
| @@ -41,22 +42,25 @@ function verdict(run: Run | undefined, headOid: string): Html { | ||
| 41 | 42 | } |
| 42 | 43 | |
| 43 | 44 | /** |
| 44 | * m / c / r act on the row the cursor is on (j / k, the shell's own); the | |
| 45 | * buttons are the forms' own, so a key is a click, never a second road. The | |
| 46 | * shell ignores keys typed in a box and so does this. Each key is also a | |
| 47 | * \`data-shortcut\` on the row's control, which is what the help lists. | |
| 45 | * The keymap's merge, close and send back (m / x / b) act on the row the cursor is on (j / k, the | |
| 46 | * shell's own); the buttons are the forms' own, so a key is a click, never a second road. The shell | |
| 47 | * ignores keys typed in a box and so does this. Each key is also a \`data-shortcut\` on the row's | |
| 48 | * control, which is what the help lists. The old c and r, for two weeks, say the new key instead. | |
| 48 | 49 | */ |
| 49 | const REVIEW_KEYS_JS = ` | |
| 50 | const reviewKeysJs = (old: readonly { was: string; says: string }[]): string => ` | |
| 51 | var VERBS = ${JSON.stringify({ [keyOf("merge")]: "merge", [keyOf("close")]: "close", [keyOf("sendBack")]: "changes" })}; | |
| 52 | var OLD = ${JSON.stringify(Object.fromEntries(old.map((o) => [o.was, o.says])))}; | |
| 50 | 53 | var rowOf = function () { var a = document.activeElement; return a && a.closest ? a.closest('li[data-ask]') : null; }; |
| 51 | 54 | document.addEventListener('keydown', function (e) { |
| 52 | 55 | var t = e.target; |
| 53 | 56 | if (e.metaKey || e.ctrlKey || e.altKey || (t && t.matches && t.matches('input, textarea, select, [contenteditable]'))) return; |
| 54 | 57 | if (t && t.closest && t.closest('dialog[open]')) return; |
| 55 | var verb = { m: 'merge', c: 'close', r: 'changes' }[e.key]; | |
| 58 | if (OLD[e.key] && rowOf()) { e.preventDefault(); e.stopImmediatePropagation(); if (window.forgeSay) window.forgeSay(OLD[e.key]); return; } | |
| 59 | var verb = VERBS[e.key]; | |
| 56 | 60 | var li = verb && rowOf(); |
| 57 | 61 | var f = li && li.querySelector('form[data-verb="' + verb + '"]'); |
| 58 | 62 | if (!f) return; |
| 59 | e.preventDefault(); e.stopPropagation(); | |
| 63 | e.preventDefault(); e.stopImmediatePropagation(); | |
| 60 | 64 | if (verb === 'changes') f.querySelector('textarea').focus(); |
| 61 | 65 | else f.querySelector('button').click(); |
| 62 | 66 | }, true); |
| @@ -161,8 +165,8 @@ export function reviewPage(ctx: Ctx): Response { | ||
| 161 | 165 | note: "When the crew needs a person, it shows up here.", |
| 162 | 166 | action: html`<a class="btn" href="/?waits=me">All that wait for you</a>`, |
| 163 | 167 | }) |
| 164 | : html`${listCard(rows)}<p class="small muted">Keys: j / k move, ${key("m", "Merge the focused row", "merge")}, ${key("c", "Close the focused row", "close")}, ${key("r", "Request changes on the focused row", "request changes")} · <a href="/?waits=me">All that wait for you, on the board</a></p>`}`; | |
| 165 | const response = page({ ctx, title: "Review", body, scriptJs: asks.length === 0 ? "" : REVIEW_KEYS_JS }); | |
| 168 | : html`${listCard(rows)}<p class="small muted">Keys: j / k move, ${key(keyOf("merge"), "Merge the focused row", "merge")}, ${key(keyOf("close"), "Close the focused row", "close")}, ${key(keyOf("sendBack"), "Request changes on the focused row", "request changes")} · <a href="/?waits=me">All that wait for you, on the board</a></p>`}`; | |
| 169 | const response = page({ ctx, title: "Review", body, scriptJs: asks.length === 0 ? "" : reviewKeysJs(oldKeys("review")) }); | |
| 166 | 170 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 167 | 171 | return response; |
| 168 | 172 | } |
test/keymap-shell.test.ts added +83
| @@ -0,0 +1,83 @@ | ||
| 1 | /** | |
| 2 | * The shell's keys, pressed in a browser (keymap.ts, client.ts): a key that moved says where it | |
| 3 | * went in one line and does nothing else; a quick second key still finds its single-key button (j | |
| 4 | * then m merges as m alone does), but never after g, whose letter is a jump. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, 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 { createApp, type App } from "../src/app.ts"; | |
| 11 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 12 | import { findChromium } from "../src/looks/capture.ts"; | |
| 13 | import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts"; | |
| 14 | import { quietLogs } from "./helpers/globals.ts"; | |
| 15 | ||
| 16 | quietLogs(); | |
| 17 | const found = findChromium(); | |
| 18 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | |
| 19 | const skip = chromium === undefined && (process.env["FORGE_CHECK"] ?? "") === ""; | |
| 20 | if (skip) console.log("SKIPPING: no chromium that starts on this machine, so the shell's keys are not pressed"); | |
| 21 | ||
| 22 | let dir: string; | |
| 23 | let app: App; | |
| 24 | let servers: Servers; | |
| 25 | beforeAll(async () => { | |
| 26 | dir = await mkdtemp(join(tmpdir(), "forge-keymap-shell-")); | |
| 27 | app = createApp({ dataDir: dir, port: 0 }); | |
| 28 | servers = await serve(app); | |
| 29 | }, 30_000); | |
| 30 | afterAll(async () => { | |
| 31 | servers.stop(); | |
| 32 | app.close(); | |
| 33 | await rm(dir, { recursive: true, force: true }); | |
| 34 | }); | |
| 35 | ||
| 36 | test.skipIf(skip)( | |
| 37 | "pressed: v then a says a is approve now and approves nothing; j then m merges; g then z is no z", | |
| 38 | async () => { | |
| 39 | if (chromium === undefined) | |
| 40 | throw new Error( | |
| 41 | "no Chromium starts in this check, so the shell's keys are not pressed: the check's image must carry one (FORGE_CHROMIUM)", | |
| 42 | ); | |
| 43 | const out = JSON.parse( | |
| 44 | await evaluateLoaded( | |
| 45 | chromium, | |
| 46 | `${servers.url}/explore`, | |
| 47 | { width: 1280, height: 900 }, | |
| 48 | [], | |
| 49 | `(async () => { | |
| 50 | const main = document.getElementById('main'); | |
| 51 | const pressed = []; | |
| 52 | for (const k of ['a', 'm', 'z']) { | |
| 53 | const b = document.createElement('button'); | |
| 54 | b.type = 'button'; b.setAttribute('data-shortcut', k); b.textContent = k; | |
| 55 | b.addEventListener('click', () => pressed.push(k)); | |
| 56 | main.appendChild(b); | |
| 57 | } | |
| 58 | const was = document.createElement('span'); | |
| 59 | was.setAttribute('data-was', 'v a'); was.setAttribute('data-was-says', 'a is approve now'); | |
| 60 | main.appendChild(was); | |
| 61 | const key = (k) => document.dispatchEvent(new KeyboardEvent('keydown', { key: k, bubbles: true, cancelable: true })); | |
| 62 | const said = () => document.querySelector('.toast[data-key-says]')?.textContent.trim() ?? null; | |
| 63 | const out = {}; | |
| 64 | key('v'); key('a'); | |
| 65 | out.hint = said(); out.afterVA = pressed.slice(); | |
| 66 | key('j'); out.gone = said(); | |
| 67 | key('m'); | |
| 68 | out.afterJM = pressed.slice(); | |
| 69 | key('g'); key('z'); | |
| 70 | out.afterGZ = pressed.slice(); | |
| 71 | return JSON.stringify(out); | |
| 72 | })()`, | |
| 73 | ), | |
| 74 | ) as { hint: string | null; afterVA: string[]; gone: string | null; afterJM: string[]; afterGZ: string[] }; | |
| 75 | expect(out.hint).toBe("a is approve now"); | |
| 76 | expect(out.afterVA).toEqual([]); | |
| 77 | // The next key takes the line away. | |
| 78 | expect(out.gone).toBeNull(); | |
| 79 | expect(out.afterJM).toEqual(["m"]); | |
| 80 | expect(out.afterGZ).toEqual(["m"]); | |
| 81 | }, | |
| 82 | 30_000, | |
| 83 | ); |
test/keymap.test.ts +32 −5
| @@ -8,7 +8,8 @@ import { expect, test } from "bun:test"; | ||
| 8 | 8 | import { readdirSync, readFileSync, statSync } from "node:fs"; |
| 9 | 9 | import { join, relative } from "node:path"; |
| 10 | 10 | import { decideKey } from "../src/web/key_decision.ts"; |
| 11 | import { KEYMAP, MOVES, VERBS, keyOf, type KeyDef, type KeyKind } from "../src/web/keymap.ts"; | |
| 11 | import { GO_PAGES } from "../src/web/go_pages.ts"; | |
| 12 | import { KEYMAP, MOVES, OLD_KEYS, OLD_KEYS_UNTIL, REPO_TABS, VERBS, keyOf, oldKeys, type KeyDef, type KeyKind } from "../src/web/keymap.ts"; | |
| 12 | 13 | import { bridgeJs } from "../src/web/bridge_client.ts"; |
| 13 | 14 | import { DISMISS_KEY, NEW_ISSUE_KEY } from "../src/web/script_keys.ts"; |
| 14 | 15 | |
| @@ -19,10 +20,6 @@ const ROOT = join(import.meta.dir, ".."); | ||
| 19 | 20 | * the map. This list only shrinks; a file here that no longer has a literal must leave it. |
| 20 | 21 | */ |
| 21 | 22 | const PENDING: Record<string, string> = { |
| 22 | "src/web/pages/pull.ts": "(b) pulls and the pull page: the verdicts v a, v r, v c become a, b, x", | |
| 23 | "src/web/studio/review_page.ts": "(b) pulls and the pull page: c and r become x and b", | |
| 24 | "src/web/repo_steps.ts": "(b) pulls and the pull page: the repository's g-letter tabs", | |
| 25 | "src/web/pages/repo.ts": "(b) pulls and the pull page: e to propose a change", | |
| 26 | 23 | "src/web/pages/explorer.ts": "(c) issues and runs: t finds a file here, which Tell the crew owns everywhere else", |
| 27 | 24 | }; |
| 28 | 25 | |
| @@ -77,6 +74,36 @@ test("one key, one meaning: no two verbs share a key on one kind of thing, and n | ||
| 77 | 74 | for (const [, d] of Object.entries(KEYMAP)) if ("terminal" in d) expect(d.terminal.reason.length).toBeGreaterThan(20); |
| 78 | 75 | }); |
| 79 | 76 | |
| 77 | test("a moved key says where it went for two weeks, then nothing: the date is in code, not an alias", () => { | |
| 78 | const before = new Date(Date.parse(OLD_KEYS_UNTIL) - 1); | |
| 79 | expect(oldKeys("pull", before)).toEqual([ | |
| 80 | { was: "v a", key: "a", says: "a is approve now" }, | |
| 81 | { was: "v r", key: "b", says: "b is send back now" }, | |
| 82 | { was: "v c", key: "c", says: "c is comment now" }, | |
| 83 | ]); | |
| 84 | expect(oldKeys("review", before).map((o) => [o.was, o.key])).toEqual([["c", "x"], ["r", "b"]]); | |
| 85 | expect(oldKeys("pull", new Date(OLD_KEYS_UNTIL))).toEqual([]); | |
| 86 | expect(oldKeys("review", new Date(Date.parse(OLD_KEYS_UNTIL) + 86_400_000))).toEqual([]); | |
| 87 | // Two weeks from the change, not a standing alias. | |
| 88 | expect(Date.parse(OLD_KEYS_UNTIL) - Date.parse("2026-12-01T00:00:00Z")).toBeLessThanOrEqual(15 * 86_400_000); | |
| 89 | // The verdicts' v chords are no key of the map's; /review's old c and r are, as write and queue | |
| 90 | // again. | |
| 91 | for (const o of OLD_KEYS.filter((k) => k.page === "pull")) expect(Object.values(KEYMAP).some((d) => d.key === o.was)).toBe(false); | |
| 92 | }); | |
| 93 | ||
| 94 | test("a repository's tabs are g jumps of their own, and shadow a forge-wide one only where the map says", () => { | |
| 95 | const tabs = Object.values(REPO_TABS); | |
| 96 | expect(new Set(tabs).size).toBe(tabs.length); | |
| 97 | const global = new Set(GO_PAGES.flatMap((p) => (p.key === undefined ? [] : [`g ${p.key}`]))); | |
| 98 | expect(tabs.filter((k) => global.has(k)).sort()).toEqual(["g f", "g s"]); | |
| 99 | }); | |
| 100 | ||
| 101 | test("the shell says where a moved key went, and a quick second key still finds its button", () => { | |
| 102 | const client = readFileSync(join(ROOT, "src/web/client.ts"), "utf8"); | |
| 103 | expect(client).toContain("doc.querySelector('[data-was=\"' + esc(joined) + '\"]')"); | |
| 104 | expect(client).toContain("seq.length === 2 && seq[0] !== 'g' ? doc.querySelector('[data-shortcut=\"' + esc(e.key) + '\"]')"); | |
| 105 | }); | |
| 106 | ||
| 80 | 107 | test("the g jumps the map names are go_pages.ts's", () => { |
| 81 | 108 | expect([keyOf("home"), keyOf("talk")]).toEqual(["g h", "g t"]); |
| 82 | 109 | }); |
test/review-act.test.ts +43 −3
| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | /** `/review` acts: Merge, Close, Request changes and Reply, each by form POST, then on to the next ask. */ |
| 2 | 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | import { OLD_KEYS_UNTIL, provideOldKeysClockForTest } from "../src/web/keymap.ts"; | |
| 4 | import { findChromium } from "../src/looks/capture.ts"; | |
| 5 | import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts"; | |
| 3 | 6 | import { mkdtempSync, rmSync } from "node:fs"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| 5 | 8 | import { join } from "node:path"; |
| @@ -118,7 +121,8 @@ test("each row offers the four actions as plain forms, and the keys are listed", | ||
| 118 | 121 | for (const verb of ["merge", "close", "changes", "reply"]) expect(page).toContain(`data-verb="${verb}"`); |
| 119 | 122 | expect(page).toContain('action="/review/act"'); |
| 120 | 123 | expect(page).toContain(`id="${anchorOf(n)}"`); |
| 121 | for (const k of ["m", "c", "r"]) expect(page).toContain(`data-shortcut="${k}"`); | |
| 124 | // The keymap's merge, close and send back (keymap.ts). | |
| 125 | for (const k of ["m", "x", "b"]) expect(page).toContain(`data-shortcut="${k}"`); | |
| 122 | 126 | await act({ number: String(n), verb: "close" }); |
| 123 | 127 | }); |
| 124 | 128 | |
| @@ -203,10 +207,46 @@ test("the key script ships only when there are asks, and sanitises the hash it f | ||
| 203 | 207 | const n = seeded("Keyed"); |
| 204 | 208 | const withAsks = await (await fetch(`${servers.url}/review`, { headers: { cookie } })).text(); |
| 205 | 209 | const asksAll = await withScripts(servers.url, withAsks); |
| 206 | expect(asksAll).toContain("m: 'merge'"); | |
| 210 | // The keys are the keymap's, handed as data. | |
| 211 | expect(asksAll).toContain('var VERBS = {"m":"merge","x":"close","b":"changes"};'); | |
| 212 | // For two weeks the old c and r say the new key, then the script carries none (keymap.ts | |
| 213 | // OLD_KEYS), with the clock pinned on either side of the date. | |
| 214 | provideOldKeysClockForTest(new Date(Date.parse(OLD_KEYS_UNTIL) - 86_400_000)); | |
| 215 | const hinted = await withScripts(servers.url, await (await fetch(`${servers.url}/review`, { headers: { cookie } })).text()); | |
| 216 | provideOldKeysClockForTest(new Date(OLD_KEYS_UNTIL)); | |
| 217 | const after = await withScripts(servers.url, await (await fetch(`${servers.url}/review`, { headers: { cookie } })).text()); | |
| 218 | provideOldKeysClockForTest(undefined); | |
| 219 | expect(hinted).toContain('var OLD = {"c":"x is close now","r":"b is send back now"};'); | |
| 220 | expect(after).toContain("var OLD = {};"); | |
| 207 | 221 | expect(asksAll).toContain("location.hash.replace(/[^#a-z0-9-]/g, '')"); |
| 208 | 222 | for (const a of orderedAsks(app.db, alice)) await act({ number: String(numberOf(a)), verb: "close" }); |
| 209 | 223 | expect(n).toBeGreaterThan(0); |
| 210 | 224 | const empty = await (await fetch(`${servers.url}/review`, { headers: { cookie } })).text(); |
| 211 | expect(await withScripts(servers.url, empty)).not.toContain("m: 'merge'"); | |
| 225 | expect(await withScripts(servers.url, empty)).not.toContain("var VERBS = "); | |
| 212 | 226 | }); |
| 227 | ||
| 228 | const found = findChromium(); | |
| 229 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | |
| 230 | const noBrowser = chromium === undefined && (process.env["FORGE_CHECK"] ?? "") === ""; | |
| 231 | if (noBrowser) console.log("SKIPPING: no chromium that starts on this machine, so /review's keys are not pressed"); | |
| 232 | ||
| 233 | test.skipIf(noBrowser)("in a browser, the old c on a focused row says x is close now, and the shell's own c (Write, else New issue) never runs", async () => { | |
| 234 | if (chromium === undefined) throw new Error("no Chromium starts in this check, so /review's keys are not pressed: the check's image must carry one (FORGE_CHROMIUM)"); | |
| 235 | seeded("Pressed"); | |
| 236 | provideOldKeysClockForTest(new Date(Date.parse(OLD_KEYS_UNTIL) - 86_400_000)); | |
| 237 | try { | |
| 238 | const [name, value] = cookie.split("=") as [string, string]; | |
| 239 | const out = JSON.parse(await evaluateLoaded(chromium, `${servers.url}/review`, { width: 1280, height: 900 }, [{ name, value }], `(async () => { | |
| 240 | const link = document.querySelector('li[data-ask] [data-nav]'); | |
| 241 | link.focus(); | |
| 242 | link.dispatchEvent(new KeyboardEvent('keydown', { key: 'c', bubbles: true, cancelable: true })); | |
| 243 | await new Promise((r) => requestAnimationFrame(r)); | |
| 244 | return JSON.stringify({ path: location.pathname, said: document.querySelector('.toast[data-key-says]')?.textContent.trim() ?? null, focus: document.activeElement === link }); | |
| 245 | })()`)) as { path: string; said: string | null; focus: boolean }; | |
| 246 | expect(out.said).toBe("x is close now"); | |
| 247 | expect(out.path).toBe("/review"); | |
| 248 | expect(out.focus).toBe(true); | |
| 249 | } finally { | |
| 250 | provideOldKeysClockForTest(undefined); | |
| 251 | } | |
| 252 | }, 30_000); |
test/web-ui.test.ts +19 −8
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 13 | import { OLD_KEYS_UNTIL, provideOldKeysClockForTest } from "../src/web/keymap.ts"; | |
| 13 | 14 | import { mkdtemp, rm, writeFile, mkdir } from "node:fs/promises"; |
| 14 | 15 | import { tmpdir } from "node:os"; |
| 15 | 16 | import { join } from "node:path"; |
| @@ -1008,22 +1009,32 @@ describe("web ui", () => { | ||
| 1008 | 1009 | expect(issue).not.toContain("close-reason"); |
| 1009 | 1010 | expect(issue).not.toContain("close-into"); |
| 1010 | 1011 | |
| 1011 | // The verdicts are `v` chords on the radios, and only the verdicts this | |
| 1012 | // person may pass: the author never sees `v a`, a reader only `v c`. | |
| 1012 | // The verdicts are the keymap's a, b and c on the radios, and only the verdicts this | |
| 1013 | // person may pass: the author never sees approve, a reader only comment. | |
| 1013 | 1014 | const change = `/mel/proj/pulls/${pullNumber}`; |
| 1014 | 1015 | const pull = `${change}/files`; |
| 1015 | 1016 | const asAuthor = await as(pull, owner); |
| 1016 | expect(asAuthor).not.toContain('data-shortcut="v a"'); | |
| 1017 | expect(asAuthor).not.toContain('value="approved"'); | |
| 1017 | 1018 | expect(asAuthor).toMatch( |
| 1018 | /<input[^>]*value="changes_requested"[^>]*data-shortcut="v r"[^>]*title="Request changes"/, | |
| 1019 | /<input[^>]*value="changes_requested"[^>]*data-shortcut="b"[^>]*title="Request changes"/, | |
| 1019 | 1020 | ); |
| 1020 | 1021 | expect(asAuthor).toMatch( |
| 1021 | /<input[^>]*value="commented"[^>]*data-shortcut="v c"[^>]*title="Comment"/, | |
| 1022 | /<input[^>]*value="commented"[^>]*data-shortcut="c"[^>]*title="Comment"/, | |
| 1022 | 1023 | ); |
| 1024 | // For two weeks the old chord says the new key (keymap.ts OLD_KEYS), then is gone: the clock is | |
| 1025 | // pinned on either side of the date, so this means the same on any day. | |
| 1026 | provideOldKeysClockForTest(new Date(Date.parse(OLD_KEYS_UNTIL) - 86_400_000)); | |
| 1027 | const hinted = await as(pull, owner); | |
| 1028 | provideOldKeysClockForTest(new Date(OLD_KEYS_UNTIL)); | |
| 1029 | const after = await as(pull, owner); | |
| 1030 | provideOldKeysClockForTest(undefined); | |
| 1031 | expect(hinted).toContain('data-was="v r" data-was-says="b is send back now"'); | |
| 1032 | expect(hinted).toContain('data-was="v c" data-was-says="c is comment now"'); | |
| 1033 | expect(after).not.toContain("data-was="); | |
| 1023 | 1034 | const asReader = await as(pull, stranger); |
| 1024 | expect(asReader).not.toContain('data-shortcut="v a"'); | |
| 1025 | expect(asReader).not.toContain('data-shortcut="v r"'); | |
| 1026 | expect(asReader).toContain('data-shortcut="v c"'); | |
| 1035 | expect(asReader).not.toContain('value="approved"'); | |
| 1036 | expect(asReader).not.toContain('value="changes_requested"'); | |
| 1037 | expect(asReader).toContain('data-shortcut="c"'); | |
| 1027 | 1038 | // Close, reopen and merge carry no key at all. |
| 1028 | 1039 | for (const html of [await as(change, owner), issue]) { |
| 1029 | 1040 | const state = html.slice( |
new above
offline
Principle 8, plain words: 'c is write now' reads as a map label. For the pull's comment verdict say 'c is comment now'.