|
8 | 8 |
|
9 | 9 | from codeflash.code_utils.code_utils import ( |
10 | 10 | cleanup_paths, |
| 11 | + exit_with_message, |
11 | 12 | file_name_from_test_module_name, |
12 | 13 | file_path_from_module_name, |
13 | 14 | get_all_function_names, |
@@ -751,3 +752,33 @@ def __init__(self): |
751 | 752 | """ |
752 | 753 | result = validate_python_code(code) |
753 | 754 | assert result == code |
| 755 | + |
| 756 | + |
| 757 | +class TestExitWithMessageSubagent: |
| 758 | + @patch("codeflash.code_utils.code_utils.is_subagent_mode", return_value=True) |
| 759 | + def test_outputs_structured_xml_in_subagent_mode(self, _mock_subagent: MagicMock, capsys: pytest.CaptureFixture[str]) -> None: |
| 760 | + with pytest.raises(SystemExit) as exc_info: |
| 761 | + exit_with_message("Something went wrong", error_on_exit=True) |
| 762 | + assert exc_info.value.code == 1 |
| 763 | + captured = capsys.readouterr() |
| 764 | + assert "<codeflash-error>" in captured.out |
| 765 | + assert "Something went wrong" in captured.out |
| 766 | + assert "</codeflash-error>" in captured.out |
| 767 | + |
| 768 | + @patch("codeflash.code_utils.code_utils.is_subagent_mode", return_value=True) |
| 769 | + def test_escapes_xml_special_chars(self, _mock_subagent: MagicMock, capsys: pytest.CaptureFixture[str]) -> None: |
| 770 | + with pytest.raises(SystemExit): |
| 771 | + exit_with_message('File <foo> & "bar" not found', error_on_exit=True) |
| 772 | + captured = capsys.readouterr() |
| 773 | + assert "<foo>" in captured.out |
| 774 | + assert "&" in captured.out |
| 775 | + |
| 776 | + @patch("codeflash.code_utils.code_utils.is_subagent_mode", return_value=False) |
| 777 | + @patch("codeflash.code_utils.code_utils.is_LSP_enabled", return_value=False) |
| 778 | + def test_no_xml_when_not_subagent( |
| 779 | + self, _mock_lsp: MagicMock, _mock_subagent: MagicMock, capsys: pytest.CaptureFixture[str] |
| 780 | + ) -> None: |
| 781 | + with pytest.raises(SystemExit): |
| 782 | + exit_with_message("Normal error", error_on_exit=True) |
| 783 | + captured = capsys.readouterr() |
| 784 | + assert "<codeflash-error>" not in captured.out |
0 commit comments