feat(character): appearance/motive 全栈穿线 + motive/traits 口径重切
打通 appearance/motive 从生成→schema→契约→落库→前端整条穿线 (DB 列早在初始迁移、此前一直 NULL,无新迁移),并原子重切人物 内驱口径。 - @llm: CharacterCard/character-gen.md 加 appearance/motive(给默认值守 解析韧性),重切——动机唯一落 motive、traits 只留核心/表层/阴影三层、 arc 引用 motive;regen prompt_hashes.json 金标准。 - @backend: CharacterCardView + CharacterWriteRepo/SqlCharacterWriteRepo (create + update backfill 分支)+ CharacterWriteFields + 路由双向形变 与 _existing_characters 带上两字段。 - @frontend: pnpm gen:api 重生成 TS 客户端;CharacterCardItem 展示/编辑 两字段。 - 测试: schema 默认值/解析、动机不双写重切回归、card_to_view 双向、 ingest 透传、list 暴露、SqlCharacterWriteRepo create/backfill 真 pg 集成。
This commit is contained in:
@@ -108,6 +108,30 @@ def test_character_card_optional_collections_default_empty() -> None:
|
||||
assert card.relations == []
|
||||
|
||||
|
||||
def test_character_card_has_appearance_motive_defaults() -> None:
|
||||
# ⑧ 穿线:appearance/motive 有默认值守解析韧性(LLM 漏产字段不致整卡解析失败)。
|
||||
card = CharacterCard.model_validate(
|
||||
{"name": "甲", "role": "工具人", "backstory": "无名小卒", "arc": "始终如一"}
|
||||
)
|
||||
assert card.appearance == ""
|
||||
assert card.motive == ""
|
||||
|
||||
|
||||
def test_character_card_parses_appearance_and_motive() -> None:
|
||||
card = CharacterCard.model_validate(
|
||||
{
|
||||
"name": "苏璃",
|
||||
"role": "CP",
|
||||
"backstory": "遗孤",
|
||||
"arc": "由敌转盟",
|
||||
"appearance": "银发赤瞳,惯着玄色劲装",
|
||||
"motive": "替亡兄查清族灭真相",
|
||||
}
|
||||
)
|
||||
assert card.appearance == "银发赤瞳,惯着玄色劲装"
|
||||
assert card.motive == "替亡兄查清族灭真相"
|
||||
|
||||
|
||||
def test_character_card_requires_core_fields() -> None:
|
||||
# name/role/backstory/arc 为必填
|
||||
with pytest.raises(ValidationError):
|
||||
@@ -168,6 +192,31 @@ def test_character_gen_spec_prompt_documents_anti_duplication() -> None:
|
||||
assert "防雷同" in prompt
|
||||
|
||||
|
||||
def test_character_gen_prompt_declares_appearance_and_motive_fields() -> None:
|
||||
# ⑧ 穿线:产出契约须显式声明 appearance/motive 两个新字段。
|
||||
prompt = character_gen_spec.system_prompt
|
||||
assert "appearance" in prompt
|
||||
assert "motive" in prompt
|
||||
|
||||
|
||||
def test_motive_not_double_written_in_traits() -> None:
|
||||
# D6 重切回归:动机唯一落 `motive` 字段,`traits` 只留性格三层——
|
||||
# traits 契约行须把动机/欲望/恐惧**改导向 motive**,绝不再指示折进 traits
|
||||
# (否则双写→漂移→喂 ③ 人物塑造审查假信号)。
|
||||
prompt = character_gen_spec.system_prompt
|
||||
lines = prompt.splitlines()
|
||||
traits_line = next(line for line in lines if line.lstrip().startswith("- **traits**"))
|
||||
motive_line = next(line for line in lines if line.lstrip().startswith("- **motive**"))
|
||||
# traits 契约行显式把动机重导向 motive 字段(而非折进 traits)。
|
||||
assert "motive" in traits_line
|
||||
# 旧的「写明核心动机」折入指示已被移除。
|
||||
assert "写明核心动机" not in prompt
|
||||
assert "并写明" not in traits_line
|
||||
# motive 契约行承接内驱三要素。
|
||||
assert "动机" in motive_line
|
||||
assert "恐惧" in motive_line
|
||||
|
||||
|
||||
# ---- 共性:immutable + 是 AgentSpec ----
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user