cmd/opencodereview tests write session files into the real ~/.opencodereview on Windows
Bug Description
Running the cmd/opencodereview test binary on Windows writes review session JSONL files into the developer's real ~/.opencodereview/sessions/ - the same directory ocr session list and ocr viewer read. A test run therefore mixes generated session files into the local session history.
Root cause: os.UserHomeDir() resolves USERPROFILE on Windows, not HOME. Other packages are protected by a package-level TestMain that redirects both variables to a temp directory (added in #1416 for internal/session, internal/agent, internal/llmloop, internal/scan), but cmd/opencodereview never got that guard. 13 call sites in that package redirect only HOME (t.Setenv("HOME", t.TempDir())), which is a no-op on Windows - while the package's own helper setTestHome (cmd/opencodereview/delegate_exec_test.go:87) sets both variables and documents exactly this trap.
Steps To Reproduce
On Windows, at commit 357c3f0 (v1.12.13), snapshot %USERPROFILE%\.opencodereview before and after:
go test -count=1 -run 'TestRunSessionCompare|TestSessionCompareCompletesBothPositionals|TestScanBudgetJSON|TestValidateResumeIdentity' ./cmd/opencodereview/
Expected Behavior
Test data stays inside per-test temp directories; the real ~/.opencodereview is left untouched.
Actual Behavior
The command above added 23 session files under %USERPROFILE%\.opencodereview\sessions\, for example:
\sessions\D_Temp-TestRunSessionCompare_TextShowsCounts4049144688-002\153542f9-98b3-45b3-8ec2-841d065d66f1.jsonl
\sessions\D_Temp-TestScanBudgetJSONbudget_stop_sets_budget_exceeded724104049-003\40e1a7a3-1ee4-4aaf-ab8b-4d4aaa3e82ba.jsonl
\sessions\D_Temp-TestValidateResumeIdentity477448367-002\d9e46356-f5b9-422b-84eb-97b87cf3fe16.jsonl
The directory name embeds the test's temp repo path, so these entries show up alongside real sessions.
Environment
- open-code-review v1.12.13 (commit 357c3f0), built from source
- Windows 11 (NT 10.0.26200.0), Go 1.26.9 windows/amd64
- No LLM provider involved; this is a test-suite isolation bug, not a runtime bug
Additional Context
Impact: any contributor or CI job running go test ./cmd/opencodereview/ on Windows accumulates stale entries in their real ocr viewer. On Linux/macOS the same run is clean, because HOME is the variable os.UserHomeDir() reads there - which makes the leak easy to miss and Windows-only.
Related: #1409 / #1416 addressed the same class of leak for four internal/... packages; cmd/opencodereview was out of scope there and still leaks.
A PR mirroring the accepted TestMain pattern for this package will follow.
AI/LLM disclosure: I used the OpenAI Codex desktop agent (Codex CLI 0.162.0-alpha.17.2, GPT-5-class model) to investigate and draft this report. I set the task constraints myself, reproduced and verified every claim above on my own machine, and reviewed the text before posting.