Skip to content

Commit 0601aeb

Browse files
authored
fix: make enhance command fully programmatic with --auto-approve (#745)
- Auto-select detected base template when `-y` is passed without `--base-template` - Require `--cicd-runner` when using `-y` for explicit programmatic invocation - Update tests to include `--cicd-runner skip` with `--auto-approve` This enables fully programmatic invocation: uvx agent-starter-pack enhance . -y --cicd-runner github_actions
1 parent 3d20464 commit 0601aeb

File tree

2 files changed

+81
-7
lines changed

2 files changed

+81
-7
lines changed

agent_starter_pack/cli/commands/enhance.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,13 @@ def enhance(
599599
console.print("> Debug mode enabled")
600600
logging.debug("Starting enhance command in debug mode")
601601

602+
# Validate required options for programmatic invocation
603+
if auto_approve and not cicd_runner:
604+
raise click.ClickException(
605+
"When using --auto-approve (-y), you must specify --cicd-runner.\n"
606+
"Example: uvx agent-starter-pack enhance . -y --cicd-runner github_actions"
607+
)
608+
602609
# Handle --adk shortcut
603610
if adk:
604611
if base_template:
@@ -706,6 +713,9 @@ def enhance(
706713
f"✅ Selected base template: [cyan]{selected_base_template}[/cyan]"
707714
)
708715
console.print()
716+
elif not base_template and auto_approve:
717+
# Auto-select the detected base template when auto-approving
718+
base_template = original_base_template_name
709719

710720
# Reload config with potential base template override
711721
if cli_overrides.get("base_template"):

tests/cli/commands/test_enhance.py

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ def test_enhance_with_interactive_base_template_selection(
117117
[
118118
".",
119119
"--auto-approve",
120+
"--cicd-runner",
121+
"skip",
120122
], # Use auto-approve to skip confirmation prompts
121123
input="y\n", # Confirm enhancement
122124
)
@@ -136,7 +138,14 @@ def test_enhance_with_base_template_cli_param(self) -> None:
136138
with patch("agent_starter_pack.cli.commands.enhance.create") as mock_create:
137139
runner.invoke(
138140
enhance,
139-
[".", "--base-template", "langgraph", "--auto-approve"],
141+
[
142+
".",
143+
"--base-template",
144+
"langgraph",
145+
"--auto-approve",
146+
"--cicd-runner",
147+
"skip",
148+
],
140149
)
141150

142151
# Should call create with the specified base template
@@ -156,7 +165,14 @@ def test_enhance_with_agent_directory_cli_param(self) -> None:
156165
with patch("agent_starter_pack.cli.commands.enhance.create") as mock_create:
157166
runner.invoke(
158167
enhance,
159-
[".", "--agent-directory", "chatbot", "--auto-approve"],
168+
[
169+
".",
170+
"--agent-directory",
171+
"chatbot",
172+
"--auto-approve",
173+
"--cicd-runner",
174+
"skip",
175+
],
160176
)
161177

162178
# Should call create with the specified agent directory in cli_overrides
@@ -193,7 +209,7 @@ def test_enhance_auto_detects_agent_directory_from_pyproject(
193209
with patch("agent_starter_pack.cli.commands.enhance.create") as mock_create:
194210
runner.invoke(
195211
enhance,
196-
[".", "--auto-approve"],
212+
[".", "--auto-approve", "--cicd-runner", "skip"],
197213
)
198214

199215
# Should call create and detect 'my_agent' from pyproject.toml
@@ -224,7 +240,14 @@ def test_enhance_cli_agent_directory_overrides_detection(self) -> None:
224240
with patch("agent_starter_pack.cli.commands.enhance.create") as mock_create:
225241
runner.invoke(
226242
enhance,
227-
[".", "--agent-directory", "cli_agent", "--auto-approve"],
243+
[
244+
".",
245+
"--agent-directory",
246+
"cli_agent",
247+
"--auto-approve",
248+
"--cicd-runner",
249+
"skip",
250+
],
228251
)
229252

230253
# CLI parameter should override auto-detection
@@ -244,7 +267,14 @@ def test_enhance_warns_about_missing_agent_directory(self) -> None:
244267
with patch("agent_starter_pack.cli.commands.enhance.create") as mock_create:
245268
result = runner.invoke(
246269
enhance,
247-
[".", "--agent-directory", "missing_agent", "--auto-approve"],
270+
[
271+
".",
272+
"--agent-directory",
273+
"missing_agent",
274+
"--auto-approve",
275+
"--cicd-runner",
276+
"skip",
277+
],
248278
)
249279

250280
# Should show warning about missing directory but still proceed
@@ -271,6 +301,8 @@ def test_enhance_with_combined_params(self) -> None:
271301
"--agent-directory",
272302
"my_chatbot",
273303
"--auto-approve",
304+
"--cicd-runner",
305+
"skip",
274306
],
275307
)
276308

@@ -296,7 +328,7 @@ def test_enhance_with_adk_flag_sets_base_template(self) -> None:
296328
with patch("agent_starter_pack.cli.commands.enhance.create") as mock_create:
297329
runner.invoke(
298330
enhance,
299-
[".", "--adk", "--auto-approve"],
331+
[".", "--adk", "--auto-approve", "--cicd-runner", "skip"],
300332
)
301333

302334
# Should call create with base_template set to adk
@@ -315,7 +347,15 @@ def test_enhance_adk_flag_conflicts_with_base_template(self) -> None:
315347

316348
result = runner.invoke(
317349
enhance,
318-
[".", "--adk", "--base-template", "langgraph", "--auto-approve"],
350+
[
351+
".",
352+
"--adk",
353+
"--base-template",
354+
"langgraph",
355+
"--auto-approve",
356+
"--cicd-runner",
357+
"skip",
358+
],
319359
)
320360

321361
# Should fail with an error about conflicting options
@@ -377,6 +417,8 @@ def test_agent_engine_app_has_correct_import(
377417
"agent_engine",
378418
"--auto-approve",
379419
"--skip-checks",
420+
"--cicd-runner",
421+
"skip",
380422
],
381423
)
382424

