Skip to content

Commit 116149b

Browse files
committed
Make fixes add test.
1 parent c611ca2 commit 116149b

File tree

3 files changed

+88
-6
lines changed

3 files changed

+88
-6
lines changed

sky/client/cli/command.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,12 +1350,10 @@ def _handle_jobs_queue_request(
13501350
show_all: bool,
13511351
show_user: bool,
13521352
max_num_jobs_to_show: Optional[int],
1353-
pool_status_request_id: Optional[server_common.RequestId[List[Dict[str,
1354-
Any]]]] = None,
1355-
is_called_by_user: bool = False,
1356-
only_in_progress: bool = False,
13571353
pool_status_request_id: Optional[server_common.RequestId[List[Dict[
13581354
str, Any]]]] = None,
1355+
is_called_by_user: bool = False,
1356+
only_in_progress: bool = False,
13591357
) -> Tuple[Optional[int], str]:
13601358
"""Get the in-progress managed jobs.
13611359

sky/jobs/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1714,8 +1714,8 @@ def format_job_table(
17141714
tasks: List[Dict[str, Any]],
17151715
show_all: bool,
17161716
show_user: bool,
1717-
pool_status: Optional[List[Dict[str, Any]]] = None,
17181717
return_rows: Literal[False] = False,
1718+
pool_status: Optional[List[Dict[str, Any]]] = None,
17191719
max_jobs: Optional[int] = None,
17201720
job_status_counts: Optional[Dict[str, int]] = None,
17211721
) -> str:

tests/unit_tests/test_sky/test_cli_helpers.py

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This module contains tests for CLI helper functions in sky.client.cli.command.
44
"""
55
import traceback
6-
from typing import Dict, List, Optional, Tuple, Union
6+
from typing import Any, Dict, List, Optional, Tuple, Union
77
from unittest import mock
88

99
import colorama
@@ -75,6 +75,7 @@ def test_handle_jobs_queue_request_success_tuple_response():
7575
mock_stream.assert_called_once_with(request_id)
7676
mock_format.assert_called_once_with(
7777
managed_jobs_list,
78+
pool_status=None,
7879
show_all=False,
7980
show_user=False,
8081
max_jobs=10,
@@ -128,6 +129,89 @@ def test_handle_jobs_queue_request_success_list_response():
128129
mock_stream.assert_called_once_with(request_id)
129130
mock_format.assert_called_once_with(
130131
mock_job_records,
132+
pool_status=None,
133+
show_all=True,
134+
show_user=True,
135+
max_jobs=None,
136+
status_counts=None,
137+
)
138+
139+
140+
def test_handle_jobs_queue_request_success_list_response_with_pool_status():
141+
"""Test _handle_jobs_queue_request with list response (legacy API)."""
142+
# Create mock managed job records as dicts
143+
mock_jobs = [
144+
{
145+
'job_id': 1,
146+
'job_name': 'test-job-1'
147+
},
148+
{
149+
'job_id': 2,
150+
'job_name': 'test-job-2'
151+
},
152+
{
153+
'job_id': 3,
154+
'job_name': 'test-job-3'
155+
},
156+
]
157+
158+
# Mock job records using the model
159+
mock_job_records = [responses.ManagedJobRecord(**job) for job in mock_jobs]
160+
161+
# Mock pool status records using the model
162+
mock_pool_statuses = [
163+
{
164+
'replica_info': [
165+
{
166+
'replica_id': 1,
167+
'used_by': 3,
168+
},
169+
{
170+
'replica_id': 2,
171+
'used_by': 2,
172+
},
173+
{
174+
'replica_id': 3,
175+
'used_by': 1,
176+
},
177+
],
178+
},
179+
]
180+
181+
request_id = server_common.RequestId[List[responses.ManagedJobRecord]](
182+
'test-request-id')
183+
184+
pool_status_request_id = server_common.RequestId[List[Dict[str, Any]]](
185+
'test-pool-status-request-id')
186+
187+
with mock.patch.object(client_sdk,
188+
'stream_and_get',
189+
side_effect=[mock_job_records,
190+
mock_pool_statuses]) as mock_stream:
191+
with mock.patch.object(usage_lib.messages.usage, 'set_internal'):
192+
with mock.patch.object(
193+
table_utils, 'format_job_table',
194+
return_value='formatted table') as mock_format:
195+
num_jobs, msg = command._handle_jobs_queue_request(
196+
request_id=request_id,
197+
show_all=True,
198+
show_user=True,
199+
max_num_jobs_to_show=None,
200+
pool_status_request_id=pool_status_request_id,
201+
is_called_by_user=True,
202+
only_in_progress=False,
203+
)
204+
205+
# Verify the result - should count unique job IDs
206+
assert num_jobs == 3
207+
assert msg == 'formatted table'
208+
mock_stream.assert_has_calls([
209+
mock.call(request_id),
210+
mock.call(pool_status_request_id),
211+
])
212+
mock_format.assert_called_once_with(
213+
mock_job_records,
214+
pool_status=mock_pool_statuses,
131215
show_all=True,
132216
show_user=True,
133217
max_jobs=None,

0 commit comments

Comments
 (0)