'use strict'; const { test } = require('node:test'); const assert = require('node:assert'); const R = require('./resume-core'); test('nextRange walks the file in chunks and stops at the end', () => { assert.deepStrictEqual(R.nextRange(0, 20, 8), { start: 0, end: 7 }); assert.deepStrictEqual(R.nextRange(16, 20, 8), { start: 16, end: 19 }); assert.strictEqual(R.nextRange(20, 20, 8), null); assert.strictEqual(R.nextRange(0, 0, 8), null); }); test('parseContentRange reads start, end and total', () => { assert.deepStrictEqual(R.parseContentRange('bytes 8-15/20'), { start: 8, end: 15, total: 20 }); assert.deepStrictEqual(R.parseContentRange('bytes 0-1/*'), { start: 0, end: 1, total: null }); assert.strictEqual(R.parseContentRange('bytes */20'), null); assert.strictEqual(R.parseContentRange(null), null); }); test('backoff grows and caps at 30 s', () => { assert.deepStrictEqual([0, 1, 2, 3, 4, 9].map(R.backoffMs), [2000, 4000, 8000, 16000, 30000, 30000]); }); test('a partial is reused only for the same server copy', () => { const t = { etag: '"a.1"', size: 100 }; assert.strictEqual(R.resumeFrom({ etag: '"a.1"', size: 100 }, 40, t), 40); assert.strictEqual(R.resumeFrom({ etag: '"a.0"', size: 100 }, 40, t), 0, 'older generation'); assert.strictEqual(R.resumeFrom({ etag: '"a.1"', size: 90 }, 40, t), 0, 'size changed'); assert.strictEqual(R.resumeFrom(null, 40, t), 0, 'no sidecar'); assert.strictEqual(R.resumeFrom({ etag: '"a.1"', size: 100 }, 150, t), 100, 'never past the end'); });