"""EvalTraceService 在 chapter 快照路径返回 dialogue_lineage。""" from __future__ import annotations from types import SimpleNamespace from unittest.mock import MagicMock import pytest from sqlalchemy.ext.asyncio import AsyncSession from app.features.evaluation.eval_trace_service import EvalTraceService from app.features.memoir.chapter_evidence_snapshot import ( EVIDENCE_SNAPSHOT_SCHEMA_VERSION, ) @pytest.mark.asyncio async def test_build_chapter_bundle_dialogue_lineage_from_snapshot() -> None: msg_ln = { "schema_version": 1, "conversation_id": "cv1", "turns": [ {"user_message_id": "um-99", "assistant_message_id": "as-99"}, ], } snap = SimpleNamespace( user_id="u1", chapter_id="ch1", schema_version=EVIDENCE_SNAPSHOT_SCHEMA_VERSION, segment_ids=["s1"], conversation_ids=["cv1"], memory_chunk_ids=["mk1"], memory_fact_ids=[], timeline_event_ids=[], summary_ids=[], notes=[], message_lineage_json=msg_ln, ) chapter = SimpleNamespace( id="ch1", user_id="u1", source_segments=["s1"], current_evidence_snapshot=snap, evidence_bundle_json=None, ) db = MagicMock(spec=AsyncSession) svc = EvalTraceService(db) bundle = await svc.build_chapter_bundle("u1", chapter) assert bundle.dialogue_lineage == msg_ln assert bundle.dialogue_lineage["turns"][0]["user_message_id"] == "um-99"