Skip to content

Commit 016cd67

Browse files
icecrasher321waleedlatif1aadamgoughAdam GoughVikhyath Mondreti
authored
v0.2.6: fix + feat + improvement (#612)
* feat(function): added more granular error logs for function execution for easier debugging (#593) * added more granular error logs for function execution * added tests * fixed syntax error reporting * feat(models): added temp controls for gpt-4.1 family of models (#594) * improvement(knowledge-upload): create and upload document to KB (#579) * improvement: added knowledge upload * improvement: added greptile comments (#579) * improvement: changed to text to doc (#579) * improvement: removed comment (#579) * added input validation, tested persistence of KB selector * update docs --------- Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net> Co-authored-by: Waleed Latif <walif6@gmail.com> * fix(remove workflow.state usage): no more usage of deprecated state column in any routes (#586) * fix(remove workflow.state usage): no more usage of deprecated state col in routes * fix lint * fix chat route to only use deployed state * fix lint * better typing * remove useless logs * fix lint * restore workflow handler file * removed all other usages of deprecated 'state' column from workflows table, updated tests --------- Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local> Co-authored-by: Waleed Latif <walif6@gmail.com> * fix(doc-selector-kb): enable doc selector when kb is selected (#596) Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan> * fix(unload): remove beforeunload warning since we communicate via wss (#597) * fix(executor): fix dependency resolution, allow blocks with multiple inputs to execute (#598) * feat(billing): added migrations for usage-based billing (#601) * feat(billing): added migrations for usage-based billing * lint * lint * feat(logging): add new schemas + types for new logging system (#599) * feat(logging): add new schemas + types for logging * fix lint * update migration * fix lint * Remove migration 48 to avoid conflict with staging * fixed merge conflict * fix lint --------- Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net> * fix(createWorkflow): cleanup create workflow to prevent re-renders (#607) * fix(createWorkflow): no more client side id, duplicate schedules calls * fix lint * more cleanup * fix lint * fix spamming of create button causing issues * fix lint * add more colors + default workflow name changed * Update apps/sim/stores/workflows/registry/utils.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --------- Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * fix(telegram): added markdown text rendering (#611) * fix: added proper markdown * fix: reverted route.ts file --------- Co-authored-by: Adam Gough <adamgough@Adams-MacBook-Pro.local> * fix(kb-upload): fix and consolidate KB file uploads logic (#610) * fix(kb-upload): fix and consolidate logic * fix lint * consolidated presigned routes, fixed temp id kb store issue, added nav to next/prev chunk on edit chunk modal * fix ci test --------- Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan> Co-authored-by: Waleed Latif <walif6@gmail.com> --------- Co-authored-by: Waleed Latif <walif6@gmail.com> Co-authored-by: Adam Gough <77861281+aadamgough@users.noreply.github.com> Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net> Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local> Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan> Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: Adam Gough <adamgough@Adams-MacBook-Pro.local>
1 parent 3b98253 commit 016cd67

File tree

20 files changed

+1581
-825
lines changed

20 files changed

+1581
-825
lines changed

apps/sim/app/api/__test-utils__/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,20 @@ export function createStorageProviderMocks(options: StorageProviderMockOptions =
764764
bucket: 'test-s3-bucket',
765765
region: 'us-east-1',
766766
},
767+
S3_KB_CONFIG: {
768+
bucket: 'test-s3-kb-bucket',
769+
region: 'us-east-1',
770+
},
771+
BLOB_CONFIG: {
772+
accountName: 'testaccount',
773+
accountKey: 'testkey',
774+
containerName: 'test-container',
775+
},
776+
BLOB_KB_CONFIG: {
777+
accountName: 'testaccount',
778+
accountKey: 'testkey',
779+
containerName: 'test-kb-container',
780+
},
767781
}))
768782

769783
vi.doMock('@aws-sdk/client-s3', () => ({
@@ -806,6 +820,11 @@ export function createStorageProviderMocks(options: StorageProviderMockOptions =
806820
accountKey: 'testkey',
807821
containerName: 'test-container',
808822
},
823+
BLOB_KB_CONFIG: {
824+
accountName: 'testaccount',
825+
accountKey: 'testkey',
826+
containerName: 'test-kb-container',
827+
},
809828
}))
810829

