fix: update Java Comparator to read from test_results table
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 <noreply@anthropic.com>
This commit is contained in:
parent
d714e54e58
commit
85158b07dd
1 changed files with 42 additions and 6 deletions
|
|
@ -160,18 +160,32 @@ public final class Comparator {
|
|||
|
||||
private static List<Invocation> getInvocations(Connection conn) throws SQLException {
|
||||
List<Invocation> 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 @@ public final class Comparator {
|
|||
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.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue