mirror of
https://github.com/jarrodwatts/claude-hud.git
synced 2026-04-20 01:32:38 +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(
|
function getStatusIcon(
|
||||||
status: AgentEntry['status'],
|
status: AgentEntry['status']
|
||||||
colors?: RenderContext['config']['colors']
|
|
||||||
): string {
|
): string {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 'running':
|
case 'running':
|
||||||
return yellow('◐');
|
return yellow('◐');
|
||||||
case 'failed':
|
|
||||||
return label('✗', colors);
|
|
||||||
case 'completed':
|
case 'completed':
|
||||||
default:
|
default:
|
||||||
return green('✓');
|
return green('✓');
|
||||||
@@ -52,7 +49,7 @@ function formatAgent(
|
|||||||
agent: AgentEntry,
|
agent: AgentEntry,
|
||||||
colors?: RenderContext['config']['colors']
|
colors?: RenderContext['config']['colors']
|
||||||
): string {
|
): string {
|
||||||
const statusIcon = getStatusIcon(agent.status, colors);
|
const statusIcon = getStatusIcon(agent.status);
|
||||||
const type = magenta(agent.type);
|
const type = magenta(agent.type);
|
||||||
const model = agent.model ? label(`[${agent.model}]`, colors) : '';
|
const model = agent.model ? label(`[${agent.model}]`, colors) : '';
|
||||||
const desc = agent.description
|
const desc = agent.description
|
||||||
|
|||||||
@@ -760,6 +760,39 @@ test('renderAgentsLine renders running agents with live elapsed time', () => {
|
|||||||
Date.now = originalNow;
|
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', () => {
|
test('renderTodosLine handles in-progress and completed-only cases', () => {
|
||||||
const ctx = baseContext();
|
const ctx = baseContext();
|
||||||
ctx.transcript.todos = [
|
ctx.transcript.todos = [
|
||||||
|
|||||||
Reference in New Issue
Block a user