|
1 | 1 | import re |
2 | 2 | import uuid |
| 3 | +from types import SimpleNamespace |
3 | 4 |
|
4 | 5 | import pytest |
5 | 6 |
|
6 | 7 | from dstack._internal.core.errors import ServerClientError |
7 | 8 | from dstack._internal.core.models.configurations import ServiceConfiguration |
8 | 9 | from dstack._internal.core.models.files import FileArchiveMapping |
| 10 | +from dstack._internal.core.models.profiles import Profile, ProfileRetry |
9 | 11 | from dstack._internal.core.models.repos.local import LocalRunRepoData |
10 | 12 | from dstack._internal.core.models.runs import RunSpec |
11 | 13 | from dstack._internal.server.services.runs.spec import ( |
12 | 14 | _check_can_update_configuration, |
13 | 15 | check_can_update_run_spec, |
| 16 | + validate_run_spec_and_set_defaults, |
14 | 17 | ) |
15 | 18 | from dstack._internal.server.testing.common import get_run_spec |
16 | 19 |
|
@@ -77,6 +80,24 @@ def _run_spec_with_overrides(configuration: ServiceConfiguration, **overrides) - |
77 | 80 | return RunSpec.parse_obj({**run_spec.dict(), **run_spec_overrides}) |
78 | 81 |
|
79 | 82 |
|
| 83 | +class TestValidateRunSpecRetryDuration: |
| 84 | + def test_model_accepts_negative_retry_duration_for_backward_compatibility(self): |
| 85 | + retry = ProfileRetry(duration=-1) |
| 86 | + |
| 87 | + assert retry.duration == -1 |
| 88 | + |
| 89 | + def test_rejects_negative_retry_duration_for_new_run_specs(self): |
| 90 | + run_spec = get_run_spec( |
| 91 | + repo_id="test-repo", |
| 92 | + profile=Profile(name="default", retry=ProfileRetry(duration=-1)), |
| 93 | + ) |
| 94 | + |
| 95 | + with pytest.raises(ServerClientError, match="retry.duration cannot be negative"): |
| 96 | + validate_run_spec_and_set_defaults( |
| 97 | + SimpleNamespace(ssh_public_key="ssh-rsa test"), run_spec |
| 98 | + ) |
| 99 | + |
| 100 | + |
80 | 101 | class TestCheckCanUpdateConfigurationRouterType: |
81 | 102 | def test_sglang_to_dynamo_router_type_change_is_rejected(self): |
82 | 103 | current = _run_spec(_service_configuration(router_type="sglang")) |
|
0 commit comments