From aa4958bd9c7983594e1f0af5552e91a4fe2be808 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 2 Nov 2025 09:07:58 -0500 Subject: [PATCH] fix: use config models when empty models list provided When the trigger simulation API receives an empty models list ([]), it now correctly falls back to enabled models from config instead of running with no models. Changes: - Update condition to check for both None and empty list - Add test case for empty models list behavior - Update API documentation to clarify this behavior All 28 integration tests pass. --- API_REFERENCE.md | 2 +- api/main.py | 4 ++-- tests/integration/test_api_endpoints.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/API_REFERENCE.md b/API_REFERENCE.md index 95190b1..5fc43ab 100644 --- a/API_REFERENCE.md +++ b/API_REFERENCE.md @@ -36,7 +36,7 @@ Trigger a new simulation job for a specified date range and models. |-------|------|----------|-------------| | `start_date` | string \| null | No | Start date in YYYY-MM-DD format. If `null`, enables resume mode (each model continues from its last completed date). Defaults to `null`. | | `end_date` | string | **Yes** | End date in YYYY-MM-DD format. **Required** - cannot be null or empty. | -| `models` | array[string] | No | Model signatures to run. If omitted, uses all enabled models from server config. | +| `models` | array[string] | No | Model signatures to run. If omitted or empty array, uses all enabled models from server config. | | `replace_existing` | boolean | No | If `false` (default), skips already-completed model-days (idempotent). If `true`, re-runs all dates even if previously completed. | **Response (200 OK):** diff --git a/api/main.py b/api/main.py index 7728baa..5eccbd7 100644 --- a/api/main.py +++ b/api/main.py @@ -176,11 +176,11 @@ def create_app( with open(config_path, 'r') as f: config = json.load(f) - if request.models is not None: + if request.models is not None and len(request.models) > 0: # Use models from request (explicit override) models_to_run = request.models else: - # Use enabled models from config + # Use enabled models from config (when models is None or empty list) models_to_run = [ model["signature"] for model in config.get("models", []) diff --git a/tests/integration/test_api_endpoints.py b/tests/integration/test_api_endpoints.py index 245e212..3a5a680 100644 --- a/tests/integration/test_api_endpoints.py +++ b/tests/integration/test_api_endpoints.py @@ -119,6 +119,18 @@ class TestSimulateTriggerEndpoint: data = response.json() assert data["total_model_days"] >= 1 + def test_trigger_empty_models_uses_config(self, api_client): + """Should use enabled models from config when models is empty list.""" + response = api_client.post("/simulate/trigger", json={ + "start_date": "2025-01-16", + "end_date": "2025-01-16", + "models": [] # Empty list - should use enabled models from config + }) + + assert response.status_code == 200 + data = response.json() + assert data["total_model_days"] >= 1 + def test_trigger_enforces_single_job_limit(self, api_client): """Should reject trigger when job already running.""" # Create first job