MCPcopy
hub / github.com/tobi/qmd / runQmd

Function runQmd

test/cli.test.ts:43–84  ·  view source on GitHub ↗
(
  args: string[],
  options: { cwd?: string; env?: Record<string, string>; dbPath?: string; configDir?: string } = {}
)

Source from the content-addressed store, hash-verified

41
42// Helper to run qmd command with test database
43async function runQmd(
44 args: string[],
45 options: { cwd?: string; env?: Record<string, string>; dbPath?: string; configDir?: string } = {}
46): Promise<{ stdout: string; stderr: string; exitCode: number }> {
47 const workingDir = options.cwd || fixturesDir;
48 const dbPath = options.dbPath || testDbPath;
49 const configDir = options.configDir || testConfigDir;
50 const runner = qmdRunnerArgs(args);
51 const proc = spawn(runner.command, runner.args, {
52 cwd: workingDir,
53 env: {
54 ...process.env,
55 INDEX_PATH: dbPath,
56 QMD_CONFIG_DIR: configDir, // Use test config directory
57 PWD: workingDir, // Must explicitly set PWD since getPwd() checks this
58 QMD_DOCTOR_DEVICE_PROBE: "0", // Keep integration tests deterministic on CI hosts without usable GPU backends.
59 ...options.env,
60 },
61 stdio: ["ignore", "pipe", "pipe"],
62 });
63
64 const stdoutPromise = new Promise<string>((resolve, reject) => {
65 let data = "";
66 proc.stdout?.on("data", (chunk: Buffer) => { data += chunk.toString(); });
67 proc.once("error", reject);
68 proc.stdout?.once("end", () => resolve(data));
69 });
70 const stderrPromise = new Promise<string>((resolve, reject) => {
71 let data = "";
72 proc.stderr?.on("data", (chunk: Buffer) => { data += chunk.toString(); });
73 proc.once("error", reject);
74 proc.stderr?.once("end", () => resolve(data));
75 });
76 const exitCode = await new Promise<number>((resolve, reject) => {
77 proc.once("error", reject);
78 proc.on("close", (code) => resolve(code ?? 1));
79 });
80 const stdout = await stdoutPromise;
81 const stderr = await stderrPromise;
82
83 return { stdout, stderr, exitCode };
84}
85
86// Get a fresh database path for isolated tests
87function getFreshDbPath(): string {

Callers 2

cli.test.tsFile · 0.85
runDaemonQmdFunction · 0.85

Calls 2

qmdRunnerArgsFunction · 0.85
resolveFunction · 0.85

Tested by

no test coverage detected