@@ -22,7 +22,7 @@ def _make_executor(*entity_args) -> _EntityExecutor:
2222def _execute (executor , entity_name , operation , encoded_input = None ):
2323 """Helper to execute an entity operation."""
2424 entity_id = entities .EntityInstanceId (entity_name , "test-key" )
25- state = StateShim (None )
25+ state = StateShim (None , JsonDataConverter () )
2626 return executor .execute ("test-orchestration" , entity_id , operation , state , encoded_input )
2727
2828
@@ -75,7 +75,7 @@ def get(self):
7575 entity_id = entities .EntityInstanceId ("Counter" , "test-key" )
7676
7777 # set requires input
78- state = StateShim (None )
78+ state = StateShim (None , JsonDataConverter () )
7979 executor .execute ("test-orch" , entity_id , "set" , state , "10" )
8080 state .commit ()
8181
@@ -127,7 +127,7 @@ def counter(ctx: entities.EntityContext, input):
127127
128128 executor = _make_executor (counter )
129129 entity_id = entities .EntityInstanceId ("counter" , "test-key" )
130- state = StateShim (None )
130+ state = StateShim (None , JsonDataConverter () )
131131
132132 executor .execute ("test-orch" , entity_id , "set" , state , "42" )
133133 state .commit ()
@@ -140,19 +140,19 @@ class TestStateShimCoercion:
140140 """Tests for StateShim.get_state type coercion via the data converter."""
141141
142142 def test_get_state_none_returns_default (self ):
143- state = StateShim (None )
143+ state = StateShim (None , JsonDataConverter () )
144144 assert state .get_state (int , 0 ) == 0
145145
146146 def test_get_state_none_without_default_returns_none (self ):
147- state = StateShim (None )
147+ state = StateShim (None , JsonDataConverter () )
148148 assert state .get_state (int ) is None
149149
150150 def test_get_state_passes_through_matching_type (self ):
151- state = StateShim (5 )
151+ state = StateShim (5 , JsonDataConverter () )
152152 assert state .get_state (int ) == 5
153153
154154 def test_get_state_constructor_coercion (self ):
155- state = StateShim ("5" )
155+ state = StateShim ("5" , JsonDataConverter () )
156156 assert state .get_state (int ) == 5
157157
158158 def test_get_state_coerces_dataclass (self ):
@@ -163,7 +163,7 @@ class Counter:
163163 value : int
164164
165165 # State is stored as a plain dict (as it would be after from_json).
166- state = StateShim ({"value" : 7 })
166+ state = StateShim ({"value" : 7 }, JsonDataConverter () )
167167 result = state .get_state (Counter )
168168 assert isinstance (result , Counter )
169169 assert result .value == 7
@@ -177,7 +177,7 @@ def __init__(self, n: int):
177177 def from_json (cls , data ):
178178 return cls (data ["n" ])
179179
180- state = StateShim ({"n" : 3 })
180+ state = StateShim ({"n" : 3 }, JsonDataConverter () )
181181 result = state .get_state (Wrapped )
182182 assert isinstance (result , Wrapped )
183183 assert result .n == 3
@@ -187,7 +187,7 @@ def test_get_state_invalid_coercion_raises(self):
187187 # restoring the pre-existing strict contract for entity state access.
188188 import pytest
189189
190- state = StateShim ("not-an-int" )
190+ state = StateShim ("not-an-int" , JsonDataConverter () )
191191 with pytest .raises (TypeError ):
192192 state .get_state (int )
193193
@@ -197,7 +197,7 @@ class TestStateShimDeferredDeserialization:
197197
198198 def test_constructor_does_not_deserialize_serialized_state (self ):
199199 # A serialized payload is held verbatim until read, not eagerly parsed.
200- state = StateShim ('{"value": 7}' , is_serialized = True )
200+ state = StateShim ('{"value": 7}' , JsonDataConverter (), is_serialized = True )
201201 assert state ._current_state == '{"value": 7}'
202202
203203 def test_get_state_defers_deserialization_with_type (self ):
@@ -207,13 +207,13 @@ def test_get_state_defers_deserialization_with_type(self):
207207 class Counter :
208208 value : int
209209
210- state = StateShim ('{"value": 7}' , is_serialized = True )
210+ state = StateShim ('{"value": 7}' , JsonDataConverter (), is_serialized = True )
211211 result = state .get_state (Counter )
212212 assert isinstance (result , Counter )
213213 assert result .value == 7
214214
215215 def test_get_state_no_type_returns_parsed_value (self ):
216- state = StateShim ('{"value": 7}' , is_serialized = True )
216+ state = StateShim ('{"value": 7}' , JsonDataConverter (), is_serialized = True )
217217 assert state .get_state () == {"value" : 7 }
218218
219219 def test_deferred_deserialization_passes_raw_string_to_converter (self ):
@@ -247,11 +247,11 @@ def coerce(self, value, target_type=None):
247247 def test_encode_state_passes_through_unmodified_payload (self ):
248248 # An unread/unmodified serialized payload is returned verbatim, never
249249 # re-serialized (which would double-encode the JSON string).
250- state = StateShim ('{"value": 7}' , is_serialized = True )
250+ state = StateShim ('{"value": 7}' , JsonDataConverter (), is_serialized = True )
251251 assert state .encode_state () == '{"value": 7}'
252252
253253 def test_reading_does_not_trigger_double_encoding (self ):
254- state = StateShim ('{"value": 7}' , is_serialized = True )
254+ state = StateShim ('{"value": 7}' , JsonDataConverter (), is_serialized = True )
255255 # Reading (even with a type) must not turn the payload into a live value
256256 # that would be re-serialized into a JSON-encoded string.
257257 state .get_state ()
@@ -261,31 +261,31 @@ def test_reading_does_not_trigger_double_encoding(self):
261261 assert json .loads (encoded ) == {"value" : 7 }
262262
263263 def test_encode_state_serializes_live_value_after_set_state (self ):
264- state = StateShim ('{"value": 7}' , is_serialized = True )
264+ state = StateShim ('{"value": 7}' , JsonDataConverter (), is_serialized = True )
265265 state .set_state ({"value" : 8 })
266266 encoded = state .encode_state ()
267267 assert json .loads (encoded ) == {"value" : 8 }
268268
269269 def test_encode_state_none_when_state_is_none (self ):
270- state = StateShim (None , is_serialized = True )
270+ state = StateShim (None , JsonDataConverter (), is_serialized = True )
271271 assert state .encode_state () is None
272272
273273 def test_commit_preserves_unmodified_payload (self ):
274- state = StateShim ('{"value": 7}' , is_serialized = True )
274+ state = StateShim ('{"value": 7}' , JsonDataConverter (), is_serialized = True )
275275 state .commit ()
276276 # After commit, the (unmodified) state still round-trips without
277277 # double-encoding.
278278 assert state .encode_state () == '{"value": 7}'
279279
280280 def test_rollback_restores_unmodified_payload (self ):
281- state = StateShim ('{"value": 7}' , is_serialized = True )
281+ state = StateShim ('{"value": 7}' , JsonDataConverter (), is_serialized = True )
282282 state .commit ()
283283 state .set_state ({"value" : 99 })
284284 state .rollback ()
285285 assert state .encode_state () == '{"value": 7}'
286286
287287 def test_falsy_serialized_state_is_not_dropped (self ):
288288 # A serialized falsy value (e.g. 0) is preserved, not treated as cleared.
289- state = StateShim ("0" , is_serialized = True )
289+ state = StateShim ("0" , JsonDataConverter (), is_serialized = True )
290290 assert state .get_state (int ) == 0
291291 assert state .encode_state () == "0"
0 commit comments