mirror of
https://github.com/yamadashy/repomix.git
synced 2026-11-20 06:29:20 +01:00
intent(token-budget-test): the test hard-coded en-US separators and failed on machines with another locale (en-IN prints 2,43,512, de-DE 243.512) decision(token-budget-test): build the expected text with toLocaleString() like the message does; the product output is unchanged Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import { validateTokenBudget } from '../../src/cli/cliTokenBudget.js';
|
|
import { RepomixError } from '../../src/shared/errorHandle.js';
|
|
|
|
describe('validateTokenBudget', () => {
|
|
test('does nothing when no budget is set', () => {
|
|
expect(() => validateTokenBudget(1_000_000, undefined)).not.toThrow();
|
|
});
|
|
|
|
test('does nothing when the total is within budget', () => {
|
|
expect(() => validateTokenBudget(100, 200)).not.toThrow();
|
|
});
|
|
|
|
test('does nothing when the total exactly equals the budget', () => {
|
|
expect(() => validateTokenBudget(200, 200)).not.toThrow();
|
|
});
|
|
|
|
test('throws a RepomixError when the total exceeds the budget', () => {
|
|
expect(() => validateTokenBudget(250, 200)).toThrow(RepomixError);
|
|
});
|
|
|
|
test('includes the actual and budget token counts in the message', () => {
|
|
// The message formats the counts with toLocaleString(), so the separators depend on the
|
|
// machine's locale (en-IN prints 2,43,512).
|
|
expect(() => validateTokenBudget(243512, 180000)).toThrow(
|
|
`${(243512).toLocaleString()} > ${(180000).toLocaleString()} tokens`,
|
|
);
|
|
});
|
|
});
|