Fixes failing spec - "gh CLI Check Handler - should return installed: true when gh CLI is found" (#370)

A mock appears to have been broken by this change: https://github.com/AndyMik90/Auto-Claude/pull/185/commits/39e09e3793c5a3e84c45e54aaac6483b851a9687#diff-dbd75baa12f1f8dd98fe6c6fec63160b8be291bc8de4d2970e993e1081746ba0L110-R121

I ran into a failure on this test when setting up for the first time locally and running frontend tests. I expect this did not break elsewhere because others actually have the github CLI installed, and so it was not noticed that the code under test  executed the real filesystem commands to find it, and succeeded when doing so. But I do not have github CLI installed, and the test failed for me.

Signed-off-by: Ian <251394470+ianstantiate@users.noreply.github.com>
Co-authored-by: Andy <119136210+AndyMik90@users.noreply.github.com>
This commit is contained in:
Ian
2025-12-28 07:10:02 -05:00
committed by GitHub
parent db0cbea3f2
commit bc22064535
@@ -72,6 +72,16 @@ vi.mock('@electron-toolkit/utils', () => ({
}
}));
// Mock env-utils
const mockFindExecutable = vi.fn();
const mockGetAugmentedEnv = vi.fn();
vi.mock('../../../env-utils', () => ({
findExecutable: mockFindExecutable,
getAugmentedEnv: mockGetAugmentedEnv,
isCommandAvailable: vi.fn((cmd: string) => mockFindExecutable(cmd) !== null)
}));
// Create mock process for spawn
function createMockProcess(): EventEmitter & {
stdout: EventEmitter | null;
@@ -100,6 +110,10 @@ describe('GitHub OAuth Handlers', () => {
vi.clearAllMocks();
vi.resetModules();
// Set up default env-utils mocks
mockGetAugmentedEnv.mockReturnValue(process.env as Record<string, string>);
mockFindExecutable.mockReturnValue(null); // Default: executable not found
// Get mocked ipcMain
const electron = await import('electron');
ipcMain = electron.ipcMain as unknown as typeof ipcMain;
@@ -423,6 +437,10 @@ describe('GitHub OAuth Handlers', () => {
describe('gh CLI Check Handler', () => {
it('should return installed: true when gh CLI is found', async () => {
// Mock findExecutable to return gh path
mockFindExecutable.mockReturnValue('/usr/local/bin/gh');
// Mock execFileSync for version check
mockExecFileSync.mockImplementation((cmd: string, args?: string[]) => {
if (args && args[0] === '--version') {
return 'gh version 2.65.0 (2024-01-15)\n';
@@ -442,9 +460,8 @@ describe('GitHub OAuth Handlers', () => {
});
it('should return installed: false when gh CLI is not found', async () => {
mockExecFileSync.mockImplementation(() => {
throw new Error('Command not found');
});
// Mock findExecutable to return null (not found)
mockFindExecutable.mockReturnValue(null);
const { registerCheckGhCli } = await import('../oauth-handlers');
registerCheckGhCli();