diff --git a/reme/steps/index/reindex.py b/reme/steps/index/reindex.py index 6ba44655..82a569f3 100644 --- a/reme/steps/index/reindex.py +++ b/reme/steps/index/reindex.py @@ -4,6 +4,16 @@ from ..base_step import BaseStep from ...components import R +def _render_reindex(details: dict) -> str: + """Render the store's reindex report as one readable summary line.""" + scope = str(details.get("scope") or "all") + counts = ", ".join( + f"{name}={entry.get('indexed', 0)}" for name, entry in details.items() if isinstance(entry, dict) + ) + summary = counts or f"{details.get('indexed', 0)} indexed" + return f"Reindexed scope={scope}: {summary}" + + @R.register("reindex_step") class ReindexStep(BaseStep): """Rebuild BM25, embeddings, and/or tags without scanning workspace files.""" @@ -13,7 +23,7 @@ class ReindexStep(BaseStep): scope = str(self.context.get("scope", "all")) details = await self.file_store.reindex(scope) - self.context.response.answer = details + self.context.response.answer = _render_reindex(details) self.context.response.metadata.update(details) self.context.response.metadata["scope"] = scope return self.context.response diff --git a/tests/unit/test_reindex.py b/tests/unit/test_reindex.py index 64bd1a43..b29b9e8f 100644 --- a/tests/unit/test_reindex.py +++ b/tests/unit/test_reindex.py @@ -23,17 +23,18 @@ async def test_reindex_step_delegates_scope(scope): store.reindex.assert_awaited_once_with(scope) store.clear.assert_not_called() assert response.metadata == {"indexed": 3, "scope": scope} + assert response.answer == f"Reindexed scope={scope}: 3 indexed" @pytest.mark.asyncio async def test_reindex_step_delegates_all_once(): - """The step delegates the composite scope exactly once.""" + """The step delegates the composite scope once; the answer summarizes it.""" store = LocalFileStore(name="test_reindex_all", embedding_store="") details = { "scope": "all", - "bm25": {"scope": "bm25", "indexed": 3}, - "embedding": {"scope": "embedding", "indexed": 3}, - "tag": {"scope": "tag", "indexed": 3}, + "bm25": {"scope": "bm25", "indexed": 7}, + "embedding": {"scope": "embedding", "indexed": 5}, + "tag": {"scope": "tag", "indexed": 2}, } store.reindex = AsyncMock(return_value=details) @@ -41,6 +42,7 @@ async def test_reindex_step_delegates_all_once(): store.reindex.assert_awaited_once_with("all") assert response.metadata == details + assert response.answer == "Reindexed scope=all: bm25=7, embedding=5, tag=2" def test_reindex_job_schema_exposes_tag_scope():