From 24beabb7ebeeb8640a3cd159160a6376f68076eb Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Wed, 4 Dec 2024 09:31:22 -0800 Subject: [PATCH] fix(langgraph): Add test for invoking a single node (#701) --- libs/langgraph/src/tests/pregel.test.ts | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libs/langgraph/src/tests/pregel.test.ts b/libs/langgraph/src/tests/pregel.test.ts index ba4f21e5..3d9b613e 100644 --- a/libs/langgraph/src/tests/pregel.test.ts +++ b/libs/langgraph/src/tests/pregel.test.ts @@ -8874,6 +8874,36 @@ export function runPregelTests( expect(result.messages).toBeDefined(); expect(result.messages).toHaveLength(1); }); + + it("should be able to invoke a single node on a graph", async () => { + const graph = new StateGraph(MessagesAnnotation) + .addNode("one", (state) => { + if (!state.messages.length) { + throw new Error("State not found"); + } + return { + messages: [ + ...state.messages, + { + role: "user", + content: "success", + }, + ], + }; + }) + .addNode("two", () => { + throw new Error("Should not be called"); + }) + .addEdge(START, "one") + .addEdge("one", "two") + .addEdge("two", END) + .compile(); + const result = await graph.nodes.one.invoke({ + messages: [new HumanMessage("start")], + }); + expect(result.messages).toBeDefined(); + expect(result.messages).toHaveLength(2); + }); } runPregelTests(() => new MemorySaverAssertImmutable());