Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude): add test coverage for merged-branch detection and cleanup scoping

Adam Eivyd5217d828112
diff --git a/client/src/components/apps/tabs/GitTab.test.jsx b/client/src/components/apps/tabs/GitTab.test.jsx
index 24c2241f4b..1e9e5e5251 100644
--- a/client/src/components/apps/tabs/GitTab.test.jsx
+++ b/client/src/components/apps/tabs/GitTab.test.jsx
@@ -8,6 +8,7 @@ vi.mock('../../../services/api', () => ({
getBranchComparison: vi.fn(),
getRemoteBranches: vi.fn(),
getGitDiff: vi.fn(),
+ cleanupMergedBranches: vi.fn(),
}));
import * as api from '../../../services/api';
@@ -34,6 +35,7 @@ beforeEach(() => {
api.getBranchComparison.mockResolvedValue(COMPARISON);
api.getRemoteBranches.mockResolvedValue({ branches: [], defaultBranch: 'main' });
api.getGitDiff.mockResolvedValue({ diff: '@@ -1 +1 @@\n-old\n+new' });
+ api.cleanupMergedBranches.mockResolvedValue({ deleted: [], skipped: [] });
});
afterEach(() => {
@@ -82,3 +84,37 @@ describe('GitTab modal accessibility (issue #1090)', () => {
expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
});
});
+
+describe('GitTab merged-branch cleanup scoping', () => {
+ beforeEach(() => {
+ api.getBranches.mockResolvedValue({
+ branches: [
+ { name: 'main', current: true, tracking: 'origin/main', ahead: 0, behind: 0, isDefault: true, merged: false },
+ { name: 'feature/done', current: false, tracking: 'origin/feature/done', ahead: 0, behind: 0, isDefault: false, merged: true },
+ ],
+ });
+ api.getRemoteBranches.mockResolvedValue({
+ branches: [
+ { name: 'main', fullRef: 'origin/main', merged: false, hasLocal: true, isDefault: true },
+ { name: 'old/one', fullRef: 'origin/old/one', merged: true, hasLocal: false, isDefault: false },
+ { name: 'old/two', fullRef: 'origin/old/two', merged: true, hasLocal: false, isDefault: false },
+ ],
+ defaultBranch: 'main',
+ });
+ });
+
+ it('shows only the local confirm block when the Local panel button is clicked, and discloses full local+remote scope', async () => {
+ render(<GitTab appId="x" appName="App" repoPath="/repo" />);
+
+ const localCleanBtn = await screen.findByText('Clean 1 merged');
+ fireEvent.click(localCleanBtn);
+
+ const confirmButtons = await screen.findAllByText('Delete all merged (local + remote)');
+ expect(confirmButtons).toHaveLength(1);
+ expect(confirmButtons[0]).toHaveAttribute('title', 'Deletes merged branches both locally and on the remote');
+
+ // The Remote panel's own trigger is hidden while the Local panel's confirm is active,
+ // and it must not render its own confirm block at the same time.
+ expect(screen.queryByText('Clean 2 merged')).toBeNull();
+ });
+});
diff --git a/server/services/getBranches.test.js b/server/services/getBranches.test.js
new file mode 100644
index 0000000000..a792b79037
--- /dev/null
+++ b/server/services/getBranches.test.js
@@ -0,0 +1,95 @@
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+
+vi.mock('../lib/execGit.js', () => ({
+ execGit: vi.fn()
+}));
+
+describe('getBranches', () => {
+ let getBranches;
+ let execGit;
+
+ beforeEach(async () => {
+ const execGitModule = await import('../lib/execGit.js');
+ execGit = execGitModule.execGit;
+ const gitModule = await import('./git.js');
+ getBranches = gitModule.getBranches;
+ });
+
+ afterEach(() => {
+ vi.clearAllMocks();
+ });
+
+ it('flags a non-current, non-protected branch merged into the default branch, and excludes the current/default branch', async () => {
+ execGit.mockImplementation((args) => {
+ if (args[0] === 'branch' && args.includes('-vv')) {
+ return Promise.resolve({
+ stdout: [
+ '*|main||',
+ ' |feature/done|origin/feature/done|',
+ ' |feature/wip|origin/feature/wip|[ahead 1]'
+ ].join('\n'),
+ stderr: '',
+ exitCode: 0
+ });
+ }
+ if (args[0] === 'symbolic-ref') {
+ return Promise.resolve({ stdout: 'origin/main', stderr: '', exitCode: 0 });
+ }
+ if (args[0] === 'rev-parse' && args.includes('--verify')) {
+ return Promise.resolve({ stdout: 'abc123', stderr: '', exitCode: 0 });
+ }
+ if (args[0] === 'branch' && args.includes('--list')) {
+ return Promise.resolve({ stdout: ' main\n feature/done\n feature/wip\n', stderr: '', exitCode: 0 });
+ }
+ if (args[0] === 'branch' && args.includes('--merged')) {
+ return Promise.resolve({ stdout: 'main\nfeature/done\n', stderr: '', exitCode: 0 });
+ }
+ return Promise.resolve({ stdout: '', stderr: '', exitCode: 0 });
+ });
+
+ const branches = await getBranches('/fake/dir');
+
+ const main = branches.find(b => b.name === 'main');
+ const done = branches.find(b => b.name === 'feature/done');
+ const wip = branches.find(b => b.name === 'feature/wip');
+
+ expect(main.current).toBe(true);
+ expect(main.isDefault).toBe(true);
+ expect(main.merged).toBe(false);
+
+ expect(done.isDefault).toBe(false);
+ expect(done.merged).toBe(true);
+
+ expect(wip.merged).toBe(false);
+ });
+
+ it('never flags a protected branch (e.g. dev) as merged even when it appears in the --merged output', async () => {
+ execGit.mockImplementation((args) => {
+ if (args[0] === 'branch' && args.includes('-vv')) {
+ return Promise.resolve({
+ stdout: ['*|main||', ' |dev||'].join('\n'),
+ stderr: '',
+ exitCode: 0
+ });
+ }
+ if (args[0] === 'symbolic-ref') {
+ return Promise.resolve({ stdout: 'origin/main', stderr: '', exitCode: 0 });
+ }
+ if (args[0] === 'rev-parse' && args.includes('--verify')) {
+ return Promise.resolve({ stdout: 'abc123', stderr: '', exitCode: 0 });
+ }
+ if (args[0] === 'branch' && args.includes('--list')) {
+ return Promise.resolve({ stdout: ' main\n dev\n', stderr: '', exitCode: 0 });
+ }
+ if (args[0] === 'branch' && args.includes('--merged')) {
+ return Promise.resolve({ stdout: 'main\ndev\n', stderr: '', exitCode: 0 });
+ }
+ return Promise.resolve({ stdout: '', stderr: '', exitCode: 0 });
+ });
+
+ const branches = await getBranches('/fake/dir');
+ const dev = branches.find(b => b.name === 'dev');
+
+ expect(dev.merged).toBe(false);
+ });
+});