MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / runOneClient

Function runOneClient

e2e/local/cli-mcp-daemon-attach-stress.test.ts:142–187  ·  view source on GitHub ↗
(
  id: number,
  dataDir: string,
  callCount: number,
)

Source from the content-addressed store, hash-verified

140 * always close. Never throws — failures are captured in the report so the
141 * scenario can assert across the whole fleet. */
142const runOneClient = async (
143 id: number,
144 dataDir: string,
145 callCount: number,
146): Promise<ClientReport> => {
147 const transport = new StdioClientTransport({
148 command: "bun",
149 args: ["run", "dev:cli", "mcp", "--scope", testScope],
150 cwd: repoRoot,
151 env: { ...process.env, EXECUTOR_DATA_DIR: dataDir },
152 stderr: "pipe",
153 });
154 const client = new Client({ name: `stress-client-${id}`, version: "1.0.0" });
155 const results: string[] = [];
156 let errBuf = "";
157 transport.stderr?.on("data", (d: Buffer) => {
158 errBuf += d.toString();
159 });
160 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: capture per-client failure for fleet-wide assertions
161 try {
162 await client.connect(transport);
163 const { tools } = await client.listTools();
164 for (let i = 0; i < callCount; i++) {
165 // A value unique to (client, call) so a misrouted reply is detectable.
166 const expr = `return ${id} * 1000 + ${i}`;
167 const r = await client.callTool({ name: "execute", arguments: { code: expr } });
168 const text = (r.content as Array<{ type: string; text: string }>)[0]?.text ?? "";
169 results.push(text);
170 }
171 return { id, ok: true, tools: tools.length, results };
172 } catch (error) {
173 return {
174 id,
175 ok: false,
176 tools: 0,
177 results,
178 error:
179 (error instanceof Error ? error.message : String(error)) +
180 (errBuf
181 ? `\n stderr: ${errBuf.trim().split("\n").slice(-6).join("\n ")}`
182 : ""),
183 };
184 } finally {
185 await transport.close().catch(() => undefined);
186 }
187};
188
189const withTempData = Effect.acquireRelease(
190 Effect.sync(() => {

Calls 4

toStringMethod · 0.80
pushMethod · 0.80
connectMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected