fix: Bug - Attachments gets syncronized corrupt
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { createHash, randomBytes } from 'node:crypto';
|
||||
import { type Page } from '@playwright/test';
|
||||
import {
|
||||
test,
|
||||
@@ -182,6 +183,28 @@ test.describe('Chat messaging features', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('syncs multi-chunk image attachments byte-identical between users', async ({ createClient }) => {
|
||||
const scenario = await createChatScenario(createClient);
|
||||
const imageName = `${uniqueName('photo')}.svg`;
|
||||
const imageCaption = `Large image upload ${uniqueName('caption')}`;
|
||||
// Several P2P file chunks (64 KiB each) - regression coverage for transfers
|
||||
// that previously finalized with only the first chunks received.
|
||||
const { payload, sha256 } = createMultiChunkImagePayload(imageName);
|
||||
|
||||
await test.step('Alice sends a multi-chunk image attachment', async () => {
|
||||
await scenario.aliceMessages.attachFiles([payload]);
|
||||
await scenario.aliceMessages.sendMessage(imageCaption);
|
||||
|
||||
await scenario.aliceMessages.expectMessageImageLoaded(imageName);
|
||||
await scenario.aliceMessages.expectMessageImageContentSha256(imageName, sha256);
|
||||
});
|
||||
|
||||
await test.step('Bob receives the image fully and byte-identical', async () => {
|
||||
await expect(scenario.bobMessages.getMessageItemByText(imageCaption)).toBeVisible({ timeout: 20_000 });
|
||||
await scenario.bobMessages.expectMessageImageContentSha256(imageName, sha256);
|
||||
});
|
||||
});
|
||||
|
||||
test('renders link embeds for shared links', async ({ createClient }) => {
|
||||
const scenario = await createChatScenario(createClient);
|
||||
const messageText = `Useful docs ${MOCK_EMBED_URL}`;
|
||||
@@ -442,6 +465,24 @@ function createTextFilePayload(name: string, mimeType: string, content: string):
|
||||
};
|
||||
}
|
||||
|
||||
function createMultiChunkImagePayload(name: string): { payload: ChatDropFilePayload; sha256: string } {
|
||||
// ~300 KB of XML-safe noise inside an SVG comment so the file spans
|
||||
// multiple 64 KiB P2P transfer chunks while remaining a renderable image.
|
||||
const noise = randomBytes(225_000).toString('base64');
|
||||
const markup = buildMockSvgMarkup(name).replace('</svg>', `<!-- ${noise} --></svg>`);
|
||||
const contentBuffer = Buffer.from(markup, 'utf8');
|
||||
|
||||
return {
|
||||
payload: {
|
||||
name,
|
||||
mimeType: 'image/svg+xml',
|
||||
base64: contentBuffer.toString('base64')
|
||||
},
|
||||
sha256: createHash('sha256').update(contentBuffer)
|
||||
.digest('hex')
|
||||
};
|
||||
}
|
||||
|
||||
function buildMockSvgMarkup(label: string): string {
|
||||
return [
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" width="160" height="120" viewBox="0 0 160 120">',
|
||||
|
||||
Reference in New Issue
Block a user