Skip to content

Commit be0228e

Browse files
committed
test(execution): make RateLimiter mock constructable under vitest 4.x
The RateLimiter mock used an arrow factory (vi.fn(() => ({...}))). vitest 4.x (CI) rejects `new` on an arrow-implemented mock ("not a constructor"); 3.2.4 allowed it. The new rate-gate test is the first to actually `new RateLimiter()`, so it surfaced the failure only in CI. Switch the mock to a regular function and drop the speculative beforeEach re-establishments that didn't address it.
1 parent de40ca6 commit be0228e

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ vi.mock('@/lib/core/execution-limits', () => ({
2828
getExecutionTimeout: vi.fn(() => 0),
2929
}))
3030
vi.mock('@/lib/core/rate-limiter/rate-limiter', () => ({
31-
RateLimiter: vi.fn(() => ({ checkRateLimitWithSubscription: mockCheckRateLimit })),
31+
// Regular function (not an arrow) so `new RateLimiter()` is constructable under
32+
// vitest 4.x, which rejects `new` on an arrow-implemented mock.
33+
RateLimiter: vi.fn(function (this: unknown) {
34+
return { checkRateLimitWithSubscription: mockCheckRateLimit }
35+
}),
3236
}))
3337
vi.mock('@/lib/logs/execution/logging-session', () => loggingSessionMock)
3438
vi.mock('@/lib/workspaces/utils', () => ({
@@ -44,10 +48,7 @@ vi.mock('@sim/workflow-authz', () => ({
4448
}),
4549
}))
4650

47-
import {
48-
checkOrgMemberUsageLimit,
49-
checkServerSideUsageLimits,
50-
} from '@/lib/billing/calculations/usage-monitor'
51+
import { checkServerSideUsageLimits } from '@/lib/billing/calculations/usage-monitor'
5152
import { getHighestPrioritySubscription } from '@/lib/billing/core/subscription'
5253
import { preprocessExecution } from './preprocessing'
5354

@@ -128,7 +129,6 @@ describe('preprocessExecution logPreprocessingErrors option', () => {
128129
remaining: 100,
129130
resetAt: new Date(),
130131
})
131-
vi.mocked(checkOrgMemberUsageLimit).mockResolvedValue({ isExceeded: false } as any)
132132
})
133133

134134
it('suppresses preprocessing-error logging when logPreprocessingErrors is false', async () => {
@@ -178,7 +178,6 @@ describe('preprocessExecution ban gate', () => {
178178
currentUsage: 1,
179179
limit: 10,
180180
} as any)
181-
vi.mocked(checkOrgMemberUsageLimit).mockResolvedValue({ isExceeded: false } as any)
182181
})
183182

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

0 commit comments

Comments
 (0)