Skip to content

Commit 7523570

Browse files
fix lint
1 parent 5b93361 commit 7523570

1 file changed

Lines changed: 70 additions & 62 deletions

File tree

apps/sim/lib/copilot/vfs/file-reader.test.ts

Lines changed: 70 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -33,66 +33,74 @@ async function makeNoisePng(width: number, height: number): Promise<Buffer> {
3333
const SHARP_TEST_TIMEOUT_MS = 30_000
3434

3535
describe('readFileRecord', () => {
36-
it('returns small images as attachments without resize note', async () => {
37-
const sharp = (await import('sharp')).default
38-
const smallPng = await sharp({
39-
create: {
40-
width: 200,
41-
height: 200,
42-
channels: 3,
43-
background: { r: 255, g: 0, b: 0 },
44-
},
45-
})
46-
.png()
47-
.toBuffer()
48-
49-
downloadWorkspaceFile.mockResolvedValue(smallPng)
50-
51-
const result = await readFileRecord({
52-
id: 'wf_small',
53-
workspaceId: 'ws_1',
54-
name: 'small.png',
55-
key: 'uploads/small.png',
56-
path: '/api/files/serve/uploads%2Fsmall.png?context=mothership',
57-
size: smallPng.length,
58-
type: 'image/png',
59-
uploadedBy: 'user_1',
60-
uploadedAt: new Date(),
61-
deletedAt: null,
62-
storageContext: 'mothership',
63-
})
64-
65-
expect(result?.attachment?.type).toBe('image')
66-
expect(result?.attachment?.source.media_type).toBe('image/png')
67-
expect(result?.content).not.toContain('resized for vision')
68-
expect(Buffer.from(result?.attachment?.source.data ?? '', 'base64')).toEqual(smallPng)
69-
}, SHARP_TEST_TIMEOUT_MS)
70-
71-
it('downscales oversized images into attachments that fit the read limit', async () => {
72-
const largePng = await makeNoisePng(1800, 1800)
73-
expect(largePng.length).toBeGreaterThan(MAX_IMAGE_READ_BYTES)
74-
75-
downloadWorkspaceFile.mockResolvedValue(largePng)
76-
77-
const result = await readFileRecord({
78-
id: 'wf_large',
79-
workspaceId: 'ws_1',
80-
name: 'chesspng.png',
81-
key: 'uploads/chesspng.png',
82-
path: '/api/files/serve/uploads%2Fchesspng.png?context=mothership',
83-
size: largePng.length,
84-
type: 'image/png',
85-
uploadedBy: 'user_1',
86-
uploadedAt: new Date(),
87-
deletedAt: null,
88-
storageContext: 'mothership',
89-
})
90-
91-
expect(result?.attachment?.type).toBe('image')
92-
expect(result?.content).toContain('resized for vision')
93-
94-
const decoded = Buffer.from(result?.attachment?.source.data ?? '', 'base64')
95-
expect(decoded.length).toBeLessThanOrEqual(MAX_IMAGE_READ_BYTES)
96-
expect(result?.attachment?.source.media_type).toMatch(/^image\/(jpeg|webp|png)$/)
97-
}, SHARP_TEST_TIMEOUT_MS)
36+
it(
37+
'returns small images as attachments without resize note',
38+
async () => {
39+
const sharp = (await import('sharp')).default
40+
const smallPng = await sharp({
41+
create: {
42+
width: 200,
43+
height: 200,
44+
channels: 3,
45+
background: { r: 255, g: 0, b: 0 },
46+
},
47+
})
48+
.png()
49+
.toBuffer()
50+
51+
downloadWorkspaceFile.mockResolvedValue(smallPng)
52+
53+
const result = await readFileRecord({
54+
id: 'wf_small',
55+
workspaceId: 'ws_1',
56+
name: 'small.png',
57+
key: 'uploads/small.png',
58+
path: '/api/files/serve/uploads%2Fsmall.png?context=mothership',
59+
size: smallPng.length,
60+
type: 'image/png',
61+
uploadedBy: 'user_1',
62+
uploadedAt: new Date(),
63+
deletedAt: null,
64+
storageContext: 'mothership',
65+
})
66+
67+
expect(result?.attachment?.type).toBe('image')
68+
expect(result?.attachment?.source.media_type).toBe('image/png')
69+
expect(result?.content).not.toContain('resized for vision')
70+
expect(Buffer.from(result?.attachment?.source.data ?? '', 'base64')).toEqual(smallPng)
71+
},
72+
SHARP_TEST_TIMEOUT_MS
73+
)
74+
75+
it(
76+
'downscales oversized images into attachments that fit the read limit',
77+
async () => {
78+
const largePng = await makeNoisePng(1800, 1800)
79+
expect(largePng.length).toBeGreaterThan(MAX_IMAGE_READ_BYTES)
80+
81+
downloadWorkspaceFile.mockResolvedValue(largePng)
82+
83+
const result = await readFileRecord({
84+
id: 'wf_large',
85+
workspaceId: 'ws_1',
86+
name: 'chesspng.png',
87+
key: 'uploads/chesspng.png',
88+
path: '/api/files/serve/uploads%2Fchesspng.png?context=mothership',
89+
size: largePng.length,
90+
type: 'image/png',
91+
uploadedBy: 'user_1',
92+
uploadedAt: new Date(),
93+
deletedAt: null,
94+
storageContext: 'mothership',
95+
})
96+
97+
expect(result?.attachment?.type).toBe('image')
98+
expect(result?.content).toContain('resized for vision')
99+
100+
const decoded = Buffer.from(result?.attachment?.source.data ?? '', 'base64')
101+
expect(decoded.length).toBeLessThanOrEqual(MAX_IMAGE_READ_BYTES)
102+
expect(result?.attachment?.source.media_type).toMatch(/^image\/(jpeg|webp|png)$/)
103+
},
104+
SHARP_TEST_TIMEOUT_MS
105+
)
98106
})

0 commit comments

Comments
 (0)