test: catch bot tests up with the de-click transport ramp

Upstream a0f0b49..6f165b5 added the pause/resume fade tail but shipped no
test updates, leaving 5 assertions red (also reproducible on pristine
upstream/main, so not merge-induced).

- instance-recovery/instance harnesses: stub players borrow
  AudioPlayer.prototype.pause/resume, which now call this.setTransportRamp().
  Give the stubs that method or they throw TypeError on pause/resume.
- voice-failure: pausing deliberately emits a fade tail, so the frame count
  no longer freezes at exactly 50. Assert the de-click fade completes, then
  that the scheduler and elapsed clock are genuinely frozen — the actual
  behavior under test.

No production code changed.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
zbn297427669andClaude Code committed 2026-11-02 15:58:44 +08:00
1 parent 17008ae52e
commit ba645e5ccb
3 files changed
+18 -2

No files matched your search

+4
View File
@@ -29,6 +29,10 @@ function makeBot() {
player.getVolume = () => 50;
player.pause = AudioPlayer.prototype.pause;
player.resume = AudioPlayer.prototype.resume;
// The real pause()/resume() drive the de-click transport ramp
// (a0f0b49..6f165b5). A stub player must expose it too, or the prototype
// methods throw "setTransportRamp is not a function".
player.setTransportRamp = vi.fn();
player.play = vi.fn((_url: string, position: number) => { player.sessionId++; player.elapsed = position; player.state = "playing"; });
player.stop = vi.fn(() => { player.sessionId++; player.state = "idle"; });
const provider = { getSongUrl: vi.fn(async (): Promise<{ url: string } | null> => ({ url: "fresh" })) };
+4
View File
@@ -1780,6 +1780,10 @@ describe("BotInstance trackEnd — stale playback sessions", () => {
player.getPlaybackSessionId = AudioPlayer.prototype.getPlaybackSessionId;
player.pause = AudioPlayer.prototype.pause;
player.resume = AudioPlayer.prototype.resume;
// The real pause()/resume() drive the de-click transport ramp
// (a0f0b49..6f165b5). A stub player must expose it too, or the prototype
// methods throw "setTransportRamp is not a function".
player.setTransportRamp = vi.fn();
player.play = vi.fn(() => { player.sessionId++; player.state = "playing"; });
const provider = { getSongUrl: vi.fn(async () => ({ url: "fresh" })) };
const advances: string[] = [];
+10 -2
View File
@@ -65,9 +65,17 @@ describe("BotInstance persistent voice send failure", () => {
expect(frames).toBe(50);
h.tsClient.emit("voiceSendFailed", { consecutiveFailures: 100, durationMs: 2000 });
vi.advanceTimersByTime(3000);
expect(frames).toBe(50);
expect(h.player.getElapsed()).toBe(1);
// Pausing emits a short de-click fade tail (pauseFrames) so the last
// audible frames ramp down instead of cutting off (a0f0b49). What this
// test guards is what happens AFTER that: the scheduler must go quiet
// and elapsed must stop advancing.
expect(h.player.getState()).toBe("paused");
const framesAfterFade = frames;
const elapsedAfterFade = h.player.getElapsed();
expect(framesAfterFade).toBeLessThan(50 + 20);
vi.advanceTimersByTime(3000);
expect(frames).toBe(framesAfterFade);
expect(h.player.getElapsed()).toBe(elapsedAfterFade);
} finally { h.player.stop(); }
});