test(chat): 补齐对白与叙述排版回归
- tests/digital-message-format.test.ts: 验证公共格式预算、角色资料裁剪和继续生成规范 - tests/digital-continue.test.ts: 验证发送、继续与重新生成均向模型传递排版规则 - README.md、docs/DIGITAL_HUMANS.md: 同步文本协议、旧消息兼容与验证边界说明
This commit is contained in:
@@ -7,7 +7,10 @@ import { createApp } from "../src/app";
|
||||
import { pool } from "../src/db/pool";
|
||||
import { env } from "../src/config/env";
|
||||
import { authService } from "../src/modules/auth/auth.service";
|
||||
import type { PromptMessage } from "../src/modules/digital/digital.prompt";
|
||||
import {
|
||||
messageFormatPolicy,
|
||||
type PromptMessage,
|
||||
} from "../src/modules/digital/digital.prompt";
|
||||
|
||||
type Last = {
|
||||
role: string;
|
||||
@@ -322,3 +325,19 @@ test("空中止记录之前是用户发言时,仍要求正常回复或重新
|
||||
);
|
||||
assert.equal(r.response.statusCode, 400);
|
||||
});
|
||||
|
||||
for (const mode of ["send", "continue", "regenerate"] as const)
|
||||
test(`${mode} 真实路由向模型传递公共对白/叙述格式`, async (t) => {
|
||||
const result = await exercise(t, mode, {
|
||||
role: "assistant",
|
||||
content: "(她合上书)你好。",
|
||||
status: "complete",
|
||||
sequence_id: 3,
|
||||
});
|
||||
assert.equal(result.response.statusCode, 200);
|
||||
assert.ok(
|
||||
result.upstream
|
||||
?.find((m) => m.role === "system")
|
||||
?.content.includes(messageFormatPolicy),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/** 公共排版规则的预算与请求链路回归;不调用真实模型、不改写历史正文。 */
|
||||
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),
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user