From 2b8a7c27a23abc7f33f69b801265e5c39d300b9b Mon Sep 17 00:00:00 2001 From: sascha Date: Wed, 12 Aug 2026 13:00:10 +0200 Subject: [PATCH] Test BW Manager deploy endpoint safety gates --- tests/test_bw_manager_deploy.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/test_bw_manager_deploy.py diff --git a/tests/test_bw_manager_deploy.py b/tests/test_bw_manager_deploy.py new file mode 100644 index 0000000..cf5a339 --- /dev/null +++ b/tests/test_bw_manager_deploy.py @@ -0,0 +1,32 @@ +import importlib.util +from pathlib import Path + +import pytest +from fastapi.testclient import TestClient + + +ROOT = Path(__file__).resolve().parents[1] + + +def load_app(monkeypatch): + monkeypatch.setenv("BUTLER_TOKEN", "test-token") + spec = importlib.util.spec_from_file_location("butler_bw_test", ROOT / "app.py") + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def test_bw_manager_deploy_rejects_bundle_without_and_gate(monkeypatch): + app = load_app(monkeypatch) + files = {path: "placeholder" for path in app.BW_MANAGER_REPO_FILES} + files["compose.yaml"] = "services:\n bw-manager:\n build: ./src\n" + files["src/app.py"] = "def old_policy(): pass\n" + + with pytest.raises(ValueError, match="AND gate"): + app._deploy_bw_manager_compose(files) + + +def test_bw_manager_deploy_endpoint_requires_auth(monkeypatch): + app = load_app(monkeypatch) + response = TestClient(app.app).post("/vps/bw-manager/deploy") + assert response.status_code in (401, 403) \ No newline at end of file