Chart, ephemeris, reports, daily language, consult, and synastry read birth data only through resolveSubjectBirth. The current person is a request parameter outside Home(). /people replaces the settings chart pane, and deleting someone removes that person's chats and reports.
140 lines
8.2 KiB
TypeScript
140 lines
8.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
import { homeSurface as source } from "./home-surface.ts";
|
|
const route = readFileSync(new URL("../src/app/api/chart-profiles/route.ts", import.meta.url), "utf8");
|
|
|
|
test("other chart saves do not require the owner's rectification state", () => {
|
|
assert.match(source, /function missingOtherProfileStep\(profile: Profile\)/);
|
|
assert.match(source, /if \(missingOtherProfileStep\(nextProfile\)\)/);
|
|
assert.doesNotMatch(source, /saveOtherChart[\s\S]{0,500}missingProfileStep\(nextProfile\)/);
|
|
});
|
|
|
|
test("other chart save fails closed when cloud sync fails", () => {
|
|
// Former values that locked the dual-truth fallback:
|
|
// `let cloudSaved = false`, catch copy "已保存到本地星盘库;云端同步失败",
|
|
// `localStorage.setItem(chartLibraryStorageKey(accountId), JSON.stringify(next))`,
|
|
// delete copy "已从本地星盘库删除;云端同步失败". Cloud write failure is now failure.
|
|
assert.doesNotMatch(source, /let cloudSaved = false/);
|
|
assert.match(source, /await saveCloudChartProfile\(record\)/);
|
|
assert.match(source, /async function saveOtherChart[\s\S]{0,1600}catch \{[\s\S]{0,180}保存失败,请重试/);
|
|
assert.doesNotMatch(source, /localStorage\.setItem\(chartLibraryStorageKey/);
|
|
assert.doesNotMatch(source, /已保存到本地星盘库/);
|
|
assert.match(source, /已保存到云端星盘库/);
|
|
assert.match(source, /async function deleteOtherChart[\s\S]{0,500}await deleteCloudChartProfile\(recordId\)/);
|
|
assert.match(source, /async function deleteOtherChart[\s\S]{0,700}catch \{[\s\S]{0,160}删除失败,请重试[\s\S]{0,80}return;/);
|
|
assert.doesNotMatch(source, /已从本地星盘库删除/);
|
|
});
|
|
|
|
test("adding another chart waits for the user to choose a relationship type", () => {
|
|
assert.doesNotMatch(source, /async function saveOtherChart[\s\S]{0,1400}await draftSynastryQuestionFromChart\(/);
|
|
assert.match(source, /请选择关系类型后点击“用于合盘”。/);
|
|
assert.match(source, /用于合盘/);
|
|
assert.match(source, /\/api\/synastry/);
|
|
});
|
|
|
|
test("a successful cloud read replaces stale local other charts", () => {
|
|
assert.match(
|
|
source,
|
|
/fetchCloudChartLibrary\(\)[\s\S]{0,800}chartLibraryFromCloudOthers\(cloudLibrary, profileForLibrary, upsertSelfChart\)/,
|
|
);
|
|
assert.doesNotMatch(source, /fetchCloudChartLibrary\(\)[\s\S]{0,800}new Map\(\[[\s\S]{0,500}current\.filter\(\(record\) => record\.role === "other"\)/);
|
|
});
|
|
|
|
test("other chart creation lets the database create its UUID", () => {
|
|
// 原值: insert({ user_id, role, profile, updated_at }) with role taken from the body.
|
|
// 新值: insert always uses role "other" plus the validated typed columns. The id is still omitted.
|
|
// 原因: self mirrors are retired and other rows are typed columns, not an unvalidated jsonb blob.
|
|
assert.match(route, /role: "other"/);
|
|
assert.match(route, /\.insert\(\{/);
|
|
assert.doesNotMatch(route, /id: body/);
|
|
assert.doesNotMatch(route, /\.upsert\(record, \{ onConflict: "id" \}\)/);
|
|
assert.doesNotMatch(source, /id: record\.role === "self" \? undefined : record\.id/);
|
|
});
|
|
|
|
test("cloud save failures preserve the server error message", () => {
|
|
assert.match(source, /const payload = await response\.json\(\)\.catch\(\(\) => null\) as \{ error\?: string \} \| null;/);
|
|
assert.match(source, /throw new Error\(payload\?\.error \|\| "cloud_chart_profile_save_failed"\);/);
|
|
});
|
|
|
|
test("synastry selection exposes a pending state while the evidence packet is computed", () => {
|
|
assert.match(source, /const \[synastryPendingId, setSynastryPendingId\] = useState<string \| null>\(null\);/);
|
|
assert.match(source, /setSynastryPendingId\(record\.id\);/);
|
|
assert.match(source, /finally \{\s*setSynastryPendingId\(null\);\s*\}/);
|
|
assert.match(source, /disabled=\{synastryPendingId !== null\}/);
|
|
assert.match(source, /synastryPendingId === selectedOther\.id \? "正在计算合盘\.\.\." : "用于合盘"/);
|
|
});
|
|
|
|
test("relationship intent selects domain-specific evidence instead of treating every pairing as romance", () => {
|
|
const route = readFileSync(new URL("../src/app/api/synastry/route.ts", import.meta.url), "utf8");
|
|
assert.match(source, /商业合作/);
|
|
assert.match(source, /亲友\/家庭/);
|
|
assert.match(source, /其他关系/);
|
|
assert.match(source, /relationshipType: SynastryRelationshipType/);
|
|
assert.match(source, /body: JSON\.stringify\(\{ partnerChartProfileId: record\.id, relationshipType \}\)/);
|
|
assert.doesNotMatch(source, /selfProfile: profile, partnerProfile: record\.profile/);
|
|
assert.match(route, /partnerChartProfileId/);
|
|
// 原值: the route selected profiles and the chart_profiles jsonb itself.
|
|
// 新值: both people are read by loadSubjectBirth.
|
|
// 原因: D13. The other person's birth is the typed columns. "我" stays the household profile.
|
|
assert.match(route, /loadSubjectBirth/);
|
|
assert.doesNotMatch(route, /globalBirthProfileFromStoredChart/);
|
|
assert.match(route, /consumeUserRequestRateLimit\("synastry"/);
|
|
assert.match(route, /relationshipType === "business"/);
|
|
assert.match(route, /divisions: \["D2", "D10", "D11"\]/);
|
|
assert.match(route, /"D10_Dasamsa"/);
|
|
assert.match(route, /"D11_Rudramsa"/);
|
|
assert.match(route, /blockedLayers:/);
|
|
assert.match(route, /"A10"/);
|
|
assert.match(route, /"functional_benefic_malefic"/);
|
|
assert.match(route, /"vimshottari_narayana"/);
|
|
assert.match(source, /基础商业合作证据筛查/);
|
|
assert.match(source, /relationshipType === "business"/);
|
|
});
|
|
|
|
|
|
test("synastry history is replaced by the cloud list and save failures stay in page memory", () => {
|
|
// Former value: `new Map([...current, ...cloudHistory])` unioned local+cloud
|
|
// and `writeSynastryHistory(accountId, next)` on cloud save failure.
|
|
assert.doesNotMatch(source, /new Map\(\[\.\.\.current, \.\.\.cloudHistory\]/);
|
|
assert.match(source, /未能存入历史/);
|
|
assert.doesNotMatch(source, /writeSynastryHistory\(/);
|
|
assert.match(source, /discardLegacyCloudMirrorKeys\(/);
|
|
});
|
|
|
|
test("current chart selection is local and does not overwrite the owner's profile", () => {
|
|
// 原值: activeChartStorageKey and the "set as current" copy lived in the home surface.
|
|
// 新值: those symbols are gone from frontend/src. The page profile is not replaced from the archive.
|
|
// 原因: D11. The current person is a request parameter, not a second profile.
|
|
const page = readFileSync(new URL("../src/app/(app)/page.tsx", import.meta.url), "utf8");
|
|
assert.doesNotMatch(page, /activeChartStorageKey|makeDefaultChart|setProfile\(record\.profile\)/);
|
|
assert.match(readFileSync(new URL("../src/app/api/chart-profiles/[id]/route.ts", import.meta.url), "utf8"), /星盘不存在或无权更新/);
|
|
});
|
|
|
|
test("the chart library starts as a list and only renders a form after a view change", () => {
|
|
const charts = readFileSync(new URL("../src/components/chart-library-panel.tsx", import.meta.url), "utf8");
|
|
const lastReturn = charts.lastIndexOf("return (");
|
|
const list = charts.slice(lastReturn);
|
|
assert.match(charts, /useState<ChartLibraryView>\(CHART_LIBRARY_LIST_VIEW\)/);
|
|
assert.doesNotMatch(list, /ChartProfileForm|<form/);
|
|
assert.match(list, /添加其他人/);
|
|
// 原值:仅断言列表中存在“添加其他人”;新值:同步锁定标题操作区;原因:入口从列表末尾移到“其他人”分组标题,长列表中位置仍稳定。
|
|
assert.match(charts, /chart-library-group-heading-actions[\s\S]{0,900}添加其他人/);
|
|
assert.match(charts, /setView\(\{ kind: "add" \}\)/);
|
|
assert.match(charts, /setView\(CHART_LIBRARY_LIST_VIEW\)/);
|
|
});
|
|
|
|
test("other chart details own actions and self details cannot delete", () => {
|
|
const charts = readFileSync(new URL("../src/components/chart-library-panel.tsx", import.meta.url), "utf8");
|
|
const selfView = charts.slice(charts.indexOf('if (view.kind === "self")'), charts.indexOf('if (view.kind === "add"'));
|
|
assert.doesNotMatch(selfView, /删除/);
|
|
// 原值: the detail offered 设为默认.
|
|
// 新值: that action is gone.
|
|
// 原因: D11 removes "set as default".
|
|
assert.doesNotMatch(charts, /设为默认/);
|
|
assert.match(charts, /用于合盘/);
|
|
assert.match(charts, /synastryHistoryForPartner/);
|
|
assert.match(charts, /partnerHistory\.length > 0 &&/);
|
|
assert.match(source, /partnerChartId: record\.id/);
|
|
});
|