From 8805da33b6a48a609e60b3d8652e52fe8234362d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Helle=C5=9Ben?= Date: Sun, 15 Mar 2026 15:39:15 +0100 Subject: [PATCH] Remove end-to-end test for git backup push --- tests/conftest.py | 19 ++------ tests/test_git_backup.py | 97 ---------------------------------------- 2 files changed, 3 insertions(+), 113 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c7d9170..eab2847 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,9 +6,11 @@ import sys import tempfile from contextlib import suppress from pathlib import Path +from typing import TYPE_CHECKING from typing import Any -import pytest +if TYPE_CHECKING: + import pytest def pytest_addoption(parser: pytest.Parser) -> None: @@ -21,14 +23,6 @@ def pytest_addoption(parser: pytest.Parser) -> None: ) -def pytest_configure(config: pytest.Config) -> None: - """Configure test markers and isolate persistent app state per xdist worker.""" - config.addinivalue_line( - "markers", - "real_git_backup_push: marks tests that push git backup state to a real git repo", - ) - - def pytest_sessionstart(session: pytest.Session) -> None: """Isolate persistent app state per xdist worker to avoid cross-worker test interference.""" worker_id: str = os.environ.get("PYTEST_XDIST_WORKER", "gw0") @@ -64,10 +58,3 @@ def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item """Skip real git-repo push tests unless explicitly requested.""" if config.getoption("--run-real-git-backup-tests"): return - - skip_real_push = pytest.mark.skip( - reason="requires --run-real-git-backup-tests option to run", - ) - for item in items: - if "real_git_backup_push" in item.keywords: - item.add_marker(skip_real_push) diff --git a/tests/test_git_backup.py b/tests/test_git_backup.py index 8275cea..183d178 100644 --- a/tests/test_git_backup.py +++ b/tests/test_git_backup.py @@ -304,103 +304,6 @@ def test_commit_state_change_no_push_when_remote_unset(monkeypatch: pytest.Monke assert not push_calls, "git push should NOT be called when GIT_BACKUP_REMOTE is not set" -@pytest.mark.real_git_backup_push -@SKIP_IF_NO_GIT -def test_commit_state_change_e2e_push_to_bare_repo(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: - """End-to-end test: commit_state_change pushes to a real bare git repository.""" - git_executable: str | None = shutil.which("git") - assert git_executable is not None, "git executable not found" - - # Create a bare remote repository - bare_repo_path: Path = tmp_path / "remote.git" - subprocess.run([git_executable, "init", "--bare", str(bare_repo_path)], check=True, capture_output=True) # noqa: S603 - - # Configure backup with remote pointing to bare repo - backup_path: Path = tmp_path / "backup" - monkeypatch.setenv("GIT_BACKUP_PATH", str(backup_path)) - monkeypatch.setenv("GIT_BACKUP_REMOTE", str(bare_repo_path)) - - # Create mock reader with some state - mock_reader = MagicMock() - feed1 = MagicMock() - feed1.url = "https://example.com/feed.rss" - mock_reader.get_feeds.return_value = [feed1] - - def get_tag_side_effect( - feed_or_key: tuple | str, - tag: str | None = None, - default: str | None = None, - ) -> list[Any] | str | None: - if feed_or_key == (): - return [] - if tag == "webhook": - return "https://discord.com/api/webhooks/123/abc" - return default - - mock_reader.get_tag.side_effect = get_tag_side_effect - - # Perform backup with commit and push - commit_state_change(mock_reader, "Initial backup") - - # Verify commit exists in local backup repo - result: subprocess.CompletedProcess[str] = subprocess.run( # noqa: S603 - [git_executable, "-C", str(backup_path), "log", "--oneline"], - capture_output=True, - text=True, - check=True, - ) - assert "Initial backup" in result.stdout - - # Verify origin remote is configured correctly - result = subprocess.run( # noqa: S603 - [git_executable, "-C", str(backup_path), "remote", "get-url", "origin"], - capture_output=True, - text=True, - check=True, - ) - assert result.stdout.strip() == str(bare_repo_path) - - # Verify commit was pushed to the bare remote - result = subprocess.run( # noqa: S603 - [git_executable, "-C", str(bare_repo_path), "log", "--oneline", "master"], - capture_output=True, - text=True, - check=True, - ) - assert "Initial backup" in result.stdout - - # Verify state.json content in the remote - result = subprocess.run( # noqa: S603 - [git_executable, "-C", str(bare_repo_path), "show", "master:state.json"], - capture_output=True, - text=True, - check=True, - ) - state_data: dict[str, Any] = json.loads(result.stdout) - assert state_data["feeds"][0]["url"] == "https://example.com/feed.rss" - assert state_data["feeds"][0]["webhook"] == "https://discord.com/api/webhooks/123/abc" - - # Perform a second backup to verify subsequent pushes work - feed2 = MagicMock() - feed2.url = "https://another.com/feed.xml" - mock_reader.get_feeds.return_value = [feed1, feed2] - - commit_state_change(mock_reader, "Add second feed") - - # Verify both commits are in the remote - result = subprocess.run( # noqa: S603 - [git_executable, "-C", str(bare_repo_path), "log", "--oneline", "master"], - capture_output=True, - text=True, - check=True, - ) - assert "Initial backup" in result.stdout - assert "Add second feed" in result.stdout - - -# Integration tests for embed-related endpoint backups - - client: TestClient = TestClient(app) test_webhook_name: str = "Test Backup Webhook" test_webhook_url: str = "https://discord.com/api/webhooks/999999999/testbackupwebhook"