fix: Bug - Attachments gets syncronized corrupt
This commit is contained in:
@@ -132,6 +132,31 @@ export class ChatMessagesPage {
|
||||
}).toBe(true);
|
||||
}
|
||||
|
||||
/** SHA-256 of the bytes currently served by the rendered chat image. */
|
||||
async getMessageImageSha256(altText: string): Promise<string> {
|
||||
const image = this.getMessageImageByAlt(altText);
|
||||
|
||||
return image.evaluate(async (element) => {
|
||||
const img = element as HTMLImageElement;
|
||||
const response = await fetch(img.src);
|
||||
const buffer = await response.arrayBuffer();
|
||||
const digest = await crypto.subtle.digest('SHA-256', buffer);
|
||||
|
||||
return [...new Uint8Array(digest)]
|
||||
.map((byte) => byte.toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
});
|
||||
}
|
||||
|
||||
/** Asserts the rendered chat image is byte-identical to the sent file. */
|
||||
async expectMessageImageContentSha256(altText: string, expectedSha256: string): Promise<void> {
|
||||
await this.expectMessageImageLoaded(altText);
|
||||
await expect.poll(() => this.getMessageImageSha256(altText), {
|
||||
timeout: 30_000,
|
||||
message: `Image ${altText} should be received byte-identical (no truncated/corrupt transfer)`
|
||||
}).toBe(expectedSha256);
|
||||
}
|
||||
|
||||
getEmbedCardByTitle(title: string): Locator {
|
||||
return this.page.locator('app-chat-link-embed').filter({
|
||||
has: this.page.getByText(title, { exact: true })
|
||||
|
||||
@@ -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