52f3c04b3b
Measured use of the three chips above the composer was negligible. They were also not what they appeared to be: the server looked up a fixed triplet by session theme and passed it as metadata that overrode anything the model produced, so the same ten hardcoded sets served every user regardless of question or chart. That is a plausible reason nobody pressed them. Both copies of the per-theme table are gone, reply metadata narrows to the session title, and the two parse entry points collapse into one now that they return the same shape. The write schema still tolerates a suggestions field so a client on the previous bundle does not lose its message mid-deploy, and stored answers containing the legacy hidden block are still stripped rather than shown raw. Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
2.2 KiB
TypeScript
49 lines
2.2 KiB
TypeScript
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(
|
|
[
|
|
"回答正文",
|
|
'<!--AYANAM_SUGGESTIONS:["模型问题一","模型问题二","模型问题三"]-->',
|
|
"<!--AYANAM_TITLE:模型标题-->",
|
|
].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/);
|
|
});
|