From ab2b3318c3e2609d6d7f83646ced4bdba5a9f362 Mon Sep 17 00:00:00 2001 From: Alexander Spies Date: Mon, 4 Aug 2025 13:02:34 +0200 Subject: [PATCH] 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. --- muted-tests.yml | 3 --- .../qa/rest/generative/GenerativeRestTest.java | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/muted-tests.yml b/muted-tests.yml index 5e64ea2748ed1..4560306137cfa 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -509,9 +509,6 @@ tests: - class: org.elasticsearch.xpack.sql.qa.mixed_node.SqlCompatIT method: testNullsOrderWithMissingOrderSupportQueryingNewNode issue: https://github.com/elastic/elasticsearch/issues/132249 -- class: org.elasticsearch.xpack.esql.qa.multi_node.GenerativeIT - method: test - issue: https://github.com/elastic/elasticsearch/issues/132273 - class: org.elasticsearch.common.logging.JULBridgeTests method: testThrowable issue: https://github.com/elastic/elasticsearch/issues/132280 diff --git a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java index 053f026cd0eda..6bedc96fd5a59 100644 --- a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java +++ b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java @@ -160,7 +160,7 @@ private static CommandGenerator.ValidationResult checkResults( ); if (outputValidation.success() == false) { for (Pattern allowedError : ALLOWED_ERROR_PATTERNS) { - if (allowedError.matcher(outputValidation.errorMessage()).matches()) { + if (isAllowedError(outputValidation.errorMessage(), allowedError)) { return outputValidation; } } @@ -171,13 +171,24 @@ private static CommandGenerator.ValidationResult checkResults( private void checkException(EsqlQueryGenerator.QueryExecuted query) { for (Pattern allowedError : ALLOWED_ERROR_PATTERNS) { - if (allowedError.matcher(query.exception().getMessage()).matches()) { + if (isAllowedError(query.exception().getMessage(), allowedError)) { return; } } fail("query: " + query.query() + "\nexception: " + query.exception().getMessage()); } + /** + * Long lines in exceptions can be split across several lines. When a newline is inserted, the end of the current line and the beginning + * of the new line are marked with a backslash {@code \}; the new line will also have whitespace before the backslash for aligning. + */ + private static final Pattern ERROR_MESSAGE_LINE_BREAK = Pattern.compile("\\\\\n\\s*\\\\"); + + private static boolean isAllowedError(String errorMessage, Pattern allowedPattern) { + String errorWithoutLineBreaks = ERROR_MESSAGE_LINE_BREAK.matcher(errorMessage).replaceAll(""); + return allowedPattern.matcher(errorWithoutLineBreaks).matches(); + } + @SuppressWarnings("unchecked") public static EsqlQueryGenerator.QueryExecuted execute(String command, int depth, @Nullable ProfileLogger profileLogger) { try {