Route small images through in-memory receive instead of serialized disk chunk-acks, and improve gallery hydration for local copies and pending downloads so thumbnails display without minutes-long progress stalls. Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import {
|
|
describe,
|
|
expect,
|
|
it
|
|
} from 'vitest';
|
|
|
|
import { buildChatMessageGalleryTiles, resolveChatMessageGalleryTileState } from './chat-message-image-gallery.rules';
|
|
|
|
describe('buildChatMessageGalleryTiles', () => {
|
|
it('marks displayable, hydrating, downloading, and retry tiles from attachment state', () => {
|
|
const tiles = buildChatMessageGalleryTiles([
|
|
{
|
|
id: 'displayable',
|
|
filename: 'ready.png',
|
|
mime: 'image/png',
|
|
isImage: true,
|
|
available: true,
|
|
objectUrl: 'blob:http://localhost/ready'
|
|
},
|
|
{
|
|
id: 'hydrating',
|
|
filename: 'saved.png',
|
|
mime: 'image/png',
|
|
isImage: true,
|
|
available: false,
|
|
savedPath: '/appdata/saved.png'
|
|
},
|
|
{
|
|
id: 'partial',
|
|
filename: 'partial.png',
|
|
mime: 'image/png',
|
|
isImage: true,
|
|
available: false,
|
|
receivedBytes: 128,
|
|
size: 512
|
|
},
|
|
{
|
|
id: 'retry',
|
|
filename: 'failed.png',
|
|
mime: 'image/png',
|
|
isImage: true,
|
|
available: false,
|
|
size: 256
|
|
}
|
|
]);
|
|
|
|
expect(tiles.map((tile) => tile.state)).toEqual([
|
|
'displayable',
|
|
'hydrating',
|
|
'downloading',
|
|
'retry'
|
|
]);
|
|
});
|
|
|
|
it('treats zero-byte pending requests as downloading instead of retry', () => {
|
|
const attachment = {
|
|
id: 'pending',
|
|
filename: 'waiting.png',
|
|
mime: 'image/png',
|
|
isImage: true,
|
|
available: false,
|
|
size: 256
|
|
};
|
|
|
|
expect(resolveChatMessageGalleryTileState(attachment)).toBe('retry');
|
|
expect(resolveChatMessageGalleryTileState(attachment, { pendingRequest: true })).toBe('downloading');
|
|
});
|
|
});
|