From 18d17250fec237705ffe4835fedc4b1b39d7d2a5 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 00:42:01 +0800 Subject: [PATCH] fix(report): with VedAstro off the local chart still goes to the top of the reading, so the report packet has D1 and personal reports stop failing as calculation_unavailable (BUG-2429) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8 --- docs/BUG_HISTORY.md | 17 ++++++ scripts/vedastro_priority.py | 6 ++ .../test_report_core_chart_switch_off_2429.py | 60 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 tests/test_report_core_chart_switch_off_2429.py diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index d0c443f56..42bc8acee 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -33180,3 +33180,20 @@ - **防复发**:总开关默认关闭;替换本地盘只在一处、且以回显核对为前提;新测试锁住零调用。 - **关联记录**:BUG-2172 / BUG-2171(#327 调用失败与回显核对)、BUG-1508、BUG-734。 - **修复版本**:下一版(staging)。 + +## BUG-2429 | 关掉 VedAstro 后个人报告全部失败:报告包里没有 D1 盘,长报告快照校验不过,报 `calculation_unavailable`(「这份报告没有写成,点数已退回」) + +- **状态**:resolved(仓库内,未推送;待 staging 部署后由负责人复测一份个人报告)。 +- **现象**:staging 4b8a64535 上负责人生成个人报告,失败码 `calculation_unavailable`,点数退回;`/api/health` 正常。 +- **触发条件**:BUG-2427 之后 VedAstro 开关默认关闭(staging 未设 `VEDASTRO_ENABLED`)。与出生资料无关,公开案例同样失败。 +- **排查**: + - 先查了 BUG-2416 只读容器:在只读根目录、只有 `/tmp` 和 `scratch/local` 可写的沙箱里起计算服务(含进程池),`/api/professional_report_reference` 三种入参(普通、时辰窗、候选区间)都返回 200;Python 审计钩子记录到的 `/tmp`、`scratch/local` 以外写入为 0。 + - 再查 BUG-2428 内存上限:单份报告计算进程峰值约 350 MB,主进程约 120 MB,没有接近 1.5 GB。 + - 用计算服务的真实返回跑前端 `generatePersonalReportLongform`:抛出 `longform_snapshot_generation_failed`,内层是快照 schema 对 `charts` 的校验失败——16 张盘里缺 D1。 +- **根因**:BUG-2427 在 `scripts/vedastro_priority.py::apply_vedastro_source_priority` 新增的关闭分支直接返回,没有像其它分支那样把本地盘的 `planets` / `ascendant` / `houses` 提到完整解读顶层。报告包 `core_chart` 因此只剩 `chart`,前端 `assembleLongformCharts` 取不到 D1,`validateLongformSnapshot` 拒收,每份个人报告都按 `calculation_unavailable` 失败并退点。正文 Markdown 也少了依赖 `core_chart.planets` 的内容(同一案例约少 6.5 万字符)。 +- **修复**:关闭分支也把本地盘的这三项提到顶层,盘本身不改写、不加回退说明、不写 `source`(BUG-2427 的约定不变)。修复后 `core_chart` 的上升、行星、宫位与 BUG-2427 之前(0054781bc)逐项相同,前端长报告流程返回 ready(8 张事实表、16 张盘)。冻结文件未改。 +- **验证**:新增 `tests/test_report_core_chart_switch_off_2429.py`(关闭包下顶层有本地盘三项且盘不变;开关默认关时公开案例报告包 `core_chart` 有上升、至少 9 颗行星和宫位);去掉修复时两条都失败。`tests/test_bug_2427_external_engine_switch_off.py`、`test_professional_report_reference_api`、`test_vedastro_official_full_snapshot` 及读 `core_chart` 的报告测试通过。 +- **为何没拦住**:前端长报告测试用的是静态引擎夹具,不经过真实计算;Python 报告测试只核对正文,没核对报告包里的 D1 输入;BUG-2427 的关闭用例只断言盘不被改写,没断言顶层字段。 +- **防复发**:新测试用真实计算锁住报告包 D1 输入;以后改 `apply_vedastro_source_priority` 任一分支都要保证顶层三项与本地盘一致。 +- **关联记录**:BUG-2427(引入)、BUG-2416 / BUG-2428(已排除)。 +- **修复版本**:`fix/bug-2429-report-calc`(未推送)。 diff --git a/scripts/vedastro_priority.py b/scripts/vedastro_priority.py index fe665d090..9612e9b74 100644 --- a/scripts/vedastro_priority.py +++ b/scripts/vedastro_priority.py @@ -240,6 +240,12 @@ def apply_vedastro_source_priority( if is_disabled_packet(official_snapshot): # BUG-2427: VedAstro is off by decision. The local chart is the chart; nothing is # rewritten and no "official blocked" fallback wording is attached to it. + # BUG-2429: the local chart's planets / ascendant / houses still go to the top of + # the report, as every other branch does. 原值:直接返回,顶层没有这三项,报告包的 + # core_chart 只剩 chart,D1 盘取不到,长报告快照校验失败(calculation_unavailable)。 + for key in ("planets", "ascendant", "houses"): + if key in local_chart: + report[key] = local_chart[key] modules["source_priority"] = { "mode": "local_engine_vedastro_disabled", "official_snapshot_status": "disabled", diff --git a/tests/test_report_core_chart_switch_off_2429.py b/tests/test_report_core_chart_switch_off_2429.py new file mode 100644 index 000000000..eb3020c23 --- /dev/null +++ b/tests/test_report_core_chart_switch_off_2429.py @@ -0,0 +1,60 @@ +"""BUG-2429: with the VedAstro switch off (BUG-2427 default) the personal report failed. + +BUG-2427's disabled branch of ``apply_vedastro_source_priority`` returned before +lifting the local chart's planets / ascendant / houses to the top of the full +reading, as every other branch does. The report packet's ``core_chart`` then had +only ``chart``; the web's longform snapshot had no D1 chart, its schema check +failed and every personal report ended as ``calculation_unavailable``. + +(Named without "vedastro" so tests/conftest.py keeps the product default: off.) +""" +from __future__ import annotations + +import json +import os + +from scripts import vedastro_switch + + +def _local_report() -> dict: + chart = { + "birth_info": {"date": "1990-06-15", "hour": 10, "minute": 20, "lat": 31.2, "lon": 121.5, "tz": 8}, + "ascendant": {"sign": "Leo", "sign_index": 4, "degree": 12.5}, + "planets": {"Sun": {"sign": "Gemini", "house": 11}, "Moon": {"sign": "Aries", "house": 9}}, + "houses": {"1": {"sign": "Leo"}}, + } + return {"chart": chart, "modules": {}} + + +def test_disabled_snapshot_still_puts_the_local_chart_on_top(): + from scripts.vedastro_priority import apply_vedastro_source_priority + + report = _local_report() + chart_before = json.dumps(report["chart"], sort_keys=True) + apply_vedastro_source_priority(report, official_snapshot=vedastro_switch.disabled_packet("vedastro_service_adapter")) + + for key in ("planets", "ascendant", "houses"): + assert report[key] == report["chart"][key], key + # BUG-2427 stays: the chart itself is not rewritten and carries no fallback wording. + assert json.dumps(report["chart"], sort_keys=True) == chart_before + assert "fallback_reason" not in report["chart"] + assert "source" not in report + assert report["modules"]["source_priority"]["mode"] == "local_engine_vedastro_disabled" + + +def test_full_report_packet_core_chart_has_d1_with_the_switch_off(): + assert os.environ.get("VEDASTRO_ENABLED") is None # product default, as on staging + from scripts.report_density_packet import report_density_packet + from tests.public_chart_reports import public_chart_reports + + packet, _, _ = public_chart_reports("steve_jobs_1955_aa") + core = report_density_packet(packet)["core_chart"] + # What frontend assembleLongformCharts reads for D1 (personal-report-generation.ts): + # core_chart.ascendant.sign(_index) and core_chart.planets..house|sign. + ascendant = core.get("ascendant") + assert isinstance(ascendant, dict) and ascendant.get("sign"), core.keys() + planets = core.get("planets") + assert isinstance(planets, dict) and len(planets) >= 9 + assert all(isinstance(row, dict) and (row.get("house") or row.get("sign")) for row in planets.values()) + assert isinstance(core.get("houses"), (dict, list)) and core["houses"] + assert planets == core["chart"]["planets"]