45 lines
2.6 KiB
TypeScript
45 lines
2.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import {
|
|
consultationDomainIds,
|
|
consultationDomainRegistry,
|
|
normalizeConsultationDomain,
|
|
validateConsultationDomainPlan,
|
|
} from "../src/lib/consultation-domain-registry.ts";
|
|
import { consultationInputSchema } from "../src/mastra/consultation-workflow.ts";
|
|
import { chatSessionWriteSchema } from "../src/lib/chat-session-write-contract.ts";
|
|
import { defaultGuidedJyotishTopics } from "../src/lib/guided-jyotish-topics.ts";
|
|
|
|
const expected = ["career", "marriage", "wealth", "health", "education", "migration", "family", "annual", "timing", "general"];
|
|
|
|
test("domain registry is the complete allowlist used by UI and workflow input", () => {
|
|
assert.deepEqual([...consultationDomainIds], expected);
|
|
assert.deepEqual(consultationDomainRegistry.map((domain) => domain.id), expected);
|
|
assert.deepEqual(defaultGuidedJyotishTopics.map((topic) => topic.id), expected);
|
|
for (const theme of expected) {
|
|
assert.equal(consultationInputSchema.safeParse({ year: 2000, month: 1, day: 1, hour: 0, minute: 0, lat: 0, lon: 0, tz: 0, city: "Test", question: "test", theme }).success, true);
|
|
}
|
|
});
|
|
|
|
test("aliases normalize to stable persisted domain ids", () => {
|
|
assert.equal(normalizeConsultationDomain("relationship"), "marriage");
|
|
assert.equal(normalizeConsultationDomain("finance"), "wealth");
|
|
assert.equal(normalizeConsultationDomain("health-pressure"), "health");
|
|
assert.equal(normalizeConsultationDomain("home"), "migration");
|
|
assert.equal(normalizeConsultationDomain("unknown"), null);
|
|
});
|
|
|
|
test("server domain plans are allowlisted, ordered and deduplicated", () => {
|
|
assert.deepEqual(validateConsultationDomainPlan(["career", "finance", "career", "home"]), ["career", "wealth", "migration"]);
|
|
assert.throws(() => validateConsultationDomainPlan([]), /invalid_consultation_domain_plan/);
|
|
assert.throws(() => validateConsultationDomainPlan(["career", "prashna"]), /unsupported_consultation_domain/);
|
|
});
|
|
|
|
test("session persistence accepts every canonical domain and rejects product routes", () => {
|
|
for (const theme of expected) {
|
|
const parsed = chatSessionWriteSchema.safeParse({ title: "Test", theme, model_id: "test", messages: [], session_type: "consultation", rectification_case_id: null, updated_at: "2026-08-14T00:00:00.000Z" });
|
|
assert.equal(parsed.success, true, theme);
|
|
}
|
|
assert.equal(chatSessionWriteSchema.safeParse({ title: "Test", theme: "muhurta", model_id: "test", messages: [], session_type: "consultation", rectification_case_id: null, updated_at: "2026-08-14T00:00:00.000Z" }).success, false);
|
|
});
|