mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-03 04:46:07 +00:00
os.homedir() reads USERPROFILE on Windows and never HOME, so the isolation setup and every test that moved home were still resolving the developer's real home directory. Fixtures came back empty, real sessions leaked into counts, and the code under test wrote plans, receipts and a sync ledger into the real ~/.config/codeburn during a run. USERPROFILE now joins the redirected variables and a shared setHome() helper moves HOME and USERPROFILE together; every spawn env carries both. The remaining Windows-only failures were POSIX-shaped fixtures: chmod tricks that only toggle a read-only attribute on NTFS, pid 1 as an always-alive lock holder, splitting paths on '/', bare tar, mode-bit expectations, and per-file timeouts too short for the cost of a tsx spawn. Each gets a platform-aware equivalent so nothing is skipped on Windows and the POSIX branches stay byte-for-byte what they were. Full run on Windows: 267 files passed, 2 skipped, 3592 tests passed.
14 lines
633 B
TypeScript
14 lines
633 B
TypeScript
/**
|
|
* Points the home directory at `dir` for the code under test, or clears it.
|
|
*
|
|
* `os.homedir()` reads HOME on POSIX and USERPROFILE on Windows, never the other, so a
|
|
* test that sets only HOME still resolves the real home on Windows: fixtures come back
|
|
* empty and, worse, the code under test writes into the developer's real
|
|
* `~/.config/codeburn`. Every test that moves home goes through here so both move together.
|
|
*/
|
|
export function setHome(dir: string | undefined): void {
|
|
for (const key of ['HOME', 'USERPROFILE'] as const) {
|
|
if (dir === undefined) delete process.env[key]
|
|
else process.env[key] = dir
|
|
}
|
|
}
|