Files
life-echo/api/tests/test_memory_consistency_rules.py
Kevin 71fbd39e32 feat(api)!: memory single chain — async MemoryService, strict eval closure
Route all memory ingest/retrieve/enrichment/compaction through async MemoryService.
Remove legacy sync memory implementations (ingest/retrieve/compaction); Celery and
memoir Phase2 call asyncio.run into MemoryService-backed helpers.

Memoir Phase1 batch ingest uses MemoryService.ingest_transcripts_batch; drop chapters.
evidence_bundle_json mirror (Alembic 0015). Evaluation uses snapshot/link-only bundles;
raise EvidenceClosureMissing instead of partial/fallback lineage tiers.

Split memoir state into NarrativeCoverageState and InterviewControlState; delete the
_interview_meta_store adapter layer. Remove rolling-query and recent-fact fallback
settings from config and evidence assembly.

Update judges, docs, tests, and PlaygroundPage alignment.

Made-with: Cursor
2026-04-30 14:11:50 +08:00

62 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Memory 检索:无 recent fallbackcompaction 后事实 stale。"""
from __future__ import annotations
from unittest.mock import AsyncMock, MagicMock
import pytest
from app.features.memory import repo as memory_repo
@pytest.mark.asyncio
async def test_search_facts_async_does_not_use_recent_fallback(
monkeypatch: pytest.MonkeyPatch,
) -> None:
calls: list[bool] = []
async def boom(*_a, **_k):
calls.append(True)
raise AssertionError("get_facts_for_user should not run")
monkeypatch.setattr(memory_repo, "get_facts_for_user", boom)
mock_session = MagicMock()
result = MagicMock()
result.unique.return_value.scalars.return_value.all.return_value = []
mock_session.execute = AsyncMock(return_value=result)
out = await memory_repo.search_facts_for_user_async(
mock_session, "user-1", "no_such_subject_xyz", 5
)
assert out == []
assert calls == []
@pytest.mark.asyncio
async def test_search_facts_async_empty_query_returns_empty_without_fallback(
monkeypatch: pytest.MonkeyPatch,
) -> None:
calls: list[bool] = []
async def boom(*_a, **_k):
calls.append(True)
raise AssertionError("get_facts_for_user should not run")
monkeypatch.setattr(memory_repo, "get_facts_for_user", boom)
mock_session = MagicMock()
out = await memory_repo.search_facts_for_user_async(mock_session, "user-1", "", 5)
assert out == []
assert calls == []
@pytest.mark.asyncio
async def test_mark_facts_stale_for_excluded_chunk_returns_rowcount() -> None:
session = MagicMock()
session.execute = AsyncMock(return_value=MagicMock(rowcount=3))
n = await memory_repo.mark_facts_stale_for_excluded_chunk(
session, user_id="u1", chunk_id="chunk-9"
)
assert n == 3