- 
                Notifications
    
You must be signed in to change notification settings  - Fork 22
 
Clean concolic tests #26
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
          
     Merged
      
      
    
  
     Merged
                    Changes from 7 commits
      Commits
    
    
            Show all changes
          
          
            12 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c6c6fff
              
                first pass
              
              
                KRRT7 b79db77
              
                cleanup
              
              
                KRRT7 04fc3e6
              
                Update codeflash/code_utils/code_replacer.py
              
              
                KRRT7 af1f078
              
                Revert "Update codeflash/code_utils/code_replacer.py"
              
              
                KRRT7 8879e2e
              
                blocklisted funcs bugfix
              
              
                KRRT7 252381f
              
                codeflash suggestion
              
              
                KRRT7 b8bc645
              
                redundant Path() calls
              
              
                KRRT7 5c6e1bd
              
                move concolic related code to it's own file
              
              
                KRRT7 9095ca5
              
                update tests
              
              
                KRRT7 57afa8c
              
                ⚡️ Speed up method `AssertCleanup.transform_asserts` by 46% in PR #26…
              
              
                codeflash-ai[bot] 59250cc
              
                Merge remote-tracking branch 'origin/main' into clean_concolic_tests
              
              
                KRRT7 b9c19e9
              
                Merge pull request #30 from codeflash-ai/codeflash/optimize-pr26-2025…
              
              
                KRRT7 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,10 @@ | ||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| import ast | ||||||||||||||||||||
| import re | ||||||||||||||||||||
| from collections import defaultdict | ||||||||||||||||||||
| from functools import lru_cache | ||||||||||||||||||||
| from typing import TYPE_CHECKING, TypeVar | ||||||||||||||||||||
| from typing import TYPE_CHECKING, Optional, TypeVar | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| import libcst as cst | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| 
          
            
          
           | 
    @@ -336,3 +337,91 @@ def function_to_optimize_original_worktree_fqn( | |||||||||||||||||||
| + "." | ||||||||||||||||||||
| + function_to_optimize.qualified_name | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| class AssertCleanup: | ||||||||||||||||||||
| def transform_asserts(self, code: str) -> str: | ||||||||||||||||||||
| lines = code.splitlines() | ||||||||||||||||||||
| result_lines = [] | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| for line in lines: | ||||||||||||||||||||
| transformed = self._transform_assert_line(line) | ||||||||||||||||||||
| if transformed is not None: | ||||||||||||||||||||
| result_lines.append(transformed) | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| result_lines.append(line) | ||||||||||||||||||||
                
      
                  KRRT7 marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| return "\n".join(result_lines) | ||||||||||||||||||||
                
      
                  KRRT7 marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| def _transform_assert_line(self, line: str) -> Optional[str]: | ||||||||||||||||||||
| indent = line[: len(line) - len(line.lstrip())] | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| assert_match = re.match(r"\s*assert\s+(.*?)(?:\s*==\s*.*)?$", line) | ||||||||||||||||||||
| if assert_match: | ||||||||||||||||||||
| expression = assert_match.group(1).strip() | ||||||||||||||||||||
                
      
                  KRRT7 marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||||||||||||||||||||
| if expression.startswith("not "): | ||||||||||||||||||||
| return f"{indent}{expression}" | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| expression = re.sub(r"[,;]\s*$", "", expression) | ||||||||||||||||||||
| return f"{indent}{expression}" | ||||||||||||||||||||
                
      
                  KRRT7 marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| unittest_match = re.match(r"(\s*)self\.assert([A-Za-z]+)\((.*)\)$", line) | ||||||||||||||||||||
| if unittest_match: | ||||||||||||||||||||
| indent, assert_method, args = unittest_match.groups() | ||||||||||||||||||||
                
      
                  KRRT7 marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| if args: | ||||||||||||||||||||
| arg_parts = self._split_top_level_args(args) | ||||||||||||||||||||
| if arg_parts and arg_parts[0]: | ||||||||||||||||||||
| return f"{indent}{arg_parts[0]}" | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| return None | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| def _split_top_level_args(self, args_str: str) -> list[str]: | ||||||||||||||||||||
| result = [] | ||||||||||||||||||||
| current = [] | ||||||||||||||||||||
| depth = 0 | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| for char in args_str: | ||||||||||||||||||||
| if char in "([{": | ||||||||||||||||||||
| depth += 1 | ||||||||||||||||||||
| current.append(char) | ||||||||||||||||||||
| elif char in ")]}": | ||||||||||||||||||||
                
       | 
||||||||||||||||||||
| for char in args_str: | |
| if char in "([{": | |
| depth += 1 | |
| current.append(char) | |
| elif char in ")]}": | |
| char_to_depth_change = {"(": 1, "[": 1, "{": 1, ")": -1, "]": -1, "}": -1} | |
| if char in char_to_depth_change: | |
| depth += char_to_depth_change[char] | 
        
          
              
                  KRRT7 marked this conversation as resolved.
              
              
                Outdated
          
            Show resolved
            Hide resolved
        
      
                  KRRT7 marked this conversation as resolved.
              
              
                Outdated
          
            Show resolved
            Hide resolved
                
          
              
                  KRRT7 marked this conversation as resolved.
              
              
                Outdated
          
            Show resolved
            Hide resolved
        
      
                  KRRT7 marked this conversation as resolved.
              
              
                Outdated
          
            Show resolved
            Hide resolved
                
          
              
                  KRRT7 marked this conversation as resolved.
              
              
                Outdated
          
            Show resolved
            Hide resolved
        
      
                  KRRT7 marked this conversation as resolved.
              
              
                Outdated
          
            Show resolved
            Hide resolved
        
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
      
      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.