M6:缘契、人格与世界——契约版本链、铸魂分灵、河图境界与三界分流
- 缘契域 domains/yuanqi:covenants(当前版)+ covenant_events(不可变历史);提议—问心—铭契—撤回全链;边界变更立即生效;多维关系并存,服务层拒绝 affinity/好感度单一键;浪漫维度成人资格标记位 - 道体铸魂与分灵 domains/jingsheng/soul.py:soul_forgings 确认流(锚点变更 pending→confirmed 应用并签发新魂籍版本,确认前人物锚点不变);分灵创建新人物(继承资料与谱系 lineage 链、不继承原身份,魂籍从 v1 起) - 河图域 domains/hetu:persistent_worlds 境界 + world_entities/world_relations 境界作用域重建 + 世谱挂接;境界正史视图(scope=persistent_world 归真集合);canonize 后置推进正史计数 - 三界分流:reality→息壤提取(不变);persistent_world→境界实录+正史推进;simulation→只记试演实录;factual_records 增 scope 列——境界/幻境实录与真界本相隔离 - 正影打通:引文 target_type=memory 时被引记忆 superseded → 返回 successor_memory_id 提示,不静默替换 - 前端:人物详情页缘契面板(提议维度选择/铭契/撤回/事件史)+ 世界页重建(境界目录/实体/正史概览)+ covenants/worlds api 库 - 退役:旧 personality/drive/evolution/world 模块、服务、端点、仓储、schema、前端五页与组件样式;迁移 007 退役九张旧表与 characters.current_personality_version_id - 验收(test_m6_domains 六用例):多维无单一好感度/铭契版本链/事件不可抹除/撤回立即生效/边界即时/铸魂确认流+魂籍版本/分灵谱系/境界正史不进真界(实录 scope 隔离+真界候选=0)/引文正影后继 - 四套件:后端 379、前端 199、BFF 4、神识 5 包全绿(2 个预存环境失败不变);迁移 007 净库+±1 干净
This commit is contained in:
1 parent
684261f4b4
commit
7e23d6fa84
108 files changed
+2600
-9732
No files matched your search
@@ -1,107 +0,0 @@
|
||||
"""内驱力数据访问测试(好奇问题 + 次生目标)。"""
|
||||
|
||||
import pytest
|
||||
|
||||
from app.db.session import AsyncSessionLocal
|
||||
from app.models.big_cycle import BigCycle
|
||||
from app.models.drive import CuriosityQuestion, ExploratorySubgoal
|
||||
from app.repositories import drive as drive_repo
|
||||
from app.services.characters import get_active_character_model
|
||||
|
||||
|
||||
async def _seed_cycle(session, character_id: str) -> str:
|
||||
cycle = BigCycle(
|
||||
character_id=character_id,
|
||||
trigger="test",
|
||||
status="completed",
|
||||
memory_count_at_trigger=20,
|
||||
)
|
||||
session.add(cycle)
|
||||
await session.flush()
|
||||
return cycle.id
|
||||
|
||||
|
||||
def _curiosity(character_id: str, cycle_id: str, **overrides) -> CuriosityQuestion:
|
||||
base = {
|
||||
"character_id": character_id,
|
||||
"cycle_id": cycle_id,
|
||||
"question": "q",
|
||||
"source": "memory_gap",
|
||||
"related_entities_json": "[]",
|
||||
"expected_value": 0.5,
|
||||
"urgency": 0.5,
|
||||
"risk_level": "L2",
|
||||
}
|
||||
base.update(overrides)
|
||||
return CuriosityQuestion(**base)
|
||||
|
||||
|
||||
def _subgoal(
|
||||
character_id: str, cycle_id: str, curiosity_id: str, **overrides
|
||||
) -> ExploratorySubgoal:
|
||||
base = {
|
||||
"character_id": character_id,
|
||||
"cycle_id": cycle_id,
|
||||
"curiosity_question_id": curiosity_id,
|
||||
"title": "t",
|
||||
"description": "d",
|
||||
"expected_information_gain": 0.6,
|
||||
"interruption_cost": 0.3,
|
||||
"risk_level": "L2",
|
||||
"status": "candidate",
|
||||
}
|
||||
base.update(overrides)
|
||||
return ExploratorySubgoal(**base)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_curiosity_add_get_list() -> None:
|
||||
async with AsyncSessionLocal() as session:
|
||||
character = await get_active_character_model(session)
|
||||
cycle_id = await _seed_cycle(session, character.id)
|
||||
curios = _curiosity(character.id, cycle_id, question="为何频繁提到项目X")
|
||||
await drive_repo.add_curiosities(session, [curios])
|
||||
await drive_repo.add_curiosities(
|
||||
session, [_curiosity(character.id, cycle_id, source="world_uncertainty")]
|
||||
)
|
||||
await session.commit()
|
||||
cid = curios.id
|
||||
|
||||
async with AsyncSessionLocal() as session:
|
||||
fetched = await drive_repo.get_curiosity(session, cid)
|
||||
all_items, total = await drive_repo.list_curiosities(session, character.id)
|
||||
gap, gap_total = await drive_repo.list_curiosities(
|
||||
session, character.id, source="memory_gap"
|
||||
)
|
||||
assert fetched is not None
|
||||
assert fetched.question == "为何频繁提到项目X"
|
||||
assert total == 2
|
||||
assert gap_total == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_subgoal_add_get_list() -> None:
|
||||
async with AsyncSessionLocal() as session:
|
||||
character = await get_active_character_model(session)
|
||||
cycle_id = await _seed_cycle(session, character.id)
|
||||
curios = _curiosity(character.id, cycle_id)
|
||||
await drive_repo.add_curiosities(session, [curios])
|
||||
await session.flush()
|
||||
curiosity_id = curios.id
|
||||
sub = _subgoal(character.id, cycle_id, curiosity_id, title="询问项目目标")
|
||||
await drive_repo.add_subgoals(session, [sub])
|
||||
await drive_repo.add_subgoals(
|
||||
session, [_subgoal(character.id, cycle_id, curiosity_id, status="approved")]
|
||||
)
|
||||
await session.commit()
|
||||
sid = sub.id
|
||||
|
||||
async with AsyncSessionLocal() as session:
|
||||
fetched = await drive_repo.get_subgoal(session, sid)
|
||||
_, total = await drive_repo.list_subgoals(session, character.id)
|
||||
cand, cand_total = await drive_repo.list_subgoals(session, character.id, status="candidate")
|
||||
assert fetched is not None
|
||||
assert fetched.title == "询问项目目标"
|
||||
assert fetched.curiosity_question_id == curiosity_id
|
||||
assert total == 2
|
||||
assert cand_total == 1
|
||||
@@ -1,100 +0,0 @@
|
||||
"""演化候选数据访问测试。"""
|
||||
|
||||
import pytest
|
||||
|
||||
from app.db.session import AsyncSessionLocal
|
||||
from app.models.big_cycle import BigCycle
|
||||
from app.models.evolution import EvolutionCandidate
|
||||
from app.repositories import evolution as evolution_repo
|
||||
from app.repositories.json_utils import dumps
|
||||
from app.services.characters import get_active_character_model
|
||||
|
||||
|
||||
async def _seed_cycle(session, character_id: str) -> str:
|
||||
cycle = BigCycle(
|
||||
character_id=character_id,
|
||||
trigger="test",
|
||||
status="completed",
|
||||
memory_count_at_trigger=20,
|
||||
)
|
||||
session.add(cycle)
|
||||
await session.flush()
|
||||
return cycle.id
|
||||
|
||||
|
||||
def _make_candidate(character_id: str, cycle_id: str, **overrides) -> EvolutionCandidate:
|
||||
base = {
|
||||
"character_id": character_id,
|
||||
"cycle_id": cycle_id,
|
||||
"type": "personality",
|
||||
"source": "big_cycle",
|
||||
"level": "L4",
|
||||
"scope": "character_scope",
|
||||
"title": "t",
|
||||
"proposal": "p",
|
||||
"delta_json": dumps({}),
|
||||
"evidence_ids_json": "[]",
|
||||
"confidence": 0.5,
|
||||
"benefit_score": 0.5,
|
||||
"risk_score": 0.5,
|
||||
"drift_score": 0.0,
|
||||
"auto_apply_allowed": False,
|
||||
"status": "pending",
|
||||
}
|
||||
base.update(overrides)
|
||||
return EvolutionCandidate(**base)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_and_get_candidate() -> None:
|
||||
async with AsyncSessionLocal() as session:
|
||||
character = await get_active_character_model(session)
|
||||
cycle_id = await _seed_cycle(session, character.id)
|
||||
candidate = _make_candidate(character.id, cycle_id, title="身份调整")
|
||||
await evolution_repo.add_candidates(session, [candidate])
|
||||
await session.commit()
|
||||
cid = candidate.id
|
||||
|
||||
async with AsyncSessionLocal() as session:
|
||||
fetched = await evolution_repo.get_candidate(session, cid)
|
||||
assert fetched is not None
|
||||
assert fetched.title == "身份调整"
|
||||
assert fetched.status == "pending"
|
||||
assert fetched.source == "big_cycle"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_candidates_with_filters_and_paging() -> None:
|
||||
async with AsyncSessionLocal() as session:
|
||||
character = await get_active_character_model(session)
|
||||
cycle_id = await _seed_cycle(session, character.id)
|
||||
await evolution_repo.add_candidates(
|
||||
session,
|
||||
[
|
||||
_make_candidate(character.id, cycle_id, type="personality", status="pending"),
|
||||
_make_candidate(character.id, cycle_id, type="procedural", status="applied"),
|
||||
_make_candidate(character.id, cycle_id, type="procedural", status="pending"),
|
||||
],
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
async with AsyncSessionLocal() as session:
|
||||
all_items, total = await evolution_repo.list_candidates(session, character.id)
|
||||
assert total == 3
|
||||
assert len(all_items) == 3
|
||||
|
||||
pending, pending_total = await evolution_repo.list_candidates(
|
||||
session, character.id, status="pending"
|
||||
)
|
||||
assert pending_total == 2
|
||||
assert len(pending) == 2
|
||||
|
||||
procedural, proc_total = await evolution_repo.list_candidates(
|
||||
session, character.id, candidate_type="procedural"
|
||||
)
|
||||
assert proc_total == 2
|
||||
|
||||
page1, _ = await evolution_repo.list_candidates(session, character.id, page=1, page_size=2)
|
||||
page2, _ = await evolution_repo.list_candidates(session, character.id, page=2, page_size=2)
|
||||
assert len(page1) == 2
|
||||
assert len(page2) == 1
|
||||
Reference in new issue
Block a user