Add versioned metric graph authority, owned browser evidence, paginated and all-tab traversal, deterministic sampling policies, and analyst-facing run inspection. Provision the DEV/PREPROD/PROD Superset, Gitea and million-row ClickHouse lab; retain reproducible lifecycle evidence and explicit incomplete-traversal limits.
67 lines
3.3 KiB
Python
67 lines
3.3 KiB
Python
# #region Test.Api.GitLocalRepository [C:3] [TYPE Module] [SEMANTICS test,git,local,api]
|
|
# @BRIEF Check local promotion policy and SSH repository URL matching without TestClient startup.
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
from fastapi import HTTPException
|
|
import pytest
|
|
|
|
from src.api.routes.git import _repo_lifecycle_routes, _repo_routes
|
|
from src.api.routes.git_schemas import PromoteRequest
|
|
|
|
|
|
# #region Test.Api.GitLocalRepository.SshHostMatch [C:2] [TYPE Function]
|
|
# @TEST_INVARIANT SSH repository host must match the configured Git server host.
|
|
def test_ssh_repository_host_match():
|
|
config = "https://git.example.test"
|
|
assert _repo_routes._remote_matches_config("git@git.example.test:team/repo.git", config)
|
|
assert _repo_routes._remote_matches_config("ssh://git@git.example.test/team/repo.git", config)
|
|
assert not _repo_routes._remote_matches_config("git@other.example.test:team/repo.git", config)
|
|
assert not _repo_routes._remote_matches_config("git@git.example.test:bad path", config)
|
|
# #endregion Test.Api.GitLocalRepository.SshHostMatch
|
|
|
|
|
|
# #region Test.Api.GitLocalRepository.DirectPromotion [C:3] [TYPE Function]
|
|
# @TEST_INVARIANT Local direct promotion needs no remote policy exception reason.
|
|
@pytest.mark.asyncio
|
|
async def test_local_direct_promotion_without_reason(monkeypatch):
|
|
from src.api.routes import git as package
|
|
|
|
binding = MagicMock(config_id=None, remote_url=None)
|
|
db = MagicMock()
|
|
db.query.return_value.filter.return_value.first.return_value = binding
|
|
service = MagicMock()
|
|
service.promote_direct_merge = AsyncMock(return_value={"status": "merged"})
|
|
monkeypatch.setattr(package, "_resolve_dashboard_id_from_ref", AsyncMock(return_value=42))
|
|
monkeypatch.setattr(_repo_lifecycle_routes, "get_git_service", lambda: service)
|
|
monkeypatch.setattr(_repo_lifecycle_routes, "_apply_git_identity_from_profile", AsyncMock())
|
|
|
|
response = await _repo_lifecycle_routes.promote_dashboard(
|
|
dashboard_ref="42", payload=PromoteRequest(from_branch="dev", to_branch="preprod", mode="direct"),
|
|
config_manager=object(), db=db, current_user=MagicMock(), _=None,
|
|
)
|
|
assert response.status == "merged"
|
|
assert response.policy_violation is False
|
|
service.promote_direct_merge.assert_awaited_once()
|
|
# #endregion Test.Api.GitLocalRepository.DirectPromotion
|
|
|
|
|
|
# #region Test.Api.GitLocalRepository.RemoteDirectPolicy [C:3] [TYPE Function]
|
|
# @TEST_INVARIANT Remote direct promotion still requires an audit reason.
|
|
@pytest.mark.asyncio
|
|
async def test_remote_direct_promotion_requires_reason(monkeypatch):
|
|
from src.api.routes import git as package
|
|
|
|
binding = MagicMock(config_id="cfg", remote_url="https://git.example.test/team/repo.git")
|
|
db = MagicMock()
|
|
db.query.return_value.filter.return_value.first.return_value = binding
|
|
monkeypatch.setattr(package, "_resolve_dashboard_id_from_ref", AsyncMock(return_value=42))
|
|
with pytest.raises(HTTPException) as caught:
|
|
await _repo_lifecycle_routes.promote_dashboard(
|
|
dashboard_ref="42", payload=PromoteRequest(from_branch="dev", to_branch="preprod", mode="direct"),
|
|
config_manager=object(), db=db, current_user=MagicMock(), _=None,
|
|
)
|
|
assert caught.value.status_code == 400
|
|
# #endregion Test.Api.GitLocalRepository.RemoteDirectPolicy
|
|
|
|
# #endregion Test.Api.GitLocalRepository
|