Implements the review comment on #2: > I would like to give names for remotes ## Summary Adds a `remotes=[{"name": ..., "url": ...}, ...]` constructor to `GitClone` so the config author controls how each URL maps to a git remote. The existing `url=str` / `url=[str]` shorthand is kept as backward-compatible (positional list still maps to `origin`, `repo1`, `repo2`, ...), so PR #2's `test_git_clone_multiple_urls` continues to pass. ## Changes - **`backend/steps/git.py`** — `GitClone.__init__` now accepts either `url=` or `remotes=`. With `remotes=`, every entry must carry a non-empty unique `name` and `url`; duplicates and missing fields raise `ValueError`. The constructor rejects passing both or neither. `self.remotes` becomes the source of truth; `self.urls` is a derived list (kept for any introspection). `CheckoutMerged.find_desired_commits` falls back to the configured primary remote instead of the hardcoded `'origin'` when a branch key has no remote prefix, so configs that don't name a remote `origin` still work. - **`backend/configs/brencher.py`, `brencher2.py`** — switch from positional list to named remotes `github`, `gitea_admin`, `gitea_hermes`. - **`tests/test_git_integration.py`** — adds `test_git_clone_named_remotes` (asserts the user-chosen names appear verbatim and `origin`/`repo1` do not leak) and `test_git_clone_remotes_validation` (covers every rejection path: empty list, missing/empty name, missing/empty url, duplicate name, both-kwargs, no-kwargs). ## Diff vs #2 ``` backend/configs/brencher.py | 8 ++--- backend/configs/brencher2.py | 8 ++--- backend/steps/git.py | 76 +++++++++++++++++++++++++++++++++++++++------- tests/test_git_integration.py | 75 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 20 deletions(-) ``` Targets `admin/multiple_remotes` so this lands on top of #2. After #2 merges, this is a clean follow-up; if #2 is reworked, this branch will need a rebase. ## Verification - `python3 -m py_compile` on all 4 changed files: clean. - AST-driven call-shape check: every `GitClone(...)` in both configs uses the new `remotes=` kwarg with exactly `{github, gitea_admin, gitea_hermes}`; no positional-list leftover in configs. - Executed the new `__init__` in isolation against a stubbed `super()` and exercised 12 cases: 3 OK shapes (url=str, url=[..], remotes=[valid]) and 9 rejection shapes (empty list, missing/empty name, missing/empty url, duplicate name, both-kwargs, no-kwargs, non-dict entry). All 12 produced the asserted `ValueError`/`TypeError` with the expected message substring. - Could not run `pytest` in this sandbox (PyPI is blocked by the proxy and no `pytest`/`gitpython` is pre-installed). The two new tests and PR #2's existing test should be run in a real env before merge. --------- Co-authored-by: hermes <hermes@rudolf.keenetic.link> Co-authored-by: rudolf <rudolfss13@gmail.com> Reviewed-on: http://192.168.1.96/admin/brencher/pulls/3 Reviewed-by: admin <rudolfss13@gmail.com> Co-authored-by: hermes <rudolfss13+hermes@gmail.com>
Integration Tests for git.py
This directory contains integration tests for the CheckoutMerged and GitUnmerge classes from backend/steps/git.py.
Overview
The integration tests simulate real git operations in isolated temporary directories to ensure the git merge and unmerge functionality works correctly in various scenarios without affecting the host environment.
Test Structure
The tests are organized into two files:
test_git_integration.py- Main integration tests for CheckoutMerged and GitUnmergetest_remote_repo.py- Helper classes and utilities for creating test repositories and mock objects
Helper Classes
The test_remote_repo.py file provides:
RemoteRepoHelper- Manages creation and cleanup of temporary test repositoriesMockGitClone- Mock GitClone object for testingMockDockerSwarmCheck- Mock DockerSwarmCheck object with configurable version strings
Test Coverage
CheckoutMerged Class Tests
- test_checkout_merged_two_branches - Tests merging two branches successfully
- test_checkout_merged_three_branches - Tests merging three branches successfully
- test_checkout_merged_fast_forward - Tests merging with fast-forward (linear history)
- test_checkout_merged_conflicting_branches - Tests that conflicting branches fail gracefully
- test_checkout_merged_existing_auto_branch - Tests that existing auto branches are reused
- test_checkout_merged_empty_branches - Tests that empty branch lists are rejected
Combined CheckoutMerged and GitUnmerge Tests
- test_checkout_merged_and_unmerge_valid_version - Tests merging branches and then extracting branch information from version string
GitUnmerge-Specific Tests
- test_git_unmerge_invalid_version - Tests handling of invalid version formats
- test_git_unmerge_nonhead_commit - Tests behavior when version corresponds to non-HEAD commit in a branch ( expected to fail)
Test Improvements
Recent refactoring improvements:
- Centralized repository setup code in
RemoteRepoHelperclass - Single instances of
MockGitCloneandMockDockerSwarmCheckdefined in helper file - Enhanced assertions that check actual field values (not just "is not None")
- Merged GitUnmerge tests with CheckoutMerged tests where they share scenarios
Running the Tests
Option 1: Run in Docker (Recommended - Isolated Environment)
The tests can be run inside a Docker container to ensure complete isolation from the host system:
./run_integration_tests.sh
This script will:
- Build a Docker image with all necessary dependencies
- Run the integration tests inside a container
- Clean up after completion
Option 2: Run Locally
If you prefer to run tests locally (requires Python 3.12.3+ and git):
# Install dependencies
pip install -r requirements.txt
# Run tests
python -m pytest tests/test_git_integration.py -v
Option 3: Run Specific Tests
To run a specific test:
python -m pytest tests/test_git_integration.py::TestGitIntegration::test_checkout_merged_two_branches -v
Test Scenarios Simulated
Merge Scenarios
- 2 branches merge: Creates two divergent branches from a common ancestor and merges them
- 3 branches merge: Creates three divergent branches from a common ancestor and merges them
- Fast-forward merge: Tests merging when one branch is directly ahead of another
- Conflicting branches: Creates branches that modify the same file differently, expecting merge conflicts
Repository Simulation
Each test:
- Creates a temporary "remote" repository
- Creates a temporary "local" clone
- Simulates various branch scenarios
- Executes the merge/unmerge operations
- Verifies the results
- Cleans up all temporary files
CI Integration
These tests are integrated into the CI pipeline through the python-package.yml workflow, which runs pytest on every
push and pull request.
Dependencies
- Python 3.12.3+
- pytest
- gitpython
- git (system package)
All Python dependencies are specified in requirements.txt.