diff --git a/launcher/mpv.test.ts b/launcher/mpv.test.ts index a2743d5..5742343 100644 --- a/launcher/mpv.test.ts +++ b/launcher/mpv.test.ts @@ -5,7 +5,7 @@ import path from 'node:path'; import net from 'node:net'; import { EventEmitter } from 'node:events'; import type { Args } from './types'; -import { startOverlay, state, waitForUnixSocketReady } from './mpv'; +import { runAppCommandCaptureOutput, startOverlay, state, waitForUnixSocketReady } from './mpv'; import * as mpvModule from './mpv'; function createTempSocketPath(): { dir: string; socketPath: string } { @@ -19,6 +19,18 @@ test('mpv module exposes only canonical socket readiness helper', () => { assert.equal('waitForSocket' in mpvModule, false); }); +test('runAppCommandCaptureOutput captures status and stdio', () => { + const result = runAppCommandCaptureOutput(process.execPath, [ + '-e', + 'process.stdout.write("stdout-line"); process.stderr.write("stderr-line");', + ]); + + assert.equal(result.status, 0); + assert.equal(result.stdout, 'stdout-line'); + assert.equal(result.stderr, 'stderr-line'); + assert.equal(result.error, undefined); +}); + test('waitForUnixSocketReady returns false when socket never appears', async () => { const { dir, socketPath } = createTempSocketPath(); try { diff --git a/launcher/mpv.ts b/launcher/mpv.ts index 6abd753..bdcc3eb 100644 --- a/launcher/mpv.ts +++ b/launcher/mpv.ts @@ -658,6 +658,28 @@ export function runAppCommandWithInherit(appPath: string, appArgs: string[]): ne process.exit(result.status ?? 0); } +export function runAppCommandCaptureOutput( + appPath: string, + appArgs: string[], +): { + status: number; + stdout: string; + stderr: string; + error?: Error; +} { + const result = spawnSync(appPath, appArgs, { + env: buildAppEnv(), + encoding: 'utf8', + }); + + return { + status: result.status ?? 1, + stdout: result.stdout ?? '', + stderr: result.stderr ?? '', + error: result.error ?? undefined, + }; +} + export function runAppCommandWithInheritLogged( appPath: string, appArgs: string[],