@@ -59,13 +59,17 @@ def __init__(self):
5959 "Testing completion message instead of results" ),
6060 ],
6161
62- # Meaningless assertions
62+ # Meaningless assertions - IMPROVED TO REDUCE FALSE POSITIVES
6363 TheaterType .MEANINGLESS_ASSERTION : [
6464 (r'assert!\(true\)' , "Always passes - meaningless assertion" ),
65- (r'assert!\(.*\.is_ok\(\)\)' , "Only tests that no error occurred, not functionality" ),
66- (r'assert!\(.*\.len\(\)\s*>\s*0\)(?!.*&&)' , "Only tests non-empty, not content quality" ),
67- (r'assert!\(.*\.is_some\(\)\)(?!\s*,)' , "Only tests that value exists, not its content" ),
68- (r'assert!\(!.*\.is_empty\(\)\)' , "Only tests non-empty, not content validity" ),
65+ # Only flag is_ok() without descriptive message or follow-up validation
66+ (r'assert!\(.*\.is_ok\(\)\);$' , "Only tests that no error occurred, not functionality" ),
67+ (r'assert!\(.*\.len\(\)\s*>\s*0\)(?!.*&&)(?!\s*,)' , "Only tests non-empty, not content quality" ),
68+ # Only flag is_some() without message or follow-up
69+ (r'assert!\(.*\.is_some\(\)\);$' , "Only tests that value exists, not its content" ),
70+ (r'assert!\(!.*\.is_empty\(\)\);$' , "Only tests non-empty, not content validity" ),
71+ # Flag missing descriptive messages in assertions
72+ (r'assert!\([^,)]+\.get\([^)]+\)\.is_some\(\)\);$' , "Only tests that value exists, not its content" ),
6973 ],
7074
7175 # Count-based validation without content check
@@ -99,10 +103,13 @@ def __init__(self):
99103 # This pattern is harder to detect with regex, will be done in analyze_test_function
100104 ],
101105
102- # Mock/placeholder testing without real functionality
106+ # Mock/placeholder testing without real functionality - IMPROVED
103107 TheaterType .MOCK_TESTING_ONLY : [
104- (r'\.mock\(\)|Mock::|create_mock' , "Testing mock objects instead of real functionality" ),
105- (r'placeholder|stub|fake' , "Using placeholder implementations in tests" ),
108+ (r'\.mock\(\)|Mock::|create_mock(?!.*edge)' , "Testing mock objects instead of real functionality" ),
109+ # Only flag placeholder/fake if not used for negative/edge case testing
110+ (r'\b(placeholder|stub)\b(?!.*test|.*edge|.*nonexistent)' , "Using placeholder implementations in tests" ),
111+ # Allow fake for edge case testing (fake_chunk_id for testing nonexistent)
112+ (r'\bfake\b(?!.*(_id|_chunk|nonexistent|invalid))' , "Using fake implementations in tests" ),
106113 (r'todo!\(\)|unimplemented!\(\)' , "Test calls unimplemented functionality" ),
107114 ],
108115 }
@@ -219,24 +226,43 @@ def validate_test_function(self, file_path: str, start_line: int, content: List[
219226 # Combine all content
220227 full_content = '\n ' .join ([line for _ , line in content ])
221228
222- # Look for actual function calls
229+ # Look for actual function calls - ENHANCED PATTERNS
223230 has_call_tool = bool (re .search (r'\.call_tool\(' , full_content ))
224231 # More flexible await pattern to catch various async call patterns
225232 has_await_call = bool (re .search (r'\.await\b' , full_content ))
226233 # More specific execute patterns to avoid false matches
227234 has_execute_call = bool (re .search (r'\b(execute|run|process)\s*\(' , full_content , re .IGNORECASE ))
228- # Additional patterns for function calls
235+
236+ # ENHANCED: Static function calls (Struct::method, function())
237+ has_static_call = bool (re .search (r'\b[A-Z]\w*::\w+\(' , full_content ))
238+ # ENHANCED: Constructor calls (Type::new, Type::from_*)
239+ has_constructor_call = bool (re .search (r'\b[A-Z]\w*::(new|from_\w*|create|build)\(' , full_content ))
240+ # ENHANCED: Serialization calls (to_string, from_str, etc.)
241+ has_serialization = bool (re .search (r'\b(to_string|from_str|to_json|from_json|serialize|deserialize)\(' , full_content ))
242+ # ENHANCED: Extension method calls (Language::from_extension, etc.)
243+ has_extension_method = bool (re .search (r'\w+::from_\w+\(' , full_content ))
244+
245+ # Additional patterns for function calls
229246 has_function_call = bool (re .search (r'\w+\.\w+\([^)]*\)' , full_content ))
230247 has_method_chain = bool (re .search (r'\w+\.\w+\(.*\)\.\w+' , full_content ))
231248
249+ # ENHANCED: Function calls without dots (standalone functions)
250+ has_standalone_call = bool (re .search (r'\b\w+\([^)]*\)(?!\s*[;,)])' , full_content ))
251+
252+ # Combine all function call indicators
253+ has_any_function_call = (has_call_tool or has_await_call or has_execute_call or
254+ has_static_call or has_constructor_call or has_serialization or
255+ has_extension_method or has_function_call or has_method_chain or
256+ has_standalone_call )
257+
232258 # Count assertions
233259 assertion_count = len (re .findall (r'assert[_!]' , full_content ))
234260
235261 # Look for contains-only assertions
236262 contains_assertions = len (re .findall (r'assert!\([^)]*\.contains\(' , full_content ))
237263
238264 # Check for test theater patterns
239- if contains_assertions > 0 and not ( has_call_tool or has_await_call or has_function_call ) :
265+ if contains_assertions > 0 and not has_any_function_call :
240266 issues .append (TheaterIssue (
241267 file_path = file_path ,
242268 line_number = start_line ,
@@ -247,8 +273,22 @@ def validate_test_function(self, file_path: str, start_line: int, content: List[
247273 recommendation = "Replace contains assertions with actual function calls and result validation"
248274 ))
249275
250- # Only flag if no meaningful function calls are detected
251- if assertion_count > 0 and not (has_call_tool or has_await_call or has_execute_call or has_function_call or has_method_chain ):
276+ # ENHANCED: Check for valid test patterns before flagging as no_function_call
277+ is_valid_test_pattern = (
278+ # Edge case testing (nonexistent, invalid input, etc.)
279+ bool (re .search (r'\b(nonexistent|invalid|fake|non_existent)\b' , full_content , re .IGNORECASE )) or
280+ # Negative testing (should fail, should be none, etc.)
281+ bool (re .search (r'\.is_none\(\)|\.is_err\(\)' , full_content )) or
282+ # Comparison/validation tests (assert_eq, assert_ne)
283+ bool (re .search (r'assert_(eq|ne)!' , full_content )) or
284+ # Configuration/initialization tests
285+ bool (re .search (r'\b(new|default|create)\s*\(\)' , full_content )) or
286+ # Very short tests (likely simple validation)
287+ len (content ) <= 5
288+ )
289+
290+ # Only flag if no meaningful function calls are detected AND it's not a valid test pattern
291+ if assertion_count > 0 and not has_any_function_call and not is_valid_test_pattern :
252292 issues .append (TheaterIssue (
253293 file_path = file_path ,
254294 line_number = start_line ,
0 commit comments