Files
Jyotisha/frontend/tests/reading-fallback-2117.test.ts
ClaudeandClaude Opus 5.5 e2c49e3d71 fix(report): the computed body sections say the life area, not house numbers, scores or whole-day dates (BUG-2148)
After BUG-2143 the model's eight reader sections carry no house numbers, but a section that fell back to the
computed text still wrote 「第 10 宫(事业)在各宫得分里是 31 分」「金星落在第 4 宫」 and 「2023-02-28 至 2041-02-27」.
The computed text now names the life area a planet looks after, the condition its sign gives it (a condition,
not a result), a plain level for the house score, and month turning points for the current and next period.
「依据与边界」 keeps houses and numbers. Tested on two public Astro-Databank charts through the same checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-22 09:50:30 +08:00

218 lines
15 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// BUG-2117 (staging round twenty-four): 「事业」 and 「感情」 fell back to three bare computed lines. A section
// was withheld for its first reason only, the one repair fixed that reason, and the second (a dated sentence
// without its birth-time condition) survived. The condition is now put in by the program, the repair note
// names every reader-wording rule, and a section that still fails only on reader wording after the repair
// keeps its other sentences when enough of them stay. Fake writers and fictional facts only.
// BUG-2143 (产品负责人 2026-11-22): 正文不写宫位编号,这里的虚构段落改成不带宫位的说法;测的规则不变。
import assert from "node:assert/strict";
import test from "node:test";
import {
acceptReportReadingDraft,
writeReportReading,
type ReadingSkillMeta,
type ReportReadingWriter,
} from "../src/lib/personal-report-reading";
import { joinThemes } from "../src/lib/personal-report-boundary-line";
import { EVIDENCE_GRADE_CONTRACT, REPORT_READING_SECTIONS, type ReportReadingSectionId } from "../src/lib/personal-report-reading-contract";
import { computeReadingSection } from "../src/lib/personal-report-reading-fallback";
import { annualReplyStrengthVerdicts } from "../src/lib/annual-question-check";
import { annualBasisText, withoutObservationHedge } from "../src/lib/annual-reader-display";
import { reportBirthScenarioCopy } from "../src/lib/report-birth-marking";
const SKILL: ReadingSkillMeta = { name: "reading", version: "test", loaded: [{ path: "SKILL.md", sha256: "0".repeat(64) }] };
const FILL = "本段复述虚构记录中的顺序、参与者位置以及需要核对的几条线索。读者可对照各行说明追溯原记录。".repeat(3);
const SUFFIX = "另一种情景下的结论还没有评估。";
const claim = (sections: string[], required: string[]) => ({ cap: "C", sections, required: required.map((id) => ({ id })), checked: [], auxiliary: [] });
function boundaryFacts(kind: "chosen_line" | "sensitivity_range" | "birth_window" = "birth_window") {
// BUG-2141: the condition is added only for a range the user gave (birth time marked uncertain).
const source = kind === "birth_window" ? "user_stated" : kind === "chosen_line" ? "rectified_range" : "confirmed_minute";
return { birth_precision: { window: { source } }, evidence_grades: {
contract: EVIDENCE_GRADE_CONTRACT,
claims: {
career_promise: claim(["career"], ["v:D1", "v:D10"]),
timing_window: claim(["career", "now"], ["s:vimshottari"]),
},
dependency_catalog: {
"v:D1": { state: "clear_at_tolerance", aliases: ["本命盘"] },
"v:D10": { state: "boundary_sensitive", aliases: ["D10", "事业分盘"] },
"s:vimshottari": { state: "executed", aliases: ["Vimshottari"] },
},
boundary: {
contract: "report_boundary_dependence_v1", other_side_line_zh: SUFFIX,
vargas: { D10: kind === "chosen_line"
? { kind, label_zh: "事业分盘(D10)" }
: { kind, label_zh: "事业分盘(D10)", direction: "earlier", birth_time_seconds: 19 } },
refs: { "v:D10": ["D10"] },
},
} };
}
function boundaryDraft(overrides: Partial<Record<ReportReadingSectionId, Record<string, unknown>[]>>) {
return { sections: REPORT_READING_SECTIONS.map(({ id }) => ({
id, paragraphs: [{ text: FILL, kind: "fact" }, { text: FILL, kind: "fact" }, ...(overrides[id] ?? [])],
})) };
}
const careerTexts = (value: ReturnType<typeof acceptReportReadingDraft>) => {
assert.ok(value.ok, JSON.stringify(value));
const section = value.reading.sections.find(({ id }) => id === "career")!;
return section.status === "ok" ? section.paragraphs.slice(2).map(({ text }) => text) : [];
};
test("a dated conclusion in an affected paragraph gets its condition from the program, only for an uncertain birth time", () => {
const dated = { claims: ["career_promise", "timing_window"], grade: "C", refs: ["v:D10", "s:vimshottari"] };
const plain = acceptReportReadingDraft(boundaryDraft({ career: [{ text: "事业分盘显示 2027 年 5 月前更适合争取岗位调整。", ...dated }] }), boundaryFacts(), SKILL);
assert.equal(plain.diagnostics.length, 0);
// 原值(BUG-2117): 补「按你选择的出生时间,」(生时纠正里自选的情景);新值: 只在用户把出生时间标为不确定时补
// 「按你提供的出生时间,」;原因: BUG-2141,产品负责人 2026-11-22「同意」
assert.match(careerTexts(plain)[0]!, /^按你提供的出生时间,事业分盘显示 2027 年 5 月前更适合争取岗位调整。/);
// A short lead-in stays in front of the condition.
const leadIn = acceptReportReadingDraft(boundaryDraft({ career: [{ text: "时间上,2027 年 5 月前更适合争取岗位调整,事业分盘也这样看。", ...dated }] }), boundaryFacts(), SKILL);
assert.match(careerTexts(leadIn)[0]!, /^时间上,按你提供的出生时间,2027 年 5 月前/);
// A rectified or trusted minute: no condition.
for (const kind of ["chosen_line", "sensitivity_range"] as const) {
const settled = acceptReportReadingDraft(boundaryDraft({ career: [{ text: "事业分盘显示 2027 年 5 月前更适合争取岗位调整。", ...dated }] }), boundaryFacts(kind), SKILL);
assert.equal(careerTexts(settled)[0], "事业分盘显示 2027 年 5 月前更适合争取岗位调整。", kind);
}
// Already conditioned: left as written, not doubled.
const written = acceptReportReadingDraft(boundaryDraft({ career: [{ text: "按你提供的出生时间,事业分盘显示 2027 年 5 月前更适合争取岗位调整。", ...dated }] }), boundaryFacts(), SKILL);
assert.equal(careerTexts(written)[0]!.split("按你提供的出生时间").length, 2, "one in the sentence, no section line");
});
// Writer-level: a career section whose only fault is a dignity over-statement the repair does not fix.
const PARAGRAPH = "你的上升落在金牛座,因为代表你自己的星是金星,金星在盘上力气中等,你给人的感觉是稳、慢热、重视安全感。做事先看清楚再动手,喜欢把节奏握在自己手里,对外显得温和,对内很有主见。".repeat(2);
const SECTION_CLAIM: Record<string, string | null> = {
overview: null, character: "character_structure", career: "career_promise", wealth: "wealth_earning",
love: "relationship_structure", health: "health_pressure", now: "timing_window", advice: null, basis: null,
};
const writerClaim = (cap: string, sections: string[]) => ({ cap, sections, required: [], checked: [], must_disclose: [], parameter_sensitive: [] });
const FACTS = {
schema: "report-reading-facts-v3",
minute_confirmed: true,
functional: { functional_benefics: ["Saturn"], functional_malefics: ["Jupiter"], natural_vs_functional_conflicts: [] },
ascendant: { sign: "Taurus", lord: "Venus" },
planets: { Sun: { d1_sign: "Pisces", d1_house: 11 } },
domains: { career: { varga: "D10", houses: { "10": { lord: "Saturn" } } } },
timing: { md: "Rahu", mahadasha: { lord: "Rahu", start: "2023-07-08", end: "2041-07-08" } },
evidence_grades: {
contract: "report_evidence_grade_v1",
dependency_catalog: {},
claims: {
character_structure: writerClaim("C", ["overview", "character"]),
career_promise: writerClaim("C", ["overview", "career"]),
wealth_earning: writerClaim("C", ["overview", "wealth"]),
wealth_retention: writerClaim("C", ["overview", "wealth"]),
relationship_structure: writerClaim("C", ["overview", "love"]),
health_pressure: writerClaim("C", ["overview", "health"]),
health_obstruction: writerClaim("D", ["health"]),
timing_window: writerClaim("C", ["overview", "career", "wealth", "love", "health", "now"]),
},
},
};
function draft(overrides: Partial<Record<string, string[]>> = {}) {
return { sections: REPORT_READING_SECTIONS.map((section) => ({
id: section.id,
paragraphs: (overrides[section.id] ?? [PARAGRAPH, PARAGRAPH]).map((text) => {
const claimType = SECTION_CLAIM[section.id];
return claimType ? { text, claims: [claimType], grade: "C", refs: [] } : { text, kind: "fact" };
}),
})) };
}
function writer(bodies: unknown[], calls: string[] = []): ReportReadingWriter {
return Object.assign(async (input: Parameters<ReportReadingWriter>[0]) => {
calls.push(input.user);
return { body: bodies.shift(), inputTokens: 1000, outputTokens: 500 };
}, { prompt: { system: "system", skill: SKILL } });
}
const OVERSTATED = "木星在关系这一块施展不开。";
test("after the one repair, a section failing only on reader wording keeps its other sentences", async () => {
const career = [PARAGRAPH, `${PARAGRAPH}${OVERSTATED}`];
const repairOnly = { sections: draft({ career }).sections.filter(({ id }) => id === "career") };
const calls: string[] = [];
const outcome = await writeReportReading({
reportInput: {}, facts: FACTS, birthTimeConfirmed: true, write: writer([draft({ career }), repairOnly], calls),
});
assert.equal(calls.length, 2, "one draft and one repair");
// The repair note names every reader-wording rule, not only the one that was found first.
assert.match(calls[1]!, /技法或点位的名字/);
// 原值: 修改说明里也要求带日期的结论写「按你选择的出生时间,」;新值: 不再要求(程序只在出生时间标为不确定时补);原因: BUG-2141
assert.doesNotMatch(calls[1]!, /按你选择的出生时间/);
const section = outcome.reading?.sections.find(({ id }) => id === "career");
assert.equal(section && "status" in section ? section.status : undefined, "ok");
const text = section && "paragraphs" in section ? section.paragraphs.map(({ text }) => text).join("") : "";
assert.doesNotMatch(text, /施展不开/);
assert.ok(text.length > PARAGRAPH.length * 1.5);
const log = outcome.transformLog!;
assert.deepEqual(log.salvaged?.map(({ section, reasons, dropped_sentences }) => [section, reasons, dropped_sentences]),
[["career", ["dignity_overstatement"], 1]]);
assert.ok(log.salvaged![0]!.kept_ratio >= 0.6);
assert.equal(log.statistics?.final_reasons.dignity_overstatement, undefined);
});
test("a section that would keep too little, or fails a fact check, is not salvaged", async () => {
const mostly = [`${OVERSTATED}金星在收入这一块最能发挥。`, `土星在事业上一定顺利。${OVERSTATED}`];
const repairOnly = { sections: draft({ career: mostly }).sections.filter(({ id }) => id === "career") };
const outcome = await writeReportReading({
reportInput: {}, facts: FACTS, birthTimeConfirmed: true, write: writer([draft({ career: mostly }), repairOnly]),
});
const section = outcome.reading?.sections.find(({ id }) => id === "career");
assert.notEqual(section && "status" in section ? section.status : undefined, "ok");
assert.equal(outcome.transformLog?.salvaged, undefined);
// A banned phrase is a fact-level rule, never salvaged.
const banned = [PARAGRAPH, `${PARAGRAPH}你注定晚婚。`];
const love = { sections: draft({ love: banned }).sections.filter(({ id }) => id === "love") };
const kept = await writeReportReading({
reportInput: {}, facts: FACTS, birthTimeConfirmed: true, write: writer([draft({ love: banned }), love]),
});
const loveSection = kept.reading?.sections.find(({ id }) => id === "love");
assert.notEqual(loveSection && "status" in loveSection ? loveSection.status : undefined, "ok");
});
test("the computed 事业 and 感情 give the house score and Venus, not three bare lines", () => {
const facts = {
houses: {
"7": { sign: "Capricorn", lord: "Saturn", sav_score: 27 },
"10": { sign: "Aries", lord: "Mars", sav_score: 31 },
},
planets: {
Mars: { d1_house: 4, d1_dignity_zh: "入友" },
Saturn: { d1_house: 9, d1_dignity_zh: "入友" },
Venus: { d1_house: 4, d1_dignity_zh: "落陷" },
},
domains: {},
};
const career = computeReadingSection({ id: "career", title: "事业" }, facts)!;
// 原值: /第 10 宫(事业)在各宫得分里是 31 分。/、/^金星落在第 4 宫/、/在各宫得分里是 27 分。/;新值: 得分写成底子厚薄、
// 金星写它所在星座的条件,不写宫位编号和分数;原因: BUG-2148,正文计算稿也过 BUG-2143 的宫位检查
assert.ok(career.paragraphs.some(({ text }) => /事业这一块底子比较厚。/.test(text)), JSON.stringify(career));
const love = computeReadingSection({ id: "love", title: "感情" }, facts)!;
assert.ok(love.paragraphs.some(({ text }) => /^代表感情的金星:金星所在的星座对它不利/.test(text)), JSON.stringify(love));
assert.ok(love.paragraphs.some(({ text }) => /伴侣和合作这一块底子中等。/.test(text)));
});
test("round-twenty-four wording: no double 和, the report note in her words, no 「仅供观察」", () => {
assert.equal(joinThemes(["性格特点", "收入来源", "存钱守财"]), "性格特点、收入来源和存钱守财");
const zh = reportBirthScenarioCopy({ kind: "self_selected", side: "before", differingDomains: ["婚恋", "事业"] }, "personal", "zh");
assert.match(zh, /婚恋、事业这些方面的判断,按你选择的出生时间推算;其他可能的出生时间尚未作比较。/);
assert.doesNotMatch(zh, /还没有评估|只适用于|排除/);
const en = reportBirthScenarioCopy({ kind: "self_selected", side: "before", differingDomains: ["婚恋"] }, "personal", "en");
assert.match(en, /are calculated from the birth time you chose; other possible birth times have not been compared yet\./);
const note = "关系参照随出生参数变化。年龄段来自引擎的年度取样,仅供观察,不能据此确定事件时间或关系结果。";
assert.equal(withoutObservationHedge(note), "关系参照随出生参数变化。年龄段来自引擎的年度取样,不能据此确定事件时间或关系结果。");
assert.equal(annualBasisText(note), withoutObservationHedge(note));
});
test("a claim about every planet is unsupported when the material puts one below the line", () => {
const answer = "各颗星的力量都在最低线以上,都能起作用。";
const described = "年盘六维力量与最低线之比:太阳 1.08、水星 0.9,只说能否起作用,不说好坏。";
assert.deepEqual(annualReplyStrengthVerdicts(answer, described), [answer]);
// A material sentence that states the verdict itself still allows it.
assert.deepEqual(annualReplyStrengthVerdicts(answer, "这一年各颗星的力量都在最低线以上,都能起作用。"), []);
assert.deepEqual(annualReplyStrengthVerdicts("木星五分力 12.51。", described), []);
// Every planet over the line in the material: the same claim is supported.
assert.deepEqual(annualReplyStrengthVerdicts(answer, "年盘六维力量与最低线之比:太阳 1.08、木星 1.2,只说能否起作用,不说好坏。"), []);
});