Skip to content

Commit 8ecc767

Browse files
committed
lint
1 parent fdd6c37 commit 8ecc767

3 files changed

Lines changed: 52 additions & 7 deletions

File tree

agents/src/ipc/proc_pool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44
import { describe, expect, it, vi } from 'vitest';
55
import type { RunningJobInfo } from '../job.js';
6-
import { JobStatus, type JobExecutor } from './job_executor.js';
6+
import { type JobExecutor, JobStatus } from './job_executor.js';
77
import { ProcPool } from './proc_pool.js';
88

99
function createMockExecutor() {

agents/src/voice/room_io/_output.test.ts

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Future } from '../../utils.js';
66
import { ParticipantAudioOutput } from './_output.js';
77

88
describe('ParticipantAudioOutput waitForPlayoutTask', () => {
9-
it('preserves duration queued by overlapping next segment', async () => {
9+
it('resets tracked duration after non-interrupted playout', async () => {
1010
let resolvePlayout!: () => void;
1111
const waitForPlayout = new Promise<void>((resolve) => {
1212
resolvePlayout = resolve;
@@ -38,15 +38,61 @@ describe('ParticipantAudioOutput waitForPlayoutTask', () => {
3838

3939
const task = output.waitForPlayoutTask(new AbortController());
4040

41-
// Simulate a new overlapping segment that starts before the previous flush completes.
42-
output.pushedDuration += 0.5;
4341
resolvePlayout();
4442
await task;
4543

46-
expect(output.pushedDuration).toBe(0.5);
44+
expect(output.pushedDuration).toBe(0);
4745
expect(onPlaybackFinished).toHaveBeenCalledWith({
4846
playbackPosition: 1.0,
4947
interrupted: false,
5048
});
5149
});
50+
51+
it('resets duration to queue state when interrupted flush clears overlap', async () => {
52+
let resolvePlayout!: () => void;
53+
const waitForPlayout = new Promise<void>((resolve) => {
54+
resolvePlayout = resolve;
55+
});
56+
57+
const output = Object.create(ParticipantAudioOutput.prototype) as ParticipantAudioOutput & {
58+
pushedDuration: number;
59+
interruptedFuture: Future<void>;
60+
firstFrameEmitted: boolean;
61+
audioSource: {
62+
waitForPlayout: () => Promise<void>;
63+
queuedDuration: number;
64+
clearQueue: () => void;
65+
};
66+
onPlaybackFinished: (event: { playbackPosition: number; interrupted: boolean }) => void;
67+
waitForPlayoutTask: (abortController: AbortController) => Promise<void>;
68+
};
69+
70+
const onPlaybackFinished = vi.fn();
71+
output.pushedDuration = 1.0;
72+
output.interruptedFuture = new Future<void>();
73+
output.firstFrameEmitted = true;
74+
output.onPlaybackFinished = onPlaybackFinished;
75+
output.audioSource = {
76+
waitForPlayout: () => waitForPlayout,
77+
queuedDuration: 500,
78+
clearQueue: vi.fn(() => {
79+
output.audioSource.queuedDuration = 0;
80+
}),
81+
};
82+
83+
const task = output.waitForPlayoutTask(new AbortController());
84+
85+
// Overlap from the next segment arrives before interruption.
86+
output.pushedDuration += 0.5;
87+
output.interruptedFuture.resolve();
88+
resolvePlayout();
89+
await task;
90+
91+
// interrupted path clears queued overlap, so duration should not retain stale overlap time.
92+
expect(output.pushedDuration).toBe(0);
93+
expect(onPlaybackFinished).toHaveBeenCalledWith({
94+
playbackPosition: 0.5,
95+
interrupted: true,
96+
});
97+
});
5298
});

agents/src/voice/room_io/_output.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,7 @@ export class ParticipantAudioOutput extends AudioOutput {
387387
this.audioSource.clearQueue();
388388
}
389389

390-
// Remove only this segment's duration; newer captured frames remain queued for the next flush.
391-
this.pushedDuration -= accountedDuration;
390+
this.pushedDuration = 0;
392391
this.interruptedFuture = new Future();
393392
this.firstFrameEmitted = false;
394393

0 commit comments

Comments
 (0)