From 17788f3a27aed7718c639387c7f1c44a62485f17 Mon Sep 17 00:00:00 2001 From: Carlos Santos <4a.santos@gmail.com> Date: Wed, 11 Jun 2025 10:24:43 +0200 Subject: [PATCH] backend(test): add LiveKit CLI installation check before joining fake participant --- backend/tests/helpers/request-helpers.ts | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/backend/tests/helpers/request-helpers.ts b/backend/tests/helpers/request-helpers.ts index b3c0812..8e4e5c2 100644 --- a/backend/tests/helpers/request-helpers.ts +++ b/backend/tests/helpers/request-helpers.ts @@ -374,6 +374,7 @@ export const refreshParticipantToken = async (participantOptions: any) => { * @param participantName The name for the fake participant */ export const joinFakeParticipant = async (roomId: string, participantName: string) => { + await ensureLivekitCliInstalled(); const process = spawn('lk', [ 'room', 'join', @@ -392,6 +393,54 @@ export const joinFakeParticipant = async (roomId: string, participantName: strin await sleep('1s'); }; +/** + * Verifies that the LiveKit CLI tool 'lk' is installed and accessible + * @throws Error if 'lk' command is not found + */ +const ensureLivekitCliInstalled = async (): Promise => { + return new Promise((resolve, reject) => { + const checkProcess = spawn('lk', ['--version'], { + stdio: 'pipe' + }); + + let hasResolved = false; + + const resolveOnce = (success: boolean, message?: string) => { + if (hasResolved) return; + + hasResolved = true; + + if (success) { + resolve(); + } else { + reject(new Error(message || 'LiveKit CLI check failed')); + } + }; + + checkProcess.on('error', (error) => { + if (error.message.includes('ENOENT')) { + resolveOnce(false, '❌ LiveKit CLI tool "lk" is not installed or not in PATH.'); + } else { + resolveOnce(false, `Failed to check LiveKit CLI: ${error.message}`); + } + }); + + checkProcess.on('exit', (code) => { + if (code === 0) { + resolveOnce(true); + } else { + resolveOnce(false, `LiveKit CLI exited with code ${code}`); + } + }); + + // Timeout after 5 seconds + setTimeout(() => { + checkProcess.kill(); + resolveOnce(false, 'LiveKit CLI check timed out'); + }, 5000); + }); +}; + export const disconnectFakeParticipants = async () => { fakeParticipantsProcesses.forEach((process, participantName) => { process.kill();