@@ -1110,6 +1110,49 @@ def test_sync_with_jira_no_matching(
11101110 )
11111111 mock_existing_jira_issue_legacy .assert_not_called ()
11121112
1113+ @mock .patch (PATH + "pypandoc" )
1114+ def test_convert_content (self , mock_pypandoc ):
1115+ """convert_content(): normal success, TeX fallback, and double failure."""
1116+ # Case 1: Normal GFM conversion succeeds
1117+ mock_pypandoc .convert_text .return_value = "normal markdown"
1118+
1119+ result = d .convert_content ("normal markdown" )
1120+
1121+ mock_pypandoc .convert_text .assert_called_once_with (
1122+ "normal markdown" , "jira" , format = "gfm"
1123+ )
1124+ self .assertEqual (result , "normal markdown" )
1125+
1126+ # Case 2: First call fails (TeX error), fallback succeeds
1127+ mock_pypandoc .convert_text .reset_mock ()
1128+ mock_pypandoc .convert_text .side_effect = [
1129+ RuntimeError ("Error producing PDF" ),
1130+ "fallback converted" ,
1131+ ]
1132+
1133+ result = d .convert_content ("bad $tex" )
1134+
1135+ self .assertEqual (mock_pypandoc .convert_text .call_count , 2 )
1136+ first_call = mock_pypandoc .convert_text .call_args_list [0 ]
1137+ self .assertEqual (first_call [1 ]["format" ], "gfm" )
1138+
1139+ fallback_call = mock_pypandoc .convert_text .call_args_list [1 ]
1140+ self .assertEqual (
1141+ fallback_call [1 ]["format" ],
1142+ "gfm-tex_math_dollars-tex_math_single_backslash" ,
1143+ )
1144+ self .assertEqual (fallback_call [0 ][0 ], "bad \\ $tex" )
1145+ self .assertEqual (result , "fallback converted" )
1146+
1147+ # Case 3: Both calls fail, raw content preserved
1148+ mock_pypandoc .convert_text .reset_mock ()
1149+ mock_pypandoc .convert_text .side_effect = RuntimeError ("pandoc broken" )
1150+
1151+ result = d .convert_content ("raw content" )
1152+
1153+ self .assertEqual (mock_pypandoc .convert_text .call_count , 2 )
1154+ self .assertEqual (result , "raw content" )
1155+
11131156 @mock .patch (PATH + "_update_title" )
11141157 @mock .patch (PATH + "_update_description" )
11151158 @mock .patch (PATH + "_update_comments" )
0 commit comments