Navegador

navegador / tests / test_config.py
Source Blame History 177 lines
b663b12… lmata 1 """Tests for navegador.config — get_store() env var resolution and init_project()."""
b663b12… lmata 2
b663b12… lmata 3 import tempfile
b663b12… lmata 4 from pathlib import Path
b663b12… lmata 5 from unittest.mock import MagicMock, patch
b663b12… lmata 6
b663b12… lmata 7
b663b12… lmata 8 class TestGetStore:
b663b12… lmata 9 def test_explicit_path_returns_sqlite(self):
b663b12… lmata 10 with patch("navegador.graph.GraphStore") as mock_gs:
b663b12… lmata 11 mock_gs.sqlite.return_value = MagicMock()
b663b12… lmata 12 from navegador.config import get_store
b663b12… lmata 13
b663b12… lmata 14 get_store("/tmp/test.db")
b663b12… lmata 15 mock_gs.sqlite.assert_called_once_with("/tmp/test.db")
b663b12… lmata 16
b663b12… lmata 17 def test_redis_url_env_returns_redis(self, monkeypatch):
b663b12… lmata 18 monkeypatch.setenv("NAVEGADOR_REDIS_URL", "redis://localhost:6379")
b663b12… lmata 19 monkeypatch.delenv("NAVEGADOR_DB", raising=False)
b663b12… lmata 20 with patch("navegador.graph.GraphStore") as mock_gs:
b663b12… lmata 21 mock_gs.redis.return_value = MagicMock()
b663b12… lmata 22 # Re-import to pick up env changes
b663b12… lmata 23 import importlib
b663b12… lmata 24
b663b12… lmata 25 import navegador.config as cfg
b663b12… lmata 26 importlib.reload(cfg)
b663b12… lmata 27 cfg.get_store()
b663b12… lmata 28 mock_gs.redis.assert_called_once_with("redis://localhost:6379")
b663b12… lmata 29
b663b12… lmata 30 def test_db_env_returns_sqlite(self, monkeypatch):
b663b12… lmata 31 monkeypatch.delenv("NAVEGADOR_REDIS_URL", raising=False)
b663b12… lmata 32 monkeypatch.setenv("NAVEGADOR_DB", "/tmp/custom.db")
b663b12… lmata 33 with patch("navegador.graph.GraphStore") as mock_gs:
b663b12… lmata 34 mock_gs.sqlite.return_value = MagicMock()
b663b12… lmata 35 import importlib
b663b12… lmata 36
b663b12… lmata 37 import navegador.config as cfg
b663b12… lmata 38 importlib.reload(cfg)
b663b12… lmata 39 cfg.get_store()
b663b12… lmata 40 mock_gs.sqlite.assert_called_once_with("/tmp/custom.db")
b663b12… lmata 41
b663b12… lmata 42 def test_default_sqlite_path(self, monkeypatch):
b663b12… lmata 43 monkeypatch.delenv("NAVEGADOR_REDIS_URL", raising=False)
b663b12… lmata 44 monkeypatch.delenv("NAVEGADOR_DB", raising=False)
b663b12… lmata 45 with patch("navegador.graph.GraphStore") as mock_gs:
b663b12… lmata 46 mock_gs.sqlite.return_value = MagicMock()
b663b12… lmata 47 import importlib
b663b12… lmata 48
b663b12… lmata 49 import navegador.config as cfg
b663b12… lmata 50 importlib.reload(cfg)
b663b12… lmata 51 cfg.get_store()
b663b12… lmata 52 mock_gs.sqlite.assert_called_once_with(".navegador/graph.db")
b663b12… lmata 53
b663b12… lmata 54 def test_redis_takes_precedence_over_db_env(self, monkeypatch):
b663b12… lmata 55 monkeypatch.setenv("NAVEGADOR_REDIS_URL", "redis://myhost:6379")
b663b12… lmata 56 monkeypatch.setenv("NAVEGADOR_DB", "/tmp/other.db")
b663b12… lmata 57 with patch("navegador.graph.GraphStore") as mock_gs:
b663b12… lmata 58 mock_gs.redis.return_value = MagicMock()
b663b12… lmata 59 import importlib
b663b12… lmata 60
b663b12… lmata 61 import navegador.config as cfg
b663b12… lmata 62 importlib.reload(cfg)
b663b12… lmata 63 cfg.get_store()
b663b12… lmata 64 mock_gs.redis.assert_called_once_with("redis://myhost:6379")
b663b12… lmata 65 mock_gs.sqlite.assert_not_called()
b663b12… lmata 66
b663b12… lmata 67
b663b12… lmata 68 class TestInitProject:
b663b12… lmata 69 def test_creates_navegador_dir(self):
b663b12… lmata 70 with tempfile.TemporaryDirectory() as tmpdir:
b663b12… lmata 71 from navegador.config import init_project
b663b12… lmata 72 nav_dir = init_project(tmpdir)
b663b12… lmata 73 assert nav_dir.exists()
b663b12… lmata 74 assert nav_dir.name == ".navegador"
b663b12… lmata 75
b663b12… lmata 76 def test_creates_env_example(self):
b663b12… lmata 77 with tempfile.TemporaryDirectory() as tmpdir:
b663b12… lmata 78 from navegador.config import init_project
b663b12… lmata 79 nav_dir = init_project(tmpdir)
b663b12… lmata 80 env_example = nav_dir / ".env.example"
b663b12… lmata 81 assert env_example.exists()
b663b12… lmata 82 content = env_example.read_text()
b663b12… lmata 83 assert "NAVEGADOR_DB" in content
b663b12… lmata 84 assert "NAVEGADOR_REDIS_URL" in content
b663b12… lmata 85
b663b12… lmata 86 def test_does_not_overwrite_existing_env_example(self):
b663b12… lmata 87 with tempfile.TemporaryDirectory() as tmpdir:
b663b12… lmata 88 from navegador.config import init_project
b663b12… lmata 89 nav_dir = Path(tmpdir) / ".navegador"
b663b12… lmata 90 nav_dir.mkdir()
b663b12… lmata 91 env_example = nav_dir / ".env.example"
b663b12… lmata 92 env_example.write_text("custom content")
b663b12… lmata 93 init_project(tmpdir)
b663b12… lmata 94 assert env_example.read_text() == "custom content"
b663b12… lmata 95
b663b12… lmata 96 def test_creates_gitignore_if_missing(self):
b663b12… lmata 97 with tempfile.TemporaryDirectory() as tmpdir:
b663b12… lmata 98 from navegador.config import init_project
b663b12… lmata 99 init_project(tmpdir)
b663b12… lmata 100 gitignore = Path(tmpdir) / ".gitignore"
b663b12… lmata 101 assert gitignore.exists()
b663b12… lmata 102 assert ".navegador/" in gitignore.read_text()
b663b12… lmata 103
b663b12… lmata 104 def test_appends_to_existing_gitignore(self):
b663b12… lmata 105 with tempfile.TemporaryDirectory() as tmpdir:
b663b12… lmata 106 gitignore = Path(tmpdir) / ".gitignore"
b663b12… lmata 107 gitignore.write_text("*.pyc\n__pycache__/\n")
b663b12… lmata 108 from navegador.config import init_project
b663b12… lmata 109 init_project(tmpdir)
b663b12… lmata 110 content = gitignore.read_text()
b663b12… lmata 111 assert "*.pyc" in content
b663b12… lmata 112 assert ".navegador/" in content
b663b12… lmata 113
b663b12… lmata 114 def test_does_not_duplicate_gitignore_entry(self):
b663b12… lmata 115 with tempfile.TemporaryDirectory() as tmpdir:
b663b12… lmata 116 gitignore = Path(tmpdir) / ".gitignore"
b663b12… lmata 117 gitignore.write_text(".navegador/\n")
b663b12… lmata 118 from navegador.config import init_project
b663b12… lmata 119 init_project(tmpdir)
b663b12… lmata 120 content = gitignore.read_text()
b663b12… lmata 121 assert content.count(".navegador/") == 1
b663b12… lmata 122
b663b12… lmata 123 def test_returns_nav_dir_path(self):
b663b12… lmata 124 with tempfile.TemporaryDirectory() as tmpdir:
b663b12… lmata 125 from navegador.config import init_project
b663b12… lmata 126 result = init_project(tmpdir)
b663b12… lmata 127 assert isinstance(result, Path)
b663b12… lmata 128 assert result == Path(tmpdir).resolve() / ".navegador"
c4536b2… lmata 129
c4536b2… lmata 130 def test_creates_config_toml(self):
c4536b2… lmata 131 with tempfile.TemporaryDirectory() as tmpdir:
c4536b2… lmata 132 from navegador.config import init_project
c4536b2… lmata 133 nav_dir = init_project(tmpdir)
c4536b2… lmata 134 config = nav_dir / "config.toml"
c4536b2… lmata 135 assert config.exists()
c4536b2… lmata 136 content = config.read_text()
c4536b2… lmata 137 assert "[storage]" in content
c4536b2… lmata 138 assert "[llm]" in content
c4536b2… lmata 139 assert "[cluster]" in content
c4536b2… lmata 140
c4536b2… lmata 141 def test_config_toml_sqlite_defaults(self):
c4536b2… lmata 142 with tempfile.TemporaryDirectory() as tmpdir:
c4536b2… lmata 143 from navegador.config import init_project
c4536b2… lmata 144 nav_dir = init_project(tmpdir)
c4536b2… lmata 145 content = (nav_dir / "config.toml").read_text()
c4536b2… lmata 146 assert 'backend = "sqlite"' in content
c4536b2… lmata 147 assert "db_path" in content
c4536b2… lmata 148
c4536b2… lmata 149 def test_config_toml_redis_mode(self):
c4536b2… lmata 150 with tempfile.TemporaryDirectory() as tmpdir:
c4536b2… lmata 151 from navegador.config import init_project
c4536b2… lmata 152 nav_dir = init_project(tmpdir, storage="redis", redis_url="redis://host:6379")
c4536b2… lmata 153 content = (nav_dir / "config.toml").read_text()
c4536b2… lmata 154 assert 'backend = "redis"' in content
c4536b2… lmata 155 assert 'redis_url = "redis://host:6379"' in content
c4536b2… lmata 156
c4536b2… lmata 157 def test_config_toml_llm_settings(self):
c4536b2… lmata 158 with tempfile.TemporaryDirectory() as tmpdir:
c4536b2… lmata 159 from navegador.config import init_project
c4536b2… lmata 160 nav_dir = init_project(tmpdir, llm_provider="anthropic", llm_model="claude-sonnet-4-6")
c4536b2… lmata 161 content = (nav_dir / "config.toml").read_text()
c4536b2… lmata 162 assert 'provider = "anthropic"' in content
c4536b2… lmata 163 assert 'model = "claude-sonnet-4-6"' in content
c4536b2… lmata 164
c4536b2… lmata 165 def test_config_toml_cluster_enabled(self):
c4536b2… lmata 166 with tempfile.TemporaryDirectory() as tmpdir:
c4536b2… lmata 167 from navegador.config import init_project
c4536b2… lmata 168 nav_dir = init_project(tmpdir, cluster=True)
c4536b2… lmata 169 content = (nav_dir / "config.toml").read_text()
c4536b2… lmata 170 assert "enabled = true" in content
c4536b2… lmata 171
c4536b2… lmata 172 def test_config_toml_cluster_disabled_by_default(self):
c4536b2… lmata 173 with tempfile.TemporaryDirectory() as tmpdir:
c4536b2… lmata 174 from navegador.config import init_project
c4536b2… lmata 175 nav_dir = init_project(tmpdir)
c4536b2… lmata 176 content = (nav_dir / "config.toml").read_text()
c4536b2… lmata 177 assert "enabled = false" in content

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button