Skip to content

Commit 5342b63

Browse files
authored
Merge pull request #145 from Codeplain-ai/feat/show_unrecoverable_test_error_details
add unit test stdout (error details) to renderFailed state
1 parent 2a004b1 commit 5342b63

7 files changed

Lines changed: 39 additions & 11 deletions

File tree

render_machine/actions/run_conformance_tests.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from typing import Any
23

34
import render_machine.render_utils as render_utils
@@ -16,6 +17,8 @@ class RunConformanceTests(BaseAction):
1617
UNRECOVERABLE_ERROR_OUTCOME = "unrecoverable_error_occurred"
1718

1819
def execute(self, render_context: RenderContext, _previous_action_payload: Any | None):
20+
conformance_tests_script = os.path.normpath(render_context.conformance_tests_script)
21+
1922
if render_context.module_name == render_context.conformance_tests_running_context.current_testing_module_name:
2023
conformance_tests_folder_name = (
2124
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 |
3235

3336
if render_context.verbose:
3437
console.info(
35-
f"Running conformance tests script {render_context.conformance_tests_script} "
38+
f"Running conformance tests script {conformance_tests_script} "
3639
+ f"for {conformance_tests_folder_name} ("
3740
+ f"functionality {render_context.conformance_tests_running_context.current_testing_frid} "
3841
+ f"in module {render_context.conformance_tests_running_context.current_testing_module_name}"
3942
+ ")."
4043
)
4144
exit_code, conformance_tests_issue, conformance_tests_temp_file_path = render_utils.execute_script(
42-
render_context.conformance_tests_script,
45+
conformance_tests_script,
4346
[render_context.build_folder, conformance_tests_folder_name],
4447
render_context.verbose,
4548
"Conformance Tests",
@@ -72,9 +75,9 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
7275
RenderError.encode(
7376
message=conformance_tests_issue,
7477
error_type="ENVIRONMENT_ERROR",
75-
exit_code=exit_code,
76-
script=render_context.conformance_tests_script,
78+
script=conformance_tests_script,
7779
frid=render_context.conformance_tests_running_context.current_testing_frid,
80+
issue=conformance_tests_issue,
7881
).to_payload(),
7982
)
8083

render_machine/actions/run_unit_tests.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from typing import Any
23

34
import render_machine.render_utils as render_utils
@@ -15,12 +16,14 @@ class RunUnitTests(BaseAction):
1516
UNRECOVERABLE_ERROR_OUTCOME = "unrecoverable_error_occurred"
1617

1718
def execute(self, render_context: RenderContext, _previous_action_payload: Any | None):
19+
unittests_script = os.path.normpath(render_context.unittests_script)
20+
1821
if render_context.verbose:
1922
console.info(
20-
f"Running unit tests script {render_context.unittests_script}. (attempt: {render_context.unit_tests_running_context.fix_attempts + 1})"
23+
f"Running unit tests script {unittests_script}. (attempt: {render_context.unit_tests_running_context.fix_attempts + 1})"
2124
)
2225
exit_code, unittests_issue, unittests_temp_file_path = render_utils.execute_script(
23-
render_context.unittests_script,
26+
unittests_script,
2427
[render_context.build_folder],
2528
render_context.verbose,
2629
"Unit Tests",
@@ -35,13 +38,14 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
3538

3639
elif exit_code in UNRECOVERABLE_ERROR_EXIT_CODES:
3740
console.error(unittests_issue)
41+
3842
return (
3943
self.UNRECOVERABLE_ERROR_OUTCOME,
4044
RenderError.encode(
4145
message="Unit tests script failed due to problems in the environment setup. Please check your environment or update the script for running unittests.",
4246
error_type="ENVIRONMENT_ERROR",
43-
exit_code=exit_code,
44-
script=render_context.unittests_script,
47+
script=unittests_script,
48+
issue=unittests_issue,
4549
).to_payload(),
4650
)
4751
else:

render_machine/render_types.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ def format_for_display(self) -> str:
133133
if self.details:
134134
lines.append("\nDetails:")
135135
for detail_name, detail_value in self.details.items():
136-
lines.append(f" {detail_name}: {detail_value}")
136+
if detail_name == "issue":
137+
detail_value_indented = "\n".join(" " + line for line in detail_value.splitlines())
138+
lines.append(detail_value_indented)
139+
else:
140+
lines.append(f" {detail_name.capitalize()}: {detail_value}")
137141

138142
return "\n".join(lines)
139143

render_machine/render_utils.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fcntl
22
import os
3+
import re
34
import signal
45
import subprocess
56
import sys
@@ -73,6 +74,17 @@ def _kill_process(proc: subprocess.Popen) -> None:
7374
proc.kill()
7475

7576

77+
def _sanitize_script_output(script_output: str) -> str:
78+
# this function removes the escape codes that clear the console
79+
clear_console_escape_codes_pattern = r"(?:\033\[[^a-zA-Z]*[a-zA-Z])*\033\[2J(?:\033\[[^a-zA-Z]*[a-zA-Z])*"
80+
81+
pattern = re.compile(clear_console_escape_codes_pattern)
82+
parts = pattern.split(script_output)
83+
84+
# take only the part after the last clear console escape code
85+
return parts[-1] if len(parts) > 1 else script_output
86+
87+
7688
def execute_script( # noqa: C901
7789
script: str,
7890
scripts_args: list[str],
@@ -132,13 +144,15 @@ def execute_script( # noqa: C901
132144
stdout = ""
133145
elapsed_time = time.time() - start_time
134146

147+
sanitized_script_output = _sanitize_script_output(stdout)
148+
135149
# Log the info about the script execution
136150
if verbose:
137151
with tempfile.NamedTemporaryFile(
138152
mode="w+", encoding="utf-8", delete=False, suffix=".script_output"
139153
) as temp_file:
140154
temp_file.write(f"\n═════════════════════════ {script_type} Script Output ═════════════════════════\n")
141-
temp_file.write(stdout)
155+
temp_file.write(sanitized_script_output)
142156
temp_file.write("\n══════════════════════════════════════════════════════════════════════\n")
143157
temp_file_path = temp_file.name
144158
if proc.returncode != 0:
@@ -166,7 +180,7 @@ def execute_script( # noqa: C901
166180
else:
167181
console.info(f"[#79FC96]All {script_type} scripts have passed successfully.[/#79FC96]")
168182

169-
return proc.returncode, stdout, temp_file_path
183+
return proc.returncode, sanitized_script_output, temp_file_path
170184

171185
except RenderCancelledError:
172186
raise

test_scripts/run_unittests_golang.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ cp -R $1/* $GO_BUILD_SUBFOLDER
3737
cd "$GO_BUILD_SUBFOLDER" 2>/dev/null
3838

3939
if [ $? -ne 0 ]; then
40+
clear
4041
printf "Error: Go build folder '$GO_BUILD_SUBFOLDER' does not exist.\n"
4142
exit $UNRECOVERABLE_ERROR_EXIT_CODE
4243
fi

test_scripts/run_unittests_python.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ cp -R $1/* $PYTHON_BUILD_SUBFOLDER
4747
cd "$PYTHON_BUILD_SUBFOLDER" 2>/dev/null
4848

4949
if [ $? -ne 0 ]; then
50+
clear
5051
printf "Error: Python build folder '$PYTHON_BUILD_SUBFOLDER' does not exist.\n"
5152
exit $UNRECOVERABLE_ERROR_EXIT_CODE
5253
fi

test_scripts/run_unittests_react.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ cp -R $1/* $NODE_SUBFOLDER
4545
cd "$NODE_SUBFOLDER" 2>/dev/null
4646

4747
if [ $? -ne 0 ]; then
48+
clear
4849
echo "Error: Subfolder '$1' does not exist."
4950
exit $UNRECOVERABLE_ERROR_EXIT_CODE
5051
fi

0 commit comments

Comments
 (0)