Skip to content

Commit 9df27bc

Browse files
committed
tests: ai-review: adjust the output
Make sure the output is also cleaned up. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 8168a3b commit 9df27bc

1 file changed

Lines changed: 28 additions & 17 deletions

File tree

tests/series/ai-review/test.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@
1212
LOCAL_CONF_MTIME = None
1313

1414

15+
def _write_output(output_dir, cmd, exit_code=None,
16+
stdout=None, stderr=None, exception=None):
17+
"""Write sanitized command output to the outputs file."""
18+
# Extract the token before building output
19+
token_idx = cmd.index("--token") + 1
20+
token = cmd[token_idx]
21+
22+
# Build the output string
23+
output = f"Command: {' '.join(cmd)}\n"
24+
if exit_code is not None:
25+
output += f"Exit code: {exit_code}\n"
26+
output += f"\n--- STDOUT ---\n{stdout}"
27+
output += f"\n--- STDERR ---\n{stderr}"
28+
if exception is not None:
29+
output += f"Exception: {exception}\n"
30+
31+
# Sanitize and write
32+
output = output.replace(token, "$TOKEN")
33+
stdout_path = os.path.join(output_dir, "outputs")
34+
with open(stdout_path, "w", encoding="utf-8") as f:
35+
f.write(output)
36+
37+
1538
def test_series(tree, thing, result_dir) -> Tuple[int, str]:
1639
# Read in the config, cache it between executions
1740
global LOCAL_CONF, LOCAL_CONF_MTIME
@@ -62,32 +85,20 @@ def test_series(tree, thing, result_dir) -> Tuple[int, str]:
6285
cmd,
6386
capture_output=True,
6487
text=True,
65-
timeout=10,
88+
timeout=20,
6689
check=False
6790
)
6891

69-
# Hide the secret
70-
cmd[cmd.index("--token") + 1] = "$TOKEN"
71-
72-
# Write stdout/stderr to result_dir/series_id/outputs
73-
stdout_path = os.path.join(series_output_dir, "outputs")
74-
with open(stdout_path, "w", encoding="utf-8") as f:
75-
f.write(f"Command: {' '.join(cmd)}\n")
76-
f.write(f"Exit code: {result.returncode}\n")
77-
f.write(f"\n--- STDOUT ---\n{result.stdout}")
78-
f.write(f"\n--- STDERR ---\n{result.stderr}")
92+
_write_output(series_output_dir, cmd, exit_code=result.returncode,
93+
stdout=result.stdout, stderr=result.stderr)
7994

8095
if result.returncode != 0:
8196
return 250, "Submit tool error"
8297

8398
return 111, "Submitted for review"
8499

85100
except subprocess.TimeoutExpired:
86-
return 250, "Command timed out after 30 seconds"
101+
return 250, "Command timed out after 20 seconds"
87102
except Exception as e:
88-
# Write error to stdout file
89-
stdout_path = os.path.join(series_output_dir, "outputs")
90-
with open(stdout_path, "w", encoding="utf-8") as f:
91-
f.write(f"Command: {' '.join(cmd)}\n")
92-
f.write(f"Exception: {str(e)}\n")
103+
_write_output(series_output_dir, cmd, exception=str(e))
93104
return 250, "Submit tool exception"

0 commit comments

Comments
 (0)