-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconftest.py
More file actions
97 lines (78 loc) Β· 3.15 KB
/
Copy pathconftest.py
File metadata and controls
97 lines (78 loc) Β· 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""Test fixtures for FAVA Trail."""
import os
import shutil
import subprocess
from pathlib import Path
import pytest
import pytest_asyncio
# Skip all tests if jj is not installed
jj_bin = shutil.which("jj") or str(Path.home() / ".local" / "bin" / "jj")
if not Path(jj_bin).exists():
pytest.skip("jj binary not found β install via: fava-trails install-jj", allow_module_level=True)
@pytest.fixture(autouse=True)
def reset_config_store(monkeypatch, tmp_path):
"""Isolate machine config and reset ConfigStore around every test."""
from fava_trails.config import ConfigStore
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "xdg-config"))
ConfigStore.reset()
yield
ConfigStore.reset()
@pytest.fixture
def tmp_fava_home(tmp_path):
"""Create a temporary FAVA_TRAILS_DATA_REPO with monorepo initialized at root."""
home = tmp_path / "fava-trails-data"
home.mkdir()
(home / "trails").mkdir()
os.environ["FAVA_TRAILS_DATA_REPO"] = str(home)
# Init monorepo at root (not per-trail)
subprocess.run([jj_bin, "git", "init", "--colocate"], cwd=str(home), check=True)
subprocess.run(
[jj_bin, "config", "set", "--repo", "user.name", "FAVA Trail Test"],
cwd=str(home), check=True,
)
subprocess.run(
[jj_bin, "config", "set", "--repo", "user.email", "test@fava-trail.dev"],
cwd=str(home), check=True,
)
yield home
os.environ.pop("FAVA_TRAILS_DATA_REPO", None)
@pytest_asyncio.fixture
async def jj_backend(tmp_fava_home):
"""Create a JjBackend with monorepo at root, trail as subdirectory."""
from fava_trails.vcs.jj_backend import JjBackend
trail_path = tmp_fava_home / "trails" / "test-jj"
trail_path.mkdir(parents=True)
backend = JjBackend(repo_root=tmp_fava_home, trail_path=trail_path)
await backend.init_trail() # Creates dirs only, no repo init
return backend
@pytest_asyncio.fixture
async def trail_manager(tmp_fava_home):
"""Create and initialize a TrailManager with a test trail."""
from fava_trails.trail import TrailManager
from fava_trails.vcs.jj_backend import JjBackend
trail_path = tmp_fava_home / "trails" / "test"
backend = JjBackend(repo_root=tmp_fava_home, trail_path=trail_path)
manager = TrailManager("test", vcs=backend)
await manager.init()
return manager
@pytest_asyncio.fixture
async def nested_trail_managers(tmp_fava_home):
"""Create multiple nested TrailManagers for hierarchical scoping tests.
Returns dict with keys: 'company', 'team', 'project', 'epic'
mapped to TrailManagers for mw, mw/eng, mw/eng/fava-trail, mw/eng/fava-trail/auth-epic.
"""
from fava_trails.trail import TrailManager
from fava_trails.vcs.jj_backend import JjBackend
managers = {}
for name, key in [
("mw", "company"),
("mw/eng", "team"),
("mw/eng/fava-trail", "project"),
("mw/eng/fava-trail/auth-epic", "epic"),
]:
trail_path = tmp_fava_home / "trails" / name
backend = JjBackend(repo_root=tmp_fava_home, trail_path=trail_path)
manager = TrailManager(name, vcs=backend)
await manager.init()
managers[key] = manager
return managers