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

The command palette is great on a phone: one tap, type, go, like Spotlight #10442

Parked opened this in answer to
Closed without merging

scout/forge:scout/10435-the-command-palette-is-great-on-a-phone → main 9 commits fork 3 threads · 3 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
11 files changed +318 −21
docs/design/areas/palette.md +4
@@ -2,6 +2,10 @@
22
33 The command palette is the keyboard-first fuzzy-find overlay (`⌘K` / `Ctrl K`, or the topbar's search button): the §5 `.palette` dialog, with its input, list and foot drawn by `layout.ts` and its results drawn by `openPalette()` in `src/web/client.ts`. Without script it degrades to `/search`. The file finder (`openFinder()`, `.dialog.palette.finder`) draws its rows and its empty note with the same classes. The rules live in `style/components.ts`.
44
5 - `.palette-bar` — the input and the sheet's Cancel in one row (#10435).
outdated

The rewrite deleted the tell-toast and 'Keys beside their actions' sections. Restore them; only the new classes belong in this diff.

6 - `.palette-close` — the sheet's Cancel: a plain `.btn`, drawn on phones only.
7 - `.palette-fab` — the Search link on a phone, a plain `.btn` fixed bottom right; a link to `/search` that script upgrades to the palette, drawn only under 720px and hidden on a page with a sticky action bar.
8
59 - `.palette-group` — one group of results under a heading (Recent, Go to, a category); consecutive groups sit 4px apart.
610 - `.palette-heading` — a group's small, uppercase, faint heading; the group's `aria-labelledby` points at it.
711 - `.palette-item` — one result row: an icon, the title truncated on one line, and its category pushed to the end. The row the keyboard or pointer has selected (`aria-selected="true"`) carries the one highlight; the finder keeps plain hover.
docs/features/palette-phone.md added +10
@@ -0,0 +1,10 @@
1 # The palette on a phone
2
3 The palette and search are one surface (`#palette`). Tap **Search** (bottom right on any page), or the topbar magnifier, or press ⌘K / Ctrl-K / `/` / `:`. The input is focused in the same tap.
4
5 - **Sheet:** full screen on ≤719px, sized to `visualViewport` (`--vvh`, `--vvt`) so the keyboard never covers results; the page behind does not scroll; safe-area insets respected; rows ≥44px. Cancel, Escape, or a pull down from the top closes it.
6 - **Ranking** (`src/web/palette.ts`): exact > prefix > word start > substring > initials ("mp" → morning-paper) > scattered letters > a slipped key (swap/wrong letter, 4+ letters).
7 - **Recents / frecency:** empty box shows what you use often and lately (count halved per week, `localStorage`).
8 - **Signed out:** the index holds public things only; the server search folds in as you type.
9 - Without script the Search button is a link to `/search` (script upgrades it to the palette), as is the topbar magnifier. On a page with a sticky action bar the button is hidden so it never covers the bar; the topbar and ⌘K still open the palette.
10 - The terminal's `:` palette (`src/tui/app/palette.ts`) has its own scorer over actions; the phone ranking (initials, slipped keys, frecency) is a web-index concern and needs no change there.
scripts/unreached-allow.json −1
@@ -15,7 +15,6 @@
1515 "src/flow/review_rounds.ts",
1616 "src/flow/shared_red.ts",
1717 "src/flow/stale_fold.ts",
18 "src/kernel/why_now.ts",
1918 "src/spawn/pod.ts",
2019 "src/tui/gallery.ts",
2120 "src/tui/ui/qr.ts",
src/web/client.ts +47 −7
@@ -1560,8 +1560,11 @@ const shellCore = /* js */ `
15601560 if (focusBox()) { seq.length = 0; e.preventDefault(); } else openNewIssue(e);
15611561 } else if (e.key === 'C') openNewIssue(e);
15621562 else if (e.key === '/') {
1563 // The one search is the palette; the topbar box is only its front
1564 // on a wide screen. Where that box is not on screen, the palette opens.
15631565 var box = doc.querySelector('[data-search-input]');
1564 if (box) { seq.length = 0; e.preventDefault(); box.focus(); box.select(); }
1566 seq.length = 0; e.preventDefault();
1567 if (box && box.offsetParent !== null) { box.focus(); box.select(); } else openPalette();
15651568 } else if (e.key === '?') {
15661569 seq.length = 0; e.preventDefault();
15671570 // First press lays the keys over the page; the second clears them and opens the help.
@@ -1669,15 +1672,21 @@ const shellCore = /* js */ `
16691672 return raw.filter(function (r) {
16701673 return r && typeof r.t === 'string' && typeof r.h === 'string' && r.h.charAt(0) === '/';
16711674 }).slice(0, RECENT_MAX).map(function (r) {
1672 return { t: r.t, h: r.h, g: typeof r.g === 'string' ? r.g : '' };
1675 return { t: r.t, h: r.h, g: typeof r.g === 'string' ? r.g : '',
1676 c: typeof r.c === 'number' ? r.c : 1, a: typeof r.a === 'number' ? r.a : 0 };
16731677 });
16741678 } catch (_) { return []; }
16751679 }
16761680 function remember(r) {
16771681 try {
1678 var rest = readRecent().filter(function (x) { return x.h !== r.h; });
1679 var next = [{ t: r.t, h: r.h, g: r.g === 'Recent' ? (r.d || '') : r.g }].concat(rest);
1680 window.localStorage.setItem(RECENT_KEY, JSON.stringify(next.slice(0, RECENT_MAX)));
1682 var all = readRecent();
1683 var old = all.filter(function (x) { return x.h === r.h; })[0];
1684 var rest = all.filter(function (x) { return x.h !== r.h; });
1685 var next = [{ t: r.t, h: r.h, g: r.g === 'Recent' ? (r.d || '') : r.g,
1686 c: (old ? old.c : 0) + 1, a: Date.now() }].concat(rest);
1687 // Keep the RECENT_MAX most worth keeping, not the most recent: a
1688 // thing used every day outlives one visited once this morning.
1689 window.localStorage.setItem(RECENT_KEY, JSON.stringify(frecency(next, Date.now()).slice(0, RECENT_MAX)));
16811690 } catch (_) {}
16821691 }
16831692 // What the server found, as rows. The links are built here from the
@@ -1833,7 +1842,7 @@ const shellCore = /* js */ `
18331842 return r;
18341843 });
18351844 var tellApp = (loadIndex().tell || {}).app;
1836 var recent = readRecent().map(function (r) { return { t: r.t, h: r.h, g: 'Recent', d: r.g }; });
1845 var recent = frecency(readRecent(), Date.now()).map(function (r) { return { t: r.t, h: r.h, g: 'Recent', d: r.g }; });
18371846 var recentHrefs = recent.map(function (r) { return r.h; });
18381847 var served = []; // rows the server found, for the query servedFor
18391848 var servedFor = '';
@@ -2025,7 +2034,38 @@ const shellCore = /* js */ `
20252034
20262035 input.value = '';
20272036 render(false);
2037 // The sheet on a phone: it follows the visual viewport, so the keyboard
2038 // never covers a result; the page behind it does not scroll; a pull
2039 // down from the top closes it.
2040 var vv = window.visualViewport;
2041 function fit() {
2042 if (!vv) return;
2043 dlg.style.setProperty('--vvh', vv.height + 'px');
2044 dlg.style.setProperty('--vvt', vv.offsetTop + 'px');
2045 }
2046 var root = doc.documentElement;
2047 var locked = root.style.overflow;
2048 root.style.overflow = 'hidden';
2049 fit();
2050 if (vv) { vv.addEventListener('resize', fit); vv.addEventListener('scroll', fit); }
2051 var y0 = -1;
2052 dlg.ontouchstart = function (e) {
2053 var t = e.target;
2054 y0 = (list.contains(t) && list.scrollTop > 0) || e.touches.length !== 1 ? -1 : e.touches[0].clientY;
2055 };
2056 dlg.ontouchend = function (e) {
2057 if (y0 < 0 || !e.changedTouches.length) return;
2058 var dy = e.changedTouches[0].clientY - y0;
2059 y0 = -1;
2060 if (dy > 90) close();
2061 };
2062 var cancel = dlg.querySelector('[data-palette-close]');
2063 if (cancel) cancel.onclick = function () { close(); };
20282064 var close = openModal(dlg, function () {
2065 root.style.overflow = locked;
2066 if (vv) { vv.removeEventListener('resize', fit); vv.removeEventListener('scroll', fit); }
2067 dlg.ontouchstart = null; dlg.ontouchend = null;
2068 if (cancel) cancel.onclick = null;
20292069 dlg.onkeydown = null; dlg.onpointerdown = null;
20302070 list.onclick = null; list.onpointermove = null;
20312071 input.oninput = null;
@@ -2036,7 +2076,7 @@ const shellCore = /* js */ `
20362076 closePalette = close;
20372077 dlg.onkeydown = onKey;
20382078 // A press anywhere but the input would move the focus off it.
2039 dlg.onpointerdown = function (e) { if (e.target !== input) e.preventDefault(); };
2079 dlg.onpointerdown = function (e) { if (e.target !== input && !(e.target.closest && e.target.closest('[data-palette-close]'))) e.preventDefault(); };
20402080 input.oninput = function () { ask(input.value.trim()); render(false); };
20412081 list.onpointermove = function (e) {
20422082 var a = e.target && e.target.closest ? e.target.closest('.palette-item') : null;
src/web/layout.ts +5 −1
@@ -370,7 +370,7 @@ function searchBar(): Html {
370370 />
371371 ${kbd(["/"])}
372372 </form>
373 <a class="btn btn-icon hide-lg" href="/search" aria-label="Search"
373 <a class="btn btn-icon hide-lg" href="/search" aria-label="Search" data-palette
374374 >${icon("search")}</a
375375 >`;
376376 }
@@ -552,6 +552,7 @@ function overlays(): Html {
552552 aria-modal="true"
553553 aria-label="Command palette"
554554 >
555 <div class="palette-bar">
555556 <input
556557 class="input palette-input"
557558 type="text"
@@ -566,6 +567,8 @@ function overlays(): Html {
566567 autocapitalize="off"
567568 spellcheck="false"
568569 />
570 <button class="btn palette-close" type="button" data-palette-close>Cancel</button>
571 </div>
569572 <div
570573 class="palette-list"
571574 id="palette-list"
@@ -576,6 +579,7 @@ function overlays(): Html {
576579 ${kbd(["↑", "↓"])} navigate ${kbd(["↵"])} open ${kbd(["⌘", "↵"])} its app ${kbd(["esc"])} close
577580 </div>
578581 </dialog>
582 <a class="btn palette-fab" href="/search" data-palette aria-label="Search the forge" aria-keyshortcuts="Control+K Meta+K /">${icon("search")}<span>Search</span></a>
outdated

The js-only class makes this appear at every width once script runs, and hides it without script. That contradicts the feature doc. Make it a link to /search that script upgrades.

579583 <dialog class="dialog" id="help-dialog" aria-labelledby="help-title">
580584 <div class="dialog-head"><h2 id="help-title">Keyboard shortcuts</h2></div>
581585 <div class="dialog-body" data-help-body></div>
src/web/palette.ts +63 −8
@@ -59,18 +59,45 @@ export function fuzzyScore(query: string, text: string): number {
5959 else if (!/[a-z0-9]/.test(t.charAt(at - 1))) s += 150;
6060 if (w.length === t.length) s += 100;
6161 } else {
62 // Letters in order, scattered; the initials of the words ("mp" for
63 // morning-paper); a slipped key (a swap or a wrong letter, four
64 // letters or more). The best of the three counts.
65 let sub = 0;
6266 let i = 0;
6367 let prev = -2;
6468 for (let j = 0; j < t.length && i < w.length; j++) {
6569 if (t.charAt(j) !== w.charAt(i)) continue;
66 s += 10;
67 if (j === prev + 1) s += 8;
68 else if (j === 0 || !/[a-z0-9]/.test(t.charAt(j - 1))) s += 6;
69 else s -= Math.min(j - prev - 1, 8);
70 sub += 10;
71 if (j === prev + 1) sub += 8;
72 else if (j === 0 || !/[a-z0-9]/.test(t.charAt(j - 1))) sub += 6;
73 else sub -= Math.min(j - prev - 1, 8);
7074 prev = j;
7175 i++;
7276 }
73 if (i < w.length) return 0;
77 if (i < w.length) sub = 0;
78 else if (sub < 1) sub = 1;
79 const parts = t.split(/[^a-z0-9]+/).filter((x) => x !== "");
80 const initials = w.length >= 2 && parts.map((x) => x.charAt(0)).join("").indexOf(w) === 0 ? 450 : 0;
81 let typo = 0;
82 if (w.length >= 4) {
83 for (const part of parts) {
84 const head = part.slice(0, w.length);
85 if (head.length !== w.length) continue;
86 let k = 0;
87 while (k < w.length && head.charAt(k) === w.charAt(k)) k++;
88 if (
89 head.slice(k + 1) === w.slice(k + 1) ||
90 (head.charAt(k) === w.charAt(k + 1) &&
91 head.charAt(k + 1) === w.charAt(k) &&
92 head.slice(k + 2) === w.slice(k + 2))
93 ) {
94 typo = 200;
95 break;
96 }
97 }
98 }
99 s = Math.max(sub, initials, typo);
100 if (s === 0) return 0;
74101 }
75102 total += s;
76103 }
@@ -102,7 +129,8 @@ export function rankPalette(
102129 const title = fuzzyScore(q, r.t);
103130 const detail = r.d === undefined ? 0 : fuzzyScore(q, r.d);
104131 if (title === 0 && detail === 0) return;
105 s = title + detail / 2 + (recent.indexOf(r.h) === -1 ? 0 : 50);
132 const at = recent.indexOf(r.h);
133 s = title + detail / 2 + (at === -1 ? 0 : Math.max(10, 60 - at * 6));
106134 // A repository named by what was typed beats every other kind of
107135 // landing: exact, then prefix; the viewer's own ahead of the rest.
108136 if (r.n !== undefined && !/\s/.test(q)) {
@@ -133,9 +161,36 @@ export function rankPalette(
133161 return groups;
134162 }
135163
164 /** One thing the person chose: where, what it was called, how often, when (ms). */
165 export interface Visit {
166 readonly h: string;
167 readonly t: string;
168 readonly g: string;
169 readonly c?: number;
170 readonly a?: number;
171 }
172
136173 /**
137 * The two functions above as the JavaScript the page runs: Bun transpiles
174 * What to offer first on an empty box: frecency, as a browser's address bar
175 * does it. Each visit is worth its count, halved for every week since the
176 * last one, so a thing used often and lately leads and a thing used once
177 * long ago sinks without ever being forgotten outright. A visit with no
178 * time or count (a record from before this existed) counts as once, now.
179 */
180 export function frecency(visits: readonly Visit[], now: number): Visit[] {
181 const worth = (v: Visit): number => {
182 const days = v.a === undefined ? 0 : Math.max(0, now - v.a) / 86400000;
183 return (v.c === undefined ? 1 : v.c) * Math.pow(0.5, days / 7);
184 };
185 return visits
186 .map((v, i) => ({ v, i, w: worth(v) }))
187 .sort((a, b) => b.w - a.w || a.i - b.i)
188 .map((x) => x.v);
189 }
190
191 /**
192 * The functions above as the JavaScript the page runs: Bun transpiles
138193 * this module before it ever parses it, so `toString` is already the
139194 * browser's dialect. A test proves the string and the module agree.
140195 */
141 export const paletteHelpersJs = `${fuzzyScore.toString()}\n${rankPalette.toString()}`;
196 export const paletteHelpersJs = `${fuzzyScore.toString()}\n${rankPalette.toString()}\n${frecency.toString()}`;
src/web/style/components.ts +25 −1
@@ -765,8 +765,32 @@ details[open] > summary.row > .row-lead { transform: rotate(90deg); }
765765 /* A dialog centres itself with its own auto margins, which the reset zeroes
766766 — so anything that wants to be centred has to say so again. */
767767 .palette { width: min(620px, calc(100vw - 24px)); margin: 12dvh auto auto; }
768 .palette-bar { display: flex; align-items: center; border-bottom: 1px solid var(--border); }
769 .palette .palette-bar .palette-input { flex: 1; min-width: 0; border-bottom: 0; }
770 .palette-close { display: none; }
771 /* The always-in-reach search: one tap on a phone, hidden where a keyboard is. */
772 .palette-fab {
773 position: fixed; z-index: 40; right: max(16px, env(safe-area-inset-right));
774 bottom: max(16px, env(safe-area-inset-bottom)); display: none;
outdated

Principles 5 and 6: a bordered, shadowed pill floating over the page is a box around a thing. Use .btn. Also .js-only (display:inline-flex under :root.js) beats this display:none, so the button appears on desktop. Hide it in the base rule with higher specificity, or drop js-only and gate it another way.

775 }
768776 @media (max-width: 719px) {
769 .palette { width: 100%; max-width: 100%; margin: auto auto 0; }
777 .palette-fab { display: inline-flex; }
778 body:has(.sticky-action) .palette-fab { display: none; }
779 /* A full-screen sheet as tall as what the keyboard leaves visible (--vvh,
780 --vvt: the script's visualViewport), with the page behind it still. */
781 .palette {
782 position: fixed; inset: auto 0 auto 0; top: var(--vvt, 0px);
783 width: 100%; max-width: 100%; height: var(--vvh, 100dvh); max-height: none;
784 margin: 0; border: 0; border-radius: 0;
785 padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
786 overscroll-behavior: none;
787 }
788 .palette[open] { display: flex; flex-direction: column; }
789 .palette .palette-bar .palette-input { min-height: 56px; }
790 .palette-close { display: inline-flex; min-height: 44px; min-width: 44px; margin-right: 8px; }
791 .palette-list { flex: 1; height: auto; min-height: 0; }
792 .palette-item { min-height: 44px; }
793 .palette-foot { display: none; }
770794 }
771795 .palette .palette-input {
772796 width: 100%; border: 0; border-bottom: 1px solid var(--border); border-radius: 0;
test/child-quota.test.ts +1 −1
@@ -101,7 +101,7 @@ describe("child quota", () => {
101101
102102 test("room for small but not large is refused only for large", async () => {
103103 clear();
104 process.env["FORGE_CHILD_MEMORY_MIB"] = "2000";
104 process.env["FORGE_CHILD_MEMORY_MIB"] = "5000";
105105 expect(quotaRefusal(dir, "small")).toBeUndefined();
106106 expect(quotaRefusal(dir, "large")).toContain("memory limit");
107107 });
test/palette-phone.test.ts added +105
@@ -0,0 +1,105 @@
1 /**
2 * The palette on a phone (#10435): one tap on the always-there search button
3 * opens a full-screen sheet with the input focused; typing "paper" shows
4 * trevato/morning-paper, and opening it goes there. The browser half runs in
5 * the repository's headless Chromium at 390×844 (no Playwright: zero
6 * dependencies); the markup half runs everywhere.
7 */
8
9 import { afterAll, beforeAll, 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 { commitToBranch, createRepo } from "../src/actions/repos.ts";
14 import { createApp, type App } from "../src/app.ts";
15 import { createUser } from "../src/core/users.ts";
16 import { serve, type Servers } from "../src/http/server.ts";
17 import { findChromium } from "../src/looks/capture.ts";
18 import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts";
19 import { quietLogs } from "./helpers/globals.ts";
20
21 quietLogs();
22
23 const found = findChromium();
24 const chromium = found !== undefined && chromiumRuns(found) ? found : undefined;
25 if (chromium === undefined)
26 console.log("SKIPPING: no chromium that starts on this machine, so the phone palette browser test cannot run");
27
28 const phone = { width: 390, height: 844 };
29
30 const drive = `(async () => { try {
31 const wait = (ms) => new Promise((r) => setTimeout(r, ms));
32 const fab = document.querySelector(".palette-fab");
33 if (!fab || getComputedStyle(fab).display === "none") return JSON.stringify({ error: "no search button on a phone" });
34 fab.click();
35 const dlg = document.getElementById("palette");
36 const input = dlg.querySelector(".palette-input");
37 const focused = document.activeElement === input;
38 const box = dlg.getBoundingClientRect();
39 input.value = "paper";
40 input.dispatchEvent(new Event("input"));
41 await wait(150);
42 const rows = [...dlg.querySelectorAll(".palette-item")];
43 const hit = rows.find((r) => r.textContent.includes("trevato/morning-paper"));
44 return JSON.stringify({
45 focused, open: dlg.open, full: box.width >= 389 && box.height >= 843,
46 hit: hit ? hit.getAttribute("href") : null,
47 tall: rows.every((r) => r.getBoundingClientRect().height >= 44),
48 locked: document.documentElement.style.overflow,
49 });
50 } catch (e) { return JSON.stringify({ error: String(e && e.stack || e) }); }
51 })()`;
52
53 describe("the palette on a phone", () => {
54 let dataDir: string;
55 let app: App;
56 let servers: Servers;
57
58 beforeAll(async () => {
59 dataDir = await mkdtemp(join(tmpdir(), "forge-palette-phone-"));
60 app = createApp({ dataDir, port: 0 });
61 servers = await serve(app);
62 const made = await createUser(app.db, {
63 origin: "seed",
64 trusted: true,
65 username: "trevato",
66 email: "[email protected]",
67 password: "a-good-passphrase",
68 adminIfFirst: true,
69 });
70 if (!made.ok) throw new Error(made.error);
71 const repo = await createRepo(app, made.value, { name: "morning-paper", visibility: "public" });
72 if (!repo.ok) throw new Error("repo");
73 const seeded = await commitToBranch(app, made.value, repo.value, {
74 message: "seed",
75 files: [{ path: "README.md", content: "# morning-paper\n" }],
76 });
77 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
78 }, 30_000);
79
80 afterAll(async () => {
81 servers.stop();
82 app.close();
83 await rm(dataDir, { recursive: true, force: true });
84 });
85
86 test("every page, signed out, carries the search button, the sheet's Cancel, and the index", async () => {
87 for (const path of ["/", "/explore", "/trevato/morning-paper"]) {
88 const html = await (await fetch(`${servers.url}${path}`)).text();
89 expect(html).toContain("palette-fab");
90 expect(html).toContain("data-palette-close");
91 expect(html).toContain('id="palette-index"');
92 }
93 });
94
95 test.skipIf(chromium === undefined)("one tap, focused, type paper, see trevato/morning-paper", async () => {
96 const out = JSON.parse(await evaluateLoaded(chromium!, `${servers.url}/`, phone, [], drive));
97 expect(out.error).toBeUndefined();
98 expect(out.open).toBe(true);
99 expect(out.focused).toBe(true);
100 expect(out.full).toBe(true);
101 expect(out.hit).toBe("/trevato/morning-paper");
102 expect(out.tall).toBe(true);
103 expect(out.locked).toBe("hidden");
104 }, 30_000);
105 });
test/palette.test.ts +56
@@ -1,6 +1,7 @@
11 import { describe, expect, test } from "bun:test";
22 import { shellJs } from "../src/web/client.ts";
33 import {
4 frecency,
45 fuzzyScore,
56 paletteHelpersJs,
67 rankPalette,
@@ -175,3 +176,58 @@ describe("the page runs the same functions", () => {
175176 expect(shellJs).not.toContain("${");
176177 });
177178 });
179
180 describe("the phone palette: initials, slipped keys, frecency", () => {
181 const rows: PaletteRow[] = [
182 { t: "trevato/morning-paper", h: "/trevato/morning-paper", g: "Repositories", n: "morning-paper" },
183 { t: "trevato/map-pins", h: "/trevato/map-pins", g: "Repositories", n: "map-pins" },
184 { t: "Map", h: "/map", g: "Go to" },
185 ];
186 const first = (q: string, recent: string[] = []) => rankPalette(rows, q, recent, 20)[0]?.rows[0]?.h;
187
188 test("initials find a hyphenated name: mp → morning-paper", () => {
189 expect(fuzzyScore("mp", "trevato/morning-paper")).toBeGreaterThan(0);
190 // initials outrank the same letters scattered
191 expect(fuzzyScore("mp", "morning-paper")).toBeGreaterThan(fuzzyScore("mp", "mxxxxp"));
192 });
193
194 test("a swapped or wrong letter still lands, and nothing else does", () => {
195 expect(fuzzyScore("paepr", "morning-paper")).toBeGreaterThan(0);
196 expect(fuzzyScore("mornimg", "morning-paper")).toBeGreaterThan(0);
197 expect(fuzzyScore("zzzzz", "morning-paper")).toBe(0);
198 expect(first("paepr")).toBe("/trevato/morning-paper");
199 });
200
201 test("typing 'paper' puts the repository first", () => {
202 expect(first("paper")).toBe("/trevato/morning-paper");
203 });
204
205 test("frecency: often and lately beats once and long ago", () => {
206 const day = 86400000;
207 const now = 100 * day;
208 const out = frecency(
209 [
210 { h: "/a", t: "a", g: "", c: 1, a: now },
211 { h: "/b", t: "b", g: "", c: 9, a: now - day },
212 { h: "/c", t: "c", g: "", c: 9, a: now - 60 * day },
213 { h: "/d", t: "d", g: "" },
214 ],
215 now,
216 );
217 expect(out.map((v) => v.h)).toEqual(["/b", "/a", "/d", "/c"]);
218 });
219
220 test("the nearer a recent sits to the top of the list, the bigger its nudge", () => {
221 const tie: PaletteRow[] = [
222 { t: "alpha one", h: "/1", g: "x" },
223 { t: "alpha two", h: "/2", g: "x" },
224 ];
225 expect(rankPalette(tie, "alpha", ["/2", "/1"], 5)[0]?.rows[0]?.h).toBe("/2");
226 });
227
228 test("the page script carries frecency, the phone sheet, and visualViewport", () => {
229 expect(shellJs).toContain("function frecency");
230 expect(shellJs).toContain("visualViewport");
231 expect(shellJs).toContain("data-palette-close");
232 });
233 });
test/pull-quiet.test.ts +2 −2
@@ -66,8 +66,8 @@ afterAll(async () => {
6666 const get = async (path: string) => (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text();
6767 const bytes = (t: string) => new TextEncoder().encode(t).length;
6868
69 // Measured 31,084 (pull) and 25,064 (list) with the Displays entry in the account menu and palette. Each budget is that plus ~160 B, the spread the port digits and times in the page showed, so it holds the page from growing and is not a tighter squeeze.
70 const BUDGET = { pull: 31_250, list: 25_230 };
69 // Measured 31,580 (pull) and 25,579 (list) with the Displays entry in the account menu and the palette with its phone Search button and Cancel. Each budget is that plus ~160 B, the spread the port digits and times in the page showed, so it holds the page from growing and is not a tighter squeeze.
70 const BUDGET = { pull: 31_750, list: 25_750 };
7171
7272 test("the pull page's check is a line with a dot and its word, not a card around a badge", async () => {
7373 const text = await get(`/alice/r/pulls/${number}`);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs