feat: commit push/pull/fetch and others

This commit is contained in:
2026-02-16 12:24:36 +01:00
parent 9f3b5d0867
commit 56931f81ba
11 changed files with 429 additions and 2 deletions

View File

@@ -11,6 +11,9 @@ const mockInit = vi.fn();
const mockRaw = vi.fn();
const mockAdd = vi.fn();
const mockCommit = vi.fn();
const mockFetch = vi.fn();
const mockPull = vi.fn();
const mockPush = vi.fn();
const mockGetRemotes = vi.fn();
const mockAddRemote = vi.fn();
const mockRemote = vi.fn();
@@ -40,6 +43,9 @@ vi.mock('simple-git', () => ({
raw: mockRaw,
add: mockAdd,
commit: mockCommit,
fetch: mockFetch,
pull: mockPull,
push: mockPush,
getRemotes: mockGetRemotes,
addRemote: mockAddRemote,
remote: mockRemote,
@@ -451,4 +457,52 @@ describe('GitEngine', () => {
expect(result.error).toContain('prune failed');
});
});
describe('repo actions', () => {
it('should run fetch with prune and return success', async () => {
mockFetch.mockResolvedValue(undefined);
const result = await gitEngine.fetch('/tmp/project');
expect(mockFetch).toHaveBeenCalledWith(['--prune']);
expect(result).toEqual({ success: true });
});
it('should run pull and return success', async () => {
mockPull.mockResolvedValue(undefined);
const result = await gitEngine.pull('/tmp/project');
expect(mockPull).toHaveBeenCalled();
expect(result).toEqual({ success: true });
});
it('should run push and return success', async () => {
mockPush.mockResolvedValue(undefined);
const result = await gitEngine.push('/tmp/project');
expect(mockPush).toHaveBeenCalled();
expect(result).toEqual({ success: true });
});
it('should stage all files and commit with message', async () => {
mockAdd.mockResolvedValue(undefined);
mockCommit.mockResolvedValue(undefined);
const result = await gitEngine.commitAll('/tmp/project', 'feat: commit changes');
expect(mockAdd).toHaveBeenCalledWith(['-A']);
expect(mockCommit).toHaveBeenCalledWith('feat: commit changes');
expect(result).toEqual({ success: true });
});
it('should reject empty commit messages', async () => {
const result = await gitEngine.commitAll('/tmp/project', ' ');
expect(mockAdd).not.toHaveBeenCalled();
expect(mockCommit).not.toHaveBeenCalled();
expect(result).toEqual({ success: false, error: 'Commit message is required.' });
});
});
});

View File

@@ -147,6 +147,10 @@ const mockGitEngine = {
getDiff: vi.fn(),
getDiffContent: vi.fn(),
getHistory: vi.fn(),
fetch: vi.fn(),
pull: vi.fn(),
push: vi.fn(),
commitAll: vi.fn(),
initializeRepo: vi.fn(),
ensureGitignore: vi.fn(),
pruneLfsCache: vi.fn(),
@@ -454,6 +458,50 @@ describe('IPC Handlers', () => {
expect(result.success).toBe(true);
});
});
describe('git:fetch', () => {
it('should pass project path to GitEngine.fetch', async () => {
mockGitEngine.fetch.mockResolvedValue({ success: true });
const result = await invokeHandler('git:fetch', '/repo');
expect(mockGitEngine.fetch).toHaveBeenCalledWith('/repo');
expect(result).toEqual({ success: true });
});
});
describe('git:pull', () => {
it('should pass project path to GitEngine.pull', async () => {
mockGitEngine.pull.mockResolvedValue({ success: true });
const result = await invokeHandler('git:pull', '/repo');
expect(mockGitEngine.pull).toHaveBeenCalledWith('/repo');
expect(result).toEqual({ success: true });
});
});
describe('git:push', () => {
it('should pass project path to GitEngine.push', async () => {
mockGitEngine.push.mockResolvedValue({ success: true });
const result = await invokeHandler('git:push', '/repo');
expect(mockGitEngine.push).toHaveBeenCalledWith('/repo');
expect(result).toEqual({ success: true });
});
});
describe('git:commitAll', () => {
it('should pass project path and message to GitEngine.commitAll', async () => {
mockGitEngine.commitAll.mockResolvedValue({ success: true });
const result = await invokeHandler('git:commitAll', '/repo', 'feat: commit');
expect(mockGitEngine.commitAll).toHaveBeenCalledWith('/repo', 'feat: commit');
expect(result).toEqual({ success: true });
});
});
});
// ============ Project Handlers ============

View File

