BlueGit

ict rusty-teams

chore(call-e2e): echo bot 1:1 test with hold and resume

- teams --call echo|hold|resume; stats report the hold state
- call-echo-e2e.mjs: echo call connects, the app hears the prompt and our own speech back, hold stops sending, resume restarts both directions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-08 · 3 weeks ago

Hash
d0d1a44d2f81cc91874059f3ddc5518611618057
Parent
e2c4d5d1
2 files changed +135 −0
crates/app-state/src/call/remote_command.rs +17 −0
@@ -22,6 +22,9 @@ const SHARE_COMMAND: &str = "share";
22 22 const STOP_SHARE_COMMAND: &str = "stop-share";
23 23 const STATS_COMMAND: &str = "stats ";
24 24 const INPUT_COMMAND: &str = "input ";
25 const ECHO_COMMAND: &str = "echo";
26 const HOLD_COMMAND: &str = "hold";
27 const RESUME_COMMAND: &str = "resume";
25 28 const DEFAULT_DEVICE: &str = "default";
26 29
27 30 #[derive(Debug, Clone, PartialEq, Eq)]
@@ -37,6 +40,8 @@ pub enum RemoteCommand {
37 40 StopShare,
38 41 Stats(String),
39 42 Input(String),
43 EchoCall,
44 Hold(bool),
40 45 }
41 46
42 47 impl RemoteCommand {
@@ -54,6 +59,9 @@ impl RemoteCommand {
54 59 RemoteCommand::StopShare => STOP_SHARE_COMMAND.to_owned(),
55 60 RemoteCommand::Stats(path) => format!("{STATS_COMMAND}{path}"),
56 61 RemoteCommand::Input(name) => format!("{INPUT_COMMAND}{name}"),
62 RemoteCommand::EchoCall => ECHO_COMMAND.to_owned(),
63 RemoteCommand::Hold(true) => HOLD_COMMAND.to_owned(),
64 RemoteCommand::Hold(false) => RESUME_COMMAND.to_owned(),
57 65 }
58 66 }
59 67
@@ -68,6 +76,9 @@ impl RemoteCommand {
68 76 SHARE_SOURCES_COMMAND => return Some(RemoteCommand::RefreshShareSources),
69 77 SHARE_COMMAND => return Some(RemoteCommand::ShareScreen),
70 78 STOP_SHARE_COMMAND => return Some(RemoteCommand::StopShare),
79 ECHO_COMMAND => return Some(RemoteCommand::EchoCall),
80 HOLD_COMMAND => return Some(RemoteCommand::Hold(true)),
81 RESUME_COMMAND => return Some(RemoteCommand::Hold(false)),
71 82 _ => {}
72 83 }
73 84 if let Some(name) = text.strip_prefix(INPUT_COMMAND).map(str::trim) {
@@ -99,6 +110,8 @@ impl AppState {
99 110 Some(RemoteCommand::ShareScreen) => self.share_first_screen(),
100 111 Some(RemoteCommand::StopShare) => self.send_call_command(CallCommand::StopShare),
101 112 Some(RemoteCommand::Input(name)) => self.switch_input_for_test(&name),
113 Some(RemoteCommand::EchoCall) => self.start_test_call(cx),
114 Some(RemoteCommand::Hold(hold)) => self.send_call_command(CallCommand::Hold(hold)),
102 115 Some(RemoteCommand::Stats(path)) => {
103 116 let _ = std::fs::write(path, self.call_stats().to_string());
104 117 }
@@ -150,6 +163,7 @@ impl AppState {
150 163 "state": format!("{:?}", model.state),
151 164 "muted": model.muted,
152 165 "input": format!("{:?}", model.input),
166 "hold": format!("{:?}", model.hold),
153 167 "cameraOn": model.camera_on,
154 168 "localShare": model.local_share,
155 169 "screenSharer": model.screen_sharer,
@@ -192,6 +206,9 @@ mod tests {
192 206 RemoteCommand::StopShare,
193 207 RemoteCommand::Stats("C:\\temp\\stats.json".to_owned()),
194 208 RemoteCommand::Input("cable output".to_owned()),
209 RemoteCommand::EchoCall,
210 RemoteCommand::Hold(true),
211 RemoteCommand::Hold(false),
195 212 ] {
196 213 assert_eq!(RemoteCommand::decode(&command.encode()), Some(command));
197 214 }
@@ -22,6 +22,9 @@ const SHARE_COMMAND: &str = "share";
22const STOP_SHARE_COMMAND: &str = "stop-share";
22const STOP_SHARE_COMMAND: &str = "stop-share";
23const STATS_COMMAND: &str = "stats ";
23const STATS_COMMAND: &str = "stats ";
24const INPUT_COMMAND: &str = "input ";
24const INPUT_COMMAND: &str = "input ";
25const ECHO_COMMAND: &str = "echo";
26const HOLD_COMMAND: &str = "hold";
27const RESUME_COMMAND: &str = "resume";
25const DEFAULT_DEVICE: &str = "default";
28const DEFAULT_DEVICE: &str = "default";
26
29
27#[derive(Debug, Clone, PartialEq, Eq)]
30#[derive(Debug, Clone, PartialEq, Eq)]
@@ -37,6 +40,8 @@ pub enum RemoteCommand {
37 StopShare,
40 StopShare,
38 Stats(String),
41 Stats(String),
39 Input(String),
42 Input(String),
43 EchoCall,
44 Hold(bool),
40}
45}
41
46
42impl RemoteCommand {
47impl RemoteCommand {
@@ -54,6 +59,9 @@ impl RemoteCommand {
54 RemoteCommand::StopShare => STOP_SHARE_COMMAND.to_owned(),
59 RemoteCommand::StopShare => STOP_SHARE_COMMAND.to_owned(),
55 RemoteCommand::Stats(path) => format!("{STATS_COMMAND}{path}"),
60 RemoteCommand::Stats(path) => format!("{STATS_COMMAND}{path}"),
56 RemoteCommand::Input(name) => format!("{INPUT_COMMAND}{name}"),
61 RemoteCommand::Input(name) => format!("{INPUT_COMMAND}{name}"),
62 RemoteCommand::EchoCall => ECHO_COMMAND.to_owned(),
63 RemoteCommand::Hold(true) => HOLD_COMMAND.to_owned(),
64 RemoteCommand::Hold(false) => RESUME_COMMAND.to_owned(),
57 }
65 }
58 }
66 }
59
67
@@ -68,6 +76,9 @@ impl RemoteCommand {
68 SHARE_SOURCES_COMMAND => return Some(RemoteCommand::RefreshShareSources),
76 SHARE_SOURCES_COMMAND => return Some(RemoteCommand::RefreshShareSources),
69 SHARE_COMMAND => return Some(RemoteCommand::ShareScreen),
77 SHARE_COMMAND => return Some(RemoteCommand::ShareScreen),
70 STOP_SHARE_COMMAND => return Some(RemoteCommand::StopShare),
78 STOP_SHARE_COMMAND => return Some(RemoteCommand::StopShare),
79 ECHO_COMMAND => return Some(RemoteCommand::EchoCall),
80 HOLD_COMMAND => return Some(RemoteCommand::Hold(true)),
81 RESUME_COMMAND => return Some(RemoteCommand::Hold(false)),
71 _ => {}
82 _ => {}
72 }
83 }
73 if let Some(name) = text.strip_prefix(INPUT_COMMAND).map(str::trim) {
84 if let Some(name) = text.strip_prefix(INPUT_COMMAND).map(str::trim) {
@@ -99,6 +110,8 @@ impl AppState {
99 Some(RemoteCommand::ShareScreen) => self.share_first_screen(),
110 Some(RemoteCommand::ShareScreen) => self.share_first_screen(),
100 Some(RemoteCommand::StopShare) => self.send_call_command(CallCommand::StopShare),
111 Some(RemoteCommand::StopShare) => self.send_call_command(CallCommand::StopShare),
101 Some(RemoteCommand::Input(name)) => self.switch_input_for_test(&name),
112 Some(RemoteCommand::Input(name)) => self.switch_input_for_test(&name),
113 Some(RemoteCommand::EchoCall) => self.start_test_call(cx),
114 Some(RemoteCommand::Hold(hold)) => self.send_call_command(CallCommand::Hold(hold)),
102 Some(RemoteCommand::Stats(path)) => {
115 Some(RemoteCommand::Stats(path)) => {
103 let _ = std::fs::write(path, self.call_stats().to_string());
116 let _ = std::fs::write(path, self.call_stats().to_string());
104 }
117 }
@@ -150,6 +163,7 @@ impl AppState {
150 "state": format!("{:?}", model.state),
163 "state": format!("{:?}", model.state),
151 "muted": model.muted,
164 "muted": model.muted,
152 "input": format!("{:?}", model.input),
165 "input": format!("{:?}", model.input),
166 "hold": format!("{:?}", model.hold),
153 "cameraOn": model.camera_on,
167 "cameraOn": model.camera_on,
154 "localShare": model.local_share,
168 "localShare": model.local_share,
155 "screenSharer": model.screen_sharer,
169 "screenSharer": model.screen_sharer,
@@ -192,6 +206,9 @@ mod tests {
192 RemoteCommand::StopShare,
206 RemoteCommand::StopShare,
193 RemoteCommand::Stats("C:\\temp\\stats.json".to_owned()),
207 RemoteCommand::Stats("C:\\temp\\stats.json".to_owned()),
194 RemoteCommand::Input("cable output".to_owned()),
208 RemoteCommand::Input("cable output".to_owned()),
209 RemoteCommand::EchoCall,
210 RemoteCommand::Hold(true),
211 RemoteCommand::Hold(false),
195 ] {
212 ] {
196 assert_eq!(RemoteCommand::decode(&command.encode()), Some(command));
213 assert_eq!(RemoteCommand::decode(&command.encode()), Some(command));
197 }
214 }
scripts/call-echo-e2e.mjs added +118 −0
@@ -0,0 +1,118 @@
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.
3 // Checks that the app hears the bot, that our speech comes back, and that hold and resume stop and restart media.
4 // Usage: node scripts/call-echo-e2e.mjs <work dir>
5 import { spawn, execFileSync } from 'node:child_process';
6 import { readFileSync, writeFileSync } from 'node:fs';
7
8 const [workDir] = process.argv.slice(2);
9 const PROBE_DIR = process.env.PROBE_DIR ?? '/mnt/c/Users/dd/AppData/Local/Temp/call-e2e';
10 const TEAMS_EXE = process.env.TEAMS_EXE ?? '/mnt/c/Users/dd/AppData/Local/Programs/ms-teams-linux/teams.exe';
11 const POWERSHELL = '/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe';
12 const TASKLIST = '/mnt/c/Windows/System32/tasklist.exe';
13 const SCRIPT_DIR = new URL('.', import.meta.url).pathname;
14 const CONNECT_WAIT_MS = 12_000;
15 const LISTEN_SECONDS = 40;
16 const HOLD_SETTLE_MS = 6_000;
17 const HOLD_MEASURE_MS = 6_000;
18 const PLAY_SECONDS = 150;
19 const APP_THRESHOLD = { speech: 200, floor: 20 };
20 const SPEECH_TO_PAUSE = 4;
21 const RESUMED_PACKETS = 100;
22 const HELD_PACKETS = 20;
23
24 const windowsPath = (path) => execFileSync('wslpath', ['-w', path]).toString().trim();
25 const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
26 const log = (message) => console.error(`[${new Date().toISOString().slice(11, 19)}] ${message}`);
27
28 function defaultAudio(...args) {
29 const script = windowsPath(SCRIPT_DIR + 'default-audio.ps1');
30 return execFileSync(POWERSHELL, ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', script, ...args]).toString().trim();
31 }
32
33 function teamsProcessId() {
34 const rows = execFileSync(TASKLIST, ['/FI', 'IMAGENAME eq teams.exe', '/FO', 'CSV', '/NH']).toString().trim().split(/\r?\n/);
35 const processes = rows
36 .map((row) => row.split('","').map((cell) => cell.replace(/"/g, '')))
37 .filter((cells) => cells[0]?.toLowerCase() === 'teams.exe')
38 .map((cells) => ({ id: Number(cells[1]), memory: Number(cells[4].replace(/\D/g, '')) }));
39 processes.sort((left, right) => right.memory - left.memory);
40 return processes[0]?.id;
41 }
42
43 const runTeams = (...args) => spawn(TEAMS_EXE, args, { detached: true, stdio: 'ignore' }).unref();
44
45 function runProbe(...args) {
46 return new Promise((resolve, reject) => {
47 const child = spawn(PROBE_DIR + '/audio_probe.exe', args, { stdio: ['ignore', 'pipe', 'pipe'] });
48 let output = '';
49 let errors = '';
50 child.stdout.on('data', (chunk) => (output += chunk));
51 child.stderr.on('data', (chunk) => (errors += chunk));
52 child.on('exit', (code) => (code === 0 ? resolve(output) : reject(new Error(`audio_probe ${args[0]}: ${errors.trim()}`))));
53 });
54 }
55
56 async function appStats() {
57 const path = workDir + '/app-stats.json';
58 writeFileSync(path, '');
59 runTeams('--call', `stats ${windowsPath(path)}`);
60 for (let attempt = 0; attempt < 6; attempt++) {
61 await delay(1_500);
62 const text = readFileSync(path, 'utf8');
63 if (text) return JSON.parse(text);
64 }
65 throw new Error('the app wrote no stats');
66 }
67
68 function judge(levels) {
69 const sorted = [...levels].sort((left, right) => left - right);
70 const percentile = (share) => sorted[Math.min(sorted.length - 1, Math.floor(share * sorted.length))] ?? 0;
71 const [p10, p90] = [percentile(0.1), percentile(0.9)];
72 return { pass: p90 >= APP_THRESHOLD.speech && p90 >= SPEECH_TO_PAUSE * Math.max(p10, APP_THRESHOLD.floor), p10, p90 };
73 }
74
75 async function mediaDelta(ms) {
76 const before = await appStats();
77 await delay(ms);
78 const after = await appStats();
79 return { app: after, sent: after.audioOutPackets - before.audioOutPackets, received: after.audioInPackets - before.audioInPackets };
80 }
81
82 const report = { started: new Date().toISOString(), checks: {} };
83 const savedCapture = defaultAudio('get', 'capture');
84 const restoreCapture = () => defaultAudio('set', 'capture', savedCapture);
85 for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => { restoreCapture(); process.exit(130); });
86 try {
87 if (!teamsProcessId()) throw new Error('teams.exe is not running');
88 defaultAudio('set', 'capture', 'CABLE Output');
89 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}`);
97 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'));
99 report.checks.heard = judge(JSON.parse(recorded).rms);
100 runTeams('--call', 'hold');
101 await delay(HOLD_SETTLE_MS);
102 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 };
104 runTeams('--call', 'resume');
105 await delay(HOLD_SETTLE_MS);
106 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 };
108 await playing.catch((error) => (report.playError = error.message));
109 } catch (error) {
110 report.error = error.message;
111 } finally {
112 if (teamsProcessId()) runTeams('--hang-up');
113 restoreCapture();
114 }
115 report.pass = !report.error && Object.values(report.checks).every((check) => check.pass);
116 writeFileSync(workDir + '/echo-report.json', JSON.stringify(report, null, 2));
117 console.log(JSON.stringify({ pass: report.pass, checks: report.checks, error: report.error }));
118 process.exit(report.pass ? 0 : 1);
@@ -0,0 +1,118 @@
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.
3// Checks that the app hears the bot, that our speech comes back, and that hold and resume stop and restart media.
4// Usage: node scripts/call-echo-e2e.mjs <work dir>
5import { spawn, execFileSync } from 'node:child_process';
6import { readFileSync, writeFileSync } from 'node:fs';
7
8const [workDir] = process.argv.slice(2);
9const PROBE_DIR = process.env.PROBE_DIR ?? '/mnt/c/Users/dd/AppData/Local/Temp/call-e2e';
10const TEAMS_EXE = process.env.TEAMS_EXE ?? '/mnt/c/Users/dd/AppData/Local/Programs/ms-teams-linux/teams.exe';
11const POWERSHELL = '/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe';
12const TASKLIST = '/mnt/c/Windows/System32/tasklist.exe';
13const SCRIPT_DIR = new URL('.', import.meta.url).pathname;
14const CONNECT_WAIT_MS = 12_000;
15const LISTEN_SECONDS = 40;
16const HOLD_SETTLE_MS = 6_000;
17const HOLD_MEASURE_MS = 6_000;
18const PLAY_SECONDS = 150;
19const APP_THRESHOLD = { speech: 200, floor: 20 };
20const SPEECH_TO_PAUSE = 4;
21const RESUMED_PACKETS = 100;
22const HELD_PACKETS = 20;
23
24const windowsPath = (path) => execFileSync('wslpath', ['-w', path]).toString().trim();
25const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
26const log = (message) => console.error(`[${new Date().toISOString().slice(11, 19)}] ${message}`);
27
28function defaultAudio(...args) {
29 const script = windowsPath(SCRIPT_DIR + 'default-audio.ps1');
30 return execFileSync(POWERSHELL, ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', script, ...args]).toString().trim();
31}
32
33function teamsProcessId() {
34 const rows = execFileSync(TASKLIST, ['/FI', 'IMAGENAME eq teams.exe', '/FO', 'CSV', '/NH']).toString().trim().split(/\r?\n/);
35 const processes = rows
36 .map((row) => row.split('","').map((cell) => cell.replace(/"/g, '')))
37 .filter((cells) => cells[0]?.toLowerCase() === 'teams.exe')
38 .map((cells) => ({ id: Number(cells[1]), memory: Number(cells[4].replace(/\D/g, '')) }));
39 processes.sort((left, right) => right.memory - left.memory);
40 return processes[0]?.id;
41}
42
43const runTeams = (...args) => spawn(TEAMS_EXE, args, { detached: true, stdio: 'ignore' }).unref();
44
45function runProbe(...args) {
46 return new Promise((resolve, reject) => {
47 const child = spawn(PROBE_DIR + '/audio_probe.exe', args, { stdio: ['ignore', 'pipe', 'pipe'] });
48 let output = '';
49 let errors = '';
50 child.stdout.on('data', (chunk) => (output += chunk));
51 child.stderr.on('data', (chunk) => (errors += chunk));
52 child.on('exit', (code) => (code === 0 ? resolve(output) : reject(new Error(`audio_probe ${args[0]}: ${errors.trim()}`))));
53 });
54}
55
56async function appStats() {
57 const path = workDir + '/app-stats.json';
58 writeFileSync(path, '');
59 runTeams('--call', `stats ${windowsPath(path)}`);
60 for (let attempt = 0; attempt < 6; attempt++) {
61 await delay(1_500);
62 const text = readFileSync(path, 'utf8');
63 if (text) return JSON.parse(text);
64 }
65 throw new Error('the app wrote no stats');
66}
67
68function judge(levels) {
69 const sorted = [...levels].sort((left, right) => left - right);
70 const percentile = (share) => sorted[Math.min(sorted.length - 1, Math.floor(share * sorted.length))] ?? 0;
71 const [p10, p90] = [percentile(0.1), percentile(0.9)];
72 return { pass: p90 >= APP_THRESHOLD.speech && p90 >= SPEECH_TO_PAUSE * Math.max(p10, APP_THRESHOLD.floor), p10, p90 };
73}
74
75async function mediaDelta(ms) {
76 const before = await appStats();
77 await delay(ms);
78 const after = await appStats();
79 return { app: after, sent: after.audioOutPackets - before.audioOutPackets, received: after.audioInPackets - before.audioInPackets };
80}
81
82const report = { started: new Date().toISOString(), checks: {} };
83const savedCapture = defaultAudio('get', 'capture');
84const restoreCapture = () => defaultAudio('set', 'capture', savedCapture);
85for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => { restoreCapture(); process.exit(130); });
86try {
87 if (!teamsProcessId()) throw new Error('teams.exe is not running');
88 defaultAudio('set', 'capture', 'CABLE Output');
89 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}`);
97 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'));
99 report.checks.heard = judge(JSON.parse(recorded).rms);
100 runTeams('--call', 'hold');
101 await delay(HOLD_SETTLE_MS);
102 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 };
104 runTeams('--call', 'resume');
105 await delay(HOLD_SETTLE_MS);
106 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 };
108 await playing.catch((error) => (report.playError = error.message));
109} catch (error) {
110 report.error = error.message;
111} finally {
112 if (teamsProcessId()) runTeams('--hang-up');
113 restoreCapture();
114}
115report.pass = !report.error && Object.values(report.checks).every((check) => check.pass);
116writeFileSync(workDir + '/echo-report.json', JSON.stringify(report, null, 2));
117console.log(JSON.stringify({ pass: report.pass, checks: report.checks, error: report.error }));
118process.exit(report.pass ? 0 : 1);