Skip to content

test(cmd): tests leave index dirs in the real ~/.local/share/lumen - #197

Open
escooterclinic wants to merge 1 commit into
ory:mainfrom
escooterclinic:test/cmd-isolate-data-dir
Open

escooterclinic wants to merge 1 commit into
ory:mainfrom
escooterclinic:test/cmd-isolate-data-dir

Conversation

@escooterclinic

@escooterclinic escooterclinic commented Oct 24, 2026 •

Copy link
Copy Markdown

Running go test ./cmd/ on main leaves index directories in the real ~/.local/share/lumen. On a machine that also runs Lumen for real, they show up as stale indexes until lumen clean removes them. I mentioned the HOME sensitivity of the cmd tests in #195. This is the fix. Tested on main at f60f9ec, macOS.

Two tests build an index without setting XDG_DATA_HOME: TestIndexerCache_ConcurrentReads (a 4-dim index for /nonexistent/path/for/race/test) and TestSetupIndexer_DBPathVsDirectory (a 768-dim one). Pointing HOME and XDG_DATA_HOME at an empty dir and running the package on main gives two directories under lumen/. With this change it gives none.

Rather than patch those two tests, TestMain now runs the whole package with HOME, XDG_DATA_HOME and XDG_CONFIG_HOME in a temp dir, so the next test that forgets can't leak either. That also stops a developer's own Lumen config and index from leaking into the tests. TestSuiteDataDirIsIsolated checks that config.XDGDataDir() resolves under that temp dir, and it fails if the redirect is removed. Tests that set their own env with t.Setenv are unaffected, and go test ./cmd/ is green.

The patch and the test were written with a coding agent.

Summary by CodeRabbit

  • Tests
    • Improved test isolation by running the test suite with temporary home and configuration directories. This helps prevent test runs from affecting local user data and reduces interference between tests.
    • Added a check to verify that test data is stored within the isolated test environment.

Two cmd tests build an index without setting XDG_DATA_HOME, so every
go test ./cmd/ leaves index directories in the developer's real
~/.local/share/lumen. TestMain now points HOME, XDG_DATA_HOME and
XDG_CONFIG_HOME at a temp dir for the whole package, and
TestSuiteDataDirIsIsolated fails if that redirect is removed.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e98999ab-eaa9-4ac4-90e5-8340cb5d5239
Commits

Reviewing files that changed from the base of the PR and between f60f9ec and addb62d.

Files selected for processing: 1
  • cmd/hook_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Walkthrough

The test entry point now runs the suite with temporary HOME, XDG_DATA_HOME, and XDG_CONFIG_HOME values. A new test checks that config.XDGDataDir() is under the temporary suite home.

Changes: Test environment isolation

Layer / File(s) Summary
Run tests with an isolated home
cmd/hook_test.go
TestMain runs the suite through runIsolated, while retaining its early exit for subprocesses invoked with the index argument. runIsolated sets temporary home and XDG paths, then removes the temporary directory. TestSuiteDataDirIsIsolated checks that the data directory is under the suite home.

Priority: Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Suggested reviewers: aeneasr

Merge Risk: Minimal · up to addb6

The cmd tests resolve index paths under the temporary data directory. No merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the cmd test change and the data-directory isolation problem addressed by the pull request.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CLAassistant

CLAassistant commented Oct 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

2 participants