-
Notifications
You must be signed in to change notification settings - Fork 119
GSoC Module_A-week6: feat(harvester): add RFC document data models and artifact.py #1029
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
7
commits into
OWASP:main
Choose a base branch
from
ParthAggarwal16:week_6-document-builder
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
7 commits
Select commit
Hold shift + click to select a range
cf1a065
feat(harvester): add git diff retrieval pipeline
ParthAggarwal16 c815d12
Enhance diff pipeline with metadata and normalization
ParthAggarwal16 180dd8e
feat(harvester): add RFC document data models and artifact.py
ParthAggarwal16 7e572f0
feat(harvester): read files from repository commits
ParthAggarwal16 eed7d37
feat(harvester): extract markdown heading hierarchy
ParthAggarwal16 2aa99d7
feat(harvester): build structured document objects
ParthAggarwal16 3b89e67
feat(harvester): validate structured documents
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
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
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,65 @@ | ||
| import unittest | ||
| from datetime import datetime | ||
|
|
||
| from application.utils.harvester.document_builder import ( | ||
| DocumentBuilder, | ||
| ) | ||
| from application.utils.harvester.models import ( | ||
| DiffBlock, | ||
| ) | ||
|
|
||
|
|
||
| class DocumentBuilderTests(unittest.TestCase): | ||
| def test_build_document(self): | ||
| block = DiffBlock( | ||
| file_path="README.md", | ||
| repository="OWASP/ASVS", | ||
| commit_sha="abc123", | ||
| committed_at=datetime.now(), | ||
| added_lines=["Hello"], | ||
| ) | ||
|
|
||
| document = DocumentBuilder().build( | ||
| block, | ||
| "# Title\n\nHello", | ||
| pipeline_run_id="20260714T120000Z", | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| document.schema_version, | ||
| "0.2.0", | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| document.artifact_id, | ||
| "art:OWASP/ASVS:README.md", | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| document.pipeline_run_id, | ||
| "20260714T120000Z", | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| document.text, | ||
| "# Title\n\nHello", | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| document.source.repository, | ||
| "OWASP/ASVS", | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| document.locator.path, | ||
| "README.md", | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| len(document.heading_structure), | ||
| 1, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
85 changes: 85 additions & 0 deletions
85
application/tests/harvester_test/document_validator_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,85 @@ | ||
| import unittest | ||
| from datetime import datetime | ||
|
|
||
| from application.utils.harvester.document_validator import ( | ||
| DocumentValidator, | ||
| ) | ||
| from application.utils.harvester.models import ( | ||
| Document, | ||
| HeadingNode, | ||
| Locator, | ||
| SourceInfo, | ||
| ) | ||
|
|
||
|
|
||
| def make_document() -> Document: | ||
| return Document( | ||
| schema_version="0.2.0", | ||
| artifact_id="art:OWASP/ASVS:README.md", | ||
| pipeline_run_id="20260714T120000Z", | ||
| text="# Title", | ||
| source=SourceInfo( | ||
| type="github", | ||
| repository="OWASP/ASVS", | ||
| commit_sha="abc123", | ||
| committed_at=datetime.now(), | ||
| ), | ||
| locator=Locator( | ||
| kind="repo_path", | ||
| id="README.md", | ||
| path="README.md", | ||
| ), | ||
| heading_structure=[ | ||
| HeadingNode( | ||
| level=1, | ||
| text="Title", | ||
| start_line=1, | ||
| end_line=1, | ||
| ) | ||
| ], | ||
| span=None, | ||
| ) | ||
|
|
||
|
|
||
| class DocumentValidatorTests(unittest.TestCase): | ||
| def test_valid_document(self): | ||
| validator = DocumentValidator() | ||
|
|
||
| self.assertTrue(validator.validate(make_document())) | ||
|
|
||
| def test_missing_artifact_id(self): | ||
| validator = DocumentValidator() | ||
|
|
||
| document = make_document() | ||
| document.artifact_id = "" | ||
|
|
||
| self.assertFalse(validator.validate(document)) | ||
|
|
||
| def test_missing_text(self): | ||
| validator = DocumentValidator() | ||
|
|
||
| document = make_document() | ||
| document.text = "" | ||
|
|
||
| self.assertFalse(validator.validate(document)) | ||
|
|
||
| def test_invalid_source_type(self): | ||
| validator = DocumentValidator() | ||
|
|
||
| document = make_document() | ||
| document.source.type = "gitlab" | ||
|
|
||
| self.assertFalse(validator.validate(document)) | ||
|
|
||
| def test_non_markdown_document_is_valid(self): | ||
| validator = DocumentValidator() | ||
|
|
||
| document = make_document() | ||
| document.heading_structure = [] | ||
| document.text = '{"hello": "world"}' | ||
|
|
||
| self.assertTrue(validator.validate(document)) | ||
|
|
||
|
|
||
| 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
107 changes: 107 additions & 0 deletions
107
application/tests/harvester_test/heading_extractor_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,107 @@ | ||
| import unittest | ||
|
|
||
| from application.utils.harvester.heading_extractor import ( | ||
| HeadingExtractor, | ||
| ) | ||
|
|
||
|
|
||
| class HeadingExtractorTests(unittest.TestCase): | ||
| def test_single_heading(self): | ||
| text = """ | ||
| # Title | ||
|
|
||
| Hello | ||
|
|
||
| World | ||
| """ | ||
|
|
||
| headings = HeadingExtractor().extract(text) | ||
|
|
||
| self.assertEqual(len(headings), 1) | ||
|
|
||
| self.assertEqual(headings[0].text, "Title") | ||
| self.assertEqual(headings[0].level, 1) | ||
| self.assertEqual(headings[0].start_line, 2) | ||
|
|
||
| def test_nested_headings(self): | ||
| text = """ | ||
| # Root | ||
|
|
||
| ## Child One | ||
|
|
||
| content | ||
|
|
||
| ## Child Two | ||
|
|
||
| more | ||
|
|
||
| # Second Root | ||
| """ | ||
|
|
||
| headings = HeadingExtractor().extract(text) | ||
|
|
||
| self.assertEqual(len(headings), 4) | ||
|
|
||
| self.assertEqual(headings[0].text, "Root") | ||
| self.assertEqual(headings[1].text, "Child One") | ||
| self.assertEqual(headings[2].text, "Child Two") | ||
| self.assertEqual(headings[3].text, "Second Root") | ||
|
|
||
| def test_heading_ranges(self): | ||
| text = """ | ||
| # Root | ||
|
|
||
| text | ||
|
|
||
| ## Child | ||
|
|
||
| child | ||
|
|
||
| # Next | ||
| """ | ||
|
|
||
| headings = HeadingExtractor().extract(text) | ||
| self.assertEqual(headings[0].end_line, 9) | ||
| self.assertEqual(headings[1].end_line, 9) | ||
| self.assertEqual(headings[2].end_line, 10) | ||
|
|
||
| def test_ignore_non_headings(self): | ||
| text = """ | ||
| Hello | ||
|
|
||
| ###Heading | ||
|
|
||
| ####NoSpace | ||
|
|
||
| ## Valid Heading | ||
| """ | ||
|
|
||
| headings = HeadingExtractor().extract(text) | ||
| self.assertEqual(len(headings), 1) | ||
| self.assertEqual(headings[0].text, "Valid Heading") | ||
|
|
||
| def test_heading_stops_at_same_level(self): | ||
| text = """ | ||
| # Root | ||
|
|
||
| ## A | ||
|
|
||
| ### X | ||
|
|
||
| ## B | ||
|
|
||
| content | ||
| """ | ||
|
|
||
| headings = HeadingExtractor().extract(text) | ||
|
|
||
| self.assertEqual(headings[1].text, "A") | ||
| self.assertEqual(headings[2].text, "X") | ||
| self.assertEqual(headings[3].text, "B") | ||
|
|
||
| self.assertEqual(headings[1].end_line, 7) | ||
| self.assertEqual(headings[2].end_line, 7) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Make this benchmark independent of the local cache.
The test never synchronizes the repository. In a clean CI workspace,
git -C .harvester_cache/owasp/asvs/master diff ...fails before the timing assertion. Use a local fixture repository or mocked Git output. If this must contact OWASP/ASVS, move it to an explicit opt-in integration suite.🤖 Prompt for AI Agents