|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { buildUploadedFileContext } from '@/lib/mothership/chat/upload-context' |
| 3 | + |
| 4 | +describe('uploaded file discovery guidance', () => { |
| 5 | + it.each([ |
| 6 | + ['photo.png', 'image/png'], |
| 7 | + ['photo.jpeg', 'image/jpeg'], |
| 8 | + ['photo.webp', 'image/webp'], |
| 9 | + ['photo.gif', 'image/gif'], |
| 10 | + ['report.pdf', 'application/pdf'], |
| 11 | + ['photo.png', 'image/png; charset=binary'], |
| 12 | + ])('routes supported visual %s through the agent vision command', (name, mediaType) => { |
| 13 | + const { content } = buildUploadedFileContext(name, mediaType, 10) |
| 14 | + |
| 15 | + expect(content).toContain( |
| 16 | + `Inspect it with sim_cli: ${JSON.stringify({ args: ['files', 'view', `uploads/${name}`] })}` |
| 17 | + ) |
| 18 | + expect(content).not.toContain('files read') |
| 19 | + expect(content).toContain('inputs.files[].path to mount it in run_code') |
| 20 | + if (mediaType === 'application/pdf') expect(content).not.toContain('reference image') |
| 21 | + }) |
| 22 | + |
| 23 | + it.each([ |
| 24 | + ['notes.txt', 'text/plain'], |
| 25 | + ['report.md', 'text/markdown'], |
| 26 | + ['payroll.xlsx', 'application/octet-stream'], |
| 27 | + ])('retains text extraction for supported %s', (name, mediaType) => { |
| 28 | + const { content } = buildUploadedFileContext(name, mediaType, 10) |
| 29 | + |
| 30 | + expect(content).toContain(`files read "uploads/${name}"`) |
| 31 | + expect(content).not.toContain('files","view') |
| 32 | + expect(content).not.toContain('reference image') |
| 33 | + }) |
| 34 | + |
| 35 | + it.each([ |
| 36 | + ['clip.mp4', 'video/mp4'], |
| 37 | + ['audio.mp3', 'audio/mpeg'], |
| 38 | + ['drawing.svg', 'image/svg+xml'], |
| 39 | + ['scan.tiff', 'image/tiff'], |
| 40 | + ['unknown.bin', 'application/octet-stream'], |
| 41 | + ])('offers a code mount without unsupported read/view instructions for %s', (name, mediaType) => { |
| 42 | + const { content } = buildUploadedFileContext(name, mediaType, 10) |
| 43 | + |
| 44 | + expect(content).toContain(`"uploads/${name}" as inputs.files[].path to mount it in run_code.`) |
| 45 | + expect(content).not.toContain('files read') |
| 46 | + expect(content).not.toContain('files","view') |
| 47 | + expect(content).not.toContain('reference image') |
| 48 | + }) |
| 49 | + |
| 50 | + it('keeps the same encoded reference in vision and code guidance', () => { |
| 51 | + const { content } = buildUploadedFileContext('screen shot #1.png', 'image/png', 10) |
| 52 | + |
| 53 | + expect(content).toContain('"args":["files","view","uploads/screen%20shot%20%231.png"]') |
| 54 | + expect(content).toContain('"uploads/screen%20shot%20%231.png" as inputs.files[].path') |
| 55 | + }) |
| 56 | + |
| 57 | + it('retains workflow JSON import guidance', () => { |
| 58 | + const { content } = buildUploadedFileContext('workflow.json', 'application/json', 10) |
| 59 | + |
| 60 | + expect(content).toContain('files read "uploads/workflow.json"') |
| 61 | + expect(content).toContain('workflows import --workflow') |
| 62 | + }) |
| 63 | + |
| 64 | + it('retains archive extraction without suggesting direct reads or vision', () => { |
| 65 | + const { content } = buildUploadedFileContext('bundle.zip', 'application/zip', 10) |
| 66 | + |
| 67 | + expect(content).toContain('Archive "bundle.zip"') |
| 68 | + expect(content).toContain('unzip it there') |
| 69 | + expect(content).not.toContain('Read it with:') |
| 70 | + expect(content).not.toContain('Inspect it with sim_cli:') |
| 71 | + }) |
| 72 | +}) |
0 commit comments