Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
eyurtsev committed Jan 6, 2025
1 parent 89d8460 commit eede8c8
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions libs/langgraph/tests/test_pregel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5302,10 +5302,29 @@ def node_b(state):
]


def test_falsy_return_from_task() -> None:
"""Test with a falsy return from a task."""
checkpointer = MemorySaver()

@task
def falsy_task() -> bool:
return False

@entrypoint(checkpointer=checkpointer)
def graph(state: dict) -> dict:
"""React tool."""
task_result = falsy_task().result()

Check failure on line 5316 in libs/langgraph/tests/test_pregel.py

View workflow job for this annotation

GitHub Actions / cd libs/langgraph / lint #3.12

Ruff (F841)

tests/test_pregel.py:5316:9: F841 Local variable `task_result` is assigned to but never used
human_value = interrupt("test")

Check failure on line 5317 in libs/langgraph/tests/test_pregel.py

View workflow job for this annotation

GitHub Actions / cd libs/langgraph / lint #3.12

Ruff (F841)

tests/test_pregel.py:5317:9: F841 Local variable `human_value` is assigned to but never used

configurable = {"configurable": {"thread_id": uuid.uuid4()}}
graph.invoke({"a": 5}, configurable)
graph.invoke(Command(resume="123"), configurable)


def test_multiple_interrupts_imperative() -> None:
"""Test multiple interrupts with an imperative API."""
from langgraph.func import entrypoint, task
from langgraph.checkpoint.memory import MemorySaver
from langgraph.func import entrypoint, task

checkpointer = MemorySaver()
counter = 0
Expand All @@ -5321,24 +5340,21 @@ def double(x: int) -> int:
def graph(state: dict) -> dict:
"""React tool."""

all_values = []
values = []

for idx in range(3):
value = double(idx).result()
all_values.append(value)
hil_value = interrupt({"a": "boo"})
all_values.append(hil_value)
for idx in [1, 2, 3]:
values.extend([double(idx).result(), interrupt({"a": "boo"})])

return {"all_values": all_values}
return {"values": values}

configurable = {"configurable": {"thread_id": uuid.uuid4()}}
graph.invoke({}, configurable)
# Currently fails when double accepts a variable
graph.invoke(Command(resume="a"), configurable)

# Code currently fails before this block is reached
# # Provide 2 other values
# graph.invoke(Command(resume="a"), configurable)
# graph.invoke(Command(resume="a"), configurable)
# # `double` value should be cached appropriately when used w/ `interrupt`
# assert counter == 3
graph.invoke(Command(resume="b"), configurable)
result = graph.invoke(Command(resume="c"), configurable)
# `double` value should be cached appropriately when used w/ `interrupt`
assert result == {
"values": [2, "a", 4, "b", 6, "c"],
}
assert counter == 3

0 comments on commit eede8c8

Please sign in to comment.