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

Method test_add_short_doc_runs_compiler

tests/test_add_command.py:243–292  ·  view source on GitHub ↗
(self, tmp_path)

Source from the content-addressed store, hash-verified

241 mock_arun.assert_not_called()
242
243 def test_add_short_doc_runs_compiler(self, tmp_path):
244 kb_dir = self._setup_kb(tmp_path)
245 doc = tmp_path / "test.md"
246 doc.write_text("# Hello")
247
248 source_path = kb_dir / "wiki" / "sources" / "test.md"
249 source_path.write_text("# Hello converted")
250
251 from openkb.converter import ConvertResult
252
253 mock_result = ConvertResult(
254 raw_path=kb_dir / "raw" / "test.md",
255 source_path=source_path,
256 is_long_doc=False,
257 file_hash="deadbeef00" * 8,
258 doc_name="test",
259 )
260
261 # An edited doc arrives with a new content hash; the stale entry
262 # for the same doc_name must be replaced, leaving exactly ONE entry.
263 from openkb.state import HashRegistry
264
265 HashRegistry(kb_dir / ".openkb" / "hashes.json").add(
266 "stale-old-hash", {"name": "test.md", "doc_name": "test", "type": "md"}
267 )
268
269 compile_calls = []
270
271 async def compile_noop(*args, **kwargs):
272 compile_calls.append((args, kwargs))
273
274 runner = CliRunner()
275 with (
276 patch("openkb.cli._find_kb_dir", return_value=kb_dir),
277 patch("openkb.cli.convert_document", return_value=mock_result),
278 patch("openkb.agent.compiler.compile_short_doc", new=compile_noop),
279 ):
280 result = runner.invoke(cli, ["add", str(doc)])
281 assert len(compile_calls) == 1
282 assert "OK" in result.output
283
284 import json as json_mod
285
286 hashes = json_mod.loads((kb_dir / ".openkb" / "hashes.json").read_text(encoding="utf-8"))
287 meta = hashes[mock_result.file_hash]
288 assert meta["doc_name"] == "test"
289 assert meta["raw_path"] == "raw/test.md"
290 assert meta["source_path"] == "wiki/sources/test.md"
291 assert "path" in meta
292 assert "stale-old-hash" not in hashes
293
294 def test_add_oldest_legacy_entry_converges_to_single_entry(self, tmp_path):
295 """Editing a pre-doc_name-era document must not fork the registry.

Callers

nothing calls this directly

Calls 4

_setup_kbMethod · 0.95
ConvertResultClass · 0.90
HashRegistryClass · 0.90
addMethod · 0.80

Tested by

no test coverage detected