20 lines · 1.6 KB · TypeScriptRaw
import { execFileSync, spawnSync } from "node:child_process";import { existsSync } from "node:fs";import { join } from "node:path";import { expect, it } from "vitest";import { fixtureEnvironment, isolateScriptFixtures } from "./helpers/fixture-sandbox";isolateScriptFixtures();// RULE: Maintenance-script fixtures inherit neither the real home/cache nor a Git environment pointing at the primary checkout.it("contains child processes in a disposable home, cache and non-repository cwd", () => { expect(process.env.HOME).toBe(join(process.cwd(), "home")); expect(process.env.COTTON_CACHE_ROOT).toBe(join(process.env.HOME!, ".cache/cottondb")); expect(existsSync(process.env.HOME!)).toBe(true); expect(spawnSync("git", ["rev-parse", "--show-toplevel"], {encoding:"utf8"}).status).not.toBe(0); const child=JSON.parse(execFileSync(process.execPath,["-e",'console.log(JSON.stringify({home:process.env.HOME,cache:process.env.COTTON_CACHE_ROOT,cwd:process.cwd()}))'],{encoding:"utf8"})); expect(child).toEqual({home:process.env.HOME,cache:process.env.COTTON_CACHE_ROOT,cwd:process.cwd()}); const env=fixtureEnvironment("/synthetic", {HOME:"/real", COTTON_CACHE_ROOT:"/real/cache", GIT_DIR:"/primary/.git", GIT_WORK_TREE:"/primary", COTTON_CARGO_TARGET_ROOT:"/real/targets", CARGO_TARGET_DIR:"/real/target"}); expect(env).toMatchObject({HOME:"/synthetic/home", COTTON_CACHE_ROOT:"/synthetic/home/.cache/cottondb", GIT_CONFIG_GLOBAL:"/dev/null"}); for (const key of ["GIT_DIR","GIT_WORK_TREE","COTTON_CARGO_TARGET_ROOT","CARGO_TARGET_DIR"]) expect(env[key]).toBeUndefined();});