Skip to content

Commit 0861f74

Browse files
Array Fleetcursoragent
andcommitted
test(cli): harden smoke harness against parallel dist rebuilds
Ensure dist/cli.js exists before each smoke invocation so parallel vitest files (e.g. cli.test.ts beforeAll build) cannot delete the binary mid-suite and cause flaky MODULE_NOT_FOUND failures. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 18bd645 commit 0861f74

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

test/cli-smoke.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
import { describe, it, expect, beforeAll, afterAll } from "vitest";
22
import { execSync, spawnSync } from "node:child_process";
3-
import { cpSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
3+
import { cpSync, existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
44
import { join, dirname } from "node:path";
55
import { tmpdir } from "node:os";
66
import { fileURLToPath } from "node:url";
77

88
const here = dirname(fileURLToPath(import.meta.url));
9-
const CLI = join(here, "..", "dist", "cli.js");
9+
const repoRoot = join(here, "..");
10+
const CLI = join(repoRoot, "dist", "cli.js");
1011
const FIXTURE_SRC = join(here, "fixtures", "smoke-project");
1112
const pkg = JSON.parse(
1213
readFileSync(join(here, "..", "package.json"), "utf8"),
1314
) as { version: string };
1415

1516
let projectRoot: string | undefined;
1617

18+
function ensureCliBuilt(): void {
19+
if (!existsSync(CLI)) {
20+
execSync("npm run build", { cwd: repoRoot, stdio: "pipe" });
21+
}
22+
}
23+
1724
function runMex(args: string[]): {
1825
status: number | null;
1926
stdout: string;
2027
stderr: string;
2128
output: string;
2229
} {
30+
ensureCliBuilt();
2331
const result = spawnSync(process.execPath, [CLI, ...args], {
2432
cwd: projectRoot,
2533
encoding: "utf8",
@@ -40,6 +48,7 @@ function expectSuccess(result: ReturnType<typeof runMex>): void {
4048
}
4149

4250
beforeAll(() => {
51+
execSync("npm run build", { cwd: repoRoot, stdio: "pipe" });
4352
projectRoot = mkdtempSync(join(tmpdir(), "mex-smoke-"));
4453
cpSync(FIXTURE_SRC, projectRoot, { recursive: true });
4554
execSync("git init -q", { cwd: projectRoot });

0 commit comments

Comments
 (0)