chore(call-e2e): mic switch and leave/rejoin scenarios
- teams --call "input <name>|default" switches the call mic without saving the choice - call-e2e switches to another mic and back, then leaves and rejoins, checking the guest hears speech after each Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -1,4 +1,4 @@
1
use calling::{CallCommand, MuteCommand, ShareKind};
1
use calling::{CallCommand, DeviceChoice, MuteCommand, ShareKind};
2
2
use gpui_kit::*;
3
3
use serde_json::json;
4
4
@@ -21,6 +21,8 @@ const SHARE_SOURCES_COMMAND: &str = "share-sources";
21
21
const SHARE_COMMAND: &str = "share";
22
22
const STOP_SHARE_COMMAND: &str = "stop-share";
23
23
const STATS_COMMAND: &str = "stats ";
24
const INPUT_COMMAND: &str = "input ";
25
const DEFAULT_DEVICE: &str = "default";
24
26
25
27
#[derive(Debug, Clone, PartialEq, Eq)]
26
28
pub enum RemoteCommand {
@@ -34,6 +36,7 @@ pub enum RemoteCommand {
34
36
ShareScreen,
35
37
StopShare,
36
38
Stats(String),
39
Input(String),
37
40
}
38
41
39
42
impl RemoteCommand {
@@ -50,6 +53,7 @@ impl RemoteCommand {
50
53
RemoteCommand::ShareScreen => SHARE_COMMAND.to_owned(),
51
54
RemoteCommand::StopShare => STOP_SHARE_COMMAND.to_owned(),
52
55
RemoteCommand::Stats(path) => format!("{STATS_COMMAND}{path}"),
56
RemoteCommand::Input(name) => format!("{INPUT_COMMAND}{name}"),
53
57
}
54
58
}
55
59
@@ -66,6 +70,9 @@ impl RemoteCommand {
66
70
STOP_SHARE_COMMAND => return Some(RemoteCommand::StopShare),
67
71
_ => {}
68
72
}
73
if let Some(name) = text.strip_prefix(INPUT_COMMAND).map(str::trim) {
74
return (!name.is_empty()).then(|| RemoteCommand::Input(name.to_owned()));
75
}
69
76
if let Some(path) = text.strip_prefix(STATS_COMMAND).map(str::trim) {
70
77
return (!path.is_empty()).then(|| RemoteCommand::Stats(path.to_owned()));
71
78
}
@@ -91,6 +98,7 @@ impl AppState {
91
98
Some(RemoteCommand::RefreshShareSources) => self.send_call_command(CallCommand::RefreshShareSources),
92
99
Some(RemoteCommand::ShareScreen) => self.share_first_screen(),
93
100
Some(RemoteCommand::StopShare) => self.send_call_command(CallCommand::StopShare),
101
Some(RemoteCommand::Input(name)) => self.switch_input_for_test(&name),
94
102
Some(RemoteCommand::Stats(path)) => {
95
103
let _ = std::fs::write(path, self.call_stats().to_string());
96
104
}
@@ -111,6 +119,26 @@ impl AppState {
111
119
}
112
120
}
113
121
122
/// Switches the call's microphone without saving it as the user's choice.
123
fn switch_input_for_test(&self, name: &str) {
124
if name == DEFAULT_DEVICE {
125
self.send_call_command(CallCommand::SelectInput(DeviceChoice::SystemDefault));
126
return;
127
}
128
let wanted = name.to_lowercase();
129
let device = self.call.as_ref().and_then(|call| {
130
call.model
131
.devices
132
.inputs
133
.iter()
134
.find(|device| device.name.to_lowercase().contains(&wanted))
135
.map(|device| device.key())
136
});
137
if let Some(key) = device {
138
self.send_call_command(CallCommand::SelectInput(DeviceChoice::Device(key)));
139
}
140
}
141
114
142
fn call_stats(&self) -> serde_json::Value {
115
143
let Some(call) = self.call.as_ref() else {
116
144
return json!({ "inCall": false });
@@ -121,6 +149,7 @@ impl AppState {
121
149
"inCall": true,
122
150
"state": format!("{:?}", model.state),
123
151
"muted": model.muted,
152
"input": format!("{:?}", model.input),
124
153
"cameraOn": model.camera_on,
125
154
"localShare": model.local_share,
126
155
"screenSharer": model.screen_sharer,
@@ -162,6 +191,7 @@ mod tests {
162
191
RemoteCommand::ShareScreen,
163
192
RemoteCommand::StopShare,
164
193
RemoteCommand::Stats("C:\\temp\\stats.json".to_owned()),
194
RemoteCommand::Input("cable output".to_owned()),
165
195
] {
166
196
assert_eq!(RemoteCommand::decode(&command.encode()), Some(command));
167
197
}
@@ -1,4 +1,4 @@1
use calling::{CallCommand, MuteCommand, ShareKind};1
use calling::{CallCommand, DeviceChoice, MuteCommand, ShareKind};2
use gpui_kit::*;2
use gpui_kit::*;3
use serde_json::json;3
use serde_json::json;4
4
@@ -21,6 +21,8 @@ const SHARE_SOURCES_COMMAND: &str = "share-sources";21
const SHARE_COMMAND: &str = "share";21
const SHARE_COMMAND: &str = "share";22
const STOP_SHARE_COMMAND: &str = "stop-share";22
const STOP_SHARE_COMMAND: &str = "stop-share";23
const STATS_COMMAND: &str = "stats ";23
const STATS_COMMAND: &str = "stats ";24
const INPUT_COMMAND: &str = "input ";25
const DEFAULT_DEVICE: &str = "default";24
26
25
#[derive(Debug, Clone, PartialEq, Eq)]27
#[derive(Debug, Clone, PartialEq, Eq)]26
pub enum RemoteCommand {28
pub enum RemoteCommand {@@ -34,6 +36,7 @@ pub enum RemoteCommand {34
ShareScreen,36
ShareScreen,35
StopShare,37
StopShare,36
Stats(String),38
Stats(String),39
Input(String),37
}40
}38
41
39
impl RemoteCommand {42
impl RemoteCommand {@@ -50,6 +53,7 @@ impl RemoteCommand {50
RemoteCommand::ShareScreen => SHARE_COMMAND.to_owned(),53
RemoteCommand::ShareScreen => SHARE_COMMAND.to_owned(),51
RemoteCommand::StopShare => STOP_SHARE_COMMAND.to_owned(),54
RemoteCommand::StopShare => STOP_SHARE_COMMAND.to_owned(),52
RemoteCommand::Stats(path) => format!("{STATS_COMMAND}{path}"),55
RemoteCommand::Stats(path) => format!("{STATS_COMMAND}{path}"),56
RemoteCommand::Input(name) => format!("{INPUT_COMMAND}{name}"),53
}57
}54
}58
}55
59
@@ -66,6 +70,9 @@ impl RemoteCommand {66
STOP_SHARE_COMMAND => return Some(RemoteCommand::StopShare),70
STOP_SHARE_COMMAND => return Some(RemoteCommand::StopShare),67
_ => {}71
_ => {}68
}72
}73
if let Some(name) = text.strip_prefix(INPUT_COMMAND).map(str::trim) {74
return (!name.is_empty()).then(|| RemoteCommand::Input(name.to_owned()));75
}69
if let Some(path) = text.strip_prefix(STATS_COMMAND).map(str::trim) {76
if let Some(path) = text.strip_prefix(STATS_COMMAND).map(str::trim) {70
return (!path.is_empty()).then(|| RemoteCommand::Stats(path.to_owned()));77
return (!path.is_empty()).then(|| RemoteCommand::Stats(path.to_owned()));71
}78
}@@ -91,6 +98,7 @@ impl AppState {91
Some(RemoteCommand::RefreshShareSources) => self.send_call_command(CallCommand::RefreshShareSources),98
Some(RemoteCommand::RefreshShareSources) => self.send_call_command(CallCommand::RefreshShareSources),92
Some(RemoteCommand::ShareScreen) => self.share_first_screen(),99
Some(RemoteCommand::ShareScreen) => self.share_first_screen(),93
Some(RemoteCommand::StopShare) => self.send_call_command(CallCommand::StopShare),100
Some(RemoteCommand::StopShare) => self.send_call_command(CallCommand::StopShare),101
Some(RemoteCommand::Input(name)) => self.switch_input_for_test(&name),94
Some(RemoteCommand::Stats(path)) => {102
Some(RemoteCommand::Stats(path)) => {95
let _ = std::fs::write(path, self.call_stats().to_string());103
let _ = std::fs::write(path, self.call_stats().to_string());96
}104
}@@ -111,6 +119,26 @@ impl AppState {111
}119
}112
}120
}113
121
122
/// Switches the call's microphone without saving it as the user's choice.123
fn switch_input_for_test(&self, name: &str) {124
if name == DEFAULT_DEVICE {125
self.send_call_command(CallCommand::SelectInput(DeviceChoice::SystemDefault));126
return;127
}128
let wanted = name.to_lowercase();129
let device = self.call.as_ref().and_then(|call| {130
call.model131
.devices132
.inputs133
.iter()134
.find(|device| device.name.to_lowercase().contains(&wanted))135
.map(|device| device.key())136
});137
if let Some(key) = device {138
self.send_call_command(CallCommand::SelectInput(DeviceChoice::Device(key)));139
}140
}141
114
fn call_stats(&self) -> serde_json::Value {142
fn call_stats(&self) -> serde_json::Value {115
let Some(call) = self.call.as_ref() else {143
let Some(call) = self.call.as_ref() else {116
return json!({ "inCall": false });144
return json!({ "inCall": false });@@ -121,6 +149,7 @@ impl AppState {121
"inCall": true,149
"inCall": true,122
"state": format!("{:?}", model.state),150
"state": format!("{:?}", model.state),123
"muted": model.muted,151
"muted": model.muted,152
"input": format!("{:?}", model.input),124
"cameraOn": model.camera_on,153
"cameraOn": model.camera_on,125
"localShare": model.local_share,154
"localShare": model.local_share,126
"screenSharer": model.screen_sharer,155
"screenSharer": model.screen_sharer,@@ -162,6 +191,7 @@ mod tests {162
RemoteCommand::ShareScreen,191
RemoteCommand::ShareScreen,163
RemoteCommand::StopShare,192
RemoteCommand::StopShare,164
RemoteCommand::Stats("C:\\temp\\stats.json".to_owned()),193
RemoteCommand::Stats("C:\\temp\\stats.json".to_owned()),194
RemoteCommand::Input("cable output".to_owned()),165
] {195
] {166
assert_eq!(RemoteCommand::decode(&command.encode()), Some(command));196
assert_eq!(RemoteCommand::decode(&command.encode()), Some(command));167
}197
}@@ -379,9 +379,26 @@ async function runScenarios(report, tab, workDir) {
379
379
report.scenarios['app-mute'].guestHeardWhileMuted = judge(muted, WEB_THRESHOLD);
380
380
if (report.scenarios['app-mute'].guestHeardWhileMuted.p90 >= WEB_THRESHOLD.speech) report.scenarios['app-mute'].pass = false;
381
381
await scenario('app-unmute', report, tab, workDir, () => runTeams('--call', 'unmute'), (m) => !m.app.muted);
382
const unmuted = await sampleWeb(tab, 8);
383
report.scenarios['app-unmute'].guestHears = judge(unmuted, WEB_THRESHOLD);
384
if (!report.scenarios['app-unmute'].guestHears.pass) report.scenarios['app-unmute'].pass = false;
382
await audioCheck(report, 'app-unmute', tab, true);
383
await scenario('mic-to-other-device', report, tab, workDir, () => runTeams('--call', 'input microphone array'),
384
(m) => m.app.inCall && /Device/.test(m.app.input ?? ''));
385
await scenario('mic-back-to-cable', report, tab, workDir, () => runTeams('--call', 'input cable output'), (m) => m.app.inCall);
386
await audioCheck(report, 'mic-back-to-cable', tab, true);
387
await scenario('leave-and-rejoin', report, tab, workDir, async () => {
388
runTeams('--hang-up');
389
await delay(8_000);
390
runTeams('--join', report.link);
391
await delay(APP_JOIN_WAIT_MS);
392
runTeams('--unmute');
393
}, (m) => m.app.inCall);
394
await audioCheck(report, 'leave-and-rejoin', tab, true);
395
}
396
397
async function audioCheck(report, name, tab, expectSpeech) {
398
const entry = report.scenarios[name];
399
if (!entry) return;
400
entry.guestHears = judge(await sampleWeb(tab, 8), WEB_THRESHOLD);
401
if (entry.guestHears.pass !== expectSpeech) entry.pass = false;
385
402
}
386
403
387
404
const report = { started: new Date().toISOString() };
@@ -402,7 +419,7 @@ try {
402
419
log('meeting ready');
403
420
defaultAudio('set', 'capture', 'CABLE Output');
404
421
log('default mic: CABLE Output');
405
const playSeconds = Math.ceil((APP_JOIN_WAIT_MS + WEB_JOIN_TIMEOUT_MS) / 1000) + MEASURE_SECONDS + 10 + (process.env.AUDIO_ONLY ? 0 : 240);
422
const playSeconds = Math.ceil((APP_JOIN_WAIT_MS + WEB_JOIN_TIMEOUT_MS) / 1000) + MEASURE_SECONDS + 10 + (process.env.AUDIO_ONLY ? 0 : 360);
406
423
const playing = runProbe('play', 'CABLE Input', windowsPath(PROBE_DIR + '/app.wav'), String(playSeconds));
407
424
runTeams('--join', link);
408
425
log(`app joining, waiting ${APP_JOIN_WAIT_MS / 1000}s`);
@@ -379,9 +379,26 @@ async function runScenarios(report, tab, workDir) {379
report.scenarios['app-mute'].guestHeardWhileMuted = judge(muted, WEB_THRESHOLD);379
report.scenarios['app-mute'].guestHeardWhileMuted = judge(muted, WEB_THRESHOLD);380
if (report.scenarios['app-mute'].guestHeardWhileMuted.p90 >= WEB_THRESHOLD.speech) report.scenarios['app-mute'].pass = false;380
if (report.scenarios['app-mute'].guestHeardWhileMuted.p90 >= WEB_THRESHOLD.speech) report.scenarios['app-mute'].pass = false;381
await scenario('app-unmute', report, tab, workDir, () => runTeams('--call', 'unmute'), (m) => !m.app.muted);381
await scenario('app-unmute', report, tab, workDir, () => runTeams('--call', 'unmute'), (m) => !m.app.muted);382
const unmuted = await sampleWeb(tab, 8);382
await audioCheck(report, 'app-unmute', tab, true);383
report.scenarios['app-unmute'].guestHears = judge(unmuted, WEB_THRESHOLD);383
await scenario('mic-to-other-device', report, tab, workDir, () => runTeams('--call', 'input microphone array'),384
if (!report.scenarios['app-unmute'].guestHears.pass) report.scenarios['app-unmute'].pass = false;384
(m) => m.app.inCall && /Device/.test(m.app.input ?? ''));385
await scenario('mic-back-to-cable', report, tab, workDir, () => runTeams('--call', 'input cable output'), (m) => m.app.inCall);386
await audioCheck(report, 'mic-back-to-cable', tab, true);387
await scenario('leave-and-rejoin', report, tab, workDir, async () => {388
runTeams('--hang-up');389
await delay(8_000);390
runTeams('--join', report.link);391
await delay(APP_JOIN_WAIT_MS);392
runTeams('--unmute');393
}, (m) => m.app.inCall);394
await audioCheck(report, 'leave-and-rejoin', tab, true);395
}396
397
async function audioCheck(report, name, tab, expectSpeech) {398
const entry = report.scenarios[name];399
if (!entry) return;400
entry.guestHears = judge(await sampleWeb(tab, 8), WEB_THRESHOLD);401
if (entry.guestHears.pass !== expectSpeech) entry.pass = false;385
}402
}386
403
387
const report = { started: new Date().toISOString() };404
const report = { started: new Date().toISOString() };@@ -402,7 +419,7 @@ try {402
log('meeting ready');419
log('meeting ready');403
defaultAudio('set', 'capture', 'CABLE Output');420
defaultAudio('set', 'capture', 'CABLE Output');404
log('default mic: CABLE Output');421
log('default mic: CABLE Output');405
const playSeconds = Math.ceil((APP_JOIN_WAIT_MS + WEB_JOIN_TIMEOUT_MS) / 1000) + MEASURE_SECONDS + 10 + (process.env.AUDIO_ONLY ? 0 : 240);422
const playSeconds = Math.ceil((APP_JOIN_WAIT_MS + WEB_JOIN_TIMEOUT_MS) / 1000) + MEASURE_SECONDS + 10 + (process.env.AUDIO_ONLY ? 0 : 360);406
const playing = runProbe('play', 'CABLE Input', windowsPath(PROBE_DIR + '/app.wav'), String(playSeconds));423
const playing = runProbe('play', 'CABLE Input', windowsPath(PROBE_DIR + '/app.wav'), String(playSeconds));407
runTeams('--join', link);424
runTeams('--join', link);408
log(`app joining, waiting ${APP_JOIN_WAIT_MS / 1000}s`);425
log(`app joining, waiting ${APP_JOIN_WAIT_MS / 1000}s`);