-
Notifications
You must be signed in to change notification settings - Fork 118
feat: add adapter for CheatSheetRecord and Librarian integration with pipeline dry run #1036
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
Abhijeet2409
wants to merge
12
commits into
OWASP:main
Choose a base branch
from
Abhijeet2409:feature/cheatsheetrecord-librarian-adapter
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
12 commits
Select commit
Hold shift + click to select a range
a3b6315
Add CheatSheetRecord adapter
Abhijeet2409 c810629
feat: add cheat sheet dry-run and golden test cases
Abhijeet2409 6967c3c
test: align committed_at feild with extractor
Abhijeet2409 dc233d5
fix: clarify dry-run summary for stub mismatches
Abhijeet2409 880e784
Merge branch 'main' into feature/cheatsheetrecord-librarian-adapter
Abhijeet2409 ca842e5
test: add test cases for changes in extractor
Abhijeet2409 2c75d55
fix: add CodeRabbit's suggestion
Abhijeet2409 1acf8ac
test: fix committed_at regex to accept Z-suffixed UTC timestamps (CI)
Abhijeet2409 7c40da3
fix: update _get_committed_at() to return empty string on failure
Abhijeet2409 8cf45cb
Merge branch 'main' into feature/cheatsheetrecord-librarian-adapter
Abhijeet2409 646db84
Merge branch 'main' into feature/cheatsheetrecord-librarian-adapter
Abhijeet2409 1b88a70
test: add commited_at feild assertion
Abhijeet2409 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import unittest | ||
|
|
||
| from application.defs.cheatsheet_defs import CheatsheetRecord | ||
| from application.utils.external_project_parsers.parsers.cheatsheet_record_adapter import ( | ||
| MalformedCheatsheetRecordError, | ||
| section_from_cheatsheet_record, | ||
| ) | ||
|
|
||
|
|
||
| class TestSectionFromCheatsheetRecord(unittest.TestCase): | ||
| def test_valid_record_produces_expected_section(self): | ||
| record = CheatsheetRecord( | ||
| source_id="Secrets_Management_Cheat_Sheet", | ||
| title="Secrets Management Cheat Sheet", | ||
| hyperlink="https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html", | ||
| summary="Storage guidance.", | ||
| headings=["Introduction", "Architectural Patterns"], | ||
| raw_markdown_path="cheatsheets/Secrets_Management_Cheat_Sheet.md", | ||
| metadata={ | ||
| "parser_version": "v1", | ||
| "fallback_used": "false", | ||
| "committed_at": "2026-06-14T10:22:03+00:00", | ||
| }, | ||
| ) | ||
|
|
||
| section = section_from_cheatsheet_record(record) | ||
|
|
||
| self.assertEqual( | ||
| section.chunk_id, "chk:owasp_cheatsheets:Secrets_Management_Cheat_Sheet" | ||
| ) | ||
| self.assertEqual( | ||
| section.artifact_id, "art:owasp_cheatsheets:Secrets_Management_Cheat_Sheet" | ||
| ) | ||
| self.assertEqual( | ||
| section.text, "Storage guidance.\nIntroduction\nArchitectural Patterns" | ||
| ) | ||
| self.assertEqual(section.title_hint, "Secrets Management Cheat Sheet") | ||
| self.assertEqual(section.language, "en") | ||
| self.assertEqual( | ||
| str(section.source.url), | ||
| "https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html", | ||
| ) | ||
| self.assertEqual( | ||
| str(section.source.committed_at.isoformat()), "2026-06-14T10:22:03+00:00" | ||
| ) | ||
| self.assertEqual(section.locator.id, "Secrets_Management_Cheat_Sheet") | ||
| self.assertEqual( | ||
| str(section.locator.url), | ||
| "https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html", | ||
| ) | ||
|
|
||
| def test_fallback_title_and_summary_pass_through(self): | ||
| record = CheatsheetRecord( | ||
| source_id="Secrets_Management_Cheat_Sheet", | ||
| title="No title found.", | ||
| hyperlink="https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html", | ||
| summary="No summary found.", | ||
| headings=[], | ||
| raw_markdown_path="cheatsheets/Secrets_Management_Cheat_Sheet.md", | ||
| metadata={ | ||
| "parser_version": "v1", | ||
| "fallback_used": "true", | ||
| "committed_at": "2026-06-14T10:22:03+00:00", | ||
| }, | ||
| ) | ||
|
|
||
| section = section_from_cheatsheet_record(record) | ||
|
|
||
| self.assertEqual(section.title_hint, "No title found.") | ||
| self.assertEqual(section.text, "No summary found.") | ||
|
|
||
| def test_missing_committed_at_raises(self): | ||
| record = CheatsheetRecord( | ||
| source_id="Secrets_Management_Cheat_Sheet", | ||
| title="Secrets Management Cheat Sheet", | ||
| hyperlink="https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html", | ||
| summary="Storage guidance.", | ||
| headings=["Introduction"], | ||
| raw_markdown_path="cheatsheets/Secrets_Management_Cheat_Sheet.md", | ||
| metadata={ | ||
| "parser_version": "v1", | ||
| "fallback_used": "false", | ||
| "committed_at": "", | ||
| }, | ||
| ) | ||
|
|
||
| with self.assertRaises(MalformedCheatsheetRecordError): | ||
| section_from_cheatsheet_record(record) | ||
|
|
||
|
|
||
| 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
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
48 changes: 48 additions & 0 deletions
48
application/utils/external_project_parsers/parsers/cheatsheet_record_adapter.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,48 @@ | ||
| from pydantic import ValidationError | ||
| from application.utils.librarian.section_validator import _DEFAULT_LANGUAGE | ||
| from application.defs.cheatsheet_defs import CheatsheetRecord | ||
| from application.utils.librarian.schemas import ( | ||
| Locator, | ||
| LocatorKind, | ||
| SourceRef, | ||
| SourceType, | ||
| ) | ||
| from application.utils.librarian.section_validator import ( | ||
| Section, | ||
| SectionValidationError, | ||
| ) | ||
|
|
||
|
|
||
| class MalformedCheatsheetRecordError(SectionValidationError): | ||
| pass | ||
|
|
||
|
|
||
| def section_from_cheatsheet_record( | ||
| record: CheatsheetRecord, | ||
| ) -> Section: | ||
| text = "\n".join([record.summary, *record.headings]) | ||
|
|
||
| try: | ||
| source = SourceRef( | ||
| type=SourceType.url, | ||
| url=record.hyperlink, | ||
| committed_at=record.metadata.get("committed_at"), | ||
| ) | ||
|
|
||
| locator = Locator( | ||
| kind=LocatorKind.url, | ||
| id=record.source_id, | ||
| url=record.hyperlink, | ||
| ) | ||
| except ValidationError as exc: | ||
| raise MalformedCheatsheetRecordError(str(exc)) from exc | ||
|
|
||
| return Section( | ||
| artifact_id=f"art:{record.source}:{record.source_id}", | ||
| chunk_id=f"chk:{record.source}:{record.source_id}", | ||
|
Abhijeet2409 marked this conversation as resolved.
|
||
| text=text, | ||
| title_hint=record.title, | ||
| language=_DEFAULT_LANGUAGE, | ||
| source=source, | ||
| locator=locator, | ||
| ) | ||
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.