Test/semgrep malformed json fallback 1658 - #2470
Open
Khanvilkarshravani27 wants to merge 3 commits into
Open
Conversation
…1862) totalItems was only set from the first /findings call. Subsequent loadMore fetches never updated it, so the 'Load More (X/Y)' guard used a stale total whenever filters changed the server-side count between pages. Changes: - Import FindingsResponse type and use it instead of �ny in the initial load callback; filter findings to those with string ids for safety - Add setTotalItems(data.total ?? moreFindings.length) inside loadMore after each successful paginated fetch, matching the same pattern already used on initial load; also apply the id-string filter to moreFindings - Add two unit tests for the totalItems sync: one verifies the button hides when totalItems drops to match findings.length after loadMore; the other verifies the counter keeps updating correctly across pages
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Extends
testing/backend/unit/test_semgrep_scanner_plugin.pywith a newTestSemgrepParserMalformedJsonFallbacktest class that verifies the Semgrep parser's silent fallback behaviour when given malformed or structurally unexpected JSON input.The parser wraps all parsing logic in a broad
except Exception: passblock, silently returning{"count": 0, "findings": []}on any error. These tests confirm that this fallback is deterministic and consistent across four distinct malformed-input categories.Tests added:
test_truncated_json_returns_empty_findings— truncated JSON ({"results": [{) simulating a mid-write process kill →count=0, findings=[]test_mixed_stdout_with_json_fragment_returns_deterministic_empty_result— log lines mixed with a JSON fragment, called twice to assert determinism →count=0, findings=[]test_valid_json_missing_top_level_results_key_returns_empty— syntactically valid JSON but noresultskey →count=0, findings=[]test_valid_json_with_null_in_critical_fields_returns_empty_without_crash—{"results": null}which triggersTypeErroron iteration →count=0, findings=[]All 8 tests in the file (4 existing + 4 new) pass:
8 passed in 2.11sRelated Issues
Closes #1658
Type of Change
How Has This Been Tested?
Run the full test file locally:
Result:
8 passed, 1 warning in 2.11s— all pre-existing tests continue to pass alongside the four new fallback tests.Checklist