Skip to content

Commit a45eaf6

Browse files
fix(meeting-bot): dedupe prerequisite command probes
1 parent e406b3e commit a45eaf6

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎extensions/teams-meetings/src/node-host.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ vi.mock("node:child_process", async (importOriginal) => {
77
return { ...actual, spawnSync: spawnSyncMock };
88
});
99

10+
import { teamsMeetingsConfig } from "./config.js";
1011
import { handleTeamsMeetingsNodeHostCommand } from "./node-host.js";
1112

1213
const successfulProbe = {
@@ -53,6 +54,26 @@ describe("Teams meeting node-host prerequisite deadline", () => {
5354
).toEqual([10_000, 7_000, 3_000]);
5455
});
5556

57+
it("probes the default sox executable only once", async () => {
58+
await expect(
59+
handleTeamsMeetingsNodeHostCommand(
60+
JSON.stringify({
61+
action: "setup",
62+
audioInputCommand: teamsMeetingsConfig.defaultAudioInputCommand,
63+
audioOutputCommand: teamsMeetingsConfig.defaultAudioOutputCommand,
64+
}),
65+
),
66+
).resolves.toBe(JSON.stringify({ ok: true }));
67+
68+
expect(spawnSyncMock).toHaveBeenCalledTimes(2);
69+
expect(spawnSyncMock.mock.calls[1]?.[1]).toEqual([
70+
"-lc",
71+
'command -v "$1" >/dev/null 2>&1',
72+
"sh",
73+
"sox",
74+
]);
75+
});
76+
5677
it("does not start another probe after the shared deadline expires", async () => {
5778
const now = vi.spyOn(Date, "now");
5879
for (const value of [1_000, 1_000, 11_000]) {

‎src/meeting-bot/node-host.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,15 @@ export function createMeetingConfiguredNodeHost(options: MeetingConfiguredNodeHo
674674
) {
675675
throw new Error("BlackHole 2ch audio device not found on the node.");
676676
}
677+
const commandNames = new Set<string>();
677678
for (const argv of commands) {
678679
const command = argv[0];
679680
if (!command) {
680681
throw new Error(`Configured audio command not found on the node: ${command || "<empty>"}`);
681682
}
683+
commandNames.add(command);
684+
}
685+
for (const command of commandNames) {
682686
if (options.sharePrerequisiteDeadline && Date.now() >= deadline) {
683687
throw new Error(`${options.meetingLabel} audio prerequisite check timed out on the node.`);
684688
}

0 commit comments

Comments
 (0)