Merge branch 'main' into feat/support-agent-sandbox

This commit is contained in:
Novice
2026-03-24 17:12:13 +08:00
136 changed files with 4018 additions and 706 deletions

View File

@ -68,8 +68,8 @@ class TestRateLimit:
assert rate_limit.disabled()
assert not hasattr(rate_limit, "initialized")
def test_should_skip_reinitialization_of_existing_instance(self, redis_patch):
"""Test that existing instance doesn't reinitialize."""
def test_should_flush_cache_when_reinitializing_existing_instance(self, redis_patch):
"""Test existing instance refreshes Redis cache on reinitialization."""
redis_patch.configure_mock(
**{
"exists.return_value": False,
@ -82,7 +82,37 @@ class TestRateLimit:
RateLimit("client1", 10)
redis_patch.setex.assert_called_once_with(
"dify:rate_limit:client1:max_active_requests",
timedelta(days=1),
10,
)
def test_should_reinitialize_after_being_disabled(self, redis_patch):
"""Test disabled instance can be reinitialized and writes max_active_requests to Redis."""
redis_patch.configure_mock(
**{
"exists.return_value": False,
"setex.return_value": True,
}
)
# First construct with max_active_requests = 0 (disabled), which should skip initialization.
RateLimit("client1", 0)
# Redis should not have been written to during disabled initialization.
redis_patch.setex.assert_not_called()
redis_patch.reset_mock()
# Reinitialize with a positive max_active_requests value; this should not raise
# and must write the max_active_requests key to Redis.
RateLimit("client1", 10)
redis_patch.setex.assert_called_once_with(
"dify:rate_limit:client1:max_active_requests",
timedelta(days=1),
10,
)
def test_should_be_disabled_when_max_requests_is_zero_or_negative(self):
"""Test disabled state for zero or negative limits."""

View File

@ -4800,8 +4800,8 @@ class TestInternalHooksCoverage:
dataset_docs = [
SimpleNamespace(id="doc-a", doc_form=IndexStructureType.PARENT_CHILD_INDEX),
SimpleNamespace(id="doc-b", doc_form=IndexStructureType.PARENT_CHILD_INDEX),
SimpleNamespace(id="doc-c", doc_form="qa_model"),
SimpleNamespace(id="doc-d", doc_form="qa_model"),
SimpleNamespace(id="doc-c", doc_form=IndexStructureType.QA_INDEX),
SimpleNamespace(id="doc-d", doc_form=IndexStructureType.QA_INDEX),
]
child_chunks = [SimpleNamespace(index_node_id="idx-a", segment_id="seg-a")]
segments = [SimpleNamespace(index_node_id="idx-c", id="seg-c")]