|
23 | 23 | HumanMessagePromptTemplate, |
24 | 24 | PromptTemplate, |
25 | 25 | ) |
| 26 | +from langchain_core.runnables import RunnablePassthrough, RunnablePick |
26 | 27 | from langchain_core.runnables.history import RunnableWithMessageHistory |
27 | 28 | from langchain_core.tracers import log_stream |
28 | 29 | from langchain_core.utils import from_env |
@@ -1233,3 +1234,27 @@ def test_log_stream_does_not_use_all(self) -> None: |
1233 | 1234 | 'allowed_objects="messages"' in source |
1234 | 1235 | or "allowed_objects='messages'" in source |
1235 | 1236 | ) |
| 1237 | + |
| 1238 | + |
| 1239 | +def test_runnable_pick_roundtrips() -> None: |
| 1240 | + """Test `RunnablePick` can be loaded back after being dumped. |
| 1241 | +
|
| 1242 | + Regression test: `RunnablePick` reports `is_lc_serializable()` and dumps fine, |
| 1243 | + but was missing from the deserialization mapping, so `load` rejected it while |
| 1244 | + its siblings in the same module round-tripped. |
| 1245 | + """ |
| 1246 | + original = RunnablePick(keys=["a"]) |
| 1247 | + |
| 1248 | + revived = load(dumpd(original)) |
| 1249 | + |
| 1250 | + assert isinstance(revived, RunnablePick) |
| 1251 | + assert revived.keys == ["a"] |
| 1252 | + |
| 1253 | + |
| 1254 | +def test_chain_using_pick_roundtrips() -> None: |
| 1255 | + """Test a chain built with the public `.pick()` helper survives a round trip.""" |
| 1256 | + chain = RunnablePassthrough().pick(["a"]) |
| 1257 | + |
| 1258 | + revived = load(dumpd(chain)) |
| 1259 | + |
| 1260 | + assert revived.invoke({"a": 1, "b": 2}) == {"a": 1} |
0 commit comments