( cliPath: string, options: SimDeckLaunchOptions, )
| 714 | } |
| 715 | |
| 716 | async function startIsolatedService( |
| 717 | cliPath: string, |
| 718 | options: SimDeckLaunchOptions, |
| 719 | ): Promise<ServiceConnection> { |
| 720 | const port = options.port ?? (await freePortPair()); |
| 721 | const projectRoot = fs.mkdtempSync( |
| 722 | path.join(os.tmpdir(), "simdeck-test-project-"), |
| 723 | ); |
| 724 | const metadataPath = path.join( |
| 725 | os.tmpdir(), |
| 726 | `simdeck-test-${process.pid}-${Date.now()}-${crypto.randomUUID()}.json`, |
| 727 | ); |
| 728 | const accessToken = crypto.randomBytes(32).toString("hex"); |
| 729 | const packageRoot = options.projectRoot ?? process.cwd(); |
| 730 | const child = spawn( |
| 731 | cliPath, |
| 732 | [ |
| 733 | "service", |
| 734 | "run", |
| 735 | "--metadata-path", |
| 736 | metadataPath, |
| 737 | "--port", |
| 738 | String(port), |
| 739 | "--bind", |
| 740 | "127.0.0.1", |
| 741 | "--client-root", |
| 742 | path.join(packageRoot, "packages", "client", "dist"), |
| 743 | "--access-token", |
| 744 | accessToken, |
| 745 | "--video-codec", |
| 746 | options.videoCodec ?? "software", |
| 747 | ], |
| 748 | { |
| 749 | cwd: projectRoot, |
| 750 | stdio: ["ignore", "pipe", "pipe"], |
| 751 | }, |
| 752 | ); |
| 753 | const output = captureChildOutput(child); |
| 754 | const url = `http://127.0.0.1:${port}`; |
| 755 | try { |
| 756 | await waitForHealth(url, child, output); |
| 757 | } catch (error) { |
| 758 | child.kill(); |
| 759 | removeIsolatedRoot(projectRoot); |
| 760 | throw error; |
| 761 | } |
| 762 | return { |
| 763 | ok: true, |
| 764 | projectRoot, |
| 765 | pid: child.pid ?? 0, |
| 766 | url, |
| 767 | started: true, |
| 768 | child, |
| 769 | isolatedRoot: projectRoot, |
| 770 | }; |
| 771 | } |
| 772 | |
| 773 | function removeIsolatedRoot(projectRoot: string): void { |
no test coverage detected