Deploy: Stack-Auflösung mit Rückfall über die Projekt-UUID und aussagekräftiger Fehlermeldung; CORTECS_API_KEY aus der Admin-Env zählt als gesetzt

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
RubenRWU
2026-10-15 16:08:56 +02:00
parent 8c3795ec8c
commit fd5f12a8ca
3 changed files with 58 additions and 2 deletions

View File

@@ -455,3 +455,40 @@ def test_live_actions_are_locked_without_login(client, monkeypatch):
assert client.post("/api/tenants/sprinz/deploy", json={"dry_run": False}).status_code == 403
assert client.post("/api/tenants/sprinz/oidc/sync", json={"apply": True}).status_code == 403
assert client.get("/api/deploy/mode").json()["live"] is False
# ── Stack-Auflösung & Env-Rückfall ──────────────────────────────────────────
def test_stack_resolution_falls_back_to_project_uuid_and_explains_failures():
from app.services.mittwald import DeployError, Mittwald
calls = []
def http_ok(method, url, headers, body):
path = url.split("/v2")[1]
calls.append(path)
if path.endswith("/stacks/") and "/projects/" in path:
return 200, [], "" # Liste leer
if path == "/projects/p-1/":
return 200, {"id": "uuid-1"}, ""
if path == "/stacks/uuid-1/":
return 200, {"services": {}}, ""
return 404, None, "nope"
assert Mittwald("t", "https://api.test/v2", False, lambda m: None, http_ok).resolve_stack_id("p-1", "") == "uuid-1"
assert Mittwald("t", "https://api.test/v2", False, lambda m: None, lambda *a: (200, [{"id": "s-9", "description": "default"}], "")).resolve_stack_id("p-1", "") == "s-9"
assert Mittwald("t", "https://api.test/v2", False, lambda m: None, lambda *a: (200, {"stacks": [{"id": "s-7"}]}, "")).resolve_stack_id("p-1", "") == "s-7"
with pytest.raises(DeployError, match="Antwort der API.*STACK_ID in den Einstellungen"):
Mittwald("t", "https://api.test/v2", False, lambda m: None, lambda m, u, h, b: (200, [], "") if u.endswith("/stacks/") else (404, None, "x")).resolve_stack_id("p-1", "")
def test_cortecs_key_from_admin_env_counts_as_set_and_reaches_the_container(client, monkeypatch):
client.put("/api/shared-secrets/CORTECS_API_KEY", json={"value": ""}) # kein DB-Wert (andere Tests setzen ihn)
with session() as db:
t = db.get(Tenant, "sprinz")
monkeypatch.delenv("CORTECS_API_KEY", raising=False)
assert "CORTECS_API_KEY" in deploy.missing_secrets(db, t)
monkeypatch.setenv("CORTECS_API_KEY", "ck-aus-env")
assert "CORTECS_API_KEY" not in deploy.missing_secrets(db, t)
assert deploy.build_env(db, t, reveal=True)["CORTECS_API_KEY"] == "ck-aus-env"
assert "ck-aus-env" not in str(deploy.build_env(db, t, reveal=False))
assert "aus Admin-Env" in deploy.build_env(db, t, reveal=False)["CORTECS_API_KEY"]