MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / test_cache_portable_across_roots

Function test_cache_portable_across_roots

tests/test_cache.py:325–354  ·  view source on GitHub ↗

End-to-end portability: a cache entry written at one root can be consumed at a different absolute root because the file is content-hashed AND its embedded source_file is stored relative.

(tmp_path)

Source from the content-addressed store, hash-verified

323
324
325def test_cache_portable_across_roots(tmp_path):
326 """End-to-end portability: a cache entry written at one root can be
327 consumed at a different absolute root because the file is content-hashed
328 AND its embedded source_file is stored relative."""
329 import json
330 import shutil
331 from graphify.cache import save_cached, load_cached, file_hash, cache_dir
332
333 repo_a = tmp_path / "repo_a"
334 repo_a.mkdir()
335 (repo_a / "src").mkdir()
336 src_a = repo_a / "src" / "foo.py"
337 src_a.write_text("def x(): pass\n")
338 save_cached(src_a, {
339 "nodes": [{"id": "n1", "source_file": str(src_a.resolve())}],
340 "edges": [],
341 }, root=repo_a, kind="ast")
342
343 # Copy corpus + cache to a second location with a different absolute prefix.
344 repo_b = tmp_path / "repo_b"
345 shutil.copytree(repo_a, repo_b)
346
347 src_b = repo_b / "src" / "foo.py"
348 loaded = load_cached(src_b, root=repo_b, kind="ast")
349 assert loaded is not None, (
350 "cache must port across absolute prefixes (content hash + relative source_file)"
351 )
352 # Source path re-anchored to the new root, not the old one.
353 assert loaded["nodes"][0]["source_file"] == str(src_b.resolve())
354 assert not str(repo_a) in loaded["nodes"][0]["source_file"]
355
356
357# --- AST cache id portability (#2257) ---------------------------------------

Callers

nothing calls this directly

Calls 3

save_cachedFunction · 0.90
load_cachedFunction · 0.90
resolveMethod · 0.45

Tested by

no test coverage detected