codeburn/tests/cli-codex-tps.test.ts
iamtoruk 62cb4f8630 test: isolate the real home on Windows and make the CLI suite pass there
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.
2026-09-02 13:43:57 -07:00

46 lines
1.7 KiB
TypeScript

import { mkdtemp, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { spawnSync } from 'node:child_process'
import { afterEach, describe, expect, it } from 'vitest'
const homes: string[] = []
afterEach(async () => {
while (homes.length) await rm(homes.pop()!, { recursive: true, force: true })
})
function runCli(args: string[], home: string) {
return spawnSync(process.execPath, ['--import', 'tsx', 'src/cli.ts', ...args], {
cwd: process.cwd(),
env: { ...process.env, HOME: home, USERPROFILE: home, CODEX_HOME: join(home, '.codex'), TZ: 'UTC' },
encoding: 'utf-8',
timeout: 30_000,
})
}
describe('codex-tps CLI validation', () => {
it('rejects sub-second watch intervals', async () => {
const home = await mkdtemp(join(tmpdir(), 'codeburn-tps-cli-'))
homes.push(home)
const result = runCli(['codex-tps', '--watch', '0.1'], home)
expect(result.status).toBe(1)
expect(result.stderr).toContain('watch must be 0 or at least 1 second')
})
it('rejects JSON watch output instead of concatenating invalid JSON documents', async () => {
const home = await mkdtemp(join(tmpdir(), 'codeburn-tps-cli-'))
homes.push(home)
const result = runCli(['codex-tps', '--json', '--watch', '1'], home)
expect(result.status).toBe(2)
expect(result.stderr).toContain('--json cannot be combined with --watch')
})
it('returns a nonzero status for a missing explicit rollout', async () => {
const home = await mkdtemp(join(tmpdir(), 'codeburn-tps-cli-'))
homes.push(home)
const result = runCli(['codex-tps', join(home, 'missing.jsonl')], home)
expect(result.status).toBe(1)
expect(result.stderr).toContain('session file not found')
})
})