Skip to content

fix(test): add TestMain to isolate cmd/opencodereview from the real home - #1707

Open
JasonBuildAI wants to merge 1 commit into
alibaba:mainfrom
JasonBuildAI:fix/test-home-isolation-windows-jx9
Open

JasonBuildAI wants to merge 1 commit into
alibaba:mainfrom
JasonBuildAI:fix/test-home-isolation-windows-jx9

Conversation

@JasonBuildAI

@JasonBuildAI JasonBuildAI commented Oct 11, 2026 •

Copy link
Copy Markdown

Description

Running the cmd/opencodereview test binary on Windows no longer writes review session files into the developer's real ~/.opencodereview/sessions/. A package-level TestMain redirects HOME and USERPROFILE to a temporary directory for every test in the package.

Value: anyone running go test ./cmd/opencodereview/ (or make test) on Windows keeps their real session history, and the ocr viewer session list, free of test-generated entries.

os.UserHomeDir() resolves USERPROFILE on Windows, not HOME, so the 13 t.Setenv("HOME", t.TempDir()) call sites in this package never redirected the home there. Follow-up to #1416, which added this guard to internal/session, internal/agent, internal/llmloop and internal/scan: cmd/opencodereview was the remaining package without it.

Fixes #1706

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

How Has This Been Tested?

Windows 11 (NT 10.0.26200.0), Go 1.26.9 windows/amd64, at commit 357c3f0. Method: snapshot the file list under %USERPROFILE%\.opencodereview, run the command, compare.

  1. Unmodified main, targeted run:
    go test -count=1 -run 'TestRunSessionCompare|TestSessionCompareCompletesBothPositionals|TestScanBudgetJSON|TestValidateResumeIdentity' ./cmd/opencodereview/
    -> 23 files added under %USERPROFILE%\.opencodereview\sessions\, e.g.
    \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

  2. With this change:

    • go test -count=1 ./cmd/opencodereview/ -> ok github.com/alibaba/open-code-review/cmd/opencodereview 145.738s, 0 files added, 0 removed
    • make test (full suite, -race) -> exit 0, all 24 packages ok, 0 files added, 0 removed
    • make check -> exit 0; make build -> exit 0
    • %USERPROFILE%\.opencodereview\config.json unchanged: sha256 156BEFAFC67A6C486910E9D6D42D72EEB4DF705B2A71CE2481B3675A3E7F5C0C before and after
  • make test passes locally
  • Manual testing (describe below)

Checklist

  • My code follows the project's coding style (go fmt, go vet) - make check passed
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works - not applicable: this PR is test-infrastructure; the before/after snapshots above are the proof
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

AI/LLM disclosure: investigated and drafted with the OpenAI Codex desktop agent (Codex CLI 0.162.0-alpha.17.2, GPT-5-class model), used at my request under constraints I set. I reproduced the leak, ran every command quoted above, and reviewed the full diff and this description before requesting review.

Related Issues

Fixes #1706

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review skipped: no items were selected.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmd/opencodereview tests write session files into the real ~/.opencodereview on Windows

1 participant