feat(web): 角色群像按定位配比生成(role_mix 缩减版)

- 契约: CharacterGenerateRequest 加 role_mix{定位:数量},model_validator 归一
  count=各值之和(每项≥1、总和≤12),缺省退回单一 role+count
- @llm: build_character_gen_context/run_character_gen 加 role_mix 参并注入配比块
  (确定性、无时间戳,守 assemble 纯函数);router 穿参
- character-gen.md 加"按配比严格分配 role"纪律 + regen prompt_hashes 金标准
- 前端: sanitizeRoleMix/roleMixTotal + buildCharacterGenerateRequest 第4参 +
  useCharacterGen 穿参 + RoleMixEditor + CharacterGenerator 单一/配比双模
This commit is contained in:
Yaojia Wang
2026-07-06 17:24:16 +02:00
parent 72b3c81146
commit 7babb4854b
16 changed files with 428 additions and 50 deletions

View File

@@ -53,6 +53,24 @@ describe("useCharacterGen", () => {
expect(toast).not.toHaveBeenCalled();
});
it("按定位配比生成:请求体带 role_mix、count 取各值之和", async () => {
post.mockResolvedValue({ data: { cards: [] }, error: null });
const { result } = renderHook(() => useCharacterGen());
await act(async () => {
await result.current.generate({
projectId: "p1",
brief: "群像",
count: 1,
role: "忽略",
roleMix: { 主角: 1, 对手: 2 },
});
});
const body = post.mock.calls[0]?.[1]?.body;
expect(body.role_mix).toEqual({ 主角: 1, 对手: 2 });
expect(body.count).toBe(3);
expect(body.role).toBeUndefined();
});
it("生成成功但 cards 缺失:回退为空数组", async () => {
post.mockResolvedValue({ data: { cards: null }, error: null });
const { result } = renderHook(() => useCharacterGen());