Skip to content

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

:bug: Queue the inbox file tree reload

Jeffrey Chen943a61325ed8
diff --git a/kernel/cli/cmd/inbox.go b/kernel/cli/cmd/inbox.go
index a4c014bc78..4f23695180 100644
--- a/kernel/cli/cmd/inbox.go
+++ b/kernel/cli/cmd/inbox.go
@@ -214,7 +214,9 @@ var inboxConvertCmd = &cobra.Command{
}
}
- util.PushReloadFiletree()
+ // 转换会新增本地文档,需让运行中的界面刷新文件树。CLI 进程内没有 WebSocket 服务,
+ // 广播无法送达,因此与其它子命令一致改写入推送队列,由应用侧重放。
+ model.AppendPushReloadFiletreeEntry()
switch outputFormat {
case "json":
diff --git a/kernel/cli/cmd/reload_policy_test.go b/kernel/cli/cmd/reload_policy_test.go
new file mode 100644
index 0000000000..9c7354443c
--- /dev/null
+++ b/kernel/cli/cmd/reload_policy_test.go
@@ -0,0 +1,40 @@
+// SiYuan - https://github.com/siyuan-note/siyuan
+// Copyright (c) 2020-present, b3log.org
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+package cmd
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+// CLI 单次命令在独立进程里执行,进程内没有 WebSocket 服务,util 的广播函数不会有任何接收者。
+// 因此写操作后的界面刷新只能写入队列,由运行中的应用重放;广播方式属于静默失效。
+func TestCLIWriteCommandsQueueReloadsInsteadOfBroadcasting(t *testing.T) {
+ broadcasts := []string{"util.PushReloadFiletree(", "util.PushReloadTag(", "util.PushReloadUI(",
+ "util.BroadcastByType("}
+ entries, err := os.ReadDir(".")
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, entry := range entries {
+ name := entry.Name()
+ if !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") || name == "serve.go" {
+ continue
+ }
+ data, readErr := os.ReadFile(filepath.Clean(name))
+ if readErr != nil {
+ t.Fatal(readErr)
+ }
+ source := string(data)
+ for _, broadcast := range broadcasts {
+ if strings.Contains(source, broadcast) {
+ t.Errorf("%s calls %s, which cannot reach any client from a one-shot CLI process; "+
+ "append the entry with model.AppendPushReload...Entry instead", name, broadcast)
+ }
+ }
+ }
+}