@@ -139,6 +139,22 @@ def test_sdk_backend_missing_registered_best_prompt_field_is_clear(tmp_path: Pat
139139 )
140140
141141
142+ def test_sdk_backend_empty_best_prompts_dict_error_is_clear (tmp_path : Path , monkeypatch ):
143+ _install_fake_sdk (monkeypatch , best_prompts = {})
144+ prompt_path = tmp_path / "prompt.txt"
145+ prompt_path .write_text ("baseline" , encoding = "utf-8" )
146+ backend = SDKBackend (prompt_path = prompt_path , call_agent_path = "fake_call_agent_module:call_agent" )
147+
148+ with pytest .raises (ValueError , match = "best_prompts was empty" ):
149+ backend .optimize (
150+ baseline_prompt = "baseline" ,
151+ train_path = tmp_path / "train.evalset.json" ,
152+ val_path = tmp_path / "val.evalset.json" ,
153+ optimizer_config_path = tmp_path / "optimizer.json" ,
154+ output_dir = tmp_path / "out" ,
155+ )
156+
157+
142158def test_sdk_backend_passes_update_source_true (tmp_path : Path , monkeypatch ):
143159 calls = _install_fake_sdk (monkeypatch , best_prompt = "optimized prompt" )
144160 prompt_path = tmp_path / "prompt.txt"
@@ -207,7 +223,7 @@ def test_sdk_backend_empty_best_prompt_error_is_clear(tmp_path: Path, monkeypatc
207223 prompt_path .write_text ("baseline" , encoding = "utf-8" )
208224 backend = SDKBackend (prompt_path = prompt_path , call_agent_path = "fake_call_agent_module:call_agent" )
209225
210- with pytest .raises (ValueError , match = "missing registered target fields.*system_prompt" ):
226+ with pytest .raises (ValueError , match = "contained empty registered target fields.*system_prompt" ):
211227 backend .optimize (
212228 baseline_prompt = "baseline" ,
213229 train_path = tmp_path / "train.evalset.json" ,
@@ -359,8 +375,9 @@ def test_run_pipeline_mode_sdk_default_run_id_uses_sdk_started_at(tmp_path: Path
359375 sdk_call_agent = "fake_call_agent_module:call_agent" ,
360376 )
361377
362- assert report .run ["run_id" ] == "eval_optimize_loop_sdk_2026-07-04T12-34-56-00-00 "
378+ assert report .run ["run_id" ] == "eval_optimize_loop_sdk_20260704T123456Z "
363379 assert (tmp_path / "sdk_run" / "runs" / report .run ["run_id" ]).is_dir ()
380+ assert "--run-id" not in report .run ["reproducibility_command" ]
364381
365382
366383def test_run_pipeline_mode_sdk_uses_default_wrapper_gate_when_sdk_config_has_no_gate (
@@ -457,6 +474,39 @@ def test_run_pipeline_mode_sdk_custom_gate_rejects_cost_over_budget(tmp_path: Pa
457474 assert any ("cost" in reason for reason in decision .reasons )
458475
459476
477+ @pytest .mark .parametrize (
478+ ("field_name" , "field_value" ),
479+ [
480+ ("min_val_score_improvement" , True ),
481+ ("max_total_cost" , float ("nan" )),
482+ ("max_total_cost" , float ("inf" )),
483+ ],
484+ )
485+ def test_run_pipeline_mode_sdk_rejects_invalid_gate_numbers (
486+ tmp_path : Path ,
487+ monkeypatch ,
488+ field_name ,
489+ field_value ,
490+ ):
491+ _install_fake_sdk (monkeypatch , best_prompt = "optimized prompt" )
492+ gate = {"min_val_score_improvement" : 0.01 , "max_total_cost" : 1.0 }
493+ gate [field_name ] = field_value
494+ gate_path = tmp_path / "bad_gate.json"
495+ gate_path .write_text (json .dumps ({"gate" : gate }), encoding = "utf-8" )
496+
497+ with pytest .raises (ValueError , match = f"--gate-config.*{ field_name } " ):
498+ run_pipeline (
499+ mode = "sdk" ,
500+ train_path = DEFAULT_TRAIN ,
501+ val_path = DEFAULT_VAL ,
502+ optimizer_config_path = _write_sdk_optimizer_config (tmp_path ),
503+ prompt_path = DEFAULT_PROMPT ,
504+ output_dir = tmp_path / "sdk_run" ,
505+ sdk_call_agent = "fake_call_agent_module:call_agent" ,
506+ gate_config_path = gate_path ,
507+ )
508+
509+
460510def test_run_pipeline_mode_sdk_does_not_pass_wrapper_gate_config_to_agent_optimizer (
461511 tmp_path : Path ,
462512 monkeypatch ,
@@ -540,12 +590,16 @@ def test_run_pipeline_mode_sdk_registers_multiple_target_prompt_paths(tmp_path:
540590 assert (run_dir / "candidate_prompts" / "sdk_best" / "skill_prompt.txt" ).read_text (
541591 encoding = "utf-8"
542592 ) == "optimized skill"
593+ assert (run_dir / "candidate_prompts" / "sdk_best" / "bundle.txt" ).read_text (
594+ encoding = "utf-8"
595+ ) == report .candidates [0 ]["candidate" ].prompt
543596 input_hashes = json .loads ((run_dir / "input_hashes.json" ).read_text (encoding = "utf-8" ))
544597 assert set (input_hashes ["target_prompts" ]) == {"system_prompt" , "router_prompt" , "skill_prompt" }
545598 assert "gate_config" in input_hashes
546599 command = report .run ["reproducibility_command" ]
547600 assert "--sdk-call-agent fake_call_agent_module:call_agent" in command
548- assert f"--target-prompt router_prompt={ router_path } " in command
601+ assert "--target-prompt" in command
602+ assert f"router_prompt={ router_path } " in command
549603 assert "--gate-config" in command
550604
551605
0 commit comments