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: Restore cleanup results and stabilize CI regression tests
Daniel20598975bad8
diff --git a/app/tests/lockScreenWallpaperLayout.test.js b/app/tests/lockScreenWallpaperLayout.test.jsindex adebc4a68d..30a509d1af 100644--- a/app/tests/lockScreenWallpaperLayout.test.js+++ b/app/tests/lockScreenWallpaperLayout.test.js@@ -245,6 +245,13 @@ const prepareKeyboardCase = async () => {};const assertKeyboardState = async (value, submits) => {+ // 等待原生输入更新渲染状态,保留超时后的完整交互断言。+ const deadline = performance.now() + 5000;+ while ((document.getElementById("lockScreenCover").inert !== true ||+ document.getElementById("authCode").value !== value || document.activeElement !== document.getElementById("authCode") ||+ window.testSubmits !== submits) && performance.now() < deadline) {+ await new Promise(resolve => requestAnimationFrame(resolve));+ }await new Promise(resolve => requestAnimationFrame(resolve));const check = require("node:assert/strict");check.equal(document.getElementById("lockScreenCover").inert, true);@@ -331,6 +338,7 @@ if (process.versions.electron && process.type === "browser") {win.webContents.on("console-message", event => {if (event.message.includes("AssertionError")) console.error(event.message);});+ let context;try {for (const file of ["stage/auth.html", "electron/remote-auth.html"]) {for (const [width, height] of [[1200, 800], [320, 640], [640, 320], [320, 280]]) {@@ -338,6 +346,7 @@ if (process.versions.electron && process.type === "browser") {for (const dark of [false, true]) {nativeTheme.themeSource = dark ? "dark" : "light";for (const [present, glass] of [[false, true], [true, true], [true, false]]) {+ context = {file, width, height, dark, present, glass};await win.loadURL("data:text/html;charset=utf-8," + encodeURIComponent(fixtureHTML(file, dark, glass)));await win.webContents.executeJavaScript(`(async () => {try { await (${checkLayout.toString()})(${present}, ${dark}, ${file.startsWith("electron")}, ${glass}); }@@ -352,6 +361,7 @@ if (process.versions.electron && process.type === "browser") {features: [{name: feature, value: feature === "forced-colors" ? "active" : "reduce"}],});for (const dark of [false, true]) {+ context = {file, feature, dark};nativeTheme.themeSource = dark ? "dark" : "light";await win.loadURL("data:text/html;charset=utf-8," + encodeURIComponent(fixtureHTML(file, dark)));await win.webContents.executeJavaScript(`(${checkLayout.toString()})(true, ${dark}, ${file.startsWith("electron")}, false)`);@@ -359,6 +369,7 @@ if (process.versions.electron && process.type === "browser") {}await win.webContents.debugger.sendCommand("Emulation.setEmulatedMedia", {features: []});for (const reduced of [false, true]) {+ context = {file, reduced};await win.webContents.debugger.sendCommand("Emulation.setEmulatedMedia", {features: [{name: "prefers-reduced-motion", value: reduced ? "reduce" : "no-preference"}],});@@ -374,12 +385,14 @@ if (process.versions.electron && process.type === "browser") {await win.loadURL("data:text/html;charset=utf-8," + encodeURIComponent(fixtureHTML(file, false)));await win.webContents.executeJavaScript(`(${prepareKeyboardCase.toString()})()`);};+ context = {file, input: "characters"};await start();for (const [type, keyCode] of [["keyDown", "A"], ["char", "a"], ["keyUp", "A"],["keyDown", "B"], ["char", "b"], ["keyUp", "B"]]) {win.webContents.sendInputEvent({type, keyCode});}await win.webContents.executeJavaScript(`(${assertKeyboardState.toString()})("ab", 0)`);+ context = {file, input: "captcha"};await win.webContents.executeJavaScript(`{const captcha = document.getElementById("captcha");captcha.parentElement.style.display = "block";@@ -387,22 +400,33 @@ if (process.versions.electron && process.type === "browser") {}`);win.webContents.sendInputEvent({type: "keyDown", keyCode: "Escape"});win.webContents.sendInputEvent({type: "keyUp", keyCode: "Escape"});- await win.webContents.executeJavaScript(`{+ await win.webContents.executeJavaScript(`(async () => {const check = require("node:assert/strict");+ const cover = document.getElementById("lockScreenCover");+ const deadline = performance.now() + 5000;+ while (cover.inert && performance.now() < deadline) {+ await new Promise(resolve => requestAnimationFrame(resolve));+ }check.equal(document.getElementById("lockScreenCover").inert, false);check.equal(document.getElementById("authCode").value, "ab");check.equal(document.getElementById("captcha").value, "42");- }`);+ })()`);for (const [type, keyCode] of [["keyDown", "3"], ["char", "3"], ["keyUp", "3"]]) {win.webContents.sendInputEvent({type, keyCode});}- await win.webContents.executeJavaScript(`{+ await win.webContents.executeJavaScript(`(async () => {const check = require("node:assert/strict");const captcha = document.getElementById("captcha");+ const deadline = performance.now() + 5000;+ while (captcha.value !== "423" && performance.now() < deadline) {+ await new Promise(resolve => requestAnimationFrame(resolve));+ }+ await new Promise(resolve => requestAnimationFrame(resolve));check.equal(document.activeElement, captcha);check.equal(captcha.value, "423");check.equal(document.getElementById("authCode").value, "ab");- }`);+ })()`);+ context = {file, input: "enter"};await start();win.webContents.sendInputEvent({type: "keyDown", keyCode: "Enter"});win.webContents.sendInputEvent({type: "char", keyCode: "\r"});@@ -412,10 +436,12 @@ if (process.versions.electron && process.type === "browser") {win.webContents.sendInputEvent({type: "char", keyCode: "\r"});win.webContents.sendInputEvent({type: "keyUp", keyCode: "Enter"});await win.webContents.executeJavaScript(`(${assertKeyboardState.toString()})("", 1)`);+ context = {file, input: "pointer"};await start();win.webContents.sendInputEvent({type: "mouseDown", x: 40, y: 300, button: "left", clickCount: 1});win.webContents.sendInputEvent({type: "mouseUp", x: 40, y: 300, button: "left", clickCount: 1});await win.webContents.executeJavaScript(`(${assertKeyboardState.toString()})("", 0)`);+ context = {file, input: "composition"};await start();await win.webContents.executeJavaScript(`document.getElementById("lockScreenCover").dispatchEvent(new KeyboardEvent("keydown", {key: "Process", isComposing: true, bubbles: true, cancelable: true}));`);@@ -428,6 +454,7 @@ if (process.versions.electron && process.type === "browser") {for (const theme of ["daylight", "midnight"]) {const css = readFileSync(path.join(__dirname, `../appearance/themes/${theme}/theme.css`), "utf8") + styles;for (const width of [1000, 600, 320]) {+ context = {name, theme, width};win.setContentSize(width, 800);await win.loadURL("data:text/html,<html><body></body></html>");await win.webContents.executeJavaScript(`(${checkSettingsLayout.toString()})(${[@@ -437,9 +464,11 @@ if (process.versions.electron && process.type === "browser") {}}console.log("Wallpaper layouts passed");+ win.destroy();app.exit(0);} catch (error) {- console.error(error);+ console.error(context, error);+ win.destroy();app.exit(1);}});diff --git a/app/tests/snackbarPosition.test.js b/app/tests/snackbarPosition.test.jsindex 3b6ae77b7e..7629dcf39f 100644--- a/app/tests/snackbarPosition.test.js+++ b/app/tests/snackbarPosition.test.js@@ -19,7 +19,11 @@ const cases = async (source, css, densityCSS, mobileCSS) => {const root = document.documentElement;const resize = async width => {await require("electron").ipcRenderer.invoke("resize", width);- await new Promise(resolve => requestAnimationFrame(resolve));+ // 隐藏窗口的原生尺寸变更不保证在下一帧前传到渲染进程。+ const deadline = performance.now() + 5000;+ while (innerWidth !== width && performance.now() < deadline) {+ await new Promise(resolve => requestAnimationFrame(resolve));+ }check.equal(innerWidth, width, "the renderer has applied the window resize");};for (const compact of [false, true]) {@@ -103,7 +107,8 @@ if (process.versions.electron && process.type === "browser") {const {app, BrowserWindow, ipcMain} = require("electron");app.setPath("userData", process.argv[2]);await app.whenReady();- const win = new BrowserWindow({show: false, webPreferences: {nodeIntegration: true, contextIsolation: false, backgroundThrottling: false}});+ const win = new BrowserWindow({show: false, frame: false,+ webPreferences: {nodeIntegration: true, contextIsolation: false, offscreen: true, backgroundThrottling: false}});ipcMain.handle("resize", (_event, width) => win.setContentSize(width, 600));await win.loadURL("data:text/html,<html><body></body></html>");const ts = require("typescript");diff --git a/kernel/agent/prompt_test.go b/kernel/agent/prompt_test.goindex e383eaaad5..da5f2c633d 100644--- a/kernel/agent/prompt_test.go+++ b/kernel/agent/prompt_test.go@@ -135,7 +135,8 @@ func TestSystemPromptDocumentsStructuredDocumentAddressing(t *testing.T) {"Never split an hPath or use it to recover identity","Document create/list/move and inbox.convert use notebook + parentID",`parentID="" explicitly selects the notebook root`,- "returns legacyPathUnsupported in structured-title notebooks",+ `Legacy path=hPath resolves only unambiguous ancestor chains with non-empty titles and no literal "/"`,+ "unsupported or ambiguous candidates and unavailable indexes return explicit errors","document.list (notebook + parentID, omitted parentID lists the notebook root)","document.create (notebook + parentID + independent literal title)",} {diff --git a/kernel/model/assets_cleanup.go b/kernel/model/assets_cleanup.goindex f80d6742dd..36ce1809a6 100644--- a/kernel/model/assets_cleanup.go+++ b/kernel/model/assets_cleanup.go@@ -125,6 +125,7 @@ func ordinaryAssetCleanupSourceDigest() (string, error) {// Call only after every candidate has a complete history backup. The second// check catches saves completed between the first check and an actual removal.func removeOrdinaryUnusedAssets(items []*UnusedItem, historyDir string, verify func() error, remove func(string) error) (removed []string, size int64, err error) {+ removed = []string{}if err = verify(); err != nil {return}diff --git a/kernel/model/assets_cleanup_test.go b/kernel/model/assets_cleanup_test.goindex 5a134c87cd..42c1d18e84 100644--- a/kernel/model/assets_cleanup_test.go+++ b/kernel/model/assets_cleanup_test.go@@ -101,6 +101,29 @@ func TestOrdinaryAssetCleanupReferenceChanges(t *testing.T) {}}+func TestOrdinaryAssetCleanupEmptyResult(t *testing.T) {+ for _, missing := range []bool{false, true} {+ t.Run(fmt.Sprint("missing=", missing), func(t *testing.T) {+ setupUnusedAssetWorkspace(t)+ var items []*UnusedItem+ if missing {+ items = []*UnusedItem{{Item: "assets/missing.txt"}}+ }+ checks := 0+ removed, size, err := removeOrdinaryUnusedAssets(items, t.TempDir(), func() error {+ checks+++ return nil+ }, func(string) error {+ t.Fatal("empty cleanup must not remove files")+ return nil+ })+ if err != nil || removed == nil || len(removed) != 0 || size != 0 || checks != 2 {+ t.Fatalf("unexpected empty cleanup result: %v %d %v, checks=%d", removed, size, err, checks)+ }+ })+ }+}+func TestOrdinaryAssetCleanupRestoresPartialRemoval(t *testing.T) {for _, fail := range []bool{false, true} {t.Run(fmt.Sprint("failure=", fail), func(t *testing.T) {diff --git a/kernel/model/transaction_test.go b/kernel/model/transaction_test.goindex 8e9f972faf..956046bf42 100644--- a/kernel/model/transaction_test.go+++ b/kernel/model/transaction_test.go@@ -192,7 +192,11 @@ func TestCreateOperationTreeNotExposedInJSON(t *testing.T) {}func TestCommitSanitizesOperationTreesBeforeWrite(t *testing.T) {- tree := &parse.Tree{ID: "20260912000000-doc0001", Root: &ast.Node{Type: ast.NodeDocument}}+ fixture := setupFileOperationTest(t)+ tree, err := LoadTreeByBlockID(fixture.sourceID)+ if err != nil {+ t.Fatal(err)+ }preservedTree := &parse.Tree{ID: "20260912000001-doc0002"}newOperations := func() []*Operation {return []*Operation{@@ -203,6 +207,7 @@ func TestCommitSanitizesOperationTreesBeforeWrite(t *testing.T) {}}tx := &Transaction{+ luteEngine: util.NewLute(),trees: map[string]*parse.Tree{tree.ID: tree},DoOperations: newOperations(),UndoOperations: newOperations(),@@ -229,7 +234,7 @@ func TestCommitSanitizesOperationTreesBeforeWrite(t *testing.T) {if nil != err {t.Fatal(err)}- if strings.Contains(string(data), "doc000") {+ if strings.Contains(string(data), tree.ID) || strings.Contains(string(data), preservedTree.ID) {t.Fatalf("AST leaked into transaction JSON: %s", data)}return stop