Repository navigation
Remove the empty results dir of a scan that wrote nothing - #50
Open
adityaanikam wants to merge 1 commit into
Open
adityaanikam wants to merge 1 commit into
adityaanikam wants to merge 1 commit into
Conversation
scan_folder pre-creates <clone>/<clone>_VULNHUNT_RESULTS_<ts> before it launches claude. When the scan wrote nothing (auth error, crash, early timeout) it returned results_dir=None but left the empty directory in the clone. collect_results accepts any results dir named for the repo, so the failed scan was copied to the upload dir and counted as Copied instead of Missing results. Remove the directory when it is still empty after the run. An OSError is ignored, in case an --execute agent already removed or replaced it. Fixes capitalone#48
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.
Fixes #48.
scan_folderpre-creates<clone>/<clone>_VULNHUNT_RESULTS_<timestamp>/before it launchesclaude. If the scan fails before it writes anything (auth error, crash, early timeout), it returnsresults_dir=Nonebut leaves the empty directory in the clone.batch.utils.collect_resultsaccepts any untracked results directory named for the repo, so it copies the empty one and counts the repo as Copied. The failed repo never shows up under Missing results, and an empty result set ends up into_upload/.Change
In
harness/local_harness/scan.py,scan_foldernow removes the results directory when it is still empty after the run. AnOSErroris ignored, since an--executeagent may have removed or replaced it already.This is the first option from the issue. I did not change
collect_resultsto skip results directories that have no README. A scan that is killed after it wrote some files still leaves a non-empty directory without a README, andcollect_resultscollects that as before. That is a separate behaviour change.Tests
In
harness/tests/test_scan.py:test_scan_folder_removes_empty_results_dir: no results directory is left after a scan that wrote nothing.test_scan_folder_tolerates_failure_to_remove_empty_results_dir: a failingrmdirdoes not raise, andresults_diris stillNone.test_failed_scan_is_reported_missing_by_collect_results: runs a fake scan that writes nothing, thencollect_results, and expectscopiedto be empty and the repo to be undermissing(the scenario from the issue).test_scan_folder_prompt_has_preresolved_metadataasserted that the results directory exists after the scan, which only held because the empty directory was left behind. That check now runs whenclaudeis launched (in_capture_scan_argv), which is what the test is about.With
scan.pyreverted and the new tests kept,test_scan_folder_removes_empty_results_dirandtest_failed_scan_is_reported_missing_by_collect_resultsfail. The full harness suite passes on Linux (WSL, Python 3.12):pytest tests/ --cov=local_harnessgives 215 passed, with total coverage at 95%. I did not run a real scan againstclaude.