MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / startArgentToolServer

Function startArgentToolServer

scripts/bench/agent-control-benchmark.mjs:934–991  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

932}
933
934async function startArgentToolServer() {
935 const port = await freePort();
936 const packageRoot = globalPackageRoot("@swmansion/argent");
937 const serverPath = path.join(packageRoot, "dist", "tool-server.cjs");
938 const serverDir = path.join(packageRoot, "bin");
939 const devtoolsDir = path.join(packageRoot, "dylibs");
940 const env = {
941 ...process.env,
942 PORT: String(port),
943 ARGENT_TOOLS_URL: `http://127.0.0.1:${port}`,
944 ARGENT_SIMULATOR_SERVER_DIR: serverDir,
945 ARGENT_NATIVE_DEVTOOLS_DIR: devtoolsDir,
946 };
947 const started = performance.now();
948 const child = spawn("node", [serverPath, "start"], {
949 cwd: repoRoot,
950 env,
951 stdio: ["ignore", "pipe", "pipe"],
952 });
953 let output = "";
954 child.stdout.on("data", (chunk) => {
955 output += chunk.toString();
956 });
957 child.stderr.on("data", (chunk) => {
958 output += chunk.toString();
959 });
960
961 const ready = await waitUntil(async () => {
962 const response = run("argent", ["tools", "--json"], {
963 env: { ARGENT_TOOLS_URL: env.ARGENT_TOOLS_URL },
964 timeoutMs: 3000,
965 allowFailure: true,
966 });
967 return response.status === 0;
968 }, 15000);
969
970 const result = {
971 ok: ready,
972 status: ready ? 0 : 1,
973 stdout: output,
974 stderr: ready ? "" : output || "Argent tool-server did not become ready.",
975 durationMs: performance.now() - started,
976 };
977
978 return {
979 env: { ARGENT_TOOLS_URL: env.ARGENT_TOOLS_URL },
980 result,
981 stop: async () => {
982 if (!child.killed) {
983 child.kill("SIGTERM");
984 await sleep(500);
985 if (!child.killed) {
986 child.kill("SIGKILL");
987 }
988 }
989 },
990 };
991}

Callers 1

benchmarkArgentFunction · 0.85

Calls 6

globalPackageRootFunction · 0.85
waitUntilFunction · 0.85
toStringMethod · 0.80
freePortFunction · 0.70
runFunction · 0.70
sleepFunction · 0.70

Tested by

no test coverage detected