The spinner ran a CSS animation on every active row for the whole turn, repainting a composited layer at frame rate. Rows now carry a static dot — primary while running, info while unread — and the metadata slot on the right shows how long the turn has been going, updating once per second in the dot's colour. The counter is the motion the spinner used to provide, at 1 fps. Collapsed groups, folders and projects take the dot only, since one counter cannot speak for several running turns. Elapsed time is measured client-side because SessionStatus carries no timestamps, and starts are persisted so a reload resumes the same count. Two rules keep that honest. Only a liveness stamp — refreshed while a session is observed active, stamped as the page hides, and compared against the page's navigation start so a slow bootstrap is not charged to the absence — and a 90s adoption window may expire a record; a snapshot that cannot yet see a session is not evidence its turn ended. And a busy event is never read as a turn boundary, because OpenCode republishes busy at every step of the agent loop, so after a reload one of those repeats normally beats the first status snapshot. Idle and error events do end a turn, and retire the record with it. Snapshot reconciliation walks the running turns and asks whether the snapshot covers each one, rather than being handed everything it covers: only a live start can settle, so the pass scales with timing work instead of with the directory's session list, and allocates nothing per poll. Also applied to the mobile sessions sheet and session switcher. The shared duration ticker moves to hooks/ now that it has a second consumer.
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
|
|
import { dict as enDict } from '@/lib/i18n/messages/en';
|
|
import { formatMessage, type I18nKey, type I18nParams } from '@/lib/i18n';
|
|
import { formatSessionActivityDuration } from './sessionActivityDurationFormat';
|
|
|
|
const t = (key: I18nKey, params?: I18nParams): string => formatMessage(enDict, key, params);
|
|
|
|
const format = (ms: number): string => formatSessionActivityDuration(ms, t);
|
|
|
|
describe('formatSessionActivityDuration', () => {
|
|
test('renders seconds below a minute', () => {
|
|
expect(format(0)).toBe('0s');
|
|
expect(format(999)).toBe('0s');
|
|
expect(format(7_400)).toBe('7s');
|
|
expect(format(59_999)).toBe('59s');
|
|
});
|
|
|
|
test('renders minutes and seconds below an hour', () => {
|
|
expect(format(60_000)).toBe('1m 0s');
|
|
expect(format(83_000)).toBe('1m 23s');
|
|
expect(format(59 * 60_000 + 59_000)).toBe('59m 59s');
|
|
});
|
|
|
|
test('drops seconds past an hour so the label stays narrow', () => {
|
|
expect(format(3_600_000)).toBe('1h 0m');
|
|
expect(format(3_600_000 + 2 * 60_000 + 33_000)).toBe('1h 2m');
|
|
expect(format(25 * 3_600_000)).toBe('25h 0m');
|
|
});
|
|
|
|
test('clamps a negative duration rather than rendering a negative count', () => {
|
|
expect(format(-5_000)).toBe('0s');
|
|
});
|
|
});
|