# -*- coding: utf-8 -*- """HTML 报告页薄写入 helper。""" from __future__ import annotations import os import unittest from _support import IsolatedDataRoot from service.html_page_service import ( HOST_HTML_RENDER_ACTION_ID, load_html_template, render_html_placeholders, write_html_page, ) class TestHtmlPageService(unittest.TestCase): def test_host_action_id_is_stable(self) -> None: self.assertEqual(HOST_HTML_RENDER_ACTION_ID, "render-html") def test_write_html_page_atomic_under_html_dir(self) -> None: with IsolatedDataRoot() as tmp: path = write_html_page( "example-report.html", "
hello
", }, ) self.assertIn("hello
", page) self.assertNotIn("{{TITLE}}", page) dest = write_html_page("example-report.html", page) self.assertTrue(os.path.isfile(dest)) def test_rejects_unsafe_filename(self) -> None: with IsolatedDataRoot(): with self.assertRaises(ValueError): write_html_page("../x.html", "") with self.assertRaises(ValueError): write_html_page("note.txt", "") def test_example_report_shell_embedded_preview_layout(self) -> None: """守护 example-report.html:数据管理 iframe 预览布局基线不退化。""" template = load_html_template("assets/html/example-report.html") self.assertIn("overflow-x: hidden", template) self.assertIn("min-width: 0", template) self.assertIn("table-layout: fixed", template) self.assertIn("overflow-wrap: anywhere", template) self.assertNotIn("max-width:", template) def test_actions_contract_keeps_shell_pages_and_call(self) -> None: from util.runtime_paths import get_skill_root root = get_skill_root() actions_path = os.path.join(root, "references", "ACTIONS.md") with open(actions_path, encoding="utf-8") as f: actions = f.read() self.assertIn("assets/html/pages", actions) self.assertIn("jiangchang.call", actions) self.assertTrue(os.path.isfile(os.path.join(root, "assets", "html", "example-report.html"))) self.assertFalse( os.path.isfile(os.path.join(root, "assets", "html", "pages", "example-report.html")) ) if __name__ == "__main__": unittest.main()