diff --git a/render_machine/actions/run_conformance_tests.py b/render_machine/actions/run_conformance_tests.py index 06402a4..d9f9d81 100644 --- a/render_machine/actions/run_conformance_tests.py +++ b/render_machine/actions/run_conformance_tests.py @@ -1,3 +1,4 @@ +import os from typing import Any import render_machine.render_utils as render_utils @@ -16,6 +17,8 @@ class RunConformanceTests(BaseAction): UNRECOVERABLE_ERROR_OUTCOME = "unrecoverable_error_occurred" def execute(self, render_context: RenderContext, _previous_action_payload: Any | None): + conformance_tests_script = os.path.normpath(render_context.conformance_tests_script) + if render_context.module_name == render_context.conformance_tests_running_context.current_testing_module_name: conformance_tests_folder_name = ( render_context.conformance_tests_running_context.get_current_conformance_test_folder_name() @@ -32,14 +35,14 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any | if render_context.verbose: console.info( - f"Running conformance tests script {render_context.conformance_tests_script} " + f"Running conformance tests script {conformance_tests_script} " + f"for {conformance_tests_folder_name} (" + f"functionality {render_context.conformance_tests_running_context.current_testing_frid} " + f"in module {render_context.conformance_tests_running_context.current_testing_module_name}" + ")." ) exit_code, conformance_tests_issue, conformance_tests_temp_file_path = render_utils.execute_script( - render_context.conformance_tests_script, + conformance_tests_script, [render_context.build_folder, conformance_tests_folder_name], render_context.verbose, "Conformance Tests", @@ -72,9 +75,9 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any | RenderError.encode( message=conformance_tests_issue, error_type="ENVIRONMENT_ERROR", - exit_code=exit_code, - script=render_context.conformance_tests_script, + script=conformance_tests_script, frid=render_context.conformance_tests_running_context.current_testing_frid, + issue=conformance_tests_issue, ).to_payload(), ) diff --git a/render_machine/actions/run_unit_tests.py b/render_machine/actions/run_unit_tests.py index 08d1728..938d2d9 100644 --- a/render_machine/actions/run_unit_tests.py +++ b/render_machine/actions/run_unit_tests.py @@ -1,3 +1,4 @@ +import os from typing import Any import render_machine.render_utils as render_utils @@ -15,12 +16,14 @@ class RunUnitTests(BaseAction): UNRECOVERABLE_ERROR_OUTCOME = "unrecoverable_error_occurred" def execute(self, render_context: RenderContext, _previous_action_payload: Any | None): + unittests_script = os.path.normpath(render_context.unittests_script) + if render_context.verbose: console.info( - f"Running unit tests script {render_context.unittests_script}. (attempt: {render_context.unit_tests_running_context.fix_attempts + 1})" + f"Running unit tests script {unittests_script}. (attempt: {render_context.unit_tests_running_context.fix_attempts + 1})" ) exit_code, unittests_issue, unittests_temp_file_path = render_utils.execute_script( - render_context.unittests_script, + unittests_script, [render_context.build_folder], render_context.verbose, "Unit Tests", @@ -35,13 +38,14 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any | elif exit_code in UNRECOVERABLE_ERROR_EXIT_CODES: console.error(unittests_issue) + return ( self.UNRECOVERABLE_ERROR_OUTCOME, RenderError.encode( message="Unit tests script failed due to problems in the environment setup. Please check your environment or update the script for running unittests.", error_type="ENVIRONMENT_ERROR", - exit_code=exit_code, - script=render_context.unittests_script, + script=unittests_script, + issue=unittests_issue, ).to_payload(), ) else: diff --git a/render_machine/render_types.py b/render_machine/render_types.py index 58ef1c9..91c17d5 100644 --- a/render_machine/render_types.py +++ b/render_machine/render_types.py @@ -133,7 +133,11 @@ def format_for_display(self) -> str: if self.details: lines.append("\nDetails:") for detail_name, detail_value in self.details.items(): - lines.append(f" {detail_name}: {detail_value}") + if detail_name == "issue": + detail_value_indented = "\n".join(" " + line for line in detail_value.splitlines()) + lines.append(detail_value_indented) + else: + lines.append(f" {detail_name.capitalize()}: {detail_value}") return "\n".join(lines) diff --git a/render_machine/render_utils.py b/render_machine/render_utils.py index f7d8dcb..3404284 100644 --- a/render_machine/render_utils.py +++ b/render_machine/render_utils.py @@ -1,4 +1,5 @@ import os +import re import signal import subprocess import sys @@ -70,6 +71,17 @@ def _kill_process(proc: subprocess.Popen) -> None: proc.kill() +def _sanitize_script_output(script_output: str) -> str: + # this function removes the escape codes that clear the console + clear_console_escape_codes_pattern = r"(?:\033\[[^a-zA-Z]*[a-zA-Z])*\033\[2J(?:\033\[[^a-zA-Z]*[a-zA-Z])*" + + pattern = re.compile(clear_console_escape_codes_pattern) + parts = pattern.split(script_output) + + # take only the part after the last clear console escape code + return parts[-1] if len(parts) > 1 else script_output + + def execute_script( # noqa: C901 script: str, scripts_args: list[str], @@ -125,13 +137,15 @@ def execute_script( # noqa: C901 stdout = "" elapsed_time = time.time() - start_time + sanitized_script_output = _sanitize_script_output(stdout) + # Log the info about the script execution if verbose: with tempfile.NamedTemporaryFile( mode="w+", encoding="utf-8", delete=False, suffix=".script_output" ) as temp_file: temp_file.write(f"\n═════════════════════════ {script_type} Script Output ═════════════════════════\n") - temp_file.write(stdout) + temp_file.write(sanitized_script_output) temp_file.write("\n══════════════════════════════════════════════════════════════════════\n") temp_file_path = temp_file.name if proc.returncode != 0: @@ -159,7 +173,7 @@ def execute_script( # noqa: C901 else: console.info(f"[#79FC96]All {script_type} scripts have passed successfully.[/#79FC96]") - return proc.returncode, stdout, temp_file_path + return proc.returncode, sanitized_script_output, temp_file_path except RenderCancelledError: raise diff --git a/test_scripts/run_unittests_golang.sh b/test_scripts/run_unittests_golang.sh index 56da7f1..87b6ffd 100755 --- a/test_scripts/run_unittests_golang.sh +++ b/test_scripts/run_unittests_golang.sh @@ -37,6 +37,7 @@ cp -R $1/* $GO_BUILD_SUBFOLDER cd "$GO_BUILD_SUBFOLDER" 2>/dev/null if [ $? -ne 0 ]; then + clear printf "Error: Go build folder '$GO_BUILD_SUBFOLDER' does not exist.\n" exit $UNRECOVERABLE_ERROR_EXIT_CODE fi diff --git a/test_scripts/run_unittests_python.sh b/test_scripts/run_unittests_python.sh index 56bfc5c..e2fe3b2 100755 --- a/test_scripts/run_unittests_python.sh +++ b/test_scripts/run_unittests_python.sh @@ -47,6 +47,7 @@ cp -R $1/* $PYTHON_BUILD_SUBFOLDER cd "$PYTHON_BUILD_SUBFOLDER" 2>/dev/null if [ $? -ne 0 ]; then + clear printf "Error: Python build folder '$PYTHON_BUILD_SUBFOLDER' does not exist.\n" exit $UNRECOVERABLE_ERROR_EXIT_CODE fi diff --git a/test_scripts/run_unittests_react.sh b/test_scripts/run_unittests_react.sh index 514bf15..eb93da3 100755 --- a/test_scripts/run_unittests_react.sh +++ b/test_scripts/run_unittests_react.sh @@ -45,6 +45,7 @@ cp -R $1/* $NODE_SUBFOLDER cd "$NODE_SUBFOLDER" 2>/dev/null if [ $? -ne 0 ]; then + clear echo "Error: Subfolder '$1' does not exist." exit $UNRECOVERABLE_ERROR_EXIT_CODE fi