Skip to content

fix(env): detect Git Bash login shell profile on Windows - #684

Open
akshar27 wants to merge 1 commit into
Tencent:mainfrom
akshar27:fix/windows-shell-profile-detection
Open

akshar27 wants to merge 1 commit into
Tencent:mainfrom
akshar27:fix/windows-shell-profile-detection

Conversation

@akshar27

Copy link
Copy Markdown

Summary

detectShellProfile() always fell back to .bashrc on Windows, since SHELL (a POSIX convention) is never set there. But Git Bash's default launch is a login shell, which reads .bash_profile / .bash_login / .profile — never .bashrc. The injected env block gets written, the file looks correct, and the variables are never loaded. Scoped to win32 only; the existing macOS/Linux behavior is untouched.

Type of Change

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

Test Plan

  • npx tsc --noEmit passes
  • npx vitest run passes — 264 files, 3622 tests, including 7 new cases for this change
  • Added/updated tests for the change

Real, end-to-end verification (not only unit tests), per the repo's testing rule:

I don't have a Windows machine, so I couldn't run the literal Git Bash repro from the issue. Instead I did the next most honest thing: npx tsc compiled the real source to plain JS (not the tsup CLI bundle, which has no importable exports), then ran a standalone Node script against that actual compiled artifact — real module resolution, real fs.existsSync calls, real EnvHandler class, with process.platform and a real temp $HOME swapped in (not mocked at the vitest level):

=== Reproducing the exact reported bug (#682) ===
PASS  Windows, no existing dotfiles → creates .bash_profile (matches nvm-windows/Git-Bash convention)
PASS  Windows, only .bashrc exists → does NOT return .bashrc (the reported bug)
PASS  Windows, .bash_profile exists → uses it

=== Confirming zero regression on the existing (non-Windows) path ===
PASS  macOS/Linux, SHELL unset → unchanged, still .bashrc
PASS  zsh path is untouched by this change

ALL CHECKS PASSED

.bash_login and .profile fallback (the two other cases) are covered by the added Vitest cases, which also use real fs/temp-dir operations, not mocks of the function under test.

Related Issues

Fixes #682

Notes for Reviewers

SHELL is a POSIX convention Windows never sets, so detectShellProfile()
always fell back to .bashrc there. Git Bash's default launch is a login
shell, which reads .bash_profile / .bash_login / .profile — never
.bashrc — so the injected env block was written to a file the shell
never sources.

Scoped to win32 only: prefer whichever of the three login-profile files
already exists (bash's own lookup order), falling back to creating
.bash_profile — the convention most Windows dev tooling (nvm-windows,
etc.) already targets. Non-Windows bash is unaffected and still
correctly gets .bashrc.

Filed separately at @jeff-r2026's request in Tencent#661.

Note: src/uninstall.ts has an identical, unfixed copy of this same
detectShellProfile() logic. Left out of this PR since Tencent#682 scoped the
fix to env.ts specifically, but flagging it — a Windows uninstall would
still look in .bashrc to remove the block this now writes elsewhere.
@jeff-r2026 jeff-r2026 self-assigned this Sep 20, 2026
@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Keep uninstall aligned with the new profile selectionsrc/resources/env.ts:358. Installation now writes to .bash_profile, .bash_login, or .profile on Windows, while src/uninstall.ts still checks only .bashrc. Consequently, teamai uninstall silently leaves the managed env block active. Update both paths or share the detection helper.
  • [P1 blocking] Provide the required real-CLI E2E record — PR description, Test Plan. The standalone script imports a TypeScript-compiled module; it does not run the built teamai CLI. The trusted rules require npm run build followed by real-CLI end-to-end verification, so the current description lacks the mandatory E2E record.
  • [P2 non-blocking] Restore stubbed environment variablessrc/__tests__/env-handler.test.ts:240. vi.restoreAllMocks() does not undo vi.stubEnv(), leaving SHELL='' for subsequent tests. Add vi.unstubAllEnvs() to avoid order-dependent test pollution.

@jeff-r2026

Copy link
Copy Markdown
Collaborator

Please resolve the conflicts

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.

detectShellProfile() falls back to ~/.bashrc on Windows, where the login shell never reads it

2 participants