mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-14 12:16:38 +00:00
fix(cliproxy): restore live monitor provider attribution
This commit is contained in:
1 parent
7f84308a41
commit
368a625d92
4 files changed
+236
-50
No files matched your search
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
import type { CliproxyUsageApiResponse } from '../../../src/cliproxy/stats-fetcher';
|
||||
import type {
|
||||
CliproxyManagementAuthFile,
|
||||
CliproxyUsageApiResponse,
|
||||
} from '../../../src/cliproxy/stats-fetcher';
|
||||
import { buildCliproxyStatsFromUsageResponse } from '../../../src/cliproxy/stats-transformer';
|
||||
|
||||
describe('buildCliproxyStatsFromUsageResponse', () => {
|
||||
@@ -121,4 +124,89 @@ describe('buildCliproxyStatsFromUsageResponse', () => {
|
||||
expect(stats.failureCount).toBe(2);
|
||||
expect(stats.requestsByProvider).toEqual({ codex: 3, gemini: 2 });
|
||||
});
|
||||
|
||||
it('resolves canonical providers from auth_index when usage is internally bucketed', () => {
|
||||
const usage: CliproxyUsageApiResponse = {
|
||||
usage: {
|
||||
total_requests: 3,
|
||||
success_count: 2,
|
||||
failure_count: 1,
|
||||
apis: {
|
||||
'ccs-internal-managed': {
|
||||
total_requests: 3,
|
||||
models: {
|
||||
'gpt-5': {
|
||||
total_requests: 3,
|
||||
details: [
|
||||
{
|
||||
timestamp: '2026-03-26T10:00:00.000Z',
|
||||
source: 'shared@example.com',
|
||||
auth_index: 'codex-1',
|
||||
tokens: {
|
||||
input_tokens: 10,
|
||||
output_tokens: 5,
|
||||
reasoning_tokens: 0,
|
||||
cached_tokens: 0,
|
||||
total_tokens: 15,
|
||||
},
|
||||
failed: false,
|
||||
},
|
||||
{
|
||||
timestamp: '2026-03-26T10:01:00.000Z',
|
||||
source: 'shared@example.com',
|
||||
auth_index: 'gemini-1',
|
||||
tokens: {
|
||||
input_tokens: 12,
|
||||
output_tokens: 7,
|
||||
reasoning_tokens: 0,
|
||||
cached_tokens: 0,
|
||||
total_tokens: 19,
|
||||
},
|
||||
failed: false,
|
||||
},
|
||||
{
|
||||
timestamp: '2026-03-26T10:02:00.000Z',
|
||||
source: 'shared@example.com',
|
||||
auth_index: 'agy-1',
|
||||
tokens: {
|
||||
input_tokens: 8,
|
||||
output_tokens: 2,
|
||||
reasoning_tokens: 0,
|
||||
cached_tokens: 0,
|
||||
total_tokens: 10,
|
||||
},
|
||||
failed: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const authFiles: CliproxyManagementAuthFile[] = [
|
||||
{ auth_index: 'codex-1', provider: 'codex', email: 'shared@example.com' },
|
||||
{ auth_index: 'gemini-1', provider: 'gemini-cli', email: 'shared@example.com' },
|
||||
{ auth_index: 'agy-1', provider: 'antigravity', email: 'shared@example.com' },
|
||||
];
|
||||
|
||||
const stats = buildCliproxyStatsFromUsageResponse(usage, { authFiles });
|
||||
|
||||
expect(stats.accountStats['codex:shared@example.com']).toMatchObject({
|
||||
provider: 'codex',
|
||||
successCount: 1,
|
||||
failureCount: 0,
|
||||
});
|
||||
expect(stats.accountStats['gemini:shared@example.com']).toMatchObject({
|
||||
provider: 'gemini',
|
||||
successCount: 1,
|
||||
failureCount: 0,
|
||||
});
|
||||
expect(stats.accountStats['agy:shared@example.com']).toMatchObject({
|
||||
provider: 'agy',
|
||||
successCount: 0,
|
||||
failureCount: 1,
|
||||
});
|
||||
expect(stats.requestsByProvider).toEqual({ codex: 1, gemini: 1, agy: 1 });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user