-
Notifications
You must be signed in to change notification settings - Fork 116
GSoC Module A : week 4 : feat(harvester): implement repository file filtering (stacked on top of #985) #986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ParthAggarwal16
wants to merge
23
commits into
OWASP:main
Choose a base branch
from
ParthAggarwal16:week_4-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
aed4fe6
feat(harvester): implement repository configuration loader
ParthAggarwal16 f370f73
fix(harvester): address CodeRabbit validation feedback
ParthAggarwal16 9478e54
feat(harvester): add repository config loader and validation
ParthAggarwal16 43fb6cb
addressing coderabbit
ParthAggarwal16 b962246
addressing coderabbit again
ParthAggarwal16 b556308
Add repository validation rules and fixtures
ParthAggarwal16 fc4b583
normalize repository ids during validation
ParthAggarwal16 713f99d
Refine harvester validation exports and YAML fixtures
ParthAggarwal16 c7ecbf0
removed stable dev comments
ParthAggarwal16 0be6df8
Add validator success test and clean exports
ParthAggarwal16 f96ff3d
Merge branch 'main' into week_1-2-harvester-validation-and-docs
ParthAggarwal16 c728fed
test(harvester): align tests with project conventions
ParthAggarwal16 d4e7731
chore: ignore Claude and Cursor project files
ParthAggarwal16 f11f869
refactor(harvester): address review feedback
ParthAggarwal16 fbc6e20
Add repository synchronization foundation
ParthAggarwal16 29fec6a
Addressing coderabbit and adding couple of extra gaurdrails
ParthAggarwal16 2783023
Addressing coderabbit final
ParthAggarwal16 721afa8
test(harvester): align week 2 tests with project conventions
ParthAggarwal16 1738cb4
fix(harvester): address repository client review feedback
ParthAggarwal16 fee277f
feat(harvester): implement incremental change detection
ParthAggarwal16 ccb515a
fix(harvester): write checkpoints atomically
ParthAggarwal16 853f34e
feat(harvester): implement repository file filtering
ParthAggarwal16 10b8f2f
fix(harvester): improve filtering benchmark and sync behavior
ParthAggarwal16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """ | ||
| tests for Module A configuration layer (empty for now) | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import unittest | ||
| from unittest.mock import MagicMock | ||
| from unittest.mock import patch | ||
|
|
||
| from application.utils.harvester.change_detector import ( | ||
| ChangeDetector, | ||
| ) | ||
|
|
||
|
|
||
| class ChangeDetectorTests(unittest.TestCase): | ||
| @patch("application.utils.harvester.change_detector.subprocess.run") | ||
| def test_get_modified_files_since(self, mock_run): | ||
| mock_run.return_value = MagicMock( | ||
| stdout="a.md\nb.md\na.md\n", | ||
| ) | ||
|
|
||
| client = MagicMock() | ||
| detector = ChangeDetector(client) | ||
|
|
||
| files = detector.get_modified_files_since("abc123") | ||
|
|
||
| self.assertEqual( | ||
| files, | ||
| [ | ||
| "a.md", | ||
| "b.md", | ||
| ], | ||
| ) | ||
|
|
||
| @patch("application.utils.harvester.change_detector.subprocess.run") | ||
| def test_get_commits_since(self, mock_run): | ||
| mock_run.return_value = MagicMock( | ||
| stdout="111\n222\n333\n", | ||
| ) | ||
|
|
||
| client = MagicMock() | ||
| detector = ChangeDetector(client) | ||
|
|
||
| commits = detector.get_commits_since("abc123") | ||
|
|
||
| self.assertEqual( | ||
| commits, | ||
| [ | ||
| "111", | ||
| "222", | ||
| "333", | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import unittest | ||
| from datetime import datetime | ||
| from pathlib import Path | ||
|
|
||
| from application.utils.harvester.checkpoint_store import ( | ||
| CheckpointStore, | ||
| ) | ||
| from application.utils.harvester.models import ( | ||
| RepositoryCheckpoint, | ||
| ) | ||
|
|
||
|
|
||
| class CheckpointStoreTests(unittest.TestCase): | ||
| def test_save_and_load_checkpoint(self): | ||
| tmp_dir = Path(self._testMethodName) | ||
|
|
||
| try: | ||
| store = CheckpointStore( | ||
| tmp_dir / "checkpoints.json", | ||
| ) | ||
|
|
||
| checkpoint = RepositoryCheckpoint( | ||
| repository_id="owasp-asvs", | ||
| last_processed_commit="abc123", | ||
| updated_at=datetime.now(), | ||
| ) | ||
|
|
||
| store.save(checkpoint) | ||
|
|
||
| loaded = store.load("owasp-asvs") | ||
|
|
||
| if loaded is None: | ||
| self.fail("Checkpoint should have been loaded") | ||
|
|
||
| self.assertEqual( | ||
| loaded.last_processed_commit, | ||
| "abc123", | ||
| ) | ||
|
|
||
| finally: | ||
| if tmp_dir.exists(): | ||
| import shutil | ||
|
|
||
| shutil.rmtree(tmp_dir) | ||
|
|
||
| def test_load_missing_file(self): | ||
| tmp_dir = Path(self._testMethodName) | ||
|
|
||
| try: | ||
| store = CheckpointStore( | ||
| tmp_dir / "missing.json", | ||
| ) | ||
|
|
||
| self.assertIsNone( | ||
| store.load("repo"), | ||
| ) | ||
|
|
||
| finally: | ||
| if tmp_dir.exists(): | ||
| import shutil | ||
|
|
||
| shutil.rmtree(tmp_dir) | ||
|
|
||
| def test_load_missing_repository(self): | ||
| tmp_dir = Path(self._testMethodName) | ||
|
|
||
| try: | ||
| store = CheckpointStore( | ||
| tmp_dir / "checkpoint.json", | ||
| ) | ||
|
|
||
| store.save( | ||
| RepositoryCheckpoint( | ||
| repository_id="repo-a", | ||
| last_processed_commit="abc123", | ||
| updated_at=datetime.now(), | ||
| ) | ||
| ) | ||
|
|
||
| self.assertIsNone( | ||
| store.load("repo-b"), | ||
| ) | ||
|
|
||
| finally: | ||
| if tmp_dir.exists(): | ||
| import shutil | ||
|
|
||
| shutil.rmtree(tmp_dir) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| from pathlib import Path | ||
| import unittest | ||
|
|
||
| from application.utils.harvester.config_loader import ( | ||
| ConfigLoaderError, | ||
| ConfigFileNotFoundError, | ||
| load_repo_config, | ||
| ) | ||
|
|
||
| FIXTURES_DIR = Path(__file__).parent / "fixtures" | ||
|
|
||
|
|
||
| class ConfigLoaderTests(unittest.TestCase): | ||
| def test_load_valid_config(self): | ||
| config_path = FIXTURES_DIR / "valid_repos.yaml" | ||
|
|
||
| config = load_repo_config(config_path) | ||
|
|
||
| self.assertEqual(len(config.repositories), 1) | ||
|
|
||
| repo = config.repositories[0] | ||
|
|
||
| self.assertEqual(repo.id, "owasp-asvs") | ||
| self.assertEqual(repo.owner, "OWASP") | ||
| self.assertEqual(repo.repo, "ASVS") | ||
|
|
||
| def test_missing_repository_id(self): | ||
| config_path = FIXTURES_DIR / "invalid_missing_id.yaml" | ||
|
|
||
| with self.assertRaises(ConfigLoaderError): | ||
| load_repo_config(config_path) | ||
|
|
||
| def test_invalid_chunk_size(self): | ||
| config_path = FIXTURES_DIR / "invalid_chunk_size.yaml" | ||
|
|
||
| with self.assertRaisesRegex(ConfigLoaderError, "max_tokens"): | ||
| load_repo_config(config_path) | ||
|
|
||
| def test_invalid_yaml_syntax(self): | ||
| config_path = FIXTURES_DIR / "invalid_yaml.yaml" | ||
|
|
||
| with self.assertRaises(ConfigLoaderError): | ||
| load_repo_config(config_path) | ||
|
|
||
| def test_missing_config_file(self): | ||
| with self.assertRaises(ConfigFileNotFoundError): | ||
| load_repo_config("does_not_exist.yaml") | ||
|
|
||
| def test_invalid_polling_interval(self): | ||
| config_path = FIXTURES_DIR / "invalid_polling_interval.yaml" | ||
|
|
||
| with self.assertRaises(ConfigLoaderError): | ||
| load_repo_config(config_path) | ||
|
|
||
| def test_empty_include_paths(self): | ||
| config_path = FIXTURES_DIR / "empty_include_paths.yaml" | ||
|
|
||
| with self.assertRaises(ConfigLoaderError): | ||
| load_repo_config(config_path) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import unittest | ||
|
|
||
| from application.utils.harvester.file_filter import ( | ||
| FileFilter, | ||
| ) | ||
|
|
||
|
|
||
| class FileFilterTests(unittest.TestCase): | ||
| def test_extension_filtering(self): | ||
| file_filter = FileFilter() | ||
|
|
||
| result = file_filter.filter_files( | ||
| [ | ||
| "README.md", | ||
| "image.png", | ||
| "script.js", | ||
| ] | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| result, | ||
| ["README.md"], | ||
| ) | ||
|
|
||
| def test_regex_filtering(self): | ||
| file_filter = FileFilter() | ||
|
|
||
| result = file_filter.filter_files( | ||
| [ | ||
| ".github/workflows/test.yml", | ||
| "docs/setup.md", | ||
| ] | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| result, | ||
| ["docs/setup.md"], | ||
| ) | ||
|
|
||
| def test_combined_filtering(self): | ||
| file_filter = FileFilter() | ||
|
|
||
| result = file_filter.filter_files( | ||
| [ | ||
| "README.md", | ||
| ".github/workflows/test.yml", | ||
| "node_modules/react/index.js", | ||
| "docs/setup.md", | ||
| ] | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| result, | ||
| [ | ||
| "README.md", | ||
| "docs/setup.md", | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
30 changes: 30 additions & 0 deletions
30
application/tests/harvester_test/filtering_benchmark_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import unittest | ||
|
|
||
| from application.utils.harvester.file_filter import FileFilter | ||
| from application.utils.harvester.filtering_benchmark import FilteringBenchmark | ||
|
|
||
|
|
||
| class FilteringBenchmarkTests(unittest.TestCase): | ||
| def test_filtering_benchmark(self): | ||
| files = [ | ||
| "README.md", | ||
| ".github/workflows/ci.yml", | ||
| "docs/guide.md", | ||
| "image.png", | ||
| "notes.txt", | ||
| "package-lock.json", | ||
| ] | ||
|
|
||
| benchmark = FilteringBenchmark(file_filter=FileFilter()) | ||
|
|
||
| result = benchmark.run(files) | ||
|
|
||
| self.assertEqual(result.total_files, 6) | ||
| self.assertEqual(result.retained_files, 3) | ||
| self.assertEqual(result.filtered_files, 3) | ||
| self.assertEqual(result.retention_rate, 0.5) | ||
| self.assertEqual(result.filtering_rate, 0.5) | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
35 changes: 35 additions & 0 deletions
35
application/tests/harvester_test/filtering_metrics_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import unittest | ||
|
|
||
| from application.utils.harvester.filtering_metrics import ( | ||
| FilteringMetricsCollector, | ||
| ) | ||
|
|
||
|
|
||
| class FilteringMetricsCollectorTests(unittest.TestCase): | ||
| def test_filtering_metrics_collection(self): | ||
| collector = FilteringMetricsCollector() | ||
|
|
||
| collector.record_retained() | ||
| collector.record_retained() | ||
| collector.record_filtered() | ||
|
|
||
| metrics = collector.build() | ||
|
|
||
| self.assertEqual( | ||
| metrics.total_files, | ||
| 3, | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| metrics.retained_files, | ||
| 2, | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| metrics.filtered_files, | ||
| 1, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
22 changes: 22 additions & 0 deletions
22
application/tests/harvester_test/fixtures/duplicate_include_paths.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| repositories: | ||
| - id: duplicate-includes | ||
| type: github | ||
| enabled: true | ||
|
|
||
| owner: OWASP | ||
| repo: ASVS | ||
| branch: master | ||
|
|
||
| paths: | ||
| include: | ||
| - "docs/**/*.md" | ||
| - "docs/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: markdown_heading | ||
| max_tokens: 1200 | ||
| overlap_tokens: 100 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not test exclusion matching because
.ymlis already rejected by the extension allowlist; the combined test has the same problem with.js. Replace excluded examples with allowed documentation extensions so removing exclusion matching would make the test fail, e.g..github/workflows/README.mdandnode_modules/react/README.md. Add focused cases for nested paths, the real**/archive/**custom glob, invalid glob handling, explicit empty exclusions/extensions, and default-instance isolation. Keep extension and path-filter behavior in separate tests so each assertion has one reason to pass.