feat(home): 首页开场语改成一行问候,占位符改「想聊什么都可以」
开场语从「称呼行 + 追问句」收成 claude.ai 式的单行问候:时段池、 星期池、回访池按顺序拼成一个数组,按 variantSelection 确定性取一条; 名字为空时跳过带称呼的条目。副标题行与 .starter-salutation 下线, h1 降到 clamp(24px, 2.8vw, 30px) / line-height 1.25。追问改由输入框 占位符承担。 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JUei7K13cYxLHE3Axe4A45
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
dd281dd9c9
commit
ff0427cf08
@@ -77,7 +77,7 @@ test("a queued card renders above the live textarea", () => {
|
||||
inputRef: createRef<HTMLTextAreaElement>(),
|
||||
value: "还想再问一句",
|
||||
inputLabel: "输入你的问题",
|
||||
placeholder: "例如:未来半年是否适合换工作?",
|
||||
placeholder: "想聊什么都可以",
|
||||
maxLength: 500,
|
||||
inputDisabled: false,
|
||||
submitLabel: "发送",
|
||||
|
||||
@@ -386,7 +386,9 @@ test("the starter heading is drawn per visit and the entry pills carry no fine p
|
||||
const source = homeSurface;
|
||||
|
||||
// Given: the heading reads from a variant seeded once per mount and redrawn when the home is left.
|
||||
assert.match(source, /<h1 id="starter-heading">\{starterGreeting\.question\}<\/h1>/);
|
||||
// 原值 `{starterGreeting.question}` / 新值 `{starterGreeting.text}` / 原因:开场语改成单行问候,
|
||||
// 「招呼语 + 问句」两半的形状取消,heading 直接就是整行;「每次进首页重抽」这条意图没变。
|
||||
assert.match(source, /<h1 id="starter-heading">\{starterGreeting\.text\}<\/h1>/);
|
||||
assert.match(source, /useState\(\(\) => Math\.random\(\)\)/);
|
||||
assert.match(source, /starterGreetingUnseen\.current = true;\s*\n\s*setStarterGreetingSelection\(Math\.random\(\)\)/);
|
||||
|
||||
@@ -426,7 +428,10 @@ test("the starter greeting keeps the display stack and display weight", () => {
|
||||
assert.match(heading, /font-weight:\s*500\s*;/);
|
||||
assert.doesNotMatch(heading, /font-family:\s*var\(--font-body\)/);
|
||||
// 问候不该再是 52px 的落地页大标题,它现在只是输入框上面的一行。
|
||||
assert.match(heading, /font-size:\s*clamp\(26px,/);
|
||||
// 原值 `clamp(26px,` / 新值 `clamp(24px,` / 原因:开场语从「招呼语 + 问句」两行收成单行问候,
|
||||
// 不再需要 34px 上限那一档;上限同步降到 30px,断言仍然钉住「不是落地页大标题」这条意图。
|
||||
assert.match(heading, /font-size:\s*clamp\(24px, 2\.8vw, 30px\);/);
|
||||
assert.match(heading, /line-height:\s*1\.25;/);
|
||||
});
|
||||
|
||||
test("the starter home hides technical chart parameters", () => {
|
||||
|
||||
@@ -8,59 +8,171 @@ import {
|
||||
} from "../src/lib/starter-greeting.ts";
|
||||
import { homeSurface } from "./home-surface.ts";
|
||||
|
||||
// 2026-07-19 是周日,20 周一,22 周三(星期池为空),24 周五,25 周六。
|
||||
const SUNDAY = (hour: number) => new Date(2026, 6, 19, hour);
|
||||
const MONDAY = (hour: number) => new Date(2026, 6, 20, hour);
|
||||
const WEDNESDAY = (hour: number) => new Date(2026, 6, 22, hour);
|
||||
const FRIDAY = (hour: number) => new Date(2026, 6, 24, hour);
|
||||
|
||||
test("terminal and fallback greetings follow the current profile name", () => {
|
||||
// 原值: 同时锁 onboardingRequestIdentity / isCurrentOnboardingRequest,避免建议问题串号。
|
||||
// 新值: 只保留问候语随当前称呼变化。
|
||||
// 原因: 建议问题请求已删除,身份去重不再有消费点。
|
||||
const terminalGreeting = createStartGreeting("周宁", new Date(2026, 6, 19, 8), 0);
|
||||
//
|
||||
// 原值 `createStartGreeting("周宁", …, 0)` + `"周宁,从你此刻最关心的问题开始吧。"`
|
||||
// / 新值 `createStartGreeting("周宁", …, 0.25)` + `"欢迎,周宁"`
|
||||
// / 原因:时段池现在第一条是不带称呼的「早上好」,要取带称呼的条目得换下标;
|
||||
// 兜底问候按产品口径改成单行「欢迎,{名字}」,不再追问。断言强度没变:
|
||||
// 两条都仍然必须带当前称呼、不得带旧称呼。
|
||||
const terminalGreeting = createStartGreeting("周宁", SUNDAY(8), 0.25);
|
||||
const fallbackGreeting = createOnboardingFallbackGreeting("周宁");
|
||||
for (const greeting of [terminalGreeting, fallbackGreeting]) {
|
||||
assert.match(greeting, /周宁/);
|
||||
assert.doesNotMatch(greeting, /林遥/);
|
||||
}
|
||||
assert.equal(fallbackGreeting, "周宁,从你此刻最关心的问题开始吧。");
|
||||
assert.equal(terminalGreeting, "早上好,周宁");
|
||||
assert.equal(fallbackGreeting, "欢迎,周宁");
|
||||
});
|
||||
|
||||
test("the starter hero splits one time-aware greeting instead of drawing from a separate pool", () => {
|
||||
// Given: the same daypart variant, asked for as parts and as one line.
|
||||
const noon = new Date(2026, 6, 19, 12);
|
||||
const parts = createStartGreetingParts("周宁", noon, 0);
|
||||
const whole = createStartGreeting("周宁", noon, 0);
|
||||
test("the starter greeting is one line drawn from daypart, weekday and returning pools", () => {
|
||||
// 原值:`parts.salutation` = "中午好,周宁。"、`parts.question` = "现在最想理清哪件事?",
|
||||
// 并断言两半拼起来等于整行、每个时段至少 12 条不同问句。
|
||||
// 新值:`parts.text` 就是整行问候;断言时段池按下标取到「中午好」/「中午好,周宁」。
|
||||
// 原因:产品把开场语改成 claude.ai 式的单行问候,追问句移到输入框占位符,
|
||||
// 「招呼语 + 问句」两半这个形状本身被取消,问句池不再存在。
|
||||
const noon = WEDNESDAY(12);
|
||||
assert.equal(createStartGreetingParts("周宁", noon, 0).text, "中午好");
|
||||
assert.equal(createStartGreetingParts("周宁", noon, 0.5).text, "中午好,周宁");
|
||||
assert.equal(createStartGreeting("周宁", noon, 0.5), createStartGreetingParts("周宁", noon, 0.5).text);
|
||||
|
||||
// Then: the salutation carries the name and the question carries no name, and they recompose exactly.
|
||||
assert.equal(parts.salutation, "中午好,周宁。");
|
||||
assert.equal(parts.question, "现在最想理清哪件事?");
|
||||
assert.equal(`${parts.salutation}${parts.question}`, whole);
|
||||
assert.doesNotMatch(parts.question, /周宁/);
|
||||
|
||||
// And: the extremes stay inside the variant list rather than falling off the end.
|
||||
assert.equal(createStartGreetingParts("周宁", noon, 1).question, "事业、关系或选择,想先聊哪个?");
|
||||
assert.equal(createStartGreetingParts("周宁", noon, 0.999999).question, "事业、关系或选择,想先聊哪个?");
|
||||
|
||||
// And: every daypart is reachable, so the heading is not one fixed line in disguise.
|
||||
const questions = new Set([0, 8, 12, 16, 20, 23].flatMap((hour) =>
|
||||
[0, 1 / 3, 2 / 3].map((selection) =>
|
||||
createStartGreetingParts("周宁", new Date(2026, 6, 19, hour), selection).question)));
|
||||
assert.ok(questions.size >= 12);
|
||||
// 边界不越界:1 与 0.999999 都落在池内最后一条。
|
||||
assert.equal(createStartGreetingParts("周宁", noon, 1).text, "中午好,周宁");
|
||||
assert.equal(createStartGreetingParts("周宁", noon, 0.999999).text, "中午好,周宁");
|
||||
});
|
||||
|
||||
test("the starter hero stays at a salutation and a question", () => {
|
||||
test("late night has its own three lines and none of them asks a follow-up", () => {
|
||||
const lateNight = WEDNESDAY(2);
|
||||
assert.equal(createStartGreetingParts("周宁", lateNight, 0).text, "夜猫子,晚上好");
|
||||
assert.equal(createStartGreetingParts("周宁", lateNight, 1 / 3).text, "还没睡呀,周宁");
|
||||
assert.equal(createStartGreetingParts("周宁", lateNight, 0.7).text, "晚安前再聊一会");
|
||||
// 23 点与 4 点同属深夜。
|
||||
assert.equal(createStartGreetingParts("周宁", WEDNESDAY(23), 1 / 3).text, "还没睡呀,周宁");
|
||||
assert.equal(createStartGreetingParts("周宁", WEDNESDAY(4), 1 / 3).text, "还没睡呀,周宁");
|
||||
});
|
||||
|
||||
test("a blank name leaves only the lines that carry no name", () => {
|
||||
const lateNight = WEDNESDAY(2);
|
||||
assert.equal(createStartGreetingParts("", lateNight, 0).text, "夜猫子,晚上好");
|
||||
assert.equal(createStartGreetingParts(" ", lateNight, 0.9).text, "晚安前再聊一会");
|
||||
|
||||
// 周一的星期条目带称呼,名字为空时整条不可达;回访池同理。
|
||||
for (let step = 0; step < 100; step += 1) {
|
||||
for (const hasSessions of [false, true]) {
|
||||
const text = createStartGreetingParts("", MONDAY(9), step / 100, hasSessions).text;
|
||||
assert.doesNotMatch(text, /周一了/);
|
||||
assert.doesNotMatch(text, /又见面了|嗨,|最近还好吗/);
|
||||
assert.ok(text.length > 0);
|
||||
assert.doesNotMatch(text, /\{名字\}/);
|
||||
assert.doesNotMatch(text, /,$|^,/);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("the weekday pool only opens on its own day", () => {
|
||||
const friday = FRIDAY(9);
|
||||
const fridayLines = new Set(Array.from({ length: 100 }, (_, step) =>
|
||||
createStartGreetingParts("周宁", friday, step / 100).text));
|
||||
assert.ok(fridayLines.has("周五快乐"));
|
||||
|
||||
const wednesdayLines = new Set(Array.from({ length: 100 }, (_, step) =>
|
||||
createStartGreetingParts("周宁", WEDNESDAY(9), step / 100).text));
|
||||
assert.ok(!wednesdayLines.has("周五快乐"));
|
||||
assert.equal(wednesdayLines.size, 3);
|
||||
|
||||
assert.ok(new Set(Array.from({ length: 100 }, (_, step) =>
|
||||
createStartGreetingParts("周宁", MONDAY(9), step / 100).text)).has("周一了,周宁"));
|
||||
assert.ok(new Set(Array.from({ length: 100 }, (_, step) =>
|
||||
createStartGreetingParts("周宁", SUNDAY(9), step / 100).text)).has("周日,慢一点"));
|
||||
});
|
||||
|
||||
test("the returning pool needs at least one session behind the account", () => {
|
||||
const evening = WEDNESDAY(20);
|
||||
const returning = ["又见面了,周宁", "欢迎回来", "嗨,周宁", "最近还好吗,周宁?"];
|
||||
|
||||
const firstVisit = new Set(Array.from({ length: 100 }, (_, step) =>
|
||||
createStartGreetingParts("周宁", evening, step / 100, false).text));
|
||||
for (const line of returning) assert.ok(!firstVisit.has(line), `first visit must not reach ${line}`);
|
||||
assert.equal(firstVisit.size, 3);
|
||||
|
||||
const returnVisit = new Set(Array.from({ length: 100 }, (_, step) =>
|
||||
createStartGreetingParts("周宁", evening, step / 100, true).text));
|
||||
for (const line of returning) assert.ok(returnVisit.has(line), `return visit must reach ${line}`);
|
||||
assert.equal(returnVisit.size, 7);
|
||||
});
|
||||
|
||||
test("the same inputs always produce the same line", () => {
|
||||
for (const hour of [2, 8, 12, 16, 20]) {
|
||||
for (const hasSessions of [false, true]) {
|
||||
for (const step of [0, 17, 42, 99]) {
|
||||
const args = [hour, step / 100, hasSessions] as const;
|
||||
const first = createStartGreeting("周宁", WEDNESDAY(args[0]), args[1], args[2]);
|
||||
const second = createStartGreeting("周宁", WEDNESDAY(args[0]), args[1], args[2]);
|
||||
assert.equal(first, second);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("no greeting line uses a metaphor or trails off into a sentence", () => {
|
||||
for (let day = 19; day <= 25; day += 1) {
|
||||
for (let hour = 0; hour < 24; hour += 1) {
|
||||
for (const name of ["周宁", ""]) {
|
||||
for (const hasSessions of [false, true]) {
|
||||
for (let step = 0; step < 100; step += 1) {
|
||||
const text = createStartGreetingParts(
|
||||
name,
|
||||
new Date(2026, 6, day, hour),
|
||||
step / 100,
|
||||
hasSessions,
|
||||
).text;
|
||||
assert.doesNotMatch(text, /[星月陪]/, `metaphor in ${text}`);
|
||||
assert.doesNotMatch(text, /。$/, `sentence period in ${text}`);
|
||||
assert.ok(text.length > 0);
|
||||
assert.ok(text.length <= 12, `${text} is longer than one short line`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("the starter hero is one heading and nothing else", () => {
|
||||
const source = homeSurface;
|
||||
|
||||
// Given: the hero heading is the question half of the time-aware greeting.
|
||||
// 原值 `className="starter-greeting"` / 新值 `className="starter-salutation"`
|
||||
// / 原因:`.starter-greeting` 这个类名此前既指招呼语那一行、又被读成整块问候区,
|
||||
// 拆成 `.starter-greeting-block`(容器)与 `.starter-salutation`(招呼语)后不再歧义。
|
||||
// 「两行:招呼语 + 问句」这个意图本身没变。
|
||||
assert.match(source, /<p className="starter-salutation">\{starterGreeting\.salutation\}<\/p>/);
|
||||
assert.match(source, /<h1 id="starter-heading">\{starterGreeting\.question\}<\/h1>/);
|
||||
//
|
||||
// 原值:断言 `<p className="starter-salutation">` 与 `<h1>{starterGreeting.question}</h1>` 同时存在
|
||||
// / 新值:断言只剩 `<h1 id="starter-heading">{starterGreeting.text}</h1>`,且 `starter-salutation` 在源码与样式里都消失
|
||||
// / 原因:开场语改成单行问候,副标题那一行连同它的样式一起下线;断言从「两行」改成「一行且不得有第二行」,强度不降反升。
|
||||
assert.match(source, /<h1 id="starter-heading">\{starterGreeting\.text\}<\/h1>/);
|
||||
assert.doesNotMatch(source, /starter-salutation/);
|
||||
assert.doesNotMatch(source, /starterGreeting\.(salutation|question)/);
|
||||
|
||||
// Then: no third line repeats the welcome the two lines above already carry.
|
||||
// Then: no third line repeats the welcome the heading already carries.
|
||||
assert.doesNotMatch(source, /starter-hero-note/);
|
||||
const styles = readFileSync(new URL("../src/app/globals.css", import.meta.url), "utf8");
|
||||
assert.doesNotMatch(styles, /starter-hero-note/);
|
||||
assert.doesNotMatch(styles, /starter-salutation/);
|
||||
|
||||
// And: the separate static heading pool is gone for good.
|
||||
assert.doesNotMatch(source, /starterPrompt|createStarterPrompt|greetingForHour/);
|
||||
assert.doesNotMatch(source, /greeting: createStartGreeting\(/);
|
||||
});
|
||||
|
||||
test("the greeting knows whether the account already has sessions", () => {
|
||||
// hasSessions 必须来自已有的会话列表变量,不得新开一份状态。
|
||||
assert.match(homeSurface, /const starterHasPriorSessions = sessions\.some\(/);
|
||||
assert.match(homeSurface, /createStartGreetingParts\(profile\.name, new Date\(\), starterGreetingSelection, starterHasPriorSessions\)/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user