From 68f6aa13d6d9a1d1a14673bf9e30de497cf7b3f1 Mon Sep 17 00:00:00 2001 From: QuantumGhost Date: Tue, 15 Jul 2025 11:36:31 +0800 Subject: [PATCH] test(api): Add a test for the type of `VariablePool.variable_dictionary` --- .../core/workflow/test_variable_pool.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/api/tests/unit_tests/core/workflow/test_variable_pool.py b/api/tests/unit_tests/core/workflow/test_variable_pool.py index cb9a4f3c44..c65b60cb4d 100644 --- a/api/tests/unit_tests/core/workflow/test_variable_pool.py +++ b/api/tests/unit_tests/core/workflow/test_variable_pool.py @@ -1,3 +1,6 @@ +import uuid +from collections import defaultdict + import pytest from core.file import File, FileTransferMethod, FileType @@ -412,3 +415,24 @@ class TestVariablePoolSerialization: assert val1.value == val2.value # Value types should be the same (more important than exact class type) assert val1.value_type == val2.value_type + + def test_variable_pool_deserialization_default_dict(self): + variable_pool = VariablePool( + user_inputs={"a": 1, "b": "2"}, + system_variables=SystemVariable(workflow_id=str(uuid.uuid4())), + environment_variables=[ + StringVariable(name="str_var", value="a"), + ], + conversation_variables=[IntegerVariable(name="int_var", value=1)], + ) + assert isinstance(variable_pool.variable_dictionary, defaultdict) + json = variable_pool.model_dump_json() + loaded = VariablePool.model_validate_json(json) + assert isinstance(loaded.variable_dictionary, defaultdict) + + loaded.add(["non_exist_node", "a"], 1) + + pool_dict = variable_pool.model_dump() + loaded = VariablePool.model_validate(pool_dict) + assert isinstance(loaded.variable_dictionary, defaultdict) + loaded.add(["non_exist_node", "a"], 1)