33from __future__ import annotations
44
55from types import SimpleNamespace
6+ from pathlib import Path
67from unittest .mock import AsyncMock
78
89from tests .sdk .conftest import MockDevboxView , MockScenarioRunView
@@ -76,7 +77,7 @@ async def test_await_scored(self, mock_async_client: AsyncMock, scenario_run_vie
7677 result = await run .await_scored ()
7778
7879 assert result == scenario_run_view
79- mock_async_client .scenarios .runs .await_scored .assert_awaited_once_with ("run_123" , polling_config = None )
80+ mock_async_client .scenarios .runs .await_scored .assert_awaited_once_with ("run_123" )
8081
8182 async def test_score_and_await (self , mock_async_client : AsyncMock , scenario_run_view : MockScenarioRunView ) -> None :
8283 """Test score_and_await method."""
@@ -87,7 +88,20 @@ async def test_score_and_await(self, mock_async_client: AsyncMock, scenario_run_
8788 result = await run .score_and_await ()
8889
8990 assert result == scenario_run_view
90- mock_async_client .scenarios .runs .score_and_await .assert_awaited_once_with ("run_123" , polling_config = None )
91+ mock_async_client .scenarios .runs .score_and_await .assert_awaited_once_with ("run_123" )
92+
93+ async def test_score_and_complete (
94+ self , mock_async_client : AsyncMock , scenario_run_view : MockScenarioRunView
95+ ) -> None :
96+ """Test score_and_complete method."""
97+ scenario_run_view .state = "completed"
98+ mock_async_client .scenarios .runs .score_and_complete = AsyncMock (return_value = scenario_run_view )
99+
100+ run = AsyncScenarioRun (mock_async_client , "run_123" , "dev_123" )
101+ result = await run .score_and_complete ()
102+
103+ assert result == scenario_run_view
104+ mock_async_client .scenarios .runs .score_and_complete .assert_awaited_once_with ("run_123" )
91105
92106 async def test_complete (self , mock_async_client : AsyncMock , scenario_run_view : MockScenarioRunView ) -> None :
93107 """Test complete method."""
@@ -111,6 +125,19 @@ async def test_cancel(self, mock_async_client: AsyncMock, scenario_run_view: Moc
111125 assert result == scenario_run_view
112126 mock_async_client .scenarios .runs .cancel .assert_awaited_once_with ("run_123" )
113127
128+ async def test_download_logs (self , mock_async_client : AsyncMock , tmp_path : Path ) -> None :
129+ """Test download_logs method writes to file."""
130+ mock_response = AsyncMock ()
131+ mock_response .write_to_file = AsyncMock ()
132+ mock_async_client .scenarios .runs .download_logs = AsyncMock (return_value = mock_response )
133+
134+ run = AsyncScenarioRun (mock_async_client , "run_123" , "dev_123" )
135+ output_path = tmp_path / "logs.zip"
136+ await run .download_logs (output_path )
137+
138+ mock_async_client .scenarios .runs .download_logs .assert_awaited_once_with ("run_123" )
139+ mock_response .write_to_file .assert_awaited_once_with (output_path )
140+
114141 async def test_get_score_when_scored (self , mock_async_client : AsyncMock ) -> None :
115142 """Test get_score returns scoring result when scored."""
116143 scoring_result = SimpleNamespace (score = 0.95 , scoring_function_results = [])
@@ -121,6 +148,7 @@ async def test_get_score_when_scored(self, mock_async_client: AsyncMock) -> None
121148 result = await run .get_score ()
122149
123150 assert result == scoring_result
151+ mock_async_client .scenarios .runs .retrieve .assert_awaited_once_with ("run_123" )
124152
125153 async def test_get_score_when_not_scored (self , mock_async_client : AsyncMock ) -> None :
126154 """Test get_score returns None when not scored."""
@@ -131,3 +159,4 @@ async def test_get_score_when_not_scored(self, mock_async_client: AsyncMock) ->
131159 result = await run .get_score ()
132160
133161 assert result is None
162+ mock_async_client .scenarios .runs .retrieve .assert_awaited_once_with ("run_123" )
0 commit comments