ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
fix(recipes): restore CI boundary contracts
Juan Denis1fad04e880ec
diff --git a/backend/app/api/recipes.py b/backend/app/api/recipes.pyindex faaccf7a..69ce76c7 100644--- a/backend/app/api/recipes.py+++ b/backend/app/api/recipes.py@@ -11,12 +11,11 @@ is found or created so a catalog install is one call.from flask import Blueprint, jsonify, requestfrom app import db-from app.exceptions import NotFoundError+from app.exceptions import NotFoundError, ValidationErrorfrom app.middleware.rbac import admin_required, auth_required, get_current_userfrom app.models.application_manifest import STATUS_ERROR, STATUS_PENDINGfrom app.models.deployment_job import DeploymentJobfrom app.models.project import Project-from app.models.server import Serverfrom app.services import recipe_registry_servicefrom app.services.manifest_persistence_service import ManifestPersistenceServicefrom app.services.manifest_spec_service import ManifestError, ManifestSpecService@@ -28,9 +27,6 @@ from app.services.recipe_execution_service import (recipes_bp = Blueprint('recipes', __name__)-RECIPES_PROJECT_SLUG = 'recipes'--def _normalized_recipe(data, project_id):"""Resolve the manifest source: registry slug > inline content > stored."""if data.get('registry_slug'):@@ -47,21 +43,6 @@ def _normalized_recipe(data, project_id):raise ManifestError(['Provide `registry_slug`, `content`, `manifest`, or store one first'])-def _resolve_project(server):- """Find-or-create the per-workspace Recipes project for a server-targeted- run. Idempotent: every subsequent install reuses it."""- project = Project.query.filter_by(- workspace_id=server.workspace_id, slug=RECIPES_PROJECT_SLUG).first()- if project:- return project- project = Project(workspace_id=server.workspace_id,- name='Recipes', slug=RECIPES_PROJECT_SLUG,- description='Apps installed through the Recipe catalog')- db.session.add(project)- db.session.flush()- return project--def _validated_params(normalized, raw_params):"""Check up-front params against the manifest's declared inputs. Onlynon-secret inputs may be preset; secrets must use the mid-run handoff."""@@ -99,13 +80,8 @@ def list_recipe_registry():def get_recipe_registry_entry(slug):entry = recipe_registry_service.get_entry(slug)if entry is None:- return jsonify({'error': 'Recipe not found in the registry'}), 404- try:- manifest_text = recipe_registry_service.get_manifest_text(slug)- except NotFoundError as exc:- return jsonify({'error': str(exc)}), 404- except Exception:- return jsonify({'error': 'Could not download the recipe from the registry'}), 503+ raise NotFoundError('Recipe not found in the registry')+ manifest_text = recipe_registry_service.get_manifest_text(slug)public = {k: v for k, v in entry.items() if k != '_manifest_url'}return jsonify({'recipe': public, 'manifest': manifest_text}), 200@@ -118,15 +94,13 @@ def start_recipe_run():project = Noneserver = Noneif data.get('server_id'):- server = Server.query.get(data.get('server_id'))- if not server:- return jsonify({'error': 'A valid server_id is required'}), 400+ server = RecipeExecutionService.get_server(data.get('server_id'))if data.get('project_id'):project = Project.query.get(data.get('project_id'))if not project:return jsonify({'error': 'A valid project_id is required'}), 400if project is None and server is None:- return jsonify({'error': 'Provide server_id or project_id'}), 400+ raise ValidationError('Provide server_id or project_id')try:normalized, raw = _normalized_recipe(data, project.id if project else None)@@ -134,13 +108,13 @@ def start_recipe_run():except ManifestError as exc:return jsonify({'error': 'Invalid Recipe manifest', 'errors': exc.errors}), 400except (ValueError, NotFoundError) as exc:- return jsonify({'error': str(exc)}), 400+ raise ValidationError(str(exc)) from exc# A server-targeted catalog run pins the manifest's default server ref.if server is not None:normalized['server'] = server.nameif project is None:- project = _resolve_project(server)+ project = RecipeExecutionService.get_or_create_project(server)unsupported = RecipeExecutionService.unsupported_capabilities(normalized)if unsupported:diff --git a/backend/app/services/recipe_execution_service.py b/backend/app/services/recipe_execution_service.pyindex b345ccec..07394b54 100644--- a/backend/app/services/recipe_execution_service.py+++ b/backend/app/services/recipe_execution_service.py@@ -15,11 +15,13 @@ from datetime import datetime, timedeltafrom typing import Any, Callable, Dict, Optionalfrom app import db+from app.exceptions import ValidationErrorfrom app.models.application_manifest import STATUS_APPLIED, STATUS_ERRORfrom app.models.deployment_job import DeploymentJobfrom app.models.environment import Environmentfrom app.models.project import Projectfrom app.models.secret_vault import Secret, SecretVault+from app.models.server import Serverfrom app.services.manifest_apply_service import ManifestApplyServicefrom app.services.run_log_service import stream_forfrom app.services.secret_vault_service import SecretService@@ -29,6 +31,7 @@ from app.utils.sensitive_data_filter import mask_payloadRECIPE_JOB_KIND = 'recipe.run'RECIPE_WAITING = 'waiting'HANDOFF_VAULT_SLUG = 'recipe-runs'+RECIPES_PROJECT_SLUG = 'recipes'@dataclass@@ -93,6 +96,33 @@ class RecipeStepRegistry:class RecipeExecutionService:+ @staticmethod+ def get_server(server_id: str) -> Server:+ """Resolve the server target before a Recipe run mutates anything."""+ server = db.session.get(Server, server_id)+ if server is None:+ raise ValidationError('A valid server_id is required')+ return server++ @staticmethod+ def get_or_create_project(server: Server) -> Project:+ """Return the idempotent per-workspace project for catalog installs."""+ project = Project.query.filter_by(+ workspace_id=server.workspace_id,+ slug=RECIPES_PROJECT_SLUG,+ ).first()+ if project is not None:+ return project+ project = Project(+ workspace_id=server.workspace_id,+ name='Recipes',+ slug=RECIPES_PROJECT_SLUG,+ description='Apps installed through the Recipe catalog',+ )+ db.session.add(project)+ db.session.flush()+ return project+@classmethoddef register_jobs(cls) -> None:from app.services import deploy_kind_registrydiff --git a/backend/tests/test_recipe_registry.py b/backend/tests/test_recipe_registry.pyindex 8f9c69e7..5a84f080 100644--- a/backend/tests/test_recipe_registry.py+++ b/backend/tests/test_recipe_registry.py@@ -11,6 +11,7 @@ from app.services.recipe_execution_service import (RecipeExecutionService,RecipeStepRegistry,)+from factories import make_server@pytest.fixture@@ -111,6 +112,7 @@ def test_registry_lists_remote_entries_and_fetches_manifest(client, auth_headersresp = client.get('/api/v1/recipes/registry/nope', headers=auth_headers)assert resp.status_code == 404+ assert resp.get_json()['code'] == 'not_found'resp = client.get('/api/v1/recipes/registry/remote-recipe', headers=auth_headers)assert resp.status_code == 200@@ -124,6 +126,24 @@ def test_run_requires_server_or_project(client, auth_headers):response = client.post('/api/v1/recipes/runs', headers=auth_headers, json={})assert response.status_code == 400assert 'server_id' in response.get_json()['error']+ assert response.get_json()['code'] == 'validation_error'+++def test_server_target_reuses_the_workspace_recipes_project(app):+ from app.models import Project+ from app.services.workspace_service import WorkspaceService++ workspace = WorkspaceService.ensure_default_workspace()+ server = make_server(db, workspace_id=workspace.id)++ resolved = RecipeExecutionService.get_server(server.id)+ first = RecipeExecutionService.get_or_create_project(resolved)+ second = RecipeExecutionService.get_or_create_project(resolved)++ assert first.id == second.id+ assert first.slug == 'recipes'+ assert Project.query.filter_by(+ workspace_id=workspace.id, slug='recipes').count() == 1def test_params_reject_unknown_keys(client, auth_headers, project):