Skip to content

Commit d7a1353

Browse files
committed
fix build, speedup tests by up to 40%
1 parent 7cc013e commit d7a1353

File tree

12 files changed

+468
-282
lines changed

12 files changed

+468
-282
lines changed

apps/sim/app/api/knowledge/search/route.test.ts

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
*
66
* @vitest-environment node
77
*/
8-
import {
9-
createEnvMock,
10-
createMockRequest,
11-
mockKnowledgeSchemas,
12-
requestUtilsMock,
13-
} from '@sim/testing'
8+
import { createEnvMock, createMockRequest, requestUtilsMock } from '@sim/testing'
149
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
1510

1611
const {
@@ -61,7 +56,74 @@ vi.mock('drizzle-orm', () => ({
6156
})),
6257
}))
6358

64-
mockKnowledgeSchemas()
59+
vi.mock('@sim/db/schema', () => ({
60+
knowledgeBase: {
61+
id: 'kb_id',
62+
userId: 'user_id',
63+
name: 'kb_name',
64+
description: 'description',
65+
tokenCount: 'token_count',
66+
embeddingModel: 'embedding_model',
67+
embeddingDimension: 'embedding_dimension',
68+
chunkingConfig: 'chunking_config',
69+
workspaceId: 'workspace_id',
70+
createdAt: 'created_at',
71+
updatedAt: 'updated_at',
72+
deletedAt: 'deleted_at',
73+
},
74+
document: {
75+
id: 'doc_id',
76+
knowledgeBaseId: 'kb_id',
77+
filename: 'filename',
78+
fileUrl: 'file_url',
79+
fileSize: 'file_size',
80+
mimeType: 'mime_type',
81+
chunkCount: 'chunk_count',
82+
tokenCount: 'token_count',
83+
characterCount: 'character_count',
84+
processingStatus: 'processing_status',
85+
processingStartedAt: 'processing_started_at',
86+
processingCompletedAt: 'processing_completed_at',
87+
processingError: 'processing_error',
88+
enabled: 'enabled',
89+
tag1: 'tag1',
90+
tag2: 'tag2',
91+
tag3: 'tag3',
92+
tag4: 'tag4',
93+
tag5: 'tag5',
94+
tag6: 'tag6',
95+
tag7: 'tag7',
96+
uploadedAt: 'uploaded_at',
97+
deletedAt: 'deleted_at',
98+
},
99+
embedding: {
100+
id: 'embedding_id',
101+
documentId: 'doc_id',
102+
knowledgeBaseId: 'kb_id',
103+
chunkIndex: 'chunk_index',
104+
content: 'content',
105+
embedding: 'embedding',
106+
tokenCount: 'token_count',
107+
characterCount: 'character_count',
108+
tag1: 'tag1',
109+
tag2: 'tag2',
110+
tag3: 'tag3',
111+
tag4: 'tag4',
112+
tag5: 'tag5',
113+
tag6: 'tag6',
114+
tag7: 'tag7',
115+
createdAt: 'created_at',
116+
},
117+
permissions: {
118+
id: 'permission_id',
119+
userId: 'user_id',
120+
entityType: 'entity_type',
121+
entityId: 'entity_id',
122+
permissionType: 'permission_type',
123+
createdAt: 'created_at',
124+
updatedAt: 'updated_at',
125+
},
126+
}))
65127

