(
args: string[],
options: { cwd?: string; env?: Record<string, string>; dbPath?: string; configDir?: string } = {}
)
| 41 | |
| 42 | // Helper to run qmd command with test database |
| 43 | async 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 |
| 87 | function getFreshDbPath(): string { |
no test coverage detected