test_install_script.py
python
sha256:d84c3167ef9c46ab0dc09702b6615966d085fdbfb99c36dbc4c0a1b36d69bd41
fix(install): uninstall.sh describes ~/.muse as the identit…
Opus 5.5
1 day ago
| 1 | """Section 43 — Install Script: 7-layer test suite. |
| 2 | |
| 3 | Covers: |
| 4 | - musehub/api/routes/musehub/install.py::sanitize_musehub_url, |
| 5 | build_sdist_url, generate_install_script, generate_uninstall_script, |
| 6 | GET /install.sh, GET /uninstall.sh |
| 7 | """ |
| 8 | from __future__ import annotations |
| 9 | |
| 10 | import hashlib |
| 11 | import json |
| 12 | import re |
| 13 | import time |
| 14 | from pathlib import Path |
| 15 | |
| 16 | import pytest |
| 17 | |
| 18 | from musehub.api.routes.musehub.install import ( |
| 19 | _SAFE_URL_RE, |
| 20 | build_sdist_url, |
| 21 | generate_install_script, |
| 22 | generate_uninstall_script, |
| 23 | sanitize_musehub_url, |
| 24 | ) |
| 25 | from musehub.config import settings |
| 26 | from musehub.protocol.version import MUSE_VERSION |
| 27 | |
| 28 | #: The release this module's fixture makes active. Selection is by the instance's |
| 29 | #: explicit ``active.json`` pointer (musehub#114 Phase 6); there is no fallback. |
| 30 | ACTIVE_VERSION = "7.6.5rc1" |
| 31 | |
| 32 | |
| 33 | @pytest.fixture(autouse=True) |
| 34 | def _active_release(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> str: |
| 35 | releases = tmp_path / "active-release" |
| 36 | releases.mkdir() |
| 37 | body = f"sdist {ACTIVE_VERSION}".encode() |
| 38 | (releases / f"muse-{ACTIVE_VERSION}.tar.gz").write_bytes(body) |
| 39 | (releases / "active.json").write_text(json.dumps({ |
| 40 | "schema": 1, "environment": "staging", "version": ACTIVE_VERSION, |
| 41 | "sha256": hashlib.sha256(body).hexdigest(), "previous": None, "activated_at": "", |
| 42 | })) |
| 43 | monkeypatch.setattr(settings, "musehub_releases_dir", str(releases)) |
| 44 | return ACTIVE_VERSION |
| 45 | |
| 46 | |
| 47 | # ───────────────────────────────────────────────────────────────────────────── |
| 48 | # LAYER 1 — UNIT |
| 49 | # ───────────────────────────────────────────────────────────────────────────── |
| 50 | |
| 51 | |
| 52 | class TestSanitizeMusehubUrlUnit: |
| 53 | """Unit: sanitize_musehub_url rejects unsafe URLs.""" |
| 54 | |
| 55 | def test_accepts_http_url(self) -> None: |
| 56 | assert sanitize_musehub_url("https://localhost:1337") == "https://localhost:1337" |
| 57 | |
| 58 | def test_accepts_https_url(self) -> None: |
| 59 | assert sanitize_musehub_url("https://musehub.example.com") == "https://musehub.example.com" |
| 60 | |
| 61 | def test_accepts_url_with_path(self) -> None: |
| 62 | result = sanitize_musehub_url("https://hub.example.com/muse") |
| 63 | assert result == "https://hub.example.com/muse" |
| 64 | |
| 65 | def test_strips_trailing_slash(self) -> None: |
| 66 | result = sanitize_musehub_url("https://hub.example.com/") |
| 67 | assert not result.endswith("/") |
| 68 | |
| 69 | def test_rejects_url_with_double_quote(self) -> None: |
| 70 | with pytest.raises(ValueError): |
| 71 | sanitize_musehub_url('https://example.com"evil') |
| 72 | |
| 73 | def test_rejects_url_with_single_quote(self) -> None: |
| 74 | with pytest.raises(ValueError): |
| 75 | sanitize_musehub_url("https://example.com'evil") |
| 76 | |
| 77 | def test_rejects_url_with_backtick(self) -> None: |
| 78 | with pytest.raises(ValueError): |
| 79 | sanitize_musehub_url("https://example.com`id`") |
| 80 | |
| 81 | def test_rejects_url_with_dollar(self) -> None: |
| 82 | with pytest.raises(ValueError): |
| 83 | sanitize_musehub_url("https://example.com$HOME") |
| 84 | |
| 85 | def test_rejects_url_with_semicolon(self) -> None: |
| 86 | with pytest.raises(ValueError): |
| 87 | sanitize_musehub_url("https://example.com;rm -rf /") |
| 88 | |
| 89 | def test_rejects_url_with_newline(self) -> None: |
| 90 | with pytest.raises(ValueError): |
| 91 | sanitize_musehub_url("https://example.com\nevil") |
| 92 | |
| 93 | def test_rejects_non_http_scheme(self) -> None: |
| 94 | with pytest.raises(ValueError): |
| 95 | sanitize_musehub_url("ftp://example.com") |
| 96 | |
| 97 | def test_rejects_empty_string(self) -> None: |
| 98 | with pytest.raises(ValueError): |
| 99 | sanitize_musehub_url("") |
| 100 | |
| 101 | |
| 102 | class TestBuildSdistUrlUnit: |
| 103 | """Unit: build_sdist_url produces correct URLs — no platform/arch needed.""" |
| 104 | |
| 105 | def test_basic_url(self) -> None: |
| 106 | url = build_sdist_url("https://hub.example.com", "1.2.3") |
| 107 | assert url == "https://hub.example.com/releases/muse-1.2.3.tar.gz" |
| 108 | |
| 109 | def test_ends_with_tar_gz(self) -> None: |
| 110 | url = build_sdist_url("https://localhost:1337", "0.1.0") |
| 111 | assert url.endswith(".tar.gz") |
| 112 | |
| 113 | def test_version_embedded(self) -> None: |
| 114 | url = build_sdist_url("http://localhost", "9.9.9") |
| 115 | assert "9.9.9" in url |
| 116 | |
| 117 | def test_under_releases_path(self) -> None: |
| 118 | url = build_sdist_url("https://hub.example.com", "1.0.0") |
| 119 | assert "/releases/" in url |
| 120 | |
| 121 | def test_no_platform_in_url(self) -> None: |
| 122 | url = build_sdist_url("https://hub.example.com", "1.0.0") |
| 123 | for platform in ("linux", "darwin", "arm64", "x86_64"): |
| 124 | assert platform not in url |
| 125 | |
| 126 | |
| 127 | class TestGenerateInstallScriptUnit: |
| 128 | """Unit: generate_install_script content and structure.""" |
| 129 | |
| 130 | def test_starts_with_shebang(self) -> None: |
| 131 | script = generate_install_script("https://localhost:1337") |
| 132 | assert script.startswith("#!/usr/bin/env sh") |
| 133 | |
| 134 | def test_contains_musehub_url(self) -> None: |
| 135 | url = "https://hub.example.com" |
| 136 | script = generate_install_script(url) |
| 137 | assert url in script |
| 138 | |
| 139 | def test_url_is_double_quoted_in_assignment(self) -> None: |
| 140 | url = "https://hub.example.com" |
| 141 | script = generate_install_script(url) |
| 142 | assert f'MUSEHUB_URL="{url}"' in script |
| 143 | |
| 144 | def test_contains_muse_version(self) -> None: |
| 145 | script = generate_install_script("https://localhost:1337") |
| 146 | assert ACTIVE_VERSION in script |
| 147 | |
| 148 | def test_contains_set_euf(self) -> None: |
| 149 | script = generate_install_script("https://localhost:1337") |
| 150 | assert "set -euf" in script |
| 151 | |
| 152 | def test_contains_tar_gz_archive_reference(self) -> None: |
| 153 | script = generate_install_script("https://localhost:1337") |
| 154 | assert ".tar.gz" in script |
| 155 | |
| 156 | def test_requires_python_314(self) -> None: |
| 157 | script = generate_install_script("https://localhost:1337") |
| 158 | assert "3.14" in script |
| 159 | |
| 160 | def test_creates_venv(self) -> None: |
| 161 | script = generate_install_script("https://localhost:1337") |
| 162 | assert "venv" in script |
| 163 | |
| 164 | def test_uses_pip_install(self) -> None: |
| 165 | script = generate_install_script("https://localhost:1337") |
| 166 | assert "pip" in script and "install" in script |
| 167 | |
| 168 | def test_installs_full_profile_by_default(self) -> None: |
| 169 | script = generate_install_script("https://localhost:1337") |
| 170 | assert 'PROFILE="full"' in script |
| 171 | assert 'EXTRAS="all"' in script |
| 172 | |
| 173 | def test_creates_symlink(self) -> None: |
| 174 | script = generate_install_script("https://localhost:1337") |
| 175 | assert "ln -sf" in script |
| 176 | |
| 177 | def test_no_eval_in_script(self) -> None: |
| 178 | script = generate_install_script("https://localhost:1337") |
| 179 | assert "\neval " not in script and " eval " not in script |
| 180 | |
| 181 | def test_raises_for_unsafe_url(self) -> None: |
| 182 | with pytest.raises(ValueError): |
| 183 | generate_install_script('http://evil.com";rm -rf /') |
| 184 | |
| 185 | def test_custom_version_embedded(self) -> None: |
| 186 | script = generate_install_script("https://localhost:1337", version="99.0.0") |
| 187 | assert "99.0.0" in script |
| 188 | |
| 189 | |
| 190 | class TestGenerateUninstallScriptUnit: |
| 191 | """Unit: generate_uninstall_script never removes ~/.muse data.""" |
| 192 | |
| 193 | def test_starts_with_shebang(self) -> None: |
| 194 | script = generate_uninstall_script() |
| 195 | assert script.startswith("#!/usr/bin/env sh") |
| 196 | |
| 197 | def test_contains_set_euf(self) -> None: |
| 198 | script = generate_uninstall_script() |
| 199 | assert "set -euf" in script |
| 200 | |
| 201 | def test_mentions_muse_dir_preserved(self) -> None: |
| 202 | script = generate_uninstall_script() |
| 203 | assert "~/.muse" in script |
| 204 | assert "preserved" in script.lower() or "never" in script.lower() |
| 205 | |
| 206 | def test_does_not_rm_rf_muse_dir(self) -> None: |
| 207 | script = generate_uninstall_script() |
| 208 | for line in script.splitlines(): |
| 209 | stripped = line.strip() |
| 210 | if stripped.startswith("#"): |
| 211 | continue |
| 212 | if re.match(r"^rm\s", stripped) and "~/.muse" in stripped: |
| 213 | pytest.fail(f"Active rm targeting .muse: {stripped!r}") |
| 214 | |
| 215 | def test_removes_symlink_and_venv(self) -> None: |
| 216 | script = generate_uninstall_script() |
| 217 | assert "rm" in script |
| 218 | assert "venv" in script.lower() or "VENV" in script |
| 219 | |
| 220 | |
| 221 | # ───────────────────────────────────────────────────────────────────────────── |
| 222 | # LAYER 2 — INTEGRATION |
| 223 | # ───────────────────────────────────────────────────────────────────────────── |
| 224 | |
| 225 | |
| 226 | class TestInstallScriptIntegration: |
| 227 | """Integration: script functions work together coherently.""" |
| 228 | |
| 229 | def test_install_script_contains_sdist_url_pattern(self) -> None: |
| 230 | base = "https://hub.example.com" |
| 231 | script = generate_install_script(base) |
| 232 | sdist_url = build_sdist_url(base, ACTIVE_VERSION) |
| 233 | # The sdist URL or its components must be constructable from the script's vars |
| 234 | assert base in script |
| 235 | assert ACTIVE_VERSION in script |
| 236 | assert sdist_url.endswith(".tar.gz") |
| 237 | |
| 238 | def test_safe_url_re_pattern_matches_valid_urls(self) -> None: |
| 239 | valid = [ |
| 240 | "https://localhost:1337", |
| 241 | "https://musehub.example.com", |
| 242 | "https://hub.example.com/muse", |
| 243 | "http://192.168.1.1:8080", |
| 244 | ] |
| 245 | for url in valid: |
| 246 | assert _SAFE_URL_RE.match(url), f"Expected {url!r} to be safe" |
| 247 | |
| 248 | def test_safe_url_re_pattern_rejects_metacharacters(self) -> None: |
| 249 | dangerous = [ |
| 250 | "http://evil.com\";rm -rf /", |
| 251 | "http://evil.com`id`", |
| 252 | "http://evil.com$HOME", |
| 253 | "http://evil.com;evil", |
| 254 | "http://evil.com'x", |
| 255 | ] |
| 256 | for url in dangerous: |
| 257 | assert not _SAFE_URL_RE.match(url), f"Expected {url!r} to be rejected" |
| 258 | |
| 259 | def test_generate_install_script_version_matches_active_pointer_default(self) -> None: |
| 260 | script = generate_install_script("http://localhost") |
| 261 | assert f'MUSE_VERSION="{ACTIVE_VERSION}"' in script |
| 262 | |
| 263 | def test_uninstall_does_not_reference_musehub_url(self) -> None: |
| 264 | """Uninstall script is URL-independent — no MUSEHUB_URL substitution needed.""" |
| 265 | script = generate_uninstall_script() |
| 266 | assert "MUSEHUB_URL" not in script |
| 267 | |
| 268 | def test_build_sdist_url_with_current_version(self) -> None: |
| 269 | url = build_sdist_url("https://staging.musehub.ai", MUSE_VERSION) |
| 270 | assert MUSE_VERSION in url |
| 271 | assert url.endswith(".tar.gz") |
| 272 | assert "linux" not in url |
| 273 | assert "darwin" not in url |
| 274 | |
| 275 | |
| 276 | # ───────────────────────────────────────────────────────────────────────────── |
| 277 | # LAYER 3 — E2E |
| 278 | # ───────────────────────────────────────────────────────────────────────────── |
| 279 | |
| 280 | |
| 281 | class TestInstallScriptE2E: |
| 282 | """E2E: /install.sh and /uninstall.sh endpoints via async test client.""" |
| 283 | |
| 284 | async def test_get_install_sh_returns_200(self, client: AsyncClient) -> None: |
| 285 | r = await client.get("/install.sh") |
| 286 | assert r.status_code == 200 |
| 287 | |
| 288 | async def test_get_install_sh_content_type_is_shell(self, client: AsyncClient) -> None: |
| 289 | r = await client.get("/install.sh") |
| 290 | ct = r.headers.get("content-type", "") |
| 291 | assert "sh" in ct or "plain" in ct |
| 292 | |
| 293 | async def test_get_install_sh_starts_with_shebang(self, client: AsyncClient) -> None: |
| 294 | r = await client.get("/install.sh") |
| 295 | assert r.text.startswith("#!/usr/bin/env sh") |
| 296 | |
| 297 | async def test_get_install_sh_contains_set_euf(self, client: AsyncClient) -> None: |
| 298 | r = await client.get("/install.sh") |
| 299 | assert "set -euf" in r.text |
| 300 | |
| 301 | async def test_get_install_sh_contains_muse_version(self, client: AsyncClient) -> None: |
| 302 | r = await client.get("/install.sh") |
| 303 | assert ACTIVE_VERSION in r.text |
| 304 | |
| 305 | async def test_get_install_sh_contains_tar_gz(self, client: AsyncClient) -> None: |
| 306 | r = await client.get("/install.sh") |
| 307 | assert ".tar.gz" in r.text |
| 308 | |
| 309 | async def test_get_install_sh_contains_venv(self, client: AsyncClient) -> None: |
| 310 | r = await client.get("/install.sh") |
| 311 | assert "venv" in r.text |
| 312 | |
| 313 | async def test_get_install_sh_no_auth_required(self, client: AsyncClient) -> None: |
| 314 | r = await client.get("/install.sh") |
| 315 | assert r.status_code == 200 |
| 316 | |
| 317 | async def test_get_uninstall_sh_returns_200(self, client: AsyncClient) -> None: |
| 318 | r = await client.get("/uninstall.sh") |
| 319 | assert r.status_code == 200 |
| 320 | |
| 321 | async def test_get_uninstall_sh_content_type_is_shell(self, client: AsyncClient) -> None: |
| 322 | r = await client.get("/uninstall.sh") |
| 323 | ct = r.headers.get("content-type", "") |
| 324 | assert "sh" in ct or "plain" in ct |
| 325 | |
| 326 | async def test_get_uninstall_sh_starts_with_shebang(self, client: AsyncClient) -> None: |
| 327 | r = await client.get("/uninstall.sh") |
| 328 | assert r.text.startswith("#!/usr/bin/env sh") |
| 329 | |
| 330 | async def test_get_uninstall_sh_no_auth_required(self, client: AsyncClient) -> None: |
| 331 | r = await client.get("/uninstall.sh") |
| 332 | assert r.status_code == 200 |
| 333 | |
| 334 | async def test_get_uninstall_sh_does_not_rm_muse_dir(self, client: AsyncClient) -> None: |
| 335 | r = await client.get("/uninstall.sh") |
| 336 | for line in r.text.splitlines(): |
| 337 | stripped = line.strip() |
| 338 | if stripped.startswith("#"): |
| 339 | continue |
| 340 | if re.match(r"^rm\s", stripped) and "~/.muse" in stripped: |
| 341 | pytest.fail(f"Uninstall script removes .muse: {stripped!r}") |
| 342 | |
| 343 | async def test_get_uninstall_sh_mentions_muse_dir_preserved(self, client: AsyncClient) -> None: |
| 344 | r = await client.get("/uninstall.sh") |
| 345 | text = r.text.lower() |
| 346 | assert "~/.muse" in text |
| 347 | assert "preserved" in text or "never" in text |
| 348 | |
| 349 | |
| 350 | # ───────────────────────────────────────────────────────────────────────────── |
| 351 | # LAYER 4 — STRESS |
| 352 | # ───────────────────────────────────────────────────────────────────────────── |
| 353 | |
| 354 | |
| 355 | class TestInstallScriptStress: |
| 356 | """Stress: repeated generation and URL validation at volume.""" |
| 357 | |
| 358 | def test_generate_install_script_1000_times_identical(self) -> None: |
| 359 | url = "https://hub.example.com" |
| 360 | first = generate_install_script(url) |
| 361 | for _ in range(1000): |
| 362 | assert generate_install_script(url) == first |
| 363 | |
| 364 | def test_generate_uninstall_script_1000_times_identical(self) -> None: |
| 365 | first = generate_uninstall_script() |
| 366 | for _ in range(1000): |
| 367 | assert generate_uninstall_script() == first |
| 368 | |
| 369 | def test_sanitize_url_10000_valid_urls(self) -> None: |
| 370 | for i in range(10_000): |
| 371 | url = f"https://hub{i}.example.com" |
| 372 | result = sanitize_musehub_url(url) |
| 373 | assert result == url |
| 374 | |
| 375 | def test_build_sdist_url_1000_times(self) -> None: |
| 376 | for _ in range(1000): |
| 377 | url = build_sdist_url("https://hub.example.com", MUSE_VERSION) |
| 378 | assert url.endswith(".tar.gz") |
| 379 | |
| 380 | async def test_get_install_sh_20_sequential_requests_identical(self, client: AsyncClient) -> None: |
| 381 | first = None |
| 382 | for _ in range(20): |
| 383 | r = await client.get("/install.sh") |
| 384 | assert r.status_code == 200 |
| 385 | if first is None: |
| 386 | first = r.text |
| 387 | assert r.text == first |
| 388 | |
| 389 | |
| 390 | # ───────────────────────────────────────────────────────────────────────────── |
| 391 | # LAYER 5 — DATA INTEGRITY |
| 392 | # ───────────────────────────────────────────────────────────────────────────── |
| 393 | |
| 394 | |
| 395 | class TestInstallScriptDataIntegrity: |
| 396 | """Data Integrity: script content correctness and determinism.""" |
| 397 | |
| 398 | def test_install_script_is_valid_utf8(self) -> None: |
| 399 | script = generate_install_script("https://localhost:1337") |
| 400 | encoded = script.encode("utf-8") |
| 401 | assert encoded.decode("utf-8") == script |
| 402 | |
| 403 | def test_uninstall_script_is_valid_utf8(self) -> None: |
| 404 | script = generate_uninstall_script() |
| 405 | encoded = script.encode("utf-8") |
| 406 | assert encoded.decode("utf-8") == script |
| 407 | |
| 408 | def test_install_script_deterministic_same_url(self) -> None: |
| 409 | url = "https://hub.example.com" |
| 410 | assert generate_install_script(url) == generate_install_script(url) |
| 411 | |
| 412 | def test_install_script_different_for_different_urls(self) -> None: |
| 413 | s1 = generate_install_script("https://hub1.example.com") |
| 414 | s2 = generate_install_script("https://hub2.example.com") |
| 415 | assert s1 != s2 |
| 416 | |
| 417 | def test_sdist_url_unique_per_version(self) -> None: |
| 418 | urls = [build_sdist_url("https://hub.example.com", v) for v in ("1.0.0", "2.0.0", "3.0.0")] |
| 419 | assert len(urls) == len(set(urls)) |
| 420 | |
| 421 | def test_uninstall_script_does_not_change_between_calls(self) -> None: |
| 422 | assert generate_uninstall_script() == generate_uninstall_script() |
| 423 | |
| 424 | def test_install_script_uses_mktemp_for_tmp_dir(self) -> None: |
| 425 | script = generate_install_script("http://localhost") |
| 426 | assert "mktemp" in script |
| 427 | |
| 428 | def test_install_script_cleans_up_tmp_on_exit(self) -> None: |
| 429 | script = generate_install_script("http://localhost") |
| 430 | assert "trap" in script or "cleanup" in script |
| 431 | |
| 432 | def test_install_script_creates_bin_dir_with_mkdir_p(self) -> None: |
| 433 | script = generate_install_script("http://localhost") |
| 434 | assert "mkdir -p" in script |
| 435 | |
| 436 | |
| 437 | # ───────────────────────────────────────────────────────────────────────────── |
| 438 | # LAYER 6 — SECURITY |
| 439 | # ───────────────────────────────────────────────────────────────────────────── |
| 440 | |
| 441 | |
| 442 | class TestInstallScriptSecurity: |
| 443 | """Security: shell injection prevention and uninstall data-preservation guarantee.""" |
| 444 | |
| 445 | @pytest.mark.parametrize("injection", [ |
| 446 | 'https://evil.com"; rm -rf / ; echo "', |
| 447 | "https://evil.com`id`", |
| 448 | "https://evil.com$(id)", |
| 449 | "https://evil.com$HOME", |
| 450 | "https://evil.com; cat /etc/passwd", |
| 451 | "https://evil.com\nrm -rf /", |
| 452 | "https://evil.com' && evil", |
| 453 | ]) |
| 454 | def test_sanitize_rejects_injection_url(self, injection: str) -> None: |
| 455 | with pytest.raises(ValueError): |
| 456 | sanitize_musehub_url(injection) |
| 457 | |
| 458 | @pytest.mark.parametrize("injection", [ |
| 459 | 'https://evil.com"; rm -rf / ; echo "', |
| 460 | "https://evil.com`id`", |
| 461 | ]) |
| 462 | def test_generate_install_raises_for_injection(self, injection: str) -> None: |
| 463 | with pytest.raises(ValueError): |
| 464 | generate_install_script(injection) |
| 465 | |
| 466 | def test_uninstall_script_never_removes_muse_dir(self) -> None: |
| 467 | script = generate_uninstall_script() |
| 468 | for line in script.splitlines(): |
| 469 | stripped = line.strip() |
| 470 | if stripped.startswith("#"): |
| 471 | continue |
| 472 | if re.match(r"^rm\s", stripped) and "~/.muse" in stripped: |
| 473 | pytest.fail(f"Active rm targeting .muse: {stripped!r}") |
| 474 | |
| 475 | def test_install_script_no_eval(self) -> None: |
| 476 | script = generate_install_script("http://localhost") |
| 477 | for line in script.splitlines(): |
| 478 | if line.strip().startswith("#"): |
| 479 | continue |
| 480 | assert not re.match(r"^\s*eval\s", line), f"eval found: {line!r}" |
| 481 | |
| 482 | def test_install_script_no_source_untrusted(self) -> None: |
| 483 | script = generate_install_script("http://localhost") |
| 484 | for line in script.splitlines(): |
| 485 | if line.strip().startswith("#"): |
| 486 | continue |
| 487 | assert not re.search(r"\bsource\s+https?://", line) |
| 488 | assert not re.search(r"^\s*\.\s+https?://", line) |
| 489 | |
| 490 | async def test_endpoints_return_200_not_500(self, client: AsyncClient) -> None: |
| 491 | for path in ("/install.sh", "/uninstall.sh"): |
| 492 | r = await client.get(path) |
| 493 | assert r.status_code == 200, f"{path} returned {r.status_code}" |
| 494 | |
| 495 | async def test_endpoints_no_stack_trace(self, client: AsyncClient) -> None: |
| 496 | for path in ("/install.sh", "/uninstall.sh"): |
| 497 | r = await client.get(path) |
| 498 | assert "Traceback" not in r.text |
| 499 | |
| 500 | def test_install_script_musehub_url_quoted(self) -> None: |
| 501 | url = "https://hub.example.com" |
| 502 | script = generate_install_script(url) |
| 503 | assert f'MUSEHUB_URL="{url}"' in script |
| 504 | |
| 505 | |
| 506 | # ───────────────────────────────────────────────────────────────────────────── |
| 507 | # LAYER 7 — PERFORMANCE |
| 508 | # ───────────────────────────────────────────────────────────────────────────── |
| 509 | |
| 510 | |
| 511 | class TestInstallScriptPerformance: |
| 512 | """Performance: script generation and endpoint latency budgets.""" |
| 513 | |
| 514 | def test_generate_install_script_under_5ms(self) -> None: |
| 515 | url = "https://localhost:1337" |
| 516 | t0 = time.perf_counter() |
| 517 | generate_install_script(url) |
| 518 | elapsed = time.perf_counter() - t0 |
| 519 | assert elapsed < 0.005, f"generate_install_script took {elapsed*1000:.1f}ms" |
| 520 | |
| 521 | def test_generate_uninstall_script_under_1ms(self) -> None: |
| 522 | t0 = time.perf_counter() |
| 523 | generate_uninstall_script() |
| 524 | elapsed = time.perf_counter() - t0 |
| 525 | assert elapsed < 0.001, f"generate_uninstall_script took {elapsed*1000:.1f}ms" |
| 526 | |
| 527 | def test_sanitize_url_under_1ms_per_call(self) -> None: |
| 528 | url = "https://hub.example.com" |
| 529 | t0 = time.perf_counter() |
| 530 | for _ in range(1000): |
| 531 | sanitize_musehub_url(url) |
| 532 | elapsed = time.perf_counter() - t0 |
| 533 | assert elapsed < 0.1, f"1K sanitize_url calls took {elapsed*1000:.1f}ms" |
| 534 | |
| 535 | async def test_get_install_sh_under_100ms(self, client: AsyncClient) -> None: |
| 536 | t0 = time.perf_counter() |
| 537 | r = await client.get("/install.sh") |
| 538 | elapsed = time.perf_counter() - t0 |
| 539 | assert r.status_code == 200 |
| 540 | assert elapsed < 0.1, f"GET /install.sh took {elapsed*1000:.1f}ms" |
| 541 | |
| 542 | async def test_get_uninstall_sh_under_100ms(self, client: AsyncClient) -> None: |
| 543 | t0 = time.perf_counter() |
| 544 | r = await client.get("/uninstall.sh") |
| 545 | elapsed = time.perf_counter() - t0 |
| 546 | assert r.status_code == 200 |
| 547 | assert elapsed < 0.1, f"GET /uninstall.sh took {elapsed*1000:.1f}ms" |
| 548 | |
| 549 | |
| 550 | # ───────────────────────────────────────────────────────────────────────────── |
| 551 | # Phase 2b — profile / manifest contract (script text; behaviour is exercised by |
| 552 | # tests/install_e2e against the real script) |
| 553 | # ───────────────────────────────────────────────────────────────────────────── |
| 554 | |
| 555 | from musehub.api.routes.musehub.install import INSTALLER_REVISION # noqa: E402 |
| 556 | |
| 557 | |
| 558 | class TestInstallerProfileContract: |
| 559 | def script(self) -> str: |
| 560 | return generate_install_script("https://localhost:1337", version="1.2.3") |
| 561 | |
| 562 | def test_revision_is_an_int_embedded_in_the_script(self) -> None: |
| 563 | assert isinstance(INSTALLER_REVISION, int) |
| 564 | assert f"INSTALLER_REVISION={INSTALLER_REVISION}" in self.script() |
| 565 | |
| 566 | def test_revision_constant_matches_template_literal(self) -> None: |
| 567 | m = re.search(r"^INSTALLER_REVISION=(\d+)$", self.script(), re.M) |
| 568 | assert m and int(m.group(1)) == INSTALLER_REVISION |
| 569 | |
| 570 | def test_documents_the_environment_contract(self) -> None: |
| 571 | s = self.script() |
| 572 | for name in ("MUSE_PROFILE", "MUSE_EXTRAS", "MUSE_WHEELHOUSE"): |
| 573 | assert name in s |
| 574 | |
| 575 | def test_manifest_is_written_atomically_after_verification(self) -> None: |
| 576 | s = self.script() |
| 577 | assert s.index("mv -f") > s.index('"$VENV_DIR/bin/muse" --version') |
| 578 | assert s.index("mv -f") > s.index("verify.py\" \"$MUSE_VERSION\"") |
| 579 | assert "$MANIFEST.new" in s |
| 580 | |
| 581 | def test_binary_symlink_comes_after_the_manifest(self) -> None: |
| 582 | s = self.script() |
| 583 | assert s.index("ln -sf") > s.index("mv -f") |
| 584 | |
| 585 | def test_no_secrets_or_tokens_embedded(self) -> None: |
| 586 | s = self.script().lower() |
| 587 | assert "token" not in s and "password" not in s |
File History
9 commits
sha256:d84c3167ef9c46ab0dc09702b6615966d085fdbfb99c36dbc4c0a1b36d69bd41
fix(install): uninstall.sh describes ~/.muse as the identit…
Opus 5.5
1 day ago
sha256:7626f7726b75381c2fc1cc637fc1eff985dc031df13ee8a7c6ce2735e27d5a20
feat(release): select the served muse by an explicit active…
Opus 5.5
minor
⚠
12 days ago
sha256:8d2339e3feaef5da2c7a3d6304444ec8d569fd4faf340cae62c47486d59fe8b6
feat(install): MUSE_PROFILE/MUSE_EXTRAS/MUSE_WHEELHOUSE and…
Opus 5.5
patch
12 days ago
sha256:42b85c455874b92a57e82fafa5bcea5088a00aa5cb41493aadf125cdd9c08fc8
test(install): red e2e + contract tests for profiles, manif…
Opus 5.5
patch
12 days ago
sha256:54c830e4c1c1f64c0c14e0f9c9f222cf66330f6e435d0bbdf878a32f8b6612f6
feat(install): install the full parser profile (muse[all]) …
Opus 5.5
12 days ago
sha256:610bebdf8c345da9ee65454fc6f3b19060ef5fb36e008d675b6d036104deb1c3
chore: fix all param_object typing violations — achieve 0 ratchet
Sonnet 4.6
minor
⚠
201 days ago
sha256:2de7b961dcf6e76b7a3ca92553b19d9375032db88aeb079f0783e88f57c193e2
chore: use https://localhost:1337 throughout docs, source, …
Sonnet 4.6
minor
⚠
207 days ago
sha256:a88854503673dcad22463307411e1cc28e8c62b99ef5c8194ca642f1f99d101b
chore: swap port to 1337 (was 10003)
Sonnet 4.6
minor
⚠
209 days ago
sha256:1023a5ce87c517287e801d82ad4243278310d0420cd8d628b253ebdff5caa80b
refactor(tests): strip _sectionN suffixes from all test filenames
Human
major
⚠
218 days ago