mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-21 12:55:09 +00:00
* Revert "fix(server): tolerate existing workspace dirs" This reverts commitd7e1125db3. * Revert "fix(server): support Gemini computer use requests" This reverts commit8b6483a633. * Revert "feat(agent): add reset controls for sessions and memory" This reverts commitf54eff4543. * Revert "fix: add cloud sync sign-in disclosure" This reverts commitf1ebfa5232. * Revert "fix: allow pasted images in agent text box" This reverts commitb89ea201fa. * fix(server): stabilize Hermes harness state paths * fix: address review feedback for PR #995
77 lines
2.2 KiB
TypeScript
77 lines
2.2 KiB
TypeScript
import { describe, expect, it } from 'bun:test'
|
|
import { stageAttachment } from './attachments'
|
|
|
|
function restoreGlobal(name: string, value: unknown) {
|
|
if (value === undefined) {
|
|
Reflect.deleteProperty(globalThis, name)
|
|
return
|
|
}
|
|
Reflect.set(globalThis, name, value)
|
|
}
|
|
|
|
describe('stageAttachment', () => {
|
|
it('uses the recompressed blob media type for large images', async () => {
|
|
const originalCreateImageBitmap = Reflect.get(
|
|
globalThis,
|
|
'createImageBitmap',
|
|
)
|
|
const originalOffscreenCanvas = Reflect.get(globalThis, 'OffscreenCanvas')
|
|
const originalHTMLCanvasElement = Reflect.get(
|
|
globalThis,
|
|
'HTMLCanvasElement',
|
|
)
|
|
|
|
class FakeOffscreenCanvas {
|
|
width: number
|
|
height: number
|
|
|
|
constructor(width: number, height: number) {
|
|
this.width = width
|
|
this.height = height
|
|
}
|
|
|
|
getContext() {
|
|
return {
|
|
drawImage() {},
|
|
}
|
|
}
|
|
|
|
async convertToBlob(options: { type?: string }) {
|
|
return new Blob([new Uint8Array([9, 8, 7])], {
|
|
type: options.type ?? 'image/jpeg',
|
|
})
|
|
}
|
|
}
|
|
|
|
try {
|
|
Reflect.set(globalThis, 'createImageBitmap', async () => ({
|
|
width: 4096,
|
|
height: 2048,
|
|
close() {},
|
|
}))
|
|
Reflect.set(globalThis, 'OffscreenCanvas', FakeOffscreenCanvas)
|
|
Reflect.set(globalThis, 'HTMLCanvasElement', class HTMLCanvasElement {})
|
|
|
|
const file = new File([new Uint8Array(2 * 1024 * 1024)], 'shot.png', {
|
|
type: 'image/png',
|
|
})
|
|
|
|
const result = await stageAttachment(file)
|
|
|
|
expect(result.ok).toBe(true)
|
|
if (!result.ok) throw new Error(result.error.message)
|
|
expect(result.attachment.mediaType).toBe('image/jpeg')
|
|
expect(result.attachment.dataUrl).toStartWith('data:image/jpeg;base64,')
|
|
expect(result.attachment.payload).toMatchObject({
|
|
kind: 'image',
|
|
mediaType: 'image/jpeg',
|
|
dataUrl: result.attachment.dataUrl,
|
|
})
|
|
} finally {
|
|
restoreGlobal('createImageBitmap', originalCreateImageBitmap)
|
|
restoreGlobal('OffscreenCanvas', originalOffscreenCanvas)
|
|
restoreGlobal('HTMLCanvasElement', originalHTMLCanvasElement)
|
|
}
|
|
})
|
|
})
|