Skip to content

Conversation

@g1331
Copy link
Contributor

@g1331 g1331 commented Jan 17, 2026

Base Branch

  • This PR targets the develop branch (required for all feature/fix PRs)
  • This PR targets main (hotfix only - maintainers)

Description

What happened?

When using the Insights feature on Windows, users encounter a fatal error:

Claude Code on Windows requires git-bash
ProcessError: Command failed with exit code 1

The Insights chat becomes completely unusable, displaying the error message instead of responding to user queries.

Why did this happen?

The Claude Code CLI on Windows requires git-bash (bash.exe) to execute shell commands. This is communicated via the CLAUDE_CODE_GIT_BASH_PATH environment variable.

The root cause is an inconsistency between two code paths:

Component Location Git Bash Detection
AgentProcess agent-process.ts ✅ Has detection logic
InsightsConfig insights/config.ts Missing detection

When the Electron app spawns a Python subprocess for Insights, it uses InsightsConfig.getProcessEnv() to build the environment variables. This method was missing the CLAUDE_CODE_GIT_BASH_PATH detection that AgentProcess.setupProcessEnvironment() already had.

As a result, when the Python backend invokes Claude Code CLI, the CLI cannot find git-bash and fails with the error shown above.

How did we fix it?

  1. Extract shared utility function (DRY principle)

    • Moved deriveGitBashPath() from agent-process.ts to env-utils.ts
    • This function derives the bash.exe path from a given git.exe path
    • Handles various Git for Windows installation structures:
      • Git/cmd/git.exeGit/bin/bash.exe
      • Git/bin/git.exeGit/bin/bash.exe
      • Git/mingw64/bin/git.exeGit/bin/bash.exe
      • Git/mingw32/bin/git.exeGit/bin/bash.exe
  2. Add Git Bash detection to InsightsConfig

    • Added the same detection logic to InsightsConfig.getProcessEnv()
    • Now sets CLAUDE_CODE_GIT_BASH_PATH environment variable when Git is found
  3. Add comprehensive unit tests

    • 10 new test cases covering all Git installation path variants
    • Tests for non-Windows platforms (should return null)
    • Tests for paths with spaces
    • Tests for fallback path logic
  4. Clean up stale mocks

    • Removed incorrect deriveGitBashPath mock from cli-tool-manager in test files
    • Added correct mock location in env-utils mock

Related Issue

Related to upstream issue: anthropics/claude-code#11496

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 📚 Documentation
  • ♻️ Refactor
  • 🧪 Test

Area

  • Frontend
  • Backend
  • Fullstack

Commit Message Format

fix(insights): add Git Bash path detection for Windows

Checklist

  • I've synced with develop branch
  • I've tested my changes locally
  • I've followed the code principles (SOLID, DRY, KISS)
  • My PR is small and focused (< 400 lines ideally)

Platform Testing Checklist

CRITICAL: This project supports Windows, macOS, and Linux. Platform-specific bugs are a common source of breakage.

  • Windows tested (tested locally, fix verified working)
  • macOS tested (CI will verify)
  • Linux tested (CI will verify)
  • Used centralized platform/ module instead of direct process.platform checks
  • No hardcoded paths (used dynamic Git path detection)

If you only have access to one OS: CI now tests on all platforms. Ensure all checks pass before submitting.

CI/Testing Requirements

  • All CI checks pass on all platforms (Windows, macOS, Linux)
  • All existing tests pass (1771 passed locally)
  • New features include test coverage
  • Bug fixes include regression tests

Screenshots

Before After
Error: Claude Code on Windows requires git-bash Insights working correctly after fix

Feature Toggle

  • N/A - Feature is complete and ready for all users

Breaking Changes

Breaking: No

Files Changed

File Change
env-utils.ts Added shared deriveGitBashPath() function
agent-process.ts Removed duplicate function, now imports from env-utils.ts
insights/config.ts Added Git Bash detection in getProcessEnv()
env-utils.test.ts Added 10 unit tests for deriveGitBashPath()
agent-process.test.ts Fixed mock location
ipc-handlers.test.ts Removed stale mock

