From 5e238423d6daabbfbb8f1619517366304e7b5239 Mon Sep 17 00:00:00 2001 From: Hao19911125 <99091644+Hao19911125@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:47:03 +0800 Subject: [PATCH] Fix cloud backup restore runtime refresh --- index.js | 6 ++++- tests/graph-persistence.mjs | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 684b59c..cdb6a8e 100644 --- a/index.js +++ b/index.js @@ -5559,7 +5559,11 @@ async function refreshRuntimeGraphAfterSyncApplied(syncPayload = {}) { const action = String(syncPayload?.action || "") .trim() .toLowerCase(); - if (action !== "download" && action !== "merge") { + if ( + action !== "download" && + action !== "merge" && + action !== "restore-backup" + ) { return { refreshed: false, reason: "action-not-supported", diff --git a/tests/graph-persistence.mjs b/tests/graph-persistence.mjs index 892a1d6..cd9d6c6 100644 --- a/tests/graph-persistence.mjs +++ b/tests/graph-persistence.mjs @@ -1936,6 +1936,51 @@ result = { ); } +{ + const harness = await createGraphPersistenceHarness({ + chatId: "chat-sync-refresh-restore", + chatMetadata: { + integrity: "chat-sync-refresh-restore-ready", + }, + }); + harness.api.setCurrentGraph( + normalizeGraphRuntimeState( + createMeaningfulGraph("chat-sync-refresh-restore", "stale-runtime-restore"), + "chat-sync-refresh-restore", + ), + ); + harness.api.setGraphPersistenceState({ + loadState: "loaded", + chatId: "chat-sync-refresh-restore", + reason: "runtime-stale", + revision: 5, + lastPersistedRevision: 5, + dbReady: true, + writesBlocked: false, + }); + harness.api.setIndexedDbSnapshot( + buildSnapshotFromGraph( + createMeaningfulGraph("chat-sync-refresh-restore", "fresh-indexeddb-restore"), + { + chatId: "chat-sync-refresh-restore", + revision: 9, + }, + ), + ); + + const runtimeOptions = harness.api.buildBmeSyncRuntimeOptions(); + await runtimeOptions.onSyncApplied({ + chatId: "chat-sync-refresh-restore", + action: "restore-backup", + }); + + assert.equal( + harness.api.getCurrentGraph().nodes[0]?.fields?.title, + "事件-fresh-indexeddb-restore", + "restore-backup 后应刷新当前运行时图谱", + ); +} + { const harness = await createGraphPersistenceHarness({ chatId: "chat-sync-refresh-active",