import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import test from "node:test"; import { createConsultationReplyMetadata, consultationReplyMetadataSchema } from "../src/lib/consultation-reply-metadata.ts"; import { parseAgentReply } from "../src/lib/agent-reply.ts"; test("server-owned metadata is a bounded title and nothing else", () => { const metadata = createConsultationReplyMetadata({ question: "未来的重点是什么?" }); const parsed = consultationReplyMetadataSchema.parse(metadata); assert.deepEqual(Object.keys(parsed), ["title"]); assert.ok(parsed.title.length >= 6 && parsed.title.length <= 14); assert.doesNotMatch(parsed.title, /[\d\p{P}\p{S}]/u); }); test("the schema rejects a suggestions field so the chips cannot come back through metadata", () => { assert.equal( consultationReplyMetadataSchema.safeParse({ title: "工作变化的重点是什么", suggestions: ["一", "二", "三"] }).success, false, ); }); test("server metadata wins over a model title and produces no suggestions", () => { const reply = parseAgentReply( [ "回答正文", '', "", ].join("\n"), createConsultationReplyMetadata({ question: "工作变化的重点是什么?" }), ); assert.equal(reply.text, "回答正文"); assert.equal(reply.title, "工作变化的重点是什么"); assert.deepEqual(Object.keys(reply), ["text", "title"]); }); test("no per-theme suggestion table survives anywhere in the reply pipeline", () => { // Two copies of the same ten-theme triplet used to exist; both are gone, and the // consult route must no longer attach a suggestions field to the stored message. const metadata = readFileSync(new URL("../src/lib/consultation-reply-metadata.ts", import.meta.url), "utf8"); const parsing = readFileSync(new URL("../src/lib/agent-reply.ts", import.meta.url), "utf8"); const route = readFileSync(new URL("../src/app/api/consult/route.ts", import.meta.url), "utf8"); assert.doesNotMatch(metadata, /fallbackSuggestions|suggestions:/); assert.doesNotMatch(parsing, /fallbackSuggestions/); assert.doesNotMatch(route, /suggestions/); });