Summary by CodeRabbit

  • New Features

    • Detects Git Bash on Windows and injects its path into the process environment to improve CLI behavior.
  • Integration

    • Environment assembly now includes discovered Git Bash info via a dependency-injectable helper for more consistent Windows runtime setups.
  • Tests

    • Expanded tests to cover Windows and non-Windows scenarios, multiple Git Bash layouts, path quoting, and environment precedence.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds Windows Git Bash discovery and environment injection via new exported functions deriveGitBashPath and getGitBashEnv in env-utils.ts; consumers (agent, insights) call getGitBashEnv; tests and mocks updated to support platform-aware behavior and pre-import fs/platform stubbing.

Changes

Cohort / File(s) Change Summary
Env utilities & tests
apps/frontend/src/main/env-utils.ts, apps/frontend/src/main/__tests__/env-utils.test.ts
Add `deriveGitBashPath(gitExePath): string
Agent & insights consumers
apps/frontend/src/main/agent/agent-process.ts, apps/frontend/src/main/insights/config.ts
Replace in-file Git Bash detection with DI getGitBashEnv() and merge returned env (e.g., CLAUDE_CODE_GIT_BASH_PATH) into spawned process environments.
Test mocks / tests updated
apps/frontend/src/main/agent/agent-process.test.ts, apps/frontend/src/main/__tests__/ipc-handlers.test.ts
Move deriveGitBashPath mock into env-utils mock, add getGitBashEnv mock (returns {}), and remove deriveGitBashPath from cli-tool-manager mocks; adjust tests for platform-aware behavior.

Sequence Diagram(s)

sequenceDiagram
    participant Agent as AgentProcess
    participant EnvUtils as env-utils
    participant ToolMgr as cli-tool-manager
    participant FS as Filesystem

    Agent->>EnvUtils: getGitBashEnv(toolInfoFn?)
    EnvUtils->>ToolMgr: request git tool info (lazy)
    ToolMgr-->>EnvUtils: { found, path, source }
    alt Windows & git found
        EnvUtils->>FS: fs.existsSync(candidate bash paths)
        FS-->>EnvUtils: exists / not exists
        EnvUtils-->>Agent: { CLAUDE_CODE_GIT_BASH_PATH: "C:\\...\\bash.exe" }
    else non-Windows or not found
        EnvUtils-->>Agent: {}
    end
    Agent->>Agent: merge env and spawn child process with final env
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

bug, area/frontend, os/windows, size/M, priority/medium

Suggested reviewers

  • AndyMik90
  • AlexMadera

Poem

🐰 I hopped through PATHs and peeked in bins,

I sniffed for bash where git begins,
I found a shell and tucked it neat,
Pushed it into envs for processes to meet,
A rabbit’s work—small, tidy, sweet. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely describes the main change: adding Git Bash path detection for Windows in the insights feature to fix a Windows-only failure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @g1331, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug affecting the Insights feature on Windows, where the application failed to correctly identify and utilize the Git Bash executable. The core of the fix involves centralizing the Git Bash path detection logic into a shared utility function and ensuring that the Insights configuration properly incorporates this path into its process environment. This change enhances cross-platform compatibility and robustness for Windows users interacting with the Insights feature.

Highlights

  • Bug Fix for Windows Insights Feature: Resolved an issue where the Insights feature on Windows would fail with a 'Claude Code requires git-bash' error due to missing Git Bash path detection in its environment configuration.
  • Refactored Git Bash Path Detection: The deriveGitBashPath utility function, responsible for locating bash.exe within various Git for Windows installation structures, has been extracted from agent-process.ts and moved to env-utils.ts for better reusability and adherence to the DRY principle.
  • Integrated Git Bash Detection into Insights Configuration: The InsightsConfig.getProcessEnv() method now includes logic to detect and set the CLAUDE_CODE_GIT_BASH_PATH environment variable on Windows, mirroring the existing detection in AgentProcess.setupProcessEnvironment().
  • Comprehensive Unit Tests Added: Ten new unit tests have been added for the deriveGitBashPath function, covering non-Windows platforms, various Git installation paths (cmd, bin, mingw64, mingw32), paths with spaces, and fallback logic.
  • Cleaned Up Stale Mocks: Outdated mocks for deriveGitBashPath in test files related to cli-tool-manager have been removed, reflecting the function's new location.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sentry
Copy link

sentry bot commented Jan 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses a bug on Windows for the Insights feature by ensuring the Git Bash path is detected and passed to the environment. The refactoring of deriveGitBashPath into a shared utility is a great step towards cleaner code. My main feedback is to take this a step further by also extracting the calling logic into a shared utility to avoid duplication between InsightsConfig and AgentProcess, and to use the project's platform abstractions for consistency. The addition of comprehensive unit tests for the new utility is excellent.

@g1331 g1331 force-pushed the fix/windows-insights-git-bash branch 2 times, most recently from 9058540 to 3de801a Compare January 17, 2026 04:11
@g1331 g1331 marked this pull request as ready for review January 17, 2026 04:51
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/frontend/src/main/__tests__/env-utils.test.ts (1)

61-114: Avoid hardcoded system paths in test fixtures.

Several tests embed real system locations (e.g., C:\Program Files, /usr/local/bin, /opt/homebrew/bin). Please replace these with synthetic fixtures (e.g., C:\Tools\..., /tmp/...) or build paths via helpers so tests don’t assume real installation layouts. Apply similar replacements throughout this file.

🔧 Example adjustments
- expect(shouldUseShell('D:\\Program Files\\nodejs\\claude.cmd')).toBe(true);
+ expect(shouldUseShell('D:\\Tools\\nodejs\\claude.cmd')).toBe(true);

- expect(shouldUseShell('/usr/local/bin/claude')).toBe(false);
+ expect(shouldUseShell('/tmp/bin/claude')).toBe(false);

- const result = deriveGitBashPath('C:\\Program Files\\Git\\cmd\\git.exe');
+ const result = deriveGitBashPath('C:\\Tools\\Git\\cmd\\git.exe');

As per coding guidelines, avoid hardcoding platform-specific system paths.

Also applies to: 131-244, 270-386, 413-429, 478-551, 625-651

🤖 Fix all issues with AI agents
In `@apps/frontend/src/main/env-utils.ts`:
- Around line 626-634: The lazy loader getToolInfoLazy uses bare require() which
will crash in ESM builds; replace the direct require usage in getToolInfoLazy
(and the module-level _getToolInfo initialization) with an ESM-safe
createRequire(import.meta.url) based loader similar to worktree-handlers.ts:
create a local require via createRequire(import.meta.url) and call that to load
'./cli-tool-manager' and assign its getToolInfo to _getToolInfo before invoking
it so the circular lazy import remains but works under "type":"module".

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/frontend/src/main/env-utils.ts`:
- Around line 619-622: The logs in deriveGitBashPath are printing full Windows
paths and error objects which may contain usernames/PII; update the warnings in
deriveGitBashPath and the similar log around lines 665-666 to redact sensitive
path info by replacing user-specific segments with a generic marker (e.g., "~"
or only keep the executable basename) or log a boolean/existence result instead
of the full path, and ensure the caught error is sanitized (do not stringify the
full error with paths — log a short message or error.code only). Locate
deriveGitBashPath and the other logging site by name, remove direct printing of
bashPath/altBashPath/error, and emit sanitized messages like "bash.exe not
found" or "error deriving git-bash path: <sanitized-info>" while preserving
useful non-PII diagnostic detail.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/frontend/src/main/env-utils.ts`:
- Around line 560-643: The deriveGitBashPath function can receive quoted or
empty gitExePath causing path.win32.dirname and fs.existsSync to fail; before
any path operations, normalize the input by trimming whitespace, stripping
surrounding double or single quotes (e.g., gitExePath =
gitExePath.trim().replace(/^["'](.*)["']$/, '$1')), return null if the resulting
string is empty, and then proceed using winPath on the cleaned path; update the
initial lines of deriveGitBashPath to use this normalized variable so all
subsequent dirname/basename/join and existsSync checks operate on an unquoted
path.

Comment on lines +560 to +650

/**
* Derive git-bash (bash.exe) path from git executable path on Windows.
*
* Git for Windows installs bash.exe in Git/bin/ directory. This function
* handles various git.exe locations:
* - .../Git/cmd/git.exe -> .../Git/bin/bash.exe
* - .../Git/bin/git.exe -> .../Git/bin/bash.exe
* - .../Git/mingw64/bin/git.exe -> .../Git/bin/bash.exe
*
* @param gitExePath - Path to git.exe (e.g., D:\Program Files\Git\mingw64\bin\git.exe)
* @returns Path to bash.exe if found, null otherwise
*/
function formatPathForLogs(filePath: string): string {
if (!filePath) {
return '';
}
return path.win32.basename(filePath) || path.basename(filePath);
}

function formatErrorForLogs(error: unknown): string {
if (error && typeof error === 'object' && 'code' in error) {
const code = (error as { code?: unknown }).code;
return typeof code === 'string' || typeof code === 'number' ? String(code) : 'unknown';
}
if (error instanceof Error) {
return error.name;
}
return 'unknown';
}

export function deriveGitBashPath(gitExePath: string): string | null {
if (!isWindows()) {
return null;
}

try {
// Use win32 path ops to correctly parse Windows-style paths on non-Windows runners
const winPath = path.win32;
const gitDir = winPath.dirname(gitExePath); // e.g., D:\...\Git\mingw64\bin
const gitDirName = winPath.basename(gitDir).toLowerCase();

// Find Git installation root
let gitRoot: string;

if (gitDirName === 'cmd') {
// .../Git/cmd/git.exe -> .../Git
gitRoot = winPath.dirname(gitDir);
} else if (gitDirName === 'bin') {
// Could be .../Git/bin/git.exe OR .../Git/mingw64/bin/git.exe
const parent = winPath.dirname(gitDir);
const parentName = winPath.basename(parent).toLowerCase();
if (parentName === 'mingw64' || parentName === 'mingw32') {
// .../Git/mingw64/bin/git.exe -> .../Git
gitRoot = winPath.dirname(parent);
} else {
// .../Git/bin/git.exe -> .../Git
gitRoot = parent;
}
} else {
// Unknown structure - try to find 'bin' sibling
gitRoot = winPath.dirname(gitDir);
}

// Bash.exe is in Git/bin/bash.exe
const bashPath = winPath.join(gitRoot, 'bin', 'bash.exe');

if (fs.existsSync(bashPath)) {
return bashPath;
}

// Fallback: check one level up if gitRoot didn't work
const altBashPath = winPath.join(winPath.dirname(gitRoot), 'bin', 'bash.exe');
if (fs.existsSync(altBashPath)) {
return altBashPath;
}

console.warn('[deriveGitBashPath] bash.exe not found in standard locations.');
return null;
} catch (error) {
console.warn('[deriveGitBashPath] Error deriving git-bash path:', formatErrorForLogs(error));
return null;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Handle quoted or empty git.exe paths to avoid false negatives.

If gitExePath arrives quoted (common when paths with spaces are serialized) or empty, path.win32.dirname preserves quotes and existsSync will fail even when bash.exe exists. Normalize and strip surrounding quotes before path ops.

🛠️ Proposed fix
 export function deriveGitBashPath(gitExePath: string): string | null {
   if (!isWindows()) {
     return null;
   }
+  if (!gitExePath || !gitExePath.trim()) {
+    return null;
+  }

   try {
     // Use win32 path ops to correctly parse Windows-style paths on non-Windows runners
     const winPath = path.win32;
-    const gitDir = winPath.dirname(gitExePath);  // e.g., D:\...\Git\mingw64\bin
+    const normalizedGitExePath = winPath.normalize(
+      gitExePath.trim().replace(/^"+|"+$/g, '')
+    );
+    const gitDir = winPath.dirname(normalizedGitExePath);  // e.g., D:\...\Git\mingw64\bin
🤖 Prompt for AI Agents
In `@apps/frontend/src/main/env-utils.ts` around lines 560 - 643, The
deriveGitBashPath function can receive quoted or empty gitExePath causing
path.win32.dirname and fs.existsSync to fail; before any path operations,
normalize the input by trimming whitespace, stripping surrounding double or
single quotes (e.g., gitExePath = gitExePath.trim().replace(/^["'](.*)["']$/,
'$1')), return null if the resulting string is empty, and then proceed using
winPath on the cleaned path; update the initial lines of deriveGitBashPath to
use this normalized variable so all subsequent dirname/basename/join and
existsSync checks operate on an unquoted path.

@AndyMik90 AndyMik90 self-assigned this Jan 17, 2026
Copy link
Owner

@AndyMik90 AndyMik90 left a comment

Choose a reason for hiding this comment

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

🤖 Auto Claude PR Review

Merge Verdict: 🟠 NEEDS REVISION

🟠 Needs revision - 2 issue(s) require attention.

2 issue(s) must be addressed (1 required, 1 recommended), 3 suggestions

Risk Assessment

Factor Level Notes
Complexity High Based on lines changed
Security Impact None Based on security findings
Scope Coherence Good Based on structural review

Findings Summary

  • High: 1 issue(s)
  • Medium: 1 issue(s)
  • Low: 3 issue(s)

Generated by Auto Claude PR Review

Findings (5 selected of 5 total)

🟠 [1c30adbd5e08] [HIGH] Code duplication: Inline Git Bash detection instead of using getGitBashEnv()

📁 apps/frontend/src/main/insights/config.ts:144

The PR creates a shared getGitBashEnv() utility in env-utils.ts, but insights/config.ts reimplements the same logic inline (lines 144-160) instead of using the shared function. The comment claims this is 'to avoid lazy-loading issues with bundlers', but this is incorrect: getGitBashEnv() supports dependency injection via the toolInfoFn parameter specifically to avoid lazy loading. Meanwhile, agent-process.ts correctly uses const gitBashEnv = getGitBashEnv();. This duplication means: (1) Two places to maintain, (2) Inconsistent logging - insights/config.ts logs full paths (line 154) while env-utils.ts uses formatPathForLogs() for PII protection.

Suggested fix:

Replace lines 144-160 with: `const gitBashEnv = getGitBashEnv(getToolInfo);` using the dependency injection parameter to avoid lazy loading concerns. Update import to include getGitBashEnv.

🟡 [fd009e67e6af] [MEDIUM] Direct process.platform check violates CLAUDE.md platform abstraction guidelines

📁 apps/frontend/src/main/insights/config.ts:147

The code uses process.platform === 'win32' directly instead of the centralized isWindows() helper from the platform module. CLAUDE.md explicitly states: 'Import from these modules instead of checking process.platform directly' and marks direct checks as '❌ WRONG'. The same file also has direct platform checks at lines 125 and 129 for path comparison logic.

Suggested fix:

Import `isWindows` from '../platform' and replace `process.platform === 'win32'` with `isWindows()` at lines 125, 129, and 147.

🔵 [c9215d069dcd] [LOW] Logs full path instead of using formatPathForLogs() for PII protection

📁 apps/frontend/src/main/insights/config.ts:154

Line 154 logs the full bashPath: console.log('[InsightsConfig] Setting CLAUDE_CODE_GIT_BASH_PATH:', bashPath);. However, the shared getGitBashEnv() in env-utils.ts uses formatPathForLogs(bashPath) which extracts only the basename to protect potentially sensitive directory structures (Windows paths often contain usernames like C:\Users\JohnDoe...). This inconsistency exposes PII in logs.

Suggested fix:

Either use the shared `getGitBashEnv()` function (preferred), or use `formatPathForLogs(bashPath)` for the log message.

🔵 [1e55f123550c] [LOW] Non-null assertion on potentially undefined module export

📁 apps/frontend/src/main/env-utils.ts:651

The lazy loading pattern uses _getToolInfo = require('./cli-tool-manager').getToolInfo and then _getToolInfo!(tool) with a non-null assertion. If the require returns an object where getToolInfo is undefined (e.g., bundler misconfiguration, export renamed), _getToolInfo would be undefined but pass the null check on line 650, causing a TypeError when called. While the outer try-catch in getGitBashEnv would catch this, a clearer error would help debugging.

Suggested fix:

Add type validation after require: `const imported = require('./cli-tool-manager').getToolInfo; if (typeof imported !== 'function') throw new Error('getToolInfo not exported correctly'); _getToolInfo = imported;`

🔵 [9ce2e55706d2] [LOW] Missing test case for error thrown by getToolInfo

📁 apps/frontend/src/main/__tests__/env-utils.test.ts:555

The test suite for getGitBashEnv (lines 555-653) tests many scenarios but lacks a test for when the injected toolInfoFn throws an exception. The getGitBashEnv function has error handling for this case (lines 676-688), but it's not verified by tests.

Suggested fix:

Add test: `it('should return empty object and log warning if getToolInfo throws', () => { mockGetToolInfo.mockImplementation(() => { throw new Error('Detection failed'); }); expect(getGitBashEnv(mockGetToolInfo)).toEqual({}); });`

This review was generated by Auto Claude.

@g1331 g1331 requested a review from AndyMik90 January 17, 2026 13:24
AndyMik90
AndyMik90 previously approved these changes Jan 17, 2026
Copy link
Owner

@AndyMik90 AndyMik90 left a comment

Choose a reason for hiding this comment

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

good use of the new iswindows

@AndyMik90
Copy link
Owner

@g1331 I'm getting "This branch has conflicts that must be resolved" but cannot see the confliccts.

g1331 added 10 commits January 18, 2026 10:20
- Extract deriveGitBashPath() to shared env-utils.ts (DRY principle)
- Add CLAUDE_CODE_GIT_BASH_PATH env var detection in InsightsConfig
- Add 10 unit tests for deriveGitBashPath covering various Git install paths
- Clean up stale mocks in test files

Fixes Windows "Claude Code requires git-bash" error when using Insights feature.
The issue occurred because InsightsConfig.getProcessEnv() was missing the
Git Bash detection logic that AgentProcess already had.
Address code review feedback from Gemini Code Assist:
- Extract shared getGitBashEnv() function to env-utils.ts
- Simplify AgentProcess.setupProcessEnvironment() to use shared function
- Simplify InsightsConfig.getProcessEnv() to use shared function
- Use isWindows() from platform module instead of direct process.platform check
- Add dependency injection parameter for testability (avoids circular dependency)
- Add 6 unit tests for getGitBashEnv()

This follows the DRY principle and centralizes Git Bash detection logic.
Tests for deriveGitBashPath and getGitBashEnv were failing on macOS/Ubuntu
because they only mocked process.platform but the isWindows() function
from the platform module was not mocked.

- Added vi.mock for ../platform module with isWindows() and isUnix()
- Set default return values (false/true) for non-Windows behavior
- Added setPlatformMock() helper to dynamically control mock return values
- Updated all test blocks to call setPlatformMock() when setting platform

This allows Windows-specific logic to be tested on any CI runner platform
while maintaining proper isolation between test cases.
The lazy-loaded getGitBashEnv() using createRequire was failing silently
in bundled Electron apps, causing CLAUDE_CODE_GIT_BASH_PATH to not be set.

Reverted to the working pattern: direct ESM import of getToolInfo from
cli-tool-manager with explicit process.platform === 'win32' check.
Address PR review feedback:
- Replace inline Git Bash detection with getGitBashEnv(toolInfoFn)
- Use isWindows() from platform module instead of direct process.platform checks
- Add type adapter for CLITool compatibility
Apply same fix as insights/config.ts to avoid lazy loading issues
in bundled Electron apps. Use getGitBashEnv() with toolInfoFn
parameter instead of parameterless call.
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