Skip to content

Conversation

@alvin-r
Copy link
Contributor

@alvin-r alvin-r commented Mar 28, 2025

User description

merged test_results.py into models.py to avoid circular imports. Also refactored out some logic from CoverageData into CoverageUtils so we don't clutter the models.py file


PR Type

  • Enhancement
  • Tests

Description

  • Integrated test result and verification types into models.

  • Removed deprecated test_results module.

  • Redirected and refactored imports across modules.

  • Introduced CoverageUtils for coverage handling.


Changes walkthrough 📝

Relevant files
Refactoring
11 files
instrument_existing_tests.py
Updated import for VerificationType from models.                 
+1/-2     
discover_unit_tests.py
Replaced test_results import with models import.                 
+1/-2     
PrComment.py
Adjusted import to fetch TestResults from models.               
+1/-1     
function_optimizer.py
Updated imports to use TestResults and TestType from models.
+3/-2     
optimizer.py
Modified import order and consolidated ValidCode usage.   
+1/-2     
critic.py
Changed TestType import to retrieve from models.                 
+6/-2     
explanation.py
Updated TestResults import from models.                                   
+1/-1     
codeflash_capture.py
Altered VerificationType import to reference models.         
+1/-1     
equivalence.py
Adjusted import ordering; moved to models for test types.
+2/-3     
parse_test_output.py
Redirected sqlite coverage loading to CoverageUtils.         
+4/-10   
test_runner.py
Updated TestFiles and TestType imports from models.           
+1/-2     
Enhancement
2 files
models.py
Added VerificationType, TestType, and test result classes.
+244/-214
coverage_utils.py
New module: CoverageUtils for sqlite coverage extraction.
+229/-0 
Removal
1 files
test_results.py
Removed redundant test_results module; functionality moved to models.
+0/-249 
Tests
8 files
test_codeflash_capture.py
Revised imports to include new TestType and VerificationType.
+1/-2     
test_comparator.py
Updated import to use models for test result classes.       
+1/-1     
test_critic.py
Refactored imports for FunctionTestInvocation and TestResults.
+4/-1     
test_instrument_all_and_run.py
Switched to models for CodePosition, FunctionParent, and TestType.
+1/-2     
test_instrument_tests.py
Extended imports with TestType and TestsInFile from models.
+9/-2     
test_instrumentation_run_results_aiservice.py
Updated imports to use models for test results and verification.
+1/-2     
test_merge_test_results.py
Changed merge test results to use models for FunctionTestInvocation.
+1/-1     
test_test_runner.py
Modified imports to retrieve TestFile and TestType from models.
+1/-2     

Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @github-actions
    Copy link

    github-actions bot commented Mar 28, 2025

    PR Reviewer Guide 🔍

    (Review updated until commit d6bcdbd)

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Refactoring Impact

    New enums and classes for test results and verification (such as VerificationType, TestType, InvocationId, FunctionTestInvocation, and TestResults) replace the previous test_results module. Please ensure that all dependent modules are updated correctly and that existing functionality remains consistent.

    class VerificationType(str, Enum): FUNCTION_CALL = ( "function_call" # Correctness verification for a test function, checks input values and output values) ) INIT_STATE_FTO = "init_state_fto" # Correctness verification for fto class instance attributes after init INIT_STATE_HELPER = "init_state_helper" # Correctness verification for helper class instance attributes after init class TestType(Enum): EXISTING_UNIT_TEST = 1 INSPIRED_REGRESSION = 2 GENERATED_REGRESSION = 3 REPLAY_TEST = 4 CONCOLIC_COVERAGE_TEST = 5 INIT_STATE_TEST = 6 def to_name(self) -> str: if self is TestType.INIT_STATE_TEST: return "" names = { TestType.EXISTING_UNIT_TEST: "⚙️ Existing Unit Tests", TestType.INSPIRED_REGRESSION: "🎨 Inspired Regression Tests", TestType.GENERATED_REGRESSION: "🌀 Generated Regression Tests", TestType.REPLAY_TEST: "⏪ Replay Tests", TestType.CONCOLIC_COVERAGE_TEST: "🔎 Concolic Coverage Tests", } return names[self]
    Temporary File Handling

    The new CoverageUtils class uses a temporary JSON file to process coverage data. Verify that the temporary file is managed safely (including proper deletion) and that potential file I/O errors are handled gracefully.

    temp_json_file = database_path.with_suffix(".report.json") with temp_json_file.open("w") as f: try: reporter.report(morfs=[source_code_path.as_posix()], outfile=f) except NoDataError: sentry_sdk.capture_message(f"No coverage data found for {function_name} in {source_code_path}") return CoverageUtils.create_empty(source_code_path, function_name, code_context) with temp_json_file.open() as f: original_coverage_data = json.load(f) coverage_data, status = CoverageUtils._parse_coverage_file(temp_json_file, source_code_path) main_func_coverage, dependent_func_coverage = CoverageUtils._fetch_function_coverages( function_name, code_context, coverage_data, original_cov_data=original_coverage_data ) total_executed_lines, total_unexecuted_lines = CoverageUtils._aggregate_coverage( main_func_coverage, dependent_func_coverage ) total_lines = total_executed_lines | total_unexecuted_lines coverage = len(total_executed_lines) / len(total_lines) * 100 if total_lines else 0.0 # coverage = (lines covered of the original function + its 1 level deep helpers) / (lines spanned by original function + its 1 level deep helpers), if no helpers then just the original function coverage functions_being_tested = [main_func_coverage.name] if dependent_func_coverage: functions_being_tested.append(dependent_func_coverage.name) graph = CoverageUtils._build_graph(main_func_coverage, dependent_func_coverage) temp_json_file.unlink()
    @github-actions
    Copy link

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @alvin-r alvin-r marked this pull request as ready for review March 28, 2025 22:26
    @github-actions
    Copy link

    Persistent review updated to latest commit d6bcdbd

    @github-actions
    Copy link

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @alvin-r alvin-r requested review from KRRT7 and misrasaurabh1 and removed request for misrasaurabh1 March 28, 2025 22:32
    @alvin-r alvin-r merged commit b1443a3 into main Mar 28, 2025
    16 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    3 participants