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: Repair failing frontend tests
Jeffrey Chen98c817e51397
diff --git a/app/src/business/openRecentDocs.layout.test.ts b/app/src/business/openRecentDocs.layout.test.tsindex d625677459..263ce11c1e 100644--- a/app/src/business/openRecentDocs.layout.test.ts+++ b/app/src/business/openRecentDocs.layout.test.ts@@ -126,7 +126,9 @@ const browserCases = async (sources: string[], css: string, languages: Record<stconst contentRect = switchRoot.querySelector(".switch-doc").getBoundingClientRect();const style = getComputedStyle(path);check.equal(style.padding, "4px 8px", "switch path padding: " + label);- check.equal(style.borderTopWidth, "1px", "switch path border: " + label);+ // 1px 边框在非整数缩放下会被吸附到整设备像素,计算值可能为 0.666667px。+ check.ok(Math.abs(parseFloat(style.borderTopWidth) - 1) < 0.5,+ "switch path border: " + label);check.ok(Math.abs(pathRect.height - 27) < 1, "switch path height: " + label);check.ok(Math.abs(pathRect.top - path.previousElementSibling.getBoundingClientRect().bottom) < 1,"switch path follows list: " + label);diff --git a/app/src/protyle/render/listMindmap/arrows.test.ts b/app/src/protyle/render/listMindmap/arrows.test.tsindex 6f9b8f2fd9..1e739958c3 100644--- a/app/src/protyle/render/listMindmap/arrows.test.ts+++ b/app/src/protyle/render/listMindmap/arrows.test.ts@@ -296,6 +296,8 @@ test("the shared direction selector preserves focus and only patches arrow direcconstructor(public tag: string) {}append(...elements: Control[]) { this.children.push(...elements); }replaceChildren() { this.children = []; }+ // 色卡行会遍历带 --current 的子项补标记;本桩的 classList 不记录类名,因而确实没有命中项。+ querySelectorAll(): Control[] { return []; }querySelector(tag: string): Control | undefined {for (const child of this.children) {const result = child.tag === tag ? child : child.querySelector(tag);diff --git a/app/src/protyle/render/listMindmap/fullscreen.test.ts b/app/src/protyle/render/listMindmap/fullscreen.test.tsindex 2bccacdc39..596505acc7 100644--- a/app/src/protyle/render/listMindmap/fullscreen.test.ts+++ b/app/src/protyle/render/listMindmap/fullscreen.test.ts@@ -22,10 +22,14 @@ const browserCases = async (source: string, css: string, contentCSS: string, theconst resizeWindow = async (width: number, height: number) => {await require("electron").ipcRenderer.invoke("mindmap-fullscreen-size", width, height);// 原生窗口调用返回时,渲染进程可能尚未收到新的视口尺寸。- for (let count = 0; count < 120 && (innerWidth !== width || innerHeight !== height); count++) {+ // 窗口尺寸由操作系统取整,高 DPI 下可能与请求值相差 1px,因此按容差等待。+ for (let count = 0; count < 120 &&+ (Math.abs(innerWidth - width) > 1 || Math.abs(innerHeight - height) > 1); count++) {await frame();}- check.deepEqual([innerWidth, innerHeight], [width, height]);+ // 仍要求尺寸确实换了,只是允许 1px 的设备像素取整。+ check.ok(Math.abs(innerWidth - width) <= 1 && Math.abs(innerHeight - height) <= 1,+ `viewport did not resize: ${innerWidth}x${innerHeight} vs ${width}x${height}`);await settle();};const originalWindow = {width: innerWidth, height: innerHeight};@@ -730,6 +734,7 @@ app.whenReady().then(async () => {});assert.match(result.stdout, /Mindmap fullscreen cases passed/);} finally {- rmSync(temporary, {recursive: true, force: true});+ // Electron 子进程退出后文件句柄可能尚未释放,Windows 上需要重试删除。+ rmSync(temporary, {recursive: true, force: true, maxRetries: 10, retryDelay: 100});}});diff --git a/app/src/protyle/toolbar/fontFamilyMenu.test.ts b/app/src/protyle/toolbar/fontFamilyMenu.test.tsindex 2368ac309b..170a23e972 100644--- a/app/src/protyle/toolbar/fontFamilyMenu.test.ts+++ b/app/src/protyle/toolbar/fontFamilyMenu.test.ts@@ -172,7 +172,9 @@ const browserCases = async (sources: Record<string, string>, toolbarSource: stricontrols.hideKeyboardToolbarUtilOnEditorClick();await require("electron").ipcRenderer.invoke("font-resize", 350);await settle();- check.equal(menuElement.style.height, "350px", "font sheet still tracks the available viewport while searching");+ // 断言跟随本次 resize 传入的高度,不是与 innerHeight 自比;设备像素取整会差 1px。+ check.ok(Math.abs(parseFloat(menuElement.style.height) - 350) <= 1,+ "font sheet still tracks the available viewport while searching");check.ok(search().getBoundingClientRect().top >= menuElement.getBoundingClientRect().top);check.ok(search().getBoundingClientRect().bottom <= innerHeight);search().value = "Font 12";diff --git a/app/src/protyle/util/pasteIdentity.test.ts b/app/src/protyle/util/pasteIdentity.test.tsindex ed7b88e44a..e7fa63a5a8 100644--- a/app/src/protyle/util/pasteIdentity.test.ts+++ b/app/src/protyle/util/pasteIdentity.test.ts@@ -11,6 +11,9 @@ import {ModuleKind, ScriptTarget, transpileModule} from "typescript";const browserCases = async (sources: Record<string, string>, lutePath: string) => {const check = require("node:assert/strict");require(lutePath);+ // 粘贴入口读取编辑器配置来决定 Markdown 语法、公式分隔符与 URL 自动转换。+ Object.assign(window, {siyuan: {languages: {}, config: {editor: {markdown: {},+ mathDelimiterCompatibility: true, pasteURLAutoConvert: false}}}});const constants = {Constants: {ZWSP: "\u200b", CUSTOM_RIFF_DECKS: "custom-riff-decks"}};const load = (source: string, mocks: Record<string, unknown>) => {const api = {};diff --git a/app/src/protyle/util/tableCellPaste.test.ts b/app/src/protyle/util/tableCellPaste.test.tsindex aa6f4795ec..bad73d0f41 100644--- a/app/src/protyle/util/tableCellPaste.test.ts+++ b/app/src/protyle/util/tableCellPaste.test.ts@@ -7,6 +7,7 @@ import {test} from "node:test";import {createSourceFile, isVariableStatement, ModuleKind, ScriptTarget, transpileModule} from "typescript";import {promisify} from "node:util";+const browserCases = async (source: string, pasteSource: string) => {const check: typeof assert = require("node:assert/strict");const noop = () => {};@@ -22,10 +23,10 @@ const browserCases = async (source: string, pasteSource: string) => {const api = new Function(...Object.keys(dependencies), source + "\nreturn {getAgentLute, configureAVRichTextLute, " +"getAVRichTextUnsupportedPasteBlocks, getTableClipboardBlockDOM, getTableRangeHTML, processTable, getTablePasteTarget, " +"hasClosestBlock, getTableCellRichContext, setTableCellRichContext, restoreTableVirtualizationDOM, " +- "setTableCellRich, getTableCellRichBlockDOM};")(...Object.values(dependencies)) as+ "setTableCellRich, getTableCellRichBlockDOM, markdownMathPaste, htmlMathPaste};")(...Object.values(dependencies)) astypeof import("../render/setLute") & typeof import("../render/av/richText") & typeof import("./table") &typeof import("./hasClosest") & typeof import("./tableCellRichContext") & typeof import("./tableCellRich") &- typeof import("./tableVirtualizationDOM") & {+ typeof import("./tableVirtualizationDOM") & typeof import("./mathPaste") & {processTable: (range: Range, html: string, protyle: IProtyle, block: HTMLElement, target: unknown) => boolean,getTablePasteTarget: (range: Range) => unknown,};@@ -86,6 +87,7 @@ const browserCases = async (source: string, pasteSource: string) => {const block = api.hasClosestBlock(range.startContainer) as HTMLElement;check.equal(api.processTable(range, html, owner, block, api.getTablePasteTarget(range)), true);}},+ "./mathPaste": {markdownMathPaste: api.markdownMathPaste, htmlMathPaste: api.htmlMathPaste},};const exports = {};new Function("exports", "require", pasteSource)(exports, (id: string) => mocks[id] || {});@@ -208,7 +210,7 @@ test("table clipboard fills the outer grid while a cell editor is active", {time.map(statement => statement.getText(insert)).join("\n");const source = ["longTextWrap.ts", "inlineElementBoundary.ts", "../toolbar/fontFamilyCore.ts", "../../util/escape.ts","../render/setLute.ts", "../render/av/richTextValue.ts", "../render/av/richText.ts", "tableCellRichValue.ts",- "tableCellRich.ts", "tableCellRichContext.ts", "tableVirtualizationDOM.ts", "hasClosest.ts", "table.ts"]+ "tableCellRich.ts", "tableCellRichContext.ts", "tableVirtualizationDOM.ts", "hasClosest.ts", "table.ts", "mathPaste.ts"].map(name => compile(read(name))).join("\n") + "\n" + compile(processTable);const pasteSource = transpileModule(read("paste.ts"), {compilerOptions: {target: ScriptTarget.ES2022, module: ModuleKind.CommonJS},diff --git a/app/tests/superBlockCreation.test.js b/app/tests/superBlockCreation.test.jsindex 7e2f5631f4..1a3ced39ae 100644--- a/app/tests/superBlockCreation.test.js+++ b/app/tests/superBlockCreation.test.js@@ -19,6 +19,7 @@ const sources = () => {return {functions: [extract("block/util.ts", ["genEmptyElement", "genSBElement", "refreshSbResize", "rebalanceSbWidth", "refreshSbAndPersistWidth"]),+ extract("block/headingLevel.ts", ["getHeadingLevel"]),extract("block/superBlock.ts", ["getSuperBlockCommand", "getSuperBlockCommandLayout", "getSuperBlockTailHeadings"]),extract("block/insertSuperBlock.ts", ["genEmptySuperBlock", "focusInsertedBlock", "insertSuperBlockChild", "createSuperBlockColumn"]),extract("protyle/wysiwyg/transaction.ts", ["turnsIntoOneTransaction"]),diff --git a/app/tests/templateManager.test.js b/app/tests/templateManager.test.jsindex 5edab9b1c9..e2971d65c3 100644--- a/app/tests/templateManager.test.js+++ b/app/tests/templateManager.test.js@@ -295,7 +295,7 @@ const runCases = async (sources, css, mobile, legacyMobile) => {source.value = original;if (mobile && width === 360) {await require("electron").ipcRenderer.invoke("template-manager-size", width, 360);- await waitFor(() => window.innerHeight === 360, "mobile keyboard viewport did not resize");+ await waitFor(() => Math.abs(window.innerHeight - 360) <= 1, "mobile keyboard viewport did not resize");button("source").scrollIntoView({block: "nearest"});assert.ok(button("source").getBoundingClientRect().bottom <= 360, "actions remain reachable above the keyboard");}