From a7634ad1bfebbe1b027310873d0093f166f099da Mon Sep 17 00:00:00 2001 From: Alexander Spies Date: Mon, 4 Aug 2025 17:00:41 +0200 Subject: [PATCH] ESQL: Fix skipping of generative tests (#132390) 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. (cherry picked from commit ccfbf490334bca674412da7db3dc28806544c917) # Conflicts: # muted-tests.yml --- .../qa/rest/generative/GenerativeRestTest.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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 e997995e50b9d..bf4f1e76f1860 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 @@ -144,7 +144,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; } } @@ -155,13 +155,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") private EsqlQueryGenerator.QueryExecuted execute(String command, int depth) { try {