Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
42 lines
2.6 KiB
TypeScript
42 lines
2.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { test } from "node:test";
|
|
|
|
import { assembleChartView } from "../src/lib/chart-view-load.ts";
|
|
import { CHART_VIEW_COPY } from "../src/lib/chart-view-labels.ts";
|
|
import { invalidateChartPage, pinChartSnapshotIdentity, refreshChartPage, resetSecondaryPageDataForTests } from "../src/lib/secondary-page-data.ts";
|
|
|
|
const golden = JSON.parse(readFileSync(new URL("./fixtures/chart-view-golden.json", import.meta.url), "utf8"));
|
|
const profile = { name: "Synthetic", date: "1990-06-15", time: "12:00", placeLabel: "Synthetic", latitude: 39.9, longitude: 116.4, timezoneOffset: 8, timezoneId: "Asia/Shanghai", ayanamsa: "raman", birthTimeStatus: "accepted" };
|
|
|
|
// BUG-2063: saving a time in 生时纠正 makes a new birth revision; the chart cache stayed pinned to the
|
|
// revision read at app start, so 星盘 showed 「星盘结果的格式对不上」 until the page was reloaded.
|
|
test("after a rectification save the chart page reads the new birth revision instead of failing", async () => {
|
|
const view = await assembleChartView({ userId: "synthetic", accountId: "synthetic", profileFingerprint: "fp-after", profile: profile as never,
|
|
asOf: "2026-09-15", layers: [], postEngine: async () => ({ status: "ok", payload: golden.chart }) as never });
|
|
const body = { ...view.body, birthInputRevision: "rev-after" };
|
|
const original = globalThis.fetch;
|
|
globalThis.fetch = (async () => new Response(JSON.stringify(body), { status: 200 })) as typeof fetch;
|
|
try {
|
|
resetSecondaryPageDataForTests();
|
|
pinChartSnapshotIdentity({ accountId: "synthetic", fingerprint: "fp-before", birthInputRevision: "rev-before" });
|
|
const stale = await refreshChartPage();
|
|
assert.equal(stale.kind === "view" && "message" in stale.view ? stale.view.message : null, CHART_VIEW_COPY.schemaFailure, "the failure this fixes");
|
|
|
|
resetSecondaryPageDataForTests();
|
|
pinChartSnapshotIdentity({ accountId: "synthetic", fingerprint: "fp-before", birthInputRevision: "rev-before" });
|
|
invalidateChartPage();
|
|
const fresh = await refreshChartPage();
|
|
assert.equal(fresh.kind === "view" ? fresh.view.status : fresh.kind, "ok");
|
|
} finally {
|
|
globalThis.fetch = original;
|
|
resetSecondaryPageDataForTests();
|
|
}
|
|
});
|
|
|
|
test("every rectification save drops the chart and ephemeris caches", () => {
|
|
const page = readFileSync(new URL("../src/components/chart-choice/chart-choice-page.tsx", import.meta.url), "utf8");
|
|
const afterSave = page.slice(page.indexOf("const afterSave = useCallback"), page.indexOf("}, [reloadStart]);"));
|
|
assert.match(afterSave, /invalidateChartPage\(\);\s*invalidateEphemerisPage\(\);/);
|
|
});
|