Files
Jyotisha/frontend/tests/chart-view-zero-year.test.ts
ClaudeandClaude Opus 5.5 d676292343 fix: astrologer acceptance for BUG-1758/1763/1752 (source ledger, audit acceptance, engine boundaries)
- BUG-1758: the card's affliction layer is a source ledger: one entry per fact
  with its input, effect (conflicts / not_executed) and every house it bears
  on; a fact shared by two houses is one source, never two votes.
- BUG-1763: output acceptance after the one repair: a professional answer
  without the Technique Audit Table, or any answer without the engine audit
  rows (plain mode's evidence entry), fails as incomplete (kept text, no charge).
- BUG-1752: engine rows carry exact local start/end with UTC offset, parent
  start, cycle, and a meta block (365.25-day years, zone, [start, end)); the
  chart page copies them. Tests: midnight crossing, birth balance, second
  cycle, zero-length rows and 0-year Narayana / Chara MDs never current.
- Goldens recaptured (evidence card TTL=0; chart-view dasha from the engine).

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

151 lines
7.2 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.
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import React from "react";
import test from "node:test";
import { renderToStaticMarkup } from "react-dom/server";
import { ChartDashaTab } from "../src/components/chart-page/chart-dasha-tab.tsx";
import type { ChartViewOk } from "../src/lib/chart-view-contract.ts";
import { assembleChartView } from "../src/lib/chart-view-load.ts";
import { CHARA_ZERO_YEAR_LABEL } from "../src/lib/chart-view-labels.ts";
import { buildChartView, type ChartViewProfileInput } from "../src/lib/chart-view-mapper.ts";
Object.assign(globalThis, { React });
/**
* Generated from the real engine, not a hand-built shape, via the configured
* Python and JyotishAPIHandler.__new__()._compute_chart + _compute_chara_dasha.
* 1985-08-03 03:59, lat 39.9042, lon 116.4074, tz 8, ayanamsa raman, node_mode mean,
* skip_vedastro_main_entry_overview, antardasha true.
* Sagittarius duration_years is 0 (debilitated). scripts/jaimini.py was not modified.
*/
const golden = JSON.parse(readFileSync(new URL("./fixtures/chara-zero-year-1985-08-03-beijing.golden.json", import.meta.url), "utf8")) as {
chart: Record<string, unknown>;
chara: Record<string, unknown>;
};
const profile: ChartViewProfileInput = {
name: "虚构",
date: "1985-08-03",
time: "03:59",
placeLabel: "北京",
latitude: 39.9042,
longitude: 116.4074,
timezoneOffset: 8,
timezoneId: "Asia/Shanghai",
ayanamsa: "raman",
birthTimeStatus: "reported",
};
function viewFrom(chara: Record<string, unknown>): ChartViewOk {
return buildChartView({
chart: golden.chart,
varga: null,
chara,
western: null,
profile,
asOf: "2026-09-25",
});
}
test("a real zero-year Chara mahadasha keeps twelve continuous periods and does not throw", async () => {
const view = viewFrom(golden.chara);
const periods = view.dasha.chara.periods;
assert.equal(periods.length, 12);
const sagittarius = periods.find((period) => period.sign === "Sagittarius");
assert.ok(sagittarius);
assert.equal(sagittarius.zeroYear, true);
assert.equal(sagittarius.antardashas.length, 0);
assert.equal(sagittarius.start, sagittarius.end);
for (let index = 0; index < periods.length - 1; index += 1) {
assert.equal(periods[index]?.end, periods[index + 1]?.start);
}
const assembled = await assembleChartView({
userId: "synthetic",
accountId: "synthetic",
profileFingerprint: "fixture-zero-year",
profile,
asOf: "2026-09-25",
layers: ["chara"],
postEngine: async (path) => {
if (path === "/api/chart") return { status: "ok", payload: golden.chart };
if (path === "/api/dasha/chara") return { status: "ok", payload: golden.chara };
return { status: "http_error", path, elapsedMs: 0, httpStatus: 404 };
},
});
assert.equal(assembled.httpStatus, 200);
assert.equal(assembled.body.status, "ok");
});
test("zero antardasha weights on a positive mahadasha do not produce an invalid date", () => {
const chara = structuredClone(golden.chara) as {
result: { chara_dasha: { dasha_sequence: Array<{ duration_years: number; antardashas?: Array<{ duration_years: number }> }> } };
};
const positive = chara.result.chara_dasha.dasha_sequence.find((row) => row.duration_years > 0);
assert.ok(positive?.antardashas?.length);
for (const antar of positive.antardashas ?? []) antar.duration_years = 0;
const view = viewFrom(chara);
const mapped = view.dasha.chara.periods.find((period) => period.sign !== "Sagittarius" && period.antardashas.length > 0);
assert.ok(mapped);
for (const antar of mapped.antardashas) {
assert.match(antar.start, /^\d{4}-\d{2}-\d{2}$/);
assert.match(antar.end, /^\d{4}-\d{2}-\d{2}$/);
}
});
// 原值:零年行是 `chart-page-dasha-period is-zero` 列表项,时间轴是彩色条 `data-dasha-segment`,
// 每条大运一个 Collapsible
// 新值:零年行是表格里的 `tr.is-zero`,没有「看小运」,不进年龄刻度尺;说明写在表下
// 原因:2026-11-02 第二条运法按原型改成「现在」一行 + 年龄刻度尺 + 紧凑表格
test("a zero-year period is grey, closed, and absent from the timeline", () => {
const view = viewFrom(golden.chara);
const markup = renderToStaticMarkup(React.createElement(ChartDashaTab, { view, secondOnly: true }));
const zero = markup.split("<tr").find((item) => item.includes(CHARA_ZERO_YEAR_LABEL) && item.includes("射手"));
assert.ok(zero);
assert.match(zero, /class="is-zero"/);
assert.doesNotMatch(zero, /看小运|aria-expanded/);
// 原值:表下有一行「0 年:本段时长为 0,不展开」
// 新值:零年行仍在表里,表下没有任何说明
// 原因:2026-11-02 产品规则:第二条运法卡片不放提示式说明或脚注
assert.doesNotMatch(markup, /本段时长为 0|不展开/);
const ruler = markup.slice(markup.indexOf("chart-deep-ruler"), markup.indexOf("<table"));
const bands = ruler.match(/chart-deep-ruler-band/g) ?? [];
assert.equal(bands.length, view.dasha.chara.periods.filter((period) => !period.zeroYear).length);
assert.equal(bands.length, 11);
// Only the current period opens its sub-periods, and no open row is the zero-year one.
const open = markup.split("<tr").filter((item) => item.includes('aria-expanded="true"'));
assert.equal(open.length, view.dasha.chara.periods.filter((period) => period.current).length);
for (const row of open) assert.doesNotMatch(row, />0 年</);
});
// 原值:零年说明紧跟在零年列表项里,切出来的片段里没有 `<ul`
// 新值:零年行在表格里,没有小运展开行;说明在表下,一次
// 原因:2026-11-02 第二条运法改成紧凑表格
test("the zero-year Chara row shows 0 年 and does not render sub-periods", () => {
const view = viewFrom(golden.chara);
const markup = renderToStaticMarkup(React.createElement(ChartDashaTab, { view, secondOnly: true }));
const rows = markup.split("<tr").slice(1);
const index = rows.findIndex((item) => item.includes(CHARA_ZERO_YEAR_LABEL) && item.includes("射手"));
assert.ok(index >= 0);
assert.doesNotMatch(rows[index + 1] ?? "", /chart-dasha-subrow/);
// 原值:零年说明在表下出现一次
// 新值:不出现;零年行本身就是唯一的标记
// 原因:2026-11-02 产品规则:第二条运法卡片不放提示式说明或脚注
assert.doesNotMatch(markup, /chart-page-note/);
});
// Astrologer's acceptance note 2026-11-08 (BUG-1752): a 0-year sign-dasha MD (Chara here; Narayana can
// yield the same row) occupies no time under [start, end) and is never shown as current, even on its own day.
test("a zero-year mahadasha is never current, even on the day it starts and ends", () => {
const sagittarius = viewFrom(golden.chara).dasha.chara.periods.find((period) => period.sign === "Sagittarius")!;
const view = buildChartView({ chart: golden.chart, varga: null, chara: golden.chara, western: null, profile, asOf: sagittarius.start });
const periods = view.dasha.chara.periods;
const zero = periods.find((period) => period.zeroYear)!;
assert.equal(zero.current, false);
const running = periods.filter((period) => period.current);
assert.equal(running.length, 1);
assert.notEqual(running[0]!.sign, zero.sign);
assert.equal(running[0]!.start, zero.end);
});