import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import test from "node:test"; import { defaultGuidedJyotishTopics, generalGuidedJyotishTopics, } from "../src/lib/guided-jyotish-topics.ts"; const pageSource = readFileSync(new URL("../src/app/page.tsx", import.meta.url), "utf8"); const globalStyles = readFileSync(new URL("../src/app/globals.css", import.meta.url), "utf8"); const appSidebarSource = readFileSync(new URL("../src/components/app-sidebar.tsx", import.meta.url), "utf8"); const guidedTopicsSource = readFileSync(new URL("../src/lib/guided-jyotish-topics.ts", import.meta.url), "utf8"); function sourceBetween(source: string, startMarker: string, endMarker: string) { const start = source.indexOf(startMarker); const end = source.indexOf(endMarker, start); assert.notEqual(start, -1); assert.notEqual(end, -1); return source.slice(start, end); } test("keeps starter questions visible while the user edits a draft", () => { // Given: the empty-session starter block and its render guard. const guardStart = pageSource.indexOf("{profileComplete && presetMessageFinished"); const onboardingBranch = pageSource.indexOf("(onboardingPending ?", guardStart); // When: the guard is inspected independently of the card copy and layout. assert.notEqual(guardStart, -1); assert.notEqual(onboardingBranch, -1); const starterVisibilityGuard = pageSource.slice(guardStart, onboardingBranch); // Then: draft text cannot hide the cards before a message is submitted. assert.doesNotMatch(starterVisibilityGuard, /\bdraft\b/); }); test("completed account initialization switches directly to the home cards", () => { assert.doesNotMatch(pageSource, /setOnboardingJustCompleted\(true\)/); assert.doesNotMatch(pageSource, /!profileComplete \|\| onboardingJustCompleted/); }); test("default starter questions are guided Jyotish topics with evidence and claim boundaries", () => { assert.match(pageSource, /defaultGuidedJyotishTopics/); assert.match(pageSource, /starterSuggestions\.map/); assert.match(pageSource, /starterThemes\.find\(\(candidate\) => candidate\.id === item\.theme\)/); assert.match(pageSource, /chooseSuggestedQuestion\(item\.text, item\.theme\)/); assert.match(guidedTopicsSource, /strictWorkflowRoute/); assert.match(guidedTopicsSource, /evidencePreview/); assert.match(guidedTopicsSource, /confidenceCap/); assert.match(guidedTopicsSource, /claimBoundary/); assert.match(guidedTopicsSource, /D10/); assert.match(guidedTopicsSource, /D9/); assert.match(guidedTopicsSource, /Ashtakavarga/); assert.match(guidedTopicsSource, /独立 holdout/); }); test("profiles without a usable birth minute only receive general-knowledge homepage prompts", () => { assert.deepEqual(generalGuidedJyotishTopics.map((topic) => topic.id), defaultGuidedJyotishTopics.map((topic) => topic.id)); assert.deepEqual(generalGuidedJyotishTopics.map((topic) => topic.prompt), [ "印度占星一般会从哪些因素理解事业方向?", "印度占星一般如何分析关系模式?", "印度占星一般如何分析财富结构与风险?", "印度占星中的时间推运通常会看哪些因素?", ]); assert.match(pageSource, /const starterThemes = personalChartAvailable \? themes : generalGuidedJyotishTopics/); assert.match(pageSource, /personalChartAvailable[\s\S]*?回答一般占星知识/); assert.match(pageSource, /完成生时校正后,再讨论个人星盘结论/); assert.match(pageSource, /personalChartAvailable \? "daily_starlanguage" : null/); }); test("keeps follow-up suggestions visible while the user edits a draft", () => { // Given: the follow-up suggestion block and its render guard. const suggestionGuard = sourceBetween( pageSource, "{activeSuggestions.length > 0", "(\n