mirror of
https://github.com/jarrodwatts/claude-hud.git
synced 2026-04-19 08:42:39 +00:00
test: cover agent elapsed formatting
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user