test(ai-workflow-builder): Use checkpointer.getTuple in checkpoint- (#31081)

Co-authored-by: n8n-cat-bot[bot] <n8n-cat-bot[bot]@users.noreply.github.com>
This commit is contained in:
n8n-cat-bot[bot] 2026-05-25 17:32:45 +01:00 committed by GitHub
parent eaa641f77d
commit 5d7b5e6bd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,7 +11,6 @@
*/
import { AIMessage, HumanMessage } from '@langchain/core/messages';
import type { BaseMessage } from '@langchain/core/messages';
import type { CheckpointTuple } from '@langchain/langgraph';
import {
Annotation,
Command,
@ -42,30 +41,11 @@ async function getCheckpointMessages(
checkpointer: MemorySaver,
threadId: string,
): Promise<BaseMessage[]> {
let latestTuple: CheckpointTuple | undefined;
for await (const tuple of checkpointer.list({ configurable: { thread_id: threadId } })) {
if (!latestTuple || isLaterCheckpoint(tuple, latestTuple)) latestTuple = tuple;
}
const messages = latestTuple?.checkpoint?.channel_values?.messages;
const tuple = await checkpointer.getTuple({ configurable: { thread_id: threadId } });
const messages = tuple?.checkpoint?.channel_values?.messages;
return Array.isArray(messages) ? (messages as BaseMessage[]) : [];
}
function isLaterCheckpoint(candidate: CheckpointTuple, current: CheckpointTuple): boolean {
const candidateStep = getCheckpointStep(candidate);
const currentStep = getCheckpointStep(current);
if (candidateStep !== currentStep) return candidateStep > currentStep;
return candidate.checkpoint.ts > current.checkpoint.ts;
}
function getCheckpointStep(tuple: CheckpointTuple): number {
const step = tuple.metadata?.step;
return typeof step === 'number' ? step : Number.NEGATIVE_INFINITY;
}
// ============================================================================
// Tests
// ============================================================================