|
| 1 | +"""Tests for LuxeConfig.cache_dir() resolution + dispatch wiring.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from luxe_cli.registry import LuxeConfig |
| 10 | + |
| 11 | + |
| 12 | +def _cfg(**overrides) -> LuxeConfig: |
| 13 | + base = dict(agents=[]) |
| 14 | + base.update(overrides) |
| 15 | + return LuxeConfig(**base) |
| 16 | + |
| 17 | + |
| 18 | +def test_cache_dir_default_is_local_cache_under_cwd(tmp_path, monkeypatch): |
| 19 | + monkeypatch.chdir(tmp_path) |
| 20 | + cfg = _cfg() |
| 21 | + p = cfg.cache_dir() |
| 22 | + assert p == tmp_path / "local-cache" |
| 23 | + assert p.is_dir() |
| 24 | + |
| 25 | + |
| 26 | +def test_cache_dir_honors_absolute_path(tmp_path): |
| 27 | + target = tmp_path / "elsewhere" |
| 28 | + cfg = _cfg(local_cache_dir=str(target)) |
| 29 | + p = cfg.cache_dir() |
| 30 | + assert p == target |
| 31 | + assert p.is_dir() |
| 32 | + |
| 33 | + |
| 34 | +def test_cache_dir_expands_tilde(tmp_path, monkeypatch): |
| 35 | + monkeypatch.setenv("HOME", str(tmp_path)) |
| 36 | + cfg = _cfg(local_cache_dir="~/my-cache") |
| 37 | + p = cfg.cache_dir() |
| 38 | + assert p == tmp_path / "my-cache" |
| 39 | + assert p.is_dir() |
| 40 | + |
| 41 | + |
| 42 | +def test_cache_dir_creates_missing_dir(tmp_path): |
| 43 | + target = tmp_path / "fresh" / "nested" |
| 44 | + cfg = _cfg(local_cache_dir=str(target)) |
| 45 | + assert not target.exists() |
| 46 | + cfg.cache_dir() |
| 47 | + assert target.is_dir() |
| 48 | + |
| 49 | + |
| 50 | +def test_real_agents_yaml_resolves_local_cache(tmp_path, monkeypatch): |
| 51 | + """The shipped config defaults to local-cache/, not cwd.""" |
| 52 | + monkeypatch.chdir(tmp_path) |
| 53 | + from luxe_cli.registry import load_config |
| 54 | + |
| 55 | + cfg = load_config() |
| 56 | + p = cfg.cache_dir() |
| 57 | + assert p.name == "local-cache" |
| 58 | + assert p.parent == tmp_path |
0 commit comments