An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Preserve pending local changes after download-only sync https://github.com/siyuan-note/siyuan/issues/20969
Daniel5509b4b1f072
diff --git a/kernel/model/sync.go b/kernel/model/sync.goindex 75540e8465..4630c005b4 100644--- a/kernel/model/sync.go+++ b/kernel/model/sync.go@@ -64,7 +64,6 @@ func SyncDataDownload() (err error) {}func syncDataDownloadLocked() (err error) {- revision := pendingSync.begin()util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)now := util.CurrentTimeMillis()@@ -76,7 +75,8 @@ func syncDataDownloadLocked() (err error) {code = 2}util.BroadcastByType("main", "syncing", code, Conf.Sync.Load().Stat, nil)- pendingSync.finish(revision, err == nil, notifySyncPending)+ // Download-only completion does not publish local changes, including an empty remote.+ // Keep the pending hint until an upload or full sync actually publishes them.if 1 == code {consumeShorthands()}diff --git a/kernel/model/sync_pending_test.go b/kernel/model/sync_pending_test.goindex 22872228c1..4345508262 100644--- a/kernel/model/sync_pending_test.go+++ b/kernel/model/sync_pending_test.go@@ -1,11 +1,16 @@package modelimport (+ "os"+ "path/filepath""reflect""sync""testing""testing/synctest""time"++ "github.com/siyuan-note/siyuan/kernel/conf"+ "github.com/siyuan-note/siyuan/kernel/util")func TestSyncPendingCoalescesChanges(t *testing.T) {@@ -30,6 +35,54 @@ func TestSyncPendingCoalescesChanges(t *testing.T) {})}+func TestSyncPendingDownloadToEmptyRemote(t *testing.T) {+ prepareAssetDownloadRepoTest(t)+ if err := ensureAllSyncAssets(); err != nil {+ t.Fatal(err)+ }+ remote := Conf.Sync.Load().Local.Endpoint+ if err := os.Rename(filepath.Join(remote, "main"), filepath.Join(remote, "saved")); err != nil {+ t.Fatal(err)+ }+ Conf.Sync.Load().AssetDownloadMode = 0+ Conf.Lang = "en"+ previousLangs := util.Langs+ util.Langs = map[string]map[int]string{"en": {150: "%d %d %d %d %s %s"}}+ t.Cleanup(func() { util.Langs = previousLangs })+ Conf.Editor.Store(conf.NewEditor())+ file := filepath.Join(util.DataDir, "local.txt")+ if err := os.WriteFile(file, []byte("not uploaded"), 0644); err != nil {+ t.Fatal(err)+ }+ pendingSync.mu.Lock()+ previousPending := pendingSync.pending+ pendingSync.pending = true+ pendingSync.mu.Unlock()+ t.Cleanup(func() {+ pendingSync.mu.Lock()+ pendingSync.pending = previousPending+ pendingSync.mu.Unlock()+ })+ lockSync()+ err := syncDataDownloadLocked()+ unlockSync()+ if err != nil {+ t.Fatal(err)+ }+ pendingSync.mu.Lock()+ pending := pendingSync.pending+ pendingSync.mu.Unlock()+ if !pending {+ t.Fatal("download-only sync cleared unpublished local changes")+ }+ if data, err := os.ReadFile(file); err != nil || string(data) != "not uploaded" {+ t.Fatalf("download changed local data: %q %v", data, err)+ }+ if _, err := os.Stat(filepath.Join(Conf.Sync.Load().Local.Endpoint, "main", "refs", "latest")); !os.IsNotExist(err) {+ t.Fatalf("download published local changes: %v", err)+ }+}+func TestSyncPendingCompletion(t *testing.T) {for _, test := range []struct {name string