fix(ui): pada shown as 第 N 分区 everywhere users or the model read it — second sweep + shape guards (BUG-2349 follow-up)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
This commit is contained in:
@@ -32105,6 +32105,16 @@
|
||||
- 防复发:用户可见文字一律用「星宿分区」,不写「足」「pada」。
|
||||
- 关联记录:BUG-2340(盘面数据)、出生时间稳定性卡片(2026-11-03)。
|
||||
- 修复版本:分支 `claude/pada-wording-2349`。
|
||||
- 跟进(第二次扫,2026-11-25):
|
||||
- 现象:负责人截图里仍有「第 N 足」:盘面检视副标题「上升 … Purva Phalguni 第 1 足」、盘面数据行星表、「出生资料与口径」那一排小标签。
|
||||
- 为什么第一次漏了:第一次只按字面写法找 `第${x}足`、`月宿(足)`,没找带空格的模板(`` ` 第 ${pada} 足` ``)、JSX 里拆开的写法(`第 {row.pada} 足`)、单独的列头 `<th>足</th>`、「(足未提供)」,也没扫 Python f-string(`f' 第{pada}足'`)和把旧文字改写成「第 N Pada(星宿四分区)」的规整正则。
|
||||
- 本次改动(全部改为「第 N 分区」/「(分区未提供)」/「分区」):
|
||||
- 前端:`lib/ephemeris-view.ts`(月宿说明);`chart-board/chart-inspector.tsx` 三处(行星月宿、本命月宿、盘面检视副标题里的上升);`chart-side-cards.tsx`(月宿列与「足未提供」);`chart-deep-reading.tsx` 两处(「出生资料与口径」小标签、月宿一行);`chart-data-planets.tsx` 两处(上升行、行星行);`chart-data-card.tsx` 列头「足」→「分区」。
|
||||
- Python(报告与问答取数里模型和用户能读到的文字):`scripts/research/professional_parity_closure.py` 三处 f-string(星宿层、本命星宿、月亮星宿);`scripts/pl9_full_data_export.py` 与 `scripts/pl9_language_terms.py` 把旧的「第N足」改写成「第N分区」(原来改成「第N Pada(星宿四分区)」),行星表列头「Pada」→「星宿分区」。
|
||||
- 不改:合盘 Rajju 的「足」(身体部位,`RAJJU_ZH`);`pl9_full_data_export.py` 里中译英对照表的 `"足": "pada"`(只用于英文版把残留中文译回英文);Jaimini「奇数足」排法(odd-footed signs,不是星宿 Pada);报告附录已用的「星宿四分」列头(不含「足」/「pada」,本次不动);命令行工具 `dasha_analyzer.py` 的打印。
|
||||
- 防复发:新增两道按形状找的守卫:`frontend/tests/pada-wording-guard-2349.test.ts`(前端源码里 `第 N 足`、`第 ${…} 足`、`第 {…} 足`、「足未提供」、单独的「足」文字,只放过 `RAJJU_ZH` 那一行)和 `tests/test_pada_wording_guard_2349.py`(scripts/ 全部 .py 的 `第 N 足`、`第{…}足` f-string、`第%s足`、「足未提供」,并验证旧文字被改写成「第N分区」)。两道守卫都带样例,确认能拦住这次漏掉的每一种写法。
|
||||
- 验证:钉住的断言按原值 / 新值 / 原因更新(`ephemeris-route.test.ts`、`ephemeris-readable-panchanga.test.tsx` 月宿「第 4 足」→「第 4 分区」);读到改动文件的前端测试逐个跑过;读到改动 Python 模块的 54 个测试逐个跑过,4 个失败(`test_report_chart_blank_columns`、`test_report_status_words_20261111`、`test_full_data_parity_chapters`、`test_report_narayana_shadbala_20261111`)在改动前的 staging 上同样失败,与本次无关。用产品样式渲染组件截图(390 手机浅色):盘面检视、行星表、出生资料与口径。
|
||||
- 修复版本:分支 `claude/pada-sweep-2362`。
|
||||
|
||||
## BUG-2360 | 后台给人设了角色(包括 Owner),对方能打开后台页面,但生成兑换码等操作一律「无权执行此操作」(403)
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ function PointTable({ view, board, group }: { view: ChartViewOk; board: ChartBoa
|
||||
<th scope="col">名称</th>
|
||||
<th scope="col">{arudha ? "星座" : "黄道经度"}</th>
|
||||
<th scope="col">宫位</th>
|
||||
{arudha ? <th scope="col">来自</th> : <><th scope="col">月宿</th><th scope="col">宿主</th><th scope="col">足</th></>}
|
||||
{arudha ? <th scope="col">来自</th> : <><th scope="col">月宿</th><th scope="col">宿主</th><th scope="col">分区</th></>}
|
||||
<th scope="col">传统含义</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -137,7 +137,7 @@ export function PlanetTable({ view, board }: { view: ChartViewOk; board: ChartBo
|
||||
<th scope="row">{asc.label}</th>
|
||||
<td className="chart-graha-num">{asc.signLabel} {formatDegreeMinutes(asc.degreeInSign)}</td>
|
||||
<td className="chart-graha-num">1</td>
|
||||
<td>{asc.nakshatra ? `${asc.nakshatra}${asc.pada ? ` 第 ${asc.pada} 足` : ""}` : "—"}</td>
|
||||
<td>{asc.nakshatra ? `${asc.nakshatra}${asc.pada ? ` 第 ${asc.pada} 分区` : ""}` : "—"}</td>
|
||||
<td>{asc.nakshatraLord ?? "—"}</td>
|
||||
<AscendantStatusCell />
|
||||
<td>—</td>
|
||||
@@ -165,7 +165,7 @@ export function PlanetTable({ view, board }: { view: ChartViewOk; board: ChartBo
|
||||
{row.retrograde && !node ? <span className="chart-graha-retro"> 逆</span> : null}
|
||||
</td>
|
||||
<td className="chart-graha-num">{row.house}</td>
|
||||
<td>{row.nakshatra} 第 {row.pada} 足</td>
|
||||
<td>{row.nakshatra} 第 {row.pada} 分区</td>
|
||||
<td>{row.nakshatraLord}</td>
|
||||
<td className={dignity?.step === 0 ? "chart-graha-bad" : dignity && dignity.step >= 6 ? "chart-graha-good" : undefined}>
|
||||
{dignity?.label ?? "—"}
|
||||
|
||||
@@ -754,7 +754,7 @@ function BirthCard({ view }: { view: ChartViewOk }) {
|
||||
const profile = view.profile;
|
||||
const place = displayPlaceLabel(profile.placeLabel);
|
||||
const lunar = calendar
|
||||
? [calendar.tithi, moon ? `${moon.nakshatra}${moon.pada === null ? "" : ` 第 ${moon.pada} 足`}` : null, calendar.weekday]
|
||||
? [calendar.tithi, moon ? `${moon.nakshatra}${moon.pada === null ? "" : ` 第 ${moon.pada} 分区`}` : null, calendar.weekday]
|
||||
: [];
|
||||
const pills = [
|
||||
`${profile.date} ${profile.time}`,
|
||||
@@ -806,7 +806,7 @@ function BirthCard({ view }: { view: ChartViewOk }) {
|
||||
<h4>出生历法</h4>
|
||||
<dl className="chart-book-grid is-three">
|
||||
<div><dt>提毗</dt><dd>{calendar.tithi ?? "—"}</dd></div>
|
||||
<div><dt>月宿</dt><dd>{moon ? `${moon.nakshatra}${moon.pada === null ? "(足未提供)" : ` 第 ${moon.pada} 足`}` : "—"}</dd></div>
|
||||
<div><dt>月宿</dt><dd>{moon ? `${moon.nakshatra}${moon.pada === null ? "(分区未提供)" : ` 第 ${moon.pada} 分区`}` : "—"}</dd></div>
|
||||
<div><dt>星期</dt><dd>{calendar.weekday}</dd></div>
|
||||
</dl>
|
||||
</>
|
||||
|
||||
@@ -84,7 +84,7 @@ function PointDetail({ model, point }: { model: BoardModel; point: ChartViewPoin
|
||||
<>
|
||||
<Fact label="传统含义" value={point.note} wide />
|
||||
{point.nakshatra ? (
|
||||
<Fact label="月宿" value={`${point.nakshatra} 第 ${point.pada ?? "—"} 足${point.nakshatraLord ? `,宿主 ${point.nakshatraLord}` : ""}`} />
|
||||
<Fact label="月宿" value={`${point.nakshatra} 第 ${point.pada ?? "—"} 分区${point.nakshatraLord ? `,宿主 ${point.nakshatraLord}` : ""}`} />
|
||||
) : null}
|
||||
<Fact label="所在座的主" value={lord ? `${PLANET_NAME_ZH[lord]}${lordAt ? `,落第 ${lordAt} 宫` : ""}` : "—"} />
|
||||
{point.sourceHouse ? (
|
||||
@@ -172,7 +172,7 @@ function BodyDetail({ view, model, source, keyName, transitSky }: {
|
||||
</Fact>
|
||||
) : null}
|
||||
{row ? (
|
||||
<Fact label={source.natal ? "月宿" : "本命月宿"} value={`${row.nakshatra}${row.pada === null ? "(足未提供)" : ` 第 ${row.pada} 足`}${row.nakshatraLord ? `,宿主 ${row.nakshatraLord}` : ""}`} />
|
||||
<Fact label={source.natal ? "月宿" : "本命月宿"} value={`${row.nakshatra}${row.pada === null ? "(分区未提供)" : ` 第 ${row.pada} 分区`}${row.nakshatraLord ? `,宿主 ${row.nakshatraLord}` : ""}`} />
|
||||
) : null}
|
||||
{strength ? (
|
||||
<Fact label="六力" value={<>{`${strength.rupas.toFixed(2)} 鲁帕,${Math.round(strength.percent)}%`}<MetBand status={shadbalaStatus(strength)} label={shadbalaLabel(strength)} /></>}>
|
||||
@@ -419,7 +419,7 @@ function AscendantHead({ view, model }: { view: ChartViewOk; model: BoardModel |
|
||||
const lord = model ? houseLord(model, model.ascendantHouse) : null;
|
||||
// Where the lord sits is the first fact below, so the line only names it.
|
||||
const line = [
|
||||
asc.nakshatra ? `${asc.nakshatra}${asc.pada ? ` 第 ${asc.pada} 足` : ""}` : "",
|
||||
asc.nakshatra ? `${asc.nakshatra}${asc.pada ? ` 第 ${asc.pada} 分区` : ""}` : "",
|
||||
lord ? `宫主${PLANET_NAME_ZH[lord]}` : "",
|
||||
].filter(Boolean).join(",");
|
||||
return <Head glyph="升" title={`上升 ${asc.signLabel} ${formatDegreeMinutes(asc.degreeInSign)}`} line={line || undefined} />;
|
||||
|
||||
@@ -79,7 +79,7 @@ export function ChartGrahaCard({ view, selection, onSelect, compact = false }: {
|
||||
</th>
|
||||
<td className="chart-graha-num">{row.signLabel} {formatDegreeMinutes(row.degreeInSign)}</td>
|
||||
<td className="chart-graha-num">{row.house}</td>
|
||||
<td>{row.nakshatra} {row.pada === null ? "(足未提供)" : `第 ${row.pada} 足`}</td>
|
||||
<td>{row.nakshatra} {row.pada === null ? "(分区未提供)" : `第 ${row.pada} 分区`}</td>
|
||||
{compact ? null : (
|
||||
<td className="chart-graha-num">
|
||||
{key === "rahu" || key === "ketu" ? "—" : (
|
||||
|
||||
@@ -381,7 +381,7 @@ export function panchangaFactorsFromEngine(report: unknown, date: string): Ephem
|
||||
label: FACTOR_LABEL.nakshatra,
|
||||
value: nakshatraName,
|
||||
quality: parseQuality(asRecord(panchanga.nakshatra)?.quality),
|
||||
detail: pada !== null && pada >= 1 && pada <= 4 ? `第 ${pada} 足` : null,
|
||||
detail: pada !== null && pada >= 1 && pada <= 4 ? `第 ${pada} 分区` : null,
|
||||
},
|
||||
{
|
||||
key: "yoga",
|
||||
|
||||
@@ -120,7 +120,10 @@ test("D5 rows: Chinese first, engine name second; 星期 has no second line; unk
|
||||
|
||||
test("D5 over the real engine golden: 2026-09-15 reads in Chinese", () => {
|
||||
const rows = panchangaDisplayRows(panchangaFactorsFromEngine(panchangaGolden, "2026-09-15"));
|
||||
assert.deepEqual(rows.map((row) => row.primary), ["星期二", "白分初五", "亢宿 第 4 足", "分离", "巴瓦"]);
|
||||
// 原值:「第 4 足」
|
||||
// 新值:「第 4 分区」
|
||||
// 原因:BUG-2349 跟进(第二次扫):用户看到的星宿 Pada 一律叫「第 N 分区」
|
||||
assert.deepEqual(rows.map((row) => row.primary), ["星期二", "白分初五", "亢宿 第 4 分区", "分离", "巴瓦"]);
|
||||
assert.deepEqual(rows.map((row) => row.secondary), [null, "Shukla Panchami", "Swati", "Vaidhriti", "Bava"]);
|
||||
});
|
||||
|
||||
|
||||
@@ -257,7 +257,10 @@ test("golden engine packets pass the narrow response contract", () => {
|
||||
const factors = panchangaFactorsFromEngine(panchangaGolden, "2026-09-15");
|
||||
assert.equal(factors.length, 5);
|
||||
assert.equal(factors.find((item) => item.key === "tithi")?.value, "Shukla Panchami");
|
||||
assert.equal(factors.find((item) => item.key === "nakshatra")?.detail, "第 4 足");
|
||||
// 原值:「第 4 足」
|
||||
// 新值:「第 4 分区」
|
||||
// 原因:BUG-2349 跟进(第二次扫):用户看到的星宿 Pada 一律叫「第 N 分区」
|
||||
assert.equal(factors.find((item) => item.key === "nakshatra")?.detail, "第 4 分区");
|
||||
|
||||
const transits = transitsFromEngine({ transitChart: transitGolden, natalChart: natalGolden });
|
||||
assert.equal(transits.bodies.length, 9);
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readdirSync, readFileSync } from "node:fs";
|
||||
import { join, relative } from "node:path";
|
||||
import test from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
// BUG-2349 跟进:用户能读到的星宿 Pada 一律叫「星宿分区 / 第 N 分区」。第一次扫只找了 `第${x}足` 这类
|
||||
// 字面写法,漏了带空格、换插值写法和 JSX 的版本。这里按形状找,不按某一种写法找。
|
||||
const sourceRoot = fileURLToPath(new URL("../src/", import.meta.url));
|
||||
|
||||
const PATTERNS: ReadonlyArray<readonly [string, RegExp]> = [
|
||||
["第 N 足(数字)", /第\s*\d+\s*足/u],
|
||||
["第 ${…} 足(模板插值)", /第\s*\$\{[^}]*\}\s*足/u],
|
||||
["第 {…} 足(JSX 插值)", /第\s*\{[^}]*\}\s*足/u],
|
||||
["足未提供", /足未提供/u],
|
||||
["单独的「足」文字(列头、标签)", /["'`>]\s*足\s*["'`<]/u],
|
||||
];
|
||||
|
||||
// 只放过合盘 Rajju 的「足」:那是身体部位(脚),不是星宿 Pada。
|
||||
const ALLOWED_LINE = /RAJJU_ZH[^\n]*Pada:\s*"足"/u;
|
||||
|
||||
function* sourceFiles(directory: string): Generator<string> {
|
||||
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
||||
const file = join(directory, entry.name);
|
||||
if (entry.isDirectory()) yield* sourceFiles(file);
|
||||
else if (entry.isFile() && /\.(tsx?|mjs|json)$/.test(entry.name)) yield file;
|
||||
}
|
||||
}
|
||||
|
||||
export function padaWordingFailures(text: string, path: string): string[] {
|
||||
const failures: string[] = [];
|
||||
text.split("\n").forEach((line, index) => {
|
||||
if (ALLOWED_LINE.test(line)) return;
|
||||
for (const [name, pattern] of PATTERNS) {
|
||||
if (pattern.test(line)) failures.push(`${path}:${index + 1} ${name}: ${line.trim().slice(0, 120)}`);
|
||||
}
|
||||
});
|
||||
return failures;
|
||||
}
|
||||
|
||||
test("frontend source shows pada as 「第 N 分区」, never 「第 N 足」 (BUG-2349 follow-up)", () => {
|
||||
const failures: string[] = [];
|
||||
for (const file of sourceFiles(sourceRoot)) {
|
||||
failures.push(...padaWordingFailures(readFileSync(file, "utf8"), relative(sourceRoot, file)));
|
||||
}
|
||||
assert.deepEqual(failures, []);
|
||||
});
|
||||
|
||||
test("the guard catches the variants the first sweep missed", () => {
|
||||
const samples = [
|
||||
"detail: `第 ${pada} 足`",
|
||||
"`${asc.nakshatra}${asc.pada ? ` 第 ${asc.pada} 足` : \"\"}`",
|
||||
"<td>{row.nakshatra} 第 {row.pada} 足</td>",
|
||||
"\"(足未提供)\"",
|
||||
"<th scope=\"col\">足</th>",
|
||||
"上升 Purva Phalguni 第 1 足",
|
||||
];
|
||||
for (const sample of samples) assert.notDeepEqual(padaWordingFailures(sample, "sample"), [], sample);
|
||||
const allowed = 'const RAJJU_ZH: Readonly<Record<string, string>> = { Pada: "足", Kati: "腰" };';
|
||||
assert.deepEqual(padaWordingFailures(allowed, "sample"), []);
|
||||
assert.deepEqual(padaWordingFailures("`第 ${pada} 分区`", "sample"), []);
|
||||
});
|
||||
@@ -224,7 +224,7 @@ def _sanitize_pl9_ai_density_markdown(
|
||||
"Planetary Raw Positions": "行星原始位置",
|
||||
"| Field | Value |": "| 字段 | 数值 |",
|
||||
"| Panchanga | Value |": "| Panchanga | 数值 |",
|
||||
"| Planet | R/C | Sign | Degree | Longitude | House | Nakshatra | Pada | Speed |": "| 行星 | 顺逆 | 星座 | 落座度数 | 黄经 | 宫位 | 星宿 | Pada | 速度 |",
|
||||
"| Planet | R/C | Sign | Degree | Longitude | House | Nakshatra | Pada | Speed |": "| 行星 | 顺逆 | 星座 | 落座度数 | 黄经 | 宫位 | 星宿 | 星宿分区 | 速度 |",
|
||||
"| Planet | RL | NL | SL | SS | Status | SB |": "| 行星 | 星座主 | 星宿主 | Sub Lord | Sub-sub | 状态 | Shadbala |",
|
||||
"| Point | Sign | Degree | Longitude | Lord |": "| 点位 | 星座 | 落座度数 | 黄经 | 守护星 |",
|
||||
"| Body | Sign | Degree | Longitude |": "| 对象 | 星座 | 落座度数 | 黄经 |",
|
||||
@@ -255,8 +255,8 @@ def _sanitize_pl9_ai_density_markdown(
|
||||
r"\1落在\2,表示\3会主要通过\4来表现。",
|
||||
text,
|
||||
)
|
||||
text = re.sub(r"第([1-4])足", r"第\1 Pada(星宿四分区)", text)
|
||||
text = text.replace("Pada | 速度", "Pada(星宿四分区) | 速度")
|
||||
text = re.sub(r"第([1-4])足", r"第\1分区", text)
|
||||
text = text.replace("Pada | 速度", "星宿分区 | 速度")
|
||||
text = text.replace("Natural friends", "天然友星")
|
||||
text = text.replace("Natural enemies", "天然敌星")
|
||||
text = text.replace("Temporary relation", "临时关系")
|
||||
|
||||
@@ -536,8 +536,8 @@ def normalize_zh_markdown_terms(markdown: str) -> str:
|
||||
r"\1落在\2,表示\3会主要通过\4来表现。",
|
||||
text,
|
||||
)
|
||||
text = re.sub(r"第([1-4])足", r"第\1 Pada(星宿四分区)", text)
|
||||
text = text.replace("Pada | 速度", "Pada(星宿四分区) | 速度")
|
||||
text = re.sub(r"第([1-4])足", r"第\1分区", text)
|
||||
text = text.replace("Pada | 速度", "星宿分区 | 速度")
|
||||
text = _normalize_zh_dasha_prose(text)
|
||||
text = _thicken_zh_dasha_density(text)
|
||||
text = _normalize_mula_gloss(_restore_zh_nakshatra_glosses(_collapse_duplicate_zh_parentheses(text)))
|
||||
|
||||
@@ -2068,7 +2068,7 @@ def _build_dasha_page_series(
|
||||
if dignity:
|
||||
natal_bits.append(f"尊贵状态为{dignity}")
|
||||
if nakshatra:
|
||||
natal_bits.append(f"星宿为{nakshatra}{f' 第{pada}足' if pada else ''}")
|
||||
natal_bits.append(f"星宿为{nakshatra}{f' 第{pada}分区' if pada else ''}")
|
||||
if functional_role:
|
||||
natal_bits.append(f"功能性角色为{functional_role}")
|
||||
if current_ad:
|
||||
@@ -2483,7 +2483,7 @@ def build_graha_interpretation_pack(
|
||||
"说明这颗星的表达会通过定位星所在宫位继续展开。"
|
||||
),
|
||||
"nakshatra": (
|
||||
f"星宿层:{planet_label}位于{nakshatra_label}{f' 第{pada}足' if pada else ''},星宿主为{nakshatra_lord_label}"
|
||||
f"星宿层:{planet_label}位于{nakshatra_label}{f' 第{pada}分区' if pada else ''},星宿主为{nakshatra_lord_label}"
|
||||
f",位于{_house_label(nakshatra_lord_row.get('house'))};"
|
||||
"星宿主会进一步修饰这颗星的表达方式,并与当前大运节奏一起阅读。"
|
||||
),
|
||||
@@ -2528,7 +2528,7 @@ def build_graha_interpretation_pack(
|
||||
"evidence_label": care_status,
|
||||
"source_path": "modules.chart.planets.Moon + modules.remedies",
|
||||
"sections": {
|
||||
"nakshatra_context": f"月亮星宿:{moon_nakshatra_label}{f' 第{moon_pada}足' if moon_pada else ''}。本页保留星宿定位,用于连接本命语境与既有补救模块;不从星宿直接推导身体疾病或部位。",
|
||||
"nakshatra_context": f"月亮星宿:{moon_nakshatra_label}{f' 第{moon_pada}分区' if moon_pada else ''}。本页保留星宿定位,用于连接本命语境与既有补救模块;不从星宿直接推导身体疾病或部位。",
|
||||
"remedy_context": (
|
||||
f"本仓补救模块返回{len(remedy_evidence)}条证据、{len(recommendation_rows)}条支持性实践建议。"
|
||||
+ ("建议按原始证据链排序阅读,不把任一仪式、咒语、捐赠或宝石视为结果保证。" if remedy_snapshot else "补救模块未返回,因此不补写替代性建议。")
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
"""BUG-2349 跟进(第二次扫):Python 拼出来、用户或模型能读到的星宿 Pada 写成「第 N 分区」,不写「第 N 足」。
|
||||
|
||||
第一次扫只找了前端的 `第${x}足` 字面写法,漏了 Python f-string(`f' 第{pada}足'`)。
|
||||
这里按形状扫 scripts/ 下全部 .py:第 + 数字 / {插值} + 足,以及「足未提供」。
|
||||
把旧文字改成新文字的正则(`第([1-4])足`)不是这几种形状,不会被拦。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from scripts.pl9_language_terms import normalize_zh_markdown_terms
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
PATTERNS = (
|
||||
("第 N 足(数字)", re.compile(r"第\s*\d+\s*足")),
|
||||
("第 {…} 足(f-string 插值)", re.compile(r"第\s*\{[^}]*\}\s*足")),
|
||||
("第 %s 足(% 格式)", re.compile(r"第\s*%[sd]\s*足")),
|
||||
("足未提供", re.compile(r"足未提供")),
|
||||
)
|
||||
|
||||
|
||||
def pada_wording_failures(text: str, path: str) -> list[str]:
|
||||
failures = []
|
||||
for number, line in enumerate(text.splitlines(), start=1):
|
||||
for name, pattern in PATTERNS:
|
||||
if pattern.search(line):
|
||||
failures.append(f"{path}:{number} {name}: {line.strip()[:120]}")
|
||||
return failures
|
||||
|
||||
|
||||
def test_scripts_never_build_pada_as_zu() -> None:
|
||||
failures: list[str] = []
|
||||
for file in sorted((ROOT / "scripts").rglob("*.py")):
|
||||
failures.extend(pada_wording_failures(file.read_text(encoding="utf-8"), str(file.relative_to(ROOT))))
|
||||
assert failures == []
|
||||
|
||||
|
||||
def test_guard_catches_the_missed_variants() -> None:
|
||||
for sample in (
|
||||
"natal_bits.append(f\"星宿为{nakshatra}{f' 第{pada}足' if pada else ''}\")",
|
||||
"f'月亮星宿:{label} 第 {moon_pada} 足'",
|
||||
"'第 %s 足' % pada",
|
||||
"上升 Purva Phalguni 第 1 足",
|
||||
"(足未提供)",
|
||||
):
|
||||
assert pada_wording_failures(sample, "sample"), sample
|
||||
assert pada_wording_failures('re.sub(r"第([1-4])足", r"第\\1分区", text)', "sample") == []
|
||||
|
||||
|
||||
def test_legacy_zu_text_is_rewritten_as_fenqu() -> None:
|
||||
text = normalize_zh_markdown_terms("| 星宿 | Pada | 速度 |\n月亮在 Ashwini 第2足")
|
||||
assert "第2分区" in text
|
||||
assert "足" not in text
|
||||
assert "Pada" not in text
|
||||
Reference in New Issue
Block a user