mirror of
https://github.com/langgenius/dify.git
synced 2026-03-17 04:47:50 +08:00
Length limit for UserAction fields (vibe-kanban e9ec1f07)
Add the following length limit to UserAction fields: - limit the length of `id` to 20 chars. - limit the length of title to 40 chars. Add some unit tests to ensure the validation rules are enforced.
This commit is contained in:
@ -166,8 +166,8 @@ class UserAction(BaseModel):
|
||||
# It also serves as the identifiers of output handle.
|
||||
#
|
||||
# The id must be a valid identifier (satisfy the _IDENTIFIER_PATTERN above.)
|
||||
id: str
|
||||
title: str
|
||||
id: str = Field(max_length=20)
|
||||
title: str = Field(max_length=20)
|
||||
button_style: ButtonStyle = ButtonStyle.DEFAULT
|
||||
|
||||
@field_validator("id")
|
||||
|
||||
@ -126,6 +126,34 @@ class TestUserAction:
|
||||
|
||||
assert action.button_style == ButtonStyle.DEFAULT
|
||||
|
||||
def test_user_action_length_boundaries(self):
|
||||
"""Test user action id and title length boundaries."""
|
||||
action = UserAction(id="a" * 20, title="b" * 20)
|
||||
|
||||
assert action.id == "a" * 20
|
||||
assert action.title == "b" * 20
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("field_name", "value"),
|
||||
[
|
||||
("id", "a" * 21),
|
||||
("title", "b" * 21),
|
||||
],
|
||||
)
|
||||
def test_user_action_length_limits(self, field_name: str, value: str):
|
||||
"""User action fields should enforce max length."""
|
||||
data = {"id": "approve", "title": "Approve"}
|
||||
data[field_name] = value
|
||||
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
UserAction(**data)
|
||||
|
||||
errors = exc_info.value.errors()
|
||||
assert any(
|
||||
error["loc"] == (field_name,) and error["type"] == "string_too_long"
|
||||
for error in errors
|
||||
)
|
||||
|
||||
|
||||
class TestHumanInputNodeData:
|
||||
"""Test HumanInputNodeData entity."""
|
||||
|
||||
Reference in New Issue
Block a user