A pageindex_cloud doc removes only local artifacts; the cloud is never contacted even when a pageindex.db happens to exist.
(tmp_path)
| 1284 | |
| 1285 | |
| 1286 | def test_remove_cloud_doc_never_touches_pageindex(tmp_path): |
| 1287 | """A pageindex_cloud doc removes only local artifacts; the cloud is |
| 1288 | never contacted even when a pageindex.db happens to exist.""" |
| 1289 | from unittest.mock import patch |
| 1290 | |
| 1291 | from click.testing import CliRunner |
| 1292 | |
| 1293 | from openkb.cli import cli |
| 1294 | from openkb.state import HashRegistry |
| 1295 | |
| 1296 | # Minimal KB |
| 1297 | (tmp_path / "raw").mkdir() |
| 1298 | for sub in ("sources/images", "summaries", "concepts", "entities", "reports"): |
| 1299 | (tmp_path / "wiki" / sub).mkdir(parents=True) |
| 1300 | openkb_dir = tmp_path / ".openkb" |
| 1301 | openkb_dir.mkdir() |
| 1302 | (openkb_dir / "config.yaml").write_text("model: gpt-4o-mini\n") |
| 1303 | # A stray pageindex.db to prove the cloud path is gated by type, not just |
| 1304 | # by the DB's absence. |
| 1305 | (openkb_dir / "pageindex.db").write_bytes(b"") |
| 1306 | (tmp_path / "wiki" / "index.md").write_text("# Index\n") |
| 1307 | |
| 1308 | # Cloud artifacts + registry entry |
| 1309 | (tmp_path / "wiki" / "summaries" / "cloud-doc.md").write_text("---\n---\n# s\n") |
| 1310 | (tmp_path / "wiki" / "sources" / "cloud-doc.json").write_text("[]") |
| 1311 | registry = HashRegistry(openkb_dir / "hashes.json") |
| 1312 | registry.add( |
| 1313 | "synthhash", |
| 1314 | { |
| 1315 | "name": "Cloud Paper.pdf", |
| 1316 | "doc_name": "cloud-doc", |
| 1317 | "type": "pageindex_cloud", |
| 1318 | "origin": "cloud", |
| 1319 | "path": "pageindex-cloud:cloud-1", |
| 1320 | "source_path": "wiki/sources/cloud-doc.json", |
| 1321 | "doc_id": "cloud-1", |
| 1322 | }, |
| 1323 | ) |
| 1324 | |
| 1325 | runner = CliRunner() |
| 1326 | with ( |
| 1327 | patch("openkb.cli._find_kb_dir", return_value=tmp_path), |
| 1328 | patch("pageindex.PageIndexClient") as mock_client, |
| 1329 | ): |
| 1330 | result = runner.invoke(cli, ["remove", "cloud-doc", "--yes"]) |
| 1331 | |
| 1332 | assert result.exit_code == 0, result.output |
| 1333 | # The cloud client must never be constructed. |
| 1334 | mock_client.assert_not_called() |
| 1335 | # Local artifacts are gone and the registry entry is removed. |
| 1336 | assert not (tmp_path / "wiki" / "summaries" / "cloud-doc.md").exists() |
| 1337 | assert not (tmp_path / "wiki" / "sources" / "cloud-doc.json").exists() |
| 1338 | assert HashRegistry(openkb_dir / "hashes.json").get("synthhash") is None |
nothing calls this directly
no test coverage detected