From 85158b07ddd41fd4a331ca48fe32ba1eb1988cfe Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Tue, 3 Feb 2026 00:23:01 +0000 Subject: [PATCH] fix: update Java Comparator to read from test_results table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Comparator was reading from an `invocations` table, but Java instrumentation writes to a `test_results` table. This aligns the Comparator with the cross-language schema consistency requirement. Changes: - Update SQL query to SELECT from test_results table - Map columns: iteration_id + loop_index → call_id - Map return_value → resultJson for comparison - Construct method_id from test_class_name.function_getting_tested - Add parseIterationId() helper to extract numeric ID from string format - Set args_json and error_json to null (not captured in test_results schema) This enables behavior verification to work correctly by reading the data that instrumented tests actually write. Test results: All 336 Java tests pass (18 comparator tests + 318 others) Co-Authored-By: Claude Sonnet 4.5 --- .../main/java/com/codeflash/Comparator.java | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/codeflash-java-runtime/src/main/java/com/codeflash/Comparator.java b/codeflash-java-runtime/src/main/java/com/codeflash/Comparator.java index 97b27a92e..1e471564d 100644 --- a/codeflash-java-runtime/src/main/java/com/codeflash/Comparator.java +++ b/codeflash-java-runtime/src/main/java/com/codeflash/Comparator.java @@ -160,18 +160,32 @@ public static ComparisonResult compare(String originalDbPath, String candidateDb private static List getInvocations(Connection conn) throws SQLException { List invocations = new ArrayList<>(); - String sql = "SELECT call_id, method_id, args_json, result_json, error_json FROM invocations ORDER BY call_id"; + String sql = "SELECT test_class_name, function_getting_tested, loop_index, iteration_id, return_value " + + "FROM test_results ORDER BY loop_index, iteration_id"; try (PreparedStatement stmt = conn.prepareStatement(sql); ResultSet rs = stmt.executeQuery()) { while (rs.next()) { + String testClassName = rs.getString("test_class_name"); + String functionName = rs.getString("function_getting_tested"); + int loopIndex = rs.getInt("loop_index"); + String iterationId = rs.getString("iteration_id"); + String returnValue = rs.getString("return_value"); + + // Create unique call_id from loop_index and iteration_id + // Parse iteration_id which is in format "iter_testIteration" (e.g., "1_0") + long callId = (loopIndex * 10000L) + parseIterationId(iterationId); + + // Construct method_id as "ClassName.methodName" + String methodId = testClassName + "." + functionName; + invocations.add(new Invocation( - rs.getLong("call_id"), - rs.getString("method_id"), - rs.getString("args_json"), - rs.getString("result_json"), - rs.getString("error_json") + callId, + methodId, + null, // args_json not captured in test_results schema + returnValue, // return_value maps to resultJson + null // error_json not captured in test_results schema )); } } @@ -179,6 +193,28 @@ private static List getInvocations(Connection conn) throws SQLExcept return invocations; } + /** + * Parse iteration_id string to extract the numeric iteration number. + * Format: "iter_testIteration" (e.g., "1_0" → 1) + */ + private static long parseIterationId(String iterationId) { + if (iterationId == null || iterationId.isEmpty()) { + return 0; + } + try { + // Split by underscore and take the first part + String[] parts = iterationId.split("_"); + return Long.parseLong(parts[0]); + } catch (Exception e) { + // If parsing fails, try to parse the whole string + try { + return Long.parseLong(iterationId); + } catch (Exception ex) { + return 0; + } + } + } + /** * Compare two JSON values for equivalence. */