fix: normalize file paths in DocReader cache for cross-platform compatibility

Resolves Windows test failure where short path format (RUNNER~1) didn't match
long path format (runneradmin) in cache lookups. Also fixes macOS symlink
issues (/var vs /private/var).

Changes:
- Use path.resolve() for cache keys in DocReader._read_file
- Update test to use resolved paths for assertion

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
YonghaoZhao722
2026-05-06 14:02:35 +08:00
parent 0ee3d989a4
commit dad0148950
2 changed files with 4 additions and 3 deletions

View File

@@ -113,7 +113,7 @@ class DocReader:
return result
def _read_file(self, path: Path) -> list[str]:
key = str(path)
key = str(path.resolve())
if key in self._cache:
return self._cache[key]

View File

@@ -349,13 +349,14 @@ Connection pooling is configured in src/db/pool.py.
def test_cache(self):
from kaiwu.knowledge.doc_reader import DocReader
from pathlib import Path
with tempfile.TemporaryDirectory() as d:
with open(os.path.join(d, "doc.md"), "w", encoding="utf-8") as f:
f.write("This is a test document with enough content to be a paragraph.\n")
reader = DocReader(d)
reader.find_relevant("test")
# Second call should use cache
assert str(os.path.join(d, "doc.md")) in reader._cache
# Second call should use cache (use resolved path for comparison)
assert str(Path(d, "doc.md").resolve()) in reader._cache
# ── PatternMd.count_similar_failures ───────────────────────