A tiny, local-first CLI that finds the files your AI coding agent actually needs — and packs them into a focused context.
| 1 | """Tests for ignore matching.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | |
| 7 | from agent_context.ignore import IgnoreMatcher |
| 8 | |
| 9 | |
| 10 | def test_builtin_node_modules(tmp_path: Path): |
| 11 | matcher = IgnoreMatcher.create(tmp_path, use_gitignore=False) |
| 12 | assert matcher.should_skip_dir("node_modules") |
| 13 | assert matcher.is_ignored("node_modules/lodash/index.js") |
| 14 | |
| 15 | |
| 16 | def test_builtin_dist_venv(tmp_path: Path): |
| 17 | matcher = IgnoreMatcher.create(tmp_path, use_gitignore=False) |
| 18 | assert matcher.should_skip_dir("dist") |
| 19 | assert matcher.should_skip_dir(".venv") |
| 20 | assert matcher.should_skip_dir("__pycache__") |
| 21 | assert matcher.is_ignored("package-lock.json") |
| 22 | |
| 23 | |
| 24 | def test_gitignore_file(tmp_path: Path): |
| 25 | (tmp_path / ".gitignore").write_text("secret/\n*.log\n", encoding="utf-8") |
| 26 | matcher = IgnoreMatcher.create(tmp_path) |
| 27 | assert matcher.should_skip_dir("secret") |
| 28 | assert matcher.is_ignored("app.log") |
| 29 | assert not matcher.is_ignored("src/main.py") |
| 30 | |
| 31 | |
| 32 | def test_custom_exclude(tmp_path: Path): |
| 33 | matcher = IgnoreMatcher.create( |
| 34 | tmp_path, |
| 35 | exclude=["generated/**"], |
| 36 | use_gitignore=False, |
| 37 | use_builtins=False, |
| 38 | ) |
| 39 | assert matcher.is_ignored("generated/foo.ts") |
| 40 | assert not matcher.is_ignored("src/foo.ts") |
| 41 | |
| 42 | |
| 43 | def test_custom_include(tmp_path: Path): |
| 44 | matcher = IgnoreMatcher.create( |
| 45 | tmp_path, |
| 46 | include=["src/**"], |
| 47 | use_gitignore=False, |
| 48 | use_builtins=False, |
| 49 | ) |
| 50 | assert not matcher.is_ignored("src/a.py") |
| 51 | assert matcher.is_ignored("docs/a.md") |
| 52 | |
| 53 | |
| 54 | def test_does_not_ignore_src(tmp_path: Path): |
| 55 | matcher = IgnoreMatcher.create(tmp_path, use_gitignore=False) |
| 56 | assert not matcher.should_skip_dir("src") |
| 57 | assert not matcher.is_ignored("src/auth/middleware.ts") |