test: delete slow, timing-based and redundant tests

This commit is contained in:
imSp4rky
2026-12-05 15:20:05 -07:00
parent 783a2fc185
commit 3a0a74e694
292 changed files with 153 additions and 15174 deletions
-72
View File
@@ -50,29 +50,6 @@ def test_parse_spec(spec, url, branch, dest):
assert service_repo.parse_spec(spec) == (url, branch, dest)
def test_slug_distinguishes_hosts():
# same owner/repo on different hosts must not share a clone dir
a = service_repo.parse_spec("https://github.com/owner/repo")[2]
b = service_repo.parse_spec("https://gitlab.com/owner/repo")[2]
assert a != b
def test_repos_base_uses_configured_local_dir(monkeypatch, tmp_path):
from unshackle.core.config import config
monkeypatch.setattr(config.directories, "services", ["owner/repo", str(tmp_path / "svc")], raising=False)
assert service_repo.repos_base() == (tmp_path / "svc" / "_repos")
def test_is_stale(tmp_path):
stamp = tmp_path / "stamp"
assert service_repo.is_stale(stamp, ttl=10) is True # missing → stale
stamp.write_text(str(time.time()))
assert service_repo.is_stale(stamp, ttl=10) is False # fresh
stamp.write_text(str(time.time() - 100))
assert service_repo.is_stale(stamp, ttl=10) is True # old
def test_clone_invokes_git(monkeypatch, tmp_path):
monkeypatch.setattr(service_repo.binaries, "Git", "git")
monkeypatch.setattr(service_repo, "repos_base", lambda: tmp_path)
@@ -142,22 +119,6 @@ def test_is_dirty_clean(monkeypatch):
assert service_repo.is_dirty(Path("/x")) is False
def test_is_dirty_ignores_untracked_files(monkeypatch):
# status must ask git to skip untracked files so importing services (__pycache__) isn't "dirty"
seen = []
monkeypatch.setattr(service_repo.binaries, "Git", "git")
def run(args, **kw):
seen.append(args)
out = b"0" if args[3] == "rev-list" else b""
return subprocess.CompletedProcess(args, 0, out, b"")
monkeypatch.setattr(service_repo.subprocess, "run", run)
service_repo.is_dirty(Path("/x"))
status_args = next(a for a in seen if a[3] == "status")
assert "--untracked-files=no" in status_args
def test_auto_refresh_refuses_dirty_clone(monkeypatch, tmp_path):
"""Auto path (force=False): a stale clone with local edits raises instead of clobbering."""
dest = tmp_path / "github.com__a__b"
@@ -238,13 +199,6 @@ def test_refresh_reports_discarded_local_edits(monkeypatch, tmp_path):
assert changes == ["!EXAMPLE"]
def test_changed_services_up_to_date(monkeypatch):
monkeypatch.setattr(service_repo.binaries, "Git", "git")
# same HEAD before/after → no diff computed at all
monkeypatch.setattr(service_repo.subprocess, "run", lambda *a, **k: pytest.fail("no git diff when HEAD unchanged"))
assert service_repo.changed_services(Path("/x"), "same", "same") == []
@pytest.fixture
def bytecode_clone(tmp_path):
"""A clone of a repo that commits a ``.pyc``, with that ``.pyc`` rewritten as an import does."""
@@ -303,29 +257,3 @@ def test_untracked_bytecode_does_not_block_pull(bytecode_clone, tmp_path):
service_repo.pull(dest, tmp_path / "stamp")
assert (dest / "EXAMPLE" / "__init__.py").read_text() == "X = 2\n"
assert (dest / "OTHER" / "__init__.cpython-314-x86_64-linux-gnu.so").read_bytes() == b"compiled"
@pytest.mark.parametrize("order", [["a", "b"], ["b", "a"]])
def test_collision_first_source_wins(tmp_path, order):
"""Discovery dedupes by tag honoring list order: the FIRST source to define a tag wins,
whether it's a local dir or a repo clone; later duplicates are shadowed."""
dirs = {}
for name in ("a", "b"):
svc = tmp_path / name / "EXAMPLE"
svc.mkdir(parents=True)
(svc / "__init__.py").touch()
dirs[name] = tmp_path / name
seen: dict = {}
shadowed: list = []
for name in order: # services.py preserves config order
for path in dirs[name].glob("*/__init__.py"):
tag = path.parent.stem
if tag in seen:
shadowed.append((tag, path, seen[tag]))
else:
seen[tag] = path
winner, loser = order[0], order[1]
assert seen["EXAMPLE"] == dirs[winner] / "EXAMPLE" / "__init__.py"
assert shadowed and shadowed[0][1] == dirs[loser] / "EXAMPLE" / "__init__.py"