/** 公共排版规则的预算与请求链路回归;不调用真实模型、不改写历史正文。 */ import test from "node:test"; import assert from "node:assert/strict"; import { contentSchema } from "../src/modules/digital/digital.schema"; import { assemblePrompt, continuationMessages, messageFormatPolicy, } from "../src/modules/digital/digital.prompt"; test("角色、预设和实验快照不能挤掉回复格式,最小预算仍完整保留", () => { const body = contentSchema.shape.body.parse({ cover: "", contextBudget: 6000, systemPrompt: "旧预设要求一整段输出", description: "角色背景".repeat(3000), }); const history = [{ role: "user" as const, content: "用".repeat(4000) }]; const result = assemblePrompt( { ...body, name: "测试角色" }, body, [], history, { persona: "", userName: "旅人", memory: "" }, [], ); const system = result.messages[0].content; assert.ok(system.includes(messageFormatPolicy)); assert.ok( system.indexOf(messageFormatPolicy) > system.indexOf("旧预设要求一整段输出"), ); assert.ok(result.characters <= body.contextBudget); assert.equal(result.messages.at(-1)?.content, history[0].content); assert.match(system, /动作、神态、环境与角色在故事中的心理描写/); }); test("继续生成携带相同格式且不修改历史正文,账号偏好仍在系统末尾", () => { const body = contentSchema.shape.body.parse({ cover: "" }); const history = [ { role: "assistant" as const, content: "(她点点头)你好。" }, ]; const prompt = assemblePrompt( { ...body, name: "测试角色" }, body, [], history, { persona: "", userName: "旅人", memory: "" }, [], ); const continued = continuationMessages(prompt.messages); assert.match(continued.at(-1)!.content, /对白使用双引号,叙述用单星号包裹/); assert.equal(history[0].content, "(她点点头)你好。"); assert.ok( prompt.messages[0].content.lastIndexOf("账号内容偏好") > prompt.messages[0].content.indexOf(messageFormatPolicy), ); });