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

The terminal's Adapter screen lists the last pull runs #10151

Closed opened this
Closed without merging

mason/forge:mason/10128-the-terminal-s-adapter-screen-lists-the → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
2 files changed +58 −3
src/tui/screens/adapter.ts +27 −3
@@ -7,6 +7,7 @@
77 */
88
99 import { adapterFactsOf, adapterRows, type AdapterFacts } from "../../apps/adapter_facts.ts";
10 import { pullRunLines, type PullRunLine } from "../../apps/pull.ts";
1011 import { getAppByRepo, type AppRecord } from "../../core/apps.ts";
1112 import { canSeeOwnerFacts, type Repo } from "../../core/repos.ts";
1213 import type { Ctx, Screen } from "../app/app.ts";
@@ -14,7 +15,8 @@ import type { Command } from "../app/palette.ts";
1415 import type { Session } from "../session.ts";
1516 import { style } from "../term/style.ts";
1617 import { truncate } from "../term/width.ts";
17 import { drawFacts } from "./common.ts";
18 import { binding } from "../app/keys.ts";
19 import { Scroll, drawFacts, drawLines } from "./common.ts";
1820
1921 const mayRead = (f: Session, repo: Repo): boolean => canSeeOwnerFacts(f.db, repo, f.user);
2022
@@ -31,13 +33,24 @@ export function adapterCommands(f: Session, ctx: Ctx, repo: Repo | undefined): C
3133 ];
3234 }
3335
36 /** One run as a line: when, state, the three counts, and a failed run's error. */
37 export function runText(run: PullRunLine): string {
38 const when = run.at.slice(0, 16).replace("T", " ");
39 const counts = `${run.written} written ${run.skipped} skipped ${run.failed} failed`;
40 const head = `${when} ${run.state.padEnd(6)} ${counts}`;
41 return run.error === null ? head : `${head} ${run.error}`;
42 }
43
3444 /** `facts` is the read; a test passes its own so the gate is checked without a git repository. */
3545 export function adapterScreen(
3646 f: Session,
3747 ctx: Ctx,
3848 repo: Repo,
3949 facts: (record: AppRecord) => Promise<AdapterFacts | undefined> = (record) => adapterFactsOf(f.app, record),
50 runsOf: (appId: string) => PullRunLine[] = (appId) => pullRunLines(f.db, appId),
4051 ): Screen {
52 const scroll = new Scroll();
53 let runs: PullRunLine[] = [];
4154 let rows: Array<[string, string]> | undefined;
4255 let loaded = false;
4356 const load = (): void => {
@@ -46,6 +59,7 @@ export function adapterScreen(
4659 loaded = true;
4760 return;
4861 }
62 runs = runsOf(record.id);
4963 void facts(record).then(
5064 (read) => {
5165 rows = read === undefined ? undefined : adapterRows(read);
@@ -61,7 +75,7 @@ export function adapterScreen(
6175 load();
6276 return {
6377 title: `${repo.ownerName}/${repo.name} — Adapter`,
64 keys: [],
78 keys: [binding(["j", "k"], "scroll runs")],
6579 render(area, s) {
6680 const c = ctx.theme.c;
6781 if (rows === undefined) {
@@ -70,7 +84,17 @@ export function adapterScreen(
7084 return;
7185 }
7286 drawFacts(s, area, c, rows);
87 const top = rows.length + 1;
88 if (top >= area.h) return;
89 const below = { ...area, y: area.y + top, h: area.h - top };
90 const lines = [[{ text: "Last pulls", style: style(c.mutedFg, c.bg) }]];
91 if (runs.length === 0) lines.push([{ text: "No pulls yet.", style: style(c.mutedFg, c.bg) }]);
92 for (const run of runs) {
93 const text = truncate(runText(run), Math.max(0, area.w - 1));
94 lines.push([{ text, style: style(run.state === "failed" ? c.fg : c.mutedFg, c.bg) }]);
95 }
96 drawLines(s, below, c, scroll, lines);
7397 },
74 key: () => false,
98 key: (e) => rows !== undefined && scroll.key(e, runs.length + 1),
7599 };
76100 }
test/adapter-tui.test.ts +31
@@ -107,3 +107,34 @@ test("a guest gets no entry, and the screen reads nothing", async () => {
107107 expect(seen.read).toBe(0);
108108 expect(seen.text).not.toContain("c-secret-9");
109109 });
110
111 const good = { id: "r1", at: "2026-11-09T10:19:00.000Z", durationMs: 40, state: "ok", error: null, written: 3, skipped: 2, failed: 1, cursor: "c1", repeat: false } as const;
112 const bad = { ...good, id: "r2", at: "2026-11-09T09:19:00.000Z", state: "failed", error: "the source answered 500", written: 0, skipped: 0, failed: 0, cursor: null } as const;
113
114 async function lookRuns(user: User, runs: Array<typeof good | typeof bad>) {
115 const terminal = headlessTerminal(100, 12);
116 const { app: tui, session } = createForgeApp(
117 app,
118 { sshUsername: user.username, remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user },
119 { terminal, exitHooks: false },
120 );
121 tui.start();
122 tui.ctx.push(adapterScreen(session, tui.ctx, repo, async () => facts, () => [...runs]));
123 await settleApp(tui);
124 await settleApp(tui);
125 const text = tui.screen.toText();
126 tui.stop?.();
127 return text;
128 }
129
130 test("the screen lists a good and a failed run below the facts", async () => {
131 const text = await lookRuns(olive, [good, bad]);
132 expect(text).toContain("Last pulls");
133 expect(text).toContain("2026-11-09 10:19 ok 3 written 2 skipped 1 failed");
134 expect(text).toContain("failed 0 written 0 skipped 0 failed the source answered 500");
135 });
136
137 test("with no runs it says so, and a stranger sees no runs", async () => {
138 expect(await lookRuns(olive, [])).toContain("No pulls yet.");
139 expect(await lookRuns(otto, [good])).not.toContain("Last pulls");
140 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs