From 75a76bbb487db22d6e631183460e81165c3d2214 Mon Sep 17 00:00:00 2001 From: Bill Date: Fri, 7 Nov 2025 13:11:09 -0500 Subject: [PATCH] fix: address code review issues for Task 1 - Add test for ValueError when all simulations completed - Include warnings in API response for user visibility - Improve error message validation in tests --- api/main.py | 1 + .../test_job_manager_duplicate_detection.py | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/api/main.py b/api/main.py index b307622..0d0c923 100644 --- a/api/main.py +++ b/api/main.py @@ -318,6 +318,7 @@ def create_app( status="pending", total_model_days=len(all_dates) * len(models_to_run), message=message, + warnings=warnings if warnings else None, **deployment_info ) diff --git a/tests/unit/test_job_manager_duplicate_detection.py b/tests/unit/test_job_manager_duplicate_detection.py index a37409b..a373a86 100644 --- a/tests/unit/test_job_manager_duplicate_detection.py +++ b/tests/unit/test_job_manager_duplicate_detection.py @@ -179,3 +179,35 @@ def test_create_job_returns_warnings_for_skipped_simulations(temp_db): details = manager.get_job_details(result["job_id"]) assert len(details) == 1 assert details[0]["date"] == "2025-10-16" + + +def test_create_job_raises_error_when_all_simulations_completed(temp_db): + """Test that ValueError is raised when ALL requested simulations are already completed.""" + manager = JobManager(db_path=temp_db) + + # Create and complete first simulation + result_1 = manager.create_job( + config_path="test_config.json", + date_range=["2025-10-15", "2025-10-16"], + models=["model-a", "model-b"] + ) + job_id_1 = result_1["job_id"] + + # Mark all model-days as completed + manager.update_job_detail_status(job_id_1, "2025-10-15", "model-a", "completed") + manager.update_job_detail_status(job_id_1, "2025-10-15", "model-b", "completed") + manager.update_job_detail_status(job_id_1, "2025-10-16", "model-a", "completed") + manager.update_job_detail_status(job_id_1, "2025-10-16", "model-b", "completed") + + # Try to create job with same date range and models (all already completed) + with pytest.raises(ValueError) as exc_info: + manager.create_job( + config_path="test_config.json", + date_range=["2025-10-15", "2025-10-16"], + models=["model-a", "model-b"] + ) + + # Verify error message contains expected text + error_message = str(exc_info.value) + assert "All requested simulations are already completed" in error_message + assert "Skipped 4 model-day pair(s)" in error_message