|
12 | 12 | LOCAL_CONF_MTIME = None |
13 | 13 |
|
14 | 14 |
|
| 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 | + |
15 | 38 | def test_series(tree, thing, result_dir) -> Tuple[int, str]: |
16 | 39 | # Read in the config, cache it between executions |
17 | 40 | global LOCAL_CONF, LOCAL_CONF_MTIME |
@@ -62,32 +85,20 @@ def test_series(tree, thing, result_dir) -> Tuple[int, str]: |
62 | 85 | cmd, |
63 | 86 | capture_output=True, |
64 | 87 | text=True, |
65 | | - timeout=10, |
| 88 | + timeout=20, |
66 | 89 | check=False |
67 | 90 | ) |
68 | 91 |
|
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) |
79 | 94 |
|
80 | 95 | if result.returncode != 0: |
81 | 96 | return 250, "Submit tool error" |
82 | 97 |
|
83 | 98 | return 111, "Submitted for review" |
84 | 99 |
|
85 | 100 | except subprocess.TimeoutExpired: |
86 | | - return 250, "Command timed out after 30 seconds" |
| 101 | + return 250, "Command timed out after 20 seconds" |
87 | 102 | 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)) |
93 | 104 | return 250, "Submit tool exception" |
0 commit comments