Skip to content

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

:white_check_mark: Restore frontend and kernel test fixtures

Danielce64de29b32c
diff --git a/app/src/protyle/util/navigationHistory.test.ts b/app/src/protyle/util/navigationHistory.test.ts
index 9dab80478a..e62f3de346 100644
--- a/app/src/protyle/util/navigationHistory.test.ts
+++ b/app/src/protyle/util/navigationHistory.test.ts
@@ -34,6 +34,7 @@ const navigate = (action: string[], tablet = true, suppressFocus = false) => {
},
focusBlock: () => { focused++; return range; },
preventScroll: () => {},
+ recordRestoredSpellcheckFocus: () => {},
bgFade: () => {},
scrollCenter: () => {},
setTimeout: (callback: () => void, delay: number) => { if (!delay) { callback(); } },
@@ -43,7 +44,7 @@ const navigate = (action: string[], tablet = true, suppressFocus = false) => {
runInNewContext(compiled, context);
context.navigate({
block: {id: "block", rootID: "root"},
- wysiwyg: {element: {querySelectorAll: () => [element], firstElementChild: element}},
+ wysiwyg: {element: {ownerDocument: {activeElement: null}, querySelectorAll: () => [element], firstElementChild: element}},
contentElement: {addEventListener: () => {}},
observer: {unobserve: () => {}},
}, action, undefined, undefined, false, suppressFocus);
diff --git a/app/tests/agentStreamingMarkdown.test.js b/app/tests/agentStreamingMarkdown.test.js
index 3ea9a20f62..7f1a3f5e46 100644
--- a/app/tests/agentStreamingMarkdown.test.js
+++ b/app/tests/agentStreamingMarkdown.test.js
@@ -13,7 +13,9 @@ const sources = () => {
"layout/dock/agent/AgentChat",
"layout/dock/agent/AgentMessageRenderer",
"layout/dock/agent/AgentScrollState",
+ "layout/dock/agent/AgentReasoning",
"protyle/render/setLute",
+ "protyle/util/inlineElementBoundary",
"util/escape",
].map(name => [name, ts.transpileModule(readFileSync(path.join(__dirname, "../src", name + ".ts"), "utf8"), {
compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2021},
@@ -92,7 +94,7 @@ const runCases = async (sources, css, luteScript) => {
const messages = load("layout/dock/agent/AgentMessageRenderer");
messages.postRender = () => counts.postRender++;
const {AgentChat} = load("layout/dock/agent/AgentChat");
- window.siyuan = {languages: {agentChat: "Agent"}};
+ window.siyuan = {languages: {agentChat: "Agent"}, storage: {}};
for (const method of ["initUI", "bindEvents", "checkConfigChanged"]) {
AgentChat.prototype[method] = () => {};
}
@@ -574,7 +576,8 @@ const runCases = async (sources, css, luteScript) => {
}
// 实际浏览器 Worker 加载实际 Lute;模块在内存转译,不构建或替换应用产物。
body.remove();
- const workerModules = Object.fromEntries(["protyle/render/setLute", "layout/dock/agent/AgentMarkdownWorker"]
+ const workerModules = Object.fromEntries(["protyle/render/setLute", "protyle/util/inlineElementBoundary",
+ "layout/dock/agent/AgentMarkdownWorker"]
.map(name => [name, sources[name]]));
const bootstrap = modules => {
const cache = {};
diff --git a/app/tests/verticalNavigation.test.js b/app/tests/verticalNavigation.test.js
index 19c6def35b..64f0ce4bf7 100644
--- a/app/tests/verticalNavigation.test.js
+++ b/app/tests/verticalNavigation.test.js
@@ -33,6 +33,7 @@ const rendererModules = () => {
modules["render/tabsRender"] = "export const setTabTitleNavigationEditing = () => false;";
modules["../util/highlightById"] = "export const scrollCenter = () => {};";
modules["render/av/focus"] = 'import {focusEditableAtGoalX} from "../../wysiwyg/verticalCaret";\n' +
+ 'import {isTableLikeView} from "./viewType";\n' +
'import {ensureAVTableBoundaryRow, getAVData} from "./virtualScroll";\n' +
"const clearSelect = () => {};\n" +
extract("render/av/focus", ["getVisibleAVTitle", "focusAVTitleByVerticalArrow", "focusAVVerticalRegion",
@@ -92,7 +93,7 @@ const rendererModules = () => {
import {isInEmbedBlock} from "./hasClosest";
const focusByOffset = element => { window.restoredFocusElement = element; return true; };\n` +
extract("util/selection", ["restoreFocusContext"]);
- for (const name of ["virtualScroll", "selectionState", "rangeSelect", "groupTableVirtual", "backlinkScroll"]) {
+ for (const name of ["virtualScroll", "selectionState", "rangeSelect", "groupTableVirtual", "backlinkScroll", "viewType"]) {
modules[`render/av/${name}`] = readFileSync(path.join(root, "render/av", `${name}.ts`), "utf8");
}
modules["../constants"] = "const SIYUAN_VERSION = 'test', NODE_ENV = 'test';\n" +
@@ -590,6 +591,11 @@ const runElectron = async () => {
});
});
let exitCode = 0;
+ win.webContents.on("console-message", (details) => {
+ if (details.level === "error") {
+ console.error(details.message);
+ }
+ });
try {
await win.loadURL("data:text/html,<html><body></body></html>");
win.webContents.debugger.attach("1.3");
diff --git a/kernel/api/attr_test.go b/kernel/api/attr_test.go
index a7e16d85e0..b643f2a00b 100644
--- a/kernel/api/attr_test.go
+++ b/kernel/api/attr_test.go
@@ -29,6 +29,7 @@ import (
"github.com/88250/lute/parse"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/cache"
+ "github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
@@ -48,6 +49,7 @@ func TestBlockAttrsRespectPublishAccess(t *testing.T) {
previousDataDir := util.DataDir
previousLangs := util.Langs
model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
util.DataDir = t.TempDir()
util.BlockTreeDBPath = filepath.Join(util.DataDir, "blocktree.db")
util.Langs = map[string]map[int]string{
diff --git a/kernel/api/block_test.go b/kernel/api/block_test.go
index 1ff14022c1..15d0b5ad76 100644
--- a/kernel/api/block_test.go
+++ b/kernel/api/block_test.go
@@ -180,6 +180,10 @@ func TestCheckBlockRefRejectsDeletedIDsOutsideIDs(t *testing.T) {
}
func TestFilterBlockAndRefIDsByPublishAccess(t *testing.T) {
+ previousConf := model.Conf
+ model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
+ t.Cleanup(func() { model.Conf = previousConf })
const (
boxID = "20260724000000-boxid01"
publicID = "20260724000001-public1"
@@ -249,6 +253,10 @@ func TestFilterBlockAndRefIDsByPublishAccess(t *testing.T) {
}
func TestGetBlockInfoPublishAccess(t *testing.T) {
+ previousConf := model.Conf
+ model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
+ t.Cleanup(func() { model.Conf = previousConf })
const (
boxID = "20260806000020-box0020"
protectedID = "20260806000021-protect"
@@ -362,6 +370,10 @@ type docBlocksOrdersResponse struct {
}
func TestBlockPublishAccessGuards(t *testing.T) {
+ previousConf := model.Conf
+ model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
+ t.Cleanup(func() { model.Conf = previousConf })
const (
boxID = "20260724000000-boxid03"
publicID = "20260724000020-public3"
diff --git a/kernel/api/file_test.go b/kernel/api/file_test.go
index 4c16c73ca7..c2c013fd5a 100644
--- a/kernel/api/file_test.go
+++ b/kernel/api/file_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"github.com/gin-gonic/gin"
+ "github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/internal/testutil"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
@@ -166,6 +167,10 @@ func TestGetFileAdminCanFollowAssetsSymlinkOutsideWorkspace(t *testing.T) {
// 直接读取显式隐藏(Visible:false)笔记本下的普通文件与 .sy 文档,
// 隐藏仅控制发布文件树中的列出,不构成访问控制边界。
func TestGetFileReaderCanReadHiddenNotebookFile(t *testing.T) {
+ previousConf := model.Conf
+ model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
+ t.Cleanup(func() { model.Conf = previousConf })
workspaceDir := testutil.PublicDataDir(t)
origWorkspaceDir, origDataDir := util.WorkspaceDir, util.DataDir
util.WorkspaceDir = workspaceDir
@@ -216,6 +221,10 @@ func TestGetFileReaderCanReadHiddenNotebookFile(t *testing.T) {
// TestGetFileReaderCanReadVisibleNotebookFile 验证 reader 仍可读取可见笔记本下的文件,
// 防止 Visible 校验误伤正常发布访问。
func TestGetFileReaderCanReadVisibleNotebookFile(t *testing.T) {
+ previousConf := model.Conf
+ model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
+ t.Cleanup(func() { model.Conf = previousConf })
workspaceDir := testutil.PublicDataDir(t)
origWorkspaceDir, origDataDir := util.WorkspaceDir, util.DataDir
util.WorkspaceDir = workspaceDir
@@ -261,6 +270,10 @@ func TestGetFileReaderCanReadVisibleNotebookFile(t *testing.T) {
// TestGetFileEditorCanReadHiddenNotebookFile 验证编辑者不受发布可见性限制,
// 仍可通过原始文件 API 读取隐藏笔记本下的普通文件。
func TestGetFileEditorCanReadHiddenNotebookFile(t *testing.T) {
+ previousConf := model.Conf
+ model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
+ t.Cleanup(func() { model.Conf = previousConf })
workspaceDir := testutil.PublicDataDir(t)
origWorkspaceDir, origDataDir := util.WorkspaceDir, util.DataDir
util.WorkspaceDir = workspaceDir
@@ -306,6 +319,10 @@ func TestGetFileEditorCanReadHiddenNotebookFile(t *testing.T) {
// TestGetFileDeniesNotebookSiyuanConf 验证非管理员无法通过原始文件 API 读取笔记本
// .siyuan 目录下的内部文件(与发布可见性无关,黑名单独立拦截)。
func TestGetFileDeniesNotebookSiyuanConf(t *testing.T) {
+ previousConf := model.Conf
+ model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
+ t.Cleanup(func() { model.Conf = previousConf })
workspaceDir := testutil.PublicDataDir(t)
origWorkspaceDir, origDataDir := util.WorkspaceDir, util.DataDir
util.WorkspaceDir = workspaceDir
diff --git a/kernel/api/filetree_test.go b/kernel/api/filetree_test.go
index f12030995b..db69df0437 100644
--- a/kernel/api/filetree_test.go
+++ b/kernel/api/filetree_test.go
@@ -172,14 +172,15 @@ func TestAuthFilePublishAccessReturnsUniformFailure(t *testing.T) {
oldLangs := util.Langs
util.DataDir = t.TempDir()
model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
model.Conf.Lang = "test"
util.Langs = map[string]map[int]string{
"test": {285: passwordIncorrect},
"en": {285: passwordIncorrect},
}
t.Cleanup(func() {
+ defer func() { model.Conf = oldConf }()
util.DataDir = oldDataDir
- model.Conf = oldConf
util.Langs = oldLangs
if oldDataDir != "" {
if err := model.SetPublishAccess(oldPublishAccess); err != nil {
@@ -306,14 +307,15 @@ func TestAuthFilePublishAccessThrottlesBruteForce(t *testing.T) {
oldLangs := util.Langs
util.DataDir = t.TempDir()
model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
model.Conf.Lang = "test"
util.Langs = map[string]map[int]string{
"test": {285: "Password is incorrect", 354: passwordLocked},
"en": {285: "Password is incorrect", 354: passwordLocked},
}
t.Cleanup(func() {
+ defer func() { model.Conf = oldConf }()
util.DataDir = oldDataDir
- model.Conf = oldConf
util.Langs = oldLangs
if oldDataDir != "" {
if err := model.SetPublishAccess(oldPublishAccess); err != nil {
@@ -431,6 +433,7 @@ func TestPublishAccessConfigurationRejectsEncryptedNotebook(t *testing.T) {
oldLangs := util.Langs
util.DataDir = t.TempDir()
model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
model.Conf.Lang = "test"
util.Langs = map[string]map[int]string{
"test": {313: "Encrypted notebooks do not support this operation"},
@@ -440,8 +443,8 @@ func TestPublishAccessConfigurationRejectsEncryptedNotebook(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(func() {
+ defer func() { model.Conf = oldConf }()
util.DataDir = oldDataDir
- model.Conf = oldConf
util.Langs = oldLangs
if oldDataDir != "" {
if err := model.SetPublishAccess(oldPublishAccess); err != nil {
@@ -678,6 +681,10 @@ func TestGetDocOptionallyReturnsEmbeddedDocInfo(t *testing.T) {
}
func TestFilterFileTreePublishAccess(t *testing.T) {
+ previousConf := model.Conf
+ model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
+ t.Cleanup(func() { model.Conf = previousConf })
const (
boxID = "20260725000000-boxid01"
publicID = "20260725000001-public1"
@@ -781,6 +788,7 @@ func TestListDocsByPathFiltersSubFileCountForPublishReader(t *testing.T) {
oldPublishAccess := model.GetPublishAccess()
util.DataDir = t.TempDir()
model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
model.Conf.FileTree = conf.NewFileTree()
const testLang = "filetree-subfile-count-test"
installAPITestTimeLangs(t, testLang)
diff --git a/kernel/api/icon_publish_access_test.go b/kernel/api/icon_publish_access_test.go
index b0c660c113..3a9de0414c 100644
--- a/kernel/api/icon_publish_access_test.go
+++ b/kernel/api/icon_publish_access_test.go
@@ -75,6 +75,7 @@ func TestGetDynamicIconEnforcesPublishAccess(t *testing.T) {
}
model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
model.Conf.Lang = "en"
model.Conf.Editor = conf.NewEditor()
diff --git a/kernel/api/notebook_security_test.go b/kernel/api/notebook_security_test.go
index fa320901a3..b34e392816 100644
--- a/kernel/api/notebook_security_test.go
+++ b/kernel/api/notebook_security_test.go
@@ -78,6 +78,7 @@ func TestGetNotebookInfoHidesInvisibleNotebookFromReader(t *testing.T) {
oldConf, oldDataDir := model.Conf, util.DataDir
util.DataDir = t.TempDir()
model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
model.Conf.FileTree = conf.NewFileTree()
const testLang = "notebook-security-test"
oldTimeLang, hadTimeLang := util.TimeLangs[testLang]
@@ -217,6 +218,7 @@ func TestGetNotebookInfoExcludesPublishExcludedDocumentsForReader(t *testing.T)
oldPublishAccess := model.GetPublishAccess()
util.DataDir = t.TempDir()
model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
model.Conf.FileTree = conf.NewFileTree()
const testLang = "notebook-info-publish-test"
installAPITestTimeLangs(t, testLang)
diff --git a/kernel/api/notebook_test.go b/kernel/api/notebook_test.go
index 5d1f70b712..746d6c9836 100644
--- a/kernel/api/notebook_test.go
+++ b/kernel/api/notebook_test.go
@@ -40,6 +40,7 @@ func TestListNotebooksSortsBySubDocCount(t *testing.T) {
oldPublishAccess := model.GetPublishAccess()
util.DataDir = t.TempDir()
model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
model.Conf.FileTree = conf.NewFileTree()
model.Conf.NotebookCrypto = conf.NewNotebookCrypto()
*model.Conf.FileTree.BoxDocEnabled = true
diff --git a/kernel/api/plugin_publish_test.go b/kernel/api/plugin_publish_test.go
index 01da7b010e..c1f3e05c1d 100644
--- a/kernel/api/plugin_publish_test.go
+++ b/kernel/api/plugin_publish_test.go
@@ -21,6 +21,7 @@ func TestAPIContractPluginPublish(t *testing.T) {
util.WorkspaceDir = t.TempDir()
util.DataDir, util.ConfDir = filepath.Join(util.WorkspaceDir, "data"), filepath.Join(util.WorkspaceDir, "conf")
model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
model.Conf.Bazaar = &conf.Bazaar{Trust: true}
t.Cleanup(func() {
util.WorkspaceDir, util.DataDir, util.ConfDir, model.Conf = oldWorkspace, oldData, oldConfDir, oldConf
diff --git a/kernel/api/storage_test.go b/kernel/api/storage_test.go
index a8ef2f8eba..f461bf111a 100644
--- a/kernel/api/storage_test.go
+++ b/kernel/api/storage_test.go
@@ -25,12 +25,17 @@ import (
"testing"
"github.com/gin-gonic/gin"
+ "github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
)
func TestCriteriaCRUD(t *testing.T) {
gin.SetMode(gin.TestMode)
+ oldConf := model.Conf
+ model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
+ t.Cleanup(func() { model.Conf = oldConf })
oldDataDir := util.DataDir
util.DataDir = t.TempDir()
diff --git a/kernel/model/plugin_test.go b/kernel/model/plugin_test.go
index f06bf4addb..6e064f1ba4 100644
--- a/kernel/model/plugin_test.go
+++ b/kernel/model/plugin_test.go
@@ -29,6 +29,7 @@ func TestSetPetalPublishEnabled(t *testing.T) {
originalConf := Conf
originalDataDir := util.DataDir
Conf = NewAppConf()
+ Conf.Sync = conf.NewSync()
Conf.Bazaar = &conf.Bazaar{Trust: true}
util.DataDir = t.TempDir()
t.Cleanup(func() {
diff --git a/kernel/server/plugin_publish_test.go b/kernel/server/plugin_publish_test.go
index e16d5704ef..0c5451ea8b 100644
--- a/kernel/server/plugin_publish_test.go
+++ b/kernel/server/plugin_publish_test.go
@@ -17,6 +17,7 @@ func TestPluginPublishStaticBoundaries(t *testing.T) {
oldData, oldConf := util.DataDir, model.Conf
util.DataDir = t.TempDir()
model.Conf = model.NewAppConf()
+ model.Conf.Sync = conf.NewSync()
model.Conf.Bazaar = &conf.Bazaar{Trust: true}
t.Cleanup(func() { util.DataDir, model.Conf = oldData, oldConf })
for name, data := range map[string]string{