diff --git a/backend/app.py b/backend/app.py index 608ba14..e560e29 100644 --- a/backend/app.py +++ b/backend/app.py @@ -6,7 +6,7 @@ import time import traceback import types from dataclasses import asdict, replace -from typing import List, Dict, Any, Optional, Tuple +from typing import List, Dict, Any, Optional from typing import TypeVar import socketio as socketio_client @@ -15,7 +15,7 @@ from flask import Flask, send_from_directory from flask.json.provider import DefaultJSONProvider from flask_socketio import SocketIO, emit -from enironment import AbstractStep, Environment, wrap_in_cached +from enironment import Environment, wrap_in_cached from processing import reset_caches from steps.git import GitClone from steps.step import CachingStep @@ -174,9 +174,9 @@ def get_local_envs_to_emit() -> Dict[str, Dict[str, Any]]: }) else: pipeline_state.append({ - "name": r.name, - "status": result, - }) + "name": r.name, + "status": result, + }) except BaseException as e: stack = traceback.format_exception(type(e), e, e.__traceback__) pipeline_state.append({ @@ -198,9 +198,10 @@ def get_global_envs_to_emit() -> Any: common_keys = set(local_envs.keys()) & set(environments_slaves.keys()) if len(common_keys) > 0: socketio.emit('error', {'message': f"Conflict: both master and slave have environment with id {common_keys}"}, - namespace='/ws/errors') + namespace='/ws/errors') return merge_result + def get_local_branches_to_emit() -> Dict[str, Dict[str, List[Any]]]: global environments branches: Dict[str, Dict[str, List[Any]]] = {} @@ -208,15 +209,16 @@ def get_local_branches_to_emit() -> Dict[str, Dict[str, List[Any]]]: branches[k] = {} try: for step in env.pipeline: - if isinstance(step, GitClone): - branches[k] = {**step.get_branches()} - if isinstance(step, CachingStep) and isinstance(step.step, GitClone): - branches[k] = {**step.step.get_branches()} + if isinstance(step, GitClone): + branches[k] = {**step.get_branches()} + if isinstance(step, CachingStep) and isinstance(step.step, GitClone): + branches[k] = {**step.step.get_branches()} except BaseException as e: logger.error(f"Error fetching branches for environment {env.id}: {str(e)}") return branches + def get_global_branches_to_emit() -> Dict[str, Dict[str, List[Any]]]: global branches_slaves local_branches: Dict[str, Dict[str, List[Any]]] = get_local_branches_to_emit() @@ -230,12 +232,12 @@ environment_update_event = threading.Event() def serve_state() -> Any: return get_global_envs_to_emit() + @app.route('/branches') def serve_branches() -> Any: return get_global_branches_to_emit() - class EnvironmentNamespace(Namespace): def on_connect(self, auth: Optional[Any] = None) -> None: @@ -310,7 +312,7 @@ class App: configs.brencher_local1.brencher_local1, configs.torrserv_proxy.torrserv_proxy, configs.immich.immich, - configs.registry.registry, + configs.registry.registry, ] environments = {e.id: e for e in environments_l} @@ -323,9 +325,9 @@ class App: environments = {k: e for k, e in environments.items() if k not in cli_env_ids} else: cli_env_pairs = {x[0]: x[1] if len(x) > 1 else None for x in [x.split(":") - for x in cli_env_ids_str.split(',') - if len(x) > 0 - ] + for x in cli_env_ids_str.split(',') + if len(x) > 0 + ] } logger.info(f"cli_env_ids {cli_env_pairs}") if cli_env_pairs and len(cli_env_pairs) > 0: @@ -348,7 +350,6 @@ class App: environments = {id: wrap_in_cached(e) for id, e in environments.items()} - def processing_thread(self) -> None: while True: import processing diff --git a/backend/configs/brencher.py b/backend/configs/brencher.py index e57e6ed..7efe95d 100644 --- a/backend/configs/brencher.py +++ b/backend/configs/brencher.py @@ -6,22 +6,22 @@ from steps.git import GitClone, CheckoutMerged, GitUnmerge clone = GitClone() checkoutMerged = CheckoutMerged(clone, - push=False, - git_user_email="rudolfss13@gmail.com", - git_user_name="brencher_bot" - ) + push=False, + git_user_email="rudolfss13@gmail.com", + git_user_name="brencher_bot" + ) buildDocker = DockerComposeBuild(clone, - docker_repo_username="", - docker_repo_password="", - docker_compose_path="docker-compose.yml", - docker_repo_url="https://registry.rudolf.keenetic.link", - publish=False, - envs=lambda: { + docker_repo_username="", + docker_repo_password="", + docker_compose_path="docker-compose.yml", + docker_repo_url="https://registry.rudolf.keenetic.link", + publish=False, + envs=lambda: { "version": "auto-" + checkoutMerged.progress().version, "user_group": "1000:137" }, - ) + ) dockerSwarmCheck = DockerSwarmCheck( stack_name="brencher", diff --git a/backend/configs/brencher2.py b/backend/configs/brencher2.py index 72fb27d..8d14bcd 100644 --- a/backend/configs/brencher2.py +++ b/backend/configs/brencher2.py @@ -22,22 +22,22 @@ def checkPingF(obj: Any) -> None: clone = GitClone() checkoutMerged = CheckoutMerged(clone, - push=False, - git_user_email="rudolfss13@gmail.com", - git_user_name="brencher_bot" - ) + push=False, + git_user_email="rudolfss13@gmail.com", + git_user_name="brencher_bot" + ) buildDocker = DockerComposeBuild(clone, - docker_repo_username="", - docker_repo_password="", - docker_compose_path="docker-compose.yml", - docker_repo_url="https://registry.rudolf.keenetic.link", - publish=False, - envs=lambda: { + docker_repo_username="", + docker_repo_password="", + docker_compose_path="docker-compose.yml", + docker_repo_url="https://registry.rudolf.keenetic.link", + publish=False, + envs=lambda: { "version": "auto-" + checkoutMerged.progress().version, "user_group": "1000:137" }, - ) + ) dockerSwarmCheck = DockerSwarmCheck( stack_name="brencher2", diff --git a/backend/configs/brencher_local1.py b/backend/configs/brencher_local1.py index 9e522f0..b9e7de8 100644 --- a/backend/configs/brencher_local1.py +++ b/backend/configs/brencher_local1.py @@ -4,10 +4,10 @@ from steps.git import GitClone, CheckoutMerged, GitUnmerge clone = GitClone() checkoutMerged = CheckoutMerged(clone, - push=False, - git_user_email="rudolfss13@gmail.com", - git_user_name="brencher_bot" - ) + push=False, + git_user_email="rudolfss13@gmail.com", + git_user_name="brencher_bot" + ) # Step 1: Build the image image_build = DockerImageBuild( diff --git a/backend/configs/brencher_local2.py b/backend/configs/brencher_local2.py index 5dcd524..f37c7ef 100644 --- a/backend/configs/brencher_local2.py +++ b/backend/configs/brencher_local2.py @@ -5,23 +5,23 @@ from steps.git import GitClone, CheckoutMerged, GitUnmerge clone = GitClone() checkoutMerged = CheckoutMerged(clone, - push=False, - git_user_email="rudolfss13@gmail.com", - git_user_name="brencher_bot" - ) + push=False, + git_user_email="rudolfss13@gmail.com", + git_user_name="brencher_bot" + ) buildDocker = DockerComposeBuild(clone, - docker_repo_username="", - docker_repo_password="", - docker_compose_path="docker-compose.yml", - docker_repo_url="https://registry.rudolf.keenetic.link", - publish=False, - envs=lambda: { + docker_repo_username="", + docker_repo_password="", + docker_compose_path="docker-compose.yml", + docker_repo_url="https://registry.rudolf.keenetic.link", + publish=False, + envs=lambda: { "version": "auto-" + checkoutMerged.progress().version, "user_group": "1000:998" }, - ) + ) dockerSwarmCheck = DockerSwarmCheck( stack_name="brencher_local2", ) diff --git a/backend/configs/immich.py b/backend/configs/immich.py index 0002f8c..a07482d 100644 --- a/backend/configs/immich.py +++ b/backend/configs/immich.py @@ -5,10 +5,10 @@ from steps.git import GitClone, CheckoutMerged, GitUnmerge clone = GitClone(branchNamePrefix="ansible") checkoutMerged = CheckoutMerged(clone, - push=False, - git_user_email="rudolfss13@gmail.com", - git_user_name="brencher_bot" - ) + push=False, + git_user_email="rudolfss13@gmail.com", + git_user_name="brencher_bot" + ) dockerSwarmCheck = DockerSwarmCheck( stack_name="immich", diff --git a/backend/configs/registry.py b/backend/configs/registry.py index 15d7a91..5afd121 100644 --- a/backend/configs/registry.py +++ b/backend/configs/registry.py @@ -5,10 +5,10 @@ from steps.git import GitClone, CheckoutMerged, GitUnmerge clone = GitClone(branchNamePrefix="ansible") checkoutMerged = CheckoutMerged(clone, - push=False, - git_user_email="rudolfss13@gmail.com", - git_user_name="brencher_bot" - ) + push=False, + git_user_email="rudolfss13@gmail.com", + git_user_name="brencher_bot" + ) dockerSwarmCheck = DockerSwarmCheck( stack_name="registry", diff --git a/backend/configs/torrserv_proxy.py b/backend/configs/torrserv_proxy.py index fa062bb..b341b5f 100644 --- a/backend/configs/torrserv_proxy.py +++ b/backend/configs/torrserv_proxy.py @@ -4,21 +4,21 @@ from steps.git import GitClone, CheckoutMerged, GitUnmerge clone = GitClone() checkoutMerged = CheckoutMerged(clone, - push=False, - git_user_email="rudolfss13@gmail.com", - git_user_name="brencher_bot" - ) + push=False, + git_user_email="rudolfss13@gmail.com", + git_user_name="brencher_bot" + ) buildDocker = DockerComposeBuild(clone, - docker_repo_username="", - docker_repo_password="", - docker_compose_path="docker-compose.yml", - docker_repo_url="https://registry.rudolf.keenetic.link", - publish=False, - envs=lambda: { + docker_repo_username="", + docker_repo_password="", + docker_compose_path="docker-compose.yml", + docker_repo_url="https://registry.rudolf.keenetic.link", + publish=False, + envs=lambda: { "version": "auto-" + checkoutMerged.progress().version, }, - ) + ) dockerSwarmCheck = DockerSwarmCheck( stack_name="torrserv_proxy", diff --git a/backend/enironment.py b/backend/enironment.py index 348179e..e7cb89b 100644 --- a/backend/enironment.py +++ b/backend/enironment.py @@ -50,11 +50,12 @@ class AbstractStep[T](ABC): def progress(self) -> T: pass + def wrap_in_cached(e: Environment) -> Environment: from dataclasses import replace from steps.step import CachingStep result = replace(e, pipeline=[CachingStep(step) for step in e.pipeline]) - cached = {it.step: it for it in result.pipeline if isinstance(it, CachingStep) } + cached = {it.step: it for it in result.pipeline if isinstance(it, CachingStep)} for step in result.pipeline: if isinstance(step, CachingStep): step.step.env = result @@ -67,4 +68,3 @@ def wrap_in_cached(e: Environment) -> Environment: setattr(step.step, attr_name, cached_step) return result - diff --git a/backend/processing.py b/backend/processing.py index 93fe4a3..93bcd2f 100644 --- a/backend/processing.py +++ b/backend/processing.py @@ -11,12 +11,14 @@ logger = logging.getLogger(__name__) _last_reset_time: float = 0 RESET_INTERVAL = 3 * 60 # 3 minutes in seconds + def reset_caches(environemnts: List[Environment]) -> None: for env in environemnts: for step in env.pipeline: if isinstance(step, CachingStep): step.reset() + def process_all_jobs( environemnts: List[Environment], onupdate: Callable[[], None] @@ -32,7 +34,9 @@ def process_all_jobs( for step in env.pipeline: try: step.progress() - if (isinstance(step, GitUnmerge) or (isinstance(step, CachingStep) and isinstance(step.step, GitUnmerge))) and len(env.branches) == 0: + if (isinstance(step, GitUnmerge) or ( + isinstance(step, CachingStep) and isinstance(step.step, GitUnmerge))) and len( + env.branches) == 0: # TODO Move to separate job. # If branches list empty, need to find any brunch which includes commit and add pair (branch, commit) # If branches not empty, need to find most priority branch (project specific) and add (branch, HEAD) diff --git a/backend/steps/docker.py b/backend/steps/docker.py index a717732..eeb6cde 100644 --- a/backend/steps/docker.py +++ b/backend/steps/docker.py @@ -1,9 +1,7 @@ -import hashlib import logging import os import re import subprocess -import tempfile from dataclasses import dataclass from typing import List, Dict, Callable, Any, Mapping, Protocol, Union, runtime_checkable @@ -20,13 +18,13 @@ logger = logging.getLogger(__name__) class DockerComposeBuild(AbstractStep[List[str]]): def __init__(self, - wd: GitClone, # TODO should be CheckoutMerged - docker_repo_username: str, - docker_repo_password: str, - docker_compose_path: str, - docker_repo_url: str, - publish: bool, - envs: Callable[[], Dict[str, Any]], **kwargs: Any) -> None: + wd: GitClone, # TODO should be CheckoutMerged + docker_repo_username: str, + docker_repo_password: str, + docker_compose_path: str, + docker_repo_url: str, + publish: bool, + envs: Callable[[], Dict[str, Any]], **kwargs: Any) -> None: super().__init__(**kwargs) self.wd = wd self.envs = envs @@ -107,8 +105,8 @@ class DockerSwarmCheckResult: class DockerSwarmCheck(AbstractStep[Dict[str, DockerSwarmCheckResult]]): def __init__(self, - stack_name: str, - **kwargs: Any) -> None: + stack_name: str, + **kwargs: Any) -> None: super().__init__(**kwargs) self.stack_name = stack_name @@ -139,13 +137,13 @@ class HasImage(Protocol): class DockerSwarmDeploy(AbstractStep[str]): def __init__(self, - wd: GitClone, - buildDocker: DockerComposeBuild | None, - stackChecker: AbstractStep[Mapping[str, Union[HasImage, HasVersion]]], - docker_compose_path: str, - envs: Callable[[], Dict[str, Any]], - stack_name: str, - **kwargs: Any) -> None: + wd: GitClone, + buildDocker: DockerComposeBuild | None, + stackChecker: AbstractStep[Mapping[str, Union[HasImage, HasVersion]]], + docker_compose_path: str, + envs: Callable[[], Dict[str, Any]], + stack_name: str, + **kwargs: Any) -> None: super().__init__(**kwargs) self.wd = wd self.buildDocker = buildDocker @@ -261,7 +259,7 @@ class DockerSwarmDeploy(AbstractStep[str]): swarmEnv: dict[str, str] = {} if os.path.exists(os.path.join(os.path.dirname(tmp_compose_path), ".env")): swarmEnv = {k: v for k, v in dotenv_values(os.path.join(os.path.dirname(tmp_compose_path), ".env")).items() - if v is not None} + if v is not None} # merge_dicts(swarmEnv, env) result = subprocess.run(cmd, capture_output=True, text=True) # , cwd=os.path.dirname(tmp_compose_path), env=swarmEnv) diff --git a/backend/steps/docker_plain.py b/backend/steps/docker_plain.py index 1d8ff69..209221b 100644 --- a/backend/steps/docker_plain.py +++ b/backend/steps/docker_plain.py @@ -20,21 +20,21 @@ class DockerImageBuildResult: image_name: str image_tag: str full_image: str - # build_logs: List[str] +# build_logs: List[str] class DockerImageBuild(AbstractStep[DockerImageBuildResult]): """Build a single Docker image from a Dockerfile""" def __init__(self, - wd: CheckoutMerged, - dockerfile_path: str, - image_name: str, - image_tag: Callable[[], str] | str, - build_context: Optional[str] = None, - build_args: Optional[Dict[str, str]] = None, - nocache: bool = False, - **kwargs: Any) -> None: + wd: CheckoutMerged, + dockerfile_path: str, + image_name: str, + image_tag: Callable[[], str] | str, + build_context: Optional[str] = None, + build_args: Optional[Dict[str, str]] = None, + nocache: bool = False, + **kwargs: Any) -> None: super().__init__(**kwargs) self.wd = wd self.dockerfile_path = dockerfile_path @@ -117,8 +117,8 @@ class DockerContainerCheck(AbstractStep[Dict[str, DockerContainerCheckResult]]): """Check if a Docker container exists and get its status""" def __init__(self, - container_name: str, - **kwargs: Any) -> None: + container_name: str, + **kwargs: Any) -> None: super().__init__(**kwargs) self.container_name = container_name @@ -169,14 +169,14 @@ class DockerContainerDeploy(AbstractStep[DockerContainerDeployResult]): """Deploy a single Docker container""" def __init__(self, - image_build: DockerImageBuild, - container_name: str, - ports: Optional[Dict[str, int]] = None, - environment: Optional[Dict[str, str]] = None, - volumes: Optional[Dict[str, Dict[str, str]]] = None, - network: Optional[str] = None, - restart_policy: Optional[Dict[str, Any]] = None, - **kwargs: Any) -> None: + image_build: DockerImageBuild, + container_name: str, + ports: Optional[Dict[str, int]] = None, + environment: Optional[Dict[str, str]] = None, + volumes: Optional[Dict[str, Dict[str, str]]] = None, + network: Optional[str] = None, + restart_policy: Optional[Dict[str, Any]] = None, + **kwargs: Any) -> None: super().__init__(**kwargs) self.image_build = image_build self.container_name = container_name diff --git a/backend/steps/git.py b/backend/steps/git.py index ae1e290..2148db6 100644 --- a/backend/steps/git.py +++ b/backend/steps/git.py @@ -1,10 +1,10 @@ import hashlib import logging import os +import shutil import tempfile from dataclasses import dataclass from typing import List, Tuple, Set, Dict, Any, Mapping, runtime_checkable -import shutil import git from git.objects import Commit @@ -16,7 +16,7 @@ logger = logging.getLogger(__name__) class GitClone(AbstractStep[str]): def __init__(self, repo_path: str | None = None, branchNamePrefix: str = "", credEnvPrefix: str = "GIT", - **kwargs: Any): + **kwargs: Any): super().__init__(**kwargs) self.repo_path = repo_path self.branchNamePrefix = branchNamePrefix @@ -35,7 +35,7 @@ class GitClone(AbstractStep[str]): def progress(self) -> str: self.repo_path = self.repo_path or os.path.join(tempfile.gettempdir(), - f"{self.env.id}_{hashlib.sha1(self.env.repo.encode()).hexdigest()[:5]}") + f"{self.env.id}_{hashlib.sha1(self.env.repo.encode()).hexdigest()[:5]}") logger.info(f"Cloning repository {self.env.repo} to {self.repo_path}") os.makedirs(self.repo_path, exist_ok=True) try: @@ -55,7 +55,7 @@ class GitClone(AbstractStep[str]): )) if self.branchNamePrefix != "": repo.config_writer().set_value('remote "origin"', "fetch", - f"+refs/heads/{self.branchNamePrefix}/*:refs/remotes/origin/{self.branchNamePrefix}/*").release() + f"+refs/heads/{self.branchNamePrefix}/*:refs/remotes/origin/{self.branchNamePrefix}/*").release() repo.remotes.origin.fetch(prune=True) if not os.path.exists(os.path.join(self.repo_path, ".git")): raise BaseException(f"Failed to clone repository {self.env.repo} to {self.repo_path}") @@ -102,6 +102,7 @@ def _commits_childs(repo: git.Repo) -> Dict[Commit, List[Commit]]: childs.setdefault(p, []).append(c) return childs + def ensure_clean(repo: git.Repo) -> None: if repo.is_dirty() or len(repo.untracked_files) > 0: raise BaseException(f"Changes in repo: U{repo.untracked_files}") @@ -111,10 +112,10 @@ class CheckoutMerged(AbstractStep[CheckoutAndMergeResult]): wd: GitClone def __init__(self, wd: GitClone, - git_user_email: str, - git_user_name: str, - push: bool = True, - **kwargs: Any): + git_user_email: str, + git_user_name: str, + push: bool = True, + **kwargs: Any): super().__init__(**kwargs) self.wd = wd self.git_user_email = git_user_email @@ -171,7 +172,7 @@ class CheckoutMerged(AbstractStep[CheckoutAndMergeResult]): def find_common_merge_commits() -> Set[Commit]: merge_commit: list[tuple[Commit, list[Commit]]] = [(c, self._find_merge_childs(childs, c)) for c in - commit_ids.keys()] + commit_ids.keys()] legal_merge_commits = [set(l) for c, l in merge_commit] result = legal_merge_commits[0] for l in legal_merge_commits[1:]: @@ -239,6 +240,7 @@ class CheckoutMerged(AbstractStep[CheckoutAndMergeResult]): from typing import Protocol, Any + @runtime_checkable class HasVersion(Protocol): version: str @@ -248,8 +250,8 @@ class GitUnmerge(AbstractStep[List[Tuple[str, str]]]): wd: GitClone def __init__(self, wd: GitClone, - check: AbstractStep[Mapping[str, HasVersion]], - **kwargs: Any): + check: AbstractStep[Mapping[str, HasVersion]], + **kwargs: Any): super().__init__(**kwargs) self.wd = wd self.check = check @@ -276,7 +278,7 @@ class GitUnmerge(AbstractStep[List[Tuple[str, str]]]): # branches = [head.name for head in repo.heads if head.commit.hexsha == commit.hexsha] branches = [ref.name for ref in repo.remotes.origin.refs if ref.commit.hexsha == commit.hexsha] branches = [b[len('origin/'):] for b in branches if - b.startswith('origin/') and not b.startswith('origin/HEAD')] + b.startswith('origin/') and not b.startswith('origin/HEAD')] if len(branches) == 0 or branches[0].startswith('auto/'): if childs is None: @@ -286,9 +288,9 @@ class GitUnmerge(AbstractStep[List[Tuple[str, str]]]): current = commitsSet.pop() for child in childs.get(current, []): branches = [ref.name for ref in repo.remotes.origin.refs if - ref.commit.hexsha == child.hexsha] + ref.commit.hexsha == child.hexsha] branches = [b[len('origin/'):] for b in branches if - b.startswith('origin/') and not b.startswith('origin/HEAD')] + b.startswith('origin/') and not b.startswith('origin/HEAD')] if len(branches) > 0: commitsSet = set() diff --git a/tests/__init__.py b/tests/__init__.py index 3d6fef5..1d0a320 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -5,4 +5,3 @@ from pathlib import Path backend_path = Path(__file__).parent.parent / "backend" if str(backend_path) not in sys.path: sys.path.insert(0, str(backend_path)) - diff --git a/tests/conftest.py b/tests/conftest.py index 03e39e4..8a8dea8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,6 +10,7 @@ import pytest from tests.test_remote_repo import RemoteRepoHelper + @pytest.hookimpl(hookwrapper=True) def pytest_runtest_makereport(item: pytest.Item, call: pytest.CallInfo[object]) -> object: """Expose test phase reports on the test item for fixture finalizers.""" @@ -33,7 +34,7 @@ class EventuallyFn(Protocol): @pytest.fixture def eventually() -> EventuallyFn: - def _eventually(assert_fn: Callable[[], bool], timeout: float=2.0, interval:float=0.05) -> None: + def _eventually(assert_fn: Callable[[], bool], timeout: float = 2.0, interval: float = 0.05) -> None: deadline = time.monotonic() + timeout last_error = None while time.monotonic() < deadline: diff --git a/tests/integration/test_containertest.py b/tests/integration/test_containertest.py index da47169..bb70a97 100644 --- a/tests/integration/test_containertest.py +++ b/tests/integration/test_containertest.py @@ -14,6 +14,7 @@ from conftest import EventuallyFn # type: ignore[import-not-found] logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) + class TestDockerContainer: @pytest.fixture(autouse=True) diff --git a/tests/test_cached_env.py b/tests/test_cached_env.py index 1b14ca1..c8edab0 100644 --- a/tests/test_cached_env.py +++ b/tests/test_cached_env.py @@ -1,30 +1,27 @@ import pytest from enironment import wrap_in_cached -from steps.git import CheckoutAndMergeResult from tests.test_remote_repo import RemoteRepoHelper class TestCachedEnv: - """Tests for the CachedEnv wrapper around GitEnv.""" - + """Tests for the CachedEnv wrapper around GitEnv.""" - def test_checkout_merged_empty_branches(self, repo_helper: RemoteRepoHelper) -> None: - """Test CheckoutMerged with empty branches list - should fail""" + def test_checkout_merged_empty_branches(self, repo_helper: RemoteRepoHelper) -> None: + """Test CheckoutMerged with empty branches list - should fail""" - commit1 = repo_helper.create_commit(repo_helper.repo, "master", "master", "file1.txt", "content1", "Initial commit") + commit1 = repo_helper.create_commit(repo_helper.repo, "master", "master", "file1.txt", "content1", + "Initial commit") - repo_helper.env = wrap_in_cached(repo_helper.env) + repo_helper.env = wrap_in_cached(repo_helper.env) - repo_helper.env.branches = [] + repo_helper.env.branches = [] - with pytest.raises(BaseException, match="Empty branches set"): - repo_helper.checkout_merged.progress() - - repo_helper.env.branches = [('master', 'HEAD')] - result = repo_helper.checkout_merged.progress() - - # Verify same auto branch is used with actual value checks - assert result.commit_hash == commit1.hexsha, f"Expected {commit1.hexsha}, got {result.commit_hash}" + with pytest.raises(BaseException, match="Empty branches set"): + repo_helper.checkout_merged.progress() + repo_helper.env.branches = [('master', 'HEAD')] + result = repo_helper.checkout_merged.progress() + # Verify same auto branch is used with actual value checks + assert result.commit_hash == commit1.hexsha, f"Expected {commit1.hexsha}, got {result.commit_hash}" diff --git a/tests/test_dummy.py b/tests/test_dummy.py index 8d5f233..0e4852b 100644 --- a/tests/test_dummy.py +++ b/tests/test_dummy.py @@ -6,7 +6,6 @@ # from inline_snapshot import snapshot - # from dirty_equals import IsInt, IsNow # from pydantic import TypeAdapter @@ -20,5 +19,3 @@ # "created_at": IsNow(), # Проверит время, близкое к текущему # "status": "active" # }) - - diff --git a/tests/test_remote_repo.py b/tests/test_remote_repo.py index c25d7cb..11325aa 100644 --- a/tests/test_remote_repo.py +++ b/tests/test_remote_repo.py @@ -72,21 +72,26 @@ class RemoteRepoHelper: git_unmerge ] ) + @property def checkout_merged(self) -> AbstractStep[CheckoutAndMergeResult]: - return [i for i in self.env.pipeline if isinstance(i, CheckoutMerged) or (isinstance(i, CachingStep) and isinstance(i.step, CheckoutMerged))][0] - + return [i for i in self.env.pipeline if + isinstance(i, CheckoutMerged) or (isinstance(i, CachingStep) and isinstance(i.step, CheckoutMerged))][0] + @property def git_clone(self) -> AbstractStep[str]: - return [i for i in self.env.pipeline if isinstance(i, GitClone) or (isinstance(i, CachingStep) and isinstance(i.step, GitClone))][0] + return [i for i in self.env.pipeline if + isinstance(i, GitClone) or (isinstance(i, CachingStep) and isinstance(i.step, GitClone))][0] @property def git_unmerge(self) -> AbstractStep[List[Tuple[str, str]]]: - return [i for i in self.env.pipeline if isinstance(i, GitUnmerge) or (isinstance(i, CachingStep) and isinstance(i.step, GitUnmerge))][0] + return [i for i in self.env.pipeline if + isinstance(i, GitUnmerge) or (isinstance(i, CachingStep) and isinstance(i.step, GitUnmerge))][0] @property def mock_check(self) -> AbstractStep[Dict[str, HasVersion]]: - return [i for i in self.env.pipeline if isinstance(i, MockDockerSwarmCheck) or (isinstance(i, CachingStep) and isinstance(i.step, MockDockerSwarmCheck))][0] + return [i for i in self.env.pipeline if isinstance(i, MockDockerSwarmCheck) or ( + isinstance(i, CachingStep) and isinstance(i.step, MockDockerSwarmCheck))][0] def teardown(self) -> None: """Clean up temporary directories""" @@ -96,7 +101,7 @@ class RemoteRepoHelper: shutil.rmtree(self.local_dir, ignore_errors=True) def create_commit(self, repo: git.Repo, from_branch: str, to_branch: str, filename: str, content: str, - message: str) -> git.Commit: + message: str) -> git.Commit: """Create a commit in the repository If to_branch doesn't exist, it will be created from from_branch and checked out. @@ -154,6 +159,6 @@ class RemoteRepoHelper: def print_git_logs(self) -> None: """Print remote and local repository logs for debugging failed tests.""" print(f"Version: {git.__version__}") - + print(self._safe_git_log(self.remote_dir, "remote")) print(self._safe_git_log(self.local_dir, "local")) diff --git a/typesPlayground/TypedDict1.py b/typesPlayground/TypedDict1.py index 73a0a0f..a22c543 100644 --- a/typesPlayground/TypedDict1.py +++ b/typesPlayground/TypedDict1.py @@ -19,6 +19,8 @@ class C2(TypedDict): @dataclass class C1V(C1, C2): name: str + + # version: str # version1: str