@@ -7,7 +7,14 @@ import { useAppStore } from '../../../src/renderer/store';
vi.mock('@monaco-editor/react', () => ({
__esModule: true,
default: (_props: unknown) => null,
DiffEditor: (props: { original: string; modified: string; language?: string; options?: Record<string, unknown> }) => (
DiffEditor: (props: {
original: string;
modified: string;
language?: string;
options?: Record<string, unknown>;
keepCurrentOriginalModel?: boolean;
keepCurrentModifiedModel?: boolean;
}) => (
<div data-testid="monaco-diff-editor">
<div>original:{props.original}</div>
<div>modified:{props.modified}</div>
@@ -15,6 +22,8 @@ vi.mock('@monaco-editor/react', () => ({
<div>renderSideBySide:{String(props.options?.renderSideBySide)}</div>
<div>wordWrap:{String(props.options?.wordWrap)}</div>
<div>hideUnchanged:{String((props.options?.hideUnchangedRegions as { enabled?: boolean } | undefined)?.enabled)}</div>
<div>keepOriginal:{String(props.keepCurrentOriginalModel)}</div>
<div>keepModified:{String(props.keepCurrentModifiedModel)}</div>
</div>
),
}));
@@ -67,5 +76,7 @@ describe('GitDiffView', () => {
expect(screen.getByText('renderSideBySide:false')).toBeInTheDocument();
expect(screen.getByText('wordWrap:on')).toBeInTheDocument();
expect(screen.getByText('hideUnchanged:false')).toBeInTheDocument();
expect(screen.getByText('keepOriginal:true')).toBeInTheDocument();
expect(screen.getByText('keepModified:true')).toBeInTheDocument();
});
});

View File

@@ -34,7 +34,12 @@ describe('GitSidebar', () => {
getRepoState: vi.fn().mockResolvedValue({ isRepo: false, hasRemote: false }),
getStatus: vi.fn().mockResolvedValue({ files: [], counts: { untracked: 0, modified: 0, deleted: 0, renamed: 0, staged: 0, total: 0 } }),
getDiff: vi.fn().mockResolvedValue({ filePath: 'posts/a.md', patch: 'diff --git a/posts/a.md b/posts/a.md' }),
getDiffContent: vi.fn().mockResolvedValue({ filePath: 'posts/a.md', original: '', modified: '' }),
getHistory: vi.fn().mockResolvedValue([]),
fetch: vi.fn().mockResolvedValue({ success: true }),
pull: vi.fn().mockResolvedValue({ success: true }),
push: vi.fn().mockResolvedValue({ success: true }),
commitAll: vi.fn().mockResolvedValue({ success: true }),
init: vi.fn().mockResolvedValue({ success: true }),
ensureGitignore: vi.fn().mockResolvedValue({ updated: false, created: false, addedEntries: [] }),
onInitProgress: vi.fn().mockImplementation(() => () => {}),
@@ -328,4 +333,64 @@ describe('GitSidebar', () => {
expect(transcriptToggle).toHaveAttribute('aria-expanded', 'true');
expect(screen.getByText(/100% — failed to configure remote repository/i)).toBeInTheDocument();
});
it('wires fetch, pull, and push buttons', async () => {
(window as any).electronAPI.git.getRepoState = vi.fn().mockResolvedValue({
isRepo: true,
rootPath: '/repo/path',
currentBranch: 'main',
hasRemote: true,
});
render(<GitSidebar />);
const fetchButton = await screen.findByRole('button', { name: /fetch/i });
const pullButton = screen.getByRole('button', { name: /pull/i });
const pushButton = screen.getByRole('button', { name: /push/i });
await act(async () => {
fireEvent.click(fetchButton);
fireEvent.click(pullButton);
fireEvent.click(pushButton);
});
expect((window as any).electronAPI.git.fetch).toHaveBeenCalledWith('/repo/path');
expect((window as any).electronAPI.git.pull).toHaveBeenCalledWith('/repo/path');
expect((window as any).electronAPI.git.push).toHaveBeenCalledWith('/repo/path');
});
it('commits all changes and closes open git-diff tabs', async () => {
(window as any).electronAPI.git.getRepoState = vi.fn().mockResolvedValue({
isRepo: true,
rootPath: '/repo/path',
currentBranch: 'main',
hasRemote: true,
});
useAppStore.setState({
tabs: [
{ type: 'git-diff', id: 'git-diff:posts/first.md', isTransient: false },
{ type: 'post', id: 'post-1', isTransient: false },
{ type: 'git-diff', id: 'git-diff:posts/second.md', isTransient: true },
],
activeTabId: 'git-diff:posts/first.md',
});
render(<GitSidebar />);
const commitInput = await screen.findByPlaceholderText(/commit message/i);
await act(async () => {
fireEvent.change(commitInput, { target: { value: 'feat: commit from sidebar' } });
});
const commitButton = screen.getByRole('button', { name: /^commit$/i });
await act(async () => {
fireEvent.click(commitButton);
});
expect((window as any).electronAPI.git.commitAll).toHaveBeenCalledWith('/repo/path', 'feat: commit from sidebar');
expect(getStore().tabs).toEqual([
{ type: 'post', id: 'post-1', isTransient: false },
]);
});
});