811830
vi.doMock('@azure/storage-blob', () => ({

apps/sim/app/api/files/presigned/route.test.ts

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ describe('/api/files/presigned', () => {
3939
const response = await POST(request)
4040
const data = await response.json()
4141

42-
expect(response.status).toBe(400)
42+
expect(response.status).toBe(500) // Changed from 400 to 500 (StorageConfigError)
4343
expect(data.error).toBe('Direct uploads are only available when cloud storage is enabled')
44+
expect(data.code).toBe('STORAGE_CONFIG_ERROR')
4445
expect(data.directUploadSupported).toBe(false)
4546
})
4647

@@ -64,7 +65,8 @@ describe('/api/files/presigned', () => {
6465
const data = await response.json()
6566

6667
expect(response.status).toBe(400)
67-
expect(data.error).toBe('Missing fileName or contentType')
68+
expect(data.error).toBe('fileName is required and cannot be empty')
69+
expect(data.code).toBe('VALIDATION_ERROR')
6870
})
6971

7072
it('should return error when contentType is missing', async () => {
@@ -87,7 +89,59 @@ describe('/api/files/presigned', () => {
8789
const data = await response.json()
8890

8991
expect(response.status).toBe(400)
90-
expect(data.error).toBe('Missing fileName or contentType')
92+
expect(data.error).toBe('contentType is required and cannot be empty')
93+
expect(data.code).toBe('VALIDATION_ERROR')
94+
})
95+
96+
it('should return error when fileSize is invalid', async () => {
97+
setupFileApiMocks({
98+
cloudEnabled: true,
99+
storageProvider: 's3',
100+
})
101+
102+
const { POST } = await import('./route')
103+
104+
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
105+
method: 'POST',
106+
body: JSON.stringify({
107+
fileName: 'test.txt',
108+
contentType: 'text/plain',
109+
fileSize: 0,
110+
}),
111+
})
112+
113+
const response = await POST(request)
114+
const data = await response.json()
115+
116+
expect(response.status).toBe(400)
117+
expect(data.error).toBe('fileSize must be a positive number')
118+
expect(data.code).toBe('VALIDATION_ERROR')
119+
})
120+
121+
it('should return error when file size exceeds limit', async () => {
122+
setupFileApiMocks({
123+
cloudEnabled: true,
124+
storageProvider: 's3',
125+
})
126+
127+
const { POST } = await import('./route')
128+
129+
const largeFileSize = 150 * 1024 * 1024 // 150MB (exceeds 100MB limit)
130+
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
131+
method: 'POST',
132+
body: JSON.stringify({
133+
fileName: 'large-file.txt',
134+
contentType: 'text/plain',
135+
fileSize: largeFileSize,
136+
}),
137+
})
138+
139+
const response = await POST(request)
140+
const data = await response.json()
141+
142+
expect(response.status).toBe(400)
143+
expect(data.error).toContain('exceeds maximum allowed size')
144+
expect(data.code).toBe('VALIDATION_ERROR')
91145
})
92146

93147
it('should generate S3 presigned URL successfully', async () => {
@@ -122,6 +176,34 @@ describe('/api/files/presigned', () => {
122176
expect(data.directUploadSupported).toBe(true)
123177
})
124178

179+
it('should generate knowledge-base S3 presigned URL with kb prefix', async () => {
180+
setupFileApiMocks({
181+
cloudEnabled: true,
182+
storageProvider: 's3',
183+
})
184+
185+
const { POST } = await import('./route')
186+
187+
const request = new NextRequest(
188+
'http://localhost:3000/api/files/presigned?type=knowledge-base',
189+
{
190+
method: 'POST',
191+
body: JSON.stringify({
192+
fileName: 'knowledge-doc.pdf',
193+
contentType: 'application/pdf',
194+
fileSize: 2048,
195+
}),
196+
}
197+
)
198+
199+
const response = await POST(request)
200+
const data = await response.json()
201+
202+
expect(response.status).toBe(200)
203+
expect(data.fileInfo.key).toMatch(/^kb\/.*knowledge-doc\.pdf$/)
204+
expect(data.directUploadSupported).toBe(true)
205+
})
206+
125207
it('should generate Azure Blob presigned URL successfully', async () => {
126208
setupFileApiMocks({
127209
cloudEnabled: true,
@@ -182,8 +264,9 @@ describe('/api/files/presigned', () => {
182264
const response = await POST(request)
183265
const data = await response.json()
184266

185-
expect(response.status).toBe(400)
186-
expect(data.error).toBe('Unknown storage provider')
267+
expect(response.status).toBe(500) // Changed from 400 to 500 (StorageConfigError)
268+
expect(data.error).toBe('Unknown storage provider: unknown') // Updated error message
269+
expect(data.code).toBe('STORAGE_CONFIG_ERROR')
187270
expect(data.directUploadSupported).toBe(false)
188271
})
189272

@@ -225,8 +308,10 @@ describe('/api/files/presigned', () => {
225308
const data = await response.json()
226309

227310
expect(response.status).toBe(500)
228-
expect(data.error).toBe('Error')
229-
expect(data.message).toBe('S3 service unavailable')
311+
expect(data.error).toBe(
312+
'Failed to generate S3 presigned URL - check AWS credentials and permissions'
313+
) // Updated error message
314+
expect(data.code).toBe('STORAGE_CONFIG_ERROR')
230315
})
231316

232317
it('should handle Azure Blob errors gracefully', async () => {
@@ -269,8 +354,8 @@ describe('/api/files/presigned', () => {
269354
const data = await response.json()
270355

271356
expect(response.status).toBe(500)
272-
expect(data.error).toBe('Error')
273-
expect(data.message).toBe('Azure service unavailable')
357+
expect(data.error).toBe('Failed to generate Azure Blob presigned URL') // Updated error message
358+
expect(data.code).toBe('STORAGE_CONFIG_ERROR')
274359
})
275360

276361
it('should handle malformed JSON gracefully', async () => {
@@ -289,9 +374,9 @@ describe('/api/files/presigned', () => {
289374
const response = await POST(request)
290375
const data = await response.json()
291376

292-
expect(response.status).toBe(500)
293-
expect(data.error).toBe('SyntaxError')
294-
expect(data.message).toContain('Unexpected token')
377+
expect(response.status).toBe(400) // Changed from 500 to 400 (ValidationError)
378+
expect(data.error).toBe('Invalid JSON in request body') // Updated error message
379+
expect(data.code).toBe('VALIDATION_ERROR')
295380
})
296381
})
297382

0 commit comments

Comments
 (0)