@ftrdotdev/pi-tui 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +225 -0
- package/README.md +5 -0
- package/package.json +18 -15
- package/src/activity-service.test.ts +97 -0
- package/src/activity.test.ts +1 -1
- package/src/activity.ts +38 -0
- package/src/chrome/budget.test.ts +345 -0
- package/src/chrome/budget.ts +220 -0
- package/src/chrome/declarations.ts +303 -0
- package/src/chrome/facts.test.ts +165 -0
- package/src/chrome/facts.ts +267 -0
- package/src/chrome/frame.ts +45 -0
- package/src/chrome/laws.test.ts +231 -0
- package/src/chrome/port.test.ts +164 -0
- package/src/chrome/port.ts +67 -0
- package/src/chrome/service-provider.test.ts +383 -0
- package/src/chrome/service-provider.ts +55 -0
- package/src/commands/git-execution.test.ts +5 -2
- package/src/commands/git-execution.ts +27 -15
- package/src/commands/git-status.test.ts +47 -15
- package/src/commands/git-status.ts +83 -31
- package/src/components/bordered-box.test.ts +12 -15
- package/src/components/bordered-box.ts +11 -7
- package/src/components/define-component.ts +1 -1
- package/src/components/index.ts +7 -0
- package/src/components/row-list.test.ts +310 -0
- package/src/components/row-list.ts +272 -0
- package/src/config.test.ts +118 -3
- package/src/config.ts +50 -42
- package/src/frame/box-frame.test.ts +53 -7
- package/src/harness-policy.test.ts +47 -0
- package/src/icons.test.ts +19 -0
- package/src/icons.ts +50 -31
- package/src/index.test.ts +135 -0
- package/src/index.ts +118 -119
- package/src/layers.test.ts +94 -0
- package/src/layers.ts +92 -0
- package/src/runtime-service.test.ts +218 -0
- package/src/runtime-service.ts +103 -0
- package/src/runtime.test.ts +165 -66
- package/src/runtime.ts +127 -93
- package/src/session-lifecycle-service.test.ts +95 -0
- package/src/session-lifecycle.test.ts +77 -0
- package/src/session-lifecycle.ts +21 -0
- package/src/state.test.ts +132 -3
- package/src/state.ts +43 -13
- package/src/telemetry-service.test.ts +250 -0
- package/src/telemetry.test.ts +322 -0
- package/src/telemetry.ts +130 -23
- package/src/ui/editor-tint.test.ts +58 -45
- package/src/ui/editor-tint.ts +1 -1
- package/src/ui/editor.ts +117 -53
- package/src/ui/footer.test.ts +349 -120
- package/src/ui/footer.ts +147 -124
- package/src/ui/header.test.ts +203 -223
- package/src/ui/header.ts +32 -96
- package/src/ui/preview.test.ts +73 -70
- package/src/ui/preview.ts +48 -33
- package/src/ui/render-helpers.test.ts +82 -13
- package/src/ui/render-helpers.ts +110 -122
- package/src/ui/settings-command.test.ts +70 -11
- package/src/ui/settings-command.ts +30 -45
- package/src/ui/theme-color.test.ts +4 -3
- package/src/usage-totals-service.test.ts +230 -0
- package/src/usage-totals-service.ts +59 -0
- package/src/utils.test.ts +46 -50
- package/src/utils.ts +41 -239
- package/src/vim/editor-host.test.ts +201 -75
- package/src/vim/editor-state.ts +2 -2
- package/src/vim/mode-indicator.test.ts +6 -5
- package/src/vim/mode-indicator.ts +13 -9
- package/src/vim/selection-render.ts +8 -4
- package/src/vim/text-model.test.ts +52 -14
- package/src/vim/text-model.ts +1 -1
- package/src/vim/vim-router.test.ts +3 -0
- package/src/vim/vim-router.ts +1 -1
package/src/ui/footer.test.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
// Each test is its own entry point: it builds a fresh layer for one scenario and
|
|
2
|
+
// runs its effects inside it, so providing there is the pattern the rule allows.
|
|
3
|
+
/* oxlint-disable effecttsgo/strict-effect-provide */
|
|
4
|
+
import { afterEach, assert, beforeEach, it, vi } from "@effect/vitest";
|
|
5
|
+
import { themeDouble } from "@ftrdotdev/pi-test-kit";
|
|
6
|
+
import { footerCtxDouble, stubChromePort } from "../../test-support/doubles.ts";
|
|
2
7
|
import { Effect } from "effect";
|
|
3
8
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
4
9
|
import { GitStatus } from "../commands/git-status.ts";
|
|
@@ -6,7 +11,16 @@ import type { TuiConfig } from "../config.ts";
|
|
|
6
11
|
import type { IconGlyphs } from "../icons.ts";
|
|
7
12
|
import { ActivityTracker, type ActivityEvent } from "../activity.ts";
|
|
8
13
|
import type { FooterState } from "../state.ts";
|
|
9
|
-
import {
|
|
14
|
+
import { getUsageTotals, invalidateUsageCache } from "../state.ts";
|
|
15
|
+
import {
|
|
16
|
+
FooterRenderService,
|
|
17
|
+
installFooter,
|
|
18
|
+
planFooterLine1,
|
|
19
|
+
planFooterLine2,
|
|
20
|
+
type FooterHooks,
|
|
21
|
+
} from "./footer.ts";
|
|
22
|
+
import { composeLine } from "../chrome/budget.ts";
|
|
23
|
+
import { makePlainChromeProvider, type ChromeFacts, type ChromePort } from "../chrome/port.ts";
|
|
10
24
|
import { renderTimerSegment } from "./render-helpers.ts";
|
|
11
25
|
|
|
12
26
|
// ---------------------------------------------------------------------------
|
|
@@ -21,14 +35,20 @@ import { renderTimerSegment } from "./render-helpers.ts";
|
|
|
21
35
|
// argument and ctx.ui.theme (the recorded identity assumption)
|
|
22
36
|
// ---------------------------------------------------------------------------
|
|
23
37
|
|
|
24
|
-
const plainTheme = {
|
|
25
|
-
fg: (_color: string, text: string) => text,
|
|
26
|
-
bg: (_color: string, text: string) => text,
|
|
27
|
-
bold: (text: string) => `*${text}*`,
|
|
28
|
-
} as unknown as Theme;
|
|
38
|
+
const plainTheme = themeDouble({ bold: (text) => `*${text}*` });
|
|
29
39
|
|
|
30
40
|
const WIDTHS = [30, 40, 60, 80, 100, 120];
|
|
31
41
|
|
|
42
|
+
/** The instant a test that consults the clock installs before it renders. */
|
|
43
|
+
const FIXED_CLOCK = Date.parse("2021-03-04T05:06:07.000Z");
|
|
44
|
+
|
|
45
|
+
// Timers are the runner's job: the fragment carries no clock policy, so this
|
|
46
|
+
// file puts the real clock back after any test that faked it.
|
|
47
|
+
afterEach(() => vi.useRealTimers());
|
|
48
|
+
|
|
49
|
+
// The usage cache is a single module slot, so every test starts empty.
|
|
50
|
+
beforeEach(() => invalidateUsageCache());
|
|
51
|
+
|
|
32
52
|
const state: FooterState = {
|
|
33
53
|
git: GitStatus.make({
|
|
34
54
|
branch: "feature/refactor",
|
|
@@ -156,18 +176,19 @@ const ctxFixture = {
|
|
|
156
176
|
// Fake ctx.ui.setFooter captures the factory; the SAME identity theme
|
|
157
177
|
// instance is passed as both the factory theme argument and ctx.ui.theme
|
|
158
178
|
// (the recorded identity assumption).
|
|
159
|
-
const makeMountCtx = (captureFactory: (f: unknown) => void) =>
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
179
|
+
const makeMountCtx = (captureFactory: (f: unknown) => void) =>
|
|
180
|
+
footerCtxDouble({
|
|
181
|
+
model: ctxFixture.model,
|
|
182
|
+
cwd: ctxFixture.cwd,
|
|
183
|
+
getContextUsage: ctxFixture.getContextUsage,
|
|
184
|
+
sessionManager: ctxFixture.sessionManager,
|
|
185
|
+
ui: {
|
|
186
|
+
theme: plainTheme,
|
|
187
|
+
setFooter(factory: unknown) {
|
|
188
|
+
captureFactory(factory);
|
|
189
|
+
},
|
|
168
190
|
},
|
|
169
|
-
}
|
|
170
|
-
});
|
|
191
|
+
});
|
|
171
192
|
|
|
172
193
|
const runMount = (): { component: { render(width: number): string[] } } => {
|
|
173
194
|
let capturedFactory: ((tui: unknown, theme: Theme, data: unknown) => unknown) | undefined;
|
|
@@ -178,7 +199,16 @@ const runMount = (): { component: { render(width: number): string[] } } => {
|
|
|
178
199
|
setRequestRender: () => {},
|
|
179
200
|
scheduleGitRefresh: () => {},
|
|
180
201
|
};
|
|
181
|
-
const cleanup = installFooter(
|
|
202
|
+
const cleanup = installFooter(
|
|
203
|
+
mountCtx,
|
|
204
|
+
makePlainChromeProvider(mountCtx, {
|
|
205
|
+
state: getState,
|
|
206
|
+
config: getConfig,
|
|
207
|
+
model: getModelMeta,
|
|
208
|
+
extensionStatuses: () => new Map(),
|
|
209
|
+
}),
|
|
210
|
+
hooks,
|
|
211
|
+
);
|
|
182
212
|
void cleanup;
|
|
183
213
|
const component = capturedFactory!(undefined, plainTheme, footerData()) as {
|
|
184
214
|
render(width: number): string[];
|
|
@@ -199,34 +229,34 @@ const footerData = () => ({
|
|
|
199
229
|
|
|
200
230
|
const FOOTER_EXPECTED: Record<string, string[]> = {
|
|
201
231
|
30: [
|
|
202
|
-
"
|
|
203
|
-
"
|
|
204
|
-
"
|
|
232
|
+
" ◧ 100k/200k",
|
|
233
|
+
"◈ Anthropic · claude-sonnet\u001b[0m...\u001b[0m",
|
|
234
|
+
"❖ 2 errors | running",
|
|
205
235
|
],
|
|
206
236
|
40: [
|
|
207
|
-
"
|
|
208
|
-
"
|
|
209
|
-
"
|
|
237
|
+
"⌂ /.../pi-mono ⎇ feature/\u001b[0m...\u001b[0m ◧ 100k/200k",
|
|
238
|
+
"◈ Anthropic · claude-sonnet-4-0 ↑ 2.4\u001b[0m...\u001b[0m",
|
|
239
|
+
"❖ 2 errors | running",
|
|
210
240
|
],
|
|
211
241
|
60: [
|
|
212
|
-
"
|
|
213
|
-
"
|
|
214
|
-
"
|
|
242
|
+
"⌂ /workspace/pi-mono ⎇ feature/refactor [●3 ▲\u001b[0m...\u001b[0m ◧ 100k/200k",
|
|
243
|
+
"◈ Anthropic · claude-sonnet-4-0 ↑ 2.4k | ↓ 800 | $ 0.084",
|
|
244
|
+
"❖ 2 errors | running",
|
|
215
245
|
],
|
|
216
246
|
80: [
|
|
217
|
-
"
|
|
218
|
-
"
|
|
219
|
-
"
|
|
247
|
+
"⌂ /workspace/pi-mono ⎇ feature/refactor [●3 ▲2 ?1 ▣1 ⋔2/1] ◧ 100k/200k",
|
|
248
|
+
"◈ Anthropic · claude-sonnet-4-0 · ✳ medium ↑ 2.4k | ↓ 800 | $ 0.084",
|
|
249
|
+
"❖ 2 errors | running",
|
|
220
250
|
],
|
|
221
251
|
100: [
|
|
222
|
-
"
|
|
223
|
-
"
|
|
224
|
-
"
|
|
252
|
+
"⌂ /workspace/pi-mono ⎇ feature/refactor [●3 ▲2 ?1 ▣1 ⋔2/1] ◧ 100k/200k",
|
|
253
|
+
"◈ Anthropic · claude-sonnet-4-0 · ✳ medium ↑ 2.4k | ↓ 800 | $ 0.084",
|
|
254
|
+
"❖ 2 errors | running",
|
|
225
255
|
],
|
|
226
256
|
120: [
|
|
227
|
-
"
|
|
228
|
-
"
|
|
229
|
-
"
|
|
257
|
+
"⌂ /workspace/pi-mono ⎇ feature/refactor [●3 ▲2 ?1 ▣1 ⋔2/1] ◧ 100k/200k",
|
|
258
|
+
"◈ Anthropic · claude-sonnet-4-0 · ✳ medium ↑ 2.4k | ↓ 800 | $ 0.084",
|
|
259
|
+
"❖ 2 errors | running",
|
|
230
260
|
],
|
|
231
261
|
};
|
|
232
262
|
|
|
@@ -274,7 +304,16 @@ it("installFooter registers the request-render hook and branch subscriber at mou
|
|
|
274
304
|
},
|
|
275
305
|
};
|
|
276
306
|
|
|
277
|
-
const cleanup = installFooter(
|
|
307
|
+
const cleanup = installFooter(
|
|
308
|
+
mountCtx,
|
|
309
|
+
makePlainChromeProvider(mountCtx, {
|
|
310
|
+
state: getState,
|
|
311
|
+
config: getConfig,
|
|
312
|
+
model: getModelMeta,
|
|
313
|
+
extensionStatuses: () => new Map(),
|
|
314
|
+
}),
|
|
315
|
+
hooks,
|
|
316
|
+
);
|
|
278
317
|
void cleanup;
|
|
279
318
|
const tui = { requestRender: () => void renders++ };
|
|
280
319
|
const component = capturedFactory!(tui, plainTheme, data) as { dispose: () => void };
|
|
@@ -304,59 +343,219 @@ it("installFooter registers the request-render hook and branch subscriber at mou
|
|
|
304
343
|
// ---------------------------------------------------------------------------
|
|
305
344
|
|
|
306
345
|
// The context the service reads: same fixture, no setFooter seam involved.
|
|
307
|
-
const svcCtx = {
|
|
346
|
+
const svcCtx = footerCtxDouble({
|
|
308
347
|
model: ctxFixture.model,
|
|
309
348
|
cwd: ctxFixture.cwd,
|
|
310
349
|
getContextUsage: ctxFixture.getContextUsage,
|
|
311
350
|
sessionManager: ctxFixture.sessionManager,
|
|
312
351
|
ui: { theme: plainTheme },
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
const footerLayer = (getConfigOverride: () => TuiConfig = getConfig) =>
|
|
355
|
+
FooterRenderService.make(portFor({ config: getConfigOverride }));
|
|
356
|
+
|
|
357
|
+
/** The plain provider over the service fixture context. */
|
|
358
|
+
const portFor = (
|
|
359
|
+
overrides: { state?: () => FooterState; config?: () => TuiConfig } = {},
|
|
360
|
+
): ChromePort =>
|
|
361
|
+
makePlainChromeProvider(svcCtx, {
|
|
362
|
+
state: overrides.state ?? getState,
|
|
363
|
+
config: overrides.config ?? getConfig,
|
|
364
|
+
model: getModelMeta,
|
|
365
|
+
extensionStatuses: () => footerData().getExtensionStatuses(),
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
/** The service fixture port with an explicit theme (for styling assertions). */
|
|
369
|
+
const themedPort = (theme: Theme): ChromePort => {
|
|
370
|
+
const port = portFor();
|
|
371
|
+
return { facts: { ...port.facts, theme: () => theme } };
|
|
313
372
|
};
|
|
314
373
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
),
|
|
331
|
-
);
|
|
374
|
+
/** Config with only the token total and cost facts on. */
|
|
375
|
+
const onlyTokensAndCostConfig: TuiConfig = {
|
|
376
|
+
...config,
|
|
377
|
+
footerSegments: {
|
|
378
|
+
cwd: false,
|
|
379
|
+
gitBranch: false,
|
|
380
|
+
gitStatus: false,
|
|
381
|
+
gitCommit: false,
|
|
382
|
+
runtime: false,
|
|
383
|
+
context: false,
|
|
384
|
+
tokens: true,
|
|
385
|
+
cost: true,
|
|
386
|
+
extensionStatuses: false,
|
|
387
|
+
},
|
|
388
|
+
};
|
|
332
389
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
390
|
+
/** A `ChromePort` for the pure planners, with the token/cost fixture default. */
|
|
391
|
+
const stubPort = (overrides: Partial<ChromeFacts> = {}): ChromePort =>
|
|
392
|
+
stubChromePort({
|
|
393
|
+
config: () => onlyTokensAndCostConfig,
|
|
394
|
+
usage: () => ({
|
|
395
|
+
input: 1200,
|
|
396
|
+
output: 400,
|
|
397
|
+
cacheRead: 800,
|
|
398
|
+
cacheWrite: 100,
|
|
399
|
+
cost: 0.084,
|
|
400
|
+
latestCacheHitRate: 38.1,
|
|
401
|
+
}),
|
|
402
|
+
...overrides,
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it.effect("the footer never renders work-state words", () => {
|
|
406
|
+
// Arrange: a live run with two seconds elapsed on a frozen clock.
|
|
407
|
+
vi.useFakeTimers({ toFake: ["Date"] });
|
|
408
|
+
vi.setSystemTime(FIXED_CLOCK);
|
|
409
|
+
const tracker = new ActivityTracker();
|
|
410
|
+
tracker.handle({ type: "run_start", now: FIXED_CLOCK - 2000 });
|
|
411
|
+
const liveState = timerState({ tracker, lastDoneIn: undefined });
|
|
412
|
+
|
|
413
|
+
return Effect.gen(function* () {
|
|
414
|
+
const svc = yield* FooterRenderService;
|
|
415
|
+
|
|
416
|
+
// Act: read line 1.
|
|
417
|
+
const line1 = (yield* svc.render(80))[0]!;
|
|
418
|
+
|
|
419
|
+
// Assert: work state is pi's editor indicator, not a footer word.
|
|
420
|
+
assert.ok(!line1.includes("working"));
|
|
421
|
+
assert.ok(!line1.includes("waiting"));
|
|
422
|
+
assert.ok(!line1.includes("done"));
|
|
423
|
+
assert.ok(line1.includes("2s"));
|
|
424
|
+
}).pipe(Effect.provide(FooterRenderService.make(portFor({ state: () => liveState }))));
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it("the footer drops the cache-hit chip and keeps token totals and cost", () => {
|
|
428
|
+
// Arrange: the fixture's cache tokens are non-zero.
|
|
429
|
+
const { component } = runMount();
|
|
430
|
+
|
|
431
|
+
// Act: read line 2.
|
|
432
|
+
const line2 = component.render(80)[1]!;
|
|
433
|
+
|
|
434
|
+
// Assert: token totals and cost remain; no `c 38.1%` chip.
|
|
435
|
+
assert.match(line2, /\| \$\s?0\.084$/);
|
|
436
|
+
assert.ok(!/\bc\s?\d/.test(line2));
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it("line 2 is fitted by declared priority, not by a tail truncation", () => {
|
|
440
|
+
// Arrange: only the token total and cost facts resolve; the model identity
|
|
441
|
+
// is below its declared floor and is unavailable.
|
|
442
|
+
// Act: plan line 2 at 20 columns.
|
|
443
|
+
const decisions = planFooterLine2(stubPort(), 20);
|
|
444
|
+
|
|
445
|
+
// Assert: the token total (priority 8) survives, cost (7) yields in order.
|
|
446
|
+
const token = decisions.find((entry) => entry.id === "tokenCounts");
|
|
447
|
+
const cost = decisions.find((entry) => entry.id === "cost");
|
|
448
|
+
assert.ok(token);
|
|
449
|
+
assert.ok(cost);
|
|
450
|
+
assert.ok(token.action === "keep" || token.action === "truncate");
|
|
451
|
+
assert.strictEqual(cost.action, "drop");
|
|
452
|
+
assert.ok(composeLine(decisions, 20).length <= 20);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it("keeps the context ratio at 30 columns before any tokens are counted", () => {
|
|
456
|
+
// Arrange: the window is known, but the session has no estimated tokens yet.
|
|
457
|
+
const base = portFor();
|
|
458
|
+
for (const tokens of [0, null]) {
|
|
459
|
+
const port: ChromePort = {
|
|
460
|
+
facts: {
|
|
461
|
+
...base.facts,
|
|
462
|
+
contextUsage: () => ({ tokens, contextWindow: 200_000, percent: tokens }),
|
|
463
|
+
},
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
// Act: plan line 1 at the narrow width.
|
|
467
|
+
const context = planFooterLine1(port, 30).find((entry) => entry.id === "contextOccupancy");
|
|
468
|
+
|
|
469
|
+
// Assert: the highest-priority fact is kept, not dropped by its floor.
|
|
470
|
+
assert.ok(context, `${tokens}: missing context decision`);
|
|
471
|
+
assert.notStrictEqual(context.action, "drop", `${tokens}: context dropped`);
|
|
472
|
+
assert.ok(composeLine([context], 30).includes(tokens === null ? "—/200k" : "0/200k"));
|
|
337
473
|
}
|
|
338
474
|
});
|
|
339
475
|
|
|
340
|
-
it("
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
476
|
+
it("keeps every non-off thinking level, including low and max", () => {
|
|
477
|
+
const base = portFor();
|
|
478
|
+
for (const effort of ["minimal", "low", "medium", "high", "xhigh", "max"]) {
|
|
479
|
+
// Arrange: the same footer, with the model reporting this effort.
|
|
480
|
+
const port: ChromePort = {
|
|
481
|
+
facts: {
|
|
482
|
+
...base.facts,
|
|
483
|
+
model: () => ({ provider: "Anthropic", model: "claude-sonnet-4-0", effort }),
|
|
484
|
+
},
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
// Act: plan line 2 at the frozen 80-column width.
|
|
488
|
+
const thinking = planFooterLine2(port, 80).find((entry) => entry.id === "thinking");
|
|
489
|
+
|
|
490
|
+
// Assert: the label is present, not dropped below its floor.
|
|
491
|
+
assert.ok(thinking, `${effort}: missing thinking decision`);
|
|
492
|
+
assert.notStrictEqual(thinking.action, "drop", `${effort}: dropped`);
|
|
493
|
+
assert.ok(thinking.text.includes(effort), `${effort}: missing label`);
|
|
494
|
+
}
|
|
344
495
|
});
|
|
345
496
|
|
|
346
|
-
it("
|
|
347
|
-
|
|
348
|
-
const
|
|
497
|
+
it.effect("styles the line-2 separators with the theme's dim token", () => {
|
|
498
|
+
// Arrange: a theme that records dim paint without changing visible width.
|
|
499
|
+
const dims: string[] = [];
|
|
500
|
+
const spyTheme = themeDouble({
|
|
501
|
+
fg: (color, text) => {
|
|
502
|
+
if (color === "dim") dims.push(text);
|
|
503
|
+
return text;
|
|
504
|
+
},
|
|
505
|
+
});
|
|
349
506
|
|
|
350
|
-
|
|
351
|
-
|
|
507
|
+
return Effect.gen(function* () {
|
|
508
|
+
const svc = yield* FooterRenderService;
|
|
352
509
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
510
|
+
// Act: render through the service, not the composer directly.
|
|
511
|
+
const line = (yield* svc.render(80))[1]!;
|
|
512
|
+
|
|
513
|
+
// Assert: the stats pipe and both dots (model identity and the thinking
|
|
514
|
+
// separator) are painted dim by the service wiring.
|
|
515
|
+
assert.ok(line.includes("↑"));
|
|
516
|
+
assert.ok(dims.includes(" | "));
|
|
517
|
+
assert.ok(dims.filter((text) => text === " · ").length >= 2);
|
|
518
|
+
}).pipe(Effect.provide(FooterRenderService.make(themedPort(spyTheme))));
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it.effect(
|
|
522
|
+
"FooterRenderService.render reproduces the frozen golden lines at every pinned width",
|
|
523
|
+
() =>
|
|
524
|
+
Effect.gen(function* () {
|
|
525
|
+
const svc = yield* FooterRenderService;
|
|
526
|
+
for (const w of WIDTHS) {
|
|
527
|
+
const rendered = yield* svc.render(w);
|
|
528
|
+
assert.deepStrictEqual(rendered, FOOTER_EXPECTED[String(w)]);
|
|
529
|
+
}
|
|
530
|
+
}).pipe(Effect.provide(footerLayer())),
|
|
531
|
+
);
|
|
532
|
+
|
|
533
|
+
it.effect("FooterRenderService.render returns a single empty line for non-positive widths", () =>
|
|
534
|
+
Effect.gen(function* () {
|
|
535
|
+
const svc = yield* FooterRenderService;
|
|
536
|
+
const zero = yield* svc.render(0);
|
|
537
|
+
assert.deepStrictEqual(zero, [""]);
|
|
538
|
+
const negative = yield* svc.render(-1);
|
|
539
|
+
assert.deepStrictEqual(negative, [""]);
|
|
540
|
+
}).pipe(Effect.provide(footerLayer())),
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
it.effect("FooterRenderService.render re-invokes the live getters on every run", () => {
|
|
544
|
+
let liveConfig: TuiConfig = config;
|
|
545
|
+
return Effect.gen(function* () {
|
|
546
|
+
const svc = yield* FooterRenderService;
|
|
547
|
+
|
|
548
|
+
const withContext = yield* svc.render(80);
|
|
549
|
+
assert.ok(withContext[0]!.includes("100k/200k"));
|
|
550
|
+
|
|
551
|
+
liveConfig = {
|
|
552
|
+
...config,
|
|
553
|
+
footerSegments: { ...config.footerSegments, context: false },
|
|
554
|
+
};
|
|
555
|
+
const withoutContext = yield* svc.render(80);
|
|
556
|
+
assert.ok(!withoutContext[0]!.includes("100k/200k"));
|
|
557
|
+
assert.ok(withoutContext[0]!.includes("feature/refactor"));
|
|
558
|
+
}).pipe(Effect.provide(footerLayer(() => liveConfig)));
|
|
360
559
|
});
|
|
361
560
|
|
|
362
561
|
// ---------------------------------------------------------------------------
|
|
@@ -365,11 +564,10 @@ it("FooterRenderService.render re-invokes the live getters on every run", () =>
|
|
|
365
564
|
// the no-timer pixels byte-for-byte.
|
|
366
565
|
// ---------------------------------------------------------------------------
|
|
367
566
|
|
|
368
|
-
const timerTheme = {
|
|
369
|
-
fg: (color
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
} as unknown as Theme;
|
|
567
|
+
const timerTheme = themeDouble({
|
|
568
|
+
fg: (color, text) => `${color}:${text}`,
|
|
569
|
+
bold: (text) => `*${text}*`,
|
|
570
|
+
});
|
|
373
571
|
|
|
374
572
|
const TIMER_GLYPHS = { working: "o", done: "+", inference: "~", tool: ">" } as IconGlyphs;
|
|
375
573
|
|
|
@@ -388,8 +586,11 @@ const scriptedState = (
|
|
|
388
586
|
return timerState({ tracker, ...overrides });
|
|
389
587
|
};
|
|
390
588
|
|
|
589
|
+
const timerSegment = (s: FooterState, now: number) =>
|
|
590
|
+
renderTimerSegment(timerTheme, s.tracker, s.lastDoneIn, TIMER_GLYPHS, now);
|
|
591
|
+
|
|
391
592
|
it("renderTimerSegment renders nothing without an active or finished timer", () => {
|
|
392
|
-
assert.strictEqual(
|
|
593
|
+
assert.strictEqual(timerSegment(timerState(), 5000), undefined);
|
|
393
594
|
});
|
|
394
595
|
|
|
395
596
|
it("renderTimerSegment counts working time excluding completed user waits", () => {
|
|
@@ -400,8 +601,8 @@ it("renderTimerSegment counts working time excluding completed user waits", () =
|
|
|
400
601
|
]);
|
|
401
602
|
// Elapsed 4s minus a completed 2s wait = 2s of active work; no inference
|
|
402
603
|
// or tool spans in this script, so there is no split.
|
|
403
|
-
const seg =
|
|
404
|
-
assert.strictEqual(seg?.total, "accent:o
|
|
604
|
+
const seg = timerSegment(s, 5000);
|
|
605
|
+
assert.strictEqual(seg?.total, "accent:o accent:2s");
|
|
405
606
|
assert.strictEqual(seg?.split, "");
|
|
406
607
|
});
|
|
407
608
|
|
|
@@ -414,15 +615,15 @@ it("renderTimerSegment reports waiting while a user prompt is open", () => {
|
|
|
414
615
|
]);
|
|
415
616
|
// The open wait spans 1s (t=4s..5s); working time stops counting and the
|
|
416
617
|
// label is exactly the previous waiting string.
|
|
417
|
-
const seg =
|
|
418
|
-
assert.strictEqual(seg?.total, "warning:o warning:
|
|
618
|
+
const seg = timerSegment(s, 5000);
|
|
619
|
+
assert.strictEqual(seg?.total, "warning:o warning:1s");
|
|
419
620
|
assert.strictEqual(seg?.split, "");
|
|
420
621
|
});
|
|
421
622
|
|
|
422
623
|
it("renderTimerSegment reports the finished run's wait-free duration", () => {
|
|
423
624
|
const s = timerState({ lastDoneIn: 90_000 });
|
|
424
|
-
const seg =
|
|
425
|
-
assert.strictEqual(seg?.total, "success:+
|
|
625
|
+
const seg = timerSegment(s, 5000);
|
|
626
|
+
assert.strictEqual(seg?.total, "success:+ text:1m 30s");
|
|
426
627
|
// A tracker that never ran has no frozen split.
|
|
427
628
|
assert.strictEqual(seg?.split, "");
|
|
428
629
|
});
|
|
@@ -437,8 +638,8 @@ it("renderTimerSegment shows the live total and split while working", () => {
|
|
|
437
638
|
]);
|
|
438
639
|
// At t=6s: inference 1000..2000 + 4000..5000 = 2s (tool subsumes the
|
|
439
640
|
// open message while it runs); tool 2000..4000 = 2s; total 1000..6000.
|
|
440
|
-
const seg =
|
|
441
|
-
assert.strictEqual(seg?.total, "accent:o
|
|
641
|
+
const seg = timerSegment(s, 6000);
|
|
642
|
+
assert.strictEqual(seg?.total, "accent:o accent:5s");
|
|
442
643
|
assert.strictEqual(seg?.split, "dim:~ accent:2s dim:> accent:2s");
|
|
443
644
|
});
|
|
444
645
|
|
|
@@ -458,19 +659,20 @@ it("renderTimerSegment shows the frozen total and split after the run", () => {
|
|
|
458
659
|
const s = timerState({ tracker, lastDoneIn: frozen.total - frozen.wait });
|
|
459
660
|
|
|
460
661
|
// Frozen: the same pixels at any later instant — no live ticking.
|
|
461
|
-
const at = (now: number) =>
|
|
662
|
+
const at = (now: number) => timerSegment(s, now);
|
|
462
663
|
for (const now of [7000, 60_000]) {
|
|
463
664
|
const seg = at(now);
|
|
464
|
-
assert.strictEqual(seg?.total, "success:+
|
|
665
|
+
assert.strictEqual(seg?.total, "success:+ text:5s");
|
|
465
666
|
assert.strictEqual(seg?.split, "dim:~ accent:2s dim:> accent:2s");
|
|
466
667
|
}
|
|
467
668
|
});
|
|
468
669
|
|
|
469
|
-
it("the split yields before the total on narrow widths", () => {
|
|
670
|
+
it.effect("the split yields before the total on narrow widths", () => {
|
|
470
671
|
// A live run whose buckets are non-zero: a complete 10s run ending in the
|
|
471
|
-
// past, so the
|
|
472
|
-
|
|
473
|
-
const base =
|
|
672
|
+
// past, so the render's clock never moves between the events and the read.
|
|
673
|
+
vi.useFakeTimers({ toFake: ["Date"] });
|
|
674
|
+
const base = FIXED_CLOCK;
|
|
675
|
+
vi.setSystemTime(base);
|
|
474
676
|
const tracker = new ActivityTracker();
|
|
475
677
|
for (const event of [
|
|
476
678
|
{ type: "run_start", now: base - 10_000 },
|
|
@@ -496,31 +698,58 @@ it("the split yields before the total on narrow widths", () => {
|
|
|
496
698
|
context: false,
|
|
497
699
|
},
|
|
498
700
|
};
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
701
|
+
return Effect.gen(function* () {
|
|
702
|
+
const packSvc = yield* FooterRenderService;
|
|
703
|
+
|
|
704
|
+
const narrow = (yield* packSvc.render(10))[0]!;
|
|
705
|
+
const wide = (yield* packSvc.render(40))[0]!;
|
|
706
|
+
|
|
707
|
+
// Narrow: the split (priority 6) drops, the total (priority 12) survives.
|
|
708
|
+
assert.ok(narrow.includes("▶"));
|
|
709
|
+
assert.ok(!narrow.includes("✻"));
|
|
710
|
+
assert.ok(!narrow.includes("⚙"));
|
|
711
|
+
// Wide: both parts render.
|
|
712
|
+
assert.ok(wide.includes("▶"));
|
|
713
|
+
assert.ok(wide.includes("✻"));
|
|
714
|
+
assert.ok(wide.includes("⚙"));
|
|
715
|
+
assert.strictEqual(Date.now(), base);
|
|
716
|
+
}).pipe(
|
|
717
|
+
Effect.provide(
|
|
718
|
+
FooterRenderService.make(portFor({ state: () => liveState, config: () => bareConfig })),
|
|
512
719
|
),
|
|
513
720
|
);
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
// ---------------------------------------------------------------------------
|
|
724
|
+
// Module state — the usage cache is one slot the file must not inherit
|
|
725
|
+
// ---------------------------------------------------------------------------
|
|
726
|
+
|
|
727
|
+
it("invalidating the usage cache makes the next read recompute", () => {
|
|
728
|
+
// The cache is keyed by the session entries; the first read fills it and the
|
|
729
|
+
// invalidator is the only thing that empties it. Without this hook the suite
|
|
730
|
+
// would depend on ENTRIES never changing across files.
|
|
731
|
+
const first = getUsageTotals(svcCtx);
|
|
732
|
+
assert.strictEqual(getUsageTotals(svcCtx), first);
|
|
733
|
+
|
|
734
|
+
invalidateUsageCache();
|
|
735
|
+
|
|
736
|
+
const recomputed = getUsageTotals(svcCtx);
|
|
737
|
+
assert.notStrictEqual(recomputed, first);
|
|
738
|
+
assert.deepStrictEqual(recomputed, first);
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
let filledTotals: unknown;
|
|
742
|
+
|
|
743
|
+
it("a usage read caches its totals", () => {
|
|
744
|
+
const totals = getUsageTotals(svcCtx);
|
|
745
|
+
filledTotals = totals;
|
|
746
|
+
assert.strictEqual(getUsageTotals(svcCtx), totals);
|
|
747
|
+
});
|
|
514
748
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
//
|
|
519
|
-
|
|
520
|
-
assert.
|
|
521
|
-
assert.ok(!narrow.includes(">"));
|
|
522
|
-
// Wide: both parts render.
|
|
523
|
-
assert.ok(wide.includes("working"));
|
|
524
|
-
assert.ok(wide.includes("~"));
|
|
525
|
-
assert.ok(wide.includes(">"));
|
|
749
|
+
it("a test starts with an empty usage cache", () => {
|
|
750
|
+
// Order-independent: if the caching test ran first, the hook above emptied
|
|
751
|
+
// the cache, so this read is a new object; otherwise nothing was cached yet
|
|
752
|
+
// and the comparison is against `undefined`. Without the hook the second
|
|
753
|
+
// order returns the previous test's object and this fails.
|
|
754
|
+
assert.notStrictEqual(getUsageTotals(svcCtx), filledTotals);
|
|
526
755
|
});
|