Files
Toju/toju-app/src/app/domains/attachment/domain/logic/attachment-autodownload.rules.spec.ts
T
myxeliumandCursor 497033aff0 fix: Bug - Sending files and attachment issues (cross-transport auto-download race)
Re-queue attachment auto-downloads when the chat message arrives, since
file-announce (WebRTC) can beat chat-message (websocket) and the announce-time
pass gives up on an unknown room. Gate stalled-download resets on chunk-progress
staleness so an active transfer is never cancelled mid-stream, which deadlocked
the retry against the sender's active-transfer dedupe.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-12 21:26:59 +02:00

53 lines
1.9 KiB
TypeScript

import { ATTACHMENT_STALLED_DOWNLOAD_THRESHOLD_MS, shouldResetStalledAttachmentDownload } from './attachment-autodownload.rules';
const NOW_MS = 1_750_000_000_000;
describe('attachment autodownload rules', () => {
it('does not reset an actively transferring download with recent chunk progress', () => {
// Regression: the pending-request marker is deleted on the first received
// chunk, so an in-flight multi-chunk transfer has receivedBytes > 0 and no
// pending request - it must NOT be treated as stalled while chunks flow.
expect(shouldResetStalledAttachmentDownload({
available: false,
receivedBytes: 128,
lastUpdateMs: NOW_MS - 100
}, false, NOW_MS)).toBe(false);
});
it('resets partial downloads with no progress past the stall threshold', () => {
expect(shouldResetStalledAttachmentDownload({
available: false,
receivedBytes: 128,
lastUpdateMs: NOW_MS - ATTACHMENT_STALLED_DOWNLOAD_THRESHOLD_MS - 1
}, false, NOW_MS)).toBe(true);
});
it('treats partial downloads without a progress timestamp as stalled', () => {
expect(shouldResetStalledAttachmentDownload({
available: false,
receivedBytes: 128
}, false, NOW_MS)).toBe(true);
});
it('never resets downloads with a pending request or already available', () => {
expect(shouldResetStalledAttachmentDownload({
available: false,
receivedBytes: 128,
lastUpdateMs: NOW_MS - ATTACHMENT_STALLED_DOWNLOAD_THRESHOLD_MS - 1
}, true, NOW_MS)).toBe(false);
expect(shouldResetStalledAttachmentDownload({
available: true,
receivedBytes: 128,
lastUpdateMs: NOW_MS - ATTACHMENT_STALLED_DOWNLOAD_THRESHOLD_MS - 1
}, false, NOW_MS)).toBe(false);
});
it('never resets downloads that have not received any bytes', () => {
expect(shouldResetStalledAttachmentDownload({
available: false,
receivedBytes: 0
}, false, NOW_MS)).toBe(false);
});
});