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:
QuantumGhost
2026-01-16 18:18:37 +08:00
parent 1f47ea8452
commit 7bc7a8d0ab
2 changed files with 30 additions and 2 deletions

View File

@ -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")

View File

@ -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."""