test: cover probeImage error wrapping and the retreating durable boundary
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import sharp from 'sharp'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { detectImage } from '../src/image.ts'
|
||||
import { detectImage, probeImage } from '../src/image.ts'
|
||||
|
||||
async function raster(format: 'png' | 'jpeg' | 'webp' | 'gif'): Promise<Uint8Array> {
|
||||
const image = sharp({
|
||||
@@ -39,4 +39,13 @@ describe('raster decoding', () => {
|
||||
await expect(sharp(truncated).metadata()).resolves.toMatchObject({ width: 3, height: 2 })
|
||||
await expect(detectImage(truncated)).rejects.toMatchObject({ code: 'INVALID_IMAGE' })
|
||||
})
|
||||
|
||||
it('probes malformed bytes and unsupported formats into the same stable error', async () => {
|
||||
await expect(probeImage(Uint8Array.of(1, 2, 3)))
|
||||
.rejects.toMatchObject({ code: 'INVALID_IMAGE' })
|
||||
const unsupported = await sharp({
|
||||
create: { width: 1, height: 1, channels: 4, background: { r: 0, g: 0, b: 0, alpha: 1 } },
|
||||
}).tiff().toBuffer()
|
||||
await expect(probeImage(unsupported)).rejects.toMatchObject({ code: 'INVALID_IMAGE' })
|
||||
})
|
||||
})
|
||||
@@ -77,6 +77,14 @@ describe('local attachment store', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('retreats the durable boundary to the closest existing ancestor when the home directory does not exist yet', async () => {
|
||||
const storageRoot = join(await root(), 'home', 'attachments', 'v1')
|
||||
|
||||
const ref = await saveImageFile(storageRoot, { data: PNG, mediaType: 'image/png' }, LIMITS)
|
||||
|
||||
await expect(readImageFile(storageRoot, ref)).resolves.toEqual({ ref, data: PNG })
|
||||
})
|
||||
|
||||
it('publishes one private content-addressed object and deduplicates equal bytes', async () => {
|
||||
const storageRoot = await root()
|
||||
const first = await saveImageFile(storageRoot, {
|
||||
|
||||
Reference in New Issue
Block a user