Files
claude-mem/tests/utils/project-filter.test.ts
Alex Newman bf439043cf MAESTRO: Merge PRs #920 and #699 - Add project exclusion and folder CLAUDE.md exclusion settings
Cherry-picked both PRs to main (both had merge conflicts with current main).

PR #920 (@Spunky84): CLAUDE_MEM_EXCLUDED_PROJECTS setting with glob patterns
to exclude entire projects from memory tracking (privacy/confidentiality).
Early-exit in session-init and observation handlers. 11 unit tests.

PR #699 (@leepokai): CLAUDE_MEM_FOLDER_MD_EXCLUDE setting with JSON array
of paths to exclude from CLAUDE.md file generation (fixes SwiftUI/Xcode
build conflicts and drizzle kit migration failures). Closes #620.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 05:23:01 -05:00

97 lines
3.6 KiB
TypeScript

/**
* Project Filter Tests
*
* Tests glob-based path matching for project exclusion.
* Source: src/utils/project-filter.ts
*/
import { describe, it, expect } from 'bun:test';
import { isProjectExcluded } from '../../src/utils/project-filter.js';
import { homedir } from 'os';
describe('Project Filter', () => {
describe('isProjectExcluded', () => {
describe('with empty patterns', () => {
it('returns false for empty pattern string', () => {
expect(isProjectExcluded('/Users/test/project', '')).toBe(false);
expect(isProjectExcluded('/Users/test/project', ' ')).toBe(false);
});
});
describe('with exact path matching', () => {
it('matches exact paths', () => {
expect(isProjectExcluded('/tmp/secret', '/tmp/secret')).toBe(true);
expect(isProjectExcluded('/tmp/public', '/tmp/secret')).toBe(false);
});
});
describe('with * wildcard (single directory level)', () => {
it('matches any directory name', () => {
expect(isProjectExcluded('/tmp/secret', '/tmp/*')).toBe(true);
expect(isProjectExcluded('/tmp/anything', '/tmp/*')).toBe(true);
});
it('does not match across directory boundaries', () => {
expect(isProjectExcluded('/tmp/a/b', '/tmp/*')).toBe(false);
});
});
describe('with ** wildcard (any path depth)', () => {
it('matches any path depth', () => {
expect(isProjectExcluded('/Users/test/kunden/client1/project', '/Users/*/kunden/**')).toBe(true);
expect(isProjectExcluded('/Users/test/kunden/deep/nested/project', '/Users/*/kunden/**')).toBe(true);
});
});
describe('with ? wildcard (single character)', () => {
it('matches single character', () => {
expect(isProjectExcluded('/tmp/a', '/tmp/?')).toBe(true);
expect(isProjectExcluded('/tmp/ab', '/tmp/?')).toBe(false);
});
});
describe('with ~ home directory expansion', () => {
it('expands ~ to home directory', () => {
const home = homedir();
expect(isProjectExcluded(`${home}/secret`, '~/secret')).toBe(true);
expect(isProjectExcluded(`${home}/projects/secret`, '~/projects/*')).toBe(true);
});
});
describe('with multiple patterns', () => {
it('returns true if any pattern matches', () => {
const patterns = '/tmp/*,~/kunden/*,/var/secret';
expect(isProjectExcluded('/tmp/test', patterns)).toBe(true);
expect(isProjectExcluded(`${homedir()}/kunden/client`, patterns)).toBe(true);
expect(isProjectExcluded('/var/secret', patterns)).toBe(true);
expect(isProjectExcluded('/home/user/public', patterns)).toBe(false);
});
});
describe('with Windows-style paths', () => {
it('normalizes backslashes to forward slashes', () => {
expect(isProjectExcluded('C:\\Users\\test\\secret', 'C:/Users/*/secret')).toBe(true);
});
});
describe('real-world patterns', () => {
it('excludes customer projects', () => {
const patterns = '~/kunden/*,~/customers/**';
const home = homedir();
expect(isProjectExcluded(`${home}/kunden/acme-corp`, patterns)).toBe(true);
expect(isProjectExcluded(`${home}/customers/bigco/project1`, patterns)).toBe(true);
expect(isProjectExcluded(`${home}/projects/opensource`, patterns)).toBe(false);
});
it('excludes temporary directories', () => {
const patterns = '/tmp/*,/var/tmp/*';
expect(isProjectExcluded('/tmp/scratch', patterns)).toBe(true);
expect(isProjectExcluded('/var/tmp/test', patterns)).toBe(true);
expect(isProjectExcluded('/home/user/tmp', patterns)).toBe(false);
});
});
});
});