Skip to content

Commit

Permalink
Add test to confirm only one root run is produced
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos committed Sep 4, 2024
1 parent af780f9 commit dc10b3a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion libs/langgraph/tests/test_pregel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9823,12 +9823,18 @@ def edit(state: JokeState):

graph = builder.compile(checkpointer=checkpointer)
config = {"configurable": {"thread_id": "1"}}
tracer = FakeTracer()

# invoke and pause at nested interrupt
assert graph.invoke({"subjects": ["cats", "dogs"]}, config=config) == {
assert graph.invoke(
{"subjects": ["cats", "dogs"]}, config={**config, "callbacks": [tracer]}
) == {
"subjects": ["cats", "dogs"],
"jokes": [],
}
assert len(tracer.runs) == 1, "Should produce exactly 1 root run"

# check state
outer_state = graph.get_state(config)
assert outer_state == StateSnapshot(
values={"subjects": ["cats", "dogs"], "jokes": []},
Expand Down
8 changes: 6 additions & 2 deletions libs/langgraph/tests/test_pregel_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -8467,15 +8467,19 @@ async def edit(state: JokeState):
async with awith_checkpointer(checkpointer_name) as checkpointer:
graph = builder.compile(checkpointer=checkpointer)
config = {"configurable": {"thread_id": "1"}}
tracer = FakeTracer()

# invoke and pause at nested interrupt
assert await graph.ainvoke({"subjects": ["cats", "dogs"]}, config=config) == {
assert await graph.ainvoke(
{"subjects": ["cats", "dogs"]}, config={**config, "callbacks": [tracer]}
) == {
"subjects": ["cats", "dogs"],
"jokes": [],
}
assert len(tracer.runs) == 1, "Should produce exactly 1 root run"

# check state
outer_state = await graph.aget_state(config)

assert outer_state == StateSnapshot(
values={"subjects": ["cats", "dogs"], "jokes": []},
tasks=(
Expand Down

0 comments on commit dc10b3a

Please sign in to comment.