Skip to content

Commit

Permalink
fix(langgraph): Add test for invoking a single node (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul authored Dec 4, 2024
1 parent 586628f commit 24beabb
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions libs/langgraph/src/tests/pregel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

0 comments on commit 24beabb

Please sign in to comment.