@@ -453,6 +495,8 @@ def test_agent_engine_app_created_in_custom_agent_directory(
453495
"agent_engine",
454496
"--auto-approve",
455497
"--skip-checks",
498+
"--cicd-runner",
499+
"skip",
456500
],
457501
)
458502

@@ -586,6 +630,8 @@ def test_adk_live_populates_frontend_files(self, tmp_path: pathlib.Path) -> None
586630
"agent_engine",
587631
"--auto-approve",
588632
"--skip-checks",
633+
"--cicd-runner",
634+
"skip",
589635
],
590636
)
591637

@@ -722,6 +768,8 @@ def test_data_ingestion_populates_files(self, tmp_path: pathlib.Path) -> None:
722768
"--include-data-ingestion",
723769
"--auto-approve",
724770
"--skip-checks",
771+
"--cicd-runner",
772+
"skip",
725773
],
726774
)
727775

@@ -803,6 +851,8 @@ def test_yaml_agent_shim_generated_for_agent_engine(
803851
"agent_engine",
804852
"--auto-approve",
805853
"--skip-checks",
854+
"--cicd-runner",
855+
"skip",
806856
],
807857
)
808858

@@ -872,6 +922,8 @@ def test_yaml_agent_shim_generated_for_cloud_run(
872922
"cloud_run",
873923
"--auto-approve",
874924
"--skip-checks",
925+
"--cicd-runner",
926+
"skip",
875927
],
876928
)
877929

@@ -922,6 +974,8 @@ def test_yaml_agent_shim_in_custom_directory(self, tmp_path: pathlib.Path) -> No
922974
"agent_engine",
923975
"--auto-approve",
924976
"--skip-checks",
977+
"--cicd-runner",
978+
"skip",
925979
],
926980
)
927981

@@ -963,6 +1017,8 @@ def test_yaml_agent_detection_message_shown(self, tmp_path: pathlib.Path) -> Non
9631017
"agent_engine",
9641018
"--auto-approve",
9651019
"--skip-checks",
1020+
"--cicd-runner",
1021+
"skip",
9661022
],
9671023
)
9681024

@@ -999,6 +1055,8 @@ def test_yaml_agent_shim_overwrites_template_agent_py(
9991055
"agent_engine",
10001056
"--auto-approve",
10011057
"--skip-checks",
1058+
"--cicd-runner",
1059+
"skip",
10021060
],
10031061
)
10041062

@@ -1069,6 +1127,8 @@ def test_app_injected_for_adk_templates_without_app(
10691127
"agent_engine",
10701128
"--auto-approve",
10711129
"--skip-checks",
1130+
"--cicd-runner",
1131+
"skip",
10721132
],
10731133
)
10741134

@@ -1115,6 +1175,8 @@ def test_app_not_injected_for_non_adk_templates(
11151175
"agent_engine",
11161176
"--auto-approve",
11171177
"--skip-checks",
1178+
"--cicd-runner",
1179+
"skip",
11181180
],
11191181
)
11201182

@@ -1164,6 +1226,8 @@ def test_app_not_injected_when_already_present(
11641226
"agent_engine",
11651227
"--auto-approve",
11661228
"--skip-checks",
1229+
"--cicd-runner",
1230+
"skip",
11671231
],
11681232
)
11691233

0 commit comments

Comments
 (0)