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

Sentinel: shared:01m23vygyffx5hg2f5vm8r74sr:3o41r733sv is past its budget: trevato/forge: "windows on the terminal's subscriptions screen > moving the cursor redraws from memory: no query reache… #8240

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/8234-sentinel-shared-01m23vygyffx5hg2f5vm8r74 → main 2 commits fork 1 thread · 1 unresolved

  • Merged. scout/8234-sentinel-shared-01m23vygyffx5hg2f5vm8r74 was merged into main as a77c2e8.

Review

Sign in to review this change.
1 file changed +32 −6
test/tui-subscriptions-windows.test.ts +32 −6
@@ -144,25 +144,51 @@ describe("windows on the terminal's subscriptions screen", () => {
144144 expect(rest).toContain(`resets ${first.slice(first.indexOf("resets ") + "resets ".length)}`);
145145 });
146146
147 test("moving the cursor redraws from memory: no query reaches the database", async () => {
148 const h = await open();
147 /** Database calls made while `run` goes, counting only those with the screen's own frame on the stack. */
148 async function screenQueries(run: () => Promise<void>): Promise<number> {
149149 const db = forge.db as unknown as { query: (...a: unknown[]) => unknown; prepare: (...a: unknown[]) => unknown };
150150 const { query, prepare } = db;
151151 let calls = 0;
152 db.query = (...a) => (calls++, query.apply(forge.db, a));
153 db.prepare = (...a) => (calls++, prepare.apply(forge.db, a));
152 // Other timers in this process share the database, so a call counts only when
153 // screens/subscriptions is on its stack; the limit is raised so that frame is never cut off.
154 const ours = () => {
155 const limit = Error.stackTraceLimit;
156 Error.stackTraceLimit = 200;
outdated

Drop core/subscriptions|core/standing|core/usage from the regex. Timers and other actions call those modules too, so they leak into calls. Match only screens/subscriptions, and raise Error.stackTraceLimit around new Error() so the frame is not truncated.

157 const stack = new Error().stack ?? "";
158 Error.stackTraceLimit = limit;
159 return stack.includes("screens/subscriptions");
160 };
161 db.query = (...a) => (ours() && calls++, query.apply(forge.db, a));
162 db.prepare = (...a) => (ours() && calls++, prepare.apply(forge.db, a));
154163 try {
155 await h.press("j");
156 await h.press("k");
164 await run();
157165 } finally {
158166 db.query = query;
159167 db.prepare = prepare;
160168 }
169 return calls;
170 }
171
172 test("moving the cursor redraws from memory: no query reaches the database", async () => {
173 const h = await open();
174 const calls = await screenQueries(async () => {
175 await h.press("j");
176 await h.press("k");
177 });
161178 expect(calls).toBe(0);
162179 expect(h.text()).toContain("windows not seen yet");
163180 h.stop();
164181 });
165182
183 test("the query counter sees the screen's own reads (it is not vacuous)", async () => {
184 let h: Awaited<ReturnType<typeof open>> | undefined;
185 const calls = await screenQueries(async () => {
186 h = await open();
187 });
188 expect(calls).toBeGreaterThan(0);
189 h?.stop();
190 });
191
166192 test("an account with no window seen says so, whichever row the cursor is on", async () => {
167193 const h = await open();
168194 await h.press("g");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs