33 lines
1.6 KiB
TypeScript
33 lines
1.6 KiB
TypeScript
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";
|
|
import { consultationDomainIds } from "../src/lib/consultation-domain-registry.ts";
|
|
|
|
for (const theme of consultationDomainIds) {
|
|
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(
|
|
[
|
|
"回答正文",
|
|
'<!--AYANAM_SUGGESTIONS:["模型问题一","模型问题二","模型问题三"]-->',
|
|
"<!--AYANAM_TITLE:模型标题-->",
|
|
].join("\n"),
|
|
"career",
|
|
createConsultationReplyMetadata({ theme: "career", question: "工作变化的重点是什么?" }),
|
|
);
|
|
|
|
assert.equal(reply.text, "回答正文");
|
|
assert.deepEqual(reply.suggestions, ["我更适合怎样的职业路径?", "未来一年事业上要避开什么?", "我该如何发挥自己的优势?"]);
|
|
assert.equal(reply.title, "工作变化的重点是什么");
|
|
});
|