This commit is contained in:
2026-09-11 13:40:53 -04:00
parent 0f00e11823
commit 1acd371668
7 changed files with 204 additions and 5 deletions
+26
View File
@@ -0,0 +1,26 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { VoiceStateMachine } from '../daemon/voice-state.js';
import { QvacScheduler } from '../daemon/qvac-scheduler.js';
test('voice state machine handles wake, reply, cancel, and idle sleep', () => {
let now = 0;
const voice = new VoiceStateMachine({ now: () => now, idleMs: 100 });
voice.wake(); voice.utterance(); voice.speak(); voice.finishSpeaking();
assert.equal(voice.state, 'LISTENING');
assert.equal(voice.command('hands off'), 'cancel');
assert.equal(voice.state, 'ARMED');
voice.wake(); now = 101; voice.expireIdle();
assert.equal(voice.state, 'SLEEPING');
});
test('QVAC scheduler prioritizes voice and keeps one active job', async () => {
const scheduler = new QvacScheduler();
const order = [];
const first = scheduler.run(async () => { order.push('first'); await new Promise((r) => setTimeout(r, 5)); }, { lane: 'background' });
const media = scheduler.run(async () => order.push('media'), { lane: 'background' });
const voice = scheduler.run(async () => order.push('voice'), { lane: 'voice' });
await Promise.all([first, media, voice]);
assert.deepEqual(order, ['first', 'voice', 'media']);
assert.deepEqual(scheduler.status(), { running: 0, queued: [] });
});