mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
Keep an active voice session through engine switches
The page creates the voice once; each engine attachment only gives it that scene's action runner, pointer canvas and annotation events. Calls made during a switch wait for the incoming engine and are refused with ENGINE_SWITCHING when none attaches in time; results name the engine that answered, and the session hears engine-changed after a switch. The analyst's follow-up memory and layer enable times outlive one engine's runner. scripts/qa-voice-engine-switch.mjs drives a fake microphone and Realtime transport through the switches.
This commit is contained in:
1 parent
35ed499ae4
commit
05578c61b9
13 files changed
+998
-139
No files matched your search
@@ -0,0 +1,107 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createSceneRunner, engineSwitchingRefusal } from './sceneRunner.js';
|
||||
|
||||
const engine = (kind) => ({ kind });
|
||||
|
||||
function runnerFor(log) {
|
||||
return (scene) => {
|
||||
const run = async (name, args, options) => {
|
||||
log.push({ name, kind: scene.engine.kind, signal: options.signal });
|
||||
return { ok: true, action: name };
|
||||
};
|
||||
run.dispose = () => log.push({ disposed: scene.engine.kind });
|
||||
run.resetConversation = () => log.push({ reset: scene.engine.kind });
|
||||
return run;
|
||||
};
|
||||
}
|
||||
|
||||
test('calls run on the attached engine and say which engine answered', async () => {
|
||||
const log = [];
|
||||
const run = createSceneRunner({ build: runnerFor(log) });
|
||||
run.attach({ engine: engine('cesium') });
|
||||
assert.deepEqual(await run('set_layer', {}), {
|
||||
ok: true,
|
||||
action: 'set_layer',
|
||||
engine: 'cesium',
|
||||
});
|
||||
run.attach({ engine: engine('navara') });
|
||||
assert.equal((await run('set_layer', {})).engine, 'navara');
|
||||
assert.deepEqual(log[1], { disposed: 'cesium' });
|
||||
assert.equal(run.engineKind(), 'navara');
|
||||
});
|
||||
|
||||
test('a call during a switch waits for the next engine and runs there', async () => {
|
||||
const log = [];
|
||||
let switching = false;
|
||||
const run = createSceneRunner({
|
||||
build: runnerFor(log),
|
||||
isSwitching: () => switching,
|
||||
});
|
||||
run.attach({ engine: engine('cesium') });
|
||||
switching = true;
|
||||
const pending = run('set_layer', {});
|
||||
run.detach();
|
||||
await new Promise((resolve) => setTimeout(resolve, 5));
|
||||
assert.equal(log.filter((entry) => entry.name).length, 0);
|
||||
run.attach({ engine: engine('navara') });
|
||||
const result = await pending;
|
||||
assert.equal(result.engine, 'navara');
|
||||
switching = false;
|
||||
});
|
||||
|
||||
test('a call refused when no engine attaches in time names ENGINE_SWITCHING', async () => {
|
||||
const run = createSceneRunner({
|
||||
build: runnerFor([]),
|
||||
isSwitching: () => true,
|
||||
switchWaitMs: 10,
|
||||
});
|
||||
run.attach({ engine: engine('cesium') });
|
||||
run.detach();
|
||||
const result = await run('annotate_map', {});
|
||||
assert.deepEqual(result, engineSwitchingRefusal('annotate_map'));
|
||||
assert.equal(result.code, 'ENGINE_SWITCHING');
|
||||
});
|
||||
|
||||
test('a switch that settles without a new engine lets waiting calls run', async () => {
|
||||
const log = [];
|
||||
let switching = true;
|
||||
const run = createSceneRunner({
|
||||
build: runnerFor(log),
|
||||
isSwitching: () => switching,
|
||||
});
|
||||
run.attach({ engine: engine('cesium') });
|
||||
const pending = run('set_layer', {});
|
||||
switching = false;
|
||||
run.wake();
|
||||
assert.equal((await pending).engine, 'cesium');
|
||||
});
|
||||
|
||||
test('the attachment signal aborts calls in flight when the engine detaches', async () => {
|
||||
let seen;
|
||||
const run = createSceneRunner({
|
||||
build: () => async (name, args, options) => {
|
||||
seen = options.signal;
|
||||
await new Promise((resolve) => setTimeout(resolve, 5));
|
||||
return { ok: !options.signal.aborted };
|
||||
},
|
||||
});
|
||||
run.attach({ engine: engine('cesium') });
|
||||
const pending = run('fly_to_location', {});
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
run.detach();
|
||||
assert.equal(seen.aborted, true);
|
||||
assert.equal((await pending).ok, false);
|
||||
});
|
||||
|
||||
test('a disposed runner refuses and wakes its waiting calls', async () => {
|
||||
const run = createSceneRunner({
|
||||
build: runnerFor([]),
|
||||
isSwitching: () => true,
|
||||
});
|
||||
const pending = run('set_layer', {});
|
||||
run.dispose();
|
||||
const result = await pending;
|
||||
assert.equal(result.cancelled, true);
|
||||
assert.equal((await run('set_layer', {})).cancelled, true);
|
||||
});
|
||||
Reference in new issue
Block a user