An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:construction_worker: Scale frontend test concurrency to available cores https://github.com/siyuan-note/siyuan/issues/20480
Daniel4fa57fe6115e
diff --git a/app/package.json b/app/package.jsonindex 24fa7d7624..e49b50f244 100644--- a/app/package.json+++ b/app/package.json@@ -14,7 +14,7 @@"typecheck": "tsc -p tsconfig.typecheck.json && tsc -p tsconfig.api.json","api:generate": "node scripts/api-contracts.mjs","api:check": "node scripts/api-contracts.mjs --check",- "test": "node --import tsx --test --test-concurrency=1 \"src/**/*.test.ts\" \"tests/**/*.test.js\" \"electron/**/*.test.js\" \"scripts/**/*.test.js\"",+ "test": "node scripts/test.mjs","dev": "webpack --mode development --config webpack.config.js","dev:mobile": "webpack --mode development --config webpack.mobile.js","dev:desktop": "webpack --mode development --config webpack.desktop.js",diff --git a/app/scripts/test.mjs b/app/scripts/test.mjsnew file mode 100644index 0000000000..80c4eb2995--- /dev/null+++ b/app/scripts/test.mjs@@ -0,0 +1,19 @@+import {spawnSync} from "node:child_process";+import {availableParallelism} from "node:os";++// 按可用核心数并行执行,限制上限以避免多个 Electron 子进程耗尽运行资源。+const concurrency = Math.min(4, availableParallelism());+// 运行参数放在测试路径之前,支持通过命令行覆盖并发度及筛选用例。+const result = spawnSync(process.execPath, [+ "--import", "tsx", "--test", `--test-concurrency=${concurrency}`,+ ...process.argv.slice(2),+ "src/**/*.test.ts", "tests/**/*.test.js", "electron/**/*.test.js", "scripts/**/*.test.js",+], {stdio: "inherit"});+if (result.error) {+ throw result.error;+}+if (result.signal) {+ process.kill(process.pid, result.signal);+} else {+ process.exitCode = result.status;+}diff --git a/docs/API-CONTRACTS.md b/docs/API-CONTRACTS.mdindex b84a95b249..e88341139e 100644--- a/docs/API-CONTRACTS.md+++ b/docs/API-CONTRACTS.md@@ -221,4 +221,4 @@ go test -tags "fts5 sqlcipher" ./... -count=1Import and static-file fixtures use `internal/testutil.PublicDataDir` to create and clean up explicitly validated non-sensitive directories independently of `TMPDIR` and `GOTMPDIR`. The helper tries the user home, current directory, and filesystem root, and reports a fixture setup failure if none is safe and writable. CI also reruns the affected path tests with `/tmp` as `TMPDIR` and a separate `GOTMPDIR` to cover environment overrides.-The prerelease workflow `.github/workflows/cd.yml` runs language validation, contract and type checks, all kernel packages on Linux, and all frontend, Electron, and packaging-script tests on Windows. These checks run only for prerelease tag pushes (`*-alpha*`, `*-beta*`, `*-rc*`) or manual dispatch of this workflow; ordinary branch pushes and pull requests do not trigger them. Desktop and Android packaging require all three validation and test jobs to pass. Frontend discovery is restricted to `src/**/*.test.ts`, `tests/**/*.test.js`, `electron/**/*.test.js`, and `scripts/**/*.test.js`, so packaged copies under `app/build` are excluded. Test files run serially to avoid Electron process startup contention. New regression tests in these locations are included automatically; update the test command and this document when adding a new test location or filename convention. Keep `Contract` in Go contract regression test names so they remain easy to run separately.+The prerelease workflow `.github/workflows/cd.yml` runs language validation, contract and type checks, all kernel packages on Linux, and all frontend, Electron, and packaging-script tests on Windows. These checks run only for prerelease tag pushes (`*-alpha*`, `*-beta*`, `*-rc*`) or manual dispatch of this workflow; ordinary branch pushes and pull requests do not trigger them. Desktop and Android packaging require all three validation and test jobs to pass. Frontend discovery is restricted to `src/**/*.test.ts`, `tests/**/*.test.js`, `electron/**/*.test.js`, and `scripts/**/*.test.js`, so packaged copies under `app/build` are excluded. Test files run in separate processes with concurrency selected from the available CPU cores, capped at four to limit Electron process startup contention. Use `pnpm test --test-concurrency=1` for serial execution. New regression tests in these locations are included automatically; update the test command and this document when adding a new test location or filename convention. Keep `Contract` in Go contract regression test names so they remain easy to run separately.diff --git a/docs/API-CONTRACTS.zh-CN.md b/docs/API-CONTRACTS.zh-CN.mdindex cfcfd7b311..a67f6017e7 100644--- a/docs/API-CONTRACTS.zh-CN.md+++ b/docs/API-CONTRACTS.zh-CN.md@@ -205,4 +205,4 @@ go test -tags "fts5 sqlcipher" ./... -count=1导入和静态文件测试数据使用 `internal/testutil.PublicDataDir` 创建并清理经过显式验证的非敏感目录,不依赖 `TMPDIR` 和 `GOTMPDIR`。该辅助函数依次尝试用户主目录、当前目录和文件系统根目录;若没有安全且可写的位置,则报告测试数据准备失败。CI 还会将 `TMPDIR` 设为 `/tmp`,并使用独立的 `GOTMPDIR` 重新运行受影响的路径测试,以覆盖环境变量覆盖的情况。-CI 在 Linux 上运行所有内核包的测试,在 Windows 上运行所有前端、Electron 和打包脚本测试。前端测试发现范围限定为 `src/**/*.test.ts`、`tests/**/*.test.js`、`electron/**/*.test.js` 和 `scripts/**/*.test.js`,因此排除 `app/build` 下的打包副本。测试文件串行执行,以避免 Electron 进程启动争用。这些位置新增的回归测试会自动纳入;新增测试位置或文件命名约定时,须同步更新测试命令和本文档。Go 契约回归测试的名称应保留 `Contract`,以便单独运行。+CI 在 Linux 上运行所有内核包的测试,在 Windows 上运行所有前端、Electron 和打包脚本测试。前端测试发现范围限定为 `src/**/*.test.ts`、`tests/**/*.test.js`、`electron/**/*.test.js` 和 `scripts/**/*.test.js`,因此排除 `app/build` 下的打包副本。测试文件在独立进程中运行,根据可用 CPU 核心数选择并发度,上限为 4,以限制 Electron 进程启动争用。通过 `pnpm test --test-concurrency=1` 可串行执行。这些位置新增的回归测试会自动纳入;新增测试位置或文件命名约定时,须同步更新测试命令和本文档。Go 契约回归测试的名称应保留 `Contract`,以便单独运行。