openpencil/tests/engine/tools/export-image.test.ts
Danila Poyarkov 8294e32f33 feat(ai): add isolated visual inspection
- Route bounded selection renders through the optional Vision model

- Return compact text findings without retaining image data in Design chat history

- Bound MCP and AI image exports by their longest pixel edge
2026-08-13 21:15:44 +03:00

60 lines
1.6 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { getTool, setupToolTest } from '#tests/helpers/tools'
type ExportImageResult = {
width?: unknown
height?: unknown
scale?: unknown
}
function exportImageResult(value: unknown): ExportImageResult {
return typeof value === 'object' && value !== null ? value : {}
}
describe('export_image tool', () => {
test('bounds model-facing image output by its longest edge without upscaling', async () => {
const { figma } = setupToolTest()
const frame = figma.createFrame()
frame.resize(2560, 1600)
const calls: Array<{ scale?: number; format?: string }> = []
figma.exportImage = async (_ids, options) => {
calls.push(options)
return new Uint8Array([1, 2, 3])
}
const result = exportImageResult(
await getTool('export_image').execute(figma, {
ids: [frame.id],
format: 'PNG',
scale: 2,
maxEdge: 1280
})
)
expect(calls).toEqual([{ scale: 0.5, format: 'PNG' }])
expect(result.width).toBe(1280)
expect(result.height).toBe(800)
expect(result.scale).toBe(0.5)
})
test('keeps the requested scale when the image already fits', async () => {
const { figma } = setupToolTest()
const frame = figma.createFrame()
frame.resize(640, 400)
const calls: Array<{ scale?: number; format?: string }> = []
figma.exportImage = async (_ids, options) => {
calls.push(options)
return new Uint8Array([1])
}
await getTool('export_image').execute(figma, {
ids: [frame.id],
scale: 1,
maxEdge: 1280
})
expect(calls[0]?.scale).toBe(1)
})
})