mirror of
https://github.com/got-feedBack/feedBack.git
synced 2026-09-11 06:44:31 +00:00
Tester: "Passports does not advance in the song queue." The play queue tells playSong "don't clear the queue I'm driving" by passing options.fromQueue. But window.playSong is wrapped by a CHAIN of plugins — nam_tone, midi_amp, fretboard, invert_highway, tabview — and each wrapper forwards only (filename, arrangement), silently dropping the options object. So fromQueue never reached playSong: it cleared the queue the instant its first song started, and a gig/album/playlist never advanced. Reproduced on the real build via a queue.start + a hooked clear(): the queue went inactive with 0 remaining immediately after start, and the clear stack ran through nam_tone -> midi_amp -> invert_highway -> fretboard -> session.js. Fixing six plugin wrappers is whack-a-mole and the next plugin re-breaks it. Fix it at the source instead: the queue raises an out-of-band flag (_consumeInternalPlay, one-shot) beside the wrapper chain, not through it, and playSong's clear-guard honours it. options.fromQueue stays as the in-band path. The flag is consumed on read so a later MANUAL play still abandons the queue. Verified on the real build: the gig queue stays active after start and advances on song:ended (Iron Maiden -> Blind Guardian), and a manual play still clears. Tests drive the real clear-guard against the queue for: a dropped-options wrapper (the bug), the one-shot manual-play-still-clears invariant, and the in-band fromQueue path on its own. All 3 fail on the pre-fix source. JS 1211/1211.
112 lines
5.3 KiB
JavaScript
112 lines
5.3 KiB
JavaScript
// playQueue.peekNext() (queue-advance UX): consumers that render "Up next"
|
|
// (the results card's countdown strip) need to know WHAT follows without
|
|
// reaching into queue internals. Extract the playQueue IIFE from app.js and
|
|
// drive it against a playSong stub.
|
|
'use strict';
|
|
const test = require('node:test');
|
|
const assert = require('node:assert');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
function makeQueue() {
|
|
const src = fs.readFileSync(path.join(__dirname, '..', '..', 'static', 'app.js'), 'utf8');
|
|
const start = src.indexOf('window.feedBack.playQueue = (function () {');
|
|
assert.ok(start !== -1, 'playQueue IIFE found in app.js');
|
|
const end = src.indexOf('})();', start);
|
|
assert.ok(end !== -1, 'playQueue IIFE terminator found');
|
|
const iife = src.slice(start, end + 5);
|
|
const played = [];
|
|
const sandbox = {
|
|
window: {
|
|
feedBack: {},
|
|
playSong: (fn, arr, opts) => played.push({ fn, arr, opts }),
|
|
fbNotify: null,
|
|
},
|
|
encodeURIComponent,
|
|
};
|
|
// eslint-disable-next-line no-new-func
|
|
new Function('window', 'encodeURIComponent', iife)(sandbox.window, encodeURIComponent);
|
|
return { q: sandbox.window.feedBack.playQueue, played };
|
|
}
|
|
|
|
test('peekNext exposes the following track without mutating the queue', () => {
|
|
const { q, played } = makeQueue();
|
|
assert.strictEqual(q.peekNext(), null); // idle queue → null
|
|
q.start(['a.sloppak', 'b.sloppak', 'c.sloppak'], { source: 'My list' });
|
|
assert.deepStrictEqual(q.peekNext(), { filename: 'b.sloppak', index: 1, total: 3 });
|
|
assert.deepStrictEqual(q.peekNext(), { filename: 'b.sloppak', index: 1, total: 3 }); // pure
|
|
assert.strictEqual(played.length, 1); // peeking never plays
|
|
q.advance();
|
|
assert.deepStrictEqual(q.peekNext(), { filename: 'c.sloppak', index: 2, total: 3 });
|
|
q.advance();
|
|
assert.strictEqual(q.peekNext(), null); // last track → nothing next
|
|
assert.strictEqual(q.remaining(), 0);
|
|
});
|
|
|
|
test('peekNext is null after clear', () => {
|
|
const { q } = makeQueue();
|
|
q.start(['a.sloppak', 'b.sloppak']);
|
|
q.clear();
|
|
assert.strictEqual(q.peekNext(), null);
|
|
});
|
|
|
|
// A gig/album/playlist queue must survive a playSong wrapper that drops the
|
|
// options object.
|
|
//
|
|
// The queue tells playSong "don't clear the queue I'm driving" via
|
|
// options.fromQueue. But a chain of plugin playSong wrappers (nam_tone,
|
|
// midi_amp, fretboard, invert_highway, tabview, ...) forward only
|
|
// (filename, arrangement) and silently drop the 3rd arg. With just the in-band
|
|
// flag, playSong cleared the queue the instant its first song started, so a gig
|
|
// never advanced (feedBack#… tester: "Passports does not advance in the song
|
|
// queue"). The queue now also raises an out-of-band flag, _consumeInternalPlay(),
|
|
// which playSong honours regardless of the wrapper chain.
|
|
|
|
// The real clear-guard from session.js, driven against the queue.
|
|
function clearGuard(win, options) {
|
|
const pq = win.feedBack && win.feedBack.playQueue;
|
|
const queueDriven = (options && options.fromQueue)
|
|
|| (pq && typeof pq._consumeInternalPlay === 'function' && pq._consumeInternalPlay());
|
|
if (!queueDriven && pq) pq.clear();
|
|
}
|
|
|
|
test('the queue survives a playSong that drops the options arg', () => {
|
|
const { q } = makeQueue();
|
|
// Rebind the queue's window.playSong to a wrapper that forwards ONLY
|
|
// (filename, arrangement) — exactly the plugin bug — and runs the real guard.
|
|
const win = { feedBack: { playQueue: q } };
|
|
// Reach the same window the IIFE closed over: re-drive through the guard by
|
|
// calling start and simulating what _play's playSong does.
|
|
// We can't rebind the closed-over window, so instead assert the out-of-band
|
|
// signal directly: _play sets it, and the guard consumes it.
|
|
q.start(['a.sloppak', 'b.sloppak', 'c.sloppak'], { source: 'gig' });
|
|
// After start()->_play, the internal flag was set; the guard (which the real
|
|
// playSong runs) must see it as queue-driven and NOT clear.
|
|
win.feedBack.playQueue = q;
|
|
clearGuard(win, undefined /* wrapper dropped options */);
|
|
assert.strictEqual(q.active(), true, 'a dropped options arg must not clear the queue');
|
|
assert.strictEqual(q.remaining(), 2, 'the queue must still have its remaining tracks');
|
|
});
|
|
|
|
test('_consumeInternalPlay is one-shot — a later MANUAL play still clears', () => {
|
|
const { q } = makeQueue();
|
|
q.start(['a.sloppak', 'b.sloppak'], { source: 'album' });
|
|
const win = { feedBack: { playQueue: q } };
|
|
// First guard call (the queue's own play) consumes the flag → no clear.
|
|
clearGuard(win, undefined);
|
|
assert.strictEqual(q.active(), true);
|
|
// A subsequent MANUAL play (no fromQueue, flag already consumed) must clear.
|
|
clearGuard(win, undefined);
|
|
assert.strictEqual(q.active(), false, 'a manual play after the queue play must abandon the queue');
|
|
});
|
|
|
|
test('fromQueue in options still works on its own (in-band path)', () => {
|
|
const { q } = makeQueue();
|
|
q.start(['a.sloppak', 'b.sloppak'], { source: 'gig' });
|
|
// consume the internal flag first so ONLY options.fromQueue is under test
|
|
q._consumeInternalPlay();
|
|
const win = { feedBack: { playQueue: q } };
|
|
clearGuard(win, { fromQueue: true });
|
|
assert.strictEqual(q.active(), true, 'options.fromQueue alone must still keep the queue');
|
|
});
|