66128
vi.mock('@sim/db', () => ({
67129
db: mockDbChain,

apps/sim/app/workspace/[workspaceId]/logs/components/logs-toolbar/components/notifications/notifications.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
useConnectedAccounts,
3939
useConnectOAuthService,
4040
} from '@/hooks/queries/oauth/oauth-connections'
41+
import type { CoreTriggerType } from '@/stores/logs/filters/types'
4142
import { SlackChannelSelector } from './components/slack-channel-selector'
4243
import { WorkflowSelector } from './components/workflow-selector'
4344

@@ -427,7 +428,7 @@ export const NotificationSettings = memo(function NotificationSettings({
427428
workflowIds: formData.workflowIds,
428429
allWorkflows: formData.allWorkflows,
429430
levelFilter: formData.levelFilter,
430-
triggerFilter: formData.triggerFilter,
431+
triggerFilter: formData.triggerFilter as CoreTriggerType[],
431432
includeFinalOutput: formData.includeFinalOutput,
432433
// Trace spans only available for webhooks (too large for email/Slack)
433434
includeTraceSpans: activeTab === 'webhook' ? formData.includeTraceSpans : false,

apps/sim/lib/core/config/redis.test.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,27 @@ vi.mock('ioredis', () => ({
1414
default: MockRedisConstructor,
1515
}))
1616

17+
import {
18+
closeRedisConnection,
19+
getRedisClient,
20+
onRedisReconnect,
21+
resetForTesting,
22+
} from '@/lib/core/config/redis'
23+
1724
describe('redis config', () => {
1825
beforeEach(() => {
1926
vi.clearAllMocks()
2027
vi.useFakeTimers()
28+
resetForTesting()
29+
MockRedisConstructor.mockImplementation(() => mockRedisInstance)
2130
})
2231

2332
afterEach(() => {
2433
vi.useRealTimers()
25-
vi.resetModules()
2634
})
2735

2836
describe('onRedisReconnect', () => {
2937
it('should register and invoke reconnect listeners', async () => {
30-
const { onRedisReconnect, getRedisClient } = await import('@/lib/core/config/redis')
3138
const listener = vi.fn()
3239
onRedisReconnect(listener)
3340

@@ -41,7 +48,6 @@ describe('redis config', () => {
4148
})
4249

4350
it('should not invoke listeners when PINGs succeed', async () => {
44-
const { onRedisReconnect, getRedisClient } = await import('@/lib/core/config/redis')
4551
const listener = vi.fn()
4652
onRedisReconnect(listener)
4753

@@ -56,7 +62,6 @@ describe('redis config', () => {
5662
})
5763

5864
it('should reset failure count on successful PING', async () => {
59-
const { onRedisReconnect, getRedisClient } = await import('@/lib/core/config/redis')
6065
const listener = vi.fn()
6166
onRedisReconnect(listener)
6267

@@ -74,7 +79,6 @@ describe('redis config', () => {
7479
})
7580

7681
it('should call disconnect(true) after 2 consecutive PING failures', async () => {
77-
const { getRedisClient } = await import('@/lib/core/config/redis')
7882
getRedisClient()
7983

8084
mockRedisInstance.ping.mockRejectedValue(new Error('ETIMEDOUT'))
@@ -87,7 +91,6 @@ describe('redis config', () => {
8791
})
8892

8993
it('should handle listener errors gracefully without breaking health check', async () => {
90-
const { onRedisReconnect, getRedisClient } = await import('@/lib/core/config/redis')
9194
const badListener = vi.fn(() => {
9295
throw new Error('listener crashed')
9396
})
@@ -107,7 +110,6 @@ describe('redis config', () => {
107110

108111
describe('closeRedisConnection', () => {
109112
it('should clear the PING interval', async () => {
110-
const { getRedisClient, closeRedisConnection } = await import('@/lib/core/config/redis')
111113
getRedisClient()
112114

113115
mockRedisInstance.quit.mockResolvedValue('OK')
@@ -120,23 +122,20 @@ describe('redis config', () => {
120122
})
121123

122124
describe('retryStrategy', () => {
123-
async function captureRetryStrategy(): Promise<(times: number) => number> {
124-
vi.resetModules()
125-
125+
function captureRetryStrategy(): (times: number) => number {
126126
let capturedConfig: Record<string, unknown> = {}
127127
MockRedisConstructor.mockImplementation((_url: string, config: Record<string, unknown>) => {
128128
capturedConfig = config
129129
return { ping: vi.fn(), on: vi.fn() }
130130
})
131131

132-
const { getRedisClient } = await import('@/lib/core/config/redis')
133132
getRedisClient()
134133

135134
return capturedConfig.retryStrategy as (times: number) => number
136135
}
137136

138-
it('should use exponential backoff with jitter', async () => {
139-
const retryStrategy = await captureRetryStrategy()
137+
it('should use exponential backoff with jitter', () => {
138+
const retryStrategy = captureRetryStrategy()
140139
expect(retryStrategy).toBeDefined()
141140

142141
const delay1 = retryStrategy(1)
@@ -152,8 +151,8 @@ describe('redis config', () => {
152151
expect(delay5).toBeLessThanOrEqual(13000)
153152
})
154153

155-
it('should cap at 30s for attempts beyond 10', async () => {
156-
const retryStrategy = await captureRetryStrategy()
154+
it('should cap at 30s for attempts beyond 10', () => {
155+
const retryStrategy = captureRetryStrategy()
157156
expect(retryStrategy(11)).toBe(30000)
158157
expect(retryStrategy(100)).toBe(30000)
159158
})

apps/sim/lib/core/config/redis.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,17 @@ export async function closeRedisConnection(): Promise<void> {
194194
}
195195
}
196196
}
197+
198+
/**
199+
* Reset all module-level state. Only intended for use in tests.
200+
*/
201+
export function resetForTesting(): void {
202+
if (pingInterval) {
203+
clearInterval(pingInterval)
204+
pingInterval = null
205+
}
206+
globalRedisClient = null
207+
pingFailures = 0
208+
pingInFlight = false
209+
reconnectListeners.length = 0
210+
}

0 commit comments

Comments
 (0)