fix(calling): end the test call when the Echo bot hangs up
- The app stayed alone in the call after the bot played the recording back; Teams ends the test call then - call-echo-e2e checks the call ends by itself and runs hold/resume in a second echo call Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -21,7 +21,7 @@ use crate::audio::{SAMPLE_RATE, rms, tone_ratio, write_wav};
21
21
use crate::audio_io::{AudioMode, AudioSetup};
22
22
use crate::background::{BackgroundChoice, BackgroundPicture};
23
23
use crate::breakout::{self, RoomWatcher};
24
use crate::callee_gate::{CalleeGate, roster_has_callee};
24
use crate::callee_gate::{CalleeGate, EchoWatch, roster_has_callee};
25
25
use crate::camera::{CameraDevice, list_cameras};
26
26
use crate::captions::{
27
27
BotAction, CAPTIONS_DATA_ID, CaptionEntry, CaptionFlow, CaptionState, CaptionStep,
@@ -800,6 +800,7 @@ async fn drive(
800
800
let mut outgoing_limit = OUTGOING_TIMEOUT;
801
801
let is_meeting = spec.as_ref().is_some_and(CallSpec::is_meeting);
802
802
let is_echo = matches!(spec, Some(CallSpec::Echo));
803
let mut echo_watch = EchoWatch::default();
803
804
let mut callee_gate = CalleeGate::new(spec.as_ref().map_or(0, CallSpec::callee_count));
804
805
let meeting_target = match &spec {
805
806
Some(CallSpec::Meeting(target)) => Some(target.clone()),
@@ -1391,6 +1392,11 @@ async fn drive(
1391
1392
let entries = roster.entries();
1392
1393
timeline.record("roster", format!("{} participant(s)", entries.len()));
1393
1394
control.send(CallUpdate::Roster(entries));
1395
if is_echo && echo_watch.bot_left(roster.members().iter().map(|member| member.mri.as_str())) {
1396
timeline.record("echo bot left", "test call ends like in Teams");
1397
advance(state, CallSignal::RemoteEnd(EndKind::Normal), control);
1398
break;
1399
}
1394
1400
if callee_gate.is_waiting() && roster_has_callee(roster.members().iter().map(|member| member.mri.as_str()), &own_mri) {
1395
1401
outgoing_deadline = None;
1396
1402
if callee_gate.callee_joined() {
@@ -21,7 +21,7 @@ use crate::audio::{SAMPLE_RATE, rms, tone_ratio, write_wav};21
use crate::audio_io::{AudioMode, AudioSetup};21
use crate::audio_io::{AudioMode, AudioSetup};22
use crate::background::{BackgroundChoice, BackgroundPicture};22
use crate::background::{BackgroundChoice, BackgroundPicture};23
use crate::breakout::{self, RoomWatcher};23
use crate::breakout::{self, RoomWatcher};24
use crate::callee_gate::{CalleeGate, roster_has_callee};24
use crate::callee_gate::{CalleeGate, EchoWatch, roster_has_callee};25
use crate::camera::{CameraDevice, list_cameras};25
use crate::camera::{CameraDevice, list_cameras};26
use crate::captions::{26
use crate::captions::{27
BotAction, CAPTIONS_DATA_ID, CaptionEntry, CaptionFlow, CaptionState, CaptionStep,27
BotAction, CAPTIONS_DATA_ID, CaptionEntry, CaptionFlow, CaptionState, CaptionStep,@@ -800,6 +800,7 @@ async fn drive(800
let mut outgoing_limit = OUTGOING_TIMEOUT;800
let mut outgoing_limit = OUTGOING_TIMEOUT;801
let is_meeting = spec.as_ref().is_some_and(CallSpec::is_meeting);801
let is_meeting = spec.as_ref().is_some_and(CallSpec::is_meeting);802
let is_echo = matches!(spec, Some(CallSpec::Echo));802
let is_echo = matches!(spec, Some(CallSpec::Echo));803
let mut echo_watch = EchoWatch::default();803
let mut callee_gate = CalleeGate::new(spec.as_ref().map_or(0, CallSpec::callee_count));804
let mut callee_gate = CalleeGate::new(spec.as_ref().map_or(0, CallSpec::callee_count));804
let meeting_target = match &spec {805
let meeting_target = match &spec {805
Some(CallSpec::Meeting(target)) => Some(target.clone()),806
Some(CallSpec::Meeting(target)) => Some(target.clone()),@@ -1391,6 +1392,11 @@ async fn drive(1391
let entries = roster.entries();1392
let entries = roster.entries();1392
timeline.record("roster", format!("{} participant(s)", entries.len()));1393
timeline.record("roster", format!("{} participant(s)", entries.len()));1393
control.send(CallUpdate::Roster(entries));1394
control.send(CallUpdate::Roster(entries));1395
if is_echo && echo_watch.bot_left(roster.members().iter().map(|member| member.mri.as_str())) {1396
timeline.record("echo bot left", "test call ends like in Teams");1397
advance(state, CallSignal::RemoteEnd(EndKind::Normal), control);1398
break;1399
}1394
if callee_gate.is_waiting() && roster_has_callee(roster.members().iter().map(|member| member.mri.as_str()), &own_mri) {1400
if callee_gate.is_waiting() && roster_has_callee(roster.members().iter().map(|member| member.mri.as_str()), &own_mri) {1395
outgoing_deadline = None;1401
outgoing_deadline = None;1396
if callee_gate.callee_joined() {1402
if callee_gate.callee_joined() {@@ -47,6 +47,22 @@ pub fn roster_has_callee<'a>(
47
47
participant_mris.into_iter().any(|mri| mri != own_mri)
48
48
}
49
49
50
/// The Echo bot hangs up after playing the recording back; Teams then ends the test call.
51
#[derive(Debug, Default)]
52
pub struct EchoWatch {
53
seen: bool,
54
}
55
56
impl EchoWatch {
57
pub fn bot_left<'a>(&mut self, participant_mris: impl IntoIterator<Item = &'a str>) -> bool {
58
if participant_mris.into_iter().any(|mri| mri == crate::signaling::ECHO_BOT_MRI) {
59
self.seen = true;
60
return false;
61
}
62
self.seen
63
}
64
}
65
50
66
#[cfg(test)]
51
67
mod tests {
52
68
use super::*;
@@ -100,4 +116,15 @@ mod tests {
100
116
assert!(gate.media_connected());
101
117
assert!(!gate.callee_joined());
102
118
}
119
120
#[test]
121
fn the_echo_call_ends_only_after_the_bot_was_there_and_left() {
122
let me = "8:orgid:me";
123
let bot = crate::signaling::ECHO_BOT_MRI;
124
let mut watch = EchoWatch::default();
125
assert!(!watch.bot_left([me]));
126
assert!(!watch.bot_left([me, bot]));
127
assert!(!watch.bot_left([me, bot]));
128
assert!(watch.bot_left([me]));
129
}
103
130
}
@@ -47,6 +47,22 @@ pub fn roster_has_callee<'a>(47
participant_mris.into_iter().any(|mri| mri != own_mri)47
participant_mris.into_iter().any(|mri| mri != own_mri)48
}48
}49
49
50
/// The Echo bot hangs up after playing the recording back; Teams then ends the test call.51
#[derive(Debug, Default)]52
pub struct EchoWatch {53
seen: bool,54
}55
56
impl EchoWatch {57
pub fn bot_left<'a>(&mut self, participant_mris: impl IntoIterator<Item = &'a str>) -> bool {58
if participant_mris.into_iter().any(|mri| mri == crate::signaling::ECHO_BOT_MRI) {59
self.seen = true;60
return false;61
}62
self.seen63
}64
}65
50
#[cfg(test)]66
#[cfg(test)]51
mod tests {67
mod tests {52
use super::*;68
use super::*;@@ -100,4 +116,15 @@ mod tests {100
assert!(gate.media_connected());116
assert!(gate.media_connected());101
assert!(!gate.callee_joined());117
assert!(!gate.callee_joined());102
}118
}119
120
#[test]121
fn the_echo_call_ends_only_after_the_bot_was_there_and_left() {122
let me = "8:orgid:me";123
let bot = crate::signaling::ECHO_BOT_MRI;124
let mut watch = EchoWatch::default();125
assert!(!watch.bot_left([me]));126
assert!(!watch.bot_left([me, bot]));127
assert!(!watch.bot_left([me, bot]));128
assert!(watch.bot_left([me]));129
}103
}130
}@@ -1,6 +1,6 @@
1
1
// 1:1 call end-to-end test against the Echo bot with the deployed Windows app: no second person needed.
2
2
// The app's mic is VB-CABLE fed with a speech file; the bot plays its prompt, records us and plays it back.
3
// Checks that the app hears the bot, that our speech comes back, and that hold and resume stop and restart media.
3
// Checks the app hears the bot and our own speech back, that the call ends when the bot hangs up, and hold/resume in a second call.
4
4
// Usage: node scripts/call-echo-e2e.mjs <work dir>
5
5
import { spawn, execFileSync } from 'node:child_process';
6
6
import { readFileSync, writeFileSync } from 'node:fs';
@@ -15,11 +15,13 @@ const CONNECT_WAIT_MS = 12_000;
15
15
const LISTEN_SECONDS = 40;
16
16
const HOLD_SETTLE_MS = 6_000;
17
17
const HOLD_MEASURE_MS = 6_000;
18
const PLAY_SECONDS = 150;
18
const PLAY_SECONDS = 200;
19
19
const APP_THRESHOLD = { speech: 200, floor: 20 };
20
20
const SPEECH_TO_PAUSE = 4;
21
21
const RESUMED_PACKETS = 100;
22
const HELD_PACKETS = 20;
22
const PROMPT_START_MS = 3_000;
23
const ENDED_WAIT_MS = 15_000;
24
const HELD_PACKETS = 60;
23
25
24
26
const windowsPath = (path) => execFileSync('wslpath', ['-w', path]).toString().trim();
25
27
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -87,24 +89,34 @@ try {
87
89
if (!teamsProcessId()) throw new Error('teams.exe is not running');
88
90
defaultAudio('set', 'capture', 'CABLE Output');
89
91
const playing = runProbe('play', 'CABLE Input', windowsPath(PROBE_DIR + '/app.wav'), String(PLAY_SECONDS));
90
runTeams('--call', 'echo');
91
log(`echo call placed, waiting ${CONNECT_WAIT_MS / 1000}s`);
92
await delay(CONNECT_WAIT_MS);
93
runTeams('--unmute');
94
const connected = await appStats();
95
report.checks.connected = { pass: connected.inCall && /Connected/.test(connected.state), state: connected.state };
96
if (!report.checks.connected.pass) throw new Error(`echo call not connected: ${connected.state}`);
92
const placeEcho = async () => {
93
runTeams('--call', 'echo');
94
log(`echo call placed, waiting ${CONNECT_WAIT_MS / 1000}s`);
95
await delay(CONNECT_WAIT_MS);
96
runTeams('--unmute');
97
const connected = await appStats();
98
if (!(connected.inCall && /Connected/.test(connected.state))) throw new Error(`echo call not connected: ${connected.state}`);
99
};
100
await placeEcho();
101
report.checks.connected = { pass: true };
97
102
log(`listening ${LISTEN_SECONDS}s for the prompt and our echo`);
98
103
const recorded = await runProbe('record-process', String(teamsProcessId()), String(LISTEN_SECONDS), windowsPath(workDir + '/echo-heard.wav'));
99
104
report.checks.heard = judge(JSON.parse(recorded).rms);
105
await delay(ENDED_WAIT_MS);
106
const after = await appStats();
107
report.checks.endsWhenBotLeaves = { pass: !after.inCall, inCall: after.inCall, state: after.state };
108
if (after.inCall) runTeams('--hang-up');
109
await delay(5_000);
110
await placeEcho();
111
await delay(PROMPT_START_MS);
100
112
runTeams('--call', 'hold');
101
113
await delay(HOLD_SETTLE_MS);
102
114
const held = await mediaDelta(HOLD_MEASURE_MS);
103
report.checks.hold = { pass: held.sent <= HELD_PACKETS && /Local/.test(held.app.hold), sent: held.sent, received: held.received, hold: held.app.hold };
115
report.checks.hold = { pass: held.sent <= HELD_PACKETS && /Local/.test(held.app.hold), sent: held.sent, hold: held.app.hold };
104
116
runTeams('--call', 'resume');
105
117
await delay(HOLD_SETTLE_MS);
106
118
const resumed = await mediaDelta(HOLD_MEASURE_MS);
107
report.checks.resume = { pass: resumed.sent >= RESUMED_PACKETS && resumed.received >= RESUMED_PACKETS && /Active/.test(resumed.app.hold), sent: resumed.sent, received: resumed.received, hold: resumed.app.hold };
119
report.checks.resume = { pass: resumed.sent >= RESUMED_PACKETS && /Active/.test(resumed.app.hold), sent: resumed.sent, hold: resumed.app.hold };
108
120
await playing.catch((error) => (report.playError = error.message));
109
121
} catch (error) {
110
122
report.error = error.message;
@@ -1,6 +1,6 @@1
// 1:1 call end-to-end test against the Echo bot with the deployed Windows app: no second person needed.1
// 1:1 call end-to-end test against the Echo bot with the deployed Windows app: no second person needed.2
// The app's mic is VB-CABLE fed with a speech file; the bot plays its prompt, records us and plays it back.2
// The app's mic is VB-CABLE fed with a speech file; the bot plays its prompt, records us and plays it back.3
// Checks that the app hears the bot, that our speech comes back, and that hold and resume stop and restart media.3
// Checks the app hears the bot and our own speech back, that the call ends when the bot hangs up, and hold/resume in a second call.4
// Usage: node scripts/call-echo-e2e.mjs <work dir>4
// Usage: node scripts/call-echo-e2e.mjs <work dir>5
import { spawn, execFileSync } from 'node:child_process';5
import { spawn, execFileSync } from 'node:child_process';6
import { readFileSync, writeFileSync } from 'node:fs';6
import { readFileSync, writeFileSync } from 'node:fs';@@ -15,11 +15,13 @@ const CONNECT_WAIT_MS = 12_000;15
const LISTEN_SECONDS = 40;15
const LISTEN_SECONDS = 40;16
const HOLD_SETTLE_MS = 6_000;16
const HOLD_SETTLE_MS = 6_000;17
const HOLD_MEASURE_MS = 6_000;17
const HOLD_MEASURE_MS = 6_000;18
const PLAY_SECONDS = 150;18
const PLAY_SECONDS = 200;19
const APP_THRESHOLD = { speech: 200, floor: 20 };19
const APP_THRESHOLD = { speech: 200, floor: 20 };20
const SPEECH_TO_PAUSE = 4;20
const SPEECH_TO_PAUSE = 4;21
const RESUMED_PACKETS = 100;21
const RESUMED_PACKETS = 100;22
const HELD_PACKETS = 20;22
const PROMPT_START_MS = 3_000;23
const ENDED_WAIT_MS = 15_000;24
const HELD_PACKETS = 60;23
25
24
const windowsPath = (path) => execFileSync('wslpath', ['-w', path]).toString().trim();26
const windowsPath = (path) => execFileSync('wslpath', ['-w', path]).toString().trim();25
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));27
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));@@ -87,24 +89,34 @@ try {87
if (!teamsProcessId()) throw new Error('teams.exe is not running');89
if (!teamsProcessId()) throw new Error('teams.exe is not running');88
defaultAudio('set', 'capture', 'CABLE Output');90
defaultAudio('set', 'capture', 'CABLE Output');89
const playing = runProbe('play', 'CABLE Input', windowsPath(PROBE_DIR + '/app.wav'), String(PLAY_SECONDS));91
const playing = runProbe('play', 'CABLE Input', windowsPath(PROBE_DIR + '/app.wav'), String(PLAY_SECONDS));90
runTeams('--call', 'echo');92
const placeEcho = async () => {91
log(`echo call placed, waiting ${CONNECT_WAIT_MS / 1000}s`);93
runTeams('--call', 'echo');92
await delay(CONNECT_WAIT_MS);94
log(`echo call placed, waiting ${CONNECT_WAIT_MS / 1000}s`);93
runTeams('--unmute');95
await delay(CONNECT_WAIT_MS);94
const connected = await appStats();96
runTeams('--unmute');95
report.checks.connected = { pass: connected.inCall && /Connected/.test(connected.state), state: connected.state };97
const connected = await appStats();96
if (!report.checks.connected.pass) throw new Error(`echo call not connected: ${connected.state}`);98
if (!(connected.inCall && /Connected/.test(connected.state))) throw new Error(`echo call not connected: ${connected.state}`);99
};100
await placeEcho();101
report.checks.connected = { pass: true };97
log(`listening ${LISTEN_SECONDS}s for the prompt and our echo`);102
log(`listening ${LISTEN_SECONDS}s for the prompt and our echo`);98
const recorded = await runProbe('record-process', String(teamsProcessId()), String(LISTEN_SECONDS), windowsPath(workDir + '/echo-heard.wav'));103
const recorded = await runProbe('record-process', String(teamsProcessId()), String(LISTEN_SECONDS), windowsPath(workDir + '/echo-heard.wav'));99
report.checks.heard = judge(JSON.parse(recorded).rms);104
report.checks.heard = judge(JSON.parse(recorded).rms);105
await delay(ENDED_WAIT_MS);106
const after = await appStats();107
report.checks.endsWhenBotLeaves = { pass: !after.inCall, inCall: after.inCall, state: after.state };108
if (after.inCall) runTeams('--hang-up');109
await delay(5_000);110
await placeEcho();111
await delay(PROMPT_START_MS);100
runTeams('--call', 'hold');112
runTeams('--call', 'hold');101
await delay(HOLD_SETTLE_MS);113
await delay(HOLD_SETTLE_MS);102
const held = await mediaDelta(HOLD_MEASURE_MS);114
const held = await mediaDelta(HOLD_MEASURE_MS);103
report.checks.hold = { pass: held.sent <= HELD_PACKETS && /Local/.test(held.app.hold), sent: held.sent, received: held.received, hold: held.app.hold };115
report.checks.hold = { pass: held.sent <= HELD_PACKETS && /Local/.test(held.app.hold), sent: held.sent, hold: held.app.hold };104
runTeams('--call', 'resume');116
runTeams('--call', 'resume');105
await delay(HOLD_SETTLE_MS);117
await delay(HOLD_SETTLE_MS);106
const resumed = await mediaDelta(HOLD_MEASURE_MS);118
const resumed = await mediaDelta(HOLD_MEASURE_MS);107
report.checks.resume = { pass: resumed.sent >= RESUMED_PACKETS && resumed.received >= RESUMED_PACKETS && /Active/.test(resumed.app.hold), sent: resumed.sent, received: resumed.received, hold: resumed.app.hold };119
report.checks.resume = { pass: resumed.sent >= RESUMED_PACKETS && /Active/.test(resumed.app.hold), sent: resumed.sent, hold: resumed.app.hold };108
await playing.catch((error) => (report.playError = error.message));120
await playing.catch((error) => (report.playError = error.message));109
} catch (error) {121
} catch (error) {110
report.error = error.message;122
report.error = error.message;