-
Notifications
You must be signed in to change notification settings - Fork 118
GSOC-Week1-Module_A #920
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
10
commits into
OWASP:main
Choose a base branch
from
ParthAggarwal16:week_1-2-harvester-validation-and-docs
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
GSOC-Week1-Module_A #920
Changes from all commits
Commits
Show all changes
10 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 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) | ||
| """ |
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 | ||
| max_tokens: 1200 | ||
| overlap_tokens: 100 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 |
34 changes: 34 additions & 0 deletions
34
application/tests/harvester_test/fixtures/duplicate_repo_ids.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,34 @@ | ||
| repositories: | ||
| - id: asvs | ||
| type: github | ||
| owner: OWASP | ||
| repo: ASVS | ||
|
|
||
| paths: | ||
| include: | ||
| - "4.0/en/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: markdown | ||
| max_tokens: 1200 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 | ||
|
|
||
| - id: asvs | ||
| type: github | ||
| owner: OWASP | ||
| repo: CheatSheetSeries | ||
|
|
||
| paths: | ||
| include: | ||
| - "cheatsheets/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: markdown | ||
| max_tokens: 1200 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 |
34 changes: 34 additions & 0 deletions
34
application/tests/harvester_test/fixtures/duplicate_repositories.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,34 @@ | ||
| repositories: | ||
| - id: asvs-1 | ||
| type: github | ||
| owner: OWASP | ||
| repo: ASVS | ||
|
|
||
| paths: | ||
| include: | ||
| - "4.0/en/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: markdown | ||
| max_tokens: 1200 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 | ||
|
|
||
| - id: asvs-2 | ||
| type: github | ||
| owner: OWASP | ||
| repo: ASVS | ||
|
|
||
| paths: | ||
| include: | ||
| - "4.0/en/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: markdown | ||
| max_tokens: 1200 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 |
16 changes: 16 additions & 0 deletions
16
application/tests/harvester_test/fixtures/empty_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,16 @@ | ||
| repositories: | ||
| - id: asvs | ||
| type: github | ||
| owner: OWASP | ||
| repo: ASVS | ||
|
|
||
| paths: | ||
| include: [] | ||
|
|
||
| chunking: | ||
| strategy: markdown | ||
| max_tokens: 1200 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 |
21 changes: 21 additions & 0 deletions
21
application/tests/harvester_test/fixtures/empty_owner.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,21 @@ | ||
| repositories: | ||
| - id: empty-owner | ||
| type: github | ||
| enabled: true | ||
|
|
||
| owner: "" | ||
| repo: ASVS | ||
| branch: master | ||
|
|
||
| paths: | ||
| include: | ||
| - "docs/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: markdown | ||
| max_tokens: 1200 | ||
| overlap_tokens: 100 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 |
18 changes: 18 additions & 0 deletions
18
application/tests/harvester_test/fixtures/invalid_chunk_size.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,18 @@ | ||
| repositories: | ||
| - id: owasp-asvs | ||
|
|
||
| type: github | ||
| owner: OWASP | ||
| repo: ASVS | ||
|
|
||
| paths: | ||
| include: | ||
| - "4.0/en/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: markdown | ||
| max_tokens: 0 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 |
21 changes: 21 additions & 0 deletions
21
application/tests/harvester_test/fixtures/invalid_chunking_strategy.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,21 @@ | ||
| repositories: | ||
| - id: invalid-strategy | ||
| type: github | ||
| enabled: true | ||
|
|
||
| owner: OWASP | ||
| repo: ASVS | ||
| branch: master | ||
|
|
||
| paths: | ||
| include: | ||
| - "docs/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: invalid_strategy | ||
| max_tokens: 1200 | ||
| overlap_tokens: 100 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 |
17 changes: 17 additions & 0 deletions
17
application/tests/harvester_test/fixtures/invalid_missing_id.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,17 @@ | ||
| repositories: | ||
| - type: github | ||
|
|
||
| owner: OWASP | ||
| repo: ASVS | ||
|
|
||
| paths: | ||
| include: | ||
| - "4.0/en/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: markdown | ||
| max_tokens: 1200 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 |
17 changes: 17 additions & 0 deletions
17
application/tests/harvester_test/fixtures/invalid_polling_interval.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,17 @@ | ||
| repositories: | ||
| - id: asvs | ||
| type: github | ||
| owner: OWASP | ||
| repo: ASVS | ||
|
|
||
| paths: | ||
| include: | ||
| - "4.0/en/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: markdown | ||
| max_tokens: 1200 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 0 |
21 changes: 21 additions & 0 deletions
21
application/tests/harvester_test/fixtures/invalid_polling_mode.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,21 @@ | ||
| repositories: | ||
| - id: invalid-polling | ||
| type: github | ||
| enabled: true | ||
|
|
||
| owner: OWASP | ||
| repo: ASVS | ||
| branch: master | ||
|
|
||
| paths: | ||
| include: | ||
| - "docs/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: markdown | ||
| max_tokens: 1200 | ||
| overlap_tokens: 100 | ||
|
|
||
| polling: | ||
| mode: realtime | ||
| interval_minutes: 60 |
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,4 @@ | ||
| repositories: | ||
| - id: broken | ||
| paths: | ||
| include: [unclosed |
16 changes: 16 additions & 0 deletions
16
application/tests/harvester_test/fixtures/valid_repos.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,16 @@ | ||
| repositories: | ||
| - id: owasp-asvs | ||
| type: github | ||
| owner: OWASP | ||
| repo: ASVS | ||
| paths: | ||
| include: | ||
| - "4.0/en/**/*.md" | ||
|
|
||
| chunking: | ||
| strategy: markdown | ||
| max_tokens: 1200 | ||
|
|
||
| polling: | ||
| mode: incremental | ||
| interval_minutes: 60 |
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,75 @@ | ||
| from pathlib import Path | ||
| import pytest | ||
| from application.utils.harvester.config_loader import ( | ||
| ConfigLoaderError, | ||
| load_repo_config, | ||
| ) | ||
|
|
||
| FIXTURES_DIR = Path(__file__).parent / "fixtures" | ||
|
|
||
|
|
||
| def test_load_valid_config(): | ||
| config_path = FIXTURES_DIR / "valid_repos.yaml" | ||
|
|
||
| config = load_repo_config(config_path) | ||
|
|
||
| assert len(config.repositories) == 1 | ||
|
|
||
| repo = config.repositories[0] | ||
|
|
||
| assert repo.id == "owasp-asvs" | ||
| assert repo.owner == "OWASP" | ||
| assert repo.repo == "ASVS" | ||
|
|
||
|
|
||
| def test_missing_repository_id(): | ||
| config_path = FIXTURES_DIR / "invalid_missing_id.yaml" | ||
| with pytest.raises(ConfigLoaderError): | ||
| load_repo_config(config_path) | ||
|
|
||
|
|
||
| def test_invalid_chunk_size(): | ||
| config_path = FIXTURES_DIR / "invalid_chunk_size.yaml" | ||
| with pytest.raises(ConfigLoaderError, match="max_tokens"): | ||
| load_repo_config(config_path) | ||
|
|
||
|
|
||
| def test_invalid_yaml_syntax(): | ||
| config_path = FIXTURES_DIR / "invalid_yaml.yaml" | ||
| with pytest.raises(ConfigLoaderError): | ||
| load_repo_config(config_path) | ||
|
|
||
|
|
||
| def test_missing_config_file(): | ||
| with pytest.raises(FileNotFoundError): | ||
| load_repo_config("does_not_exist.yaml") | ||
|
|
||
|
|
||
| def test_empty_owner(): | ||
| config_path = FIXTURES_DIR / "empty_owner.yaml" | ||
|
|
||
| with pytest.raises( | ||
| ConfigLoaderError, | ||
| match="owner", | ||
| ): | ||
| load_repo_config(config_path) | ||
|
|
||
|
|
||
| def test_invalid_chunking_strategy(): | ||
| config_path = FIXTURES_DIR / "invalid_chunking_strategy.yaml" | ||
|
|
||
| with pytest.raises( | ||
| ConfigLoaderError, | ||
| match="strategy", | ||
| ): | ||
| load_repo_config(config_path) | ||
|
|
||
|
|
||
| def test_invalid_polling_mode(): | ||
| config_path = FIXTURES_DIR / "invalid_polling_mode.yaml" | ||
|
|
||
| with pytest.raises( | ||
| ConfigLoaderError, | ||
| match="mode", | ||
| ): | ||
| load_repo_config(config_path) |
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,53 @@ | ||
| from pathlib import Path | ||
| import pytest | ||
| from application.utils.harvester.config_loader import ( | ||
| load_repo_config, | ||
| ) | ||
| from application.utils.harvester.repos_validator import ( | ||
| RepositoryValidationError, | ||
| validate_repositories, | ||
| ) | ||
|
|
||
| FIXTURES_DIR = Path(__file__).parent / "fixtures" | ||
|
|
||
|
|
||
| def test_duplicate_repository_ids(): | ||
| config_path = FIXTURES_DIR / "duplicate_repo_ids.yaml" | ||
|
|
||
| config = load_repo_config(config_path) | ||
|
|
||
| with pytest.raises( | ||
| RepositoryValidationError, | ||
| match="Duplicate repository id", | ||
| ): | ||
| validate_repositories(config) | ||
|
|
||
|
|
||
| def test_duplicate_repositories(): | ||
| config_path = FIXTURES_DIR / "duplicate_repositories.yaml" | ||
| config = load_repo_config(config_path) | ||
|
|
||
| with pytest.raises( | ||
| RepositoryValidationError, | ||
| match="Duplicate repository detected", | ||
| ): | ||
| validate_repositories(config) | ||
|
|
||
|
|
||
| def test_duplicate_include_paths(): | ||
| config_path = FIXTURES_DIR / "duplicate_include_paths.yaml" | ||
| config = load_repo_config(config_path) | ||
|
|
||
| with pytest.raises( | ||
| RepositoryValidationError, | ||
| match="duplicate include paths", | ||
| ): | ||
| validate_repositories(config) | ||
|
|
||
|
|
||
| def test_validate_valid_repositories(): | ||
| config_path = FIXTURES_DIR / "valid_repos.yaml" | ||
|
|
||
| config = load_repo_config(config_path) | ||
|
|
||
| validate_repositories(config) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.