From dad0148950495c49227163b954af890e7790b05a Mon Sep 17 00:00:00 2001 From: YonghaoZhao722 <118432288+YonghaoZhao722@users.noreply.github.com> Date: Wed, 6 May 2026 14:02:35 +0800 Subject: [PATCH] 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) --- kaiwu/knowledge/doc_reader.py | 2 +- kaiwu/tests/test_p1_features.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/kaiwu/knowledge/doc_reader.py b/kaiwu/knowledge/doc_reader.py index 7f85014..3af4541 100644 --- a/kaiwu/knowledge/doc_reader.py +++ b/kaiwu/knowledge/doc_reader.py @@ -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] diff --git a/kaiwu/tests/test_p1_features.py b/kaiwu/tests/test_p1_features.py index b142cf8..73a93b2 100644 --- a/kaiwu/tests/test_p1_features.py +++ b/kaiwu/tests/test_p1_features.py @@ -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 ───────────────────────