Files
genoffice/apps/docs/tests/ai-image-sniff.test.ts
T
merrick-2002andGenOffice 6d9b6812dd Sync snapshot (2026-08-23) (#130)
- Convert scanned PDFs to editable text with local OCR, running through the operating system's own engine on macOS and Windows
- Add a much richer AI workflow to Docs, PDF, and Markdown: selection-scoped questions, batched edits, character-level edits, comment and tracked-change awareness, citations back to the source block, and in-document image generation
- Let Slides open the same presentation in a second window and edit it from both
- Improve PDF to Excel table recovery: tables spanning pages merge into one worksheet, and label/value grids and rule-less statement bands become real rows
- Fix a large wave of Word layout fidelity in Docs, Excel parity in Sheets, and PowerPoint import fidelity in Slides

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-08-23 23:10:02 +08:00

21 lines
937 B
TypeScript

import { describe, expect, it } from 'vitest'
import { sniffImageMime } from '../src/renderer/ai/tools'
// the shared ai:fetch-image handler labels every non-png/gif content-type as
// jpeg — the sniff must catch mislabeled webp/svg before they enter the docx
describe('sniffImageMime', () => {
const b64 = (bytes: string) => Buffer.from(bytes, 'binary').toString('base64')
it('identifies png, gif and jpeg by magic bytes', () => {
expect(sniffImageMime(b64('\x89PNG\r\n\x1a\n....'))).toBe('image/png')
expect(sniffImageMime(b64('GIF89a......'))).toBe('image/gif')
expect(sniffImageMime(b64('\xff\xd8\xff\xe0....JFIF'))).toBe('image/jpeg')
})
it('rejects webp and svg regardless of the reported content-type', () => {
expect(sniffImageMime(b64('RIFF\0\0\0\0WEBPVP8 '))).toBeNull()
expect(sniffImageMime(b64('<svg xmlns="ht'))).toBeNull()
expect(sniffImageMime('%%%not-base64%%%')).toBeNull()
})
})