Skip to content

Commit d89fb2a

Browse files
committed
test: isolate dispatch tests from quota state
1 parent fa9854f commit d89fb2a

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

tests/server/_helpers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ async def _noop_quota_refresher(config: Any, **kwargs) -> None:
3131
"""Quota refresher stub: no-op."""
3232

3333

34+
def _patch_dispatch_quota_no_sleep(monkeypatch: Any) -> None:
35+
"""Patch dispatch_food_truck's quota dependencies for non-quota tests."""
36+
monkeypatch.setattr(
37+
"autoskillit.server._misc.check_and_sleep_if_needed",
38+
_no_sleep_quota_checker,
39+
)
40+
monkeypatch.setattr(
41+
"autoskillit.server._misc._refresh_quota_cache",
42+
_noop_quota_refresher,
43+
)
44+
45+
3446
def _make_recipe_info(name: str = "test-recipe"):
3547
return _fleet_make_recipe_info(name, path_prefix="/fake/recipes/")
3648

tests/server/test_tools_dispatch_halt.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
from autoskillit.fleet import FleetSemaphore
1111
from tests.fakes import InMemoryHeadlessExecutor, InMemoryRecipeRepository
12-
from tests.server._helpers import _make_recipe_info, _make_standard_recipe
12+
from tests.server._helpers import (
13+
_make_recipe_info,
14+
_make_standard_recipe,
15+
_patch_dispatch_quota_no_sleep,
16+
)
1317

1418
pytestmark = [pytest.mark.layer("server"), pytest.mark.medium, pytest.mark.feature("fleet")]
1519

