import { assert, createLogicSuite } from '@genesislcap/foundation-testing';
import { formatCompactTokenCount, formatCompactTokenCountSafe, sumTokens } from './sum-tokens';
const assistantMsg = (overrides = {}) => (Object.assign({ role: 'assistant', content: '' }, overrides));
const suite = createLogicSuite('sumTokens');
suite('returns 0 for an empty message list', () => {
    assert.is(sumTokens([]), 0);
});
suite('sums input and output tokens on top-level messages', () => {
    assert.is(sumTokens([
        assistantMsg({ inputTokens: 100, outputTokens: 50 }),
        assistantMsg({ inputTokens: 200, outputTokens: 0 }),
    ]), 350);
});
suite('includes sub-agent trace tokens attached to a tool call', () => {
    assert.is(sumTokens([
        assistantMsg({
            inputTokens: 10,
            outputTokens: 5,
            toolCalls: [
                {
                    id: 'tc1',
                    name: 'spawn_sub',
                    args: {},
                    subAgentTrace: [assistantMsg({ inputTokens: 1000, outputTokens: 400 })],
                },
            ],
        }),
    ]), 1415);
});
const formatSuite = createLogicSuite('formatCompactTokenCount');
formatSuite('formats millions with one decimal when needed', () => {
    assert.is(formatCompactTokenCount(1400000), '<span class="value">1.4</span><span class="suffix">M</span>');
});
formatSuite('formats whole millions without a decimal', () => {
    assert.is(formatCompactTokenCount(2000000), '<span class="value">2</span><span class="suffix">M</span>');
});
formatSuite('formats thousands compactly', () => {
    assert.is(formatCompactTokenCount(3200), '<span class="value">3.2</span><span class="suffix">K</span>');
});
formatSuite('formats small counts with grouping', () => {
    assert.is(formatCompactTokenCount(842), '842');
});
formatSuite('rolls K suffix up to M when rounding would yield 1000K', () => {
    assert.is(formatCompactTokenCount(999950), '<span class="value">1</span><span class="suffix">M</span>');
    assert.is(formatCompactTokenCount(999949), '<span class="value">999.9</span><span class="suffix">K</span>');
});
formatSuite('safe formatter preserves compact markup', () => {
    assert.is(formatCompactTokenCountSafe(1400000), '<span class="value">1.4</span><span class="suffix">M</span>');
});
suite.run();
formatSuite.run();
