fix(report): use the upstream reader edition for new longform bodies

New reports request reader_main from upstream origin/main 23b9609e.
KP and transit no longer copy an empty vars() dict, solar returns keep
birth_asc_sign_idx, and ordinary projection deletes internal lines whole.
This commit is contained in:
jesse-ux
2026-09-25 02:21:46 +08:00
parent 59c2301838
commit 3c2f7bd559
22 changed files with 3126 additions and 65 deletions
+34 -1
View File
@@ -26,6 +26,24 @@ class ProfessionalReportReferenceInputError(ValueError):
"""The professional-reference request is outside the public contract."""
READER_MAIN_EDITION = "reader_main"
REFERENCE_EDITION = "reference"
REPORT_VERSION_READER = "pl9_personal_long_report.v3"
def _normalize_edition(value: Any) -> str:
if value is None or value == "":
return REFERENCE_EDITION
if not isinstance(value, str):
raise ProfessionalReportReferenceInputError("edition must be a string")
normalized = value.strip()
if normalized in {"", REFERENCE_EDITION, "professional_reference"}:
return REFERENCE_EDITION
if normalized == READER_MAIN_EDITION:
return READER_MAIN_EDITION
raise ProfessionalReportReferenceInputError("edition must be reference or reader_main")
def _normalize_format(value: Any) -> str:
if value is None:
return "json"
@@ -100,6 +118,7 @@ def build_professional_report_reference(handler, body: dict[str, Any], *, engine
if not isinstance(body, dict):
raise ProfessionalReportReferenceInputError("request body must be an object")
output_format = _normalize_format(body.get("format"))
edition = _normalize_edition(body.get("edition"))
packs = _normalize_packs(body.get("packs"))
birth = handler._high_rigor_birth_payload(body)
@@ -114,15 +133,29 @@ def build_professional_report_reference(handler, body: dict[str, Any], *, engine
except ValueError as exc:
raise ProfessionalReportReferenceInputError(str(exc)) from exc
if edition == READER_MAIN_EDITION and isinstance(packet, dict):
packet = dict(packet)
packet["report_version"] = REPORT_VERSION_READER
if output_format == "markdown":
if edition == READER_MAIN_EDITION:
try:
from scripts.pl9_reader_export import _pl9_export_markdown_for_edition
except ModuleNotFoundError: # pragma: no cover - direct scripts/ execution path
from pl9_reader_export import _pl9_export_markdown_for_edition
markdown = _pl9_export_markdown_for_edition(packet, READER_MAIN_EDITION)
else:
markdown = resolved_engine.render_pl9_markdown(packet)
return {
"format": "markdown",
"markdown": resolved_engine.render_pl9_markdown(packet),
"edition": edition,
"report_version": REPORT_VERSION_READER if edition == READER_MAIN_EDITION else packet.get("report_version"),
"markdown": markdown,
**({"fact_table_packet": report_density_packet(packet),
"reader_dasha_applicability": clean_reader_appendix_markdown(render_dasha_applicability(packet))}
if body.get("include_fact_tables") is True else {}),
}
return {
"format": "json",
"edition": edition,
"report": packet,
}