|
1 | 1 | import time |
| 2 | +from io import StringIO |
| 3 | + |
| 4 | +from rich.console import Console |
2 | 5 |
|
3 | 6 | from planemo.galaxy.invocations.progress import ( |
4 | 7 | WorkflowProgress, |
@@ -168,3 +171,37 @@ def test_workflow_progress_completed_step_state_counting(): |
168 | 171 | workflow_progress.step_states.get("completed") or 0 |
169 | 172 | ) |
170 | 173 | assert num_scheduled == 2 |
| 174 | + |
| 175 | + |
| 176 | +def test_format_job_error_details_escapes_rich_markup(): |
| 177 | + # Regression: failed-job stderr containing strings like Java's Arrays.toString |
| 178 | + # output (e.g. ImageJ --debug) starts with "[/tmp/..." which rich's markup parser |
| 179 | + # treats as a closing tag and rejects with MarkupError, masking the real failure. |
| 180 | + bracketed_argv = ( |
| 181 | + "[/tmp/shed_dir/toolshed.g2.bx.psu.edu/repos/imgteam/imagej2_analyze_particles_binary/" |
| 182 | + "862af85a50ec/imagej2_analyze_particles_binary/imagej2_analyze_particles_binary_jython_script.py, " |
| 183 | + "/tmp/job/outputs/dataset_cc.dat, /tmp/files/dataset_99.dat, " |
| 184 | + "yes, 50-Infinity, 0.0, 1.0, Outlines, no, no, no, output.tiff, tiff, ]" |
| 185 | + ) |
| 186 | + job_details = { |
| 187 | + "exit_code": 1, |
| 188 | + "tool_id": "toolshed.g2.bx.psu.edu/repos/imgteam/imagej2_analyze_particles_binary/" |
| 189 | + "imagej2_analyze_particles_binary/20240614+galaxy0", |
| 190 | + "command_line": "ImageJ --jython /tmp/shed_dir/script.py /tmp/input.dat", |
| 191 | + "stdout": "", |
| 192 | + "stderr": bracketed_argv, |
| 193 | + } |
| 194 | + |
| 195 | + with WorkflowProgress(DisplayConfiguration()) as workflow_progress: |
| 196 | + lines = workflow_progress._format_job_error_details("JOB_ID_42", job_details) |
| 197 | + |
| 198 | + # Render through a Console with markup parsing on (the default) to ensure |
| 199 | + # the assembled output does not blow up rich. |
| 200 | + console = Console(file=StringIO(), force_terminal=False, width=200) |
| 201 | + console.print("\n".join(lines)) # would raise MarkupError before the fix |
| 202 | + output = console.file.getvalue() |
| 203 | + |
| 204 | + # Content must be preserved verbatim, not stripped. |
| 205 | + assert "/tmp/shed_dir/" in output |
| 206 | + assert "output.tiff" in output |
| 207 | + assert "20240614+galaxy0" in output |
0 commit comments