Files
thedotmack__claude-mem/tests/npx-cli/windows-git-bash-preflight.test.ts
Alex Newman 6682ea6e3e fix(windows): address PR #3661 review and tester findings
Four fixes from the megafix review cycle:

- mirror-dir.cjs: refuse identical or ancestor/descendant source and
  destination roots before any filesystem mutation. The --delete pass
  enumerated the destination first, so a source nested inside the
  destination was seen as stale and recursively deleted (Greptile P1).

- worker-logs.cjs: track file identity (dev/ino) in the --follow loop.
  A rename-and-recreate rotation whose replacement matched the old
  offset's byte size was skipped forever by the size-only check
  (Greptile P2).

- windows-git-bash-preflight: derive bin\bash.exe from every `git`
  PATH hit instead of only the first. Git for Windows puts both
  mingw64\bin\git.exe and cmd\git.exe on PATH; when mingw64 sorts
  first the derivation missed the real bash and doctor reported a
  false negative (tester report, D:\JavaTool\GIT layout).

- doctor: a missing .install-version marker with node_modules present
  is now a warn, not a required failure. The marker is written only by
  the npx installer — marketplace-flow and dev build-and-sync installs
  never have one, so the check always failed for them and its repair
  suggestion would overwrite the checkout under test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JT1VTKoaTf7VfePb7nVfwz
2026-08-25 16:24:52 -07:00

115 lines
4.0 KiB
TypeScript

import { describe, it, expect } from 'bun:test';
import {
checkWindowsGitBash,
GIT_BASH_REMEDIATION,
STANDARD_GIT_BASH_PATHS,
type GitBashProbe,
} from '../../src/npx-cli/utils/windows-git-bash-preflight.js';
// Windows #3605 (fail-loudly slice) — claude-mem hooks require bash, and on
// Windows Claude Code resolves it via a closed chain (CLAUDE_CODE_GIT_BASH_PATH
// -> standard Git for Windows paths -> `git` on PATH -> null, no WSL fallback).
// This preflight replicates that chain to detect "no Git Bash reachable" ahead
// of the first opaque hook throw.
function probeThatMustNotBeCalled(): GitBashProbe {
return {
fileExists: () => {
throw new Error('fileExists should not be called off-Windows');
},
lookupGitCandidates: () => {
throw new Error('lookupGitCandidates should not be called off-Windows');
},
};
}
describe('checkWindowsGitBash', () => {
it('reports the actionable error when no bash is reachable anywhere in the chain', () => {
const probe: GitBashProbe = {
fileExists: () => false,
lookupGitCandidates: () => [],
};
const result = checkWindowsGitBash('win32', {}, probe);
expect(result.ok).toBe(false);
expect(result.detail).toBe(GIT_BASH_REMEDIATION);
expect(result.detail).toContain('Git for Windows');
expect(result.detail).toContain('CLAUDE_CODE_GIT_BASH_PATH');
});
it('passes when CLAUDE_CODE_GIT_BASH_PATH points at a real file', () => {
const probe: GitBashProbe = {
fileExists: (path) => path === 'D:\\custom\\bash.exe',
lookupGitCandidates: () => {
throw new Error('should not fall through to PATH lookup');
},
};
const result = checkWindowsGitBash(
'win32',
{ CLAUDE_CODE_GIT_BASH_PATH: 'D:\\custom\\bash.exe' },
probe,
);
expect(result.ok).toBe(true);
expect(result.resolvedPath).toBe('D:\\custom\\bash.exe');
});
it('passes when Git is present at the standard install path', () => {
const probe: GitBashProbe = {
fileExists: (path) => path === STANDARD_GIT_BASH_PATHS[0],
lookupGitCandidates: () => {
throw new Error('should not fall through to PATH lookup');
},
};
const result = checkWindowsGitBash('win32', {}, probe);
expect(result.ok).toBe(true);
expect(result.resolvedPath).toBe(STANDARD_GIT_BASH_PATHS[0]);
});
it('falls through to `git` on PATH and resolves ../../bin/bash.exe relative to it', () => {
const probe: GitBashProbe = {
fileExists: (path) => path === 'C:\\Program Files\\Git\\bin\\bash.exe',
lookupGitCandidates: () => ['C:\\Program Files\\Git\\cmd\\git.exe'],
};
const result = checkWindowsGitBash('win32', {}, probe);
expect(result.ok).toBe(true);
expect(result.resolvedPath).toBe('C:\\Program Files\\Git\\bin\\bash.exe');
});
// #3661 tester report: Git for Windows at a non-standard root puts both
// mingw64\bin\git.exe and cmd\git.exe on PATH. When mingw64\bin sorts first,
// its ../../bin derivation points at mingw64\bin\bash.exe (does not exist);
// the cmd\git.exe hit derives the real <Git>\bin\bash.exe. Every candidate
// must be tried, not just the first.
it('tries every `git` PATH hit when the first one does not yield a bash.exe', () => {
const probe: GitBashProbe = {
fileExists: (path) => path === 'D:\\JavaTool\\GIT\\bin\\bash.exe',
lookupGitCandidates: () => [
'D:\\JavaTool\\GIT\\mingw64\\bin\\git.exe',
'D:\\JavaTool\\GIT\\cmd\\git.exe',
],
};
const result = checkWindowsGitBash('win32', {}, probe);
expect(result.ok).toBe(true);
expect(result.resolvedPath).toBe('D:\\JavaTool\\GIT\\bin\\bash.exe');
});
it('does not run at all on darwin', () => {
const result = checkWindowsGitBash('darwin', {}, probeThatMustNotBeCalled());
expect(result.ok).toBe(true);
});
it('does not run at all on linux', () => {
const result = checkWindowsGitBash('linux', {}, probeThatMustNotBeCalled());
expect(result.ok).toBe(true);
});
});