import { beforeEach, describe, expect, it, mock } from 'bun:test'; const gitService = { stageGitFiles: mock(), unstageGitFiles: mock(), }; mock.module('./gitService', () => gitService); const { handleStandardGitBridgeMessage } = await import('./bridge-git-runtime'); describe('bridge git runtime index mutations', () => { beforeEach(() => { gitService.stageGitFiles.mockReset(); gitService.unstageGitFiles.mockReset(); }); it('accepts legacy stage path payloads', async () => { const response = await handleStandardGitBridgeMessage({ id: '1', type: 'api:git/stage', payload: { directory: '/repo', path: 'a.ts' }, }); expect(response).toEqual({ id: '1', type: 'api:git/stage', success: true, data: { success: true } }); expect(gitService.stageGitFiles).toHaveBeenCalledWith('/repo', ['a.ts']); }); it('accepts bulk stage paths payloads', async () => { const response = await handleStandardGitBridgeMessage({ id: '1', type: 'api:git/stage', payload: { directory: '/repo', paths: ['a.ts', 'b.ts'] }, }); expect(response?.success).toBe(true); expect(gitService.stageGitFiles).toHaveBeenCalledWith('/repo', ['a.ts', 'b.ts']); }); it('accepts legacy unstage path payloads', async () => { const response = await handleStandardGitBridgeMessage({ id: '1', type: 'api:git/unstage', payload: { directory: '/repo', path: 'a.ts' }, }); expect(response).toEqual({ id: '1', type: 'api:git/unstage', success: true, data: { success: true } }); expect(gitService.unstageGitFiles).toHaveBeenCalledWith('/repo', ['a.ts']); }); it('accepts bulk unstage paths payloads', async () => { const response = await handleStandardGitBridgeMessage({ id: '1', type: 'api:git/unstage', payload: { directory: '/repo', paths: ['a.ts', 'b.ts'] }, }); expect(response?.success).toBe(true); expect(gitService.unstageGitFiles).toHaveBeenCalledWith('/repo', ['a.ts', 'b.ts']); }); it('rejects invalid path payloads', async () => { const response = await handleStandardGitBridgeMessage({ id: '1', type: 'api:git/stage', payload: { directory: '/repo', paths: [' ', null] }, }); expect(response?.success).toBe(false); expect(gitService.stageGitFiles).not.toHaveBeenCalled(); }); });