Files
access-manage/tests/digital-message-format.test.ts
T
湛兮 905100da40 test(chat): 补齐对白与叙述排版回归
- tests/digital-message-format.test.ts: 验证公共格式预算、角色资料裁剪和继续生成规范
- tests/digital-continue.test.ts: 验证发送、继续与重新生成均向模型传递排版规则
- README.md、docs/DIGITAL_HUMANS.md: 同步文本协议、旧消息兼容与验证边界说明
2026-10-27 22:19:05 +08:00

59 lines
2.1 KiB
TypeScript

/** 公共排版规则的预算与请求链路回归;不调用真实模型、不改写历史正文。 */
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),
);
});