Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion packages/cli/src/__tests__/pi-transcript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { describe, test } from 'node:test';
import { visibleWidth } from '@earendil-works/pi-tui';
import type { PipeShellOutput, PtyShellOutput } from '@maka/core/shell-run';
import type { ShellRunToolResult } from '@maka/core/shell-run-result';
import type { SessionEvent, ToolResultContent } from '@maka/core/events';
import type { ProviderRetryEvent, SessionEvent, ToolResultContent } from '@maka/core/events';
import type { StoredMessage } from '@maka/core/session';
import {
appendUserPrompt,
Expand All @@ -42,6 +42,7 @@ import {
toggleAllThinkingExpansion,
toggleAllToolExpansion,
type MakaPiToolEntry,
type MakaPiTranscriptMetadata,
} from '../pi-transcript.js';

function toolStatus(entry: MakaPiToolEntry | undefined): string | undefined {
Expand Down Expand Up @@ -3650,6 +3651,46 @@ describe('Maka Pi TUI transcript', () => {
assert.doesNotMatch(expanded, /progress-0\b/);
assert.match(expanded, /progress-512\b/);
});

test('activity strip reports cancellation ahead of working and retry states', () => {
const strip = (extra: Partial<MakaPiTranscriptMetadata>): string =>
stripAnsi(renderMakaPiActivityStrip({ ...meta(), ...extra }, 80));

// A running turn with nothing else to say reports elapsed work.
assert.equal(strip({ turnElapsedMs: 3_000 }), 'Working… 3s');

// Cancellation is announced from the moment the gesture is accepted, so the
// first render after recognition already reads `Cancelling…` — zero elapsed
// is the common case, not an edge case, and must not fall back to `Working…`.
assert.equal(strip({ turnElapsedMs: 3_000, interruptElapsedMs: 0 }), 'Cancelling… 0s');

// A cleanup that outlives the gesture (a tool held through the process
// termination grace) stays legible as progress rather than looking hung.
assert.equal(strip({ turnElapsedMs: 9_000, interruptElapsedMs: 2_000 }), 'Cancelling… 2s');

// A retry scheduled before the interrupt is superseded by it: the turn is no
// longer working towards anything the user asked for.
assert.equal(
strip({
turnElapsedMs: 9_000,
interruptElapsedMs: 1_000,
providerRetry: scheduledRetry(),
}),
'Cancelling… 1s',
);

// Without an interrupt the retry still wins over `Working…`, unchanged.
assert.equal(
strip({
turnElapsedMs: 9_000,
providerRetry: scheduledRetry(),
}),
'Retrying in 30s (2/5)',
);

// An idle transcript stays silent even though a previous interrupt happened.
assert.equal(strip({}), '');
});
});

describe('transcript entry render memoization', () => {
Expand Down Expand Up @@ -4045,6 +4086,20 @@ function subagentResult(
};
}

function scheduledRetry(): ProviderRetryEvent {
return {
type: 'provider_retry',
phase: 'scheduled',
id: 'event-retry',
turnId: 'turn-1',
ts: 1,
attempt: 2,
maxAttempts: 5,
delayMs: 30_000,
reason: 'rate_limit',
};
}

function stripAnsi(text: string): string {
return text.replace(/\x1b\[[0-9;]*m/g, '');
}
Loading