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: Report CLI and MCP synchronization failures https://github.com/siyuan-note/siyuan/issues/21013
Daniel39d21513a9ad
diff --git a/kernel/cli/cmd/repo_failure_test.go b/kernel/cli/cmd/repo_failure_test.goindex f29f4d39b0..995563e188 100644--- a/kernel/cli/cmd/repo_failure_test.go+++ b/kernel/cli/cmd/repo_failure_test.go@@ -14,7 +14,7 @@ func TestRepoAndSyncCommandsReportUnavailableOperations(t *testing.T) {model.Conf.Sync.Load().Enabled = falsedryRun = falset.Cleanup(func() { model.Conf, dryRun = previousConf, previousDryRun })- for _, command := range []*cobra.Command{repoCheckoutCmd, syncPushCmd, syncPullCmd} {+ for _, command := range []*cobra.Command{repoCheckoutCmd, syncCmd, syncPushCmd, syncPullCmd} {t.Run(command.Name(), func(t *testing.T) {input := &cobra.Command{}input.Flags().String("id", "missing", "")diff --git a/kernel/cli/cmd/sync.go b/kernel/cli/cmd/sync.goindex 552239c295..37b3573059 100644--- a/kernel/cli/cmd/sync.go+++ b/kernel/cli/cmd/sync.go@@ -40,7 +40,9 @@ var syncCmd = &cobra.Command{return nil}- model.SyncData(true)+ if err := model.SyncData(true); err != nil {+ return err+ }fmt.Println("ok")return nil},diff --git a/kernel/mcp/tools/sync.go b/kernel/mcp/tools/sync.goindex 70f3b87730..a84dfd6684 100644--- a/kernel/mcp/tools/sync.go+++ b/kernel/mcp/tools/sync.go@@ -58,17 +58,23 @@ func syncHandler(args map[string]any) (CallToolResult, error) {}func syncPerform(_ map[string]any) (CallToolResult, error) {- model.SyncData(true)+ if err := model.SyncData(true); err != nil {+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "sync failed: " + err.Error()}}, IsError: true}, nil+ }return CallToolResult{Content: []ContentItem{{Type: "text", Text: "sync done: " + model.Conf.Sync.Load().Stat}}}, nil}func syncUpload(_ map[string]any) (CallToolResult, error) {- model.SyncDataUpload()+ if err := model.SyncDataUpload(); err != nil {+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "sync upload failed: " + err.Error()}}, IsError: true}, nil+ }return CallToolResult{Content: []ContentItem{{Type: "text", Text: "sync upload done: " + model.Conf.Sync.Load().Stat}}}, nil}func syncDownload(_ map[string]any) (CallToolResult, error) {- model.SyncDataDownload()+ if err := model.SyncDataDownload(); err != nil {+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "sync download failed: " + err.Error()}}, IsError: true}, nil+ }return CallToolResult{Content: []ContentItem{{Type: "text", Text: "sync download done: " + model.Conf.Sync.Load().Stat}}}, nil}diff --git a/kernel/mcp/tools/sync_test.go b/kernel/mcp/tools/sync_test.gonew file mode 100644index 0000000000..e2f79e4ca8--- /dev/null+++ b/kernel/mcp/tools/sync_test.go@@ -0,0 +1,24 @@+package tools++import (+ "strings"+ "testing"++ "github.com/siyuan-note/siyuan/kernel/conf"+ "github.com/siyuan-note/siyuan/kernel/model"+)++func TestSyncActionsReportUnavailableOperations(t *testing.T) {+ previous := model.Conf+ model.Conf = &model.AppConf{Lang: "en", Sync: model.NewConfSection(conf.NewSync())}+ model.Conf.Sync.Load().Enabled = false+ t.Cleanup(func() { model.Conf = previous })+ for _, action := range []string{"perform", "upload", "download"} {+ t.Run(action, func(t *testing.T) {+ result, err := syncHandler(map[string]any{"action": action})+ if err != nil || !result.IsError || !strings.Contains(result.Content[0].Text, "failed") {+ t.Fatalf("unavailable sync reported success: %+v, %v", result, err)+ }+ })+ }+}diff --git a/kernel/model/sync.go b/kernel/model/sync.goindex 7a5aff289e..667c43de58 100644--- a/kernel/model/sync.go+++ b/kernel/model/sync.go@@ -262,8 +262,8 @@ func finishBootSync(revision uint64, cloudPublished bool, err error) {}}-func SyncData(byHand bool) {- syncData(false, byHand)+func SyncData(byHand bool) error {+ return syncData(false, byHand)}// SyncDataBeforeEnableEncryptedNotebook 在启用加密笔记本前执行一次完整同步。@@ -333,6 +333,9 @@ func syncData(exit, byHand bool) (err error) {defer logging.Recover()if !checkSync(false, exit, byHand) {+ if byHand {+ return err+ }return nil}@@ -344,6 +347,9 @@ func syncData(exit, byHand bool) (err error) {}unlock, ok := lockSyncRequest(requests)if !ok {+ if byHand {+ return err+ }return nil}defer unlock()