import assert from "node:assert/strict"; import test from "node:test"; import { loadGeneralDailyPanchangaContext, type GeneralDailyPanchangaContext, } from "../src/lib/general-daily-panchanga.ts"; test("loads a public Panchanga day without inventing a birth minute", async () => { let requestBody: Record | null = null; const fetchImpl: typeof fetch = async (_input, init) => { requestBody = JSON.parse(String(init?.body)) as Record; return new Response(JSON.stringify({ success: true, endpoint: "panchanga_range", report: { calculation_policy: { panchanga: "SwissEph Lahiri at sunrise-relative reference time", }, days: [{ query_date: "2026-08-15", panchanga: { tithi: { full_name: "Shukla Tritiya", quality: "subha" }, nakshatra: { nakshatra: "Uttara Phalguni", quality: "subha" }, yoga: { yoga: "Siddha", quality: "subha" }, vara: { vara: "Saturday", quality: "asubha" }, overall_quality: "吉(Subha)", }, condition_tags: [{ key: "good_choghadiya", label: "Has auspicious Choghadiya window", guidance: "At least one auspicious window is available.", }], }], }, }), { status: 200, headers: { "content-type": "application/json" } }); }; const context = await loadGeneralDailyPanchangaContext({ date: "2026-08-15", reference: { latitude: 25.033, longitude: 121.5654, timezoneOffset: 8, placeLabel: "已保存地点" }, fetchImpl, apiBase: "http://jyotish.test", }); assert.deepEqual(requestBody, { start_date: "2026-08-15", end_date: "2026-08-15", lat: 25.033, lon: 121.5654, tz: 8, }); assert.deepEqual(context satisfies GeneralDailyPanchangaContext, { scope: "public_day_no_natal_chart", date: "2026-08-15", referencePlace: "已保存地点", calculationPolicy: "SwissEph Lahiri at sunrise-relative reference time", panchanga: { vara: "Saturday", tithi: "Shukla Tritiya", nakshatra: "Uttara Phalguni", yoga: "Siddha", overallQuality: "吉(Subha)", }, conditionTags: [{ key: "good_choghadiya", label: "Has auspicious Choghadiya window", guidance: "At least one auspicious window is available.", }], boundaries: [ "仅为所选地点与日期的公共 Panchanga 日历,不是个人命盘或个人预测。", "未使用出生分钟、时段中点、00:00 或任何候选出生时间。", "不得据此声称个人上升点、宫位、大运、本命过境叠加或确定事件。", ], }); }); test("rejects an incomplete Panchanga response instead of fabricating daily evidence", async () => { const fetchImpl: typeof fetch = async () => new Response(JSON.stringify({ success: true, endpoint: "panchanga_range", report: { days: [] }, }), { status: 200 }); await assert.rejects( loadGeneralDailyPanchangaContext({ date: "2026-08-15", fetchImpl, apiBase: "http://jyotish.test" }), /general_daily_panchanga_unavailable/, ); });