test: cover agent elapsed formatting

This commit is contained in:
Jarrod Watts
2026-04-04 14:55:08 +11:00
parent 3790411344
commit 5d923d75ca
2 changed files with 35 additions and 5 deletions

View File

@@ -34,14 +34,11 @@ export function renderAgentsLine(ctx: RenderContext): string | null {
}
function getStatusIcon(
status: AgentEntry['status'],
colors?: RenderContext['config']['colors']
status: AgentEntry['status']
): string {
switch (status) {
case 'running':
return yellow('◐');
case 'failed':
return label('✗', colors);
case 'completed':
default:
return green('✓');
@@ -52,7 +49,7 @@ function formatAgent(
agent: AgentEntry,
colors?: RenderContext['config']['colors']
): string {
const statusIcon = getStatusIcon(agent.status, colors);
const statusIcon = getStatusIcon(agent.status);
const type = magenta(agent.type);
const model = agent.model ? label(`[${agent.model}]`, colors) : '';
const desc = agent.description

View File

@@ -760,6 +760,39 @@ test('renderAgentsLine renders running agents with live elapsed time', () => {
Date.now = originalNow;
}
});
test('renderAgentsLine formats elapsed time in hours for long-running agents', () => {
const ctx = baseContext();
ctx.transcript.agents = [
{
id: 'agent-1',
type: 'plan',
status: 'completed',
startTime: new Date(0),
endTime: new Date((2 * 60 * 60 + 5 * 60) * 1000),
},
];
const line = renderAgentsLine(ctx);
assert.ok(line?.includes('2h 5m'));
});
test('renderAgentsLine clamps negative elapsed time to under one second', () => {
const ctx = baseContext();
ctx.transcript.agents = [
{
id: 'agent-1',
type: 'plan',
status: 'completed',
startTime: new Date(5000),
endTime: new Date(1000),
},
];
const line = renderAgentsLine(ctx);
assert.ok(line?.includes('<1s'));
});
test('renderTodosLine handles in-progress and completed-only cases', () => {
const ctx = baseContext();
ctx.transcript.todos = [