fix: preserve exports on close and support themed PDF without export quotas

This commit is contained in:
2026-09-07 14:04:03 +08:00
parent 47c53b6f38
commit 9f097ea629
20 changed files with 485 additions and 123 deletions
+6 -6
View File
@@ -334,17 +334,16 @@ def test_pdf_exporter_function_plot_fallback_on_error() -> None:
assert any("函数图像" in w for w in result.warnings)
def test_pdf_exporter_limits_function_plot_count() -> None:
def test_pdf_exporter_has_no_function_plot_count_quota() -> None:
from app.export.exporters.pdf import PdfExporter
blocks = "\n\n".join("```function-plot\ny = x\n```" for _ in range(20))
result = asyncio.run(PdfExporter().export(parse_document(blocks), ExportOptions()))
assert result.content[:4] == b"%PDF"
# 超出数量上限的图块回退占位并记 warning
assert any("数量超过上限" in w for w in result.warnings)
assert not any("函数图像" in w for w in result.warnings)
def test_pdf_exporter_limits_total_plot_nodes(monkeypatch) -> None:
def test_pdf_exporter_has_no_total_plot_node_quota(monkeypatch) -> None:
import app.export.exporters._common as common_mod
from app.export.exporters.pdf import PdfExporter
@@ -352,7 +351,7 @@ def test_pdf_exporter_limits_total_plot_nodes(monkeypatch) -> None:
md = "```function-plot\ny = x\n```\n\n```function-plot\ny = x + x + x + x\n```"
result = asyncio.run(PdfExporter().export(parse_document(md), ExportOptions()))
assert result.content[:4] == b"%PDF"
assert any("累计复杂度" in w for w in result.warnings)
assert not any("函数图像" in w for w in result.warnings)
def test_docx_exporter_embeds_plot_and_warns_missing_mermaid() -> None:
@@ -831,7 +830,8 @@ def test_callout_formats(name):
xml = z.read("word/document.xml").decode()
assert all(word in xml for word in ["Title", "Body", "item", "second", "w:shd"])
result = PdfExporter().render(doc, ExportOptions(theme_id="sepia"))
assert result.content.startswith(b"%PDF") and len(result.warnings) == 1
assert result.content.startswith(b"%PDF")
assert not any("浅色打印" in warning for warning in result.warnings)
@pytest.mark.parametrize("fold", ["", "+", "-"])