The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: trim salvage tests to invariants
teknium181235c9add42
diff --git a/apps/desktop/src/components/assistant-ui/tool/fallback-vision-image.test.tsx b/apps/desktop/src/components/assistant-ui/tool/fallback-vision-image.test.tsxindex f1b4787f40b..cf0806d96d2 100644--- a/apps/desktop/src/components/assistant-ui/tool/fallback-vision-image.test.tsx+++ b/apps/desktop/src/components/assistant-ui/tool/fallback-vision-image.test.tsx@@ -82,31 +82,6 @@ describe('vision_analyze activity image', () => {expect(await screen.findByRole('dialog')).toBeTruthy()})- it('keeps a cold portrait image contained in its fixed frame instead of overriding its size', async () => {- $connection.set({ mode: 'local' } as never)- renderVisionRow()-- fireEvent.click(screen.getByRole('button', { expanded: false }))-- const img = await screen.findByRole('img')-- await waitFor(() => expect(img.getAttribute('src')).toBe(DATA_URL))- Object.defineProperties(img, { naturalWidth: { value: 400 }, naturalHeight: { value: 800 } })- fireEvent.load(img)-- // A cold image has no intrinsic dimensions yet, so its frame keeps the- // fallback shape and the image must fit inside it rather than size itself.- const frame = img.closest<HTMLElement>('[data-slot="aui_markdown-image"]')!-- expect(parseFloat(frame.style.aspectRatio)).toBeCloseTo(16 / 9)- expect(img.classList).toContain('size-full')- expect(img.classList).toContain('object-contain')-- for (const override of ['h-auto', 'w-full', 'object-cover']) {- expect(img.classList).not.toContain(override)- }- })-it('reads a remote-gateway image through the profile-scoped fs API, never the local reader', async () => {$connection.set({ mode: 'remote', profile: 'wsl-work' } as never)renderVisionRow()diff --git a/apps/desktop/src/components/chat/image-geometry-lifecycle.test.tsx b/apps/desktop/src/components/chat/image-geometry-lifecycle.test.tsxdeleted file mode 100644index a93ef186266..00000000000--- a/apps/desktop/src/components/chat/image-geometry-lifecycle.test.tsx+++ /dev/null@@ -1,106 +0,0 @@-import { act, cleanup, fireEvent, render, renderHook } from '@testing-library/react'-import { afterEach, beforeEach, expect, it, vi } from 'vitest'--import { ComposerScopeProvider, MAIN_COMPOSER_SCOPE } from '@/app/chat/composer/scope'-import { useMediaImage } from '@/hooks/use-media-image'-import { mediaImageKey, rememberMediaImageDimensions } from '@/lib/media'-import { $connection } from '@/store/session'--import { GeneratedImage } from './generated-image-result'--vi.mock('./image-generation-placeholder', () => ({ DiffusionCanvas: () => null }))--const data = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"/>'-let reads: Array<(value: string) => void>-const read = vi.fn(() => new Promise<string>(resolve => reads.push(resolve)))--beforeEach(() => {- reads = []- read.mockClear()- vi.stubGlobal('hermesDesktop', { readFileDataUrl: read, api: vi.fn(() => read().then(dataUrl => ({ dataUrl }))) })- $connection.set({ connectionId: 'lifecycle-local', mode: 'local', profile: 'a' } as never)-})--afterEach(() => {- cleanup()- $connection.set(null)- vi.unstubAllGlobals()-})--function frame(container: HTMLElement) {- return container.querySelector<HTMLElement>('[data-slot="aui_generated-image"]')!-}--async function decode(container: HTMLElement, width: number, height: number) {- await act(async () => reads.shift()!(data))- const img = container.querySelector('img')!- Object.defineProperties(img, { naturalWidth: { value: width }, naturalHeight: { value: height } })- fireEvent.load(img)-}--it.each([- { name: 'result metadata', width: 900, height: 600, cached: false },- { name: 'warm cache', width: 800, height: 800, cached: true },- { name: 'same aspect but smaller intrinsic width', width: 160, height: 90, cached: false }-])('keeps the pending frame when the result arrives with $name', async ({ name, width, height, cached }) => {- const path = `/lifecycle/${name}.svg`- const result = { success: true, image: path, pixel_size: cached ? undefined : `${width}x${height}` }-- if (cached) {- rememberMediaImageDimensions(mediaImageKey(path, $connection.get()), width, height)- }-- const mounted = render(<GeneratedImage aspectRatio="landscape" />)- const pendingStyle = frame(mounted.container).style.cssText- mounted.rerender(<GeneratedImage aspectRatio="landscape" result={result} />)-- // This must hold before the file read settles, not just after img.onload.- expect(frame(mounted.container).style.cssText).toBe(pendingStyle)- expect(mounted.container.querySelector('img')).toBeNull()- await decode(mounted.container, width, height)- expect(frame(mounted.container).style.cssText).toBe(pendingStyle)- mounted.unmount()-- // A fresh mount of the completed result still benefits from intrinsic size.- const warm = render(<GeneratedImage aspectRatio="landscape" result={result} />)- expect(parseFloat(frame(warm.container).style.aspectRatio)).toBeCloseTo(width / height)- const warmStyle = frame(warm.container).style.cssText- await decode(warm.container, width, height)- fireEvent.error(warm.container.querySelector('img')!)- expect(frame(warm.container).style.cssText).toBe(warmStyle)-})--it.each([- { connectionId: 'owner-b', profile: 'a' },- { connectionId: 'owner-a', profile: 'b' }-])('does not inherit a pending frame across owner $connectionId/$profile', owner => {- const view = (connectionId: string, profile: string, result?: unknown) => (- <ComposerScopeProvider value={{ ...MAIN_COMPOSER_SCOPE, connectionId, profile }}>- <GeneratedImage aspectRatio="landscape" result={result} />- </ComposerScopeProvider>- )-- const mounted = render(view('owner-a', 'a'))- mounted.rerender(view(owner.connectionId, owner.profile, { image: '/lifecycle/other.svg', pixel_size: '600x900' }))- expect(parseFloat(frame(mounted.container).style.aspectRatio)).toBeCloseTo(600 / 900)-})--it('still resets the frame between two actual image sources', () => {- const mounted = render(<GeneratedImage result={{ image: '/lifecycle/first.svg', pixel_size: '900x600' }} />)- mounted.rerender(<GeneratedImage result={{ image: '/lifecycle/second.svg', pixel_size: '600x900' }} />)- expect(parseFloat(frame(mounted.container).style.aspectRatio)).toBeCloseTo(600 / 900)-})--it('does not reserve an empty markdown image unless the caller opts in', () => {- const mounted = renderHook(- ({ path }) => useMediaImage(path, 16 / 9, path ? { width: 600, height: 900 } : undefined),- {- initialProps: { path: '' }- }- )-- expect(mounted.result.current.frameStyle.aspectRatio).toBeCloseTo(16 / 9)- // Markdown callers keep the default source-based lifetime.- mounted.rerender({ path: '/lifecycle/markdown.svg' })- expect(mounted.result.current.frameStyle.aspectRatio).toBeCloseTo(600 / 900)-})diff --git a/apps/desktop/src/components/chat/image-geometry.test.tsx b/apps/desktop/src/components/chat/image-geometry.test.tsxindex d2dfdc6aad4..b78f070cbe9 100644--- a/apps/desktop/src/components/chat/image-geometry.test.tsx+++ b/apps/desktop/src/components/chat/image-geometry.test.tsx@@ -96,6 +96,18 @@ it.each(cases)('reserves $kind frames through cold decode, warm return and failuexpect(warm.container.textContent).toMatch(/Open image/i)})+it('keeps the pending generated-image frame when its result arrives', async () => {+ const path = '/geometry/pending.svg'+ const mounted = render(<GeneratedImage aspectRatio="landscape" />)+ const pendingStyle = frame(mounted.container).style.cssText+ mounted.rerender(<GeneratedImage aspectRatio="landscape" result={{ success: true, image: path, pixel_size: '900x600' }} />)++ // Must hold before the file read settles, not just after img.onload.+ expect(frame(mounted.container).style.cssText).toBe(pendingStyle)+ await decode(mounted.container, 900, 600)+ expect(frame(mounted.container).style.cssText).toBe(pendingStyle)+})+it.each(['markdown', 'generated'])('%s dimensions follow owner and source, not stale reads or hints', async kind => {const path = `${paths.second}?${kind}`diff --git a/apps/desktop/src/lib/generated-images.test.ts b/apps/desktop/src/lib/generated-images.test.tsindex 7eb1e85cbf5..7fb32105104 100644--- a/apps/desktop/src/lib/generated-images.test.ts+++ b/apps/desktop/src/lib/generated-images.test.ts@@ -2,30 +2,12 @@ import { describe, expect, it } from 'vitest'import {dedupeGeneratedImageEchoesInParts,- generatedImageDimensionsFromResult,generatedImageEchoSources,generatedImageFromResult,stripGeneratedImageEchoes} from './generated-images'describe('generatedImageFromResult', () => {- it('uses decoded pixel_size, never requested sizing, for intrinsic geometry', () => {- const dimensions = { width: 900, height: 600 }-- const result = {- success: true,- image: '/image.png',- pixel_size: `${dimensions.width}x${dimensions.height}`,- size: '1024x1024'- }-- expect(generatedImageDimensionsFromResult(JSON.stringify(result))).toEqual(dimensions)-- for (const pixel_size of [undefined, 'auto', '0x600', '9'.repeat(400) + 'x600']) {- expect(generatedImageDimensionsFromResult({ ...result, pixel_size })).toBeUndefined()- }- })-it('prefers the host-visible image path', () => {expect(generatedImageFromResult({diff --git a/apps/desktop/src/lib/media-owner-routing.test.ts b/apps/desktop/src/lib/media-owner-routing.test.tsdeleted file mode 100644index 04861c66439..00000000000--- a/apps/desktop/src/lib/media-owner-routing.test.ts+++ /dev/null@@ -1,56 +0,0 @@-import { afterEach, beforeEach, expect, it, vi } from 'vitest'--import { setApiRequestConnection } from '@/api/client'-import { $connection } from '@/store/session'--import { resolveMediaDisplaySrc } from './media'--const localData = 'data:image/png;base64,bG9jYWw='-const remoteData = 'data:image/png;base64,cmVtb3Rl'-const read = vi.fn(async () => localData)-const api = vi.fn(async () => ({ dataUrl: remoteData }))--beforeEach(() => {- read.mockClear()- api.mockReset()- api.mockResolvedValue({ dataUrl: remoteData })- vi.stubGlobal('hermesDesktop', { readFileDataUrl: read, api })- $connection.set({ connectionId: 'foreground-remote', mode: 'remote', profile: 'active' } as never)- setApiRequestConnection('foreground-remote')-})--afterEach(() => {- $connection.set(null)- setApiRequestConnection(null)- vi.unstubAllGlobals()-})--it('uses the native bridge for an explicit local owner, even with a remote foreground', async () => {- await expect(resolveMediaDisplaySrc('/local/image.png', { connectionId: 'local', profile: 'work' })).resolves.toBe(- localData- )- expect(read).toHaveBeenCalledTimes(1)- expect(read).toHaveBeenCalledWith('/local/image.png')- expect(api).not.toHaveBeenCalled()-})--it('keeps an explicit remote owner pinned to the API', async () => {- await expect(- resolveMediaDisplaySrc('/remote/image.png', { connectionId: 'owner-remote', profile: 'work' })- ).resolves.toBe(remoteData)- expect(api).toHaveBeenCalledTimes(1)- expect(api).toHaveBeenCalledWith({- connectionId: 'owner-remote',- profile: 'work',- path: '/api/fs/read-data-url?path=%2Fremote%2Fimage.png'- })- expect(read).not.toHaveBeenCalled()-})--it('never falls back to this device after a remote owner read fails', async () => {- api.mockRejectedValueOnce(new Error('remote read failed'))- await expect(- resolveMediaDisplaySrc('/same/path.png', { connectionId: 'owner-remote', profile: 'work' })- ).rejects.toThrow('remote read failed')- expect(read).not.toHaveBeenCalled()-})