From b7ad854a49d1976de192af0b8e64f10012699414 Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 18:34:20 +0200 Subject: [PATCH 01/15] refactor backend --- backend/app.py | 433 ++++++++++------------------------------------- backend/utils.py | 31 ++++ backend/web.py | 217 ++++++++++++++++++++++++ 3 files changed, 342 insertions(+), 339 deletions(-) create mode 100644 backend/utils.py create mode 100644 backend/web.py diff --git a/backend/app.py b/backend/app.py index 7831b4c..bc783ae 100644 --- a/backend/app.py +++ b/backend/app.py @@ -1,22 +1,15 @@ -import asyncio -import json import logging import os import signal import sys import threading import traceback -from dataclasses import asdict, replace -from typing import Any, Dict, List, Optional, TypeVar, Tuple +from typing import Any, Callable, Dict, List, Optional +from utils import sigchld_handler from dotenv import load_dotenv -from fastapi import FastAPI, Response, WebSocket, WebSocketDisconnect -from fastapi.middleware.cors import CORSMiddleware -from fastapi.responses import FileResponse -from enironment import Environment, wrap_in_cached, SharedStateHolder, SharedStateConflictError, SharedState, get_step -from processing import reset_caches -from secondary import SecondaryManager +from enironment import Environment, wrap_in_cached, SharedStateHolder, get_step from steps.git import GitClone from steps.step import CachingStep @@ -29,317 +22,14 @@ load_dotenv("local.env") load_dotenv('/run/secrets/brencher-secrets') -class DataclassJSONEncoder(json.JSONEncoder): - def default(self, o: Any) -> Any: - if hasattr(o, '__dataclass_fields__'): - return asdict(o) - if isinstance(o, BaseException): - return str(o) - try: - return super().default(o) - except TypeError: - return str(o) - - -def custom_json_dumps(obj: Any) -> str: - return json.dumps(obj, cls=DataclassJSONEncoder) - - -app = FastAPI() - -app.add_middleware( - CORSMiddleware, - allow_origins=["*"], - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], -) - -FRONTEND_DIR = os.path.join(os.path.dirname(__file__), '../frontend') - -# In-memory state -environments: Dict[str, Environment] = {} -state_lock = threading.Lock() - -# Active WebSocket connections -ws_connections: Dict[WebSocket, Dict[str, Any]] = {} - -# Event loop reference for thread-safe async calls -_event_loop: Optional[asyncio.AbstractEventLoop] = None - - -environment_update_event = threading.Event() - - -# --- Static File Serving --- - -@app.get("/") -async def serve_index() -> FileResponse: - return FileResponse(os.path.join(FRONTEND_DIR, 'index.html')) - - -@app.get("/state") -async def serve_state() -> Response: - return Response(content=custom_json_dumps(get_global_envs_to_emit()), media_type="application/json") - - -@app.get("/branches") -async def serve_branches_route() -> Response: - return Response(content=custom_json_dumps(get_global_branches_to_emit()), media_type="application/json") - - -@app.get("/{path:path}") -async def serve_static(path: str) -> FileResponse: - file_path = os.path.join(FRONTEND_DIR, path) - if os.path.exists(file_path) and os.path.isfile(file_path): - return FileResponse(file_path) - return FileResponse(os.path.join(FRONTEND_DIR, 'index.html')) - - -# --- Utility Functions --- - -T = TypeVar('T') - - -def merge_dicts(a: Dict[str, T], b: Dict[str, T]) -> Dict[str, T]: - result: Dict[str, T] = {} - for k in (a.keys() | b.keys()): - if k not in a or k not in b: - result[k] = a.get(k, b.get(k)) # type: ignore[assignment] - continue - if ( - isinstance(a[k], dict) - and isinstance(b[k], dict) - ): - result[k] = merge_dicts(a[k], b[k]) # type: ignore[arg-type,assignment] - else: - result[k] = b[k] - return result - - -def get_local_envs_to_emit() -> Dict[str, Dict[str, Any]]: - env_dtos: Dict[str, Dict[str, Any]] = {} - for env in environments.values(): - pipeline_state: List[Dict[str, Any]] = [] - for r in env.pipeline: - try: - if isinstance(r, CachingStep): - result = r._result - else: - result = r.progress() - - if isinstance(result, BaseException): - stack = traceback.format_exception(type(result), result, result.__traceback__) - pipeline_state.append({ - "name": r.name, - "status": [str(result), stack], - "error": True, - "is_running": True, - }) - else: - pipeline_state.append({ - "name": r.name, - "status": result, - "is_running": False, - }) - except BaseException as e: - stack = traceback.format_exception(type(e), e, e.__traceback__) - pipeline_state.append({ - "name": r.name, - "status": [str(e), stack], - "error": True, - "is_running": True, - }) - env_dtos[env.id] = {'id': env.id } - env_dtos[env.id]['pipeline'] = pipeline_state - try: - shared_state = env.state.progress() - env_dtos[env.id]['branches'] = shared_state.branches - env_dtos[env.id]['branches_token'] = shared_state.token - env_dtos[env.id]['dry'] = shared_state.dry - except BaseException: - pass - return env_dtos - - -def get_global_envs_to_emit() -> Any: - global environments - local_envs = get_local_envs_to_emit() - merged: Dict[str, Any] = local_envs - for connector in secondaryManager or []: - v = connector.environments - common_keys = set(merged.keys()) & set(v.keys()) - if len(common_keys) > 0: - _schedule_async(broadcast_error({'message': f"Conflict: both master and secondary have environment with id {common_keys}"})) - merged = merge_dicts(merged, v) - return merged - - - -def get_local_branches_to_emit() -> Dict[str, Dict[str, List[Any]]]: - global environments - branches: Dict[str, Dict[str, List[Any]]] = {} - for k, env in environments.items(): - branches[k] = {} - try: - step = get_step(env.pipeline, GitClone) - branches[k] = {**step.get_branches()} - except BaseException as e: - stack = traceback.format_exception(type(e), e, e.__traceback__) - logger.error(f"Error fetching branches for environment {env.id}: {str(e)}\n{''.join(stack)}") - - return branches - - - -def get_global_branches_to_emit() -> Dict[str, Dict[str, List[Any]]]: - local_branches: Dict[str, Dict[str, List[Any]]] = get_local_branches_to_emit() - merged: Dict[str, Dict[str, List[Any]]] = local_branches - for connector in secondaryManager or []: - merged = merge_dicts(merged, connector.branches) - return merged - - -# --- Async Helper for Calling from Sync Threads --- - -def _schedule_async(coro: Any) -> None: - """Schedule a coroutine from a sync thread using the saved event loop.""" - if _event_loop is not None and _event_loop.is_running(): - asyncio.run_coroutine_threadsafe(coro, _event_loop) - - -# --- WebSocket Broadcasting Functions --- - -async def broadcast(event: str, data: Any) -> None: - """Broadcast a message to all connected WebSocket clients that have not seen this data yet.""" - disconnected = set() - message = custom_json_dumps({event: data}) - - for websocket in ws_connections.keys(): - if ws_connections[websocket].get(event) == message: - continue - try: - await websocket.send_text(message) - ws_connections[websocket][event] = message - except Exception as e: - logger.error(f"Error sending to websocket: {e}") - disconnected.add(websocket) - - for ws in disconnected: - ws_connections.pop(ws, None) - -async def broadcast_all() -> None: - await broadcast("branches", get_global_branches_to_emit()) - await broadcast("environments", get_global_envs_to_emit()) - - -async def broadcast_branches(data: Any) -> None: - await broadcast("branches", data) - - -async def broadcast_environments(data: Any) -> None: - await broadcast("environments", data) - - -async def broadcast_error(data: Any) -> None: - await broadcast("error", data) - - -# --- Single WebSocket Endpoint --- - -@app.websocket("/ws") -async def websocket_endpoint(websocket: WebSocket) -> None: - await websocket.accept() - ws_connections[websocket] = {} - - try: - # Send initial state on connect and record it so duplicate broadcasts are suppressed - branches_payload = custom_json_dumps({"branches": get_global_branches_to_emit()}) - envs_payload = custom_json_dumps({"environments": get_global_envs_to_emit()}) - await websocket.send_text(branches_payload) - ws_connections[websocket]["branches"] = branches_payload - await websocket.send_text(envs_payload) - ws_connections[websocket]["environments"] = envs_payload - - while True: - data = await websocket.receive_text() - message = json.loads(data) - - if "update" in message: - update_data = message.get("update") or {} - logger.info(f"Received environment update: {update_data}") - if secondaryManager: - await secondaryManager.send({"update": update_data}) - id = update_data.get('id', '') - if id == '': - reset_caches(list(environments.values())) - elif id not in environments.keys() and id not in { j for it in secondaryManager or [] for j in it.environments.keys()}: - logger.warning(f"Received update for unknown environment id {id}") - continue - elif id in environments.keys(): - env = environments.get(id, None) - expected_token = update_data.get('token', '') - if 'branches' in update_data: - if not env: - raise RuntimeError(f"Unknown env {update_data.get('id', '')}") - env.state.set_branches(update_data.get('branches', []), expected_token=expected_token) - if 'dry' in update_data: - if not env: - raise RuntimeError(f"Unknown env {update_data.get('id', '')}") - env.state.set_dry(bool(update_data['dry']), expected_token) - - if env: - p = get_step(env.pipeline, type(env.state)) - if isinstance(p, CachingStep): - p.reset() - logger.info(f"Updated environment {env.id} branches to {update_data.get('branches')}, dry={update_data.get('dry')}") - environment_update_event.set() - - await broadcast_environments(get_global_envs_to_emit()) - - except WebSocketDisconnect as e: - ws_connections.pop(websocket, None) - except Exception as e: - logger.error(f"WebSocket error: {e}:{traceback.format_exc()}") - await broadcast_error({'message': f'{e}:{traceback.format_exc()}'}) - # await websocket.close() - # ws_connections.pop(websocket, None) - - -# --- SIGCHLD Handler --- - -def sigchld_handler(signum: int, frame: Any) -> None: - """Reap zombie processes.""" - while True: - try: - pid, status = os.waitpid(-1, os.WNOHANG) - if pid == 0: - break - except ChildProcessError: - break - - -# --- Startup Event --- - -secondaryManager: Optional[SecondaryManager] = None - -@app.on_event("startup") -async def startup_event() -> None: - global _event_loop, secondaryManager - _event_loop = asyncio.get_event_loop() - secondaryManager = SecondaryManager( - urls = os.getenv("SECONDARY_BRENCHER", ""), - on_update=lambda: broadcast_all(), - ) - - -# --- App Class (used by CLI and integration tests) --- - class App: def __init__(self, cli_env_ids_str: str, dry_run: bool = False) -> None: - global environments - signal.signal(signal.SIGCHLD, sigchld_handler) + + self.environments: Dict[str, Environment] = {} + self.state_lock = threading.Lock() + self.environment_update_event = threading.Event() + self.emit_callback: Optional[Callable[[], None]] = None import configs.brencher import configs.brencher2 @@ -359,7 +49,7 @@ class App: configs.registry.registry, configs.gmail_mcp.gmail_mcp, ] - environments = {e.id: e for e in environments_l} + self.environments = {e.id: e for e in environments_l} logger.info(f"cli_env_ids {cli_env_ids_str}") if len(cli_env_ids_str) > 0 and cli_env_ids_str[0] == '-': @@ -367,7 +57,7 @@ class App: cli_env_ids = [x for x in cli_env_ids if len(x) > 0] logger.info(f"cli_env_ids (minus) {cli_env_ids}") if cli_env_ids and len(cli_env_ids) > 0: - environments = {k: e for k, e in environments.items() if k not in cli_env_ids} + self.environments = {k: e for k, e in self.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(',') @@ -376,11 +66,11 @@ class App: } logger.info(f"cli_env_ids {cli_env_pairs}") if cli_env_pairs and len(cli_env_pairs) > 0: - environments = {k: e for k, e in environments.items() if k in cli_env_pairs.keys()} + self.environments = {k: e for k, e in self.environments.items() if k in cli_env_pairs.keys()} for k, v in cli_env_pairs.items(): if v is not None: - if k in environments: - env = environments[k] + if k in self.environments: + env = self.environments[k] for step in env.pipeline: resolve_step = step if isinstance(step, CachingStep): @@ -393,39 +83,99 @@ class App: else: logger.info(f"No branch override for environment {k}") if dry_run: - for id, e in environments.items(): + for id, e in self.environments.items(): e.state.set_dry(True) - logger.info(f"Resulting profiles {environments.keys()}") + logger.info(f"Resulting profiles {self.environments.keys()}") - environments = {id: wrap_in_cached(e) for id, e in environments.items()} + self.environments = {id: wrap_in_cached(e) for id, e in self.environments.items()} + + def get_local_envs_to_emit(self) -> Dict[str, Dict[str, Any]]: + env_dtos: Dict[str, Dict[str, Any]] = {} + for env in self.environments.values(): + pipeline_state: List[Dict[str, Any]] = [] + for r in env.pipeline: + try: + if isinstance(r, CachingStep): + result = r._result + else: + result = r.progress() + + if isinstance(result, BaseException): + stack = traceback.format_exception(type(result), result, result.__traceback__) + pipeline_state.append({ + "name": r.name, + "status": [str(result), stack], + "error": True, + "is_running": True, + }) + else: + pipeline_state.append({ + "name": r.name, + "status": result, + "is_running": False, + }) + except BaseException as e: + stack = traceback.format_exception(type(e), e, e.__traceback__) + pipeline_state.append({ + "name": r.name, + "status": [str(e), stack], + "error": True, + "is_running": True, + }) + env_dtos[env.id] = {'id': env.id } + env_dtos[env.id]['pipeline'] = pipeline_state + try: + shared_state = env.state.progress() + env_dtos[env.id]['branches'] = shared_state.branches + env_dtos[env.id]['branches_token'] = shared_state.token + env_dtos[env.id]['dry'] = shared_state.dry + except BaseException: + pass + return env_dtos + + def get_local_branches_to_emit(self) -> Dict[str, Dict[str, List[Any]]]: + branches: Dict[str, Dict[str, List[Any]]] = {} + for k, env in self.environments.items(): + branches[k] = {} + try: + step = get_step(env.pipeline, GitClone) + branches[k] = {**step.get_branches()} + except BaseException as e: + stack = traceback.format_exception(type(e), e, e.__traceback__) + logger.error(f"Error fetching branches for environment {env.id}: {str(e)}\n{''.join(stack)}") + + return branches def processing_thread(self) -> None: while True: import processing - def emit_envs() -> None: - _schedule_async(broadcast_branches(get_global_branches_to_emit())) - _schedule_async(broadcast_environments(get_global_envs_to_emit())) + emit = self.emit_callback or (lambda: None) - with state_lock: + with self.state_lock: logger.info(f"Processing") - if processing.process_all_jobs(list(environments.values()), lambda: emit_envs()): - environment_update_event.wait(timeout=1 * 5) + if processing.process_all_jobs(list(self.environments.values()), emit): + self.environment_update_event.wait(timeout=1 * 5) else: - environment_update_event.wait(timeout=1 * 60) - environment_update_event.clear() + self.environment_update_event.wait(timeout=1 * 60) + self.environment_update_event.clear() def run(self) -> None: processing = threading.Thread(target=self.processing_thread) processing.daemon = True processing.start() - def runWeb(self, port: int) -> None: - self.run() - import uvicorn - uvicorn.run(app, host='0.0.0.0', port=port, log_level='info') + def runHeadless(self) -> None: + """Run the processing loop on the current thread; blocks forever.""" + self.processing_thread() + def runWeb(self, port: int) -> None: + import web + web_app = web.WebApp(core=self, port=port) + self.emit_callback = web_app.emit_envs + self.run() + web_app.start() if __name__ == '__main__': cli_env_ids_list = sys.argv[1:] @@ -435,5 +185,10 @@ if __name__ == '__main__': else: cli_env_ids_str = cli_env_ids_list[0] + signal.signal(signal.SIGCHLD, sigchld_handler) app1 = App(cli_env_ids_str, 'dry' in sys.argv[1:]) - app1.runWeb(port=(5007 if 'noweb' in sys.argv[1:] else 5001)) + + if 'noweb' in sys.argv[1:]: + app1.runHeadless() + else: + app1.runWeb(5001) diff --git a/backend/utils.py b/backend/utils.py new file mode 100644 index 0000000..2dbb669 --- /dev/null +++ b/backend/utils.py @@ -0,0 +1,31 @@ +import json +from dataclasses import asdict +import os +from typing import Any + + +class DataclassJSONEncoder(json.JSONEncoder): + def default(self, o: Any) -> Any: + if hasattr(o, '__dataclass_fields__'): + return asdict(o) + if isinstance(o, BaseException): + return str(o) + try: + return super().default(o) + except TypeError: + return str(o) + + +def custom_json_dumps(obj: Any) -> str: + return json.dumps(obj, cls=DataclassJSONEncoder) + +def sigchld_handler(signum: int, frame: Any) -> None: + """Reap zombie processes.""" + while True: + try: + pid, status = os.waitpid(-1, os.WNOHANG) + if pid == 0: + break + except ChildProcessError: + break + diff --git a/backend/web.py b/backend/web.py new file mode 100644 index 0000000..e25f57a --- /dev/null +++ b/backend/web.py @@ -0,0 +1,217 @@ +import asyncio +import json +import logging +import os +import traceback +from contextlib import asynccontextmanager +from typing import Any, AsyncIterator, Dict, List, Optional, TypeVar + +from fastapi import FastAPI, Response, WebSocket, WebSocketDisconnect +from fastapi.middleware.cors import CORSMiddleware +from fastapi.responses import FileResponse + +from app import App +from enironment import get_step +from utils import custom_json_dumps +from processing import reset_caches +from secondary import SecondaryManager +from steps.step import CachingStep + +logger = logging.getLogger(__name__) + +FRONTEND_DIR = os.path.join(os.path.dirname(__file__), '../frontend') + +T = TypeVar('T') + + +def _merge_dicts(a: Dict[str, T], b: Dict[str, T]) -> Dict[str, T]: + result: Dict[str, T] = {} + for k in (a.keys() | b.keys()): + if k not in a or k not in b: + result[k] = a.get(k, b.get(k)) # type: ignore[assignment] + continue + if ( + isinstance(a[k], dict) + and isinstance(b[k], dict) + ): + result[k] = _merge_dicts(a[k], b[k]) # type: ignore[arg-type,assignment] + else: + result[k] = b[k] + return result + + +class WebApp: + + def __init__(self, core: App, port: int) -> None: + self.core = core + self.port = port + + self.ws_connections: Dict[WebSocket, Dict[str, Any]] = {} + self._event_loop: Optional[asyncio.AbstractEventLoop] = None + self.secondaryManager: Optional[SecondaryManager] = None + + @asynccontextmanager + async def lifespan(fastapi_app: FastAPI) -> AsyncIterator[None]: + self._event_loop = asyncio.get_event_loop() + self.secondaryManager = SecondaryManager( + urls=os.getenv("SECONDARY_BRENCHER", ""), + on_update=lambda: self.broadcast_all(), + ) + yield + + self.app = FastAPI(lifespan=lifespan) + self.app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], + ) + + self.app.get("/")(self.serve_index) + self.app.get("/state")(self.serve_state) + self.app.get("/branches")(self.serve_branches_route) + self.app.get("/{path:path}")(self.serve_static) + self.app.websocket("/ws")(self.websocket_endpoint) + + # --- State assembly (local + secondary) --- + + def get_global_envs_to_emit(self) -> Any: + local_envs = self.core.get_local_envs_to_emit() + merged: Dict[str, Any] = local_envs + for connector in self.secondaryManager or []: + v = connector.environments + common_keys = set(merged.keys()) & set(v.keys()) + if len(common_keys) > 0: + self._schedule_async(self.broadcast_error({'message': f"Conflict: both master and secondary have environment with id {common_keys}"})) + merged = _merge_dicts(merged, v) + return merged + + def get_global_branches_to_emit(self) -> Dict[str, Dict[str, List[Any]]]: + local_branches: Dict[str, Dict[str, List[Any]]] = self.core.get_local_branches_to_emit() + merged: Dict[str, Dict[str, List[Any]]] = local_branches + for connector in self.secondaryManager or []: + merged = _merge_dicts(merged, connector.branches) + return merged + + # --- Async scheduling from sync threads --- + + def _schedule_async(self, coro: Any) -> None: + if self._event_loop is not None and self._event_loop.is_running(): + asyncio.run_coroutine_threadsafe(coro, self._event_loop) + + # --- Broadcasting --- + + async def broadcast(self, event: str, data: Any) -> None: + """Broadcast a message to all connected WebSocket clients that have not seen this data yet.""" + disconnected = set() + message = custom_json_dumps({event: data}) + + for websocket in self.ws_connections.keys(): + if self.ws_connections[websocket].get(event) == message: + continue + try: + await websocket.send_text(message) + self.ws_connections[websocket][event] = message + except Exception as e: + logger.error(f"Error sending to websocket: {e}") + disconnected.add(websocket) + + for ws in disconnected: + self.ws_connections.pop(ws, None) + + async def broadcast_all(self) -> None: + await self.broadcast("branches", self.get_global_branches_to_emit()) + await self.broadcast("environments", self.get_global_envs_to_emit()) + + async def broadcast_branches(self, data: Any) -> None: + await self.broadcast("branches", data) + + async def broadcast_environments(self, data: Any) -> None: + await self.broadcast("environments", data) + + async def broadcast_error(self, data: Any) -> None: + await self.broadcast("error", data) + + def emit_envs(self) -> None: + """Sync callback used by App's processing thread to push updates to clients.""" + self._schedule_async(self.broadcast_branches(self.get_global_branches_to_emit())) + self._schedule_async(self.broadcast_environments(self.get_global_envs_to_emit())) + + # --- Routes --- + + async def serve_index(self) -> FileResponse: + return FileResponse(os.path.join(FRONTEND_DIR, 'index.html')) + + async def serve_state(self) -> Response: + return Response(content=custom_json_dumps(self.get_global_envs_to_emit()), media_type="application/json") + + async def serve_branches_route(self) -> Response: + return Response(content=custom_json_dumps(self.get_global_branches_to_emit()), media_type="application/json") + + async def serve_static(self, path: str) -> FileResponse: + file_path = os.path.join(FRONTEND_DIR, path) + if os.path.exists(file_path) and os.path.isfile(file_path): + return FileResponse(file_path) + return FileResponse(os.path.join(FRONTEND_DIR, 'index.html')) + + async def websocket_endpoint(self, websocket: WebSocket) -> None: + await websocket.accept() + self.ws_connections[websocket] = {} + + try: + # Send initial state on connect and record it so duplicate broadcasts are suppressed + branches_payload = custom_json_dumps({"branches": self.get_global_branches_to_emit()}) + envs_payload = custom_json_dumps({"environments": self.get_global_envs_to_emit()}) + await websocket.send_text(branches_payload) + self.ws_connections[websocket]["branches"] = branches_payload + await websocket.send_text(envs_payload) + self.ws_connections[websocket]["environments"] = envs_payload + + while True: + data = await websocket.receive_text() + message = json.loads(data) + + if "update" in message: + update_data = message.get("update") or {} + logger.info(f"Received environment update: {update_data}") + if self.secondaryManager: + await self.secondaryManager.send({"update": update_data}) + id = update_data.get('id', '') + if id == '': + reset_caches(list(self.core.environments.values())) + elif id not in self.core.environments.keys() and id not in {j for it in self.secondaryManager or [] for j in it.environments.keys()}: + logger.warning(f"Received update for unknown environment id {id}") + continue + elif id in self.core.environments.keys(): + env = self.core.environments.get(id, None) + expected_token = update_data.get('token', '') + if 'branches' in update_data: + if not env: + raise RuntimeError(f"Unknown env {update_data.get('id', '')}") + env.state.set_branches(update_data.get('branches', []), expected_token=expected_token) + if 'dry' in update_data: + if not env: + raise RuntimeError(f"Unknown env {update_data.get('id', '')}") + env.state.set_dry(bool(update_data['dry']), expected_token) + + if env: + p = get_step(env.pipeline, type(env.state)) + if isinstance(p, CachingStep): + p.reset() + logger.info(f"Updated environment {env.id} branches to {update_data.get('branches')}, dry={update_data.get('dry')}") + self.core.environment_update_event.set() + + await self.broadcast_environments(self.get_global_envs_to_emit()) + + except WebSocketDisconnect: + self.ws_connections.pop(websocket, None) + except Exception as e: + logger.error(f"WebSocket error: {e}:{traceback.format_exc()}") + await self.broadcast_error({'message': f'{e}:{traceback.format_exc()}'}) + + # --- Run --- + + def start(self) -> None: + import uvicorn + uvicorn.run(self.app, host='0.0.0.0', port=self.port, log_level='info') -- 2.54.0 From d3991c4331d574c1bcd979bb543061d674b2f71e Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 18:56:24 +0200 Subject: [PATCH 02/15] x --- backend/app.py | 129 ++++++++++++++++--------------- backend/web.py | 1 - tests/test_containertest.py | 3 +- tests/test_dry_run_playwright.py | 3 +- 4 files changed, 70 insertions(+), 66 deletions(-) diff --git a/backend/app.py b/backend/app.py index bc783ae..1ff0b8f 100644 --- a/backend/app.py +++ b/backend/app.py @@ -6,6 +6,7 @@ import threading import traceback from typing import Any, Callable, Dict, List, Optional +from secondary import SecondaryManager from utils import sigchld_handler from dotenv import load_dotenv @@ -22,74 +23,75 @@ load_dotenv("local.env") load_dotenv('/run/secrets/brencher-secrets') +def build_environments(cli_env_ids_str: str, dry_run: bool = False) -> Dict[str, Environment]: + import configs.brencher + import configs.brencher2 + import configs.brencher_local2 + import configs.brencher_local1 + import configs.torrserv_proxy + import configs.immich + import configs.registry + import configs.gmail_mcp + environments_l: List[Environment] = [ + configs.brencher.brencher, + configs.brencher2.brencher2, + configs.brencher_local2.brencher_local2, + configs.brencher_local1.brencher_local1, + configs.torrserv_proxy.torrserv_proxy, + configs.immich.immich, + configs.registry.registry, + configs.gmail_mcp.gmail_mcp, + ] + environments: Dict[str, Environment] = {e.id: e for e in environments_l} + + logger.info(f"cli_env_ids {cli_env_ids_str}") + if len(cli_env_ids_str) > 0 and cli_env_ids_str[0] == '-': + cli_env_ids = cli_env_ids_str[1:].split(',') + cli_env_ids = [x for x in cli_env_ids if len(x) > 0] + logger.info(f"cli_env_ids (minus) {cli_env_ids}") + if cli_env_ids and len(cli_env_ids) > 0: + 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 + ] + } + logger.info(f"cli_env_ids {cli_env_pairs}") + if cli_env_pairs and len(cli_env_pairs) > 0: + environments = {k: e for k, e in environments.items() if k in cli_env_pairs.keys()} + for k, v in cli_env_pairs.items(): + if v is not None: + if k in environments: + env = environments[k] + for step in env.pipeline: + resolve_step = step + if isinstance(step, CachingStep): + resolve_step = step._step + if isinstance(resolve_step, SharedStateHolder): + resolve_step.set_branches([(v, 'HEAD')]) + logger.info(f"Overriding environment {k} branches to {(v, 'HEAD')}") + else: + logger.warning(f"Environment {k} not found to override branches") + else: + logger.info(f"No branch override for environment {k}") + if dry_run: + for e in environments.values(): + e.state.set_dry(True) + + logger.info(f"Resulting profiles {environments.keys()}") + + return environments + + class App: - def __init__(self, cli_env_ids_str: str, dry_run: bool = False) -> None: - - self.environments: Dict[str, Environment] = {} + def __init__(self, environments: Dict[str, Environment]) -> None: + self.environments: Dict[str, Environment] = {id: wrap_in_cached(e) for id, e in environments.items()} self.state_lock = threading.Lock() self.environment_update_event = threading.Event() self.emit_callback: Optional[Callable[[], None]] = None - import configs.brencher - import configs.brencher2 - import configs.brencher_local2 - import configs.brencher_local1 - import configs.torrserv_proxy - import configs.immich - import configs.registry - import configs.gmail_mcp - environments_l: List[Environment] = [ - configs.brencher.brencher, - configs.brencher2.brencher2, - configs.brencher_local2.brencher_local2, - configs.brencher_local1.brencher_local1, - configs.torrserv_proxy.torrserv_proxy, - configs.immich.immich, - configs.registry.registry, - configs.gmail_mcp.gmail_mcp, - ] - self.environments = {e.id: e for e in environments_l} - - logger.info(f"cli_env_ids {cli_env_ids_str}") - if len(cli_env_ids_str) > 0 and cli_env_ids_str[0] == '-': - cli_env_ids = cli_env_ids_str[1:].split(',') - cli_env_ids = [x for x in cli_env_ids if len(x) > 0] - logger.info(f"cli_env_ids (minus) {cli_env_ids}") - if cli_env_ids and len(cli_env_ids) > 0: - self.environments = {k: e for k, e in self.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 - ] - } - logger.info(f"cli_env_ids {cli_env_pairs}") - if cli_env_pairs and len(cli_env_pairs) > 0: - self.environments = {k: e for k, e in self.environments.items() if k in cli_env_pairs.keys()} - for k, v in cli_env_pairs.items(): - if v is not None: - if k in self.environments: - env = self.environments[k] - for step in env.pipeline: - resolve_step = step - if isinstance(step, CachingStep): - resolve_step = step._step - if isinstance(resolve_step, SharedStateHolder): - resolve_step.set_branches([(v, 'HEAD')]) - logger.info(f"Overriding environment {k} branches to {(v, 'HEAD')}") - else: - logger.warning(f"Environment {k} not found to override branches") - else: - logger.info(f"No branch override for environment {k}") - if dry_run: - for id, e in self.environments.items(): - e.state.set_dry(True) - - logger.info(f"Resulting profiles {self.environments.keys()}") - - self.environments = {id: wrap_in_cached(e) for id, e in self.environments.items()} - def get_local_envs_to_emit(self) -> Dict[str, Dict[str, Any]]: env_dtos: Dict[str, Dict[str, Any]] = {} for env in self.environments.values(): @@ -186,7 +188,8 @@ if __name__ == '__main__': cli_env_ids_str = cli_env_ids_list[0] signal.signal(signal.SIGCHLD, sigchld_handler) - app1 = App(cli_env_ids_str, 'dry' in sys.argv[1:]) + environments = build_environments(cli_env_ids_str, 'dry' in sys.argv[1:]) + app1 = App(environments) if 'noweb' in sys.argv[1:]: app1.runHeadless() diff --git a/backend/web.py b/backend/web.py index e25f57a..ec10265 100644 --- a/backend/web.py +++ b/backend/web.py @@ -48,7 +48,6 @@ class WebApp: self.ws_connections: Dict[WebSocket, Dict[str, Any]] = {} self._event_loop: Optional[asyncio.AbstractEventLoop] = None - self.secondaryManager: Optional[SecondaryManager] = None @asynccontextmanager async def lifespan(fastapi_app: FastAPI) -> AsyncIterator[None]: diff --git a/tests/test_containertest.py b/tests/test_containertest.py index 3ef74a1..577a3b3 100644 --- a/tests/test_containertest.py +++ b/tests/test_containertest.py @@ -8,6 +8,7 @@ import docker import pytest import requests from app import App +from configs import brencher_local1 from .conftest import EventuallyFn logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') @@ -34,7 +35,7 @@ class TestDockerContainer: async def test_start(self, eventually: EventuallyFn) -> None: logger.info(f"Starting") - app = App(cli_env_ids_str="brencher_local1") + app = App({"brencher_local1": brencher_local1.brencher_local1}) # app.runWeb(5001) processing = threading.Thread(target=lambda: app.runWeb(5001), daemon=True) processing.start() diff --git a/tests/test_dry_run_playwright.py b/tests/test_dry_run_playwright.py index afe020b..4ef1e4c 100644 --- a/tests/test_dry_run_playwright.py +++ b/tests/test_dry_run_playwright.py @@ -8,6 +8,7 @@ import requests from playwright.sync_api import Page, sync_playwright from app import App from .conftest import EventuallyFn +from configs import brencher_local1 logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) @@ -42,7 +43,7 @@ class TestDryRunPlaywright: def test_dry_run_prevents_deploy_until_disabled(self, eventually: EventuallyFn) -> None: # Start app with brencher_local1 with main branch pre-selected. # App starts with dry=True by default (SharedStateHolderInMemory default). - app = App(cli_env_ids_str=f"{ENV_ID}:main") + app = App({"brencher_local1": brencher_local1.brencher_local1}) server_thread = threading.Thread(target=lambda: app.runWeb(APP_PORT), daemon=True) server_thread.start() -- 2.54.0 From b5e8153a004d979ab77e5203493784fa377da2f7 Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 19:14:55 +0200 Subject: [PATCH 03/15] x --- backend/app.py | 69 ++++---------------------------------- backend/discover_envs.py | 71 ++++++++++++++++++++++++++++++++++++++++ backend/web.py | 3 +- 3 files changed, 79 insertions(+), 64 deletions(-) create mode 100644 backend/discover_envs.py diff --git a/backend/app.py b/backend/app.py index 1ff0b8f..0ced9f9 100644 --- a/backend/app.py +++ b/backend/app.py @@ -6,7 +6,7 @@ import threading import traceback from typing import Any, Callable, Dict, List, Optional -from secondary import SecondaryManager +from discover_envs import build_environments, parse_arguments from utils import sigchld_handler from dotenv import load_dotenv @@ -23,67 +23,6 @@ load_dotenv("local.env") load_dotenv('/run/secrets/brencher-secrets') -def build_environments(cli_env_ids_str: str, dry_run: bool = False) -> Dict[str, Environment]: - import configs.brencher - import configs.brencher2 - import configs.brencher_local2 - import configs.brencher_local1 - import configs.torrserv_proxy - import configs.immich - import configs.registry - import configs.gmail_mcp - environments_l: List[Environment] = [ - configs.brencher.brencher, - configs.brencher2.brencher2, - configs.brencher_local2.brencher_local2, - configs.brencher_local1.brencher_local1, - configs.torrserv_proxy.torrserv_proxy, - configs.immich.immich, - configs.registry.registry, - configs.gmail_mcp.gmail_mcp, - ] - environments: Dict[str, Environment] = {e.id: e for e in environments_l} - - logger.info(f"cli_env_ids {cli_env_ids_str}") - if len(cli_env_ids_str) > 0 and cli_env_ids_str[0] == '-': - cli_env_ids = cli_env_ids_str[1:].split(',') - cli_env_ids = [x for x in cli_env_ids if len(x) > 0] - logger.info(f"cli_env_ids (minus) {cli_env_ids}") - if cli_env_ids and len(cli_env_ids) > 0: - 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 - ] - } - logger.info(f"cli_env_ids {cli_env_pairs}") - if cli_env_pairs and len(cli_env_pairs) > 0: - environments = {k: e for k, e in environments.items() if k in cli_env_pairs.keys()} - for k, v in cli_env_pairs.items(): - if v is not None: - if k in environments: - env = environments[k] - for step in env.pipeline: - resolve_step = step - if isinstance(step, CachingStep): - resolve_step = step._step - if isinstance(resolve_step, SharedStateHolder): - resolve_step.set_branches([(v, 'HEAD')]) - logger.info(f"Overriding environment {k} branches to {(v, 'HEAD')}") - else: - logger.warning(f"Environment {k} not found to override branches") - else: - logger.info(f"No branch override for environment {k}") - if dry_run: - for e in environments.values(): - e.state.set_dry(True) - - logger.info(f"Resulting profiles {environments.keys()}") - - return environments - - class App: def __init__(self, environments: Dict[str, Environment]) -> None: @@ -188,7 +127,11 @@ if __name__ == '__main__': cli_env_ids_str = cli_env_ids_list[0] signal.signal(signal.SIGCHLD, sigchld_handler) - environments = build_environments(cli_env_ids_str, 'dry' in sys.argv[1:]) + environments = build_environments(cli_env_ids_str) + if 'dry' in sys.argv[1:]: + for e in environments.values(): + e.state.set_dry(True) + app1 = App(environments) if 'noweb' in sys.argv[1:]: diff --git a/backend/discover_envs.py b/backend/discover_envs.py new file mode 100644 index 0000000..1423bea --- /dev/null +++ b/backend/discover_envs.py @@ -0,0 +1,71 @@ +import importlib +import logging +import pkgutil +from dataclasses import dataclass, field +from typing import Dict, List, Optional + +from enironment import Environment, SharedStateHolder +from steps.step import CachingStep + +logger = logging.getLogger(__name__) + +@dataclass +class ParsedEnvArgs: + excludes: List[str] = field(default_factory=list) + includes: Dict[str, Optional[str]] = field(default_factory=dict) + + +def parse_arguments(cli_env_ids_str: str) -> ParsedEnvArgs: + logger.info(f"cli_env_ids {cli_env_ids_str}") + if len(cli_env_ids_str) > 0 and cli_env_ids_str[0] == '-': + excludes = [x for x in cli_env_ids_str[1:].split(',') if len(x) > 0] + logger.info(f"cli_env_ids (minus) {excludes}") + return ParsedEnvArgs(excludes=excludes) + + includes: Dict[str, Optional[str]] = { + 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] + } + logger.info(f"cli_env_ids {includes}") + return ParsedEnvArgs(includes=includes) + + +def _discover_environments() -> Dict[str, Environment]: + import configs + found: Dict[str, Environment] = {} + seen: set[int] = set() + for module_info in pkgutil.iter_modules(configs.__path__, prefix=f"{configs.__name__}."): + module = importlib.import_module(module_info.name) + for value in vars(module).values(): + if isinstance(value, Environment) and id(value) not in seen: + seen.add(id(value)) + found[value.id] = value + return found + + +def build_environments(cli_env_ids_str: str) -> Dict[str, Environment]: + environments: Dict[str, Environment] = _discover_environments() + args: ParsedEnvArgs = parse_arguments(cli_env_ids_str) + + if args.excludes: + environments = {k: e for k, e in environments.items() if k not in args.excludes} + elif args.includes: + environments = {k: e for k, e in environments.items() if k in args.includes} + for k, v in args.includes.items(): + if v is None: + logger.info(f"No branch override for environment {k}") + continue + if k not in environments: + logger.warning(f"Environment {k} not found to override branches") + continue + env = environments[k] + for step in env.pipeline: + resolve_step = step + if isinstance(step, CachingStep): + resolve_step = step._step + if isinstance(resolve_step, SharedStateHolder): + resolve_step.set_branches([(v, 'HEAD')]) + logger.info(f"Overriding environment {k} branches to {(v, 'HEAD')}") + + logger.info(f"Resulting profiles {environments.keys()}") + return environments diff --git a/backend/web.py b/backend/web.py index ec10265..461ffe6 100644 --- a/backend/web.py +++ b/backend/web.py @@ -48,7 +48,8 @@ class WebApp: self.ws_connections: Dict[WebSocket, Dict[str, Any]] = {} self._event_loop: Optional[asyncio.AbstractEventLoop] = None - + self.secondaryManager: Optional[SecondaryManager] = None + @asynccontextmanager async def lifespan(fastapi_app: FastAPI) -> AsyncIterator[None]: self._event_loop = asyncio.get_event_loop() -- 2.54.0 From 2e84fb0ad4e8159142522631905f5cce806d222f Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 20:45:47 +0200 Subject: [PATCH 04/15] x --- .github/skills/playwright-brencher/SKILL.md | 53 ++++++++++++ tests/conftest.py | 10 +-- tests/playwright_helper.py | 65 ++++++++++++++ tests/test_dry_run_playwright.py | 93 +++++++-------------- 4 files changed, 153 insertions(+), 68 deletions(-) create mode 100644 .github/skills/playwright-brencher/SKILL.md create mode 100644 tests/playwright_helper.py diff --git a/.github/skills/playwright-brencher/SKILL.md b/.github/skills/playwright-brencher/SKILL.md new file mode 100644 index 0000000..ad65794 --- /dev/null +++ b/.github/skills/playwright-brencher/SKILL.md @@ -0,0 +1,53 @@ +--- +name: playwright-brencher +description: "Write or refactor Playwright tests for brencher UI. Use when creating page helpers, extracting browser code from tests, or enforcing set_/verify_ method naming." +--- + +# Playwright Brencher Conventions + +Use this skill when writing or refactoring Playwright tests in this repository. + +## Required API Shape + +Create and use a context manager in this style: + +```python +with brencher_page(APP_URL) as page: + page.verify_dry_run_on() + page.set_dry_run_off() + page.verify_dry_run_off() +``` + +## Naming Rules + +1. Action methods that change UI/application state must use `set_...` names. +2. Verification methods (assertions, waits, checks) must use `verify_...` names. +3. Keep low-level selector helpers private (prefix `_`). +4. Prefer one page-object class per screen/area (`BrencherPage` for the current app page). + +## Structure Rules + +1. Put shared Playwright helpers in `tests/playwright_helper.py`. +2. Keep tests focused on scenario flow; move DOM selectors and waiting logic into page helper methods. +3. Use context manager functions to own Playwright/browser lifecycle. +4. Inline trivial one-use logic where it improves readability and does not duplicate behavior. + +## Method Guidance + +Recommended style for page object methods: + +- `set_*`: click/toggle/type actions. +- `verify_*`: assert visible state, button title/text, or wait until target state is reached. + +Example method names: + +- `set_dry_run_off` +- `verify_dry_run_on` +- `verify_dry_run_off` + +## Review Checklist + +1. Test uses `with brencher_page(...) as page` style. +2. No direct `sync_playwright()` block remains in the test body when helper abstraction is intended. +3. Action and verification methods follow `set_` / `verify_` naming. +4. Selector details are encapsulated in private helper methods. diff --git a/tests/conftest.py b/tests/conftest.py index 8a8dea8..99257b7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -36,15 +36,15 @@ class EventuallyFn(Protocol): def eventually() -> EventuallyFn: def _eventually(assert_fn: Callable[[], bool], timeout: float = 2.0, interval: float = 0.05) -> None: deadline = time.monotonic() + timeout - last_error = None + last_error: BaseException | None = None while time.monotonic() < deadline: try: - res = assert_fn() - if res: + if assert_fn(): return - except AssertionError as err: + last_error = None + except Exception as err: last_error = err - time.sleep(interval) + time.sleep(interval) raise AssertionError(f"Condition not met within {timeout:.2f}s") from last_error diff --git a/tests/playwright_helper.py b/tests/playwright_helper.py new file mode 100644 index 0000000..953c5ee --- /dev/null +++ b/tests/playwright_helper.py @@ -0,0 +1,65 @@ +import logging +from contextlib import contextmanager +from typing import Generator + +from playwright.sync_api import Locator, Page, sync_playwright + + +logger = logging.getLogger(__name__) + + +class BrencherPage: + + def __init__(self, page: Page, env_id: str, action_logger: logging.Logger) -> None: + self._page = page + self._env_id = env_id + self._logger = action_logger + + def _dry_run_button(self) -> Locator: + button = self._page.locator(f'h3:has-text("{self._env_id}") button.dry-run-btn') + button.wait_for(state="visible", timeout=10000) + return button + + def verify_dry_run_on(self) -> None: + btn_title = self._dry_run_button().get_attribute("title") or "" + assert "Dry run on" in btn_title, f"Expected dry run to be active, got title: {btn_title!r}" + self._logger.info(f"Dry-run button title before click: {btn_title!r}") + + def set_dry_run_off(self) -> None: + self._dry_run_button().click() + self._logger.info("Clicked dry-run button to disable dry run") + + def click_refresh(self) -> None: + self._page.locator("#refresh-branches").click() + self._logger.info("Clicked refresh button") + + def verify_dry_run_off(self) -> None: + self._page.wait_for_function( + """(targetEnvId) => { + const h3s = [...document.querySelectorAll('h3.env-title')]; + const h3 = h3s.find(el => el.textContent.includes(targetEnvId)); + if (!h3) return false; + const btn = h3.querySelector('button.dry-run-btn'); + return btn && !btn.title.includes('Dry run on'); + }""", + arg=self._env_id, + timeout=10000, + ) + + +@contextmanager +def brencher_page( + app_link: str, + env_id: str = "brencher_local1", + action_logger: logging.Logger | None = None, +) -> Generator[BrencherPage, None, None]: + active_logger = action_logger or logger + with sync_playwright() as playwright: + browser = playwright.chromium.launch(headless=True) + page = browser.new_page() + page.goto(app_link) + page.wait_for_load_state("networkidle") + try: + yield BrencherPage(page, env_id, active_logger) + finally: + browser.close() diff --git a/tests/test_dry_run_playwright.py b/tests/test_dry_run_playwright.py index 4ef1e4c..a28f8c6 100644 --- a/tests/test_dry_run_playwright.py +++ b/tests/test_dry_run_playwright.py @@ -1,13 +1,13 @@ import logging import threading -from typing import Any, Generator +from typing import Any, Callable, Generator import docker import pytest import requests -from playwright.sync_api import Page, sync_playwright from app import App from .conftest import EventuallyFn +from .playwright_helper import brencher_page from configs import brencher_local1 logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') @@ -19,14 +19,10 @@ ENV_ID = "brencher_local1" CONTAINER_NAME = "brencher_plain-container" -def _get_pipeline_step(state_data: Any, env_id: str, step_name: str) -> Any: - pipeline = state_data[env_id]["pipeline"] - for step in pipeline: - if step["name"] == step_name: - return step - return None +def _check_state(url: str, predicate: Callable[[Any], bool]) -> bool: + state_data = requests.get(f"{url}/state", timeout=5).json() + return predicate(state_data) -@pytest.mark.skip class TestDryRunPlaywright: @pytest.fixture(autouse=True) @@ -41,9 +37,11 @@ class TestDryRunPlaywright: logger.info(f"Container {CONTAINER_NAME} stopped and removed") def test_dry_run_prevents_deploy_until_disabled(self, eventually: EventuallyFn) -> None: - # Start app with brencher_local1 with main branch pre-selected. - # App starts with dry=True by default (SharedStateHolderInMemory default). - app = App({"brencher_local1": brencher_local1.brencher_local1}) + # Start app with brencher_local1 with main branch pre-selected and dry mode on. + env = brencher_local1.brencher_local1 + env.state.set_branches([("main", "HEAD")]) + env.state.set_dry(True) + app = App({"brencher_local1": env}) server_thread = threading.Thread(target=lambda: app.runWeb(APP_PORT), daemon=True) server_thread.start() @@ -57,14 +55,13 @@ class TestDryRunPlaywright: # Wait for the pipeline to stabilize with dry=True: # DockerContainerDeploy should return status="dry-run" - def _deploy_is_dry_run() -> bool: - state_data = requests.get(f"{APP_URL}/state", timeout=5).json() - step = _get_pipeline_step(state_data, ENV_ID, "DockerContainerDeploy") - if step is None or step.get("error"): - return False - return step["status"].get("status") == "dry-run" - - eventually(_deploy_is_dry_run, timeout=120.0, interval=2.0) + eventually( + lambda: _check_state(APP_URL, lambda s: next( + p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy" + )["status"].get("status") == "dry-run"), + timeout=120.0, + interval=2.0, + ) logger.info("Pipeline is in dry-run mode") # Verify no real container was created @@ -72,51 +69,21 @@ class TestDryRunPlaywright: real_containers = docker_client.containers.list(filters={"name": CONTAINER_NAME}, all=True) assert len(real_containers) == 0, "Container should NOT exist during dry run" - # Open browser and click the dry-run button to disable dry run - with sync_playwright() as p: - browser = p.chromium.launch(headless=True) - page: Page = browser.new_page() - page.goto(APP_URL) - page.wait_for_load_state("networkidle") - - # The dry-run button shows ⏸ when active (dry=True) and ▶ when disabled (dry=False). - # It is inside the h3 heading for brencher_local1. - dry_run_btn = page.locator(f'h3:has-text("{ENV_ID}") button.dry-run-btn') - dry_run_btn.wait_for(state="visible", timeout=10000) - - # Verify button indicates dry-run is currently active (title contains "Dry run on") - btn_title = dry_run_btn.get_attribute("title") or "" - assert "Dry run on" in btn_title, f"Expected dry run to be active, got title: {btn_title!r}" - logger.info(f"Dry-run button title before click: {btn_title!r}") - - # Click to disable dry run - dry_run_btn.click() - logger.info("Clicked dry-run button to disable dry run") - - # Wait for button to update to "Running" state (title no longer says "Dry run on") - page.wait_for_function( - """(envId) => { - const h3s = [...document.querySelectorAll('h3.env-title')]; - const h3 = h3s.find(el => el.textContent.includes(envId)); - if (!h3) return false; - const btn = h3.querySelector('button.dry-run-btn'); - return btn && !btn.title.includes('Dry run on'); - }""", - arg=ENV_ID, - timeout=10000, - ) - - browser.close() + # Open browser and disable dry run from the UI. + with brencher_page(APP_URL) as page: + page.verify_dry_run_on() + page.set_dry_run_off() + page.verify_dry_run_off() + page.click_refresh() # Wait for pipeline to re-run and actually deploy the container - def _deploy_is_running() -> bool: - state_data = requests.get(f"{APP_URL}/state", timeout=5).json() - step = _get_pipeline_step(state_data, ENV_ID, "DockerContainerDeploy") - if step is None or step.get("error"): - return False - return step["status"].get("status") == "running" - - eventually(_deploy_is_running, timeout=300.0, interval=5.0) + eventually( + lambda: _check_state(APP_URL, lambda s: next( + p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy" + )["status"].get("status") == "running"), + timeout=300.0, + interval=5.0, + ) logger.info("Container deployed and running after dry run disabled") # Final sanity: real container must exist and be running -- 2.54.0 From f0e4bd8ea589a898addf7edb0f6da30250b40156 Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 20:50:47 +0200 Subject: [PATCH 05/15] x --- tests/test_dry_run_playwright.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_dry_run_playwright.py b/tests/test_dry_run_playwright.py index a28f8c6..c528a16 100644 --- a/tests/test_dry_run_playwright.py +++ b/tests/test_dry_run_playwright.py @@ -59,7 +59,7 @@ class TestDryRunPlaywright: lambda: _check_state(APP_URL, lambda s: next( p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy" )["status"].get("status") == "dry-run"), - timeout=120.0, + timeout=10.0, interval=2.0, ) logger.info("Pipeline is in dry-run mode") @@ -81,8 +81,8 @@ class TestDryRunPlaywright: lambda: _check_state(APP_URL, lambda s: next( p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy" )["status"].get("status") == "running"), - timeout=300.0, - interval=5.0, + timeout=10.0, + interval=2.0, ) logger.info("Container deployed and running after dry run disabled") -- 2.54.0 From 5abfc44e6f6aab279fcfe9b993bf583ecf29e52e Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 21:09:34 +0200 Subject: [PATCH 06/15] x --- tests/conftest.py | 6 ++-- tests/playwright_helper.py | 45 +++++++++++++++++++++++++++ tests/test_dry_run_playwright.py | 53 +++++++++++++++----------------- 3 files changed, 72 insertions(+), 32 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 99257b7..38f7b0c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,14 +27,14 @@ class EventuallyFn(Protocol): def __call__( self, assert_fn: Callable[[], bool], - timeout: float = 2.0, - interval: float = 0.05, + timeout: float = 5.0, + interval: float = 0.5, ) -> None: ... @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 = 5.0, interval: float = 0.5) -> None: deadline = time.monotonic() + timeout last_error: BaseException | None = None while time.monotonic() < deadline: diff --git a/tests/playwright_helper.py b/tests/playwright_helper.py index 953c5ee..d4ea079 100644 --- a/tests/playwright_helper.py +++ b/tests/playwright_helper.py @@ -46,6 +46,51 @@ class BrencherPage: timeout=10000, ) + def verify_pipeline_step_status(self, step_name: str, expected_status: str, timeout_ms: int = 10000) -> None: + """ + Verify that a pipeline step reaches the expected status by polling the page DOM. + + Args: + step_name: Name of the pipeline step (e.g., "DockerContainerDeploy") + expected_status: Expected status value ("running", "ok", "error", or "dry-run") + timeout_ms: Timeout in milliseconds (default 10000) + """ + # JavaScript to check pipeline step status + js_check = """(stepName, expectedStatus) => { + const jobItems = document.querySelectorAll('.job-item'); + for (const item of jobItems) { + const headerText = item.querySelector('.job-header')?.textContent || ''; + if (headerText.includes(stepName)) { + const spinner = item.querySelector('.step-spinner'); + const errorIndicator = item.querySelector('span[title="Error"]'); + + if (expectedStatus === 'running') { + return spinner !== null; + } else if (expectedStatus === 'ok') { + return spinner === null && errorIndicator === null; + } else if (expectedStatus === 'error') { + return errorIndicator !== null; + } else if (expectedStatus === 'dry-run') { + // For dry-run, check the spoiler content + const spoiler = item.querySelector('.job-spoiler'); + if (spoiler && spoiler.style.display !== 'none') { + const statusText = spoiler.textContent; + return statusText.includes('dry-run') || statusText.includes('dry_run'); + } + return false; + } + } + } + return false; + }""" + + self._page.wait_for_function( + js_check, + arg=[step_name, expected_status], + timeout=timeout_ms, + ) + self._logger.info(f"Pipeline step '{step_name}' reached status '{expected_status}'") + @contextmanager def brencher_page( diff --git a/tests/test_dry_run_playwright.py b/tests/test_dry_run_playwright.py index c528a16..1f92cbc 100644 --- a/tests/test_dry_run_playwright.py +++ b/tests/test_dry_run_playwright.py @@ -46,44 +46,39 @@ class TestDryRunPlaywright: server_thread.start() # Wait for server to be up - eventually( - lambda: requests.get(f"{APP_URL}/state", timeout=5).status_code == 200, - timeout=20.0, - interval=1.0, - ) + eventually(lambda: requests.get(f"{APP_URL}/state", timeout=5).status_code == 200) logger.info("Server is up") # Wait for the pipeline to stabilize with dry=True: # DockerContainerDeploy should return status="dry-run" - eventually( - lambda: _check_state(APP_URL, lambda s: next( - p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy" - )["status"].get("status") == "dry-run"), - timeout=10.0, - interval=2.0, - ) - logger.info("Pipeline is in dry-run mode") - - # Verify no real container was created - docker_client = docker.from_env() - real_containers = docker_client.containers.list(filters={"name": CONTAINER_NAME}, all=True) - assert len(real_containers) == 0, "Container should NOT exist during dry run" - - # Open browser and disable dry run from the UI. with brencher_page(APP_URL) as page: + eventually( + lambda: _check_state(APP_URL, lambda s: next( + p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy" + )["status"].get("status") == "dry-run"), + ) + + # page.verify_pipeline_step_status("DockerContainerDeploy", "dry-run") + logger.info("Pipeline is in dry-run mode") + + # Verify no real container was created + docker_client = docker.from_env() + real_containers = docker_client.containers.list(filters={"name": CONTAINER_NAME}, all=True) + assert len(real_containers) == 0, "Container should NOT exist during dry run" + + # Disable dry run from the UI. page.verify_dry_run_on() page.set_dry_run_off() page.verify_dry_run_off() - page.click_refresh() + page.click_refresh() # TODO Remove it - # Wait for pipeline to re-run and actually deploy the container - eventually( - lambda: _check_state(APP_URL, lambda s: next( - p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy" - )["status"].get("status") == "running"), - timeout=10.0, - interval=2.0, - ) + # Wait for pipeline to re-run and actually deploy the container + eventually( + lambda: _check_state(APP_URL, lambda s: next( + p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy" + )["status"].get("status") == "running"), + ) + # page.verify_pipeline_step_status("DockerContainerDeploy", "running") logger.info("Container deployed and running after dry run disabled") # Final sanity: real container must exist and be running -- 2.54.0 From 7a53fbe4997e4c0699a714e4fa0752581693e61c Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 21:10:43 +0200 Subject: [PATCH 07/15] x --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 9082e92..9c3e46a 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: python-version: [ - # "3.11", + "3.11.3", "3.12.3", "3.13", "3.14", -- 2.54.0 From 55fbeb31875ba3741601234ec86ba26d7b35e220 Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 21:11:37 +0200 Subject: [PATCH 08/15] x --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 9c3e46a..81a300c 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: python-version: [ - "3.11.3", + # "3.11.3", "3.12.3", "3.13", "3.14", -- 2.54.0 From 9e3c05540f33ccb642a4611a1a731fdfbcb855f6 Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 22:56:20 +0200 Subject: [PATCH 09/15] x --- .github/workflows/python-package.yml | 37 +++++++++++++++++++++++++--- requirements-dev.txt | 1 + 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 81a300c..f4c3a92 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -12,7 +12,6 @@ on: jobs: build: - runs-on: ubuntu-latest strategy: fail-fast: false @@ -31,7 +30,6 @@ jobs: "flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics", # "ty check backend", "mypy --no-incremental --config-file mypy.ini backend tests", - "pytest", ] steps: @@ -43,8 +41,41 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install flake8 pytest ty pip install -r requirements.txt pip install -r requirements-dev.txt - name: Run checker run: ${{ matrix.checker }} + + tests: + runs-on: ubuntu-latest + needs: build + strategy: + fail-fast: false + matrix: + python-version: [ + # "3.11.3", + "3.12.3", + "3.13", + "3.14", + # "3.15", + ] + checker: [ + "pytest", + ] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }}, ${{ matrix.checker }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get upgrade -y + sudo apt-get install -y --no-install-recommends git docker.io + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + - name: Run checker + run: "pytest" + + diff --git a/requirements-dev.txt b/requirements-dev.txt index 2e8e792..734d36c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,6 +5,7 @@ pytest-asyncio playwright pytest-playwright mypy +flake8 ty types-PyYAML types-requests -- 2.54.0 From c38b91d555c6e7acd56d048e767f0678f91e7d25 Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 22:58:47 +0200 Subject: [PATCH 10/15] x --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index f4c3a92..982ed44 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -71,7 +71,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get upgrade -y + # sudo apt-get upgrade -y sudo apt-get install -y --no-install-recommends git docker.io python -m pip install --upgrade pip pip install -r requirements-dev.txt -- 2.54.0 From 0b576ee4b58d0f604c7e4d632a3c1d19f051f4d7 Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 23:03:33 +0200 Subject: [PATCH 11/15] x --- .github/workflows/python-package.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 982ed44..c6daf49 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -70,11 +70,14 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - sudo apt-get update + # sudo apt-get update # sudo apt-get upgrade -y - sudo apt-get install -y --no-install-recommends git docker.io + # sudo apt-get install -y --no-install-recommends git docker.io python -m pip install --upgrade pip pip install -r requirements-dev.txt + playwright install --with-deps chromium + - name: Show Docker version + run: docker --version - name: Run checker run: "pytest" -- 2.54.0 From 8c13360c0cb522e3de0b05d229225bce6d772572 Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 23:29:00 +0200 Subject: [PATCH 12/15] x --- .github/workflows/python-package.yml | 2 -- tests/conftest.py | 26 ++++++++++++++++++++------ tests/test_containertest.py | 4 ++-- tests/test_dry_run_playwright.py | 23 ++++++++++------------- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c6daf49..e6fd1fd 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -76,8 +76,6 @@ jobs: python -m pip install --upgrade pip pip install -r requirements-dev.txt playwright install --with-deps chromium - - name: Show Docker version - run: docker --version - name: Run checker run: "pytest" diff --git a/tests/conftest.py b/tests/conftest.py index 38f7b0c..68e8d4b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,9 +4,10 @@ Pytest configuration and shared fixtures for integration tests. This file configures the Python path to allow importing backend modules and provides shared fixtures for all tests. """ -from typing import Generator, Callable, Protocol +from typing import Any, Generator, Callable, Protocol, TypeVar import pytest +import requests from tests.test_remote_repo import RemoteRepoHelper @@ -26,22 +27,35 @@ import pytest class EventuallyFn(Protocol): def __call__( self, - assert_fn: Callable[[], bool], + assert_fn: Callable[[], None], timeout: float = 5.0, interval: float = 0.5, ) -> None: ... +T = TypeVar('T') + +def assert_equal(a: T, b:T, message: str) -> None: + if a != b: + raise AssertionError(f"{message}: {a} != {b}") + +def _check_state(url: str, predicate: Callable[[Any], None]) -> None: + response = requests.get(f"{url}/state", timeout=5) + assert response.status_code == 200, f"Expected status code 200, got {response.status_code}" + state_data = response.json() + try: + predicate(state_data) + except Exception as e: + raise AssertionError(f"Predicate check failed with error: {e}\nState data: {state_data}") from e @pytest.fixture def eventually() -> EventuallyFn: - def _eventually(assert_fn: Callable[[], bool], timeout: float = 5.0, interval: float = 0.5) -> None: + def _eventually(assert_fn: Callable[[], None], timeout: float = 5.0, interval: float = 0.5) -> None: deadline = time.monotonic() + timeout last_error: BaseException | None = None while time.monotonic() < deadline: try: - if assert_fn(): - return - last_error = None + assert_fn() + return except Exception as err: last_error = err time.sleep(interval) diff --git a/tests/test_containertest.py b/tests/test_containertest.py index 577a3b3..665627f 100644 --- a/tests/test_containertest.py +++ b/tests/test_containertest.py @@ -9,7 +9,7 @@ import pytest import requests from app import App from configs import brencher_local1 -from .conftest import EventuallyFn +from .conftest import EventuallyFn, assert_equal logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) @@ -43,7 +43,7 @@ class TestDockerContainer: # await asyncio.sleep(5000) eventually( - lambda: requests.get("http://localhost:5001/state", timeout=5000).status_code == 200, + lambda: assert_equal(requests.get("http://localhost:5001/state", timeout=5000).status_code, 200, "Server did not respond with 200 OK within timeout"), 20.0, 1.0, ) diff --git a/tests/test_dry_run_playwright.py b/tests/test_dry_run_playwright.py index 1f92cbc..2cb673b 100644 --- a/tests/test_dry_run_playwright.py +++ b/tests/test_dry_run_playwright.py @@ -1,12 +1,12 @@ import logging import threading -from typing import Any, Callable, Generator +from typing import Any, Callable, Generator, TypeVar import docker import pytest import requests from app import App -from .conftest import EventuallyFn +from .conftest import EventuallyFn, _check_state, assert_equal from .playwright_helper import brencher_page from configs import brencher_local1 @@ -18,11 +18,6 @@ APP_URL = f"http://localhost:{APP_PORT}" ENV_ID = "brencher_local1" CONTAINER_NAME = "brencher_plain-container" - -def _check_state(url: str, predicate: Callable[[Any], bool]) -> bool: - state_data = requests.get(f"{url}/state", timeout=5).json() - return predicate(state_data) - class TestDryRunPlaywright: @pytest.fixture(autouse=True) @@ -46,16 +41,18 @@ class TestDryRunPlaywright: server_thread.start() # Wait for server to be up - eventually(lambda: requests.get(f"{APP_URL}/state", timeout=5).status_code == 200) + eventually(lambda: assert_equal(requests.get(f"{APP_URL}/state", timeout=5).status_code, 200, "Server did not respond with 200 OK within timeout")) logger.info("Server is up") # Wait for the pipeline to stabilize with dry=True: # DockerContainerDeploy should return status="dry-run" with brencher_page(APP_URL) as page: eventually( - lambda: _check_state(APP_URL, lambda s: next( - p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy" - )["status"].get("status") == "dry-run"), + lambda: _check_state(APP_URL, lambda s: assert_equal( + next(p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy")["status"].get('status'), + "dry-run", + "Pipeline step status is not 'dry-run'" + )), ) # page.verify_pipeline_step_status("DockerContainerDeploy", "dry-run") @@ -74,9 +71,9 @@ class TestDryRunPlaywright: # Wait for pipeline to re-run and actually deploy the container eventually( - lambda: _check_state(APP_URL, lambda s: next( + lambda: _check_state(APP_URL, lambda s: assert_equal(next( p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy" - )["status"].get("status") == "running"), + )["status"].get('status'), "running", "Pipeline step status is not 'running'")), ) # page.verify_pipeline_step_status("DockerContainerDeploy", "running") logger.info("Container deployed and running after dry run disabled") -- 2.54.0 From c00ebb7d6d625cefe8e000b7b8ee3e6ed2048b73 Mon Sep 17 00:00:00 2001 From: rudolf Date: Sat, 9 May 2026 23:55:34 +0200 Subject: [PATCH 13/15] x --- backend/steps/docker_plain.py | 4 ++++ tests/conftest.py | 2 +- tests/test_dry_run_playwright.py | 22 +++++++++++++--------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/backend/steps/docker_plain.py b/backend/steps/docker_plain.py index 7c7d2af..10836d2 100644 --- a/backend/steps/docker_plain.py +++ b/backend/steps/docker_plain.py @@ -71,6 +71,10 @@ class DockerImageBuild(AbstractStep[DockerImageBuildResult]): if len(existing_image) > 0 and not self.nocache: logger.info(f"Image {full_image} already exists locally with ID: {existing_image}") build_logs: List[str] = [] + elif self.env.dry: + logger.info(f"DRY RUN: Would build image {full_image}") + raise BaseException(f"Dry run - skipping actual build for {full_image}") + else: # Build the image build_logs = [] diff --git a/tests/conftest.py b/tests/conftest.py index 68e8d4b..cbd0085 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -38,7 +38,7 @@ def assert_equal(a: T, b:T, message: str) -> None: if a != b: raise AssertionError(f"{message}: {a} != {b}") -def _check_state(url: str, predicate: Callable[[Any], None]) -> None: +def check_state(url: str, predicate: Callable[[Any], None]) -> None: response = requests.get(f"{url}/state", timeout=5) assert response.status_code == 200, f"Expected status code 200, got {response.status_code}" state_data = response.json() diff --git a/tests/test_dry_run_playwright.py b/tests/test_dry_run_playwright.py index 2cb673b..175db58 100644 --- a/tests/test_dry_run_playwright.py +++ b/tests/test_dry_run_playwright.py @@ -6,7 +6,7 @@ import docker import pytest import requests from app import App -from .conftest import EventuallyFn, _check_state, assert_equal +from .conftest import EventuallyFn, assert_equal, check_state from .playwright_helper import brencher_page from configs import brencher_local1 @@ -48,11 +48,9 @@ class TestDryRunPlaywright: # DockerContainerDeploy should return status="dry-run" with brencher_page(APP_URL) as page: eventually( - lambda: _check_state(APP_URL, lambda s: assert_equal( - next(p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy")["status"].get('status'), - "dry-run", - "Pipeline step status is not 'dry-run'" - )), + lambda: check_state(APP_URL, lambda s: assert_equal(next( + p for p in s[ENV_ID]["pipeline"] if p["name"] == "SharedStateHolderInMemory" + )["status"]['dry'], True, "Pipeline step status is not 'running'")), ) # page.verify_pipeline_step_status("DockerContainerDeploy", "dry-run") @@ -71,9 +69,15 @@ class TestDryRunPlaywright: # Wait for pipeline to re-run and actually deploy the container eventually( - lambda: _check_state(APP_URL, lambda s: assert_equal(next( - p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy" - )["status"].get('status'), "running", "Pipeline step status is not 'running'")), + lambda: check_state(APP_URL, lambda s: assert_equal(next( + p for p in s[ENV_ID]["pipeline"] if p["name"] =="SharedStateHolderInMemory" + )["status"]['dry'], False, "Pipeline step status is not 'running'")), + ) + # Wait for pipeline to re-run and actually deploy the container + eventually( + lambda: check_state(APP_URL, lambda s: assert_equal({p["name"] for p in s[ENV_ID]["pipeline"] if bool(p['is_running'])}, set(), "Pipeline still running")), + timeout=60, + interval=1.0, ) # page.verify_pipeline_step_status("DockerContainerDeploy", "running") logger.info("Container deployed and running after dry run disabled") -- 2.54.0 From 6c7070f1632fde297f81a5484c210b13a18f2e47 Mon Sep 17 00:00:00 2001 From: rudolf Date: Sun, 10 May 2026 00:49:13 +0200 Subject: [PATCH 14/15] x --- Dockerfile_test_app | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Dockerfile_test_app diff --git a/Dockerfile_test_app b/Dockerfile_test_app new file mode 100644 index 0000000..f1bf22f --- /dev/null +++ b/Dockerfile_test_app @@ -0,0 +1,31 @@ +FROM nginx:1.27-alpine + +COPY .git /tmp/repo/.git + +# Configure nginx to listen on 5001 to match container port expectations. +RUN sed -i 's/listen 80;/listen 5001;/' /etc/nginx/conf.d/default.conf + +# Build a custom landing page directly in the image and inject git revision. +RUN set -eux; \ + apk add --no-cache --virtual .git-deps git; \ + GIT_REVISION="$(git --git-dir=/tmp/repo/.git rev-parse --short HEAD 2>/dev/null || echo unknown)"; \ + { \ + echo ''; \ + echo ''; \ + echo ''; \ + echo ' '; \ + echo ' '; \ + echo ' Brencher Test App'; \ + echo ''; \ + echo ''; \ + echo '

Nginx Is Running

'; \ + echo '

Custom landing page for the Brencher test app container.

'; \ + echo '

Port: 5001

'; \ + echo "

Git revision: ${GIT_REVISION}

"; \ + echo ''; \ + echo ''; \ + } > /usr/share/nginx/html/index.html; \ + rm -rf /tmp/repo/.git; \ + apk del .git-deps + +EXPOSE 5001 -- 2.54.0 From ff150000cd26aabc2409e42295b0adbb4cb9a175 Mon Sep 17 00:00:00 2001 From: hermes Date: Thu, 3 Sep 2026 18:12:05 +0000 Subject: [PATCH 15/15] fix(tests): remove conflict markers in playwright_helper.py --- tests/playwright_helper.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/playwright_helper.py b/tests/playwright_helper.py index d1cd9e1..ef260b4 100644 --- a/tests/playwright_helper.py +++ b/tests/playwright_helper.py @@ -196,9 +196,6 @@ class BrencherPage: @contextmanager def brencher_page( app_link: str, -<<<<<<< HEAD - env_id: str = "brencher_local1", -======= env_id: str, action_logger: logging.Logger | None = None, ) -> Generator[BrencherPage, None, None]: -- 2.54.0