Files
Jyotisha/frontend/tests/consultation-domain-migration.test.ts
T
Jesse_ChenandClaude Opus 5.5 5c65834dda feat(consult): split family into parents and children domains (engine still family)
parents (D12, 4/9 houses, Sun/Moon) and children (D7, 5th house, Jupiter,
PK) are plan/card domains with Chinese labels and the brief's aliases. They
send the family route contract to the engine and are rejected as a stored
session theme, so neither Python nor the chat_sessions.theme CHECK changes.
Methodology reports no strict checklist for them; must-use layers follow the
plan domain. Tests with 原值/新值/原因 where assertions changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017eEAG8HD3mm8gsKXgk8uU8
2026-09-27 02:54:11 +08:00

35 lines
1.6 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { consultationDomainIds, consultationEngineDomainIds } from "../src/lib/consultation-domain-registry.ts";
const migration = readFileSync(
new URL("../supabase/migrations/20260814050000_consultation_domain_registry.sql", import.meta.url),
"utf8",
);
function themeConstraintValues(sql: string) {
const constraint = sql.match(/add constraint chat_sessions_theme_check[\s\S]*?check \(theme in \(([\s\S]*?)\)\);/i);
assert.ok(constraint, "chat_sessions theme constraint must be present");
return [...constraint[1].matchAll(/'([a-z][a-z0-9_-]*)'/g)].map((match) => match[1]);
}
test("chat_sessions persists exactly the canonical consultation domains", () => {
// 原值:CHECK 值 == consultationDomainIds。
// 新值:CHECK 值 == consultationEngineDomainIds(会话主题 / 引擎领域);parents、children 只在数据卡里区分,不落库。
// 原因:TASK-consult-evidence-card-20260927 D2,不改数据库。
assert.deepEqual(themeConstraintValues(migration), [...consultationEngineDomainIds]);
assert.deepEqual(
consultationDomainIds.filter((domain) => !(consultationEngineDomainIds as readonly string[]).includes(domain)),
["parents", "children"],
);
});
test("chat_sessions does not persist aliases or independent product routes", () => {
const values = themeConstraintValues(migration);
for (const rejected of ["relationship", "finance", "health_pressure", "home", "prashna", "muhurta", "rectification", "compatibility", "spirituality"]) {
assert.equal(values.includes(rejected), false, rejected);
}
});