fix(consultation): decouple reply metadata from prompt
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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(
|
||||
[
|
||||
"回答正文",
|
||||
'<!--AYANAM_SUGGESTIONS:["模型问题一","模型问题二","模型问题三"]-->',
|
||||
"<!--AYANAM_TITLE:模型标题-->",
|
||||
].join("\n"),
|
||||
"career",
|
||||
createConsultationReplyMetadata({ theme: "career", question: "工作变化的重点是什么?" }),
|
||||
);
|
||||
|
||||
assert.equal(reply.text, "回答正文");
|
||||
assert.deepEqual(reply.suggestions, ["我更适合怎样的职业路径?", "未来一年事业上要避开什么?", "我该如何发挥自己的优势?"]);
|
||||
assert.equal(reply.title, "工作变化的重点是什么");
|
||||
});
|
||||
@@ -46,6 +46,7 @@ test("personal consultation lets the Agent invoke the server-bound workflow tool
|
||||
assert.match(tools, /\(ctx\.runWorkflow \?\? runConsultationWorkflow\)\(toolInput, \{/);
|
||||
assert.match(tools, /return \{ "run-jyotish-consultation": consultationTool \};/);
|
||||
assert.match(agenticBranch, /state\.workflowReceipt\?\.preciseTiming === "allowed"/);
|
||||
assert.match(route, /createConsultationReplyMetadata/);
|
||||
});
|
||||
|
||||
test("defers optional external evidence only for foreground chat", () => {
|
||||
@@ -76,6 +77,8 @@ test("validates and emits non-sensitive workflow and execution receipts", () =>
|
||||
test("carries commercial technique truth into the model contract", () => {
|
||||
assert.match(workflow, /technique_truth/);
|
||||
assert.match(mastra, /deterministic_claims_forbidden_for/);
|
||||
assert.doesNotMatch(mastra, /AYANAM_SUGGESTIONS|AYANAM_TITLE/);
|
||||
assert.doesNotMatch(mastra, /2-5 short paragraphs/);
|
||||
assert.match(mastra, /reference_only/);
|
||||
assert.match(mastra, /Do not use a restricted technique/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user