Files
Jyotisha/frontend/tests/reading-internal-code-2108.test.ts
ClaudeandClaude Opus 5.5 a33b5d42d4
Independent Staging Quality Gate / validate-frontend (push) Successful in 6m9s
Independent Staging Quality Gate / validate-python (push) Successful in 7m22s
Independent Staging Quality Gate / publish (push) Successful in 2m51s
fix(report): Narayana readings carry plain words; an underscore code in the reading goes to repair (BUG-2108)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-21 01:28:28 +08:00

61 lines
3.4 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { acceptReportReadingDraft, readingInternalCodes, REPORT_READING_SECTIONS, type ReadingRejection } from "../src/lib/personal-report-reading";
import { EVIDENCE_GRADE_CONTRACT } from "../src/lib/personal-report-reading-contract";
/**
* BUG-2108: the reading facts carry Narayana profile ids (rath_p50_md_parity_v1); nothing in the reading
* may show an underscore-style internal code. It is its own reason, internal_code, routed through the same
* single repair as technique_name / hedge_phrase / strength_verdict; other markup stays field_name.
*/
type Section = (typeof REPORT_READING_SECTIONS)[number]["id"];
const NEUTRAL = "这一段只说明虚构材料的记录顺序以及供比对的线索。叙述保留记录本身的范围和时间,也指出没有得到回答的问题。这里的细节用于检验逐节复查的行为。".repeat(2);
const CLAIMS: Partial<Record<Section, string>> = {
character: "character_structure", career: "career_promise", wealth: "wealth_earning",
love: "relationship_structure", health: "health_pressure", now: "timing_window",
};
const FACTS = {
evidence_grades: {
contract: EVIDENCE_GRADE_CONTRACT,
claims: Object.fromEntries(Object.entries(CLAIMS).map(([section, claim]) => [claim, { cap: "C", sections: [section] }])),
},
};
function reasonOf(section: Section, text: string): ReadingRejection | undefined {
const sections = REPORT_READING_SECTIONS.map(({ id }) => ({
id,
paragraphs: [NEUTRAL, id === section ? text : NEUTRAL].map((paragraph) => {
const claim = CLAIMS[id];
return claim ? { text: paragraph, claims: [claim], grade: "C", refs: [] } : { text: paragraph, kind: "fact" };
}),
}));
const result = acceptReportReadingDraft({ sections }, FACTS, {
name: "reading", version: "test", loaded: [{ path: "SKILL.md", sha256: "0".repeat(64) }],
});
assert.ok(result.ok, JSON.stringify(result));
const part = result.reading.sections.find(({ id }) => id === section)!;
return part.status === "withheld" ? part.reason as ReadingRejection : undefined;
}
test("BUG-2108: underscore identifiers are found; URLs, chart codes and plain words are not", () => {
assert.deepEqual(readingInternalCodes("默认排法用 rath_p50_md_parity_v1 起算。"), ["rath_p50_md_parity_v1"]);
assert.deepEqual(readingInternalCodes("bhrigu_bindu 落第 4 宫,A10_Karma_Pada 在第 7 宫。"), ["bhrigu_bindu", "A10_Karma_Pada"]);
for (const miss of ["事业分盘(D10)里水星落第 2 宫。", "见 https://example.com/a_b_c 这一页。", "Vimshottari 大运从 2012 年起。",
"下划线 _ 单独出现。", "第 7 宫主落第 1 宫。"]) {
assert.deepEqual(readingInternalCodes(miss), [], miss);
}
});
test("BUG-2108: a code in any section is internal_code, 「依据与边界」 included", () => {
assert.equal(reasonOf("basis", "Narayana 两种排法:rath_stronger_lord_start_parity_v1 从射手座起,顺排。"), "internal_code");
assert.equal(reasonOf("career", "事业这一层按 pvr_table30_v1 判断,十宫主在四宫。"), "internal_code");
assert.equal(reasonOf("basis", "Narayana 另一种排法:按小运起点星座奇偶,从射手座起,顺排。"), undefined);
});
test("BUG-2108: other markup is still field_name", () => {
assert.equal(reasonOf("career", "事业 = 十宫主在四宫。"), "field_name");
assert.equal(reasonOf("career", "事业里有 *重点* 一句。"), "field_name");
});