Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(shadow): keep the reportlab fallback on the probed font family

Yufeng He705f1a0e2748
diff --git a/agent/src/shadow_account/pdf_fallback.py b/agent/src/shadow_account/pdf_fallback.py
index dc2c2574d..24a7d8a27 100644
--- a/agent/src/shadow_account/pdf_fallback.py
+++ b/agent/src/shadow_account/pdf_fallback.py
@@ -24,14 +24,15 @@ logger = logging.getLogger(__name__)
# reportlab's TTFont only understands TrueType-flavored fonts. The first
# candidate that registers wins; .ttc files are tried with subfontIndex=0.
_FONT_FAMILY = "VibeShadowCJK"
-_font_ready: bool | None = None # None=unprobed, True=family registered
+_font_ready: bool = False # probe ran; says nothing about what it found
+_font_family: str = _FONT_FAMILY # family actually usable after the probe
def _ensure_font() -> str:
"""Register a CJK-capable TTF once and return the family name to use."""
- global _font_ready
+ global _font_ready, _font_family
if _font_ready:
- return _FONT_FAMILY
+ return _font_family
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
@@ -42,11 +43,13 @@ def _ensure_font() -> str:
except Exception:
continue
_font_ready = True
- return _FONT_FAMILY
+ _font_family = _FONT_FAMILY
+ return _font_family
logger.warning("No TrueType CJK font found; PDF fallback uses Helvetica.")
_font_ready = True
- return "Helvetica"
+ _font_family = "Helvetica"
+ return _font_family
def _file_uri_to_path(uri: str) -> Path | None:
diff --git a/agent/tests/test_shadow_account.py b/agent/tests/test_shadow_account.py
index 41144a896..1f92dc516 100644
--- a/agent/tests/test_shadow_account.py
+++ b/agent/tests/test_shadow_account.py
@@ -1093,6 +1093,33 @@ def test_pdf_degrades_to_html_only_when_both_engines_fail(
assert not (tmp_path / f"{profile.shadow_id}.pdf").exists()
+def test_reportlab_fallback_reuses_helvetica_when_no_cjk_font(
+ profitable_journal: Path, tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """On a fontless host every render must keep using Helvetica.
+
+ The first probe registers nothing, so a cached "probed" flag that reports
+ the CJK family name would hand platypus an unregistered font on the next
+ render (CI hit exactly this on the second reportlab test in a process).
+ """
+ from src.shadow_account import pdf_fallback, reporter
+
+ monkeypatch.setattr(reporter, "_WEASYPRINT_HTML", False)
+ monkeypatch.setattr(pdf_fallback, "system_cjk_candidates", lambda: [])
+ monkeypatch.setattr(pdf_fallback, "_font_ready", False)
+ profile = extract_shadow_profile(profitable_journal)
+ result = _stub_backtest_result(profile)
+
+ first = reporter.render_shadow_report(profile, result, output_dir=tmp_path / "a")
+ assert first["engine"] == "reportlab"
+ assert pdf_fallback._ensure_font() == "Helvetica"
+
+ second = reporter.render_shadow_report(profile, result, output_dir=tmp_path / "b")
+ assert second["engine"] == "reportlab"
+ assert Path(second["pdf_path"]).read_bytes()[:5] == b"%PDF-"
+
+
# ---------------- M5/M6: Tool wrappers + scanner ----------------
@pytest.mark.unit
diff --git a/desktop/electron/requirements-windows-lock.txt b/desktop/electron/requirements-windows-lock.txt
index 828e71cb3..f2676a563 100644
--- a/desktop/electron/requirements-windows-lock.txt
+++ b/desktop/electron/requirements-windows-lock.txt
@@ -3153,6 +3153,12 @@ regex==2026.7.19 \
--hash=sha256:fe31f28c94402043161876a258a9c6f757cb485905c7614ce8d6cd40e6b7bdc1 \
--hash=sha256:ffd8893ccc1c2fce6e0d6ca402d716fe1b29db70c7132609a05955e31b2aa8f2
# via tiktoken
+reportlab==5.0.1 \
+ --hash=sha256:1c36e6bb0e71780c72331eba60da7f602e8d4389a8723825af71342e49d791e8 \
+ --hash=sha256:ebd13154be1c8515e665de70bd2d303ae9ddc3ef47e44afd5116441ca0283a26
+ # via
+ # -r agent/requirements.txt
+ # vibe-trading-ai
requests==2.34.2 \
--hash=sha256:2a0d60c172f83ac6ab31e4554906c0f3b3588d37b5cb939b1c061f4907e278e0 \
--hash=sha256:f288924cae4e29463698d6d60bc6a4da69c89185ad1e0bcc4104f584e960b9ed