mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-21 02:19:31 +00:00
test: Add failing test for BaseCallbackManager.merge
(#32040)
This pull request introduces a failing unit test to reproduce the bug reported in issue #32028. The test asserts the expected behavior: `BaseCallbackManager.merge()` should combine `handlers` and `inheritable_handlers` independently, without mixing them. This test will fail on the current codebase and is intended to guide the fix and prevent future regressions. --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com> Co-authored-by: Mason Daugherty <mason@langchain.dev>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from langchain_core.callbacks.base import BaseCallbackHandler, BaseCallbackManager
|
||||
|
||||
|
||||
@@ -13,3 +15,29 @@ def test_remove_handler() -> None:
|
||||
manager = BaseCallbackManager([handler1], inheritable_handlers=[handler2])
|
||||
manager.remove_handler(handler1)
|
||||
manager.remove_handler(handler2)
|
||||
|
||||
|
||||
@pytest.mark.xfail(
|
||||
reason="TODO: #32028 merge() incorrectly mixes handlers and inheritable_handlers"
|
||||
)
|
||||
def test_merge_preserves_handler_distinction() -> None:
|
||||
"""Test that merging managers preserves the distinction between handlers.
|
||||
|
||||
This test verifies the correct behavior of the BaseCallbackManager.merge()
|
||||
method. When two managers are merged, their handlers and
|
||||
inheritable_handlers should be combined independently.
|
||||
|
||||
Currently, it is expected to xfail until the issue is resolved.
|
||||
"""
|
||||
h1 = BaseCallbackHandler()
|
||||
h2 = BaseCallbackHandler()
|
||||
ih1 = BaseCallbackHandler()
|
||||
ih2 = BaseCallbackHandler()
|
||||
|
||||
m1 = BaseCallbackManager(handlers=[h1], inheritable_handlers=[ih1])
|
||||
m2 = BaseCallbackManager(handlers=[h2], inheritable_handlers=[ih2])
|
||||
|
||||
merged = m1.merge(m2)
|
||||
|
||||
assert set(merged.handlers) == {h1, h2}
|
||||
assert set(merged.inheritable_handlers) == {ih1, ih2}
|
||||
|
Reference in New Issue
Block a user