(self, tmp_path)
| 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. |
nothing calls this directly
no test coverage detected