|
7 | 7 | FREEBUFF_GLM_MODEL_ID, |
8 | 8 | isFreebuffDeploymentHours, |
9 | 9 | } from '@codebuff/common/constants/freebuff-models' |
| 10 | +import { openCodeZenModels } from '@codebuff/common/constants/model-config' |
10 | 11 | import { postChatCompletions } from '../_post' |
11 | 12 | import { |
12 | 13 | checkFreeModeRateLimit, |
@@ -852,6 +853,85 @@ describe('/api/v1/chat/completions POST endpoint', () => { |
852 | 853 | FETCH_PATH_TEST_TIMEOUT_MS, |
853 | 854 | ) |
854 | 855 |
|
| 856 | + it( |
| 857 | + 'rejects OpenCode Zen models while the Zen integration is disabled', |
| 858 | + async () => { |
| 859 | + const fetchViaOpenCodeZen = mock( |
| 860 | + async (_url: string | URL | Request, _init?: RequestInit) => { |
| 861 | + throw new Error('OpenCode Zen should not be called') |
| 862 | + }, |
| 863 | + ) as unknown as typeof globalThis.fetch |
| 864 | + |
| 865 | + for (const codebuffModel of Object.values(openCodeZenModels)) { |
| 866 | + const req = new NextRequest( |
| 867 | + 'http://localhost:3000/api/v1/chat/completions', |
| 868 | + { |
| 869 | + method: 'POST', |
| 870 | + headers: { |
| 871 | + Authorization: 'Bearer test-api-key-123', |
| 872 | + }, |
| 873 | + body: JSON.stringify({ |
| 874 | + model: codebuffModel, |
| 875 | + messages: [ |
| 876 | + { |
| 877 | + role: 'system', |
| 878 | + content: 'system prompt', |
| 879 | + cache_control: { type: 'ephemeral' }, |
| 880 | + }, |
| 881 | + { |
| 882 | + role: 'user', |
| 883 | + content: [ |
| 884 | + { |
| 885 | + type: 'text', |
| 886 | + text: 'hello', |
| 887 | + cache_control: { type: 'ephemeral' }, |
| 888 | + }, |
| 889 | + ], |
| 890 | + }, |
| 891 | + ], |
| 892 | + tools: [ |
| 893 | + { |
| 894 | + id: 'tool_1', |
| 895 | + type: 'function', |
| 896 | + function: { |
| 897 | + name: 'read_files', |
| 898 | + parameters: { type: 'object' }, |
| 899 | + }, |
| 900 | + }, |
| 901 | + ], |
| 902 | + stream: false, |
| 903 | + codebuff_metadata: { |
| 904 | + run_id: 'run-123', |
| 905 | + client_id: 'test-client-id-123', |
| 906 | + }, |
| 907 | + }), |
| 908 | + }, |
| 909 | + ) |
| 910 | + |
| 911 | + const response = await postChatCompletions({ |
| 912 | + req, |
| 913 | + getUserInfoFromApiKey: mockGetUserInfoFromApiKey, |
| 914 | + logger: mockLogger, |
| 915 | + trackEvent: mockTrackEvent, |
| 916 | + getUserUsageData: mockGetUserUsageData, |
| 917 | + getAgentRunFromId: mockGetAgentRunFromId, |
| 918 | + fetch: fetchViaOpenCodeZen, |
| 919 | + insertMessageBigquery: mockInsertMessageBigquery, |
| 920 | + loggerWithContext: mockLoggerWithContext, |
| 921 | + }) |
| 922 | + |
| 923 | + const body = await response.json() |
| 924 | + expect(response.status).toBe(400) |
| 925 | + expect(body).toEqual({ |
| 926 | + error: 'opencode_zen_disabled', |
| 927 | + message: 'OpenCode Zen models are currently disabled.', |
| 928 | + }) |
| 929 | + } |
| 930 | + expect(fetchViaOpenCodeZen).not.toHaveBeenCalled() |
| 931 | + }, |
| 932 | + FETCH_PATH_TEST_TIMEOUT_MS, |
| 933 | + ) |
| 934 | + |
855 | 935 | it('rejects the DeepSeek V4 free agent when it requests another free model', async () => { |
856 | 936 | const req = new NextRequest( |
857 | 937 | 'http://localhost:3000/api/v1/chat/completions', |
|
0 commit comments