Skip to content

test(completion): isolate ZshInstaller tests from a real Oh My Zsh install#1400

Open
clay-good wants to merge 2 commits into
mainfrom
fix/zsh-installer-test-isolation
Open

test(completion): isolate ZshInstaller tests from a real Oh My Zsh install#1400
clay-good wants to merge 2 commits into
mainfrom
fix/zsh-installer-test-isolation

Conversation

@clay-good

@clay-good clay-good commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1321.

Status: LGTM — test-only change, no runtime code touched, full suite green.

What was wrong: test/core/completions/installers/zsh-installer.test.ts failed 17 of 50 tests on any machine with a real Oh My Zsh install. The tests inject an isolated temp home directory, but isOhMyZshInstalled() checks process.env.ZSH before falling back to that directory (zsh-installer.ts:31-46). Oh My Zsh exports $ZSH, the test runner inherits it, and every standard-Zsh test silently ran down the Oh My Zsh code path. CI containers don't have Oh My Zsh, so CI stayed green while local contributors saw a permanently red suite that could mask real regressions in this file.

How it was fixed:

  • Clear $ZSH in beforeEach and restore it in afterEach — the same save/clear/restore idiom this file already uses for OPENSPEC_NO_AUTO_CONFIG and shell-detection.test.ts uses for SHELL/COMSPEC.
  • Add one explicit test that sets $ZSH and asserts detection succeeds with no .oh-my-zsh directory present. Clearing the variable would otherwise leave that source branch with no coverage anywhere (before this PR it was only ever exercised accidentally, on the machines where the suite failed).

21 lines total, all inside the test file.

Replication / proof: On macOS with Oh My Zsh ($ZSH set):

# before (main)
npx vitest run test/core/completions/installers/zsh-installer.test.ts
#  Tests  17 failed | 33 passed (50)

# after (this branch)
npx vitest run test/core/completions/installers/zsh-installer.test.ts
#  Tests  51 passed (51)

npx vitest run
#  Test Files  105 passed (105)
#       Tests  2045 passed (2045)

Notes: The fix approach was proposed by @stanleykao72 in #1321 (credited as co-author). No behavior change for users; nothing in src/ or the published package is touched.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Improved Zsh installer test isolation by saving the prior ZSH environment value, clearing it for each test, and restoring (or removing) it afterward.
    • Added coverage to confirm isOhMyZshInstalled() returns true when the ZSH environment variable is set, independent of an .oh-my-zsh directory.

…stall

process.env.ZSH (exported by Oh My Zsh) short-circuits
isOhMyZshInstalled() before the fallback check against the injected
test home directory, so 17 of the 50 tests failed on any machine with
Oh My Zsh installed. Clear $ZSH in beforeEach and restore it in
afterEach, matching the save/restore idiom already used for
OPENSPEC_NO_AUTO_CONFIG in this file and for SHELL/COMSPEC in
shell-detection.test.ts.

Fixes #1321

Co-Authored-By: Stanley Kao <stanleykao72@gmail.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@clay-good
clay-good requested a review from TabishB as a code owner July 20, 2026 21:13
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Zsh installer tests now clear and restore process.env.ZSH around each test and verify that Oh My Zsh detection succeeds when the environment variable is set.

Changes

Zsh installer test isolation

Layer / File(s) Summary
Environment isolation and detection coverage
test/core/completions/installers/zsh-installer.test.ts
Test setup saves and clears process.env.ZSH, restores or removes it after each test, and verifies environment-based Oh My Zsh detection.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Possibly related PRs

Suggested reviewers: tabishb

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR matches #1321 by isolating the test suite from host Zsh state and adding coverage for $ZSH-based detection.
Out of Scope Changes check ✅ Passed The changes are scoped to the test file and do not introduce runtime or published-package behavior changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the test-only fix to isolate ZshInstaller tests from host Oh My Zsh installs.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/zsh-installer-test-isolation

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.

Clearing $ZSH in setup left isOhMyZshInstalled()'s env-var branch with
no coverage anywhere (before, it was only exercised accidentally on
machines with Oh My Zsh). Assert detection succeeds from $ZSH alone,
with no .oh-my-zsh directory present.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@alfred-openspec alfred-openspec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the host-environment failure: the base has 17 of 50 focused tests fail with ZSH set, while this exact head passes all 51 and restores the original environment after each test. Clean test-only fix.

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.

ZshInstaller tests fail on machines with a real Oh My Zsh install (17/50 failures)

2 participants