import { spawnSync } from "node:child_process"; import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { expect, it } from "vitest"; import { ROOT } from "../build/build.ts"; it.each(["POSIX", "cmd"])( "passes literal %s task arguments to the version validator without shell evaluation", (shell) => { const scratch = mkdtempSync(join(tmpdir(), "pi-ext-version-task-")); const marker = join(scratch, "executed"); const packagePath = join(ROOT, "package.json"); const lockPath = join(ROOT, "package-lock.json"); const before = [ readFileSync(packagePath, "utf8"), readFileSync(lockPath, "utf8"), ]; try { const version = shell === "POSIX" ? `1.2.3$(touch ${marker})` : `1.2.3 & echo injected>"${marker}"`; const result = spawnSync("mise", ["run", "//:release-version", version], { cwd: ROOT, encoding: "utf8", }); expect(result.status).not.toBe(0); const output = `${result.stdout}\n${result.stderr}`; expect(output).toMatch(/valid semver/u); expect(output).toContain(`got ${JSON.stringify(version)}`); expect(existsSync(marker)).toBe(false); expect([ readFileSync(packagePath, "utf8"), readFileSync(lockPath, "utf8"), ]).toEqual(before); } finally { rmSync(scratch, { recursive: true, force: true }); } }, );