Files
agent-zero/tests/test_dev_path_resolution.py
linkliti ae25d3ecef fix(paths): resolve /a0 paths inside nested dev checkouts
A dev checkout nested under /a0 produced /a0-prefixed real paths that fix_dev_path stripped unconditionally and that time travel re-prefixed with the base dir, so workspace paths doubled into /a0/a0/usr/... and time travel reported missing workspaces or refused operations outside the selected scope. fix_dev_path now leaves paths that already live inside the base dir untouched, time travel resolves in-checkout display paths directly, and canonical workspace display paths are posix-normalized so the /a0 root keeps its stable workspace id. Because canonical display paths are now logical /a0 paths instead of physical nested checkout paths, workspace ids derived from them change once for dev instances nested under /a0, so their existing shadow repos are re-initialized in a new location and the old directories stay on disk unreachable; production instances whose base dir is /a0 keep their ids, and the time travel plugin DOX records that one-time change.

Validation: pytest tests/test_time_travel.py tests/test_dev_path_resolution.py (21 passed); full suite in a nested dev checkout fails 9, passes 3058, skips 7, down from 32 and 3029 at the previous commit, with the time travel and commands path cases now green; removing the nested-checkout guard, the separator normalization, or the canonical path change each fails its matching new case.
2026-10-31 13:33:09 +03:00

67 lines
2.3 KiB
Python

import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from helpers import files, runtime
from plugins._time_travel.helpers import time_travel
NESTED_BASE = "/a0/usr/projects/nested"
def test_fix_dev_path_keeps_paths_inside_a_nested_checkout(monkeypatch):
monkeypatch.setattr(files, "_base_dir", NESTED_BASE)
monkeypatch.setattr(runtime, "is_development", lambda: True)
inside = f"{NESTED_BASE}/usr/workdir"
assert files.fix_dev_path(inside) == inside
assert files.fix_dev_path("/a0/usr/workdir") == inside
def test_fix_dev_path_leaves_paths_alone_outside_development(monkeypatch):
monkeypatch.setattr(files, "_base_dir", NESTED_BASE)
monkeypatch.setattr(runtime, "is_development", lambda: False)
assert files.fix_dev_path("/a0/usr/workdir") == "/a0/usr/workdir"
def test_canonical_workspace_display_path_normalizes_root():
assert time_travel.canonical_workspace_display_path("/a0") == "/a0"
assert (
time_travel.canonical_workspace_display_path("/a0/usr/workdir")
== "/a0/usr/workdir"
)
def test_canonical_workspace_display_path_uses_logical_paths_in_nested_checkout(monkeypatch):
monkeypatch.setattr(files, "_base_dir", NESTED_BASE)
assert time_travel.canonical_workspace_display_path("/a0") == "/a0"
assert (
time_travel.canonical_workspace_display_path(f"{NESTED_BASE}/usr/workdir")
== "/a0/usr/workdir"
)
assert time_travel.workspace_id_for(f"{NESTED_BASE}/usr/workdir") == time_travel.workspace_id_for(
"/a0/usr/workdir"
)
def test_canonical_workspace_display_path_uses_posix_separators(monkeypatch):
# Windows relpath yields backslash components, so normalize_a0_path can return /a0/usr\workdir
monkeypatch.setattr(files, "normalize_a0_path", lambda path: "/a0/usr\\workdir")
assert time_travel.canonical_workspace_display_path("/a0") == "/a0/usr/workdir"
def test_real_path_for_display_keeps_paths_inside_a_nested_checkout(monkeypatch):
monkeypatch.setattr(files, "_base_dir", NESTED_BASE)
assert time_travel.real_path_for_display(f"{NESTED_BASE}/usr/workdir") == Path(
NESTED_BASE, "usr/workdir"
)
assert time_travel.real_path_for_display("/a0/usr/workdir") == Path(
NESTED_BASE, "usr/workdir"
)