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 MCP snapshot checkout failures https://github.com/siyuan-note/siyuan/issues/20423
Daniela629e9133d90
diff --git a/kernel/mcp/tools/repo.go b/kernel/mcp/tools/repo.goindex ac2209906b..7af852882d 100644--- a/kernel/mcp/tools/repo.go+++ b/kernel/mcp/tools/repo.go@@ -169,7 +169,9 @@ func repoCheckout(args map[string]any) (CallToolResult, error) {if id == "" {return CallToolResult{Content: []ContentItem{{Type: "text", Text: "id is required"}}, IsError: true}, nil}- model.CheckoutRepoDirect(id)+ if err := model.CheckoutRepoDirect(id); err != nil {+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "checkout snapshot failed: " + err.Error()}}, IsError: true}, nil+ }util.PushReloadFiletree()util.ReloadUI()return CallToolResult{Content: []ContentItem{{Type: "text", Text: "checkout to snapshot: " + id}}}, nildiff --git a/kernel/mcp/tools/repo_test.go b/kernel/mcp/tools/repo_test.gonew file mode 100644index 0000000000..46d7c2aa34--- /dev/null+++ b/kernel/mcp/tools/repo_test.go@@ -0,0 +1,32 @@+package tools++import (+ "strings"+ "testing"++ "github.com/siyuan-note/siyuan/kernel/conf"+ "github.com/siyuan-note/siyuan/kernel/model"+ "github.com/siyuan-note/siyuan/kernel/util"+)++func TestRepoCheckoutFailure(t *testing.T) {+ previousConf := model.Conf+ previousLangs := util.Langs+ previousReadOnly := util.ReadOnly+ model.Conf = model.NewAppConf()+ model.Conf.Repo = &conf.Repo{}+ model.Conf.Lang = "en"+ util.Langs = map[string]map[int]string{"en": {26: "repository key is not configured"}}+ util.ReadOnly = false+ t.Cleanup(func() {+ model.Conf, util.Langs, util.ReadOnly = previousConf, previousLangs, previousReadOnly+ })+ result, err := repoHandler(map[string]any{"action": "checkout", "id": "missing-snapshot"})+ if err != nil || !result.IsError {+ t.Fatalf("failed checkout must be a tool error: %+v, %v", result, err)+ }+ text := probeText(result)+ if !strings.Contains(text, "repository key is not configured") || strings.Contains(text, "checkout to snapshot:") {+ t.Fatalf("failed checkout must return its cause without success text: %s", text)+ }+}