MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / test_full_pipeline

Method test_full_pipeline

tests/test_compiler.py:1151–1221  ·  view source on GitHub ↗
(self, tmp_path)

Source from the content-addressed store, hash-verified

1149class TestCompileShortDoc:
1150 @pytest.mark.asyncio
1151 async def test_full_pipeline(self, tmp_path):
1152 # Setup KB structure
1153 wiki = tmp_path / "wiki"
1154 (wiki / "sources").mkdir(parents=True)
1155 (wiki / "summaries").mkdir(parents=True)
1156 (wiki / "concepts").mkdir(parents=True)
1157 (wiki / "index.md").write_text(
1158 "# Index\n\n## Documents\n\n## Concepts\n\n## Explorations\n",
1159 encoding="utf-8",
1160 )
1161 source_path = wiki / "sources" / "test-doc.md"
1162 source_path.write_text("# Test Doc\n\nSome content about transformers.", encoding="utf-8")
1163 (tmp_path / ".openkb").mkdir()
1164 (tmp_path / "raw").mkdir()
1165 (tmp_path / "raw" / "test-doc.pdf").write_bytes(b"fake")
1166
1167 summary_response = json.dumps(
1168 {
1169 "description": "Discusses transformers",
1170 "content": "# Summary\n\nThis document discusses transformers.",
1171 }
1172 )
1173 concepts_list_response = json.dumps(
1174 {
1175 "create": [{"name": "transformer", "title": "Transformer"}],
1176 "update": [],
1177 "related": [],
1178 }
1179 )
1180 # The rewrite step (third sync call) returns raw Markdown.
1181 summary_rewrite_response = "# Summary\n\nThis document discusses [[concepts/transformer]]."
1182 concept_page_response = json.dumps(
1183 {
1184 "brief": "NN architecture using self-attention",
1185 "content": "# Transformer\n\nA neural network architecture.",
1186 }
1187 )
1188
1189 with patch("openkb.agent.compiler.litellm") as mock_litellm:
1190 mock_litellm.completion = MagicMock(
1191 side_effect=_mock_completion(
1192 [
1193 summary_response,
1194 concepts_list_response,
1195 summary_rewrite_response,
1196 ]
1197 )
1198 )
1199 mock_litellm.acompletion = AsyncMock(
1200 side_effect=_mock_acompletion([concept_page_response])
1201 )
1202 await compile_short_doc("test-doc", source_path, tmp_path, "gpt-4o-mini")
1203
1204 # Verify summary written
1205 summary_path = wiki / "summaries" / "test-doc.md"
1206 assert summary_path.exists()
1207 summary_text = summary_path.read_text()
1208 assert 'full_text: "sources/test-doc.md"' in summary_text

Callers

nothing calls this directly

Calls 3

compile_short_docFunction · 0.90
_mock_completionFunction · 0.85
_mock_acompletionFunction · 0.85

Tested by

no test coverage detected