|
1 | | -import { existsSync, realpathSync, rmSync } from "node:fs"; |
| 1 | +import { spawnSync } from "node:child_process"; |
| 2 | +import { existsSync, mkdtempSync, readdirSync, realpathSync, rmSync } from "node:fs"; |
2 | 3 | import { homedir, tmpdir, userInfo } from "node:os"; |
3 | | -import { join, sep } from "node:path"; |
| 4 | +import { join, resolve, sep } from "node:path"; |
| 5 | +import { fileURLToPath } from "node:url"; |
4 | 6 | import { afterEach, describe, expect, it, vi } from "vitest"; |
5 | 7 | import { fetchRegistryManifest } from "./registry/remote.js"; |
6 | 8 |
|
@@ -38,4 +40,24 @@ describe("the CLI test run", () => { |
38 | 40 | expect(existsSync(cacheFile(homedir()))).toBe(true); |
39 | 41 | expect(leaked).toBe(false); |
40 | 42 | }); |
| 43 | + |
| 44 | + // A cold cache write from each spawned CLI held Windows runs past the spawn timeout (scripts/test-home.mjs). |
| 45 | + it("spawns CLIs that write no transpiler cache into their home", () => { |
| 46 | + const home = mkdtempSync(join(tmpdir(), "hf-transpiler-cache-")); |
| 47 | + try { |
| 48 | + const cli = resolve(fileURLToPath(import.meta.url), "..", "cli.ts"); |
| 49 | + const res = spawnSync("bun", ["run", cli, "--version"], { |
| 50 | + encoding: "utf8", |
| 51 | + timeout: 30_000, |
| 52 | + env: { ...process.env, HOME: home, USERPROFILE: home }, |
| 53 | + }); |
| 54 | + expect(res.status, res.stderr).toBe(0); |
| 55 | + const cached = (readdirSync(home, { recursive: true }) as string[]).filter((path) => |
| 56 | + path.split(/[\\/]/).includes("@t@"), |
| 57 | + ); |
| 58 | + expect(cached).toEqual([]); |
| 59 | + } finally { |
| 60 | + rmSync(home, { recursive: true, force: true }); |
| 61 | + } |
| 62 | + }); |
41 | 63 | }); |
0 commit comments