Skip to content

Commit d052ccb

Browse files
committed
Fix skipping of generative ESQL tests
The error message can sometimes be split into multiple lines with backslashes marking the line boundaries. Let's make our skips work even in case of overlong lines.
1 parent 829fb56 commit d052ccb

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,6 @@ tests:
509509
- class: org.elasticsearch.xpack.sql.qa.mixed_node.SqlCompatIT
510510
method: testNullsOrderWithMissingOrderSupportQueryingNewNode
511511
issue: https://github.com/elastic/elasticsearch/issues/132249
512-
- class: org.elasticsearch.xpack.esql.qa.multi_node.GenerativeIT
513-
method: test
514-
issue: https://github.com/elastic/elasticsearch/issues/132273
515512
- class: org.elasticsearch.common.logging.JULBridgeTests
516513
method: testThrowable
517514
issue: https://github.com/elastic/elasticsearch/issues/132280

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private static CommandGenerator.ValidationResult checkResults(
160160
);
161161
if (outputValidation.success() == false) {
162162
for (Pattern allowedError : ALLOWED_ERROR_PATTERNS) {
163-
if (allowedError.matcher(outputValidation.errorMessage()).matches()) {
163+
if (isAllowedError(outputValidation.errorMessage(), allowedError)) {
164164
return outputValidation;
165165
}
166166
}
@@ -171,13 +171,24 @@ private static CommandGenerator.ValidationResult checkResults(
171171

172172
private void checkException(EsqlQueryGenerator.QueryExecuted query) {
173173
for (Pattern allowedError : ALLOWED_ERROR_PATTERNS) {
174-
if (allowedError.matcher(query.exception().getMessage()).matches()) {
174+
if (isAllowedError(query.exception().getMessage(), allowedError)) {
175175
return;
176176
}
177177
}
178178
fail("query: " + query.query() + "\nexception: " + query.exception().getMessage());
179179
}
180180

181+
/**
182+
* Long lines in exceptions can be split across several lines. When a newline is inserted, the end of the current line and the beginning
183+
* of the new line are marked with a backslash {@code \}; the new line will also have whitespace before the backslash for aligning.
184+
*/
185+
private static final Pattern ERROR_MESSAGE_LINE_BREAK = Pattern.compile("\\\\\n\\s*\\\\ ");
186+
187+
private static boolean isAllowedError(String errorMessage, Pattern allowedPattern) {
188+
String errorWithoutLineBreaks = ERROR_MESSAGE_LINE_BREAK.matcher(errorMessage).replaceAll("");
189+
return allowedPattern.matcher(errorWithoutLineBreaks).matches();
190+
}
191+
181192
@SuppressWarnings("unchecked")
182193
public static EsqlQueryGenerator.QueryExecuted execute(String command, int depth, @Nullable ProfileLogger profileLogger) {
183194
try {

0 commit comments

Comments
 (0)