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

Function test_hash_registry_remove_by_hash

tests/test_remove.py:224–253  ·  view source on GitHub ↗

Issue #58 / Bug 1: `remove_by_hash` is the hash-keyed sibling of `remove_by_doc_name`. It exists so callers that already have the file_hash in hand (e.g. the CLI after `_resolve_doc_identifier`) don't need to round-trip through the `doc_name` slug — that round trip is what silently n

(tmp_path)

Source from the content-addressed store, hash-verified

222
223
224def test_hash_registry_remove_by_hash(tmp_path):
225 """Issue #58 / Bug 1: `remove_by_hash` is the hash-keyed sibling of
226 `remove_by_doc_name`. It exists so callers that already have the
227 file_hash in hand (e.g. the CLI after `_resolve_doc_identifier`)
228 don't need to round-trip through the `doc_name` slug — that round
229 trip is what silently no-ops for legacy registry entries lacking a
230 `doc_name` key (ingested before commit c504e26).
231 """
232 path = tmp_path / "hashes.json"
233 path.write_text(
234 json.dumps(
235 {
236 "h_modern": {"name": "a.pdf", "doc_name": "a-h_modern", "type": "short"},
237 "h_legacy": {"name": "b.pdf", "type": "short"}, # no doc_name
238 }
239 )
240 )
241
242 reg = HashRegistry(path)
243
244 # Modern entry: removable by hash.
245 assert reg.remove_by_hash("h_modern") is True
246 assert reg.remove_by_hash("h_modern") is False # idempotent
247 # Legacy entry (no doc_name): removable by hash too — that's the point.
248 assert reg.remove_by_hash("h_legacy") is True
249 # Unknown hash: returns False, doesn't raise.
250 assert reg.remove_by_hash("never-existed") is False
251
252 assert reg.all_entries() == {}
253 assert json.loads(path.read_text()) == {}
254
255
256# ---------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 3

remove_by_hashMethod · 0.95
all_entriesMethod · 0.95
HashRegistryClass · 0.90

Tested by

no test coverage detected