From 98b0d89bbf982fddf6f7e699321fa31f4d9e7b6b Mon Sep 17 00:00:00 2001 From: Caspar Broekhuizen Date: Mon, 29 Sep 2025 20:51:25 -0700 Subject: [PATCH] style(langgraph): improve test documentation --- libs/langgraph/tests/test_pregel.py | 30 ++++++++++++++++++----- libs/langgraph/tests/test_pregel_async.py | 30 ++++++++++++++++++----- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/libs/langgraph/tests/test_pregel.py b/libs/langgraph/tests/test_pregel.py index 292f8efd3..7702d79e2 100644 --- a/libs/langgraph/tests/test_pregel.py +++ b/libs/langgraph/tests/test_pregel.py @@ -8521,6 +8521,11 @@ def test_interrupt_stream_mode_values(): def test_subgraph_resume_reexecutes_from_valid_checkpoint( sync_checkpointer: BaseCheckpointSaver, ) -> None: + """Verify that a resumed subgraph doesn't replay future state during a time-jump. + + After rewinding to a pre-tool checkpoint, the entire subgraph should execute again rather than replaying state from the previous execution. + """ + class InnerState(TypedDict, total=False): input: str output: str @@ -8595,15 +8600,28 @@ def test_subgraph_resume_reexecutes_from_valid_checkpoint( assert outer_tool_calls == 1 history = list(graph.get_state_history(config)) - resume_state = next( - state - for state in history - if state.next == ("model",) and "output" not in state.values - ) + # i: history[i].next, history[i].values: + # 0: ('model',) {'input': 'hello', 'output': 'subgraph result: inner 1'} + # 1: ('tools',) {'input': 'hello'} + # 2: ('model',) {'input': 'hello'} + # 3: ('__start__',) {} + + # resume from tools (node that executes subgraph) + resume_state = history[1] result = graph.invoke(Command(resume="resume"), resume_state.config) assert result["output"] == "subgraph result: inner 2" assert inner_tool_calls == 2 assert outer_tool_calls == 2 - assert outer_model_calls == 3 + assert outer_model_calls == 2 + + # resume from model + resume_state = history[2] + + result = graph.invoke(Command(resume="resume"), resume_state.config) + + assert result["output"] == "subgraph result: inner 3" + assert inner_tool_calls == 3 + assert outer_tool_calls == 3 + assert outer_model_calls == 4 diff --git a/libs/langgraph/tests/test_pregel_async.py b/libs/langgraph/tests/test_pregel_async.py index 109cf67e3..b560a82eb 100644 --- a/libs/langgraph/tests/test_pregel_async.py +++ b/libs/langgraph/tests/test_pregel_async.py @@ -9216,6 +9216,11 @@ async def test_astream_waiter_cleanup_on_cancel( async def test_subgraph_resume_reexecutes_from_valid_checkpoint( async_checkpointer: BaseCheckpointSaver, ) -> None: + """Verify that a resumed subgraph doesn't replay future state during a time-jump. + + After rewinding to a pre-tool checkpoint, the entire subgraph should execute again rather than replaying state from the previous execution. + """ + class InnerState(TypedDict, total=False): input: str output: str @@ -9290,15 +9295,28 @@ async def test_subgraph_resume_reexecutes_from_valid_checkpoint( assert outer_tool_calls == 1 history = [state async for state in graph.aget_state_history(config)] - resume_state = next( - state - for state in history - if state.next == ("model",) and "output" not in state.values - ) + # i: history[i].next, history[i].values: + # 0: ('model',) {'input': 'hello', 'output': 'subgraph result: inner 1'} + # 1: ('tools',) {'input': 'hello'} + # 2: ('model',) {'input': 'hello'} + # 3: ('__start__',) {} + + # resume from tools (node that executes subgraph) + resume_state = history[1] result = await graph.ainvoke(Command(resume="resume"), resume_state.config) assert result["output"] == "subgraph result: inner 2" assert inner_tool_calls == 2 assert outer_tool_calls == 2 - assert outer_model_calls >= 3 + assert outer_model_calls == 2 + + # resume from model + resume_state = history[2] + + result = graph.invoke(Command(resume="resume"), resume_state.config) + + assert result["output"] == "subgraph result: inner 3" + assert inner_tool_calls == 3 + assert outer_tool_calls == 3 + assert outer_model_calls == 4