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
scout/forge:scout/850-the-terminal-launcher-finds-every-reposi → main 1 commit fork
2 files
changed +48
−1
src/tui/screens/dashboard.ts +27 −1
| @@ -82,9 +82,14 @@ interface OnYouItem { | ||
| 82 | 82 | /** The `tab` order, whichever of these the frame had room for. */ |
| 83 | 83 | const ORDER: readonly PaneId[] = ["repos", "onyou", "machine"]; |
| 84 | 84 | |
| 85 | /** The page the launcher reads with; the listing clamps anything larger. */ | |
| 86 | const PAGE = 100; | |
| 87 | ||
| 85 | 88 | export function dashboardScreen(f: Session, ctx: Ctx): Screen { |
| 86 | 89 | let repos: Repo[] = []; |
| 87 | 90 | let all: Repo[] = []; |
| 91 | /** Every repository the viewer can see, read on the first keystroke of a filter. */ | |
| 92 | let everything: Repo[] | undefined; | |
| 88 | 93 | let pins: Pin[] = []; |
| 89 | 94 | let pinned = new Set<string>(); |
| 90 | 95 | let onYou: OnYouItem[] = []; |
| @@ -103,6 +108,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 103 | 108 | pins = f.user ? listPins(f.db, f.user.id) : []; |
| 104 | 109 | pinned = f.user ? pinnedRepoIds(f.db, f.user.id) : new Set<string>(); |
| 105 | 110 | all = listReposVisibleTo(f.db, f.user, { limit: 200 }); |
| 111 | everything = undefined; | |
| 106 | 112 | onYou = assignedToMe(); |
| 107 | 113 | // "Yours" is ownership plus the orgs you are on a team of; typing in the |
| 108 | 114 | // filter reaches every repository you can see. |
| @@ -141,10 +147,30 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 141 | 147 | }); |
| 142 | 148 | }; |
| 143 | 149 | |
| 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 | ||
| 144 | 170 | /** Yours with an empty filter; anything you can see once you type — |
| 145 | 171 | * the one way to find someone else's repository from here. */ |
| 146 | 172 | const shown = (): Repo[] => |
| 147 | (filter.query !== "" ? all : repos).filter((repo) => | |
| 173 | (filter.query !== "" ? visible() : repos).filter((repo) => | |
| 148 | 174 | filter.matches(`${repo.ownerName}/${repo.name} ${repo.description}`), |
| 149 | 175 | ); |
| 150 | 176 |
test/tui-apps.test.ts +21
| @@ -453,6 +453,27 @@ describe("terminal: apps, runs and the crew", () => { | ||
| 453 | 453 | } |
| 454 | 454 | }, 30_000); |
| 455 | 455 | |
| 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 | ||
| 456 | 477 | test("the removed screens are unreachable: no palette entry, no dashboard or account key", async () => { |
| 457 | 478 | const h = boot(forge, identityFor(alice)); |
| 458 | 479 | try { |
new above
offline