Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Tailor missing block errors to notebook encryption https://github.com/siyuan-note/siyuan/issues/19799

Daniel5d1203255750
diff --git a/kernel/api/box_lease.go b/kernel/api/box_lease.go
index d797e4a8ab..65e4a4d213 100644
--- a/kernel/api/box_lease.go
+++ b/kernel/api/box_lease.go
@@ -68,6 +68,9 @@ func holdEncryptedBlockRequests(c *gin.Context, boxID string, ids []string, allo
continue
}
// 查不到的块直接拒绝,防止随后解锁的笔记本在第二次查找时被无租约访问。
+ if len(model.ListAllEncryptedBoxIDs()) == 0 {
+ return errors.New("block not found")
+ }
return errors.New("block not found or its encrypted notebook is locked")
}
if model.IsEncryptedBox(block.BoxID) {
diff --git a/kernel/api/box_lease_message_test.go b/kernel/api/box_lease_message_test.go
new file mode 100644
index 0000000000..c261170a14
--- /dev/null
+++ b/kernel/api/box_lease_message_test.go
@@ -0,0 +1,38 @@
+package api
+
+import (
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/gin-gonic/gin"
+ "github.com/siyuan-note/siyuan/kernel/util"
+)
+
+func TestContractMissingBlockMessage(t *testing.T) {
+ previous := util.DataDir
+ util.DataDir = t.TempDir()
+ t.Cleanup(func() { util.DataDir = previous })
+ c, _ := gin.CreateTestContext(httptest.NewRecorder())
+ ids := []string{"20260923000000-abcdefg"}
+ check := func(expected string) {
+ t.Helper()
+ err := holdEncryptedBlockRequests(c, "", ids, false)
+ if err == nil || err.Error() != expected {
+ t.Fatalf("missing block message: %v, want %q", err, expected)
+ }
+ if err := holdEncryptedBlockRequests(c, "", ids, true); err != nil {
+ t.Fatalf("allowMissing changed: %v", err)
+ }
+ }
+ check("block not found")
+ confDir := filepath.Join(util.DataDir, "20260923000000-hijklmn", ".siyuan")
+ if err := os.MkdirAll(confDir, 0755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(confDir, "conf.json"), []byte(`{"encrypted":true,"closed":true}`), 0644); err != nil {
+ t.Fatal(err)
+ }
+ check("block not found or its encrypted notebook is locked")
+}