You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lib/validation_utils.py contains core validation helpers used across the backend, but we currently don’t have direct unit tests for the two most foundational functions:
validate_non_empty_iterable
validate_non_empty_string (drives string validation across models/validators)
Bugs here would be high blast-radius (they’re reused widely), and the expected error messages are part of the developer contract (tests elsewhere sometimes match= specific strings).
Related files
lib/validation_utils.py (functions under test)
simulation/core/utils/validators.py (calls into validate_nonnegative_value / validate_non_empty_string)
Example downstream users (for context only; not required to test here):
Issue Description
Problem:
lib/validation_utils.pycontains core validation helpers used across the backend, but we currently don’t have direct unit tests for the two most foundational functions:validate_non_empty_iterablevalidate_non_empty_string(drives string validation across models/validators)match=specific strings).Related files
lib/validation_utils.py(functions under test)simulation/core/utils/validators.py(calls intovalidate_nonnegative_value/validate_non_empty_string)simulation/core/models/profiles.pysimulation/core/models/posts.pysimulation/core/models/runs.pyRelated tests (for how tests should look)
tests/ml_tooling/llm/test_llm_service.pytests/simulation/core/test_action_generators_registry.pyWhat tests we have / don’t have today:
tests/test_validation_decorators.py.tests/lib/*coverage, but it’s currently onlytest_load_env_vars.py.lib/validation_utils.py(notests/lib/test_validation_utils.pytoday).Implementation notes / skeleton structure:
tests/lib/test_validation_utils.pyimport pytestfrom lib.validation_utils import validate_nonnegative_value, validate_non_empty_string@pytest.mark.parametrize):floatinputs (e.g.0.0,-0.1) since the helper supports both int/float.def test_validate_non_empty_string_strips_whitespace(): ...(e.g." hi "returns"hi")def test_validate_non_empty_string_raises_on_none(): ...(message contains"cannot be None")def test_validate_non_empty_string_raises_on_non_string(): ...(message contains"must be a string")def test_validate_non_empty_string_raises_on_empty_or_whitespace(): ...(message contains"cannot be empty")What success looks like:
tests/lib/test_validation_utils.pyexists and passes locally:uv run pytest tests/lib/test_validation_utils.pylib/validation_utils.py:validate_nonnegative_value:"<field> must be >= 0"whenok_equals_zero=True"<field> must be greater than 0"whenok_equals_zero=Falsevalidate_non_empty_string:None, non-str, and empty-after-strip inputs with the expected message fragments