Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring. Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
51 lines
2.9 KiB
JavaScript
51 lines
2.9 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createRequire } from 'node:module';
|
|
const require = createRequire(import.meta.url);
|
|
const { FileSettings, TransferScheduler } = require('../app/main/files-settings.js');
|
|
|
|
test('global concurrency reservations survive event latency and rate shares never multiply', async () => {
|
|
const settings = new FileSettings();
|
|
settings.save({ downloadSlots: 2, uploadSlots: 1, limitDownload: true, downloadMiB: 1 });
|
|
const configs = new Map(); const ids = new Map();
|
|
const request = async (id, cmd, args) => {
|
|
if (cmd === 'file_config') { configs.set(id, args); return { ok: true, result: {} }; }
|
|
const n = (ids.get(id) || 0) + 1; ids.set(id, n);
|
|
return { ok: true, result: { transfer_id: n, direction: 'download', state: 'queued' } };
|
|
};
|
|
const scheduler = new TransferScheduler(request, settings, () => 1);
|
|
await scheduler.requestTransfer('c1', 'file_download', {});
|
|
await scheduler.requestTransfer('c2', 'file_download', {});
|
|
await scheduler.requestTransfer('c3', 'file_download', {});
|
|
assert.equal([...configs.values()].reduce((n, c) => n + c.download_slots, 0), 2);
|
|
assert.equal(configs.get('c3').download_slots, 0);
|
|
assert.equal(configs.get('c1').download_limit + configs.get('c2').download_limit, 1048576);
|
|
settings.save({ downloadSlots: 1 });
|
|
await scheduler.changed();
|
|
assert.equal([...configs.values()].reduce((n, c) => n + c.download_slots, 0), 2, 'reducing limits drains in-flight starts, never aborts');
|
|
scheduler.onEvent('c1', { event: 'file_transfer', transfer_id: 1, direction: 'download', state: 'done' });
|
|
await scheduler.serial;
|
|
assert.equal(configs.get('c3').download_slots, 0, 'no replacement starts while at the reduced limit');
|
|
scheduler.onEvent('c2', { event: 'file_transfer', transfer_id: 1, direction: 'download', state: 'done' });
|
|
await scheduler.serial;
|
|
assert.equal(configs.get('c3').download_slots, 1);
|
|
assert.equal(configs.get('c3').download_limit, 1048576);
|
|
});
|
|
|
|
test('queued native transfers remain cancellable and terminal events free app slots', async () => {
|
|
const settings = new FileSettings(); settings.save({ uploadSlots: 1 });
|
|
const configs = new Map(); let id = 0;
|
|
const scheduler = new TransferScheduler(async (connection, cmd, args) => {
|
|
if (cmd === 'file_config') { configs.set(connection, args); return { ok: true }; }
|
|
return { ok: true, result: { transfer_id: ++id, direction: 'upload', state: 'queued' } };
|
|
}, settings, () => 1);
|
|
await scheduler.requestTransfer('a', 'file_upload', {});
|
|
const second = await scheduler.requestTransfer('b', 'file_upload', {});
|
|
assert.equal(second.result.state, 'queued');
|
|
assert.equal(configs.get('b').upload_slots, 0);
|
|
scheduler.onEvent('b', { event: 'file_transfer', transfer_id: 2, direction: 'upload', state: 'cancelled' });
|
|
await scheduler.serial;
|
|
scheduler.onClosed('a'); await scheduler.serial;
|
|
assert.equal(configs.get('b').upload_slots, 0);
|
|
});
|