mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-17 21:25:46 +02:00
more explicit tests
This commit is contained in:
@@ -5422,7 +5422,15 @@ def test_interrupt_functional(
|
||||
|
||||
config = {"configurable": {"thread_id": "1"}}
|
||||
# First run, interrupted at bar
|
||||
graph.invoke({"a": ""}, config)
|
||||
assert graph.invoke({"a": ""}, config) == {
|
||||
"__interrupt__": [
|
||||
Interrupt(
|
||||
value="Provide value for bar:",
|
||||
resumable=True,
|
||||
ns=[AnyStr("graph:")],
|
||||
)
|
||||
]
|
||||
}
|
||||
# Resume with an answer
|
||||
res = graph.invoke(Command(resume="bar"), config)
|
||||
assert res == {"a": "foobar", "b": "bar"}
|
||||
@@ -5453,7 +5461,20 @@ def test_interrupt_task_functional(
|
||||
|
||||
config = {"configurable": {"thread_id": "1"}}
|
||||
# First run, interrupted at bar
|
||||
graph.invoke({"a": ""}, config)
|
||||
assert graph.invoke({"a": ""}, config) == {
|
||||
"__interrupt__": [
|
||||
Interrupt(
|
||||
value="Provide value for bar:",
|
||||
resumable=True,
|
||||
ns=[AnyStr("graph:"), AnyStr("bar:")],
|
||||
),
|
||||
Interrupt(
|
||||
value="Provide value for bar:",
|
||||
resumable=True,
|
||||
ns=[AnyStr("graph:"), AnyStr("bar:")],
|
||||
),
|
||||
]
|
||||
}
|
||||
# Resume with an answer
|
||||
res = graph.invoke(Command(resume="bar"), config)
|
||||
assert res == {"a": "foobar"}
|
||||
@@ -5469,7 +5490,20 @@ def test_interrupt_task_functional(
|
||||
return baz_result
|
||||
|
||||
# First run, interrupted at bar
|
||||
graph.invoke({"a": ""}, config)
|
||||
assert graph.invoke({"a": ""}, config) == {
|
||||
"__interrupt__": [
|
||||
Interrupt(
|
||||
value="Provide value for bar:",
|
||||
resumable=True,
|
||||
ns=[AnyStr("graph:"), AnyStr("bar:")],
|
||||
),
|
||||
Interrupt(
|
||||
value="Provide value for bar:",
|
||||
resumable=True,
|
||||
ns=[AnyStr("graph:"), AnyStr("bar:")],
|
||||
),
|
||||
]
|
||||
}
|
||||
# Provide resumes
|
||||
graph.invoke(Command(resume="bar"), config)
|
||||
assert graph.invoke(Command(resume="baz"), config) == {"a": "foobarbaz"}
|
||||
|
||||
@@ -8226,7 +8226,20 @@ async def test_handles_multiple_interrupts_from_tasks() -> None:
|
||||
config = {"configurable": {"thread_id": "1"}}
|
||||
|
||||
result = await program.ainvoke("this is ignored", config=config)
|
||||
assert "__interrupt__" in result
|
||||
assert result == {
|
||||
"__interrupt__": [
|
||||
Interrupt(
|
||||
value="Hey do you want to add James?",
|
||||
resumable=True,
|
||||
ns=[AnyStr("program:"), AnyStr("add_participant:")],
|
||||
),
|
||||
Interrupt(
|
||||
value="Hey do you want to add James?",
|
||||
resumable=True,
|
||||
ns=[AnyStr("program:"), AnyStr("add_participant:")],
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
state = await program.aget_state(config=config)
|
||||
assert len(state.tasks[0].interrupts) == 1
|
||||
@@ -8238,7 +8251,20 @@ async def test_handles_multiple_interrupts_from_tasks() -> None:
|
||||
assert task_interrupt.value == "Hey do you want to add James?"
|
||||
|
||||
result = await program.ainvoke(Command(resume=True), config=config)
|
||||
assert "__interrupt__" in result
|
||||
assert result == {
|
||||
"__interrupt__": [
|
||||
Interrupt(
|
||||
value="Hey do you want to add Will?",
|
||||
resumable=True,
|
||||
ns=[AnyStr("program:"), AnyStr("add_participant:")],
|
||||
),
|
||||
Interrupt(
|
||||
value="Hey do you want to add Will?",
|
||||
resumable=True,
|
||||
ns=[AnyStr("program:"), AnyStr("add_participant:")],
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
state = await program.aget_state(config=config)
|
||||
assert len(state.tasks[0].interrupts) == 1
|
||||
|
||||
Reference in New Issue
Block a user