MCPcopy Index your code
hub / github.com/NativeScript/SimDeck / startIsolatedService

Function startIsolatedService

packages/simdeck-test/src/index.ts:716–771  ·  view source on GitHub ↗
(
  cliPath: string,
  options: SimDeckLaunchOptions,
)

Source from the content-addressed store, hash-verified

714}
715
716async 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
773function removeIsolatedRoot(projectRoot: string): void {

Callers 1

connectFunction · 0.85

Calls 5

freePortPairFunction · 0.85
captureChildOutputFunction · 0.85
removeIsolatedRootFunction · 0.85
toStringMethod · 0.80
waitForHealthFunction · 0.70

Tested by

no test coverage detected