Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a40cdc0eae | ||
|
|
2731c34bb7 | ||
|
|
65788b2525 | ||
|
|
9fcb4fbe41 |
@@ -1,5 +1,11 @@
|
||||
# BLOCKED
|
||||
|
||||
## #243 · Windows 全量门禁
|
||||
|
||||
- Docker Desktop 的 Linux 引擎返回 HTTP 500,前端数据库用例无法在本机完成。无 Docker 用例的 Windows 同机基线仍有既有失败。目录和预检用例在本机超时,Gitea 远端可见性已核对。
|
||||
- Python 快速门有 3 项 Kaala / PyJHora 校验失败,与 #242 的既有环境缺口相同。完整绿灯待独立验收环境复核。
|
||||
- 替代证据见 [#243 进度](docs/tasks/PROGRESS-reading-computed-fallback-20261113.md)。登录态报告真机走查留待独立验收。手机截图来自实际组件和构建样式。
|
||||
|
||||
## #242 · 公开盘模型验收与 Windows 门禁
|
||||
|
||||
- 两张公开盘各两次真实模型生成由 Claude 在验收主机运行。Windows Docker 引擎返回 HTTP 500,容器用例按既有条件跳过。
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# 印度占星 Skill 更新日志
|
||||
|
||||
## 2026-11-13 — 个人报告用盘面事实补齐解读章节
|
||||
|
||||
- 重写后仍未通过的章节以计算事实和证据等级呈现。「几条建议」没有可用稿时从正文、目录和导出省略。Skill 版本沿用当前版本(BUG-1877)。
|
||||
|
||||
## 2026-11-13 — 个人报告先修正解读标注,再重写未通过的章节
|
||||
|
||||
- 报告会自动修正可确定的依据标注,并在时限内合并重写请求。已通过核对的章节保留原文。Skill 版本沿用当前版本(BUG-1876)。
|
||||
|
||||
@@ -25297,6 +25297,18 @@
|
||||
- 关联记录:#219、#220、#240、#242、BUG-1860、BUG-1862、BUG-1863、BUG-1874。
|
||||
- 修复版本:`codex/reading-rebind-repair-20261113`,待发布。
|
||||
|
||||
## BUG-1877 | 个人报告仍显示解读章节的拦截提示
|
||||
|
||||
- 状态:fixed-pending-verify(本地定向回归通过,待 Claude 独立验收)。
|
||||
- 首次发现 / 最近更新:2026-11-13 / 2026-11-13。
|
||||
- 影响面:个人报告解读、阅读目录、Markdown 导出、存储回读与离线验收工具。
|
||||
- 现象与触发条件:逐节重写后仍被拦截的章节在页面和导出显示退回提示。依据节另有计算清单。
|
||||
- 根因:v3/v4 的逐节拦截结果被阅读页和导出作为可见章节处理,普通章节缺少事实包兜底。
|
||||
- 修复:生成端从同一事实包产出 v5 计算段落及 C/D 等级。省略失败的建议及无事实可用的旧章节。目录、阅读和导出同步。拦截记录保存在转换日志。
|
||||
- 验证与防复发:用真实引擎夹具及合成临界状态检查各领域事实、健康词检查、重写后持久化、v3/v4 回读、目录与 Markdown 一致性。验收工具记录计算兜底节数。
|
||||
- 关联记录:#243、#242、#218、BUG-1860、BUG-1863、BUG-1876。
|
||||
- 修复版本:`codex/reading-computed-fallback-20261113`,待发布。
|
||||
|
||||
## BUG-1857 | 年运 Tithi Pravesha 缺现居地,本命瑜伽证据截断
|
||||
|
||||
- 状态:fixed-pending-verify(待独立验收)。
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# #243 个人报告解读计算兜底
|
||||
|
||||
- 基线为 staging 的 `37deb3e3264b45a70768a920b7552a097dad0ac5`,包含 #242。执行分支为 `codex/reading-computed-fallback-20261113`。
|
||||
- 重写结束后,v5 保存原有通过章节及计算兜底。计算段落带来源与 C/D 等级。建议节没有可用文稿时省略。结构不合格或完全没有模型稿时仍沿用原有错误处理。整份草稿结构有效、但逐节核对均拦截时,也能从事实包生成兜底。
|
||||
- v3/v4 由服务端在已有事实包时补齐。历史快照只保存哈希的情况下,读取省略退回节。正文、目录、章节跳转及 Markdown 使用同一套可见章节。未通过的原因记录在后台转换日志。
|
||||
- 用产品默认 Raman 岁差、平均交点的公开盘引擎输出裁剪测试夹具。临界状态由测试注入。依据清单复用 #218 的依赖映射和说明,健康节通过 #218 的 `health_outcome` 检查。
|
||||
- Chromium 手机截图用 390 × 780 视口渲染真实报告解读组件及构建样式,取普通性格节和临界事业兜底节作对照,见 PR 附件。
|
||||
|
||||
## 断言变更
|
||||
|
||||
| 原值 | 新值 | 原因 |
|
||||
| --- | --- | --- |
|
||||
| 最终写入 v4,未通过的健康或事业节为 `withheld`,原因在该节上 | 写入 v5,事实不足时省略该节,后台转换日志保留原因和计数 | #243 的存储及公开投影 |
|
||||
| 页面与 Markdown 有退回文案及拦截原因 | 两端省略无事实可用的旧节,并同时检查旧文案、目录链接和退回原因不出现 | #243 的公开输出要求 |
|
||||
| 目录源码合同直接读取存储章节 | 目录使用正文和导出共用的可见章节函数 | 避免目录留下已省略章节的链接 |
|
||||
| 依据清单有模型文字未通过核对的提示 | 保留清单、原有标签与 Markdown 转义,改用计算依据引导句 | #218 清单并入兜底 |
|
||||
| 定向重写成功后的成稿无 `withheld` 项 | 每节状态为 `ok`,后台最终原因统计为空 | v5 中只保存交付章节 |
|
||||
| 快照规则的复查版本为 3 | 复查版本为 4,仍校验所有内容哈希及转换记录 | 最终交付新增计算兜底 |
|
||||
|
||||
## 验证
|
||||
|
||||
- 报告、快照和 Markdown 定向测试 70 项通过,取消 0。TypeScript 和 ESLint 通过,ESLint 有 62 条既有 warning。
|
||||
- Webpack 生产构建与同机基线通过,首页为静态。首页 HTML 直接引用的 gzip JS 从 475848 B 到 475846 B,CSS 从 91309 B 到 91300 B。Turbopack 拒绝跨工作树的依赖 junction,使用本地 webpack 构建作对照。
|
||||
- 真实引擎事实的离线验收回放中,`postcheck.json` 记录 2 节计算兜底,3 节原稿拦截,其中一节为省略的建议。
|
||||
- Windows 扩展前端测试逐名对比。基线共 3626 项,13 项失败,0 取消。分支共 3630 项,新增 4 项且既有名称无缺失。第一遍多出的目录源码断言已按上表更新,目录与兜底定向复跑 12 项全过。其余失败名称与基线逐项相同。Docker 专用用例的环境缺口见 `BLOCKED.md`。
|
||||
- Python 报告事实定向 25 项、隐私 62 项均通过。Python 快速门 1476 项通过、3 项失败、2 项跳过,另有 29 项子测试通过。失败均在 `test_upstream_technique_layers.py` 的 Kaala / PyJHora 校验,在当前 staging 基线定向复现。
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
| 任务书 | 进度 | 主题 | 状态 | 落点 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| [#243 任务书](TASK-reading-computed-fallback-20261113.md) | [执行进度](PROGRESS-reading-computed-fallback-20261113.md) | 个人报告解读计算兜底(BUG-1877) | 待验收 | `codex/reading-computed-fallback-20261113` |
|
||||
| [#242 任务书](TASK-reading-rebind-repair-20261113.md) | [执行进度](PROGRESS-reading-rebind-repair-20261113.md) | 报告解读重绑与逐节重写(BUG-1876) | 待验收 | `codex/reading-rebind-repair-20261113` |
|
||||
| [#241 修订任务书](FIX-chart-choice-questions-1.md) | [执行进度](PROGRESS-chart-choice-questions-20261113.md) | 多轮选盘事件题与判边(BUG-1875) | 待验收 | `codex/chart-choice-questions-20261113` |
|
||||
| [#240 任务书](TASK-reading-timeout-20261113.md) | [执行进度](PROGRESS-reading-timeout-20261113.md) | 报告解读超时与租期内重试(BUG-1874) | 待验收 | `codex/reading-timeout-20261113` |
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# TASK:最后仍不通过的节,改用计算直接生成的内容;页面不再出现「没有通过核对」(2026-11-13)
|
||||
|
||||
- Gitea:#243
|
||||
- 分支:`codex/reading-computed-fallback-20261113`。**开工条件:#242(重绑与重写)合入 staging**,开工前先 rebase。
|
||||
- Bug 编号:BUG-1877
|
||||
- 验收:Claude(jyotisha-e6)
|
||||
|
||||
不得自行写「产品决定/裁定」,任务书没写到的取舍一律选需拍板。不得修改或删除既有断言来让测试通过;确需修改的,写明原值/新值/原因。
|
||||
|
||||
## 产品决定(产品负责人 2026-11-13)
|
||||
|
||||
一节经过系统修正标注、模型重写一次之后仍不通过时,页面上这一节显示**由计算直接生成的内容**,不再写「这一节没有通过数据核对」,也不写原因。原因只留在后台的 `transform_log` 里。「依据与边界」被拦时生成的依据清单(#218),也并入这套做法。
|
||||
|
||||
## 要做的
|
||||
|
||||
1. **每节的计算兜底**:放在新文件 `frontend/src/lib/personal-report-reading-fallback.ts`,只读事实包,不调用模型。每节 2–4 段,句子固定,只陈述盘面事实;每段按所属结论类型的上限标等级(C 或 D)。
|
||||
- 性格:上升星座与命宫星宿;命主星落宫与尊贵;月亮落宫与尊贵;功能吉星、凶星(按 `functional.functional_profile`)。
|
||||
- 事业:第十宫星座、宫主落宫与尊贵;D10 上升(D10 在边界上时只写「出生时间误差内会换座,暂不判断」);A10、AmK。
|
||||
- 财富:第二宫、第十一宫的星座、宫主落宫;D2 上升(处理同上);第二宫、第十一宫的 SAV 分数(只报分数,不写强弱)。
|
||||
- 感情:第七宫星座、宫主落宫与尊贵;D9 上升(处理同上);UL、DK。
|
||||
- 健康:第六、第八、第十二宫的宫主落宫;Badhaka 宫和 Badhaka 宫主(标注「产品计算,待占星师复核」);不写病症。
|
||||
- 现在这几年:Vimshottari 当前的大运、小运、细运起止;Narayana 当前段(标注「参数敏感,只作条件窗口」)。
|
||||
- 总评:取性格节第一段,再加各领域第一句。
|
||||
- 几条建议:**整节不显示**。建议没法由计算生成;这节失败时,目录里也去掉它。
|
||||
- 依据与边界:沿用 #218 的依据清单。
|
||||
|
||||
文案风格:短句,中文,术语第一次出现时用半句话说明它看什么,与模型稿保持一致。
|
||||
2. **存储**:兜底的节记为 `status: "computed"`,段落带 `source: "computed"` 和 `grade`。存储版本加一,旧版本照常读取。
|
||||
3. **页面与导出**:`computed` 的节和普通的节显示方式一致,段落下面照样有等级行。删去对用户显示的 `READING_SECTION_WITHHELD_TEXT` 和 `WITHHELD_REASONS`;旧存储里已有的 withheld 节,读取时也改用兜底生成(读取时手里有事实包就生成,没有就整节不显示)。
|
||||
4. **验收工具**:`postcheck.json` 统计兜底节数。
|
||||
|
||||
## 验收
|
||||
|
||||
1. 合成事实包:每节都能生成兜底;D10、D2、D9 在边界上时,相应句子写成「暂不判断」;健康节没有病症词(跑一遍 #218 的 health_outcome 检查,必须通过)。
|
||||
2. 页面和 MD 导出里,不再出现「没有通过数据核对」,也不出现任何退回原因。
|
||||
3. 旧 v3/v4 存储里的 withheld 节能正常显示(兜底或不显示)。
|
||||
4. 原有测试全部通过;tsc 无错误、eslint 0 个错误,Python 快速门通过。
|
||||
5. 截图(手机宽度):兜底的事业节和普通节放在一起的效果,附在 PR 里。
|
||||
+1
-1
@@ -650,7 +650,7 @@ Action results and errors never take page layout. They are toasts from `src/lib/
|
||||
|
||||
- **Structure:** inside the app shell, like every other secondary page — `/reports/[reportId]` was the last standalone full-screen route, and opening a report used to drop the reader out of the app entirely. 「个人报告」 sits in the 46px header; below it the reader owns its own scroll boundary, carrying the sticky screen chrome (back and the labelled 「导出」 button) and then the longform Markdown body beside a persistent TOC rail. Every phase — loading, generating, timed-out, and each error — renders inside the same shell, so the way back is always the rail. The five-chapter writer document is storage-only and is not rendered. Reports without Markdown show “旧版本报告,请重新生成”.
|
||||
- **Reading basis fallback (BUG-1860):** when 「依据与边界」 fails the post-check, the same section shows one explanation and a list with one calculation-backed line per claim. Each line names its ceiling, required evidence that is missing or near a boundary, and disclosures. The Markdown reading carries the same list. Other withheld sections keep their one-line placeholder.
|
||||
- **Reading evidence grades (BUG-1862):** a paragraph combining multiple claim types appends 「(综合 N 类结论)」 to its evidence grade. Fact paragraphs have no grade row. Markdown uses the same labels.
|
||||
- **Reading evidence grades (BUG-1862, BUG-1877):** a model paragraph combining multiple claim types appends 「(综合 N 类结论)」 to its evidence grade. Model fact paragraphs have no grade row. Computed fallback paragraphs use the same type and spacing as the rest of the reading, with a C or D grade below each paragraph. A computed 「依据与边界」 includes the calculation checklist. The article, section chips, contents and Markdown all use the available sections, omitting failed 「几条建议」 and legacy sections with unavailable facts.
|
||||
- **Reading post-check reasons (BUG-1863):** when a section is withheld, the placeholder gives the known reason in plain Chinese. The reason sits above the calculation-backed list for 「依据与边界」. Markdown carries the same explanation.
|
||||
- **Technique audit status (BUG-1849):** newly generated English reports use readable calculation and interpretation phrases together in the Status cell, with the evidence qualifier when present. The reader also renders the earlier status format from saved reports.
|
||||
- **TOC levels (2026-09-29):** chapters (`##`) are `--color-ink` at weight 600 with `--space-3` above each new chapter; sections (`###`) are indented `--space-5` and stay `--color-ink-secondary`. The two levels read apart without relying on the current-item pill.
|
||||
|
||||
@@ -337,6 +337,7 @@ Jyotisha 的可见文案是产品的一部分。正确性红线(真实性、
|
||||
- 不写病名和诊断,健康只说作息和要多休息的时段;不给投资指令,不点名股票、基金、币;婚姻、生死不下确定结论。
|
||||
- 只用中文,罗睺 / 计都;不写英文字母、分盘代号、字段名、分数原值、「本仓」「检测器」「口径」这类内部说法。出生时间没确认时不把上升、宫位说成定论。
|
||||
- 校验不过(外文、字段名、禁词、节数不对、过长过短、一节两句以上免责)或模型失败、超时:报告照常交付,只是没有解读,不重写成别的样子。
|
||||
- 2026-11-13(#243):逐节修正和重写后仍未通过的章节用短句陈述盘面事实。术语首次出现时简单说明看什么。分盘临界写「出生时间误差内会换座,暂不判断」。八分法只报宫位分数。「几条建议」缺稿时从正文、目录和导出省略。依据清单只写能核对的计算依据和边界,拦截原因留在后台。
|
||||
|
||||
## 报告分块导出与删除
|
||||
|
||||
|
||||
@@ -4866,9 +4866,7 @@ input:not([type="radio"]):not([type="checkbox"]):not([class^="ant-"]):not([class
|
||||
.personal-report-reading-part p { font-size: 17px; line-height: 1.85; }
|
||||
.personal-report-reading-part { scroll-margin-top: 80px; padding-top: var(--space-4); }
|
||||
.personal-report-reading-part + .personal-report-reading-part { margin-top: var(--space-5); }
|
||||
/* #192 (owner 2026-11-12, prototype option B): under each graded paragraph a
|
||||
small grey line with the grade and its meaning; a withheld section is one
|
||||
muted line in its place. */
|
||||
/* Under each graded paragraph, a small grey line gives the grade and its meaning. */
|
||||
.personal-report-reading-paragraph { margin: 0 0 var(--space-5); }
|
||||
.personal-report-md-article .personal-report-reading-paragraph > p { margin-bottom: var(--space-1); }
|
||||
.personal-report-md-article .personal-report-reading-part p.personal-report-evidence-grade {
|
||||
@@ -4877,7 +4875,6 @@ input:not([type="radio"]):not([type="checkbox"]):not([class^="ant-"]):not([class
|
||||
font-size: var(--type-caption);
|
||||
line-height: 1.6;
|
||||
}
|
||||
.personal-report-reading-withheld { color: var(--color-ink-tertiary); }
|
||||
.personal-report-reading-number {
|
||||
display: block;
|
||||
color: var(--color-action-strong);
|
||||
|
||||
@@ -8,7 +8,7 @@ import remarkGfm from "remark-gfm";
|
||||
import { fencedLanguage, fencedSource } from "@/components/markdown-code-block";
|
||||
import { ReportFocusCard } from "@/components/personal-report/report-focus-card";
|
||||
import { ReportReadingSection } from "@/components/personal-report/report-reading-section";
|
||||
import { REPORT_READING_ANCHOR as READING_ANCHOR, type ReportReading } from "@/lib/personal-report-reading-contract";
|
||||
import { REPORT_READING_ANCHOR as READING_ANCHOR, visibleReadingSections, type ReportReading } from "@/lib/personal-report-reading-contract";
|
||||
import { groupReportToc, isReadingAnchor, type ReportTocGroup } from "@/lib/report-toc-groups";
|
||||
import {
|
||||
chartAriaLabel,
|
||||
@@ -424,7 +424,7 @@ export function PersonalReportMarkdownView({
|
||||
const shownReading = language === "zh" ? reading : null;
|
||||
// The reading sits on the first page, so its contents entry opens chapter 0.
|
||||
const tocGroups = useMemo(
|
||||
() => groupReportToc(outline.headings, shownReading?.sections ?? [], language),
|
||||
() => groupReportToc(outline.headings, visibleReadingSections(shownReading), language),
|
||||
[shownReading, outline, language],
|
||||
);
|
||||
const chapters = useMemo(() => outline.sections.filter((section) => !section.eager), [outline]);
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
import {
|
||||
BASIS_AUDIT_INTRO,
|
||||
READING_SECTION_WITHHELD_TEXT,
|
||||
REPORT_READING_ANCHOR,
|
||||
REPORT_READING_BASIS_LABEL,
|
||||
REPORT_READING_HEADING,
|
||||
basisAuditLine,
|
||||
evidenceGradeTag,
|
||||
readingSectionView,
|
||||
visibleReadingSections,
|
||||
type ReportReading,
|
||||
} from "@/lib/personal-report-reading-contract";
|
||||
import { readingPartAnchor } from "@/lib/report-toc-groups";
|
||||
|
||||
/**
|
||||
* The model-written reading in front of the engine report (issue #113 R1).
|
||||
* The reading in front of the engine report (issue #113 R1).
|
||||
* Plain paragraphs under one heading; the engine report follows under the
|
||||
* 「计算依据」 label. Rendered with the report, never loaded after it.
|
||||
*
|
||||
@@ -20,45 +17,38 @@ import { readingPartAnchor } from "@/lib/report-toc-groups";
|
||||
* and each section numbered and anchored so the grouped contents can land on it.
|
||||
*
|
||||
* #192 (owner 2026-11-12, prototype option B): under each graded paragraph one
|
||||
* small grey line gives the grade and its meaning; a section that failed the
|
||||
* post-check shows one line in its place, the other sections stay.
|
||||
* small grey line gives the grade and its meaning, including computed paragraphs.
|
||||
*/
|
||||
export function ReportReadingSection({ reading }: { reading: ReportReading }) {
|
||||
const sections = visibleReadingSections(reading);
|
||||
if (!sections.length) return null;
|
||||
return (
|
||||
<>
|
||||
<section aria-labelledby={REPORT_READING_ANCHOR} className="personal-report-reading">
|
||||
<h2 id={REPORT_READING_ANCHOR}>{REPORT_READING_HEADING}</h2>
|
||||
<nav aria-label="解读章节" className="personal-report-reading-chips personal-report-screen-only">
|
||||
{reading.sections.map((section) => (
|
||||
{sections.map((section) => (
|
||||
<a href={`#${readingPartAnchor(section.id)}`} key={section.id}>{section.title}</a>
|
||||
))}
|
||||
</nav>
|
||||
{reading.sections.map((section, index) => {
|
||||
const view = readingSectionView(section);
|
||||
return (
|
||||
<div className="personal-report-reading-part" id={readingPartAnchor(section.id)} key={section.id}>
|
||||
<span className="personal-report-reading-number" aria-hidden="true">{String(index + 1).padStart(2, "0")}</span>
|
||||
<h3>{section.title}</h3>
|
||||
{view.status === "withheld" ? (
|
||||
view.basisAudit ? (
|
||||
<>
|
||||
<p className="personal-report-reading-withheld">{[view.explanation, BASIS_AUDIT_INTRO].filter(Boolean).join(" ")}</p>
|
||||
<ul className="list-disc pl-5">
|
||||
{view.basisAudit.map((row) => <li key={row.claimType}>{basisAuditLine(row)}</li>)}
|
||||
</ul>
|
||||
</>
|
||||
) : <p className="personal-report-reading-withheld">{[READING_SECTION_WITHHELD_TEXT, view.explanation].filter(Boolean).join(" ")}</p>
|
||||
) : view.paragraphs.map((paragraph, paragraphIndex) => (
|
||||
<div className="personal-report-reading-paragraph" key={paragraphIndex}>
|
||||
<p>{paragraph.text}</p>
|
||||
{paragraph.grade ? (
|
||||
<p className="personal-report-evidence-grade">{evidenceGradeTag(paragraph.grade, paragraph.claimCount)}</p>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{sections.map((section, index) => (
|
||||
<div className="personal-report-reading-part" id={readingPartAnchor(section.id)} key={section.id}>
|
||||
<span className="personal-report-reading-number" aria-hidden="true">{String(index + 1).padStart(2, "0")}</span>
|
||||
<h3>{section.title}</h3>
|
||||
{section.paragraphs.map((paragraph, paragraphIndex) => (
|
||||
<div className="personal-report-reading-paragraph" key={paragraphIndex}>
|
||||
{section.computed && section.id === "basis" && paragraphIndex > 0 ? (
|
||||
<ul className="list-disc pl-5">
|
||||
{paragraph.text.split("\n").map((line, index) => <li key={index}>{line}</li>)}
|
||||
</ul>
|
||||
) : <p>{paragraph.text}</p>}
|
||||
{paragraph.grade ? (
|
||||
<p className="personal-report-evidence-grade">{evidenceGradeTag(paragraph.grade, paragraph.claimCount)}</p>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
<p className="personal-report-basis-label">{REPORT_READING_BASIS_LABEL}</p>
|
||||
</>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { canonicalReportReadingSha256, reportReadingSha256 } from "./report-reading-canonical-json";
|
||||
import { EVIDENCE_GRADE_CONTRACT, EVIDENCE_GRADES, REPORT_CLAIM_TYPES } from "./personal-report-reading-contract";
|
||||
import type { BoundReadingSection, CheckedReportReading, ReportReadingDraftSection, SnapshottedReportReading } from "./personal-report-reading-contract";
|
||||
import type { BoundReadingSection, ComputedReportReading, ReportReadingDraftSection, SnapshottedReportReading } from "./personal-report-reading-contract";
|
||||
import type { ReadingSectionTransform, ReadingTransformLog } from "./personal-report-reading-audit-contract";
|
||||
|
||||
/** Bump when the report-reading post-check rules change. */
|
||||
export const REPORT_READING_POSTCHECK_VERSION = 3;
|
||||
export const REPORT_READING_POSTCHECK_VERSION = 4;
|
||||
|
||||
function record(value: unknown): Record<string, unknown> {
|
||||
return value !== null && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
|
||||
@@ -76,7 +76,7 @@ export function reportReadingRules(commit = process.env.GITHUB_SHA ?? process.en
|
||||
}
|
||||
|
||||
export function bindReportReadingSnapshot(input: {
|
||||
reading: CheckedReportReading;
|
||||
reading: ComputedReportReading;
|
||||
reportInput: unknown;
|
||||
facts: Record<string, unknown>;
|
||||
system: string;
|
||||
|
||||
@@ -125,28 +125,24 @@ const storedWithheldSection = z.strictObject({
|
||||
reason: z.string().regex(/^[a-z_]{1,64}$/),
|
||||
basisAudit: z.array(basisAuditRow).optional(),
|
||||
});
|
||||
/** A section that failed the post-check is kept as a visible placeholder (owner 2026-11-12). */
|
||||
const storedSectionV3 = z.union([
|
||||
z.strictObject({
|
||||
id: z.enum(SECTION_IDS),
|
||||
title: z.string().min(1).max(12),
|
||||
status: z.literal("ok"),
|
||||
paragraphs: z.array(storedParagraphV3).min(1).max(MAX_SECTION_PARAGRAPHS),
|
||||
}),
|
||||
storedWithheldSection,
|
||||
]);
|
||||
/** Legacy stored sections retain their original failure metadata. */
|
||||
const storedOkSectionV3 = z.strictObject({
|
||||
id: z.enum(SECTION_IDS),
|
||||
title: z.string().min(1).max(12),
|
||||
status: z.literal("ok"),
|
||||
paragraphs: z.array(storedParagraphV3).min(1).max(MAX_SECTION_PARAGRAPHS),
|
||||
});
|
||||
const storedSectionV3 = z.union([storedOkSectionV3, storedWithheldSection]);
|
||||
const storedParagraphText = z.string().min(1).max(MAX_PARAGRAPH_CHARS);
|
||||
const storedParagraphV4 = z.union([
|
||||
boundClaim.extend({ text: storedParagraphText, refs_from_text: dependencyRefs.optional() }),
|
||||
factParagraph.extend({ text: storedParagraphText }),
|
||||
]);
|
||||
const storedSectionV4 = z.union([
|
||||
z.strictObject({
|
||||
id: z.enum(SECTION_IDS), title: z.string().min(1).max(12), status: z.literal("ok"),
|
||||
paragraphs: z.array(storedParagraphV4).min(1).max(MAX_SECTION_PARAGRAPHS),
|
||||
}),
|
||||
storedWithheldSection,
|
||||
]);
|
||||
const storedOkSectionV4 = z.strictObject({
|
||||
id: z.enum(SECTION_IDS), title: z.string().min(1).max(12), status: z.literal("ok"),
|
||||
paragraphs: z.array(storedParagraphV4).min(1).max(MAX_SECTION_PARAGRAPHS),
|
||||
});
|
||||
const storedSectionV4 = z.union([storedOkSectionV4, storedWithheldSection]);
|
||||
export type BoundReadingParagraph = z.infer<typeof storedParagraphV4>;
|
||||
export type BoundReadingSection = z.infer<typeof storedSectionV4>;
|
||||
/** Which of the astrologer's files the reading was written with (her §7.3: actually_loaded, not a path). */
|
||||
@@ -162,12 +158,40 @@ const storedReadingV4 = z.strictObject({
|
||||
skill: storedSkill, sections: z.array(storedSectionV4).length(REPORT_READING_SECTIONS.length),
|
||||
});
|
||||
export type CheckedReportReading = z.infer<typeof storedReadingV4>;
|
||||
export type SnapshottedReportReading = z.infer<typeof storedReadingWithSnapshot>;
|
||||
const storedReadingWithSnapshot = storedReadingV4.extend({
|
||||
snapshot: readingSnapshotSchema,
|
||||
transform_log: readingTransformLogSchema,
|
||||
});
|
||||
/** Version 1: the eight sections before 2026-11-07. Version 2 adds 「依据与边界」. Version 3: graded paragraphs (2026-11-12). */
|
||||
|
||||
const computedParagraph = z.strictObject({
|
||||
text: storedParagraphText, source: z.literal("computed"), grade: z.enum(["C", "D"]),
|
||||
});
|
||||
const computedSection = z.strictObject({
|
||||
id: z.enum(SECTION_IDS).refine((id): id is Exclude<ReportReadingSectionId, "advice"> => id !== "advice"),
|
||||
title: z.string().min(1).max(12), status: z.literal("computed"),
|
||||
paragraphs: z.array(computedParagraph).min(2).max(4),
|
||||
});
|
||||
export type ComputedReadingParagraph = z.infer<typeof computedParagraph>;
|
||||
export type ComputedReadingSection = z.infer<typeof computedSection>;
|
||||
|
||||
function inReadingOrder(sections: readonly { id: ReportReadingSectionId }[]) {
|
||||
return sections.every(({ id }, index) => index === 0 || SECTION_IDS.indexOf(id) > SECTION_IDS.indexOf(sections[index - 1]!.id));
|
||||
}
|
||||
const storedReadingV5 = storedReadingV4.extend({
|
||||
version: z.literal(5),
|
||||
sections: z.array(z.union([storedOkSectionV4, computedSection])).min(1).max(SECTION_IDS.length).refine(inReadingOrder),
|
||||
});
|
||||
const readerReadingV5 = storedReadingV5.extend({
|
||||
sections: z.array(z.union([storedOkSectionV3, storedOkSectionV4, computedSection])).min(1).max(SECTION_IDS.length).refine(inReadingOrder),
|
||||
});
|
||||
const storedReadingV5WithSnapshot = storedReadingV5.extend({
|
||||
snapshot: readingSnapshotSchema,
|
||||
transform_log: readingTransformLogSchema,
|
||||
});
|
||||
export type ComputedReportReading = z.infer<typeof storedReadingV5>;
|
||||
export type SnapshottedReportReading = z.infer<typeof storedReadingV5WithSnapshot>;
|
||||
|
||||
/** Versions 1–4 stay readable. V5 stores computed sections and omits absent sections. */
|
||||
export const reportReadingSchema = z.union([
|
||||
z.strictObject({
|
||||
version: z.literal(1),
|
||||
@@ -188,39 +212,12 @@ export const reportReadingSchema = z.union([
|
||||
}),
|
||||
storedReadingV4,
|
||||
storedReadingWithSnapshot,
|
||||
readerReadingV5,
|
||||
storedReadingV5WithSnapshot,
|
||||
]);
|
||||
export type ReportReading = z.infer<typeof reportReadingSchema>;
|
||||
export type ReportReadingParagraph = Readonly<{ text: string; grade?: EvidenceGrade; claimCount?: number }>;
|
||||
|
||||
/** Shown in place of a section that did not pass the post-check (owner 2026-11-12). */
|
||||
export const READING_SECTION_WITHHELD_TEXT = "这一节没有通过数据核对,暂不显示。";
|
||||
export const BASIS_AUDIT_INTRO = "这一节的模型文字没有通过核对,下面是由计算直接生成的依据清单。";
|
||||
export const READING_WITHHELD_REASONS: Readonly<Record<string, string>> = {
|
||||
field_name: "文字里混入了内部标记。",
|
||||
banned_phrase: "措辞超出了这份报告能判断的范围。",
|
||||
too_long: "有段文字超过了篇幅限制。",
|
||||
too_short: "有段文字没有完整写出。",
|
||||
disclaimer: "同一节重复写了边界说明。",
|
||||
claim_binding_missing: "有段判断没有标清使用了哪些依据。",
|
||||
claim_type_section: "这节用了与主题不对应的判断依据。",
|
||||
grade_above_cap: "判断的证据等级高于现有依据能支持的等级。",
|
||||
false_no_blocker: "有一项必需依据还不能用,文字里没有说明。",
|
||||
dignity_mismatch: "星曜状态与计算结果对不上。",
|
||||
false_missing_layer: "文字说有一项没有计算,但计算结果里有这一项。",
|
||||
current_advice_in_replay: "历史回看里写入了面向当下的建议。",
|
||||
double_transit_scope: "双行运没有核对到这节涉及的宫位。",
|
||||
yoga_status_mismatch: "格局状态与计算结果对不上。",
|
||||
house_lord_mismatch: "宫主与计算结果对不上。",
|
||||
sav_total_as_strength: "文字用固定的八分法总分判断了个人强弱。",
|
||||
badhaka_role_mix: "文字混淆了阻碍宫和阻碍宫主。",
|
||||
health_outcome: "文字对具体健康问题作了判断。",
|
||||
accuracy_claim: "文字给出了没有依据的准确率。",
|
||||
ref_outside_claims: "引用的依据与这段判断对不上。",
|
||||
ref_unstable: "判断用到的依据还不能支持这个证据等级。",
|
||||
timing_unbound: "时间判断没有对应的时间依据。",
|
||||
fact_with_inference: "盘面事实里混入了未经分级的判断。",
|
||||
claim_not_established: "摘要或建议引用了正文还没有核对通过的判断。",
|
||||
};
|
||||
const CLAIM_LABELS: Readonly<Record<ReportClaimType, string>> = {
|
||||
character_structure: "性格结构",
|
||||
career_promise: "事业倾向",
|
||||
@@ -268,23 +265,18 @@ export const EVIDENCE_GRADE_MEANING: Readonly<Record<EvidenceGrade, string>> = {
|
||||
D: "关键依据缺失,暂不能判断",
|
||||
};
|
||||
|
||||
/** One reading section as the page and the export show it, for every stored version. */
|
||||
export function readingSectionView(section: ReportReading["sections"][number]):
|
||||
| Readonly<{ status: "ok"; paragraphs: readonly ReportReadingParagraph[] }>
|
||||
| Readonly<{ status: "withheld"; explanation?: string; basisAudit?: readonly BasisAuditRow[] }> {
|
||||
if (!("status" in section)) return { status: "ok", paragraphs: section.paragraphs.map((text) => ({ text })) };
|
||||
if (section.status === "withheld") {
|
||||
return {
|
||||
status: "withheld",
|
||||
explanation: Object.hasOwn(READING_WITHHELD_REASONS, section.reason) ? READING_WITHHELD_REASONS[section.reason] : undefined,
|
||||
...(section.id === "basis" && section.basisAudit ? { basisAudit: section.basisAudit } : {}),
|
||||
};
|
||||
}
|
||||
return { status: "ok", paragraphs: section.paragraphs.map((paragraph) => {
|
||||
const { text } = paragraph;
|
||||
if (!("grade" in paragraph) || !paragraph.grade) return { text };
|
||||
return { text, grade: paragraph.grade, ...("claims" in paragraph ? { claimCount: new Set(paragraph.claims).size } : {}) };
|
||||
}) };
|
||||
/** Shared by the article, its contents, and Markdown. */
|
||||
export function visibleReadingSections(reading: ReportReading | null | undefined) {
|
||||
return (reading?.sections ?? []).flatMap(section => {
|
||||
if ("status" in section && section.status === "withheld") return [];
|
||||
const paragraphs: ReportReadingParagraph[] = section.paragraphs.map(paragraph => {
|
||||
if (typeof paragraph === "string") return { text: paragraph };
|
||||
const { text } = paragraph;
|
||||
if (!("grade" in paragraph) || !paragraph.grade) return { text };
|
||||
return { text, grade: paragraph.grade, ...("claims" in paragraph ? { claimCount: new Set(paragraph.claims).size } : {}) };
|
||||
});
|
||||
return [{ id: section.id, title: section.title, computed: "status" in section && section.status === "computed", paragraphs }];
|
||||
});
|
||||
}
|
||||
|
||||
/** 「证据等级 C:有星盘依据,还没有对得上的案例」 */
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
import { PLANET_ZH, SIGN_ZH } from "./chart-view-labels";
|
||||
import { recordOrEmpty as record, finiteNumberOrNull } from "./guards";
|
||||
import { NAKSHATRA_ZH } from "./panchanga-names-zh";
|
||||
import {
|
||||
basisAuditLine,
|
||||
EVIDENCE_GRADE_CONTRACT,
|
||||
type BasisAuditRow,
|
||||
type ComputedReadingParagraph,
|
||||
type ComputedReadingSection,
|
||||
type ReportClaimType,
|
||||
type ReportReadingSectionId,
|
||||
} from "./personal-report-reading-contract";
|
||||
|
||||
type Facts = Record<string, unknown>;
|
||||
type Domain = Exclude<ReportReadingSectionId, "overview" | "advice" | "basis">;
|
||||
|
||||
export const MISSING_READING_DEPENDENCIES = new Set([
|
||||
"blocked", "withheld", "missing", "calculation_failed", "missing_input", "not_computed", "boundary_sensitive",
|
||||
]);
|
||||
|
||||
function translated(value: unknown, labels: Readonly<Record<string, string>>) {
|
||||
return typeof value === "string" && Object.hasOwn(labels, value) ? labels[value] : undefined;
|
||||
}
|
||||
|
||||
const planet = (value: unknown) => translated(value, PLANET_ZH);
|
||||
const sign = (value: unknown) => {
|
||||
const label = translated(value, SIGN_ZH);
|
||||
return label && `${label}座`;
|
||||
};
|
||||
const house = (value: unknown) => {
|
||||
const number = finiteNumberOrNull(value);
|
||||
return number !== null && Number.isInteger(number) && number >= 1 && number <= 12 ? `第 ${number} 宫` : undefined;
|
||||
};
|
||||
|
||||
function claimGrades(facts: Facts) {
|
||||
const grades = record(facts.evidence_grades);
|
||||
return grades.contract === EVIDENCE_GRADE_CONTRACT ? record(grades.claims) : {};
|
||||
}
|
||||
|
||||
function paragraph(text: string, grade: ComputedReadingParagraph["grade"]): ComputedReadingParagraph {
|
||||
return { text, source: "computed", grade };
|
||||
}
|
||||
|
||||
function graded(text: string, claims: Facts, claimTypes: ReportClaimType | ReportClaimType[], incomplete = false) {
|
||||
const supported = [claimTypes].flat().every(type => {
|
||||
const cap = record(claims[type]).cap;
|
||||
return cap === "A" || cap === "B" || cap === "C";
|
||||
});
|
||||
return paragraph(text, !incomplete && supported ? "C" : "D");
|
||||
}
|
||||
|
||||
function placement(facts: Facts, name: unknown, label: string, showDignity = true) {
|
||||
const body = planet(name);
|
||||
const row = record(record(facts.planets)[String(name)]);
|
||||
const location = house(row.d1_house);
|
||||
const dignity = typeof row.d1_dignity_zh === "string" ? row.d1_dignity_zh : undefined;
|
||||
const details = [location && `落在${location}`, showDignity && dignity && `尊贵状态为${dignity}`].filter(Boolean);
|
||||
return {
|
||||
text: body ? `${label === body ? `${body}${details.join(",")}` : `${label}是${body}${details.length ? `,${details.join(",")}` : ""}`}。` : "",
|
||||
incomplete: !body || !location || (showDignity && !dignity),
|
||||
};
|
||||
}
|
||||
|
||||
const houseTopics: Readonly<Record<number, string>> = {
|
||||
2: "收入与积蓄", 6: "日常负担", 7: "伴侣关系", 8: "变动与恢复", 10: "事业", 11: "收益", 12: "休息与消耗",
|
||||
};
|
||||
|
||||
function natalHouse(facts: Facts, number: number, showDignity = true) {
|
||||
const row = record(record(facts.houses)[number]);
|
||||
const label = `${house(number)}(${houseTopics[number]})`;
|
||||
const zodiac = sign(row.sign);
|
||||
const lord = placement(facts, row.lord, "宫主", showDignity);
|
||||
return {
|
||||
text: zodiac ? `${label}在${zodiac}。${lord.text}` : lord.text ? `${label}的${lord.text}` : "",
|
||||
incomplete: !zodiac || lord.incomplete,
|
||||
};
|
||||
}
|
||||
|
||||
const divisionNames = { D10: "事业分盘(D10)", D2: "财富分盘(D2)", D9: "看关系的九分盘(D9)" };
|
||||
|
||||
function division(facts: Facts, domain: string, code: keyof typeof divisionNames) {
|
||||
const catalog = record(record(facts.evidence_grades).dependency_catalog);
|
||||
const state = record(catalog[`v:${code}`]).state;
|
||||
const charts = record(record(record(facts.domains)[domain]).varga_charts);
|
||||
const ascendant = sign(record(charts[code]).ascendant);
|
||||
const label = divisionNames[code];
|
||||
if (state === "boundary_sensitive") return { text: `${label}的上升在出生时间误差内会换座,暂不判断。`, incomplete: true };
|
||||
if (state !== "clear_at_tolerance" || !ascendant) return { text: "", incomplete: true };
|
||||
return { text: `${label}的上升在${ascendant}。`, incomplete: false };
|
||||
}
|
||||
|
||||
function participation(facts: Facts, domain: string, id: string) {
|
||||
const rows = record(record(facts.domains)[domain]).participation;
|
||||
return Array.isArray(rows) ? rows.map(record).find(row => row.id === id && row.state === "executed")?.value : undefined;
|
||||
}
|
||||
|
||||
const functionalProfiles: Readonly<Record<string, string>> = {
|
||||
pvr_table30_v1: "PVR 表 30",
|
||||
bphs_exception_profile: "《帕拉沙拉占星经典》例外表",
|
||||
};
|
||||
|
||||
function character(facts: Facts, claims: Facts) {
|
||||
const ascendant = record(facts.ascendant);
|
||||
const zodiac = sign(ascendant.sign);
|
||||
const mansion = translated(ascendant.nakshatra, NAKSHATRA_ZH);
|
||||
const ascendantText = [zodiac && `命盘起点的上升在${zodiac}。`, mansion && `命宫对应的星宿是${mansion}。`].filter(Boolean).join("");
|
||||
const lord = placement(facts, ascendant.lord, "上升星座的主星");
|
||||
const moon = placement(facts, "Moon", "月亮");
|
||||
const functional = record(facts.functional);
|
||||
const profile = translated(functional.functional_profile, functionalProfiles);
|
||||
const list = (value: unknown) => Array.isArray(value) ? value.map(planet).filter(Boolean).join("、") || "无" : "";
|
||||
const benefics = list(functional.functional_benefics);
|
||||
const malefics = list(functional.functional_malefics);
|
||||
const roles = [benefics && `吉星为${benefics}`, malefics && `凶星为${malefics}`].filter(Boolean).join(",");
|
||||
const grade = (text: string, incomplete: boolean) => graded(text, claims, "character_structure", incomplete);
|
||||
return [
|
||||
ascendantText && grade(ascendantText, !zodiac || !mansion),
|
||||
lord.text && grade(lord.text, lord.incomplete),
|
||||
Object.keys(record(record(facts.planets).Moon)).length > 0 && grade(moon.text, moon.incomplete),
|
||||
profile && roles && grade(`按 ${profile},依上升划分的功能吉凶星中,${roles}。`, !benefics || !malefics),
|
||||
];
|
||||
}
|
||||
|
||||
function career(facts: Facts, claims: Facts) {
|
||||
const tenth = natalHouse(facts, 10);
|
||||
const d10 = division(facts, "career", "D10");
|
||||
const a10 = sign(participation(facts, "career", "A10"));
|
||||
const amk = planet(participation(facts, "career", "AmK"));
|
||||
const indicators = [a10 && `事业映射点(A10)在${a10}。`, amk && `事业指标星(AmK)是${amk}。`].filter(Boolean).join("");
|
||||
const grade = (text: string, incomplete: boolean) => graded(text, claims, "career_promise", incomplete);
|
||||
return [tenth.text && grade(tenth.text, tenth.incomplete), d10.text && grade(d10.text, d10.incomplete),
|
||||
indicators && grade(indicators, !a10 || !amk)];
|
||||
}
|
||||
|
||||
function wealth(facts: Facts, claims: Facts) {
|
||||
const second = natalHouse(facts, 2, false);
|
||||
const eleventh = natalHouse(facts, 11, false);
|
||||
const d2 = division(facts, "wealth", "D2");
|
||||
const houses = record(facts.houses);
|
||||
const scores = [2, 11].flatMap(number => {
|
||||
const score = finiteNumberOrNull(record(houses[number]).sav_score);
|
||||
return score === null ? [] : [`${house(number)} ${score} 分`];
|
||||
});
|
||||
const earning = (text: string, incomplete: boolean) => graded(text, claims, "wealth_earning", incomplete);
|
||||
const retention = (text: string, incomplete: boolean) => graded(text, claims, "wealth_retention", incomplete);
|
||||
return [
|
||||
second.text && retention(second.text, second.incomplete),
|
||||
eleventh.text && earning(eleventh.text, eleventh.incomplete),
|
||||
d2.text && retention(d2.text, d2.incomplete),
|
||||
scores.length > 0 && graded(`八分法(SAV)给各宫计分。${scores.join(",")}。`,
|
||||
claims, ["wealth_earning", "wealth_retention"], scores.length < 2),
|
||||
];
|
||||
}
|
||||
|
||||
function love(facts: Facts, claims: Facts) {
|
||||
const seventh = natalHouse(facts, 7);
|
||||
const d9 = division(facts, "marriage", "D9");
|
||||
const ul = sign(participation(facts, "marriage", "UL"));
|
||||
const dk = planet(participation(facts, "marriage", "DK"));
|
||||
const indicators = [ul && `婚姻映射点(UL)在${ul}。`, dk && `伴侣指标星(DK)是${dk}。`].filter(Boolean).join("");
|
||||
const grade = (text: string, incomplete: boolean) => graded(text, claims, "relationship_structure", incomplete);
|
||||
return [seventh.text && grade(seventh.text, seventh.incomplete), d9.text && grade(d9.text, d9.incomplete),
|
||||
indicators && grade(indicators, !ul || !dk)];
|
||||
}
|
||||
|
||||
function health(facts: Facts, claims: Facts) {
|
||||
const houses = record(facts.houses);
|
||||
const placements = [6, 8, 12].map(number =>
|
||||
placement(facts, record(houses[number]).lord, `${house(number)}(${houseTopics[number]})的宫主`, false));
|
||||
const text = placements.map(row => row.text).join("");
|
||||
const badhaka = record(participation(facts, "health", "Badhaka"));
|
||||
const obstruction = record(badhaka.badhaka_sthana);
|
||||
const obstructionHouse = house(obstruction.house);
|
||||
const obstructionSign = sign(obstruction.sign);
|
||||
const lord = record(badhaka.badhakesh);
|
||||
const lordName = planet(lord.planet);
|
||||
const lordHouse = house(lord.house);
|
||||
const obstructionText = [
|
||||
obstructionHouse && `阻碍宫(Badhaka)是${obstructionHouse}${obstructionSign ? `,在${obstructionSign}` : ""}。`,
|
||||
lordName && `阻碍宫主是${lordName}${lordHouse ? `,落在${lordHouse}` : ""}。`,
|
||||
].filter(Boolean).join("");
|
||||
return [text && graded(text, claims, "health_pressure", placements.some(row => row.incomplete)),
|
||||
obstructionText && graded(`${obstructionText}产品计算,待占星师复核。`, claims, "health_obstruction", !obstructionHouse || !lordName)];
|
||||
}
|
||||
|
||||
function dates(row: Facts) {
|
||||
const day = (value: unknown) => typeof value === "string" ? /^\d{4}-\d{2}-\d{2}(?=$|[T ])/.exec(value)?.[0] : undefined;
|
||||
const start = day(row.start);
|
||||
const end = day(row.end);
|
||||
return start && end ? `${start} 至 ${end}` : undefined;
|
||||
}
|
||||
|
||||
function now(facts: Facts, claims: Facts) {
|
||||
const timing = record(facts.timing);
|
||||
const narayana = record(timing.narayana);
|
||||
const replay = facts.report_mode === "historical_replay";
|
||||
const reference = replay ? "回看当时" : "报告参考日";
|
||||
const vimshottariPeriods = [
|
||||
["mahadasha", `${reference}所在的维姆绍塔里大运(按星宿排出的长期运期)`],
|
||||
["antardasha", "其下的小运"],
|
||||
["pratyantardasha", "小运之内的细运"],
|
||||
] as const;
|
||||
const vimshottari = vimshottariPeriods.flatMap(([key, label]) => {
|
||||
const row = record(timing[key]);
|
||||
const ruler = planet(row.lord);
|
||||
const range = dates(row);
|
||||
return ruler && range ? [graded(`${label}由${ruler}主掌,${range}。`, claims, "timing_window")] : [];
|
||||
});
|
||||
const method = record(narayana.method_status).status;
|
||||
const current = record(narayana.mahadasha);
|
||||
const zodiac = sign(current.sign);
|
||||
const range = dates(current);
|
||||
const narayanaLabel = "纳拉亚纳大运(按星座排出的运期)";
|
||||
const conditional = "参数敏感,只作条件窗口。";
|
||||
const determined = zodiac && range && (!method || method === "determined");
|
||||
const period = determined
|
||||
? `${reference}所在的${narayanaLabel}在${zodiac},${range}。${conditional}`
|
||||
: Object.keys(narayana).length > 0 ? `${narayanaLabel}的当前段暂无法确定。${conditional}` : "";
|
||||
return [...vimshottari, period && graded(period, claims, "timing_window", !determined)];
|
||||
}
|
||||
|
||||
const domainWriters = { character, career, wealth, love, health, now } satisfies Record<Domain, (facts: Facts, claims: Facts) => unknown>;
|
||||
|
||||
function present(value: unknown): value is ComputedReadingParagraph {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
export function readingBasisAudit(claims: Facts): BasisAuditRow[] {
|
||||
return Object.entries(claims).flatMap(([claimType, value]) => {
|
||||
const claim = record(value);
|
||||
const cap = claim.cap;
|
||||
if (cap !== "A" && cap !== "B" && cap !== "C" && cap !== "D") return [];
|
||||
const missingRequired = Array.isArray(claim.required) ? claim.required.map(record)
|
||||
.filter(dep => typeof dep.state === "string" && MISSING_READING_DEPENDENCIES.has(dep.state))
|
||||
.flatMap(dep => typeof dep.id === "string" ? [dep.id] : []) : [];
|
||||
const mustDisclose = Array.isArray(claim.must_disclose)
|
||||
? claim.must_disclose.filter((id): id is string => typeof id === "string") : [];
|
||||
return [{ claimType, cap, missingRequired, mustDisclose }];
|
||||
});
|
||||
}
|
||||
|
||||
function basis(claims: Facts): ComputedReadingParagraph[] {
|
||||
const rows = readingBasisAudit(claims);
|
||||
if (!rows.length) return [];
|
||||
const paragraphs = [];
|
||||
const groupSize = Math.max(2, Math.ceil(rows.length / 3));
|
||||
for (let index = 0; index < rows.length; index += groupSize) {
|
||||
const group = rows.slice(index, index + groupSize);
|
||||
paragraphs.push(paragraph(group.map(row => basisAuditLine(row).replace(/[\r\n]+/g, " ")).join("\n"),
|
||||
group.some(row => row.cap === "D") ? "D" : "C"));
|
||||
}
|
||||
return [paragraph("下面列出计算依据支持的等级,以及还需要说明的地方。", rows.some(row => row.cap === "D") ? "D" : "C"), ...paragraphs];
|
||||
}
|
||||
|
||||
function overview(facts: Facts, claims: Facts): ComputedReadingParagraph[] {
|
||||
const opening = character(facts, claims).filter(present)[0];
|
||||
const domainSentences = (["career", "wealth", "love", "health", "now"] as const).flatMap(domain => {
|
||||
const first = domainWriters[domain](facts, claims).filter(present)[0];
|
||||
return first ? [paragraph(`${first.text.split("。", 1)[0]}。`, first.grade)] : [];
|
||||
});
|
||||
const summaries = [domainSentences.slice(0, 2), domainSentences.slice(2, 4), domainSentences.slice(4)]
|
||||
.flatMap(group => group.length ? [paragraph(group.map(item => item.text).join(""), group.some(item => item.grade === "D") ? "D" : "C")] : []);
|
||||
return opening ? [opening, ...summaries] : summaries;
|
||||
}
|
||||
|
||||
export function computeReadingSection(
|
||||
section: { id: ReportReadingSectionId; title: string },
|
||||
facts: Facts,
|
||||
): ComputedReadingSection | null {
|
||||
const { id } = section;
|
||||
if (id === "advice") return null;
|
||||
const claims = claimGrades(facts);
|
||||
const paragraphs = id === "basis" ? basis(claims) : id === "overview" ? overview(facts, claims)
|
||||
: domainWriters[id](facts, claims).filter(present);
|
||||
if (!paragraphs.length) return null;
|
||||
if (paragraphs.length === 1) paragraphs.push(paragraph("其余盘面依据暂不完整。", "D"));
|
||||
return { id, title: section.title, status: "computed", paragraphs };
|
||||
}
|
||||
@@ -17,15 +17,14 @@ import {
|
||||
MAX_TOTAL_CHARS,
|
||||
MIN_TOTAL_CHARS,
|
||||
REPORT_READING_SECTIONS,
|
||||
READING_WITHHELD_REASONS,
|
||||
reportReadingDraftEnvelopeSchema,
|
||||
reportReadingDraftParagraphSchema,
|
||||
reportReadingRepairEnvelopeSchema,
|
||||
type BasisAuditRow,
|
||||
type BoundReadingParagraph,
|
||||
type BoundReadingSection,
|
||||
type EvidenceGrade,
|
||||
type CheckedReportReading,
|
||||
type ComputedReportReading,
|
||||
type ReportReadingDraftSection,
|
||||
type ReportReadingSectionId,
|
||||
type SnapshottedReportReading,
|
||||
@@ -35,6 +34,7 @@ import type { ReadingAttempt, ReadingRebound, ReadingSectionTransform, ReadingTr
|
||||
import { claimDependencyIds, FACT_INFERENCE, GENERIC_DASHA_ALIASES, rebindReadingSection, TIMING_TEXT, type Catalog, type Claims } from "./personal-report-reading-rebind";
|
||||
import { canonicalReportReadingSha256 } from "./report-reading-canonical-json";
|
||||
import type { ReportReading } from "./personal-report-reading-contract";
|
||||
import { computeReadingSection, MISSING_READING_DEPENDENCIES, readingBasisAudit } from "./personal-report-reading-fallback";
|
||||
|
||||
export {
|
||||
REPORT_READING_BASIS_LABEL,
|
||||
@@ -286,9 +286,6 @@ const SAV_STRENGTH = /不缺|充足|强|弱|维持力|底气|力量/;
|
||||
const HEALTH_OUTCOME = /炎症|感染|外伤|受伤|损伤|骨折|手术|出血|发炎|结石|肝|肾|心脏|心血管|心律|肺|胃|血压|血糖|过敏|失眠|运动风险/;
|
||||
const ACCURACY_WORD = /成功率|准确率|命中率/;
|
||||
const PERCENTAGE = /[0-90-9一二两三四五六七八九十百零〇](?:[..][0-90-9]+)?\s*[%%]|百分之\s*[0-90-9一二两三四五六七八九十百零〇]|[0-90-9一二两三四五六七八九十几数半]\s*成(?!功|立|为|人|长)/;
|
||||
const MISSING_DEPENDENCY = new Set([
|
||||
"blocked", "withheld", "missing", "calculation_failed", "missing_input", "not_computed", "boundary_sensitive",
|
||||
]);
|
||||
|
||||
function bannedQualifiedPhrase(sentence: string): boolean {
|
||||
for (const mention of sentence.split("检测器").slice(1)) {
|
||||
@@ -330,7 +327,7 @@ function badhakaHouse(facts: Record<string, unknown> | null): unknown {
|
||||
return value?.badhaka_sthana?.house ?? value?.house;
|
||||
}
|
||||
|
||||
function checkedFactClaim(text: string, section: string, facts: Record<string, unknown> | null): ReadingRejection | undefined {
|
||||
export function checkedFactClaim(text: string, section: string, facts: Record<string, unknown> | null): ReadingRejection | undefined {
|
||||
const obstructionHouse = badhakaHouse(facts);
|
||||
for (const sentence of text.split(SENTENCE_END)) {
|
||||
if (houseLordMismatch(sentence, facts)) return "house_lord_mismatch";
|
||||
@@ -344,23 +341,7 @@ function checkedFactClaim(text: string, section: string, facts: Record<string, u
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function basisAudit(claims: Claims): BasisAuditRow[] {
|
||||
const rows: BasisAuditRow[] = [];
|
||||
for (const [claimType, claim] of Object.entries(claims)) {
|
||||
const cap = EVIDENCE_GRADES.find((grade) => grade === claim?.cap);
|
||||
if (!claimType || !cap) continue;
|
||||
const missingRequired = Array.isArray(claim.required)
|
||||
? claim.required.filter((dep) => typeof dep?.id === "string" && MISSING_DEPENDENCY.has(dep.state)).map((dep) => dep.id as string)
|
||||
: [];
|
||||
const mustDisclose = Array.isArray(claim.must_disclose)
|
||||
? claim.must_disclose.filter((id): id is string => typeof id === "string")
|
||||
: [];
|
||||
rows.push({ claimType, cap, missingRequired, mustDisclose });
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
const UNSTABLE_REFERENCE = new Set([...MISSING_DEPENDENCY, "not_evaluated"]);
|
||||
const UNSTABLE_REFERENCE = new Set([...MISSING_READING_DEPENDENCIES, "not_evaluated"]);
|
||||
|
||||
function dependencyCatalog(facts: Record<string, unknown> | null): Catalog {
|
||||
const catalog = (facts?.evidence_grades as { dependency_catalog?: unknown } | undefined)?.dependency_catalog;
|
||||
@@ -435,7 +416,7 @@ function checkSection(
|
||||
return (sentences.length ? sentences.join("。") : text).slice(0, MAX_PARAGRAPH_CHARS);
|
||||
};
|
||||
const withheld = (reason: ReadingRejection, matches?: (sentence: string) => boolean, conflicts?: RefConflict[]): Checked => ({
|
||||
section: { id: section.id, title, status: "withheld" as const, reason, ...(section.id === "basis" ? { basisAudit: basisAudit(claims) } : {}) },
|
||||
section: { id: section.id, title, status: "withheld" as const, reason, ...(section.id === "basis" ? { basisAudit: readingBasisAudit(claims) } : {}) },
|
||||
chars: 0,
|
||||
inferredRefs,
|
||||
reason,
|
||||
@@ -548,7 +529,7 @@ function invalidDraft(): DraftAcceptance {
|
||||
/**
|
||||
* The draft becomes the stored reading only when its shape holds and at least one
|
||||
* section passes. Each section is checked on its own: a section that breaks a rule
|
||||
* is withheld and shown as withheld, the others stay (owner 2026-11-12). Grades are
|
||||
* is withheld from the draft and can be repaired before publication. Grades are
|
||||
* checked against the backend's per-claim ceilings in the facts (astrologer Q3-2).
|
||||
*/
|
||||
export function acceptReportReadingDraft(
|
||||
@@ -627,8 +608,8 @@ function checkReadingDraft(
|
||||
const details = { sections: transforms, diagnostics, rebound, checked: finalized };
|
||||
if (withheld === finalized.length) return { ok: false, reason: "all_sections_withheld", ...details };
|
||||
const total = finalized.reduce((sum, { chars }) => sum + chars, 0);
|
||||
if (total < MIN_TOTAL_CHARS) return { ok: false, reason: "too_short", ...details };
|
||||
if (total > MAX_TOTAL_CHARS) return { ok: false, reason: "too_long", ...details };
|
||||
if (total < MIN_TOTAL_CHARS) return { ok: false, reason: "too_short", ...details };
|
||||
return {
|
||||
ok: true,
|
||||
withheld,
|
||||
@@ -695,11 +676,29 @@ export type ReportReadingOutcome = Readonly<{
|
||||
transformLog?: ReadingTransformLog;
|
||||
}>;
|
||||
|
||||
/** Reader and Markdown export need the accepted sections, not the generation audit. */
|
||||
export function reportReadingForReader(reading: ReportReading): ReportReading {
|
||||
if (!("snapshot" in reading)) return reading;
|
||||
/** Project legacy sections with the facts already available to the caller. */
|
||||
export function reportReadingForReader(reading: ReportReading, facts: Record<string, unknown> | null = null): ReportReading | null {
|
||||
if (reading.version === 1 || reading.version === 2) return reading;
|
||||
const { version, language, contract, skill, sections } = reading;
|
||||
return { version, language, contract, skill, sections };
|
||||
if (version === 5) return { version, language, contract, skill, sections };
|
||||
if (!sections.some(section => section.status === "withheld")) {
|
||||
return "snapshot" in reading ? { version: 4, language, contract, skill, sections: reading.sections } : reading;
|
||||
}
|
||||
const visible = sections.flatMap<Extract<ReportReading, { version: 5 }>["sections"][number]>(section => {
|
||||
if (section.status === "ok") return [section];
|
||||
const computed = facts && computeReadingSection(section, facts);
|
||||
return computed ? [computed] : [];
|
||||
});
|
||||
return visible.length ? { version: 5, language, contract, skill, sections: visible } : null;
|
||||
}
|
||||
|
||||
function computedReportReading(reading: CheckedReportReading, facts: Record<string, unknown>): ComputedReportReading {
|
||||
const sections = reading.sections.flatMap<ComputedReportReading["sections"][number]>(section => {
|
||||
if (section.status === "ok") return [section];
|
||||
const computed = computeReadingSection(section, facts);
|
||||
return computed ? [computed] : [];
|
||||
});
|
||||
return { ...reading, version: 5, sections };
|
||||
}
|
||||
|
||||
function timedSignal(parent: AbortSignal | undefined, timeoutMs: number) {
|
||||
@@ -780,7 +779,7 @@ function repairInstruction(reason: ReadingRejection, conflicts: RefConflict[] |
|
||||
? `这一节不能谈 ${topics}。删掉命中句中的跨领域内容,或改成由本节允许的依赖支持的表达。只返回本次要求修改的节。`
|
||||
: "删掉不在本节依赖表里的引用。只用事实包列出的结论与依赖编号。";
|
||||
}
|
||||
return REPAIR_INSTRUCTIONS[reason] ?? READING_WITHHELD_REASONS[reason] ?? "按事实包修正命中句中的问题。";
|
||||
return REPAIR_INSTRUCTIONS[reason] ?? "按事实包修正命中句中的问题。";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -807,6 +806,7 @@ export async function writeReportReading(input: Readonly<{
|
||||
let unavailable = "model_failed";
|
||||
const attempts: ReadingAttempt[] = [];
|
||||
let best: { reading: CheckedReportReading; rawSha256: string; attempt: number } | null = null;
|
||||
let lastCheckedDraft: { check: DraftAcceptance; rawSha256: string; attempt: number } | undefined;
|
||||
let initial: { draft: Draft; check: DraftAcceptance; rawSha256: string; attempt: number; originalSections?: readonly unknown[] } | undefined;
|
||||
let repair: ReadingTransformLog["repair"];
|
||||
let finalCheck: DraftAcceptance | undefined;
|
||||
@@ -883,17 +883,18 @@ export async function writeReportReading(input: Readonly<{
|
||||
const passes = repairSections.filter((id) => checked.checked.some(({ section }) => section.id === id && section.status === "ok"));
|
||||
const regressed = first.check.checked.some(({ section }, index) =>
|
||||
section.status === "ok" && checked.checked[index]?.section.status !== "ok");
|
||||
const adopt = checked.ok && passes.length > 0 && !regressed;
|
||||
const adopt = (checked.ok || (!best && checked.reason === "too_short")) && passes.length > 0 && !regressed;
|
||||
attempts.push({
|
||||
attempt: attempt + 1, raw_response_sha256: rawSha256, status: adopt ? "accepted" : "rejected",
|
||||
...(!adopt ? { reason: regressed ? "repair_regression" : checked.ok ? "repair_no_improvement" : checked.reason } : {}),
|
||||
sections: checked.sections.filter(({ id }) => repairSections.some((requested) => requested === id)),
|
||||
});
|
||||
autoRebound.push(...checked.rebound);
|
||||
if (adopt && checked.ok) {
|
||||
if (adopt) {
|
||||
repair.passed = passes;
|
||||
finalCheck = checked;
|
||||
best = { reading: checked.reading, rawSha256: first.rawSha256, attempt: first.attempt };
|
||||
lastCheckedDraft = { check: checked, rawSha256: first.rawSha256, attempt: first.attempt };
|
||||
if (checked.ok) best = { reading: checked.reading, rawSha256: first.rawSha256, attempt: first.attempt };
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -901,6 +902,7 @@ export async function writeReportReading(input: Readonly<{
|
||||
const accepted = usableDraft ? checkReadingDraft(usableDraft, facts, skill, { originalSections: result.originalSections })
|
||||
: invalidDraft();
|
||||
finalCheck = accepted;
|
||||
if (usableDraft) lastCheckedDraft = { check: accepted, rawSha256, attempt: attempt + 1 };
|
||||
autoRebound.push(...accepted.rebound);
|
||||
if (usableDraft && !firstDiagnostics) {
|
||||
firstDiagnostics = checkReadingDraft(usableDraft, facts, skill, { withoutRebind: true }).diagnostics;
|
||||
@@ -937,11 +939,25 @@ export async function writeReportReading(input: Readonly<{
|
||||
}
|
||||
}
|
||||
const completedAttempts = attempts.filter(({ status }) => status !== "skipped").length;
|
||||
const finalDiagnostics = finalCheck?.diagnostics ?? [];
|
||||
// A structurally valid draft can lose the model's length floor because chapters
|
||||
// were rejected. Preserve those chapter decisions for the calculated edition.
|
||||
const fallbackDraft = !best && lastCheckedDraft && !lastCheckedDraft.check.ok
|
||||
&& (lastCheckedDraft.check.reason === "all_sections_withheld" ||
|
||||
(lastCheckedDraft.check.reason === "too_short" && lastCheckedDraft.check.diagnostics.length > 0))
|
||||
? lastCheckedDraft : null;
|
||||
const computed = best ? computedReportReading(best.reading, facts) : fallbackDraft
|
||||
? computedReportReading({
|
||||
version: 4, language: "zh", contract: EVIDENCE_GRADE_CONTRACT,
|
||||
skill: { ...skill, loaded: [...skill.loaded] },
|
||||
sections: fallbackDraft.check.checked.map(({ section }) => section),
|
||||
}, facts) : null;
|
||||
const delivered = computed && (best || computed.sections.some(section => section.status === "computed")) ? computed : null;
|
||||
const selected = best ?? fallbackDraft;
|
||||
const finalDiagnostics = (fallbackDraft?.check ?? finalCheck)?.diagnostics ?? [];
|
||||
const firstConflicts = referenceConflicts(initial?.check.diagnostics ?? []);
|
||||
const finalConflicts = referenceConflicts(finalDiagnostics);
|
||||
const transformLog: ReadingTransformLog = {
|
||||
selected_attempt: best?.attempt ?? null,
|
||||
selected_attempt: delivered ? selected?.attempt ?? null : null,
|
||||
retries: Math.max(0, completedAttempts - 1),
|
||||
attempts,
|
||||
auto_rebound: autoRebound,
|
||||
@@ -957,8 +973,8 @@ export async function writeReportReading(input: Readonly<{
|
||||
final_reasons: countRejections(finalDiagnostics),
|
||||
},
|
||||
};
|
||||
const reading = best ? bindReportReadingSnapshot({
|
||||
reading: best.reading, rawSha256: best.rawSha256, transformLog,
|
||||
const reading = delivered && selected ? bindReportReadingSnapshot({
|
||||
reading: delivered, rawSha256: selected.rawSha256, transformLog,
|
||||
reportInput: input.reportInput, facts, system, gitCommit: input.gitCommit,
|
||||
}) : null;
|
||||
return { reading, ...(reading ? {} : { unavailable }), inputTokens, outputTokens, transformLog };
|
||||
|
||||
@@ -778,11 +778,12 @@ export async function resolveReportRead(deps: ReportReadCoreDeps): Promise<Repor
|
||||
? await deps.loadLongformReading({ userId: deps.userId, reportId: deps.reportId, requestId: row.requestId })
|
||||
.catch(() => null)
|
||||
: null;
|
||||
const publicReading = reading && reportReadingForReader(reading);
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
report: reportView(row, job),
|
||||
...(reading ? { reading: reportReadingForReader(reading) } : {}),
|
||||
...(publicReading ? { reading: publicReading } : {}),
|
||||
englishEdition: english.status,
|
||||
...(english.status === "ready" ? {
|
||||
longformMarkdownEn: projectOrdinaryReportMarkdown(english.markdown, "en"),
|
||||
|
||||
@@ -9,13 +9,10 @@ import type { ReportLanguage } from "./report-language";
|
||||
import { SIGN_ZH, type SignName } from "./chart-view-labels";
|
||||
import { projectOrdinaryReportMarkdown } from "./report-public-projection";
|
||||
import {
|
||||
BASIS_AUDIT_INTRO,
|
||||
READING_SECTION_WITHHELD_TEXT,
|
||||
REPORT_READING_BASIS_LABEL,
|
||||
REPORT_READING_HEADING,
|
||||
basisAuditLine,
|
||||
evidenceGradeTag,
|
||||
readingSectionView,
|
||||
visibleReadingSections,
|
||||
type ReportReading,
|
||||
} from "./personal-report-reading-contract";
|
||||
|
||||
@@ -88,20 +85,19 @@ export function buildReportExportBlocks({ markdown, charts = [], factTables = []
|
||||
// leadMarkdown also contains lifted summaries: using it here duplicates/reorders prose.
|
||||
const publishBody = (text: string) => renderReportFocusFences(stripReportChartBlocks(text), language);
|
||||
if (outline.sourcePreamble) add("body:lead", "body", language === "en" ? "Summary" : "摘要", publishBody(outline.sourcePreamble));
|
||||
if (language === "zh" && reading?.language === "zh") {
|
||||
const readingSections = language === "zh" ? visibleReadingSections(reading) : [];
|
||||
if (readingSections.length) {
|
||||
const text = [
|
||||
`## ${REPORT_READING_HEADING}`,
|
||||
...reading.sections.flatMap(section => {
|
||||
const view = readingSectionView(section);
|
||||
if (view.status === "withheld" && view.basisAudit) {
|
||||
const lines = view.basisAudit.map((row) => `- ${basisAuditLine(row).replace(/[\\`*_[\]<>&]/g, "\\$&").replace(/[\r\n]+/g, " ")}`);
|
||||
return [`### ${section.title}`, [view.explanation, BASIS_AUDIT_INTRO].filter(Boolean).join(" "), lines.join("\n")].filter(Boolean);
|
||||
}
|
||||
// The export carries the same grade tags and fallback as the page.
|
||||
return [`### ${section.title}`, ...(view.status === "withheld"
|
||||
? [[READING_SECTION_WITHHELD_TEXT, view.explanation].filter(Boolean).join(" ")]
|
||||
: view.paragraphs.map(paragraph => paragraph.grade ? `${paragraph.text}\n\n${evidenceGradeTag(paragraph.grade, paragraph.claimCount)}` : paragraph.text))];
|
||||
}),
|
||||
...readingSections.flatMap(section => [
|
||||
`### ${section.title}`,
|
||||
...section.paragraphs.map((paragraph, index) => {
|
||||
const text = section.computed && section.id === "basis" && index > 0
|
||||
? paragraph.text.split("\n").map(line => `- ${line.replace(/[\\`*_[\]<>&]/g, "\\$&")}`).join("\n")
|
||||
: paragraph.text;
|
||||
return paragraph.grade ? `${text}\n\n${evidenceGradeTag(paragraph.grade, paragraph.claimCount)}` : text;
|
||||
}),
|
||||
]),
|
||||
REPORT_READING_BASIS_LABEL,
|
||||
].join("\n\n");
|
||||
add("body:reading", "body", REPORT_READING_HEADING, text);
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
{
|
||||
"schema": "report-reading-facts-v3",
|
||||
"ascendant": {
|
||||
"sign": "Virgo",
|
||||
"lord": "Mercury",
|
||||
"nakshatra": "Uttara Phalguni"
|
||||
},
|
||||
"functional": {
|
||||
"functional_profile": "pvr_table30_v1",
|
||||
"functional_benefics": [
|
||||
"Mercury",
|
||||
"Venus"
|
||||
],
|
||||
"functional_malefics": [
|
||||
"Jupiter",
|
||||
"Mars",
|
||||
"Moon"
|
||||
]
|
||||
},
|
||||
"planets": {
|
||||
"Sun": {
|
||||
"d1_house": 6,
|
||||
"d1_dignity_zh": "极敌"
|
||||
},
|
||||
"Moon": {
|
||||
"d1_house": 7,
|
||||
"d1_dignity_zh": "入友"
|
||||
},
|
||||
"Mars": {
|
||||
"d1_house": 8,
|
||||
"d1_dignity_zh": "根本三分"
|
||||
},
|
||||
"Mercury": {
|
||||
"d1_house": 5,
|
||||
"d1_dignity_zh": "入友"
|
||||
},
|
||||
"Jupiter": {
|
||||
"d1_house": 10,
|
||||
"d1_dignity_zh": "极敌"
|
||||
},
|
||||
"Venus": {
|
||||
"d1_house": 4,
|
||||
"d1_dignity_zh": "入敌"
|
||||
},
|
||||
"Saturn": {
|
||||
"d1_house": 2,
|
||||
"d1_dignity_zh": "入旺"
|
||||
},
|
||||
"Rahu": {
|
||||
"d1_house": 4,
|
||||
"d1_dignity_zh": "极敌"
|
||||
},
|
||||
"Ketu": {
|
||||
"d1_house": 10,
|
||||
"d1_dignity_zh": "入敌"
|
||||
}
|
||||
},
|
||||
"houses": {
|
||||
"2": {
|
||||
"sign": "Libra",
|
||||
"lord": "Venus",
|
||||
"sav_score": 29
|
||||
},
|
||||
"6": {
|
||||
"sign": "Aquarius",
|
||||
"lord": "Saturn",
|
||||
"sav_score": 27
|
||||
},
|
||||
"7": {
|
||||
"sign": "Pisces",
|
||||
"lord": "Jupiter",
|
||||
"sav_score": 23
|
||||
},
|
||||
"8": {
|
||||
"sign": "Aries",
|
||||
"lord": "Mars",
|
||||
"sav_score": 28
|
||||
},
|
||||
"10": {
|
||||
"sign": "Gemini",
|
||||
"lord": "Mercury",
|
||||
"sav_score": 27
|
||||
},
|
||||
"11": {
|
||||
"sign": "Cancer",
|
||||
"lord": "Moon",
|
||||
"sav_score": 27
|
||||
},
|
||||
"12": {
|
||||
"sign": "Leo",
|
||||
"lord": "Sun",
|
||||
"sav_score": 25
|
||||
}
|
||||
},
|
||||
"timing": {
|
||||
"mahadasha": {
|
||||
"lord": "Rahu",
|
||||
"start": "2023-02-28",
|
||||
"end": "2041-02-27"
|
||||
},
|
||||
"antardasha": {
|
||||
"lord": "Jupiter",
|
||||
"start": "2025-11-10",
|
||||
"end": "2028-04-05"
|
||||
},
|
||||
"pratyantardasha": {
|
||||
"lord": "Mercury",
|
||||
"start": "2026-07-24",
|
||||
"end": "2026-11-25"
|
||||
},
|
||||
"narayana": {
|
||||
"method_status": {
|
||||
"status": "determined"
|
||||
},
|
||||
"mahadasha": {
|
||||
"sign": "Aquarius",
|
||||
"start": "2026-02-24",
|
||||
"end": "2027-02-24"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domains": {
|
||||
"career": {
|
||||
"participation": [
|
||||
{
|
||||
"id": "A10",
|
||||
"state": "executed",
|
||||
"value": "Leo"
|
||||
},
|
||||
{
|
||||
"id": "AmK",
|
||||
"state": "executed",
|
||||
"value": "Saturn"
|
||||
}
|
||||
],
|
||||
"varga_charts": {
|
||||
"D10": {
|
||||
"ascendant": "Taurus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"wealth": {
|
||||
"participation": [],
|
||||
"varga_charts": {
|
||||
"D2": {
|
||||
"ascendant": "Cancer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"marriage": {
|
||||
"participation": [
|
||||
{
|
||||
"id": "UL",
|
||||
"state": "executed",
|
||||
"value": "Taurus"
|
||||
},
|
||||
{
|
||||
"id": "DK",
|
||||
"state": "executed",
|
||||
"value": "Mars"
|
||||
}
|
||||
],
|
||||
"varga_charts": {
|
||||
"D9": {
|
||||
"ascendant": "Capricorn"
|
||||
}
|
||||
}
|
||||
},
|
||||
"health": {
|
||||
"participation": [
|
||||
{
|
||||
"id": "Badhaka",
|
||||
"state": "executed",
|
||||
"value": {
|
||||
"badhaka_sthana": {
|
||||
"house": 7,
|
||||
"sign": "Pisces"
|
||||
},
|
||||
"badhakesh": {
|
||||
"planet": "Jupiter",
|
||||
"house": 10
|
||||
},
|
||||
"status": "product_computation_pending_astrologer_review"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"evidence_grades": {
|
||||
"contract": "report_evidence_grade_v1",
|
||||
"claims": {
|
||||
"character_structure": {
|
||||
"cap": "C",
|
||||
"must_disclose": [
|
||||
"purpose_stability_not_evaluated"
|
||||
]
|
||||
},
|
||||
"career_promise": {
|
||||
"cap": "C",
|
||||
"must_disclose": [
|
||||
"purpose_stability_not_evaluated"
|
||||
]
|
||||
},
|
||||
"wealth_earning": {
|
||||
"cap": "C",
|
||||
"must_disclose": [
|
||||
"purpose_stability_not_evaluated"
|
||||
]
|
||||
},
|
||||
"wealth_retention": {
|
||||
"cap": "C",
|
||||
"must_disclose": [
|
||||
"purpose_stability_not_evaluated"
|
||||
]
|
||||
},
|
||||
"relationship_structure": {
|
||||
"cap": "C",
|
||||
"must_disclose": [
|
||||
"purpose_stability_not_evaluated"
|
||||
]
|
||||
},
|
||||
"health_pressure": {
|
||||
"cap": "C",
|
||||
"must_disclose": [
|
||||
"purpose_stability_not_evaluated"
|
||||
]
|
||||
},
|
||||
"health_obstruction": {
|
||||
"cap": "C",
|
||||
"must_disclose": [
|
||||
"purpose_stability_not_evaluated"
|
||||
]
|
||||
},
|
||||
"timing_window": {
|
||||
"cap": "C",
|
||||
"must_disclose": [
|
||||
"purpose_stability_not_evaluated"
|
||||
]
|
||||
}
|
||||
},
|
||||
"dependency_catalog": {
|
||||
"v:D2": {
|
||||
"state": "clear_at_tolerance",
|
||||
"aliases": [
|
||||
"D2",
|
||||
"财富分盘"
|
||||
]
|
||||
},
|
||||
"v:D9": {
|
||||
"state": "clear_at_tolerance",
|
||||
"aliases": [
|
||||
"D9",
|
||||
"九分盘",
|
||||
"Navamsha"
|
||||
]
|
||||
},
|
||||
"v:D10": {
|
||||
"state": "clear_at_tolerance",
|
||||
"aliases": [
|
||||
"D10",
|
||||
"事业分盘"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,7 +250,7 @@ test("the report TOC is a persistent right-hand rail that leaves the paper palet
|
||||
// 原值(3):`/<ReportToc headings=\{tocHeadings\} language=\{language\} \/>/` 与 tocHeadings 前插一条「解读」。
|
||||
// 新值:目录按 解读 / 推运 / 计算依据 分组(groupReportToc),解读按节列出。原因:产品 2026-11-07 定方案 A + 分组目录。
|
||||
assert.match(viewSource, /<ReportToc groups=\{tocGroups\} language=\{language\} \/>/);
|
||||
assert.match(viewSource, /groupReportToc\(outline\.headings, shownReading\?\.sections \?\? \[\], language\)/);
|
||||
assert.match(viewSource, /groupReportToc\(outline\.headings, visibleReadingSections\(shownReading\), language\)/);
|
||||
assert.match(viewSource, /aria-current=\{item\.id === activeId \? "location" : undefined\}/);
|
||||
assert.match(viewSource, /rehypePlugins=\{\[reportChartGrid\]\}/, "BUG-616/617 grid stays wired");
|
||||
|
||||
|
||||
@@ -256,7 +256,7 @@ test("one retry after a draft with a withheld section; tokens of both attempts a
|
||||
reportInput: {}, facts: FACTS, birthTimeConfirmed: false,
|
||||
write: writer([draft({ love: ["你注定晚婚。"] }), { sections: draft().sections.filter(({ id }) => id === "love") }], calls),
|
||||
});
|
||||
assert.ok(outcome.reading && outcome.reading.version === 4);
|
||||
assert.ok(outcome.reading && outcome.reading.version === 5);
|
||||
assert.ok(outcome.reading.sections.every((section) => "status" in section && section.status === "ok"));
|
||||
assert.deepEqual(outcome.reading.skill, SKILL);
|
||||
assert.equal(outcome.inputTokens, 2000);
|
||||
@@ -283,7 +283,9 @@ test("no facts, a failing model or a hung model all leave the report without a r
|
||||
assert.equal(hung.unavailable, "model_timeout");
|
||||
// #192 原值:两稿都含禁用词即整份不可用(rejected_banned_phrase);新值:只有那一节不显示,结构错误才整份不可用
|
||||
const partial = await writeReportReading({ reportInput: {}, facts: FACTS, birthTimeConfirmed: true, write: writer([draft({ health: ["要小心糖尿病。"] }), draft({ health: ["要小心糖尿病。"] })]) });
|
||||
assert.ok(partial.reading?.sections.some((section) => section.id === "health" && "status" in section && section.status === "withheld"));
|
||||
assert.ok(partial.reading);
|
||||
assert.equal(partial.reading.sections.some(section => section.id === "health"), false);
|
||||
assert.equal(partial.transformLog?.statistics?.final_reasons.banned_phrase, 1);
|
||||
const rejected = await writeReportReading({ reportInput: {}, facts: FACTS, birthTimeConfirmed: true, write: writer([{ sections: [] }, { sections: [] }]) });
|
||||
assert.equal(rejected.unavailable, "rejected_shape");
|
||||
});
|
||||
@@ -365,7 +367,8 @@ test("skipping the retry keeps the accepted first draft with one withheld sectio
|
||||
t.mock.timers.tick(200_000);
|
||||
const outcome = await pending;
|
||||
assert.ok(outcome.reading);
|
||||
assert.deepEqual(outcome.reading.sections.filter(({ status }) => status === "withheld").map(({ id }) => id), ["health"]);
|
||||
assert.equal(outcome.reading.sections.some(({ id }) => id === "health"), false);
|
||||
assert.equal(outcome.transformLog?.statistics?.final_reasons.banned_phrase, 1);
|
||||
assert.equal(outcome.unavailable, undefined);
|
||||
assert.equal(outcome.transformLog?.selected_attempt, 1);
|
||||
assert.equal(outcome.transformLog?.retries, 0);
|
||||
@@ -479,8 +482,7 @@ test("the page keeps a reading only in the stored shape and shows it before the
|
||||
assert.match(zh, /<p class="personal-report-evidence-grade">证据等级 C:/, "a plain line, no tap to open");
|
||||
const withheld = (accept(draft({ love: [`${PARAGRAPH}你注定晚婚。`] })) as { reading: unknown }).reading;
|
||||
const shown = renderToStaticMarkup(<PersonalReportMarkdownView markdown={markdown} reading={withheld as never} language="zh" />);
|
||||
assert.ok(shown.includes("这一节没有通过数据核对,暂不显示。"));
|
||||
assert.ok(shown.includes("<h3>感情</h3>"));
|
||||
assert.doesNotMatch(shown, /没有通过数据核对|<h3>感情<\/h3>|href="#report-reading-love"/);
|
||||
const en = renderToStaticMarkup(<PersonalReportMarkdownView markdown={markdown} reading={reading as never} language="en" />);
|
||||
assert.equal(en.includes("report-reading"), false);
|
||||
assert.equal(en.includes("计算依据"), false);
|
||||
@@ -572,7 +574,8 @@ for (const mode of ["reading", "model-down", "no-writer", "retry-skipped", "part
|
||||
} else if (mode === "partial-retry-skipped") {
|
||||
assert.equal(writes, 1);
|
||||
assert.equal(stored.snapshot.readingUnavailable, undefined);
|
||||
assert.deepEqual(stored.snapshot.reading.sections.filter(({ status }) => status === "withheld").map(({ id }) => id), ["health"]);
|
||||
assert.equal(stored.snapshot.reading.sections.some(({ id }) => id === "health"), false);
|
||||
assert.equal(stored.snapshot.reading.transform_log.statistics.final_reasons.banned_phrase, 1);
|
||||
assert.equal(stored.snapshot.reading.transform_log.selected_attempt, 1);
|
||||
assert.deepEqual(stored.snapshot.reading.transform_log.attempts[1],
|
||||
{ attempt: 2, status: "skipped", reason: "repair_skipped_deadline", sections: [] });
|
||||
|
||||
@@ -272,7 +272,8 @@ test("a repair that weakens an established summary does not discard other valid
|
||||
const result = await writeReportReading({ reportInput: {}, facts: evidence, birthTimeConfirmed: true, write });
|
||||
assert.ok(result.reading);
|
||||
assert.deepEqual(result.transformLog?.repair?.passed, ["health"]);
|
||||
assert.deepEqual(reasons(result.reading), [["career", "field_name"]]);
|
||||
assert.equal(result.reading.sections.some(({ id }) => id === "career"), false);
|
||||
assert.deepEqual(result.transformLog?.statistics?.final_reasons, { field_name: 1 });
|
||||
const first = check({
|
||||
overview: [{ text: "正文支持这一点。", claims: ["timing_window"], grade: "C" }],
|
||||
now: [{ text: "大运提供这项依据。", claims: ["timing_window"], grade: "C" }],
|
||||
@@ -332,7 +333,8 @@ test("a second usable draft gets one repair with exact cross-domain names", asyn
|
||||
}]);
|
||||
assert.equal(result.transformLog?.final_reference_conflicts, undefined);
|
||||
assert.ok(result.reading);
|
||||
assert.deepEqual(reasons(result.reading), []);
|
||||
assert.ok(result.reading.sections.every(({ status }) => status === "ok"));
|
||||
assert.deepEqual(result.transformLog?.statistics?.final_reasons, {});
|
||||
});
|
||||
|
||||
test("repair after the second draft preserves the accepted result when its deadline is too close", async (t) => {
|
||||
@@ -360,5 +362,6 @@ test("repair after the second draft preserves the accepted result when its deadl
|
||||
assert.equal(outcome.transformLog?.repair?.attempted, false);
|
||||
assert.equal(outcome.transformLog?.attempts[2]?.reason, "repair_skipped_deadline");
|
||||
assert.ok(outcome.reading);
|
||||
assert.deepEqual(reasons(outcome.reading), [["career", "field_name"]]);
|
||||
assert.equal(outcome.reading.sections.some(({ id }) => id === "career"), false);
|
||||
assert.deepEqual(outcome.transformLog?.statistics?.final_reasons, { field_name: 1 });
|
||||
});
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
import React from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { PersonalReportMarkdownView } from "../src/components/personal-report/personal-report-markdown-view";
|
||||
import { checkedFactClaim, reportReadingForReader, writeReportReading } from "../src/lib/personal-report-reading";
|
||||
import {
|
||||
EVIDENCE_GRADE_CONTRACT,
|
||||
REPORT_READING_SECTIONS,
|
||||
reportReadingSchema,
|
||||
type ReportReadingSectionId,
|
||||
} from "../src/lib/personal-report-reading-contract";
|
||||
import { computeReadingSection } from "../src/lib/personal-report-reading-fallback";
|
||||
import { buildReportExportBlocks } from "../src/lib/report-export-blocks";
|
||||
|
||||
// Projection of the public acceptance engine output, retaining only the leaves used by the fallback.
|
||||
const engineFacts = () => JSON.parse(readFileSync(new URL("./fixtures/report-reading-computed-engine.json", import.meta.url), "utf8"));
|
||||
const skill = { name: "test", version: "1", loaded: [{ path: "SKILL.md", sha256: "0".repeat(64) }] };
|
||||
const markdown = "# 合成报告\n\n## 计算正文\n\n正文。";
|
||||
|
||||
function section(id: ReportReadingSectionId) {
|
||||
return REPORT_READING_SECTIONS.find(item => item.id === id)!;
|
||||
}
|
||||
|
||||
function fallback(id: ReportReadingSectionId, facts = engineFacts()) {
|
||||
const computed = computeReadingSection(section(id), facts);
|
||||
assert.ok(computed);
|
||||
return computed;
|
||||
}
|
||||
|
||||
function textOf(computed: ReturnType<typeof fallback>) {
|
||||
return computed.paragraphs.map(({ text }) => text).join("\n");
|
||||
}
|
||||
|
||||
test("all eight computed sections use their requested engine facts and grade ceilings", () => {
|
||||
const facts = engineFacts();
|
||||
const computed = REPORT_READING_SECTIONS.filter(({ id }) => id !== "advice").map(({ id }) => fallback(id, facts));
|
||||
for (const part of computed) {
|
||||
assert.ok(part.paragraphs.length >= 2 && part.paragraphs.length <= 4, part.id);
|
||||
assert.ok(part.paragraphs.every(({ source, grade }) => source === "computed" && (grade === "C" || grade === "D")), part.id);
|
||||
}
|
||||
assert.equal(computeReadingSection(section("advice"), facts), null);
|
||||
const character = fallback("character", facts);
|
||||
assert.match(textOf(character), /上升在处女座。命宫对应的星宿是翼宿/);
|
||||
assert.match(textOf(character), /上升星座的主星是水星,落在第 \d+ 宫,尊贵状态为[\s\S]+月亮/);
|
||||
assert.match(textOf(character), /PVR 表 30.*功能吉凶星.*吉星.*凶星/);
|
||||
const career = textOf(fallback("career", facts));
|
||||
assert.match(career, /第 10 宫(事业)在双子座。宫主是水星,落在第 \d+ 宫,尊贵状态为/);
|
||||
assert.match(career, /事业分盘(D10)的上升在[\s\S]+事业映射点(A10)在狮子座。事业指标星(AmK)是土星/);
|
||||
const wealth = textOf(fallback("wealth", facts));
|
||||
assert.match(wealth, /第 2 宫(收入与积蓄)在[\s\S]+第 11 宫(收益)在[\s\S]+财富分盘(D2)的上升在[\s\S]+第 2 宫 29 分,第 11 宫 \d+ 分/);
|
||||
assert.doesNotMatch(wealth, /337|强|弱/);
|
||||
assert.match(textOf(fallback("love", facts)), /第 7 宫[\s\S]*九分盘(D9)的上升在[\s\S]+婚姻映射点(UL)在金牛座。伴侣指标星(DK)是火星/);
|
||||
const health = textOf(fallback("health", facts));
|
||||
assert.match(health, /第 6 宫[\s\S]*第 8 宫[\s\S]*第 12 宫[\s\S]*阻碍宫(Badhaka)是第 7 宫[\s\S]*阻碍宫主是木星[\s\S]*产品计算,待占星师复核/);
|
||||
assert.equal(checkedFactClaim(health, "health", facts), undefined);
|
||||
assert.equal(checkedFactClaim("这里预测骨折。", "health", facts), "health_outcome");
|
||||
const now = textOf(fallback("now", facts));
|
||||
for (const key of ["mahadasha", "antardasha", "pratyantardasha"]) {
|
||||
assert.ok(now.includes(`${facts.timing[key].start} 至 ${facts.timing[key].end}`), key);
|
||||
}
|
||||
assert.match(now, /纳拉亚纳大运.*参数敏感,只作条件窗口/);
|
||||
assert.deepEqual(fallback("overview", facts).paragraphs[0], character.paragraphs[0]);
|
||||
assert.equal(checkedFactClaim(textOf(fallback("overview", facts)), "overview", facts), undefined);
|
||||
assert.match(textOf(fallback("basis", facts)), /计算依据支持的等级[\s\S]*上限/);
|
||||
});
|
||||
|
||||
test("D10, D2 and D9 suppress their calculated sign at the birth-time boundary", () => {
|
||||
const facts = engineFacts();
|
||||
for (const [id, code] of [["career", "D10"], ["wealth", "D2"], ["love", "D9"]] as const) {
|
||||
facts.evidence_grades.dependency_catalog[`v:${code}`].state = "boundary_sensitive";
|
||||
const result = fallback(id, facts);
|
||||
const boundary = result.paragraphs.find(({ text }) => text.includes(code));
|
||||
assert.match(boundary?.text ?? "", /出生时间误差内会换座,暂不判断/);
|
||||
assert.doesNotMatch(boundary?.text ?? "", /上升在\S+座。/);
|
||||
assert.equal(boundary?.grade, "D");
|
||||
}
|
||||
facts.evidence_grades.claims.career_promise.cap = "D";
|
||||
assert.ok(fallback("career", facts).paragraphs.every(({ grade }) => grade === "D"));
|
||||
facts.report_mode = "historical_replay";
|
||||
facts.timing.narayana.method_status.status = "undetermined";
|
||||
const timing = textOf(fallback("now", facts));
|
||||
assert.match(timing, /回看当时[\s\S]*当前段暂无法确定/);
|
||||
assert.ok(!timing.includes(facts.timing.narayana.mahadasha.start));
|
||||
});
|
||||
|
||||
test("after one unsuccessful repair, computed sections are stored without rejection copy or failed advice", async () => {
|
||||
const neutral = "这一段复述了合成材料中的顺序以及可比对的线索。叙述保留记录本身的范围和时间。".repeat(3);
|
||||
const rejected = new Set(["career", "advice", "basis"]);
|
||||
const draft = {
|
||||
sections: REPORT_READING_SECTIONS.map(({ id }) => ({
|
||||
id, paragraphs: [
|
||||
{ kind: "fact", text: neutral },
|
||||
{ kind: "fact", text: rejected.has(id) ? "这节保留 field_id。" : neutral },
|
||||
],
|
||||
})),
|
||||
};
|
||||
const calls: (readonly string[] | undefined)[] = [];
|
||||
const write = Object.assign(async ({ repairSections }: { repairSections?: readonly ReportReadingSectionId[] }) => {
|
||||
calls.push(repairSections);
|
||||
return { body: repairSections ? { sections: draft.sections.filter(({ id }) => repairSections.includes(id)) } : draft, inputTokens: 1, outputTokens: 1 };
|
||||
}, { prompt: { system: "合成测试", skill } });
|
||||
const result = await writeReportReading({ reportInput: {}, facts: engineFacts(), birthTimeConfirmed: true, write });
|
||||
assert.deepEqual(calls, [undefined, ["career", "advice", "basis"]]);
|
||||
assert.equal(result.reading?.version, 5);
|
||||
const stored = reportReadingSchema.parse(JSON.parse(JSON.stringify(result.reading)));
|
||||
const reading = reportReadingForReader(stored);
|
||||
assert.ok(reading);
|
||||
assert.deepEqual(result.reading?.sections.filter(({ status }) => status === "computed").map(({ id }) => id), ["career", "basis"]);
|
||||
assert.deepEqual(result.reading?.transform_log.statistics?.final_reasons, { field_name: 3 });
|
||||
assert.doesNotMatch(JSON.stringify(reading), /field_name|field_id|transform_log|"id":"advice"/);
|
||||
const html = renderToStaticMarkup(<PersonalReportMarkdownView markdown={markdown} reading={reading} language="zh" />);
|
||||
const exported = buildReportExportBlocks({ markdown, reading }).find(({ id }) => id === "body:reading")!.text;
|
||||
for (const output of [html, exported]) {
|
||||
assert.match(output, /事业映射点(A10)在狮子座/);
|
||||
assert.match(output, /证据等级 [CD]/);
|
||||
assert.doesNotMatch(output, /没有通过(?:数据)?核对|field_name|几条建议|report-reading-advice/);
|
||||
}
|
||||
|
||||
const allRejected = { sections: draft.sections.map(({ id }) => ({
|
||||
id, paragraphs: [{ kind: "fact", text: "这节保留 field_id。" }],
|
||||
})) };
|
||||
const allComputed = await writeReportReading({
|
||||
reportInput: {}, facts: engineFacts(), birthTimeConfirmed: true, attempts: 1,
|
||||
write: Object.assign(async () => ({ body: allRejected, inputTokens: 1, outputTokens: 1 }), { prompt: write.prompt }),
|
||||
});
|
||||
assert.deepEqual(allComputed.reading?.sections.map(({ id, status }) => [id, status]),
|
||||
REPORT_READING_SECTIONS.filter(({ id }) => id !== "advice").map(({ id }) => [id, "computed"]));
|
||||
assert.equal(allComputed.transformLog?.statistics?.final_withheld, 9);
|
||||
});
|
||||
|
||||
test("v3 and v4 withheld sections are computed only when their facts are already available", () => {
|
||||
for (const version of [3, 4] as const) {
|
||||
const stored = reportReadingSchema.parse({
|
||||
version, language: "zh", contract: EVIDENCE_GRADE_CONTRACT, skill,
|
||||
sections: REPORT_READING_SECTIONS.map(({ id, title }) => ({
|
||||
id, title, ...(["career", "advice"].includes(id)
|
||||
? { status: "withheld", reason: "field_name" }
|
||||
: { status: "ok", paragraphs: [{ text: "历史报告正文。", ...(version === 4 ? { kind: "fact" } : { grade: "D" }) }] }),
|
||||
})),
|
||||
});
|
||||
const omitted = reportReadingForReader(stored);
|
||||
assert.ok(omitted && reportReadingSchema.safeParse(omitted).success);
|
||||
assert.ok(omitted.sections.every(({ id }) => id !== "career" && id !== "advice"));
|
||||
const computed = reportReadingForReader(stored, engineFacts());
|
||||
assert.ok(computed && reportReadingSchema.safeParse(computed).success);
|
||||
const career = computed.sections.find(({ id }) => id === "career");
|
||||
assert.ok(career && "status" in career && career.status === "computed");
|
||||
assert.ok(computed.sections.every(({ id }) => id !== "advice"));
|
||||
assert.doesNotMatch(JSON.stringify(computed), /field_name/);
|
||||
}
|
||||
});
|
||||
@@ -10,7 +10,8 @@ import {
|
||||
reportReadingSchema,
|
||||
type ReadingRejection,
|
||||
} from "../src/lib/personal-report-reading";
|
||||
import { BASIS_AUDIT_INTRO, EVIDENCE_GRADE_CONTRACT, READING_SECTION_WITHHELD_TEXT } from "../src/lib/personal-report-reading-contract";
|
||||
import { EVIDENCE_GRADE_CONTRACT } from "../src/lib/personal-report-reading-contract";
|
||||
import { computeReadingSection } from "../src/lib/personal-report-reading-fallback";
|
||||
import { buildReportExportBlocks } from "../src/lib/report-export-blocks";
|
||||
|
||||
type Section = (typeof REPORT_READING_SECTIONS)[number]["id"];
|
||||
@@ -131,14 +132,18 @@ test("percentages and fractions expressed as 成 cannot support accuracy claims"
|
||||
|
||||
test("withheld basis persists a fact-only audit for the page and Markdown", () => {
|
||||
const checked = reading({ basis: "检测器显示。", health: "这里预测骨折。" });
|
||||
const stored = reportReadingSchema.parse(JSON.parse(JSON.stringify(checked)));
|
||||
const basis = checked.sections.find(({ id }) => id === "basis");
|
||||
assert.ok(basis?.status === "withheld" && basis.basisAudit);
|
||||
const computed = computeReadingSection(basis, FACTS);
|
||||
const sections = checked.sections.flatMap(section => section.status === "ok" ? [section] : []);
|
||||
const stored = reportReadingSchema.parse(JSON.parse(JSON.stringify({ ...checked, version: 5, sections: [...sections, computed] })));
|
||||
const rendered = renderToStaticMarkup(createElement(ReportReadingSection, { reading: stored }));
|
||||
const markdown = buildReportExportBlocks({ markdown: "# 合成资料", reading: stored }).find((block) => block.id === "body:reading")!.text;
|
||||
for (const output of [rendered, markdown]) {
|
||||
assert.ok(output.includes(BASIS_AUDIT_INTRO));
|
||||
assert.ok(output.includes("下面列出计算依据支持的等级"));
|
||||
assert.ok(output.includes("获得收入 · 上限 C · 缺失或临界的必需依据 财富分盘上升边界 · 必须说明 六力"));
|
||||
assert.ok(output.includes("custom:missing"));
|
||||
assert.equal(output.split(READING_SECTION_WITHHELD_TEXT).length - 1, 1);
|
||||
assert.doesNotMatch(output, /没有通过(?:数据)?核对|具体健康问题|<h3>健康<\/h3>|### 健康/);
|
||||
assert.ok(!output.includes("检测器显示") && !output.includes("本命盘上升边界"));
|
||||
}
|
||||
assert.match(rendered, /unknown_claim.*unknown_dependency|unknown_dependency.*unknown_claim/);
|
||||
|
||||
@@ -79,8 +79,7 @@ test("the same raw draft is rechecked against one changed fact state and logs th
|
||||
const html = renderToStaticMarkup(createElement(ReportReadingSection, { reading: sensitive.reading }));
|
||||
const markdown = buildReportExportBlocks({ markdown: "", reading: sensitive.reading }).find(({ id }) => id === "body:reading")!.text;
|
||||
for (const output of [html, markdown]) {
|
||||
assert.match(output, /判断用到的依据还不能支持这个证据等级/);
|
||||
assert.doesNotMatch(output, /ref_unstable|D10 列在事业节/);
|
||||
assert.doesNotMatch(output, /判断用到的依据还不能支持这个证据等级|ref_unstable|D10 列在事业节|<h3>事业<\/h3>|### 事业/);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -105,7 +104,7 @@ test("the stored snapshot binds the selected raw response and records a failed r
|
||||
system_prompt_sha256: reportReadingSha256("原始提示"),
|
||||
raw_response_sha256: canonicalReportReadingSha256(rawResponse),
|
||||
stored_sha256: canonicalReportReadingSha256(stored),
|
||||
rules: { evidence_grade_contract: EVIDENCE_GRADE_CONTRACT, postcheck_version: 3, git_commit: COMMIT },
|
||||
rules: { evidence_grade_contract: EVIDENCE_GRADE_CONTRACT, postcheck_version: 4, git_commit: COMMIT },
|
||||
});
|
||||
assert.equal(stored.transform_log.selected_attempt, 1);
|
||||
assert.equal(stored.transform_log.retries, 1);
|
||||
@@ -115,6 +114,7 @@ test("the stored snapshot binds the selected raw response and records a failed r
|
||||
assert.ok(reportReadingSchema.safeParse(JSON.parse(JSON.stringify(result.reading))).success);
|
||||
assert.equal(reportReadingSchema.safeParse({ ...stored, transform_log: undefined }).success, false);
|
||||
const publicReading = reportReadingForReader(result.reading);
|
||||
assert.ok(publicReading);
|
||||
assert.equal("snapshot" in publicReading, false);
|
||||
assert.equal("transform_log" in publicReading, false);
|
||||
assert.deepEqual(publicReading.sections, result.reading.sections);
|
||||
@@ -145,6 +145,7 @@ test("offline acceptance replays an archived draft and the manifest matches ever
|
||||
for (const [name, hash] of Object.entries(manifest.files_sha256)) assert.equal(reportReadingSha256(file(name)), hash, name);
|
||||
const log = JSON.parse(file("transform_log.json").toString("utf8"));
|
||||
assert.deepEqual(log, stored.transform_log);
|
||||
assert.equal(JSON.parse(file("postcheck.json").toString("utf8")).computed_sections, 0);
|
||||
assert.deepEqual(log.attempts[0].sections.find(({ id }: { id: string }) => id === "career").paragraphs.at(-1).renamed_fields,
|
||||
[{ from: "claim_type", to: "claims" }]);
|
||||
assert.deepEqual(JSON.parse(file("raw.json").toString("utf8")), draft(true));
|
||||
|
||||
@@ -100,7 +100,10 @@ async function main() {
|
||||
...(repairSha && captured.has(repairSha) ? { "repair_raw.json": canonicalReportReadingJson(captured.get(repairSha)) } : {}),
|
||||
"reading.json": canonicalReportReadingJson(reading),
|
||||
"final.md": final ?? "",
|
||||
"postcheck.json": canonicalReportReadingJson({ ok: reading !== null, unavailable: outcome.unavailable, ...transformLog }),
|
||||
"postcheck.json": canonicalReportReadingJson({
|
||||
ok: reading !== null, unavailable: outcome.unavailable, ...transformLog,
|
||||
computed_sections: reading?.sections.filter(({ status }) => status === "computed").length ?? 0,
|
||||
}),
|
||||
"transform_log.json": canonicalReportReadingJson(transformLog ?? null),
|
||||
};
|
||||
const files_sha256 = Object.fromEntries(Object.entries(files).map(([name, content]) => [name, reportReadingSha256(content)]));
|
||||
|
||||
Reference in New Issue
Block a user