Skip to content

Commit de40ca6

Browse files
committed
test(execution,providers): fix preflight mock reset + isolate provider client cache in tests
- preprocessing.test: re-establish the checkOrgMemberUsageLimit mock in beforeEach (the only gate mock not re-set). In the full suite its implementation was reset so the success-path test got undefined -> threw -> 500 -> success:false. Mirrors how checkServerSideUsageLimits is handled. - client-cache: add clearProviderClientCacheForTests; call it in the bedrock and vllm test beforeEach so construction assertions always start from a cache miss now that those providers memoize their client.
1 parent 0a269ad commit de40ca6

4 files changed

Lines changed: 15 additions & 1 deletion

File tree

apps/sim/lib/execution/preprocessing.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ vi.mock('@sim/workflow-authz', () => ({
4444
}),
4545
}))
4646

47-
import { checkServerSideUsageLimits } from '@/lib/billing/calculations/usage-monitor'
47+
import {
48+
checkOrgMemberUsageLimit,
49+
checkServerSideUsageLimits,
50+
} from '@/lib/billing/calculations/usage-monitor'
4851
import { getHighestPrioritySubscription } from '@/lib/billing/core/subscription'
4952
import { preprocessExecution } from './preprocessing'
5053

@@ -125,6 +128,7 @@ describe('preprocessExecution logPreprocessingErrors option', () => {
125128
remaining: 100,
126129
resetAt: new Date(),
127130
})
131+
vi.mocked(checkOrgMemberUsageLimit).mockResolvedValue({ isExceeded: false } as any)
128132
})
129133

130134
it('suppresses preprocessing-error logging when logPreprocessingErrors is false', async () => {
@@ -174,6 +178,7 @@ describe('preprocessExecution ban gate', () => {
174178
currentUsage: 1,
175179
limit: 10,
176180
} as any)
181+
vi.mocked(checkOrgMemberUsageLimit).mockResolvedValue({ isExceeded: false } as any)
177182
})
178183

179184
it('blocks execution with 403 when the actor is banned (ban wins over the parallel gates)', async () => {

apps/sim/providers/bedrock/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ vi.mock('@/tools', () => ({
5050

5151
import { BedrockRuntimeClient } from '@aws-sdk/client-bedrock-runtime'
5252
import { bedrockProvider } from '@/providers/bedrock/index'
53+
import { clearProviderClientCacheForTests } from '@/providers/client-cache'
5354

5455
describe('bedrockProvider credential handling', () => {
5556
beforeEach(() => {
5657
vi.clearAllMocks()
58+
clearProviderClientCacheForTests()
5759
mockSend.mockResolvedValue({
5860
output: { message: { content: [{ text: 'response' }] } },
5961
usage: { inputTokens: 10, outputTokens: 5 },

apps/sim/providers/client-cache.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ export function getCachedProviderClient<T extends object>(key: string, factory:
2929
clientCache.set(key, client)
3030
return client
3131
}
32+
33+
/** Clears the cache so tests asserting client construction start from a miss. */
34+
export function clearProviderClientCacheForTests(): void {
35+
clientCache.clear()
36+
}

apps/sim/providers/vllm/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ vi.mock('@/stores/providers', () => ({
7979
useProvidersStore: { getState: () => ({ setProviderModels: vi.fn() }) },
8080
}))
8181

82+
import { clearProviderClientCacheForTests } from '@/providers/client-cache'
8283
import type { ProviderToolConfig } from '@/providers/types'
8384
import { vllmProvider } from '@/providers/vllm/index'
8485

@@ -117,6 +118,7 @@ const createPayload = (callIndex: number) => mockCreate.mock.calls[callIndex][0]
117118
describe('vllmProvider', () => {
118119
beforeEach(() => {
119120
vi.clearAllMocks()
121+
clearProviderClientCacheForTests()
120122
openAIArgs.length = 0
121123
envState.VLLM_BASE_URL = 'http://localhost:8000'
122124
envState.VLLM_API_KEY = undefined

0 commit comments

Comments
 (0)