test: add gemini and xai parser unit tests

This commit is contained in:
B.A. Baracus 2026-04-04 17:51:38 +00:00
parent 07a544c50d
commit 988618e165
Signed by untrusted user who does not match committer: hannibal
GPG key ID: 6EB37F7E6190AF1C
4 changed files with 153 additions and 0 deletions

View file

@ -19,6 +19,21 @@ export function getSeverity(provider) {
if (tokenPct > 0.85) return 'warning';
return 'ok';
}
if (provider.type === 'gemini-api') {
if (provider.status === 'exhausted') return 'critical';
if (provider.status === 'ok') return 'ok';
return 'unknown';
}
if (provider.type === 'xai-api') {
if (provider.status === 'rate_limited') return 'critical';
if (provider.status === 'ok') {
const reqPct = provider.requests_remaining / provider.requests_limit;
const tokPct = provider.tokens_remaining / provider.tokens_limit;
if ((reqPct < 0.1) || (tokPct < 0.1)) return 'warning';
return 'ok';
}
return 'unknown';
}
return 'unknown';
}
@ -104,6 +119,34 @@ export function generateReport(result) {
}
} else if (p.type === 'api-direct') {
detail = p.message || 'No billing data available';
} else if (p.type === 'gemini-api') {
if (p.status === 'invalid_key') {
detail = 'Invalid API key (401)';
} else if (p.status === 'no_key') {
detail = 'No API key configured';
} else if (p.status === 'exhausted') {
const retryIn = p.retry_delay_seconds ? formatDuration(p.retry_delay_seconds) : '?';
const violated = p.quota_violations?.length || 0;
detail = `EXHAUSTED — retry in ${retryIn} | ${violated} quota(s) violated`;
} else if (p.status === 'ok') {
detail = 'Reachable — no quota depth visible';
} else if (p.status === 'error') {
detail = `Error: ${p.message || 'unknown'}`;
}
} else if (p.type === 'xai-api') {
if (p.status === 'no_key') {
detail = 'No API key configured';
} else if (p.status === 'invalid_key') {
detail = 'Invalid API key (401)';
} else if (p.status === 'rate_limited') {
detail = 'Rate limited (429)';
} else if (p.status === 'ok') {
const reqPct = p.requests_limit ? `${p.requests_remaining}/${p.requests_limit} req` : '';
const tokPct = p.tokens_limit ? ` | ${p.tokens_remaining?.toLocaleString()}/${p.tokens_limit?.toLocaleString()} tok` : '';
detail = reqPct + tokPct || 'OK';
} else if (p.status === 'error') {
detail = `Error: ${p.message || 'unknown'}`;
}
} else {
detail = p.message || '';
}