@@ -195,6 +199,7 @@ async def test_no_result_block_failure_does_not_halt_campaign(
195199

196200
def _setup_standard_dispatch(self, tool_ctx, monkeypatch):
197201
"""Wire tool_ctx for a successful standard dispatch."""
202+
_patch_dispatch_quota_no_sleep(monkeypatch)
198203
tool_ctx.fleet_lock = FleetSemaphore(max_concurrent=1)
199204
repo = InMemoryRecipeRepository()
200205
recipe_info = _make_recipe_info("test-recipe")
@@ -246,6 +251,7 @@ async def test_dispatch_food_truck_halts_after_failure_when_continue_on_failure_
246251

247252
def _setup_standard_dispatch(self, tool_ctx, monkeypatch):
248253
"""Wire tool_ctx for a standard dispatch."""
254+
_patch_dispatch_quota_no_sleep(monkeypatch)
249255
tool_ctx.fleet_lock = FleetSemaphore(max_concurrent=1)
250256
repo = InMemoryRecipeRepository()
251257
recipe_info = _make_recipe_info("test-recipe")
@@ -329,6 +335,7 @@ async def test_dispatch_halts_when_no_dispatch_name_provided(
329335

330336
def _setup_standard_dispatch(self, tool_ctx, monkeypatch):
331337
"""Wire tool_ctx for a successful standard dispatch."""
338+
_patch_dispatch_quota_no_sleep(monkeypatch)
332339
tool_ctx.fleet_lock = FleetSemaphore(max_concurrent=1)
333340
repo = InMemoryRecipeRepository()
334341
recipe_info = _make_recipe_info("test-recipe")
@@ -436,6 +443,7 @@ async def test_skip_when_resolves_campaign_ref(
436443

437444
def _setup_standard_dispatch(self, tool_ctx, monkeypatch):
438445
"""Wire tool_ctx for a successful standard dispatch."""
446+
_patch_dispatch_quota_no_sleep(monkeypatch)
439447
tool_ctx.fleet_lock = FleetSemaphore(max_concurrent=1)
440448
repo = InMemoryRecipeRepository()
441449
recipe_info = _make_recipe_info("test-recipe")

tests/server/test_tools_dispatch_params.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
_make_standard_recipe,
1313
_no_sleep_quota_checker,
1414
_noop_quota_refresher,
15+
_patch_dispatch_quota_no_sleep,
1516
_simple_prompt_builder,
1617
)
1718

@@ -26,6 +27,7 @@ async def test_dispatch_food_truck_tool_passes_resume_session_id_to_executor(
2627
from autoskillit.server.tools.tools_fleet_dispatch import dispatch_food_truck
2728

2829
monkeypatch.setenv("AUTOSKILLIT_SESSION_TYPE", "fleet")
30+
_patch_dispatch_quota_no_sleep(monkeypatch)
2931
tool_ctx_kitchen_open.fleet_lock = FleetSemaphore(max_concurrent=1)
3032
repo = InMemoryRecipeRepository()
3133
recipe_info = _make_recipe_info("test-recipe")
@@ -59,6 +61,7 @@ async def test_dispatch_food_truck_tool_passes_resume_message_to_executor(
5961
from autoskillit.server.tools.tools_fleet_dispatch import dispatch_food_truck
6062

6163
monkeypatch.setenv("AUTOSKILLIT_SESSION_TYPE", "fleet")
64+
_patch_dispatch_quota_no_sleep(monkeypatch)
6265
tool_ctx_kitchen_open.fleet_lock = FleetSemaphore(max_concurrent=1)
6366
repo = InMemoryRecipeRepository()
6467
recipe_info = _make_recipe_info("test-recipe")
@@ -93,6 +96,7 @@ async def test_dispatch_food_truck_tool_passes_caller_instructions_into_prompt(
9396
from autoskillit.server.tools.tools_fleet_dispatch import dispatch_food_truck
9497

9598
monkeypatch.setenv("AUTOSKILLIT_SESSION_TYPE", "fleet")
99+
_patch_dispatch_quota_no_sleep(monkeypatch)
96100
tool_ctx_kitchen_open.fleet_lock = FleetSemaphore(max_concurrent=1)
97101
repo = InMemoryRecipeRepository()
98102
recipe_info = _make_recipe_info("test-recipe")
@@ -121,6 +125,7 @@ async def test_dispatch_food_truck_no_caller_instructions_section_when_not_speci
121125
from autoskillit.server.tools.tools_fleet_dispatch import dispatch_food_truck
122126

123127
monkeypatch.setenv("AUTOSKILLIT_SESSION_TYPE", "fleet")
128+
_patch_dispatch_quota_no_sleep(monkeypatch)
124129
tool_ctx_kitchen_open.fleet_lock = FleetSemaphore(max_concurrent=1)
125130
repo = InMemoryRecipeRepository()
126131
recipe_info = _make_recipe_info("test-recipe")
@@ -146,8 +151,9 @@ class TestDispatchFoodTruckIdleTimeout:
146151
def _set_fleet_session(self, monkeypatch):
147152
monkeypatch.setenv("AUTOSKILLIT_SESSION_TYPE", "fleet")
148153

149-
def _setup_dispatch(self, tool_ctx):
154+
def _setup_dispatch(self, tool_ctx, monkeypatch):
150155
"""Wire tool_ctx for a standard dispatch with InMemoryHeadlessExecutor."""
156+
_patch_dispatch_quota_no_sleep(monkeypatch)
151157
tool_ctx.fleet_lock = FleetSemaphore(max_concurrent=1)
152158
repo = InMemoryRecipeRepository()
153159
recipe_info = _make_recipe_info("test-recipe")
@@ -163,7 +169,7 @@ async def test_dispatch_food_truck_passes_idle_output_timeout_to_executor(
163169
"""dispatch_food_truck MCP tool forwards idle_output_timeout to executor."""
164170
from autoskillit.server.tools.tools_fleet_dispatch import dispatch_food_truck
165171

166-
self._setup_dispatch(tool_ctx_kitchen_open)
172+
self._setup_dispatch(tool_ctx_kitchen_open, monkeypatch)
167173

168174
await dispatch_food_truck(
169175
recipe="test-recipe",
@@ -182,7 +188,7 @@ async def test_dispatch_food_truck_idle_timeout_none_when_not_specified(
182188
"""When idle_output_timeout is not specified, executor receives None."""
183189
from autoskillit.server.tools.tools_fleet_dispatch import dispatch_food_truck
184190

185-
self._setup_dispatch(tool_ctx_kitchen_open)
191+
self._setup_dispatch(tool_ctx_kitchen_open, monkeypatch)
186192

187193
await dispatch_food_truck(
188194
recipe="test-recipe",
@@ -200,7 +206,7 @@ async def test_dispatch_food_truck_idle_timeout_overrides_config_default(
200206
"""Explicit idle_output_timeout=0 overrides the config default of 1000."""
201207
from autoskillit.server.tools.tools_fleet_dispatch import dispatch_food_truck
202208

203-
self._setup_dispatch(tool_ctx_kitchen_open)
209+
self._setup_dispatch(tool_ctx_kitchen_open, monkeypatch)
204210
# Config idle_output_timeout is 1000 (default from RunSkillConfig)
205211
assert tool_ctx_kitchen_open.config.run_skill.idle_output_timeout == 1000
206212

@@ -222,7 +228,7 @@ async def test_execute_dispatch_passes_idle_output_timeout_to_executor(
222228
"""execute_dispatch forwards idle_output_timeout to executor.dispatch_food_truck."""
223229
from autoskillit.fleet._api import execute_dispatch
224230

225-
self._setup_dispatch(tool_ctx)
231+
self._setup_dispatch(tool_ctx, monkeypatch)
226232

227233
await execute_dispatch(
228234
tool_ctx=tool_ctx,
@@ -252,6 +258,7 @@ async def test_dispatch_food_truck_returns_fleet_error_on_mcp_timeout(
252258
from autoskillit.server.tools.tools_fleet_dispatch import dispatch_food_truck
253259

254260
monkeypatch.setenv("AUTOSKILLIT_SESSION_TYPE", "fleet")
261+
_patch_dispatch_quota_no_sleep(monkeypatch)
255262
tool_ctx_kitchen_open.fleet_lock = FleetSemaphore(max_concurrent=1)
256263
repo = InMemoryRecipeRepository()
257264
recipe_info = _make_recipe_info("test-recipe")

0 commit comments

Comments
 (0)