Conversation
|
@parthrohit22 , @ritiksah141 - assigning the review to u both, seems like you are the code owners and do know the codebase well and what value add this brings in, please do touch base with this. |
|
Container scan - Broken CI, the push for the fix has been done to dev which triggers in the next commit, hence go ahead without minding that CI response. |
ritiksah141
left a comment
There was a problem hiding this comment.
I pulled the branch and reviewed it against the current architecture and latest dev. All 72 added tests pass, ruff passes, and the branch has no merge conflicts. The earlier Trivy failure is not part of this review, as requested in the PR discussion.
I found three coverage gaps that should be corrected before approval:
- The score tests reproduce arithmetic locally instead of executing DatabaseManager.get_score(), so regressions in production SQL aggregation and floor handling would not be detected.
- The Sentinel retry tests only assert the final False result and do not prove that three attempts occurred.
- The RAG chunking tests pass a chunk_overlap value but never verify overlap behavior.
Please also update the PR description because Closes #174 refers to this pull request itself rather than a related issue.
| class TestScoreCalculation: | ||
| """Tests for score calculation logic.""" | ||
|
|
||
| def test_score_starts_at_100(self): |
There was a problem hiding this comment.
These tests recreate the scoring arithmetic inside the test instead of calling DatabaseManager.get_score(). A regression in the query aggregation or the production floor logic would still pass. Please mock the connection rows and assert results returned by db.get_score(). Also add coverage for at least one persistence method or narrow the stated CRUD scope, since _make_db is currently unused.
| with patch("requests.post", return_value=mock_response): | ||
| with patch("time.sleep"): | ||
| result = ingest.send([ingest.normalise(RAW_FINDING, "scan-001")]) | ||
| assert result is False |
There was a problem hiding this comment.
This only verifies the final False result. It would still pass if send() stopped retrying after one request. Keep the requests.post mock and assert call_count == 3. The exception path should make the same assertion so the claimed retry behavior is protected.
| long_content = "word " * 300 | ||
| docs = [self._make_doc(long_content)] | ||
| chunks = chunk_documents(docs, chunk_size=100, chunk_overlap=10) | ||
| assert len(chunks) > 1 |
There was a problem hiding this comment.
The PR says chunk overlap is covered, but this assertion only proves that a long document creates multiple chunks. Please assert that adjacent chunk contents contain the requested overlap, or adjust the stated coverage scope.
m-khan-97
left a comment
There was a problem hiding this comment.
Went through this against the actual source for the three areas Ritik flagged, since I wanted to confirm they're real before piling on rather than just trusting the summary. All three check out:
- Score tests never call the real code path.
TestScoreCalculationintest_database_manager.pyreproduces the arithmetic inline (score -= SEVERITY_WEIGHTS["HIGH"]) instead of callingDatabaseManager.get_score(). A bug in the actual SQL aggregation/floor logic would sail through untouched. - Sentinel retry tests don't verify retry count. I checked
sentinel/ingest.py:64—send()genuinely doesfor attempt in range(1, 4)(3 attempts). Buttest_send_returns_false_after_retriesandtest_send_retries_on_exceptiononly assert the finalFalse, nevermock_post.call_count == 3. Change that loop torange(1, 2)and both tests would still pass. - Chunk overlap is asserted by count, not content. Confirmed in
ai/chunker.py:51—chunk_overlapdirectly controlsstart = split_pos - chunk_overlapfor the next chunk. None of the chunker tests check that consecutive chunks actually share the expected overlapping text; they only check chunk count andchunk_indexpresence.
Agreeing with Ritik's request for changes on this basis — the coverage numbers are real (72 tests, all passing), but for the specific claims this PR makes (CI-001 through CI-004 "closed"), these three gaps mean the corresponding regressions could land undetected. Worth fixing before merge rather than as a fast-follow, since the whole point of this PR is closing coverage gaps precisely so regressions get caught.
One separate housekeeping item, also from Ritik's review and still true: the PR description says "Closes #174" but #174 is this PR's own tracking issue for the coverage gaps — please point it at the actual issue number if there is one, or drop the auto-close keyword if #174 is just this PR.
Nice test for the HMAC signature itself, by the way — test_build_signature_uses_hmac_sha256 independently recomputes the expected signature and compares against the real function's output rather than mocking it away. That's the right pattern; would be good to see the retry-count and chunk-overlap tests follow the same approach.
|
@emon22-ts , there are quite some changes to be done, please do touch base with this PR. |
parthrohit22
left a comment
There was a problem hiding this comment.
I reviewed PR #174 against its four changed test files, the existing review threads, and the underlying testing requirements in issue #153.
I agree with @ritiksah141’s three unresolved findings, which @m-khan-97 also independently confirmed:
- The score tests reproduce the arithmetic instead of calling
DatabaseManager.get_score(). - The Sentinel tests assert only the final
Falseresult and do not prove that all three retry attempts occur. - The chunker tests verify the number of chunks but not the configured overlap between adjacent chunks.
I will not repeat those inline comments. I found two additional coverage gaps:
- Issue #153 explicitly identifies
ai/embed.pyas part of the untested RAG pipeline, but this PR does not testbuild_vectorstore()or the vector-store creation path. - The drift, resources, and prioritization success tests use empty database results and assert only
200/JSON. Their main comparison, aggregation, ranking, and response-mapping behavior is therefore not exercised.
The DatabaseManager concern is particularly important: this PR’s current head contains a duplicated GROUP BY severity inside get_score(), while all the new tests still pass because none execute the real method. This defect is inherited from the older base rather than introduced by this PR, and updating the branch from current dev should incorporate its correction. A real get_score() test should nevertheless be added to prevent recurrence.
The HMAC-SHA256 test is well designed and independently verifies the production function. Most CI checks are green, and I am not attributing the acknowledged Trivy failure to this PR.
Before approval, please:
- Address the three existing unresolved review threads.
- Add non-empty success-path tests for drift, resources, and prioritization.
- Add mocked coverage for
ai/embed.py. - Update the branch from
devand rerun CI. - Correct the related issue reference:
Closes #174currently refers to this pull request itself; the matching OpenShield testing issue is #153. - Correct the per-file test counts to 20 DatabaseManager, 20 API route, 13 Sentinel, and 19 RAG tests, which total the stated 72.
Requesting changes until the claimed coverage gaps and the underlying acceptance criteria are fully addressed.
TFT444
left a comment
There was a problem hiding this comment.
@emon22-ts fix the following changes. they asking for
Vishnu2707
left a comment
There was a problem hiding this comment.
This PR is in an idle state, the contributor hasn't responded yet.
I'll takeover from the same branch remotely , expect updated pr within 12 hours, Thank you. |
|
Hi i will do the changes that are required and really sorry i was busy with my personal stuff |
|
Hi, all review feedback addressed:
80 tests passing, ruff check and ruff format both clean. Ready for re-review. Thank you! @Vishnu2707 @parthrohit22 @ritiksah141 @TFT444 @m-khan-97 |
parthrohit22
left a comment
There was a problem hiding this comment.
Thanks for addressing the earlier feedback. I re-reviewed commit d1a2c3d against the current test files and production implementations.
The DatabaseManager.get_score() tests now execute the real method with mocked query rows, and the Sentinel retry tests correctly verify three attempts and early exit after success. Those points are resolved.
A few blockers remain before approval:
- Update the branch from dev. The PR is currently 26 commits behind, and its inherited get_score() SQL still contains a duplicated GROUP BY severity. Current dev already contains the correction. Please rebase or merge dev and rerun CI.
- Add non-empty success-path coverage for drift, resources and prioritization. These tests remain unchanged: they use empty query results and assert only 200/JSON. They do not exercise drift comparison, resource aggregation/risk mapping, prioritization scoring, sorting or response construction.
- Make the overlap assertion deterministic. The new overlap test uses repetitive content and accepts any matching suffix, so it can pass even with chunk_overlap=0. Use unique input and assert the exact configured overlap between adjacent chunks.
- Strengthen the build_vectorstore() success test. It currently catches and ignores all exceptions and only asserts load_all_documents() was called. Remove the catch-all and verify collection creation, add() calls, final rename through modify(), and the returned chunk count.
- Update the PR description. It still references Closes #174 and retains the old test counts. The related testing issue is #153; since it is already closed, Refs #153 would be clearer.
Requesting changes until these items are addressed. The current CI run is green, but it must be rerun after synchronising the branch with dev.
|
hey @parthrohit22 it will be done soon in next 12 hours . |
d1a2c3d to
b580064
Compare
|
Hi @parthrohit22 @ritiksah141 , all review feedback addressed: 1.Fixed prioritization test mocks — _make_prioritization_db now uses a single cursor with fetchone.side_effect for the two sequential fetchone() calls (scan_id, then total count), matching the route's actual single-cursor query pattern 2.Added missing resource_name field to high_rule/low_rule fixtures in test_prioritization_high_severity_ranked_first, which the route reads unconditionally 3.Fixed Python 3.9 compatibility crash in cbom.py — added from future import annotations to support the Dict[str, Any] | None union syntax (PEP 604), which was breaking create_app() for the entire test suite 4.Fixed lint failures — added trailing newline to test_api_routes.py (W292) and ran ruff format on cbom.py and test_api_routes.py 24 tests passing, ruff check and ruff format both clean, all CI jobs green. |
parthrohit22
left a comment
There was a problem hiding this comment.
Reviewed the PR end-to-end — commits, changed files, and mapped everything back to issue #153. All four coverage gaps (CI-001 → CI-004) are addressed, the tests were verified against the actual source (get_score() weights/floor, build_signature() HMAC-SHA256, normalise() severity map + defaults, send() 3-attempt retry), the cbom.py from future import annotations is a legitimate and necessary Python 3.9 compat fix, and CI is fully green (19/19).
Thanks a lot @emon22-ts for turning this around and addressing every piece of review feedback — the score tests now exercise the real DatabaseManager.get_score() via a mocked cursor instead of re-implementing the arithmetic, the sentinel retry tests assert call_count == 3 (plus the early-exit-on-success case), and the chunker tests now verify actual shared overlap content between adjacent chunks. All three of the earlier review threads are genuinely resolved in code. 🙌
A couple of non-blocking nits I'll defer to @Vishnu2707 as maintainer, since the merge decision is yours:
_make_db() in test_database_manager.py is still unused — either wire it into a persistence-method test or drop it.
The test_database_manager.py docstring mentions "CRUD" but there's no actual CRUD/persistence-method test — worth trimming the docstring or adding one small insert/save test to match scope.
Neither of these blocks the merge in my view — happy to see them handled in a follow-up if you'd prefer to keep this one moving. @Vishnu2707 over to you on whether to merge as-is or fold the nits in first.
Thanks @parthrohit22 for the initial review. The two nits, unused _make_db and the CRUD docstring, are fine as follow up work, as you said these are something that is not blocking the merge. But going back to your previous checks, you'd asked for non empty success path tests for drift, resources and prioritization. Only prioritization actually got that fix, drift and resources are still empty. I wanna make sure that's properly closed before merge since it was a specific ask, not just the nits i guess! |
e9fca90 to
0f8a788
Compare
|
Hi @Vishnu2707 @parthrohit22 @m-khan-97 @TFT444 , all items addressed plus fixes for the OWASP repo changes:
Also fixed for OWASP repo changes:
71 tests passing, ruff clean. Ready for final review. Thank you. |
parthrohit22
left a comment
There was a problem hiding this comment.
Thank you @emon22-ts for the updates and for addressing the earlier coverage feedback.
Problem with current approach
One issue remains: test_normalise_unknown_severity_raises_validation_error passes whether normalise() raises or not. The broad exception handler and or raised condition mean it does not protect the invalid-severity validation path.
Correct approach
Use pytest.raises(ValidationError, match="severity") around the normalise() call and remove the broad exception handling.
Implementation steps
Please make this assertion explicit and rerun the backend test suite.
Risks / edge cases
Without this, a regression that accepts or silently remaps an unknown severity can pass CI and affect Sentinel finding risk accuracy.
Verified: the current GitHub checks are green, including backend tests, CodeQL, dependency review, and security scans.
|
Hi @Vishnu2707 @parthrohit22 @m-khan-97 @TFT444 Ready for final review. Thank you. |
TFT444
left a comment
There was a problem hiding this comment.
Re-reviewed. Both fixes are in: test_normalise_unknown_severity_raises_validation_error now uses pytest.raises(ValidationError, match='severity') correctly, and the drift test asserts exact added == 1 / removed == 1 values with specific rule IDs. Approved.
parthrohit22
left a comment
There was a problem hiding this comment.
Thanks for the thorough work on expanding coverage, and for addressing the earlier review feedback. The Sentinel retry and validation assertions, along with the drift/resource scenarios, are much stronger now.
I found a few remaining items that need to be addressed before I can approve:
-
In
test_rag_pipeline.py,test_build_vectorstore_calls_load_all_documentscatches every exception and only patchesVECTORSTORE_DIR. The implementation writes throughINDEX_PATHusingPath.write_text(), so the current mocks do not isolate the write. Please patch both paths to a temporary directory and remove the broad exception handler so an index-write failure cannot pass silently. -
The compliance route tests currently only assert a
200response, and the shared mock returns a CIS payload for every framework. Please assert thatget_compliance_score()receives the requested framework and validate the corresponding response payload for every supported framework. -
api/routes/cbom.pyis still changed, although this PR is intended to be test-only and the description states that the CBOM change was removed. Please revert this unrelated import.
Once these are addressed and the backend test suite is rerun, I’m happy to re-review.
|
It will be done by today . Thanks
Sent from Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: PARTH ROHIT ***@***.***>
Sent: Friday, 18 September 2026 12:52:46
To: OWASP/openshield ***@***.***>
Cc: Mahfuzur Rahman Emon ***@***.***>; Mention ***@***.***>
Subject: Re: [OWASP/openshield] Test: Add missing coverage for DatabaseManager, API routes, Sentinel ingest and RAG pipeline (PR #174)
@parthrohit22 requested changes on this pull request.
Thanks for the thorough work on expanding coverage, and for addressing the earlier review feedback. The Sentinel retry and validation assertions, along with the drift/resource scenarios, are much stronger now.
I found a few remaining items that need to be addressed before I can approve:
1. In test_rag_pipeline.py, test_build_vectorstore_calls_load_all_documents catches every exception and only patches VECTORSTORE_DIR. The implementation writes through INDEX_PATH using Path.write_text(), so the current mocks do not isolate the write. Please patch both paths to a temporary directory and remove the broad exception handler so an index-write failure cannot pass silently.
2. The compliance route tests currently only assert a 200 response, and the shared mock returns a CIS payload for every framework. Please assert that get_compliance_score() receives the requested framework and validate the corresponding response payload for every supported framework.
3. api/routes/cbom.py is still changed, although this PR is intended to be test-only and the description states that the CBOM change was removed. Please revert this unrelated import.
Once these are addressed and the backend test suite is rerun, I’m happy to re-review.
—
Reply to this email directly, view it on GitHub<#174?email_source=notifications&email_token=BJCJK42IBREUJSUZJQYO2MT5PUOY5A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKMRUG42DKMZTGY4KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#pullrequestreview-5247453368>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BJCJK43VJUHRYXLBLIFMUBT5PUOY5AVCNFSNUABGKJSXA33TNF2G64TZHMYTEMRQHEYDKOBQGI5US43TOVSTWNBYGU4TEMRVGE3DPILWAI>.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS<https://github.com/notifications/mobile/ios/BJCJK45NDSRELQYR4SCLGJL5PUOY5A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKMRUG42DKMZTGY4KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y> and Android<https://github.com/notifications/mobile/android/BJCJK46UJQ7HOGPUN67HJR35PUOY5A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKMRUG42DKMZTGY4KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>. Download it today!
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
TFT444
left a comment
There was a problem hiding this comment.
@emon22-ts three blockers from the Sep 18 review remain unaddressed:
test_build_vectorstore_calls_load_all_documentshas a broad catch-all that can hide index-write failures. Patch bothVECTORSTORE_DIRandINDEX_PATHto a temp dir and remove the catch-all.- Compliance route tests only assert
200. Please assert thatget_compliance_score()receives the correct framework argument and validate the response payload for each supported framework. api/routes/cbom.pystill contains an unrelatedfrom __future__ import annotationschange. Please remove it or split it into a separate PR.
…ingest and RAG pipeline - DatabaseManager: tests for init, DSN handling, Finding dataclass, SEVERITY_WEIGHTS and get_score() SQL logic - API routes: tests for score, compliance, drift, resources and prioritization endpoints - Sentinel ingest: tests for HMAC-SHA256 signature, field mappings, retry count and early exit - RAG pipeline: tests for loader, chunker overlap, retriever error handling and embed.py pipeline - All tests passing, ruff check and format clean Refs OWASP#153 Signed-off-by: Mahfuzur Rahman Emon <mahfuzur.emon01@gmail.com>
…rebase from dev - Drift: add test_drift_with_two_scans_classifies_added_removed with 2 scans that differ so ADDED/REMOVED classification is actually exercised - Resources: add test_resources_with_mixed_severity_rows with risk_rank 3/2/1 rows so rank_to_risk mapping and by_risk_level counts are verified - Remove unused _make_db helper from test_database_manager.py - Rebased from dev (86 tests: 24 sentinel + 24 RAG + 14 DB + 24 routes) Refs OWASP#153 Signed-off-by: Mahfuzur Rahman Emon <mahfuzur.emon01@gmail.com>
…s in dev Signed-off-by: Mahfuzur Rahman Emon <mahfuzur.emon01@gmail.com>
…severity test, remove cbom.py and duplicate SEVERITY_WEIGHTS tests - Drift test now asserts summary[added]==1, summary[removed]==1, type==ADDED/REMOVED and rule_violated==AZ-NET-001 - Sentinel unknown severity test now verifies ValidationError is raised for unknown severity - cbom.py removed from diff (restored to upstream) - Duplicate SEVERITY_WEIGHTS tests removed from TestScoreCalculation - Prioritization silent guard replaced with hard assertion - _make_prioritization_db fixed to handle fetchone side_effect correctly Refs OWASP#153 Signed-off-by: Mahfuzur Rahman Emon <mahfuzur.emon01@gmail.com>
…triever/embed rewritten to BM25 - test_database_manager: import SEVERITY_WEIGHTS from openshield.severity - test_rag_pipeline: update retriever tests for BM25 (no chromadb), update embed tests for BM25 - test_api_routes: fix prioritization mock to handle fetchall side_effect for rules+severity counts Refs OWASP#153 Signed-off-by: Mahfuzur Rahman Emon <mahfuzur.emon01@gmail.com>
Signed-off-by: Mahfuzur Rahman Emon <mahfuzur.emon01@gmail.com>
Signed-off-by: Mahfuzur Rahman Emon <mahfuzur.emon01@gmail.com>
Signed-off-by: Mahfuzur Rahman Emon <mahfuzur.emon01@gmail.com>
Signed-off-by: Mahfuzur Rahman Emon <mahfuzur.emon01@gmail.com>
…ed cbom change - test_rag_pipeline: build_vectorstore test now patches VECTORSTORE_DIR and INDEX_PATH to a real temp dir, asserts the index file is written, and drops the broad try/except that could hide index-write failures. - test_api_routes: compliance tests now assert get_compliance_score() is called with the exact framework and validate the response payload (framework echoed, required keys present, passed+failed==total) for all six supported frameworks (cis, nist, iso27001, soc2, ncsc_pqc, enisa_pqc); plus an error-result -> 500 case. - cbom.py: reverted the unrelated 'from __future__ import annotations' change (now identical to dev). Refs OWASP#153 Signed-off-by: Mahfuzur Rahman Emon <mahfuzur.emon01@gmail.com>
3702f3e to
2c245cc
Compare
m-khan-97
left a comment
There was a problem hiding this comment.
I re-reviewed the current head against the three outstanding blockers. They are now resolved: the BM25 build test patches both output paths, performs the real write, and no longer swallows exceptions; all six supported compliance routes assert the exact framework passed to the database layer and validate their payloads; and api/routes/cbom.py is no longer in the PR diff. I ran the four focused test files locally: all 88 tests passed. Approved.
TFT444
left a comment
There was a problem hiding this comment.
All blockers addressed in 2c245cc: vectorstore test now patches both VECTORSTORE_DIR and INDEX_PATH, compliance route tests assert per-framework payloads, and the unrelated cbom.py import is removed. Verified by m-khan-97 as well. Approving.
|
@parthrohit22 |
parthrohit22
left a comment
There was a problem hiding this comment.
Re-reviewed 2c245cc. All three items from my 18 Sep review are properly addressed — approving.
1. test_build_vectorstore_calls_load_all_documents — now patches both VECTORSTORE_DIR and INDEX_PATH to a real tempfile.TemporaryDirectory, runs build_vectorstore() for real, and asserts bm25_index.json actually exists afterwards. The broad except is gone, so an index-write failure now fails the test instead of passing silently. test_build_vectorstore_returns_chunk_count got the same treatment, which I didn't ask for but is the right call for consistency.
2. Compliance route tests — _check_framework() asserts get_compliance_score.assert_called_once_with(framework), so a route that ignored the path parameter and always queried CIS would now fail. It also echoes the framework back from the payload and checks passed + failed == total_controls, across all six supported frameworks. The added error → 500 case alongside the existing 400/500 paths rounds out the contract.
3. api/routes/cbom.py — git diff upstream/dev <head> -- api/routes/cbom.py is empty. The unrelated change is gone and the PR is test-only again.
CI is green across all 21 checks. Thanks for staying with this through a long review cycle — the coverage here is real coverage, not line-count coverage, and the mutation-resistance in the drift and resource tests is what makes it worth merging.
What does this PR do?
Closes the four test coverage gaps identified in the audit by adding unit tests for DatabaseManager, five API route files, Sentinel HMAC signing and field mappings, and the RAG pipeline.
Type of change
Coverage gaps addressed
Files added
1.tests/test_database_manager.py - 20 tests
2.tests/test_api_routes.py - 24 tests
3.tests/test_sentinel_ingest.py - 14 tests
4.tests/test_rag_pipeline.py - 24 tests
Testing
Related issue
Refs #153