Merge pull request #1394 from codeflash-ai/fix/detect-java-compilation-failures

fix: detect and log Java compilation failures explicitly
This commit is contained in:
mashraf-222 2026-02-10 19:33:28 +02:00 committed by GitHub
commit fd6be1e8f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 2 deletions

View file

@ -1146,10 +1146,39 @@ def _run_maven_tests(
logger.debug("Running Maven command: %s in %s", " ".join(cmd), project_root)
try:
return subprocess.run(
result = subprocess.run(
cmd, check=False, cwd=project_root, env=env, capture_output=True, text=True, timeout=timeout
)
# Check if Maven failed due to compilation errors (not just test failures)
if result.returncode != 0:
# Maven compilation errors contain specific markers in output
compilation_error_indicators = [
"[ERROR] COMPILATION ERROR",
"[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin",
"compilation failure",
"cannot find symbol",
"package .* does not exist",
]
combined_output = (result.stdout or "") + (result.stderr or "")
has_compilation_error = any(
indicator.lower() in combined_output.lower() for indicator in compilation_error_indicators
)
if has_compilation_error:
logger.error(
f"Maven compilation failed for {mode} tests. "
f"Check that generated test code is syntactically valid Java. "
f"Return code: {result.returncode}"
)
# Log first 50 lines of output to help diagnose compilation errors
output_lines = combined_output.split("\n")
error_context = "\n".join(output_lines[:50]) if len(output_lines) > 50 else combined_output
logger.error(f"Maven compilation error output:\n{error_context}")
return result
except subprocess.TimeoutExpired:
logger.exception("Maven test execution timed out after %d seconds", timeout)
return subprocess.CompletedProcess(

View file

@ -1243,8 +1243,14 @@ def parse_test_xml(
)
if not test_results:
# Show actual test file paths being used (behavior or original), not just original_file_path
# For AI-generated tests, original_file_path is None, so show instrumented_behavior_file_path instead
test_paths_display = [
str(test_file.instrumented_behavior_file_path or test_file.original_file_path)
for test_file in test_files.test_files
]
logger.info(
f"Tests '{[test_file.original_file_path for test_file in test_files.test_files]}' failed to run, skipping"
f"Tests {test_paths_display} failed to run, skipping"
)
if run_result is not None:
stdout, stderr = "", ""