import unittest from app.features.story.backfill import backfill_image_into_markdown class StoryBackfillTest(unittest.TestCase): def test_appends_image_at_end_with_prompt_brief_alt(self): md = "第一段\n\n第二段" out = backfill_image_into_markdown(md, "aid-1", "院子里的藤椅") self.assertTrue(out.endswith("](asset://aid-1)\n")) self.assertIn("第二段", out) self.assertLess(out.index("第二段"), out.index("![")) def test_empty_markdown_is_only_image_ref(self): out = backfill_image_into_markdown("", "x", "提示") self.assertEqual(out, "![提示](asset://x)") def test_escapes_bracket_in_alt(self): out = backfill_image_into_markdown("正文", "a", "说明]尾") self.assertIn(r"说明\]", out)