99
1010from __future__ import annotations
1111
12+ from contextvars import Token
1213from unittest .mock import AsyncMock
1314
1415import pytest
2021from pythinker_code .wire import Wire
2122
2223
23- def _wire_context () -> tuple [Wire , object ]:
24+ def _wire_context () -> Token [Wire | None ]:
2425 import pythinker_code .soul as soul_module
2526
2627 wire = Wire ()
27- token = soul_module ._current_wire .set (wire )
28- return wire , token
28+ return soul_module ._current_wire .set (wire )
2929
3030
31- def _reset_wire_context (token : object ) -> None :
31+ def _reset_wire_context (token : Token [ Wire | None ] ) -> None :
3232 import pythinker_code .soul as soul_module
3333
3434 soul_module ._current_wire .reset (token )
@@ -54,7 +54,7 @@ async def test_prunes_compacts_and_reports_recovered(self, runtime, tmp_path) ->
5454 soul = _make_soul (runtime , tmp_path )
5555 soul .prune_context = AsyncMock (return_value = True ) # type: ignore[method-assign]
5656 soul .compact_context = AsyncMock () # type: ignore[method-assign]
57- _ , wire_token = _wire_context ()
57+ wire_token = _wire_context ()
5858
5959 try :
6060 recovered = await soul ._recover_from_context_overflow (step_no = 3 )
@@ -70,7 +70,7 @@ async def test_prune_failure_does_not_block_compaction(self, runtime, tmp_path)
7070 soul = _make_soul (runtime , tmp_path )
7171 soul .prune_context = AsyncMock (side_effect = RuntimeError ("prune broke" )) # type: ignore[method-assign]
7272 soul .compact_context = AsyncMock () # type: ignore[method-assign]
73- _ , wire_token = _wire_context ()
73+ wire_token = _wire_context ()
7474
7575 try :
7676 recovered = await soul ._recover_from_context_overflow (step_no = 3 )
@@ -85,7 +85,7 @@ async def test_compaction_failure_reports_not_recovered(self, runtime, tmp_path)
8585 soul = _make_soul (runtime , tmp_path )
8686 soul .prune_context = AsyncMock (return_value = False ) # type: ignore[method-assign]
8787 soul .compact_context = AsyncMock (side_effect = RuntimeError ("compact broke" )) # type: ignore[method-assign]
88- _ , wire_token = _wire_context ()
88+ wire_token = _wire_context ()
8989
9090 try :
9191 recovered = await soul ._recover_from_context_overflow (step_no = 3 )
0 commit comments