JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(a2a): add check for None user state before restoration
NickFuryXXXe8fc133bddfa
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/core/template/a2a_outbound_template.py b/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/core/template/a2a_outbound_template.pyindex f1caa81ea2..d9818f4504 100644--- a/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/core/template/a2a_outbound_template.py+++ b/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/core/template/a2a_outbound_template.py@@ -172,6 +172,8 @@ class A2AOutboundTemplateService:await repo.upsert(projection)for row in old_user_states:user_state = _row_for_restore(row, "updated_at")+ if user_state is None:+ continueuser_state.setdefault("user_id", None)await user_states.upsert(user_state)runtime_state = _row_for_restore(diff --git a/tests/unit_tests/gateway/test_manager_config_receiver_a2a.py b/tests/unit_tests/gateway/test_manager_config_receiver_a2a.pyindex b09b2571ca..3296dfc92f 100644--- a/tests/unit_tests/gateway/test_manager_config_receiver_a2a.py+++ b/tests/unit_tests/gateway/test_manager_config_receiver_a2a.py@@ -797,16 +797,18 @@ def test_a2a_delete_restores_projection_and_local_state_on_cleanup_failure(assert client.post(path, json=_outbound_payload()).status_code == 200user_states = repos["a2a_outbound_user_state"]runtime_states = repos["a2a_outbound_runtime_state"]- client.portal.call(- lambda: user_states.create(- {- "template_id": "a2a-weather",- "user_id": "user-1",- "user_enabled": False,- "updated_at": datetime.now(timezone.utc),- }+ expected_user_states = {"user-1": False, "user-2": True, None: False}+ for user_id, enabled in expected_user_states.items():+ client.portal.call(+ lambda user_id=user_id, enabled=enabled: user_states.create(+ {+ "template_id": "a2a-weather",+ "user_id": user_id,+ "user_enabled": enabled,+ "updated_at": datetime.now(timezone.utc),+ }+ ))- )client.portal.call(lambda: runtime_states.create({@@ -836,12 +838,13 @@ def test_a2a_delete_restores_projection_and_local_state_on_cleanup_failure()is not None)- assert (- client.portal.call(lambda: user_states.get(template_id="a2a-weather", user_id="user-1"))[- "user_enabled"- ]- is False+ restored_user_states = client.portal.call(+ lambda: user_states.list(filters={"template_id": "a2a-weather"}))+ assert len(restored_user_states) == len(expected_user_states)+ assert {+ row["user_id"]: row["user_enabled"] for row in restored_user_states+ } == expected_user_statesassert client.portal.call(lambda: runtime_states.get(template_id="a2a-weather"))["availability"] == A2AOutboundAvailability.UNREACHABLE.value@@ -849,9 +852,9 @@ def test_a2a_delete_restores_projection_and_local_state_on_cleanup_failure(monkeypatch.setattr(runtime_states, "delete", original_delete)client.portal.call(lambda: service.delete("a2a-weather"))- assert (- client.portal.call(lambda: user_states.get(template_id="a2a-weather", user_id="user-1")) is None- )+ assert client.portal.call(+ lambda: user_states.list(filters={"template_id": "a2a-weather"})+ ) == []@pytest.mark.asyncio