Files
claude-hud/tests/core.test.js
Jarrod Watts e9b0e9f680 feat: comprehensive config detection across all scopes
- Add ~/.claude.json user-scope MCP support
- Add .mcp.json project MCP support
- Add .claude/settings.local.json support
- Add CLAUDE.local.md and .claude/CLAUDE.md detection
- Deduplicate MCPs that appear in multiple files

Locations now covered:
- User: ~/.claude/CLAUDE.md, ~/.claude/rules/, ~/.claude/settings.json, ~/.claude.json
- Project: CLAUDE.md, CLAUDE.local.md, .claude/CLAUDE.md, .claude/rules/, .mcp.json
- Project settings: .claude/settings.json, .claude/settings.local.json

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-03 18:10:26 +11:00

63 lines
2.2 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { parseTranscript } from '../dist/transcript.js';
import { getContextPercent } from '../dist/stdin.js';
test('getContextPercent returns 0 when data is missing', () => {
assert.equal(getContextPercent({}), 0);
assert.equal(getContextPercent({ context_window: { context_window_size: 0 } }), 0);
});
test('getContextPercent includes cache tokens', () => {
const percent = getContextPercent({
context_window: {
context_window_size: 200,
current_usage: {
input_tokens: 50,
cache_creation_input_tokens: 25,
cache_read_input_tokens: 25,
},
},
});
assert.equal(percent, 50);
});
test('parseTranscript aggregates tools, agents, and todos', async () => {
const fixturePath = fileURLToPath(new URL('./fixtures/transcript-basic.jsonl', import.meta.url));
const result = await parseTranscript(fixturePath);
assert.equal(result.tools.length, 1);
assert.equal(result.tools[0].status, 'completed');
assert.equal(result.tools[0].target, '/tmp/example.txt');
assert.equal(result.agents.length, 1);
assert.equal(result.agents[0].status, 'completed');
assert.equal(result.todos.length, 2);
assert.equal(result.todos[1].status, 'in_progress');
assert.equal(result.sessionStart?.toISOString(), '2024-01-01T00:00:00.000Z');
});
test('parseTranscript tolerates malformed lines', async () => {
const dir = await mkdtemp(path.join(tmpdir(), 'claude-hud-'));
const filePath = path.join(dir, 'malformed.jsonl');
const lines = [
'{"timestamp":"2024-01-01T00:00:00.000Z","message":{"content":[{"type":"tool_use","id":"tool-1","name":"Read"}]}}',
'{not-json}',
'{"message":{"content":[{"type":"tool_result","tool_use_id":"tool-1"}]}}',
'',
];
await writeFile(filePath, lines.join('\n'), 'utf8');
try {
const result = await parseTranscript(filePath);
assert.equal(result.tools.length, 1);
assert.equal(result.tools[0].status, 'completed');
} finally {
await rm(dir, { recursive: true, force: true });
}
});