Skip to content

Commit 35046b1

Browse files
committed
test(provider): distinguish OpenCode billing 401 from auth failure
1 parent 02ce90b commit 35046b1

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { APIError as OpenAIAPIError } from 'openai';
2+
import { describe, expect, it } from 'vitest';
3+
4+
import { PROVIDER_API_ERROR_CODE, PROVIDER_AUTH_ERROR_CODE } from '#/kosong/contract/errors';
5+
import { convertOpenAIError } from '#/kosong/provider/bases/openai/openai-common';
6+
7+
describe('OpenCode billing rejection classification', () => {
8+
it('keeps a 401 insufficient-balance response out of provider.auth_error', () => {
9+
const source = new OpenAIAPIError(
10+
401,
11+
{ message: 'Insufficient balance. Manage your billing here: https://opencode.ai/workspace/example/billing' },
12+
'401 Insufficient balance. Manage your billing here: https://opencode.ai/workspace/example/billing',
13+
new Headers({ 'x-request-id': 'req-123' }),
14+
);
15+
16+
const error = convertOpenAIError(source);
17+
18+
expect(error.code).toBe(PROVIDER_API_ERROR_CODE);
19+
expect(error.code).not.toBe(PROVIDER_AUTH_ERROR_CODE);
20+
expect('statusCode' in error && error.statusCode).toBe(401);
21+
});
22+
23+
it('still classifies a normal 401 as provider.auth_error', () => {
24+
const source = new OpenAIAPIError(401, { message: 'Invalid API key' }, '401 Invalid API key', new Headers());
25+
expect(convertOpenAIError(source).code).toBe(PROVIDER_AUTH_ERROR_CODE);
26+
});
27+
});

0 commit comments

Comments
 (0)