Skip to content

Commit 637bb1c

Browse files
feat: refactor tests coverage (#33927)
middleware tests have gotten quite unwieldy, major restructuring, sets the stage for coverage increase this is super hard to review -- as a proof that we've retained important tests, I ran coverage on `master` and this branch and confirmed identical coverage. * moving all middleware related tests to `agents/middleware` folder * consolidating related test files * adding coverage utility to makefile
1 parent 3dfea96 commit 637bb1c

40 files changed

+5309
-4854
lines changed

libs/langchain_v1/Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all start_services stop_services coverage test test_fast extended_tests test_watch test_watch_extended integration_tests check_imports lint format lint_diff format_diff lint_package lint_tests help
1+
.PHONY: all start_services stop_services coverage coverage_agents test test_fast extended_tests test_watch test_watch_extended integration_tests check_imports lint format lint_diff format_diff lint_package lint_tests help
22

33
# Default target executed when no arguments are given to make.
44
all: help
@@ -27,8 +27,17 @@ coverage:
2727
--cov-report term-missing:skip-covered \
2828
$(TEST_FILE)
2929

30+
# Run middleware and agent tests with coverage report.
31+
coverage_agents:
32+
uv run --group test pytest \
33+
tests/unit_tests/agents/middleware/ \
34+
tests/unit_tests/agents/test_*.py \
35+
--cov=langchain.agents \
36+
--cov-report=term-missing \
37+
--cov-report=html:htmlcov \
38+
3039
test:
31-
make start_services && LANGGRAPH_TEST_FAST=0 uv run --no-sync --active --group test pytest -n auto --disable-socket --allow-unix-socket $(TEST_FILE) --cov-report term-missing:skip-covered; \
40+
make start_services && LANGGRAPH_TEST_FAST=0 uv run --no-sync --active --group test pytest -n auto --disable-socket --allow-unix-socket $(TEST_FILE) --cov-report term-missing:skip-covered --snapshot-update; \
3241
EXIT_CODE=$$?; \
3342
make stop_services; \
3443
exit $$EXIT_CODE
@@ -93,6 +102,7 @@ help:
93102
@echo 'lint - run linters'
94103
@echo '-- TESTS --'
95104
@echo 'coverage - run unit tests and generate coverage report'
105+
@echo 'coverage_agents - run middleware and agent tests with coverage report'
96106
@echo 'test - run unit tests with all services'
97107
@echo 'test_fast - run unit tests with in-memory services only'
98108
@echo 'tests - run unit tests (alias for "make test")'
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# serializer version: 1
2+
# name: test_agent_graph_with_jump_to_end_as_after_agent
3+
'''
4+
---
5+
config:
6+
flowchart:
7+
curve: linear
8+
---
9+
graph TD;
10+
__start__([<p>__start__</p>]):::first
11+
model(model)
12+
tools(tools)
13+
NoopZero\2ebefore_agent(NoopZero.before_agent)
14+
NoopOne\2eafter_agent(NoopOne.after_agent)
15+
NoopTwo\2eafter_agent(NoopTwo.after_agent)
16+
__end__([<p>__end__</p>]):::last
17+
NoopTwo\2eafter_agent --> NoopOne\2eafter_agent;
18+
NoopZero\2ebefore_agent -.-> NoopTwo\2eafter_agent;
19+
NoopZero\2ebefore_agent -.-> model;
20+
__start__ --> NoopZero\2ebefore_agent;
21+
model -.-> NoopTwo\2eafter_agent;
22+
model -.-> tools;
23+
tools -.-> model;
24+
NoopOne\2eafter_agent --> __end__;
25+
classDef default fill:#f2f0ff,line-height:1.2
26+
classDef first fill-opacity:0
27+
classDef last fill:#bfb6fc
28+
29+
'''
30+
# ---
31+
# name: test_create_agent_jump[memory]
32+
'''
33+
---
34+
config:
35+
flowchart:
36+
curve: linear
37+
---
38+
graph TD;
39+
__start__([<p>__start__</p>]):::first
40+
model(model)
41+
tools(tools)
42+
NoopSeven\2ebefore_model(NoopSeven.before_model)
43+
NoopSeven\2eafter_model(NoopSeven.after_model)
44+
NoopEight\2ebefore_model(NoopEight.before_model)
45+
NoopEight\2eafter_model(NoopEight.after_model)
46+
__end__([<p>__end__</p>]):::last
47+
NoopEight\2eafter_model --> NoopSeven\2eafter_model;
48+
NoopEight\2ebefore_model -.-> __end__;
49+
NoopEight\2ebefore_model -.-> model;
50+
NoopSeven\2eafter_model -.-> NoopSeven\2ebefore_model;
51+
NoopSeven\2eafter_model -.-> __end__;
52+
NoopSeven\2eafter_model -.-> tools;
53+
NoopSeven\2ebefore_model --> NoopEight\2ebefore_model;
54+
__start__ --> NoopSeven\2ebefore_model;
55+
model --> NoopEight\2eafter_model;
56+
tools -.-> NoopSeven\2ebefore_model;
57+
classDef default fill:#f2f0ff,line-height:1.2
58+
classDef first fill-opacity:0
59+
classDef last fill:#bfb6fc
60+
61+
'''
62+
# ---
63+
# name: test_create_agent_jump[postgres]
64+
'''
65+
---
66+
config:
67+
flowchart:
68+
curve: linear
69+
---
70+
graph TD;
71+
__start__([<p>__start__</p>]):::first
72+
model(model)
73+
tools(tools)
74+
NoopSeven\2ebefore_model(NoopSeven.before_model)
75+
NoopSeven\2eafter_model(NoopSeven.after_model)
76+
NoopEight\2ebefore_model(NoopEight.before_model)
77+
NoopEight\2eafter_model(NoopEight.after_model)
78+
__end__([<p>__end__</p>]):::last
79+
NoopEight\2eafter_model --> NoopSeven\2eafter_model;
80+
NoopEight\2ebefore_model -.-> __end__;
81+
NoopEight\2ebefore_model -.-> model;
82+
NoopSeven\2eafter_model -.-> NoopSeven\2ebefore_model;
83+
NoopSeven\2eafter_model -.-> __end__;
84+
NoopSeven\2eafter_model -.-> tools;
85+
NoopSeven\2ebefore_model --> NoopEight\2ebefore_model;
86+
__start__ --> NoopSeven\2ebefore_model;
87+
model --> NoopEight\2eafter_model;
88+
tools -.-> NoopSeven\2ebefore_model;
89+
classDef default fill:#f2f0ff,line-height:1.2
90+
classDef first fill-opacity:0
91+
classDef last fill:#bfb6fc
92+
93+
'''
94+
# ---
95+
# name: test_create_agent_jump[postgres_pipe]
96+
'''
97+
---
98+
config:
99+
flowchart:
100+
curve: linear
101+
---
102+
graph TD;
103+
__start__([<p>__start__</p>]):::first
104+
model(model)
105+
tools(tools)
106+
NoopSeven\2ebefore_model(NoopSeven.before_model)
107+
NoopSeven\2eafter_model(NoopSeven.after_model)
108+
NoopEight\2ebefore_model(NoopEight.before_model)
109+
NoopEight\2eafter_model(NoopEight.after_model)
110+
__end__([<p>__end__</p>]):::last
111+
NoopEight\2eafter_model --> NoopSeven\2eafter_model;
112+
NoopEight\2ebefore_model -.-> __end__;
113+
NoopEight\2ebefore_model -.-> model;
114+
NoopSeven\2eafter_model -.-> NoopSeven\2ebefore_model;
115+
NoopSeven\2eafter_model -.-> __end__;
116+
NoopSeven\2eafter_model -.-> tools;
117+
NoopSeven\2ebefore_model --> NoopEight\2ebefore_model;
118+
__start__ --> NoopSeven\2ebefore_model;
119+
model --> NoopEight\2eafter_model;
120+
tools -.-> NoopSeven\2ebefore_model;
121+
classDef default fill:#f2f0ff,line-height:1.2
122+
classDef first fill-opacity:0
123+
classDef last fill:#bfb6fc
124+
125+
'''
126+
# ---
127+
# name: test_create_agent_jump[postgres_pool]
128+
'''
129+
---
130+
config:
131+
flowchart:
132+
curve: linear
133+
---
134+
graph TD;
135+
__start__([<p>__start__</p>]):::first
136+
model(model)
137+
tools(tools)
138+
NoopSeven\2ebefore_model(NoopSeven.before_model)
139+
NoopSeven\2eafter_model(NoopSeven.after_model)
140+
NoopEight\2ebefore_model(NoopEight.before_model)
141+
NoopEight\2eafter_model(NoopEight.after_model)
142+
__end__([<p>__end__</p>]):::last
143+
NoopEight\2eafter_model --> NoopSeven\2eafter_model;
144+
NoopEight\2ebefore_model -.-> __end__;
145+
NoopEight\2ebefore_model -.-> model;
146+
NoopSeven\2eafter_model -.-> NoopSeven\2ebefore_model;
147+
NoopSeven\2eafter_model -.-> __end__;
148+
NoopSeven\2eafter_model -.-> tools;
149+
NoopSeven\2ebefore_model --> NoopEight\2ebefore_model;
150+
__start__ --> NoopSeven\2ebefore_model;
151+
model --> NoopEight\2eafter_model;
152+
tools -.-> NoopSeven\2ebefore_model;
153+
classDef default fill:#f2f0ff,line-height:1.2
154+
classDef first fill-opacity:0
155+
classDef last fill:#bfb6fc
156+
157+
'''
158+
# ---
159+
# name: test_create_agent_jump[sqlite]
160+
'''
161+
---
162+
config:
163+
flowchart:
164+
curve: linear
165+
---
166+
graph TD;
167+
__start__([<p>__start__</p>]):::first
168+
model(model)
169+
tools(tools)
170+
NoopSeven\2ebefore_model(NoopSeven.before_model)
171+
NoopSeven\2eafter_model(NoopSeven.after_model)
172+
NoopEight\2ebefore_model(NoopEight.before_model)
173+
NoopEight\2eafter_model(NoopEight.after_model)
174+
__end__([<p>__end__</p>]):::last
175+
NoopEight\2eafter_model --> NoopSeven\2eafter_model;
176+
NoopEight\2ebefore_model -.-> __end__;
177+
NoopEight\2ebefore_model -.-> model;
178+
NoopSeven\2eafter_model -.-> NoopSeven\2ebefore_model;
179+
NoopSeven\2eafter_model -.-> __end__;
180+
NoopSeven\2eafter_model -.-> tools;
181+
NoopSeven\2ebefore_model --> NoopEight\2ebefore_model;
182+
__start__ --> NoopSeven\2ebefore_model;
183+
model --> NoopEight\2eafter_model;
184+
tools -.-> NoopSeven\2ebefore_model;
185+
classDef default fill:#f2f0ff,line-height:1.2
186+
classDef first fill-opacity:0
187+
classDef last fill:#bfb6fc
188+
189+
'''
190+
# ---
191+
# name: test_simple_agent_graph
192+
'''
193+
---
194+
config:
195+
flowchart:
196+
curve: linear
197+
---
198+
graph TD;
199+
__start__([<p>__start__</p>]):::first
200+
model(model)
201+
tools(tools)
202+
__end__([<p>__end__</p>]):::last
203+
__start__ --> model;
204+
model -.-> __end__;
205+
model -.-> tools;
206+
tools -.-> model;
207+
classDef default fill:#f2f0ff,line-height:1.2
208+
classDef first fill-opacity:0
209+
classDef last fill:#bfb6fc
210+
211+
'''
212+
# ---
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# serializer version: 1
2+
# name: test_async_middleware_with_can_jump_to_graph_snapshot
3+
'''
4+
---
5+
config:
6+
flowchart:
7+
curve: linear
8+
---
9+
graph TD;
10+
__start__([<p>__start__</p>]):::first
11+
model(model)
12+
async_before_with_jump\2ebefore_model(async_before_with_jump.before_model)
13+
__end__([<p>__end__</p>]):::last
14+
__start__ --> async_before_with_jump\2ebefore_model;
15+
async_before_with_jump\2ebefore_model -.-> __end__;
16+
async_before_with_jump\2ebefore_model -.-> model;
17+
model --> __end__;
18+
classDef default fill:#f2f0ff,line-height:1.2
19+
classDef first fill-opacity:0
20+
classDef last fill:#bfb6fc
21+
22+
'''
23+
# ---
24+
# name: test_async_middleware_with_can_jump_to_graph_snapshot.1
25+
'''
26+
---
27+
config:
28+
flowchart:
29+
curve: linear
30+
---
31+
graph TD;
32+
__start__([<p>__start__</p>]):::first
33+
model(model)
34+
async_after_with_jump\2eafter_model(async_after_with_jump.after_model)
35+
__end__([<p>__end__</p>]):::last
36+
__start__ --> model;
37+
async_after_with_jump\2eafter_model -.-> __end__;
38+
async_after_with_jump\2eafter_model -.-> model;
39+
model --> async_after_with_jump\2eafter_model;
40+
classDef default fill:#f2f0ff,line-height:1.2
41+
classDef first fill-opacity:0
42+
classDef last fill:#bfb6fc
43+
44+
'''
45+
# ---
46+
# name: test_async_middleware_with_can_jump_to_graph_snapshot.2
47+
'''
48+
---
49+
config:
50+
flowchart:
51+
curve: linear
52+
---
53+
graph TD;
54+
__start__([<p>__start__</p>]):::first
55+
model(model)
56+
async_before_early_exit\2ebefore_model(async_before_early_exit.before_model)
57+
async_after_retry\2eafter_model(async_after_retry.after_model)
58+
__end__([<p>__end__</p>]):::last
59+
__start__ --> async_before_early_exit\2ebefore_model;
60+
async_after_retry\2eafter_model -.-> __end__;
61+
async_after_retry\2eafter_model -.-> async_before_early_exit\2ebefore_model;
62+
async_before_early_exit\2ebefore_model -.-> __end__;
63+
async_before_early_exit\2ebefore_model -.-> model;
64+
model --> async_after_retry\2eafter_model;
65+
classDef default fill:#f2f0ff,line-height:1.2
66+
classDef first fill-opacity:0
67+
classDef last fill:#bfb6fc
68+
69+
'''
70+
# ---
71+
# name: test_async_middleware_with_can_jump_to_graph_snapshot.3
72+
'''
73+
---
74+
config:
75+
flowchart:
76+
curve: linear
77+
---
78+
graph TD;
79+
__start__([<p>__start__</p>]):::first
80+
model(model)
81+
sync_before_with_jump\2ebefore_model(sync_before_with_jump.before_model)
82+
async_after_with_jumps\2eafter_model(async_after_with_jumps.after_model)
83+
__end__([<p>__end__</p>]):::last
84+
__start__ --> sync_before_with_jump\2ebefore_model;
85+
async_after_with_jumps\2eafter_model -.-> __end__;
86+
async_after_with_jumps\2eafter_model -.-> sync_before_with_jump\2ebefore_model;
87+
model --> async_after_with_jumps\2eafter_model;
88+
sync_before_with_jump\2ebefore_model -.-> __end__;
89+
sync_before_with_jump\2ebefore_model -.-> model;
90+
classDef default fill:#f2f0ff,line-height:1.2
91+
classDef first fill-opacity:0
92+
classDef last fill:#bfb6fc
93+
94+
'''
95+
# ---

0 commit comments

Comments
 (0)