Skip to content

Commit 371ca3c

Browse files
committed
fix tests
1 parent 3deb167 commit 371ca3c

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

web/src/app/api/v1/chat/completions/__tests__/completions.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import {
99
} from '@codebuff/common/constants/freebuff-models'
1010
import { openCodeZenModels } from '@codebuff/common/constants/model-config'
1111
import { postChatCompletions } from '../_post'
12-
import {
13-
checkFreeModeRateLimit,
14-
resetFreeModeRateLimits,
15-
} from '../free-mode-rate-limiter'
12+
import { resetFreeModeRateLimits } from '../free-mode-rate-limiter'
1613

1714
import type { TrackEventFn } from '@codebuff/common/types/contracts/analytics'
1815
import type { InsertMessageBigqueryFn } from '@codebuff/common/types/contracts/bigquery'
@@ -1148,6 +1145,11 @@ describe('/api/v1/chat/completions POST endpoint', () => {
11481145
})
11491146

11501147
it('requires an active session check for the Gemini thinker subagent', async () => {
1148+
const checkFreeModeRateLimitForTest = mock((userId: string) => {
1149+
expect(userId).toBe('user-new-free-gemini')
1150+
return { limited: false as const }
1151+
})
1152+
11511153
const response = await postChatCompletions({
11521154
req: new NextRequest('http://localhost:3000/api/v1/chat/completions', {
11531155
method: 'POST',
@@ -1177,11 +1179,11 @@ describe('/api/v1/chat/completions POST endpoint', () => {
11771179
expect(params.claimedInstanceId).toBe('inst-123')
11781180
return { ok: true, reason: 'active', remainingMs: 60_000 }
11791181
},
1182+
checkFreeModeRateLimit: checkFreeModeRateLimitForTest,
11801183
})
11811184

11821185
expect(response.status).toBe(200)
1183-
expect(checkFreeModeRateLimit('user-new-free-gemini').limited).toBe(false)
1184-
expect(checkFreeModeRateLimit('user-new-free-gemini').limited).toBe(true)
1186+
expect(checkFreeModeRateLimitForTest).toHaveBeenCalledTimes(1)
11851187
})
11861188

11871189
it(

web/src/llm-api/opencode-zen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ const OPENCODE_ZEN_MODELS: Record<
5858

5959
const OPENCODE_ZEN_MODEL_PREFIX = 'opencode/'
6060

61-
export function isOpenCodeZenModel(model: string): boolean {
62-
return model.startsWith(OPENCODE_ZEN_MODEL_PREFIX)
61+
export function isOpenCodeZenModel(model: unknown): model is string {
62+
return typeof model === 'string' && model.startsWith(OPENCODE_ZEN_MODEL_PREFIX)
6363
}
6464

6565
function getOpenCodeZenModelId(model: string): string {

0 commit comments

Comments
 (0)