Release 0.0.6 with reconnect fixes and regression coverage

This commit is contained in:
Schluffe committed 2026-10-21 00:39:08 +02:00
1 parent acba97a7e1
commit 9f3f21884f
10 files changed
+279 -36

No files matched your search

+27 -1
View File
@@ -21,13 +21,14 @@ const tick = () => new Promise<void>(resolve => setImmediate(resolve));
async function until(check: () => boolean) { for (let n = 0; n < 500; n++) { if (check()) return; await tick(); } assert.fail('Condition did not become true'); }
const file = (name: string, size = 3) => new File([new Uint8Array(size).fill(42)], name);
function side(channel: Channel, initiator: boolean) {
const state = { ready: false, queue: [] as QueueItem[], send: '' as TransferState | '', receive: '' as TransferState | '', results: [] as { direction: string; result: TransferResult }[], declined: [] as string[], errors: [] as string[], closed: false };
const state = { ready: false, queue: [] as QueueItem[], send: '' as TransferState | '', receive: '' as TransferState | '', results: [] as { direction: string; result: TransferResult }[], declined: [] as string[], errors: [] as string[], closed: false, pairings: [] as Record<string, unknown>[] };
const callbacks: SessionCallbacks = {
onReady() { state.ready = true; }, onQueue(items) { state.queue = items; },
onState(direction, value) { state[direction] = value; }, onProgress() {},
onComplete(direction, result) { state.results.push({ direction, result }); },
onDecline(direction, meta) { state.declined.push(meta.name); state[direction] = ''; },
onError(error) { state.errors.push(error.message); }, onClose() { state.closed = true; },
onPairing(message) { state.pairings.push(message); },
};
return { session: new FileSession(channel, initiator, callbacks), state, channel };
}
@@ -144,3 +145,28 @@ test('invalid or missing identity proof closes the session without releasing fil
assert.match(first.state.errors.join(''), /Device proof failed/);
assert.doesNotMatch(first.channel.frames.join(''), /private-name/);
});
test('pairing messages wait for mutual verification and device proofs', async t => {
const { first, second } = pair(t);
let release!: () => void;
const proof = new Promise<void>(resolve => { release = resolve; });
t.after(() => release());
for (const side of [first, second]) side.session.authenticate({ sign: async () => 'proof', verify: () => proof });
first.session.verify(); second.session.verify(); await tick();
assert.throws(() => first.session.sendPairing({ step: 'propose' }));
assert.deepEqual(second.state.pairings, []);
release(); await until(() => first.state.ready && second.state.ready);
first.session.sendPairing({ step: 'check', value: '' });
await until(() => second.state.pairings.length === 1);
assert.deepEqual(second.state.pairings, [{ v: 3, type: 'pairing', step: 'check', value: '' }]);
first.session.close();
assert.throws(() => first.session.sendPairing({ step: 'propose' }));
});
test('unsolicited pairing messages before verification never reach the setup handler', async t => {
const { first } = pair(t);
first.channel.onmessage?.(new MessageEvent('message', { data: JSON.stringify({ v: 3, type: 'pairing', step: 'propose' }) }));
await until(() => first.state.closed);
assert.deepEqual(first.state.pairings, []);
assert.match(first.state.errors[0]!, /before verification/);
});