import assert from "node:assert/strict"; import test from "node:test"; import { createConsultationReplyMetadata, consultationReplyMetadataSchema } from "../src/lib/consultation-reply-metadata.ts"; import { parseAgentReply } from "../src/lib/agent-reply.ts"; for (const theme of ["career", "marriage", "wealth", "timing", "general"] as const) { test(`server-owned metadata is bounded for ${theme}`, () => { const metadata = createConsultationReplyMetadata({ theme, question: "未来的重点是什么?" }); const parsed = consultationReplyMetadataSchema.parse(metadata); assert.equal(parsed.suggestions.length, 3); assert.ok(parsed.suggestions.every((item) => item.length > 0 && item.length <= 80)); assert.ok(parsed.title.length >= 6 && parsed.title.length <= 14); assert.doesNotMatch(parsed.title, /[\d\p{P}\p{S}]/u); }); } test("server metadata wins without blocking legacy hidden-block parsing", () => { const reply = parseAgentReply( [ "回答正文", '', "", ].join("\n"), "career", createConsultationReplyMetadata({ theme: "career", question: "工作变化的重点是什么?" }), ); assert.equal(reply.text, "回答正文"); assert.deepEqual(reply.suggestions, ["我更适合怎样的职业路径?", "未来一年事业上要避开什么?", "我该如何发挥自己的优势?"]); assert.equal(reply.title, "工作变化的重点是什么"); });