|
61 | 61 | ) |
62 | 62 | from agents.run_state import ( |
63 | 63 | CURRENT_SCHEMA_VERSION, |
| 64 | + SUPPORTED_SCHEMA_VERSIONS, |
64 | 65 | RunState, |
65 | 66 | _build_agent_map, |
66 | 67 | _deserialize_items, |
@@ -286,11 +287,13 @@ async def test_throws_error_if_schema_version_is_missing_or_invalid(self): |
286 | 287 | await RunState.from_string(agent, str_data) |
287 | 288 |
|
288 | 289 | json_data["$schemaVersion"] = "0.1" |
| 290 | + supported_versions = ", ".join(sorted(SUPPORTED_SCHEMA_VERSIONS)) |
289 | 291 | with pytest.raises( |
290 | 292 | Exception, |
291 | 293 | match=( |
292 | 294 | f"Run state schema version 0.1 is not supported. " |
293 | | - f"Please use version {CURRENT_SCHEMA_VERSION}" |
| 295 | + f"Supported versions are: {supported_versions}. " |
| 296 | + f"New snapshots are written as version {CURRENT_SCHEMA_VERSION}." |
294 | 297 | ), |
295 | 298 | ): |
296 | 299 | await RunState.from_string(agent, json.dumps(json_data)) |
@@ -3330,6 +3333,31 @@ async def test_from_json_unsupported_schema_version(self): |
3330 | 3333 | with pytest.raises(UserError, match="Run state schema version 2.0 is not supported"): |
3331 | 3334 | await RunState.from_json(agent, state_json) |
3332 | 3335 |
|
| 3336 | + @pytest.mark.asyncio |
| 3337 | + async def test_from_json_accepts_previous_schema_version(self): |
| 3338 | + """Test that from_json accepts a previous, explicitly supported schema version.""" |
| 3339 | + agent = Agent(name="TestAgent") |
| 3340 | + state_json = { |
| 3341 | + "$schemaVersion": "1.0", |
| 3342 | + "original_input": "test", |
| 3343 | + "current_agent": {"name": "TestAgent"}, |
| 3344 | + "context": { |
| 3345 | + "context": {"foo": "bar"}, |
| 3346 | + "usage": {"requests": 0, "input_tokens": 0, "output_tokens": 0, "total_tokens": 0}, |
| 3347 | + "approvals": {}, |
| 3348 | + }, |
| 3349 | + "max_turns": 3, |
| 3350 | + "current_turn": 0, |
| 3351 | + "model_responses": [], |
| 3352 | + "generated_items": [], |
| 3353 | + } |
| 3354 | + |
| 3355 | + restored = await RunState.from_json(agent, state_json) |
| 3356 | + assert restored._current_agent is not None |
| 3357 | + assert restored._current_agent.name == "TestAgent" |
| 3358 | + assert restored._context is not None |
| 3359 | + assert restored._context.context == {"foo": "bar"} |
| 3360 | + |
3333 | 3361 | @pytest.mark.asyncio |
3334 | 3362 | async def test_from_json_agent_not_found(self): |
3335 | 3363 | """Test that from_json raises error when agent is not found in agent map.""" |
|
0 commit comments