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

The terminal launcher finds every repository you can see, not only the first 200 #1003

Closed opened this in answer to
Closed without merging

scout/forge:scout/850-the-terminal-launcher-finds-every-reposi → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
2 files changed +48 −1
src/tui/screens/dashboard.ts +27 −1
@@ -82,9 +82,14 @@ interface OnYouItem {
8282 /** The `tab` order, whichever of these the frame had room for. */
8383 const ORDER: readonly PaneId[] = ["repos", "onyou", "machine"];
8484
85 /** The page the launcher reads with; the listing clamps anything larger. */
86 const PAGE = 100;
87
8588 export function dashboardScreen(f: Session, ctx: Ctx): Screen {
8689 let repos: Repo[] = [];
8790 let all: Repo[] = [];
91 /** Every repository the viewer can see, read on the first keystroke of a filter. */
92 let everything: Repo[] | undefined;
8893 let pins: Pin[] = [];
8994 let pinned = new Set<string>();
9095 let onYou: OnYouItem[] = [];
@@ -103,6 +108,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
103108 pins = f.user ? listPins(f.db, f.user.id) : [];
104109 pinned = f.user ? pinnedRepoIds(f.db, f.user.id) : new Set<string>();
105110 all = listReposVisibleTo(f.db, f.user, { limit: 200 });
111 everything = undefined;
106112 onYou = assignedToMe();
107113 // "Yours" is ownership plus the orgs you are on a team of; typing in the
108114 // filter reaches every repository you can see.
@@ -141,10 +147,30 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
141147 });
142148 };
143149
150 /**
151 * Every visible repository, paged with the listing's own cursor so a forge
152 * with more than one page loses no tail. Read once per reload, not per key.
153 */
154 const visible = (): Repo[] => {
155 if (everything !== undefined) return everything;
156 const out: Repo[] = [];
157 for (;;) {
158 const cursor = out.at(-1)?.id;
159 const page = listReposVisibleTo(f.db, f.user, {
160 limit: PAGE,
161 ...(cursor !== undefined ? { cursor } : {}),
162 });
163 out.push(...page);
164 if (page.length < PAGE) break;
165 }
166 everything = out;
167 return out;
168 };
169
144170 /** Yours with an empty filter; anything you can see once you type —
145171 * the one way to find someone else's repository from here. */
146172 const shown = (): Repo[] =>
147 (filter.query !== "" ? all : repos).filter((repo) =>
173 (filter.query !== "" ? visible() : repos).filter((repo) =>
148174 filter.matches(`${repo.ownerName}/${repo.name} ${repo.description}`),
149175 );
150176
test/tui-apps.test.ts +21
@@ -453,6 +453,27 @@ describe("terminal: apps, runs and the crew", () => {
453453 }
454454 }, 30_000);
455455
456 test("the launcher's filter reaches past the first 200 visible repositories", async () => {
457 const bob = getUserByName(forge.db, "bob")!;
458 // Oldest ids sort last, so the first-inserted is past the 200th shown.
459 const ins = forge.db.query(
460 "INSERT INTO repo (id, owner_id, name, visibility) VALUES (?1, ?2, ?3, 'public')",
461 );
462 for (let i = 0; i < 230; i++)
463 ins.run(`0000-bulk-${String(i).padStart(3, "0")}`, alice.id, i === 0 ? "deep-tail-lamp" : `bulk-${i}`);
464 const h = boot(forge, identityFor(bob));
465 try {
466 await h.until("On you");
467 expect(h.text()).not.toContain("deep-tail-lamp");
468 await h.press("/");
469 await h.type("deep-tail");
470 await h.until("alice/deep-tail-lamp");
471 } finally {
472 h.stop();
473 forge.db.query("DELETE FROM repo WHERE id LIKE '0000-bulk-%'").run();
474 }
475 }, 30_000);
476
456477 test("the removed screens are unreachable: no palette entry, no dashboard or account key", async () => {
457478 const h = boot(forge, identityFor(alice));
458479 try {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs