Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/output/quota-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function displayModelName(name: string, region: string): string {

function formatDuration(ms: number, nowLabel: string): string {
if (ms <= 0) return nowLabel;
if (ms < 60000) return `${Math.max(1, Math.floor(ms / 1000))}s`;
const hours = Math.floor(ms / 3600000);
const minutes = Math.floor((ms % 3600000) / 60000);
return hours > 0 ? `${hours}h ${minutes}m` : `${minutes}m`;
Expand Down
33 changes: 33 additions & 0 deletions test/output/quota-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,39 @@ describe('renderQuotaTable', () => {
}
});

it('renders seconds only for positive durations below one minute', () => {
const lines: string[] = [];
const originalLog = console.log;

console.log = (message?: unknown) => {
lines.push(String(message ?? ''));
};

try {
renderQuotaTable(
[
{ ...createModel(), model_name: 'subsecond', remains_time: 1 },
{ ...createModel(), model_name: 'seconds', remains_time: 59_999 },
{ ...createModel(), model_name: 'minute', remains_time: 60_000 },
{ ...createModel(), model_name: 'elapsed', remains_time: 0 },
],
{ ...createConfig(), noColor: true },
);
renderQuotaTable(
[{ ...createModel(), model_name: 'expired-cn', remains_time: -1 }],
{ ...createConfig(), region: 'cn', noColor: true },
);
} finally {
console.log = originalLog;
}

expect(lines.find(line => line.includes('subsecond'))).toContain('12h Reset 1s');
expect(lines.find(line => line.includes('seconds'))).toContain('12h Reset 59s');
expect(lines.find(line => line.includes('minute'))).toContain('12h Reset 1m');
expect(lines.find(line => line.includes('elapsed'))).toContain('12h Reset now');
expect(lines.find(line => line.includes('expired-cn'))).toContain('12h 重置 即将');
});

it('applies weekly_boost_permille (1500 ⇒ up to 150%) when rendering weekly percent', () => {
const lines: string[] = [];
const originalLog = console.log;
Expand Down
Loading