Files
planning-with-files/tests/test_path_fix.py
T
OthmanAdi 9aee747eb0 fix: session catchup after /clear — path sanitization + content injection (#106)
Two root causes found:

1. Path sanitization bug: On Windows, Git Bash passes /c/Users/... but
   Claude Code stores sessions under C--Users-... The script converted
   to -c-Users-... which never matched. Added normalize_path() that
   converts Git Bash paths to Windows paths before sanitizing.

2. Hook was advisory, not actionable: UserPromptSubmit hook only said
   "read task_plan.md" — after /clear the agent has no context and may
   ignore text advice. Now the hook dumps actual content: first 50 lines
   of task_plan.md + last 20 lines of progress.md. The agent gets the
   plan state injected directly, no tool calls needed.

Also fixed: UTF-8 encoding for session file parsing on Windows (cp1252
default caused UnicodeDecodeError on non-ASCII content).

Changes synced to all IDE variants via sync-ide-folders.py.
2026-03-20 09:35:41 +01:00

60 lines
1.7 KiB
Python

"""Test the path sanitization fix for session-catchup.py"""
import os
import sys
from pathlib import Path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'skills', 'planning-with-files', 'scripts'))
# Re-implement the fix here for testing (avoids import issues)
def normalize_path(project_path):
p = project_path
# Git Bash / MSYS2: /c/Users/... -> C:/Users/...
if len(p) >= 3 and p[0] == '/' and p[2] == '/':
p = p[1].upper() + ':' + p[2:]
try:
resolved = str(Path(p).resolve())
if os.name == 'nt' or os.sep == '\\':
p = resolved
except (OSError, ValueError):
pass
return p
def sanitize(project_path):
normalized = normalize_path(project_path)
sanitized = normalized.replace('\\', '-').replace('/', '-').replace(':', '-')
sanitized = sanitized.replace('_', '-')
if sanitized.startswith('-'):
sanitized = sanitized[1:]
return sanitized
expected = "C--Users-oasrvadmin-Documents-planning-with-files-repo"
tests = {
"Git Bash": "/c/Users/oasrvadmin/Documents/planning-with-files-repo",
"Forward slash": "C:/Users/oasrvadmin/Documents/planning-with-files-repo",
}
all_pass = True
for label, path in tests.items():
result = sanitize(path)
claude_dir = Path.home() / '.claude' / 'projects' / result
match = result == expected
exists = claude_dir.exists()
print(f"[{label}]")
print(f" Input: {path}")
print(f" Result: {result}")
print(f" Expected: {expected}")
print(f" Match: {match}")
print(f" Dir exists: {exists}")
print()
if not match:
all_pass = False
if all_pass:
print("ALL TESTS PASSED")
else:
print("SOME TESTS FAILED")
sys.exit(1)