Skip to content

Commit cacdd7c

Browse files
fix checkpoint deployment cli validation
1 parent e8636f1 commit cacdd7c

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

packages/prime/src/prime_cli/commands/deployments.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,19 @@ def create_deployment(
192192
193193
prime deployments create --checkpoint-id <checkpoint_id>
194194
"""
195-
if model_id and checkpoint_id:
195+
if model_id is not None:
196+
model_id = model_id.strip()
197+
if not model_id:
198+
console.print("[red]Error:[/red] MODEL_ID cannot be empty.")
199+
raise typer.Exit(1)
200+
201+
if checkpoint_id is not None:
202+
checkpoint_id = checkpoint_id.strip()
203+
if not checkpoint_id:
204+
console.print("[red]Error:[/red] --checkpoint-id cannot be empty.")
205+
raise typer.Exit(1)
206+
207+
if model_id is not None and checkpoint_id is not None:
196208
console.print("[red]Error:[/red] Use either MODEL_ID or --checkpoint-id, not both.")
197209
raise typer.Exit(1)
198210

@@ -204,7 +216,7 @@ def create_deployment(
204216
api_client = APIClient()
205217
deployments_client = DeploymentsClient(api_client)
206218

207-
if checkpoint_id:
219+
if checkpoint_id is not None:
208220
console.print("[bold]Deploying checkpoint:[/bold]")
209221
console.print(f" Checkpoint ID: {checkpoint_id}")
210222
console.print()

packages/prime/tests/test_deployments.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from types import SimpleNamespace
2-
from typing import Any
2+
from typing import Any, cast
33

44
from prime_cli.api.deployments import DeploymentsClient
55
from prime_cli.client import APIError
@@ -98,7 +98,7 @@ def post(self, endpoint: str, json: dict[str, Any] | None = None) -> dict:
9898
captured["json"] = json
9999
return _adapter_response()
100100

101-
adapter = DeploymentsClient(DummyAPIClient()).deploy_checkpoint("ckpt-123")
101+
adapter = DeploymentsClient(cast(Any, DummyAPIClient())).deploy_checkpoint("ckpt-123")
102102

103103
assert captured["endpoint"] == "/rft/checkpoints/ckpt-123/deploy"
104104
assert captured["json"] is None
@@ -145,6 +145,20 @@ def deploy_checkpoint(self, checkpoint_id: str) -> Any:
145145
assert "prime deployments list" in output
146146

147147

148+
def test_deployments_create_checkpoint_rejects_empty_checkpoint_id(monkeypatch) -> None:
149+
monkeypatch.setattr("prime_cli.main.check_for_update", lambda: (False, None))
150+
151+
result = runner.invoke(
152+
app,
153+
["deployments", "create", "--checkpoint-id", "", "--yes"],
154+
env=TEST_ENV,
155+
)
156+
output = strip_ansi(result.output)
157+
158+
assert result.exit_code == 1
159+
assert "Error: --checkpoint-id cannot be empty." in output
160+
161+
148162
def test_deployments_create_checkpoint_surfaces_conflict_errors(monkeypatch) -> None:
149163
monkeypatch.setattr("prime_cli.main.check_for_update", lambda: (False, None))
150164

0 commit comments

Comments
 (0)