Root cause of "4 accounts configured, rotation only ever uses 1-3": byse returns HTTP 200 + per-file status "Not video file format" for valid MKVs above an account's size tier (proven from the live rotation log: account 4ha0 accepted 1158 files up to 2.62 GB and deterministically rejected all 6 files >= 2.81 GB with that status, each costing a full ~20 min upload). The parser tagged this fileRejected, which (a) skipped the 30s recovery poll that was originally BUILT for this misleading status (guard regression from "byse skips 30s recovery poll on explicit reject") and (b) made the upload manager skip rotation entirely - so the remaining accounts were never tried and the files failed forever. Account selection is primary-first failover, so a later account only ever runs when every earlier one is hard-failed or disabled, which matches the reported "account 4 only gets used when I disable the others". The fix, layered: - parseByseResult flags "Not video file format" as err.suspectReject (alongside fileRejected). Genuine rejections (Duplicate, too small, account-level disk-full) behave exactly as before. - uploadFile runs the byse recovery poll again for suspect rejections (the file often registers asynchronously despite the status), but skips it when the caller's file probe says the upload is genuinely not a video (new opts.probeIsVideoLike, threaded from the upload manager's probe). Poll helpers now swallow an abort during their sleep and return null so a cancelled poll surfaces the original error instead of a bare AbortError. - upload-manager: on a suspect rejection of a probe-verified video, the file gets ONE attempt on each remaining pool account (new accountPools from main.js, refreshed on save-config) - WITHOUT blacklisting the rejecting account, which keeps working for smaller files. A per-batch size memo (hoster:account -> smallest rejected size) plus a known-good account preference prevent re-uploading every following oversized file through the whole chain: the second file skips known-limited accounts outright and goes straight to the account that took the first one. Alternates that fail with a genuine account error (quota/ban/full) are marked failed in-batch so no later file burns a multi-GB upload on them; deliberately no account-failed emit there, as repointing the hoster-wide override would reroute normal-sized files away from a healthy primary. - Rotation hardening from the adversarial review: the rotated-to retry loop now fast-breaks on file-rejected/hoster-transient errors instead of burning maxAttempts full uploads, and a file-class error on a rotated account no longer blacklists that account (it fails only the file). Cancelling mid-alternates or mid-rotation now records the job as aborted instead of error (this also stops the batch webhook from firing on fully user-cancelled batches). New upload-failure rot-logs are guarded against logging user aborts as failures; rotation retries are now visible in the rotation log at all (previously failures on a rotated-to account were never logged, which is why account 2's death was invisible in the support log). - file-probe: the mpeg-ts signature required only a single leading 0x47 byte, so GIFs and "G"-prefixed text classified as video and would have qualified junk for pool-wide alternate uploads; it now requires TS sync-byte periodicity (0x47 at offsets 0/188/376) and the probe head read grew from 64 to 512 bytes to make that check possible. GIF gets its own non-video signature. Tests: 9 new/reworked across suspect-reject-alternates.test.js (alternate walk, no blacklist, memo short-circuit, account-error marking, abort labeling, probe gating) and byse-reject-recovery.test.js (suspect polls + recovers, empty poll throws suspectReject, Duplicate still fast-fails, probe-confirmed non-video skips the poll) plus a TS/GIF probe regression test. Full suite 276 green.
223 lines
9.1 KiB
JavaScript
223 lines
9.1 KiB
JavaScript
const { describe, it, beforeEach, mock } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
describe('suspect-reject alternate accounts', () => {
|
|
let UploadManager;
|
|
let mockUploadFile;
|
|
let mockProbe;
|
|
|
|
function suspectErr() {
|
|
const e = new Error('Byse lehnte Datei ab: Not video file format');
|
|
e.fileRejected = true;
|
|
e.suspectReject = true;
|
|
return e;
|
|
}
|
|
|
|
beforeEach(() => {
|
|
delete require.cache[require.resolve('../lib/upload-manager')];
|
|
|
|
const hosters = require('../lib/hosters');
|
|
mockUploadFile = mock.fn(async () => ({ download_url: 'https://byse.sx/d/ok', embed_url: null, file_code: 'ok' }));
|
|
hosters.uploadFile = (...a) => mockUploadFile(...a);
|
|
hosters.prefetchBaseline = async () => null;
|
|
|
|
const fileProbe = require('../lib/file-probe');
|
|
mockProbe = mock.fn(async () => ({ ok: true, kind: 'matroska', isVideoLike: true, headHex: '1a45dfa3' }));
|
|
fileProbe.probeFileHead = (...a) => mockProbe(...a);
|
|
|
|
const fs = require('fs');
|
|
const origStatSync = fs.statSync;
|
|
fs.statSync = function (p) {
|
|
if (typeof p === 'string' && p.startsWith('/test/')) return { size: 3 * 1024 * 1024 * 1024 };
|
|
return origStatSync.call(this, p);
|
|
};
|
|
|
|
UploadManager = require('../lib/upload-manager');
|
|
});
|
|
|
|
function poolMgr(pool, settings) {
|
|
return new UploadManager({ 'byse.sx': { retries: 0, ...(settings || {}) } }, {}, { 'byse.sx': pool });
|
|
}
|
|
|
|
it('tries the file on the next pool account after a suspect rejection and succeeds without blacklisting', async () => {
|
|
const mgr = poolMgr([
|
|
{ id: 'acc1', apiKey: 'key1' },
|
|
{ id: 'acc2', apiKey: 'key2' }
|
|
]);
|
|
mockUploadFile.mock.mockImplementation(async (hoster, file, apiKey) => {
|
|
if (apiKey === 'key1') throw suspectErr();
|
|
return { download_url: 'https://byse.sx/d/alt', embed_url: null, file_code: 'alt' };
|
|
});
|
|
const rotEvents = [];
|
|
mgr.on('rot-log', (e) => rotEvents.push(e.event));
|
|
let summary = null;
|
|
mgr.on('batch-done', (s) => { summary = s; });
|
|
|
|
await mgr.startBatch([{ file: '/test/big.mkv', hoster: 'byse.sx', apiKey: 'key1', accountId: 'acc1' }]);
|
|
|
|
assert.equal(summary.succeeded, 1);
|
|
assert.equal(summary.failed, 0);
|
|
const keys = mockUploadFile.mock.calls.map(c => c.arguments[2]);
|
|
assert.deepEqual(keys, ['key1', 'key2']);
|
|
assert.ok(rotEvents.includes('suspect-reject-alt'));
|
|
assert.equal(mgr.getFailedAccountKeys().length, 0, 'suspect rejection must not blacklist any account');
|
|
});
|
|
|
|
it('fails the file when every pool account gives the suspect rejection — each tried exactly once, none blacklisted', async () => {
|
|
const mgr = poolMgr([
|
|
{ id: 'acc1', apiKey: 'key1' },
|
|
{ id: 'acc2', apiKey: 'key2' },
|
|
{ id: 'acc3', apiKey: 'key3' }
|
|
]);
|
|
mockUploadFile.mock.mockImplementation(async () => { throw suspectErr(); });
|
|
const rotEvents = [];
|
|
mgr.on('rot-log', (e) => rotEvents.push(e.event));
|
|
let summary = null;
|
|
mgr.on('batch-done', (s) => { summary = s; });
|
|
|
|
await mgr.startBatch([{ file: '/test/big.mkv', hoster: 'byse.sx', apiKey: 'key1', accountId: 'acc1' }]);
|
|
|
|
assert.equal(summary.failed, 1);
|
|
const keys = mockUploadFile.mock.calls.map(c => c.arguments[2]);
|
|
assert.deepEqual(keys, ['key1', 'key2', 'key3']);
|
|
assert.ok(rotEvents.includes('suspect-reject-exhausted'));
|
|
assert.equal(mgr.getFailedAccountKeys().length, 0);
|
|
});
|
|
|
|
it('skips pool accounts already marked failed and lands on the last one', async () => {
|
|
const mgr = poolMgr([
|
|
{ id: 'acc1', apiKey: 'key1' },
|
|
{ id: 'acc2', apiKey: 'key2' },
|
|
{ id: 'acc3', apiKey: 'key3' },
|
|
{ id: 'acc4', apiKey: 'key4' }
|
|
]);
|
|
mockUploadFile.mock.mockImplementation(async (hoster, file, apiKey) => {
|
|
if (apiKey === 'key3') throw suspectErr();
|
|
return { download_url: 'https://byse.sx/d/four', embed_url: null, file_code: 'four' };
|
|
});
|
|
let summary = null;
|
|
mgr.on('batch-done', (s) => { summary = s; });
|
|
|
|
await mgr.startBatch(
|
|
[{ file: '/test/big.mkv', hoster: 'byse.sx', apiKey: 'key3', accountId: 'acc3' }],
|
|
{ primeFailedAccounts: ['byse.sx:acc1', 'byse.sx:acc2'] }
|
|
);
|
|
|
|
assert.equal(summary.succeeded, 1);
|
|
const keys = mockUploadFile.mock.calls.map(c => c.arguments[2]);
|
|
assert.deepEqual(keys, ['key3', 'key4'], 'failed acc1/acc2 skipped, fourth account finally gets the file');
|
|
});
|
|
|
|
it('does NOT try alternates when the probe says the file is not a video', async () => {
|
|
mockProbe.mock.mockImplementation(async () => ({ ok: true, kind: 'rar', isVideoLike: false, headHex: '52617221' }));
|
|
const mgr = poolMgr([
|
|
{ id: 'acc1', apiKey: 'key1' },
|
|
{ id: 'acc2', apiKey: 'key2' }
|
|
]);
|
|
mockUploadFile.mock.mockImplementation(async () => { throw suspectErr(); });
|
|
const rotEvents = [];
|
|
mgr.on('rot-log', (e) => rotEvents.push(e.event));
|
|
let summary = null;
|
|
mgr.on('batch-done', (s) => { summary = s; });
|
|
|
|
await mgr.startBatch([{ file: '/test/archive.rar', hoster: 'byse.sx', apiKey: 'key1', accountId: 'acc1' }]);
|
|
|
|
assert.equal(summary.failed, 1);
|
|
assert.equal(mockUploadFile.mock.calls.length, 1, 'genuine non-video rejection must not burn uploads on other accounts');
|
|
assert.ok(rotEvents.includes('skip-rotation-file-rejected'));
|
|
});
|
|
|
|
it('records a user cancel during the alternates walk as aborted, not error', async () => {
|
|
const mgr = poolMgr([
|
|
{ id: 'acc1', apiKey: 'key1' },
|
|
{ id: 'acc2', apiKey: 'key2' }
|
|
]);
|
|
mockUploadFile.mock.mockImplementation(async (hoster, file, apiKey) => {
|
|
if (apiKey === 'key1') throw suspectErr();
|
|
mgr.cancel();
|
|
const e = new Error('This operation was aborted');
|
|
throw e;
|
|
});
|
|
let summary = null;
|
|
mgr.on('batch-done', (s) => { summary = s; });
|
|
|
|
await mgr.startBatch([{ file: '/test/big.mkv', hoster: 'byse.sx', apiKey: 'key1', accountId: 'acc1' }]);
|
|
|
|
assert.equal(summary.files[0].results[0].status, 'aborted');
|
|
});
|
|
|
|
it('marks an alternate failed on a genuine account error so later suspect files skip it', async () => {
|
|
const mgr = poolMgr([
|
|
{ id: 'acc1', apiKey: 'key1' },
|
|
{ id: 'acc2', apiKey: 'key2' },
|
|
{ id: 'acc3', apiKey: 'key3' }
|
|
], { parallelCount: 1 });
|
|
mockUploadFile.mock.mockImplementation(async (hoster, file, apiKey) => {
|
|
if (apiKey === 'key1') throw suspectErr();
|
|
if (apiKey === 'key2') {
|
|
const e = new Error('Byse lehnte Datei ab: 0:0:0:not enough disk space on your account');
|
|
e.accountError = true;
|
|
throw e;
|
|
}
|
|
return { download_url: 'https://byse.sx/d/three', embed_url: null, file_code: 'three' };
|
|
});
|
|
let summary = null;
|
|
mgr.on('batch-done', (s) => { summary = s; });
|
|
|
|
await mgr.startBatch([
|
|
{ file: '/test/big1.mkv', hoster: 'byse.sx', apiKey: 'key1', accountId: 'acc1' },
|
|
{ file: '/test/big2.mkv', hoster: 'byse.sx', apiKey: 'key1', accountId: 'acc1' }
|
|
]);
|
|
|
|
assert.equal(summary.succeeded, 2);
|
|
assert.ok(mgr.getFailedAccountKeys().includes('byse.sx:acc2'), 'dead alternate must be remembered');
|
|
const keys = mockUploadFile.mock.calls.map(c => c.arguments[2]);
|
|
assert.deepEqual(keys, ['key1', 'key2', 'key3', 'key3'], 'second file must skip the memoized primary AND the dead alternate');
|
|
});
|
|
|
|
it('size memo short-circuits later oversized files straight to the known-good account', async () => {
|
|
const mgr = poolMgr([
|
|
{ id: 'acc1', apiKey: 'key1' },
|
|
{ id: 'acc2', apiKey: 'key2' },
|
|
{ id: 'acc3', apiKey: 'key3' }
|
|
], { parallelCount: 1 });
|
|
mockUploadFile.mock.mockImplementation(async (hoster, file, apiKey) => {
|
|
if (apiKey === 'key1' || apiKey === 'key2') throw suspectErr();
|
|
return { download_url: 'https://byse.sx/d/three', embed_url: null, file_code: 'three' };
|
|
});
|
|
const rotEvents = [];
|
|
mgr.on('rot-log', (e) => rotEvents.push(e.event));
|
|
let summary = null;
|
|
mgr.on('batch-done', (s) => { summary = s; });
|
|
|
|
await mgr.startBatch([
|
|
{ file: '/test/big1.mkv', hoster: 'byse.sx', apiKey: 'key1', accountId: 'acc1' },
|
|
{ file: '/test/big2.mkv', hoster: 'byse.sx', apiKey: 'key1', accountId: 'acc1' }
|
|
]);
|
|
|
|
assert.equal(summary.succeeded, 2);
|
|
const keys = mockUploadFile.mock.calls.map(c => c.arguments[2]);
|
|
assert.deepEqual(keys, ['key1', 'key2', 'key3', 'key3'], 'no repeat multi-GB upload to size-limited accounts for the second file');
|
|
assert.ok(rotEvents.includes('suspect-memo-skip'), 'second file must skip its primary via the size memo');
|
|
});
|
|
|
|
it('plain fileRejected without suspect flag keeps the old fast-fail behavior', async () => {
|
|
const mgr = poolMgr([
|
|
{ id: 'acc1', apiKey: 'key1' },
|
|
{ id: 'acc2', apiKey: 'key2' }
|
|
]);
|
|
mockUploadFile.mock.mockImplementation(async () => {
|
|
const e = new Error('Byse lehnte Datei ab: Duplicate');
|
|
e.fileRejected = true;
|
|
throw e;
|
|
});
|
|
let summary = null;
|
|
mgr.on('batch-done', (s) => { summary = s; });
|
|
|
|
await mgr.startBatch([{ file: '/test/big.mkv', hoster: 'byse.sx', apiKey: 'key1', accountId: 'acc1' }]);
|
|
|
|
assert.equal(summary.failed, 1);
|
|
assert.equal(mockUploadFile.mock.calls.length, 1);
|
|
});
|
|
});
|