File size: 1,405 Bytes
1dbc34b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { describe, it, expect } from 'vitest';
import { sanitizeWorktreeByProject } from '../../../src/lib/settings-utils';

describe('sanitizeWorktreeByProject', () => {
  it('returns an empty object when input is undefined', () => {
    expect(sanitizeWorktreeByProject(undefined)).toEqual({});
  });

  it('keeps structurally valid worktree entries', () => {
    const input = {
      '/project-a': { path: null, branch: 'main' },
      '/project-b': { path: '/project-b/.worktrees/feature-x', branch: 'feature/x' },
    };

    expect(sanitizeWorktreeByProject(input)).toEqual(input);
  });

  it('drops malformed entries and keeps valid ones', () => {
    const input: Record<string, unknown> = {
      '/valid': { path: '/valid/.worktrees/feature-y', branch: 'feature/y' },
      '/valid-main': { path: null, branch: 'main' },
      '/invalid-not-object': 'bad',
      '/invalid-null': null,
      '/invalid-no-branch': { path: '/x' },
      '/invalid-branch-type': { path: '/x', branch: 123 },
      '/invalid-empty-branch': { path: '/x', branch: '   ' },
      '/invalid-path-type': { path: 42, branch: 'feature/z' },
      '/invalid-empty-path': { path: '   ', branch: 'feature/z' },
    };

    expect(sanitizeWorktreeByProject(input)).toEqual({
      '/valid': { path: '/valid/.worktrees/feature-y', branch: 'feature/y' },
      '/valid-main': { path: null, branch: 'main' },
    });
  });
});