Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
aed4fe6
feat(harvester): implement repository configuration loader
ParthAggarwal16 May 27, 2026
f370f73
fix(harvester): address CodeRabbit validation feedback
ParthAggarwal16 May 29, 2026
9478e54
feat(harvester): add repository config loader and validation
ParthAggarwal16 May 31, 2026
43fb6cb
addressing coderabbit
ParthAggarwal16 May 31, 2026
b962246
addressing coderabbit again
ParthAggarwal16 May 31, 2026
b556308
Add repository validation rules and fixtures
ParthAggarwal16 May 31, 2026
fc4b583
normalize repository ids during validation
ParthAggarwal16 May 31, 2026
713f99d
Refine harvester validation exports and YAML fixtures
ParthAggarwal16 Jun 2, 2026
c7ecbf0
removed stable dev comments
ParthAggarwal16 Jun 7, 2026
0be6df8
Add validator success test and clean exports
ParthAggarwal16 Jun 7, 2026
f96ff3d
Merge branch 'main' into week_1-2-harvester-validation-and-docs
ParthAggarwal16 Jul 2, 2026
c728fed
test(harvester): align tests with project conventions
ParthAggarwal16 Jul 2, 2026
d4e7731
chore: ignore Claude and Cursor project files
ParthAggarwal16 Jul 3, 2026
f11f869
refactor(harvester): address review feedback
ParthAggarwal16 Jul 3, 2026
fbc6e20
Add repository synchronization foundation
ParthAggarwal16 Jun 10, 2026
29fec6a
Addressing coderabbit and adding couple of extra gaurdrails
ParthAggarwal16 Jun 10, 2026
2783023
Addressing coderabbit final
ParthAggarwal16 Jun 10, 2026
721afa8
test(harvester): align week 2 tests with project conventions
ParthAggarwal16 Jul 6, 2026
1738cb4
fix(harvester): address repository client review feedback
ParthAggarwal16 Jul 18, 2026
fee277f
feat(harvester): implement incremental change detection
ParthAggarwal16 Jul 8, 2026
ccb515a
fix(harvester): write checkpoints atomically
ParthAggarwal16 Jul 18, 2026
853f34e
feat(harvester): implement repository file filtering
ParthAggarwal16 Jul 8, 2026
10b8f2f
fix(harvester): improve filtering benchmark and sync behavior
ParthAggarwal16 Jul 18, 2026
5f8c5f3
feat(harvester): add git diff retrieval pipeline
ParthAggarwal16 Jul 10, 2026
6f6bd22
feat(harvester): parse unified git diffs
ParthAggarwal16 Jul 10, 2026
d3f5917
feat(harvester): normalize extracted diff content
ParthAggarwal16 Jul 10, 2026
fde38f5
Enhance diff pipeline with metadata and normalization
ParthAggarwal16 Jul 10, 2026
8dea1c7
fix(harvester): address review feedback
ParthAggarwal16 Jul 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ tmp/
cres/*
### Local project management tooling
project management scripts/

.harvester_cache/
3 changes: 3 additions & 0 deletions application/tests/harvester_test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
tests for Module A configuration layer (empty for now)
"""
52 changes: 52 additions & 0 deletions application/tests/harvester_test/change_detector_test.py
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()
92 changes: 92 additions & 0 deletions application/tests/harvester_test/checkpoint_store_test.py
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()
63 changes: 63 additions & 0 deletions application/tests/harvester_test/config_loader_test.py
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()
117 changes: 117 additions & 0 deletions application/tests/harvester_test/diff_normalizer_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import unittest
from datetime import datetime

from application.utils.harvester.diff_normalizer import (
DiffNormalizer,
)

from application.utils.harvester.models import (
DiffBlock,
)


DIFF_METADATA = {
"repository": "OWASP/ASVS",
"commit_sha": "abc123",
"committed_at": datetime(2026, 1, 1),
}


class DiffNormalizerTests(unittest.TestCase):
def test_whitespace_normalization(self):
normalizer = DiffNormalizer()

blocks = [
DiffBlock(
file_path="README.md",
added_lines=[
" Hello World ",
"\t\tTabs\t\tEverywhere\t",
"",
" ",
"Unicode\u00a0Space",
"Mix\t of\t tabs and spaces",
" Multiple words together ",
"\u00a0\u00a0Leading unicode spaces\u00a0",
" ## Authentication ",
" - Use MFA ",
" `inline code` ",
" **Important** ",
],
**DIFF_METADATA,
)
]

result = normalizer.normalize(blocks)

self.assertEqual(
result[0].added_lines,
[
"Hello World",
"Tabs Everywhere",
"Unicode Space",
"Mix of tabs and spaces",
"Multiple words together",
"Leading unicode spaces",
"## Authentication",
"- Use MFA",
"`inline code`",
"**Important**",
],
)

def test_remove_empty_lines(self):
normalizer = DiffNormalizer()

blocks = [
DiffBlock(
file_path="README.md",
added_lines=[
"",
" ",
"Hello",
],
**DIFF_METADATA,
)
]

result = normalizer.normalize(blocks)

self.assertEqual(
result[0].added_lines,
[
"Hello",
],
)

def test_multiple_blocks(self):
normalizer = DiffNormalizer()

blocks = [
DiffBlock(
file_path="a.md",
added_lines=[" One "],
**DIFF_METADATA,
),
DiffBlock(
file_path="b.md",
added_lines=[" Two "],
**DIFF_METADATA,
),
]

result = normalizer.normalize(blocks)

self.assertEqual(
result[0].added_lines,
["One"],
)

self.assertEqual(
result[1].added_lines,
["Two"],
)


if __name__ == "__main__":
unittest.main()
Loading
Loading