55
66from pathlib import Path
77
8- from src .tools import get_overview , search_content , read_content , edit_content
8+ from src .tools import edit_content , get_overview , read_content , search_content
99
1010
1111class TestCodebaseWorkflows :
@@ -17,172 +17,170 @@ def test_data_dir(self):
1717
1818 def test_web_framework_patterns_comparison (self ):
1919 """Compare patterns between Django and Laravel web frameworks.
20-
21- Scenario: Developer migrating from Django to Laravel needs to
20+
21+ Scenario: Developer migrating from Django to Laravel needs to
2222 understand model patterns and validation approaches.
2323 """
2424 django_models = self .test_data_dir / "python" / "django-models.py"
2525 laravel_model = self .test_data_dir / "php" / "laravel-model.php"
26-
26+
2727 # Get overview of both frameworks
2828 django_overview = get_overview (str (django_models ))
2929 laravel_overview = get_overview (str (laravel_model ))
30-
30+
3131 assert django_overview ["line_count" ] > 0
3232 assert laravel_overview ["line_count" ] > 0
33-
33+
3434 # Search for model patterns
3535 django_models_search = search_content (str (django_models ), "class" , fuzzy = False )
3636 laravel_models_search = search_content (str (laravel_model ), "class" , fuzzy = False )
37-
37+
3838 assert django_models_search ["total_matches" ] > 0
3939 assert laravel_models_search ["total_matches" ] > 0
40-
40+
4141 # Search for validation patterns
4242 django_validation = search_content (str (django_models ), "valid" , fuzzy = True )
4343 laravel_validation = search_content (str (laravel_model ), "valid" , fuzzy = True )
44-
44+
4545 # At least one should have validation patterns
46- total_validation = django_validation ["total_matches" ] + laravel_validation ["total_matches" ]
46+ total_validation = (
47+ django_validation ["total_matches" ] + laravel_validation ["total_matches" ]
48+ )
4749 assert total_validation >= 0
4850
4951 def test_large_javascript_codebase_navigation (self ):
5052 """Navigate large JavaScript utility library effectively.
51-
53+
5254 Scenario: Developer needs to understand specific utility functions
5355 in the Lodash library (532KB file).
5456 """
5557 lodash_file = self .test_data_dir / "javascript" / "lodash-utility.js"
56-
58+
5759 if not lodash_file .exists ():
5860 return # Skip if file doesn't exist
59-
61+
6062 # Get overview - should use mmap strategy for this size
6163 overview = get_overview (str (lodash_file ))
6264 assert overview ["file_size" ] > 500_000 # 532KB file
6365 assert overview ["line_count" ] > 1000
64-
66+
6567 # Search for common utility functions
6668 function_search = search_content (str (lodash_file ), "function" , max_results = 10 )
6769 assert function_search ["total_matches" ] > 0
68-
70+
6971 # Test performance with specific function search
7072 map_search = search_content (str (lodash_file ), "map" , fuzzy = True , max_results = 5 )
7173 assert map_search ["total_matches" ] >= 0
7274
7375 def test_cross_language_async_patterns (self ):
7476 """Find async patterns across different programming languages.
75-
77+
7678 Scenario: Developer wants to understand async patterns across
7779 JavaScript, Python, Go, and C# codebases.
7880 """
7981 files = [
8082 self .test_data_dir / "javascript" / "lodash-utility.js" ,
81- self .test_data_dir / "python" / "django-models.py" ,
83+ self .test_data_dir / "python" / "django-models.py" ,
8284 self .test_data_dir / "go" / "docker-daemon.go" ,
83- self .test_data_dir / "csharp" / "aspnet-controller.cs"
85+ self .test_data_dir / "csharp" / "aspnet-controller.cs" ,
8486 ]
85-
87+
8688 async_patterns_found = 0
8789 for file_path in files :
8890 if file_path .exists ():
8991 result = search_content (str (file_path ), "async" , fuzzy = True )
9092 async_patterns_found += result ["total_matches" ]
91-
93+
9294 # Should find some async patterns across languages
9395 assert async_patterns_found >= 0
9496
9597 def test_rust_serialization_code_analysis (self ):
9698 """Analyze Rust serialization library code structure.
97-
98- Scenario: Developer learning Rust needs to understand
99+
100+ Scenario: Developer learning Rust needs to understand
99101 serialization patterns in the Serde library.
100102 """
101103 serde_file = self .test_data_dir / "rust" / "serde-derive.rs"
102-
104+
103105 if not serde_file .exists ():
104106 return # Skip if file doesn't exist
105-
107+
106108 overview = get_overview (str (serde_file ))
107109 assert overview ["line_count" ] > 0
108-
110+
109111 # Search for Rust-specific patterns
110112 impl_search = search_content (str (serde_file ), "impl" , fuzzy = False )
111113 struct_search = search_content (str (serde_file ), "struct" , fuzzy = False )
112-
114+
113115 # Should find some Rust patterns
114116 rust_patterns = impl_search ["total_matches" ] + struct_search ["total_matches" ]
115117 assert rust_patterns > 0
116118
117119 def test_spring_java_application_navigation (self ):
118120 """Navigate Java Spring application code.
119-
120- Scenario: Developer needs to understand Spring Boot
121+
122+ Scenario: Developer needs to understand Spring Boot
121123 application structure and annotations.
122124 """
123125 spring_file = self .test_data_dir / "java" / "spring-application.java"
124-
126+
125127 overview = get_overview (str (spring_file ))
126128 assert overview ["file_size" ] > 0
127-
129+
128130 # Search for Spring annotations and patterns
129131 annotation_search = search_content (str (spring_file ), "@" , fuzzy = False )
130132 class_search = search_content (str (spring_file ), "class" , fuzzy = False )
131-
133+
132134 assert annotation_search ["total_matches" ] >= 0
133135 assert class_search ["total_matches" ] >= 0
134136
135137 def test_code_search_and_context_extraction (self ):
136138 """Test targeted code search with context extraction.
137-
139+
138140 Scenario: Developer needs to find specific method implementations
139141 with surrounding context for understanding.
140142 """
141143 vscode_extension = self .test_data_dir / "typescript" / "vscode-extension.ts"
142-
144+
143145 if not vscode_extension .exists ():
144146 return # Skip if file doesn't exist
145-
147+
146148 # Search for function definitions with context
147- function_results = search_content (str (vscode_extension ), "function" , context_lines = 3 )
148-
149+ function_results = search_content (
150+ str (vscode_extension ), "function" , context_lines = 3
151+ )
152+
149153 for result in function_results ["results" ][:3 ]: # Check first 3 results
150154 assert "context_before" in result
151155 assert "context_after" in result
152156 assert "line_number" in result
153-
157+
154158 # Read the specific function with more context
155159 line_num = result ["line_number" ]
156160 detailed_content = read_content (
157- str (vscode_extension ),
158- line_num ,
159- mode = "lines"
161+ str (vscode_extension ), line_num , mode = "lines"
160162 )
161163 assert "content" in detailed_content
162164
163165 def test_safe_code_editing_preview (self ):
164166 """Test safe code editing with preview mode.
165-
167+
166168 Scenario: Developer wants to preview code changes before applying
167169 them to ensure no unintended modifications.
168170 """
169171 # Use a small file for editing tests
170172 spring_file = self .test_data_dir / "java" / "spring-application.java"
171-
173+
172174 # Test search and replace in preview mode
173175 result = edit_content (
174- str (spring_file ),
175- "class" ,
176- "public class" ,
177- preview = True ,
178- fuzzy = False
176+ str (spring_file ), "class" , "public class" , preview = True , fuzzy = False
179177 )
180-
178+
181179 assert "success" in result
182180 assert "preview" in result
183181 assert "changes_made" in result
184-
182+
185183 # Verify preview mode doesn't actually modify file
186184 if result ["success" ]:
187185 assert result ["preview" ] is True
188- assert "backup_created" not in result # No backup in preview mode
186+ assert "backup_created" not in result # No backup in preview mode
0 commit comments