Fix multi-device sync after persistence refactor

This commit is contained in:
Youzini-afk
2026-04-10 13:53:21 +08:00
parent a6b3137511
commit bbb44e7022
5 changed files with 356 additions and 52 deletions

View File

@@ -12,12 +12,15 @@ function createRuntime(persistResult) {
nodes: [],
edges: [],
historyState: {},
batchJournal: [],
};
let processedHistoryUpdates = 0;
let persistedGraphSnapshot = null;
return {
graph,
processedHistoryUpdates,
persistedGraphSnapshot,
ensureCurrentGraphRuntimeState() {},
throwIfAborted() {},
getCurrentGraph() {
@@ -64,6 +67,7 @@ function createRuntime(persistResult) {
};
},
async persistExtractionBatchResult() {
persistedGraphSnapshot = arguments[0]?.graphSnapshot || null;
return persistResult;
},
finalizeBatchStatus,
@@ -73,13 +77,20 @@ function createRuntime(persistResult) {
updateProcessedHistorySnapshot() {
processedHistoryUpdates += 1;
},
appendBatchJournal() {},
appendBatchJournal(targetGraph, entry) {
if (!targetGraph.batchJournal) targetGraph.batchJournal = [];
targetGraph.batchJournal.push(entry);
},
createBatchJournalEntry() {
return { id: "journal-1" };
return { id: "journal-1", processedRange: [5, 5] };
},
computePostProcessArtifacts() {
return [];
},
applyProcessedHistorySnapshotToGraph(targetGraph, _chat, floor) {
targetGraph.historyState.lastProcessedAssistantFloor = floor;
targetGraph.lastProcessedSeq = floor;
},
getGraphPersistenceState() {
return { chatId: "chat-test" };
},
@@ -87,6 +98,9 @@ function createRuntime(persistResult) {
get processedHistoryUpdates() {
return processedHistoryUpdates;
},
get persistedGraphSnapshot() {
return persistedGraphSnapshot;
},
};
}
@@ -119,6 +133,14 @@ function createRuntime(persistResult) {
runtime.graph.historyState.lastBatchStatus.historyAdvanceAllowed,
false,
);
assert.equal(
runtime.persistedGraphSnapshot?.historyState?.lastProcessedAssistantFloor,
5,
);
assert.equal(
runtime.persistedGraphSnapshot?.batchJournal?.length,
1,
);
}
{
@@ -150,6 +172,14 @@ function createRuntime(persistResult) {
runtime.graph.historyState.lastBatchStatus.historyAdvanceAllowed,
true,
);
assert.equal(
runtime.persistedGraphSnapshot?.historyState?.lastProcessedAssistantFloor,
5,
);
assert.equal(
runtime.persistedGraphSnapshot?.batchJournal?.length,
1,
);
}
console.log("extraction-persistence-gating tests passed");