An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:zap: Split editor end-to-end tests across isolated ARM runners
Daniele11dd7802f6a
diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.ymlindex f7f16add46..7009749380 100644--- a/.github/workflows/cd.yml+++ b/.github/workflows/cd.yml@@ -19,12 +19,23 @@ jobs:release_title: ${{ steps.release_info.outputs.release_title }}version: ${{ steps.version.outputs.value }}android_ref: ${{ steps.android_version.outputs.ref }}+ testing_ref: ${{ steps.testing_ref.outputs.sha }}packageManager: ${{ steps.packageManager.outputs.value }}release_body: ${{ steps.release_info.outputs.release_body }}steps:- name: Checkout codeuses: actions/checkout@v6+ - name: Resolve editor testing revision+ id: testing_ref+ continue-on-error: true+ env:+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ run: |+ SHA=$(gh api repos/siyuan-note/siyuan-testing/commits/main --jq .sha)+ [[ "$SHA" =~ ^[0-9a-f]{40}$ ]]+ echo "sha=$SHA" >> "$GITHUB_OUTPUT"+- name: Setup Pythonuses: actions/setup-python@v6with:@@ -122,6 +133,9 @@ jobs:run: python -m unittest discover -s scripts -p "test_check_lang_keys.py"- name: Check language keys and kernel placeholdersrun: python scripts/check-lang-keys.py+ - name: Test editor workflow safeguards+ continue-on-error: true+ run: python -m unittest discover -s scripts -p "test_editor_e2e_workflow.py"contracts:name: API contracts and kernel tests@@ -204,13 +218,13 @@ jobs:working-directory: app- name: Test OCR build and resource scriptsrun: python -m unittest discover -s scripts -p "test_*ocr*.py"+ - name: Test editor group selection+ continue-on-error: true+ run: node --test scripts/test-prepare-editor-e2e-groups.mjsbuild:- runs-on: ${{ matrix.config.os }}name: ${{ matrix.config.name }}needs: [prepare, languages, contracts, frontend-tests]- env:- SIYUAN_E2E_SHARDS: ${{ matrix.config.e2e_shards }}strategy:matrix:config:@@ -234,16 +248,6 @@ jobs:goarch: "amd64"suffix: "mac.dmg"e2e_shards: "main:6806"- - os: macos-latest- name: macos build mac-arm64.dmg- kernel_path: "../app/kernel-darwin-arm64/SiYuan-Kernel"- build_args_prefix: "-s -w -X"- build_args_suffix: "Mode=prod"- electron_args: "dist-darwin-arm64"- goos: "darwin"- goarch: "arm64"- suffix: "mac-arm64.dmg"- e2e_shards: "editor:6807"- os: windows-latestname: windows build win.exekernel_path: "../app/kernel/SiYuan-Kernel.exe"@@ -256,314 +260,202 @@ jobs:suffix: "win.exe"e2e_shards: "attribute-view:6808"+ uses: ./.github/workflows/desktop-build.yml+ with:+ config: ${{ toJSON(matrix.config) }}+ packageManager: ${{ needs.prepare.outputs.packageManager }}++ build_macos_arm64:+ name: macos build mac-arm64.dmg+ # ARM 独立完成构建和打包后启动 editor,避免等待其他桌面平台的整个矩阵。+ needs: [prepare, languages, contracts, frontend-tests]+ uses: ./.github/workflows/desktop-build.yml+ with:+ config: >-+ {"os":"macos-latest","name":"macos build mac-arm64.dmg","kernel_path":"../app/kernel-darwin-arm64/SiYuan-Kernel","build_args_prefix":"-s -w -X","build_args_suffix":"Mode=prod","electron_args":"dist-darwin-arm64","goos":"darwin","goarch":"arm64","suffix":"mac-arm64.dmg","e2e_shards":""}+ packageManager: ${{ needs.prepare.outputs.packageManager }}+ testing_ref: ${{ needs.prepare.outputs.testing_ref }}++ editor_e2e:+ name: macos ARM editor group ${{ matrix.group }}+ # 两组使用独立 runner 和工作空间,测试结果不回写发布产物。+ needs: [prepare, build_macos_arm64]+ runs-on: macos-latest+ timeout-minutes: 60+ permissions:+ contents: read+ strategy:+ fail-fast: false+ matrix:+ group: [1, 2]+ env:+ SIYUAN_E2E_SHARD: editor+ SIYUAN_BASE_URL: http://127.0.0.1:6807+ SIYUAN_TEST_RESULTS_DIR: test-results-editor-${{ matrix.group }}+ PLAYWRIGHT_HTML_OUTPUT_DIR: playwright-report-editor-${{ matrix.group }}+ PLAYWRIGHT_JSON_OUTPUT_FILE: editor-results-${{ matrix.group }}.jsonsteps:- - uses: actions/checkout@v6+ - name: Checkout test orchestration+ uses: actions/checkout@v6with:- path: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}+ path: source- - name: Set up MSYS2 UCRT64- uses: msys2/setup-msys2@v2- if: "contains( matrix.config.goos, 'windows')"- with:- msystem: UCRT64- install: p7zip mingw-w64-ucrt-x86_64-lua+ - name: Verify pinned revisions+ id: revisions+ shell: bash+ env:+ TESTING_REF: ${{ needs.prepare.outputs.testing_ref }}+ run: |+ [[ "$TESTING_REF" =~ ^[0-9a-f]{40}$ ]]+ test "$(git -C source rev-parse HEAD)" = "$GITHUB_SHA"+ test "$(uname -m)" = arm64- - name: Set up Go- uses: actions/setup-go@v6+ - name: Checkout pinned siyuan-testing+ uses: actions/checkout@v6with:- go-version-file: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel/go.mod- cache-dependency-path: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel/go.sum- cache: true- - run: go version-- - name: Set up goversioninfo- run: go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo && go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo- if: "contains( matrix.config.goos, 'windows')"- working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel- env:- GO111MODULE: on- CGO_ENABLED: 1- GOOS: ${{ matrix.config.goos }}- GOPATH: ${{ github.workspace }}/go- GOARCH: ${{ matrix.config.goarch }}+ repository: siyuan-note/siyuan-testing+ ref: ${{ needs.prepare.outputs.testing_ref }}+ path: siyuan-testing- name: Set up Nodeuses: actions/setup-node@v6with:node-version: 24- - name: Install Node pnpm- run: npm install -g ${{ needs.prepare.outputs.packageManager }}- working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app-- - name: Get pnpm store path- id: pnpm-store- shell: bash+ - name: Install test dependencies+ id: dependenciesrun: |- STORE_PATH=$(pnpm store path --silent)- echo "path=$STORE_PATH" >> "$GITHUB_OUTPUT"- working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app+ npm install --global ${{ needs.prepare.outputs.packageManager }}+ pnpm install --frozen-lockfile+ working-directory: siyuan-testing- - name: Cache pnpm store- uses: actions/cache@v5+ - name: Download raw ARM editor runtime+ id: download+ uses: actions/download-artifact@v8with:- path: ${{ steps.pnpm-store.outputs.path }}- key: pnpm-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles(format('go/src/github.com/{0}/app/pnpm-lock.yaml', github.repository)) }}- restore-keys: pnpm-${{ runner.os }}-${{ runner.arch }}--- - name: Install Node Dependencies- run: pnpm install --no-frozen-lockfile- working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app-- - name: Install Electron Binary- run: node node_modules/electron/install.js- working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app-- - name: Building UI- run: pnpm run build- working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app+ name: editor-runtime-macos-arm64+ path: editor-runtime- - name: Clean Build and Kernel Directories- run: |- rm -rf "${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build"- rm -rf "${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/kernel"*+ - name: Verify and restore editor runtime+ id: restoreshell: bash-- - name: Generate Icon Resource and Properties/Version Info For Windows- run: ${{ github.workspace }}\go\${{ matrix.config.gobin }}\goversioninfo -platform-specific=true -icon="resource\icon.ico" -manifest="resource\goversioninfo.exe.manifest"- if: "contains( matrix.config.goos, 'windows')"- working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel-- - name: Building Kernel- run: go build -tags "fts5 sqlcipher" -o "${{ matrix.config.kernel_path }}" -ldflags "${{ matrix.config.build_args_prefix }} github.com/${{ github.repository }}/kernel/util.${{ matrix.config.build_args_suffix }}"- working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernelenv:- GO111MODULE: on- CGO_ENABLED: 1- GOOS: ${{ matrix.config.goos }}- GOPATH: ${{ github.workspace }}/go- GOARCH: ${{ matrix.config.goarch }}-- - name: Checkout siyuan-testing- if: matrix.config.e2e_shards != ''- continue-on-error: true- uses: actions/checkout@v6- with:- repository: siyuan-note/siyuan-testing- ref: main- path: ${{ github.workspace }}/siyuan-testing-- - name: Install End-to-End Test Dependencies- if: matrix.config.e2e_shards != ''- continue-on-error: true- run: pnpm install --frozen-lockfile- working-directory: ${{ github.workspace }}/siyuan-testing-- - name: Validate End-to-End Test Shards- if: matrix.config.e2e_shards != ''+ TESTING_REF: ${{ needs.prepare.outputs.testing_ref }}+ run: |+ (cd editor-runtime && shasum -a 256 --check SHA256SUMS)+ node -e 'const r = require("./editor-runtime/revisions.json"); if (r.productSHA !== process.env.GITHUB_SHA || r.testingSHA !== process.env.TESTING_REF) throw new Error("Runtime revision mismatch");'+ test "$(git -C siyuan-testing rev-parse HEAD)" = "$TESTING_REF"+ mkdir runtime+ tar -xzf editor-runtime/runtime.tar.gz -C runtime+ test -x runtime/app/kernel-darwin-arm64/SiYuan-Kernel+ test -s runtime/app/stage/build/desktop/index.html+ test -d runtime/app/node_modules++ - name: Validate editor groups and test coverage+ id: coverageshell: bashrun: |pnpm run typecheck- # 每个 E2E job 只配置自己的 shard,校验脚本需要全量 shard 列表- # 才能验证三个 shard 的并集覆盖全部测试且无重复+ # 先检查现有三大分组,再校验 editor 两组的实际用例并集。unset SIYUAN_E2E_SHARDSpnpm run test:shards- working-directory: ${{ github.workspace }}/siyuan-testing+ node ../source/scripts/prepare-editor-e2e-groups.mjs "$PWD"+ working-directory: siyuan-testing- - name: Start Kernel for End-to-End Tests- if: matrix.config.e2e_shards != ''- continue-on-error: true- shell: bash- run: |- APP_DIR="${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app"- KERNEL_PATH="${{ matrix.config.kernel_path }}"- for shard_config in ${SIYUAN_E2E_SHARDS}; do- shard="${shard_config%:*}"- port="${shard_config#*:}"- workspace="${USERPROFILE:-${HOME}}/SiYuan-Testing"- mkdir -p "${workspace}"- "${KERNEL_PATH}" --workspace="${workspace}" serve --wd="${APP_DIR}" --port="${port}" \- > "${RUNNER_TEMP}/siyuan-e2e-${shard}-kernel-console.log" 2>&1 &- echo "$!" > "${RUNNER_TEMP}/siyuan-e2e-${shard}-kernel.pid"- done- working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel-- - name: Wait for End-to-End Test Kernels- if: matrix.config.e2e_shards != ''- continue-on-error: true+ - name: Start and wait for editor kernel+ id: kernelshell: bashrun: |- wait_for_kernel() {- local pid="$1"- local port="$2"- local log_path="$3"- local boot_progress_path="${RUNNER_TEMP}/siyuan-e2e-${port}-boot-progress.json"- for attempt in {1..60}; do- if curl --fail --silent --output "${boot_progress_path}" --request POST \- "http://127.0.0.1:${port}/api/system/bootProgress" && \- node -e 'try { const data = JSON.parse(require("node:fs").readFileSync(process.argv[1], "utf8")); process.exit(data.data?.progress >= 100 ? 0 : 1); } catch { process.exit(1); }' \- "${boot_progress_path}"; then- rm -f "${boot_progress_path}"- return- fi- if ! kill -0 "${pid}" 2>/dev/null; then- cat "${log_path}"- return 1- fi- sleep 1- done- cat "${log_path}"- if [ -f "${boot_progress_path}" ]; then- cat "${boot_progress_path}"+ mkdir -p "$HOME/SiYuan-Testing"+ "$GITHUB_WORKSPACE/runtime/app/kernel-darwin-arm64/SiYuan-Kernel" \+ --workspace="$HOME/SiYuan-Testing" serve --wd="$GITHUB_WORKSPACE/runtime/app" --port=6807 \+ > "$RUNNER_TEMP/editor-kernel-console.log" 2>&1 &+ pid=$!+ echo "$pid" > "$RUNNER_TEMP/editor-kernel.pid"+ for attempt in {1..60}; do+ if curl --fail --silent --output "$RUNNER_TEMP/editor-boot.json" --request POST \+ http://127.0.0.1:6807/api/system/bootProgress && \+ node -e 'try { const d = JSON.parse(require("node:fs").readFileSync(process.argv[1], "utf8")); process.exit(d.data?.progress >= 100 ? 0 : 1); } catch { process.exit(1); }' "$RUNNER_TEMP/editor-boot.json"; then+ exit 0fi- return 1- }- for shard_config in ${SIYUAN_E2E_SHARDS}; do- shard="${shard_config%:*}"- port="${shard_config#*:}"- pid="$(cat "${RUNNER_TEMP}/siyuan-e2e-${shard}-kernel.pid")"- wait_for_kernel "${pid}" "${port}" \- "${RUNNER_TEMP}/siyuan-e2e-${shard}-kernel-console.log"- done-- - name: Run End-to-End Tests- if: matrix.config.e2e_shards != ''- continue-on-error: true- timeout-minutes: 50- shell: bash- run: |- TEST_PIDS=()- TEST_SHARDS=()- for shard_config in ${SIYUAN_E2E_SHARDS}; do- shard="${shard_config%:*}"- port="${shard_config#*:}"- (- # UI 测试共享同一内核及全局界面状态,必须串行运行- # 编辑器分组用例较多,保留 45 分钟总时限;其他分组保持 25 分钟- # 外层步骤保留 5 分钟余量,单项用例仍使用测试配置中的超时- test_timeout=1500000- if [ "${shard}" = "editor" ]; then- test_timeout=2700000- fi- SIYUAN_BASE_URL="http://127.0.0.1:${port}" \- SIYUAN_E2E_SHARD="${shard}" \- SIYUAN_TEST_RESULTS_DIR="test-results-${shard}" \- PLAYWRIGHT_HTML_OUTPUT_DIR="playwright-report-${shard}" \- pnpm exec playwright test --config=config/playwright.focused.config.ts \- --global-timeout="${test_timeout}" --workers=1 \- --reporter=line,html --output="test-results-${shard}"- ) &- TEST_PID=$!- TEST_PIDS+=("${TEST_PID}")- TEST_SHARDS+=("${shard}")- done- TEST_STATUS=0- set +e- for index in "${!TEST_PIDS[@]}"; do- wait "${TEST_PIDS[${index}]}"- shard_status=$?- if [ "${shard_status}" -ne 0 ]; then- echo "::error title=End-to-End shard failed::${TEST_SHARDS[${index}]} exited with ${shard_status}"- TEST_STATUS=1+ if ! kill -0 "$pid" 2>/dev/null; then+ cat "$RUNNER_TEMP/editor-kernel-console.log"+ exit 1fi+ sleep 1done- set -e- exit "${TEST_STATUS}"- working-directory: ${{ github.workspace }}/siyuan-testing+ cat "$RUNNER_TEMP/editor-kernel-console.log"+ cat "$RUNNER_TEMP/editor-boot.json" 2>/dev/null || true+ exit 1- - name: Stop End-to-End Test Kernels- if: always() && matrix.config.e2e_shards != ''+ - name: Run editor group+ id: tests+ timeout-minutes: 50+ run: >-+ pnpm exec playwright test --config=config/playwright.editor-group-${{ matrix.group }}.config.ts+ --global-timeout=2700000 --workers=1 --reporter=line,html,json+ --output=test-results-editor-${{ matrix.group }}+ working-directory: siyuan-testing++ - name: Stop editor kernel+ if: always()continue-on-error: trueshell: bashrun: |- stop_kernel() {- local pid="$1"- if [ -z "${pid}" ] || ! kill -0 "${pid}" 2>/dev/null; then- return- fi- kill -TERM "${pid}"- for attempt in {1..30}; do- if ! kill -0 "${pid}" 2>/dev/null; then- return- fi- sleep 1- done- kill -KILL "${pid}"- }- for shard_config in ${SIYUAN_E2E_SHARDS}; do- shard="${shard_config%:*}"- pid_path="${RUNNER_TEMP}/siyuan-e2e-${shard}-kernel.pid"- if [ -f "${pid_path}" ]; then- stop_kernel "$(cat "${pid_path}")"- fi+ if [ ! -f "$RUNNER_TEMP/editor-kernel.pid" ]; then exit 0; fi+ pid=$(cat "$RUNNER_TEMP/editor-kernel.pid")+ if ! kill -0 "$pid" 2>/dev/null; then exit 0; fi+ kill -TERM "$pid"+ for attempt in {1..30}; do+ if ! kill -0 "$pid" 2>/dev/null; then exit 0; fi+ sleep 1done+ kill -KILL "$pid"- - name: Collect End-to-End Test Logs- if: always() && matrix.config.e2e_shards != ''- continue-on-error: true+ - name: Record editor outcome and collect logs+ if: always()shell: bash+ env:+ GROUP: ${{ matrix.group }}+ TESTING_REF: ${{ needs.prepare.outputs.testing_ref }}+ TEST_OUTCOME: ${{ steps.tests.outcome }}+ DOWNLOAD_OUTCOME: ${{ steps.download.outcome }}+ RESTORE_OUTCOME: ${{ steps.restore.outcome }}+ COVERAGE_OUTCOME: ${{ steps.coverage.outcome }}+ KERNEL_OUTCOME: ${{ steps.kernel.outcome }}run: |- log_dir="${{ github.workspace }}/siyuan-testing/kernel-logs"- mkdir -p "${log_dir}"- cp "${RUNNER_TEMP}"/siyuan-e2e-*-kernel-console.log "${log_dir}/" 2>/dev/null || true- workspace="${USERPROFILE:-${HOME}}/SiYuan-Testing"- if [ -f "${workspace}/temp/siyuan.log" ]; then- cp "${workspace}/temp/siyuan.log" "${log_dir}/siyuan.log"+ mkdir -p siyuan-testing/kernel-logs+ cp "$RUNNER_TEMP"/editor-kernel-console.log "$RUNNER_TEMP"/editor-boot.json siyuan-testing/kernel-logs/ 2>/dev/null || true+ cp "$HOME/SiYuan-Testing/temp/siyuan.log" siyuan-testing/kernel-logs/ 2>/dev/null || true+ cp editor-runtime/revisions.json siyuan-testing/kernel-logs/ 2>/dev/null || true+ if [ "$TEST_OUTCOME" = skipped ] || [ -z "$TEST_OUTCOME" ]; then+ status="NOT RUN (test prerequisites did not complete)"+ echo "::error title=Editor tests not run::Group $GROUP: download=$DOWNLOAD_OUTCOME restore=$RESTORE_OUTCOME coverage=$COVERAGE_OUTCOME kernel=$KERNEL_OUTCOME"+ else+ status="$TEST_OUTCOME (Playwright step outcome)"fi-- - name: Upload End-to-End Test Results- if: always() && matrix.config.e2e_shards != ''+ {+ echo "Editor group $GROUP: $status"+ echo "Product SHA: $GITHUB_SHA"+ echo "Testing SHA: $TESTING_REF"+ echo "Download: $DOWNLOAD_OUTCOME; restore: $RESTORE_OUTCOME; coverage: $COVERAGE_OUTCOME; kernel: $KERNEL_OUTCOME"+ } | tee siyuan-testing/kernel-logs/outcome.txt >> "$GITHUB_STEP_SUMMARY"++ - name: Upload editor reports and logs+ if: always()continue-on-error: trueuses: actions/upload-artifact@v7with:- name: siyuan-e2e-${{ matrix.config.suffix }}+ name: siyuan-e2e-editor-${{ matrix.group }}path: |- ${{ github.workspace }}/siyuan-testing/playwright-report-*- ${{ github.workspace }}/siyuan-testing/test-results-*- ${{ github.workspace }}/siyuan-testing/kernel-logs- if-no-files-found: ignore+ siyuan-testing/playwright-report-editor-*+ siyuan-testing/test-results-editor-*+ siyuan-testing/editor-results-*.json+ siyuan-testing/editor-e2e-groups.json+ siyuan-testing/kernel-logs+ if-no-files-found: warnretention-days: 14- - name: Install RPM build tools- if: matrix.config.goos == 'linux'- run: sudo apt-get install -y rpm-- - name: Building Electron App- run: pnpm run ${{ matrix.config.electron_args }}- working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app-- - name: Verify RPM Package Contents- if: matrix.config.goos == 'linux'- working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app- run: |- for package in build/*.rpm; do- test -f "$package"- build_id_entries="$(rpm -qpl "$package" | awk '/^\/usr\/lib\/\.build-id(\/|$)/')"- if [ -n "$build_id_entries" ]; then- echo "Unexpected build-id entries in $package:"- echo "$build_id_entries"- exit 1- fi- done-- - name: Upload Build Artifacts (Non-Linux)- if: matrix.config.goos != 'linux'- uses: actions/upload-artifact@v7- with:- name: siyuan-${{ matrix.config.suffix }}- path: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build/siyuan-*-${{ matrix.config.suffix }}-- - name: Upload Build Artifacts (Linux)- if: matrix.config.goos == 'linux'- uses: actions/upload-artifact@v7- with:- name: siyuan-linux- path: |- ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build/siyuan-*-linux.AppImage- ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build/siyuan-*-linux.tar.gz- ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build/siyuan-*-linux.deb- ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build/siyuan-*-linux.rpm-build_android:runs-on: ubuntu-24.04name: ubuntu build android.apk@@ -734,10 +626,17 @@ jobs:create_release:name: Create Releaseruns-on: ubuntu-24.04- needs: [prepare, build, build_android]+ needs: [prepare, build, build_macos_arm64, build_android, editor_e2e]+ # 等待两组测试结束;测试失败不阻塞发布,但构建失败或取消仍会阻止发布。+ if: >-+ ${{ always() && !cancelled() && needs.prepare.result == 'success' &&+ needs.build.result == 'success' && needs.build_macos_arm64.result == 'success' &&+ needs.build_android.result == 'success' && needs.editor_e2e.result != 'cancelled' }}steps:- - name: Download all artifacts+ - name: Download release artifactsuses: actions/download-artifact@v8+ with:+ pattern: siyuan-*- name: Prepare Release Assetsshell: bashdiff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.ymlnew file mode 100644index 0000000000..36e85acaf7--- /dev/null+++ b/.github/workflows/desktop-build.yml@@ -0,0 +1,361 @@+name: Desktop build++on:+ workflow_call:+ inputs:+ config:+ required: true+ type: string+ packageManager:+ required: true+ type: string+ testing_ref:+ default: ""+ type: string++jobs:+ build:+ runs-on: ${{ fromJSON(inputs.config).os }}+ name: ${{ fromJSON(inputs.config).name }}+ env:+ SIYUAN_E2E_SHARDS: ${{ fromJSON(inputs.config).e2e_shards }}+ steps:+ - uses: actions/checkout@v6+ with:+ path: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}++ - name: Set up MSYS2 UCRT64+ uses: msys2/setup-msys2@v2+ if: "contains( fromJSON(inputs.config).goos, 'windows')"+ with:+ msystem: UCRT64+ install: p7zip mingw-w64-ucrt-x86_64-lua++ - name: Set up Go+ uses: actions/setup-go@v6+ with:+ go-version-file: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel/go.mod+ cache-dependency-path: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel/go.sum+ cache: true+ - run: go version++ - name: Set up goversioninfo+ run: go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo && go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo+ if: "contains( fromJSON(inputs.config).goos, 'windows')"+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel+ env:+ GO111MODULE: on+ CGO_ENABLED: 1+ GOOS: ${{ fromJSON(inputs.config).goos }}+ GOPATH: ${{ github.workspace }}/go+ GOARCH: ${{ fromJSON(inputs.config).goarch }}++ - name: Set up Node+ uses: actions/setup-node@v6+ with:+ node-version: 24++ - name: Install Node pnpm+ run: npm install -g ${{ inputs.packageManager }}+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app++ - name: Get pnpm store path+ id: pnpm-store+ shell: bash+ run: |+ STORE_PATH=$(pnpm store path --silent)+ echo "path=$STORE_PATH" >> "$GITHUB_OUTPUT"+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app++ - name: Cache pnpm store+ uses: actions/cache@v5+ with:+ path: ${{ steps.pnpm-store.outputs.path }}+ key: pnpm-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles(format('go/src/github.com/{0}/app/pnpm-lock.yaml', github.repository)) }}+ restore-keys: pnpm-${{ runner.os }}-${{ runner.arch }}-++ - name: Install Node Dependencies+ run: pnpm install --no-frozen-lockfile+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app++ - name: Install Electron Binary+ run: node node_modules/electron/install.js+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app++ - name: Building UI+ run: pnpm run build+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app++ - name: Clean Build and Kernel Directories+ run: |+ rm -rf "${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build"+ rm -rf "${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/kernel"*+ shell: bash++ - name: Generate Icon Resource and Properties/Version Info For Windows+ run: ${{ github.workspace }}\go\${{ fromJSON(inputs.config).gobin }}\goversioninfo -platform-specific=true -icon="resource\icon.ico" -manifest="resource\goversioninfo.exe.manifest"+ if: "contains( fromJSON(inputs.config).goos, 'windows')"+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel++ - name: Building Kernel+ run: go build -tags "fts5 sqlcipher" -o "${{ fromJSON(inputs.config).kernel_path }}" -ldflags "${{ fromJSON(inputs.config).build_args_prefix }} github.com/${{ github.repository }}/kernel/util.${{ fromJSON(inputs.config).build_args_suffix }}"+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel+ env:+ GO111MODULE: on+ CGO_ENABLED: 1+ GOOS: ${{ fromJSON(inputs.config).goos }}+ GOPATH: ${{ github.workspace }}/go+ GOARCH: ${{ fromJSON(inputs.config).goarch }}++ - name: Snapshot raw ARM editor runtime+ id: editor-runtime+ if: fromJSON(inputs.config).goos == 'darwin' && fromJSON(inputs.config).goarch == 'arm64'+ continue-on-error: true+ shell: bash+ env:+ TESTING_REF: ${{ inputs.testing_ref }}+ run: |+ [[ "$TESTING_REF" =~ ^[0-9a-f]{40}$ ]]+ test "$(uname -m)" = arm64+ test "$(git rev-parse HEAD)" = "$GITHUB_SHA"+ test -x app/kernel-darwin-arm64/SiYuan-Kernel+ test -s app/stage/build/desktop/index.html+ test -d app/node_modules+ mkdir -p "$RUNNER_TEMP/editor-runtime"+ # 在打包脚本修改资源之前封存完整 app,tar 保留依赖链接和内核可执行权限。+ tar -czf "$RUNNER_TEMP/editor-runtime/runtime.tar.gz" app+ node -e 'require("node:fs").writeFileSync(process.argv[1], JSON.stringify({productSHA: process.env.GITHUB_SHA, testingSHA: process.env.TESTING_REF}, null, 2) + "\n")' \+ "$RUNNER_TEMP/editor-runtime/revisions.json"+ (cd "$RUNNER_TEMP/editor-runtime" && shasum -a 256 runtime.tar.gz revisions.json > SHA256SUMS)+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}++ - name: Upload raw ARM editor runtime+ if: steps.editor-runtime.outcome == 'success'+ continue-on-error: true+ uses: actions/upload-artifact@v7+ with:+ name: editor-runtime-macos-arm64+ path: ${{ runner.temp }}/editor-runtime/+ if-no-files-found: error+ compression-level: 0+ retention-days: 2++ - name: Checkout siyuan-testing+ if: fromJSON(inputs.config).e2e_shards != ''+ continue-on-error: true+ uses: actions/checkout@v6+ with:+ repository: siyuan-note/siyuan-testing+ ref: main+ path: ${{ github.workspace }}/siyuan-testing++ - name: Install End-to-End Test Dependencies+ if: fromJSON(inputs.config).e2e_shards != ''+ continue-on-error: true+ run: pnpm install --frozen-lockfile+ working-directory: ${{ github.workspace }}/siyuan-testing++ - name: Validate End-to-End Test Shards+ if: fromJSON(inputs.config).e2e_shards != ''+ shell: bash+ run: |+ pnpm run typecheck+ # 每个 E2E job 只配置自己的 shard,校验脚本需要全量 shard 列表+ # 才能验证三个 shard 的并集覆盖全部测试且无重复+ unset SIYUAN_E2E_SHARDS+ pnpm run test:shards+ working-directory: ${{ github.workspace }}/siyuan-testing++ - name: Start Kernel for End-to-End Tests+ if: fromJSON(inputs.config).e2e_shards != ''+ continue-on-error: true+ shell: bash+ run: |+ APP_DIR="${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app"+ KERNEL_PATH="${{ fromJSON(inputs.config).kernel_path }}"+ for shard_config in ${SIYUAN_E2E_SHARDS}; do+ shard="${shard_config%:*}"+ port="${shard_config#*:}"+ workspace="${USERPROFILE:-${HOME}}/SiYuan-Testing"+ mkdir -p "${workspace}"+ "${KERNEL_PATH}" --workspace="${workspace}" serve --wd="${APP_DIR}" --port="${port}" \+ > "${RUNNER_TEMP}/siyuan-e2e-${shard}-kernel-console.log" 2>&1 &+ echo "$!" > "${RUNNER_TEMP}/siyuan-e2e-${shard}-kernel.pid"+ done+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel++ - name: Wait for End-to-End Test Kernels+ if: fromJSON(inputs.config).e2e_shards != ''+ continue-on-error: true+ shell: bash+ run: |+ wait_for_kernel() {+ local pid="$1"+ local port="$2"+ local log_path="$3"+ local boot_progress_path="${RUNNER_TEMP}/siyuan-e2e-${port}-boot-progress.json"+ for attempt in {1..60}; do+ if curl --fail --silent --output "${boot_progress_path}" --request POST \+ "http://127.0.0.1:${port}/api/system/bootProgress" && \+ node -e 'try { const data = JSON.parse(require("node:fs").readFileSync(process.argv[1], "utf8")); process.exit(data.data?.progress >= 100 ? 0 : 1); } catch { process.exit(1); }' \+ "${boot_progress_path}"; then+ rm -f "${boot_progress_path}"+ return+ fi+ if ! kill -0 "${pid}" 2>/dev/null; then+ cat "${log_path}"+ return 1+ fi+ sleep 1+ done+ cat "${log_path}"+ if [ -f "${boot_progress_path}" ]; then+ cat "${boot_progress_path}"+ fi+ return 1+ }+ for shard_config in ${SIYUAN_E2E_SHARDS}; do+ shard="${shard_config%:*}"+ port="${shard_config#*:}"+ pid="$(cat "${RUNNER_TEMP}/siyuan-e2e-${shard}-kernel.pid")"+ wait_for_kernel "${pid}" "${port}" \+ "${RUNNER_TEMP}/siyuan-e2e-${shard}-kernel-console.log"+ done++ - name: Run End-to-End Tests+ if: fromJSON(inputs.config).e2e_shards != ''+ continue-on-error: true+ timeout-minutes: 50+ shell: bash+ run: |+ TEST_PIDS=()+ TEST_SHARDS=()+ for shard_config in ${SIYUAN_E2E_SHARDS}; do+ shard="${shard_config%:*}"+ port="${shard_config#*:}"+ (+ # UI 测试共享同一内核及全局界面状态,必须串行运行+ # 编辑器分组用例较多,保留 45 分钟总时限;其他分组保持 25 分钟+ # 外层步骤保留 5 分钟余量,单项用例仍使用测试配置中的超时+ test_timeout=1500000+ if [ "${shard}" = "editor" ]; then+ test_timeout=2700000+ fi+ SIYUAN_BASE_URL="http://127.0.0.1:${port}" \+ SIYUAN_E2E_SHARD="${shard}" \+ SIYUAN_TEST_RESULTS_DIR="test-results-${shard}" \+ PLAYWRIGHT_HTML_OUTPUT_DIR="playwright-report-${shard}" \+ pnpm exec playwright test --config=config/playwright.focused.config.ts \+ --global-timeout="${test_timeout}" --workers=1 \+ --reporter=line,html --output="test-results-${shard}"+ ) &+ TEST_PID=$!+ TEST_PIDS+=("${TEST_PID}")+ TEST_SHARDS+=("${shard}")+ done+ TEST_STATUS=0+ set +e+ for index in "${!TEST_PIDS[@]}"; do+ wait "${TEST_PIDS[${index}]}"+ shard_status=$?+ if [ "${shard_status}" -ne 0 ]; then+ echo "::error title=End-to-End shard failed::${TEST_SHARDS[${index}]} exited with ${shard_status}"+ TEST_STATUS=1+ fi+ done+ set -e+ exit "${TEST_STATUS}"+ working-directory: ${{ github.workspace }}/siyuan-testing++ - name: Stop End-to-End Test Kernels+ if: always() && fromJSON(inputs.config).e2e_shards != ''+ continue-on-error: true+ shell: bash+ run: |+ stop_kernel() {+ local pid="$1"+ if [ -z "${pid}" ] || ! kill -0 "${pid}" 2>/dev/null; then+ return+ fi+ kill -TERM "${pid}"+ for attempt in {1..30}; do+ if ! kill -0 "${pid}" 2>/dev/null; then+ return+ fi+ sleep 1+ done+ kill -KILL "${pid}"+ }+ for shard_config in ${SIYUAN_E2E_SHARDS}; do+ shard="${shard_config%:*}"+ pid_path="${RUNNER_TEMP}/siyuan-e2e-${shard}-kernel.pid"+ if [ -f "${pid_path}" ]; then+ stop_kernel "$(cat "${pid_path}")"+ fi+ done++ - name: Collect End-to-End Test Logs+ if: always() && fromJSON(inputs.config).e2e_shards != ''+ continue-on-error: true+ shell: bash+ run: |+ log_dir="${{ github.workspace }}/siyuan-testing/kernel-logs"+ mkdir -p "${log_dir}"+ cp "${RUNNER_TEMP}"/siyuan-e2e-*-kernel-console.log "${log_dir}/" 2>/dev/null || true+ workspace="${USERPROFILE:-${HOME}}/SiYuan-Testing"+ if [ -f "${workspace}/temp/siyuan.log" ]; then+ cp "${workspace}/temp/siyuan.log" "${log_dir}/siyuan.log"+ fi++ - name: Upload End-to-End Test Results+ if: always() && fromJSON(inputs.config).e2e_shards != ''+ continue-on-error: true+ uses: actions/upload-artifact@v7+ with:+ name: siyuan-e2e-${{ fromJSON(inputs.config).suffix }}+ path: |+ ${{ github.workspace }}/siyuan-testing/playwright-report-*+ ${{ github.workspace }}/siyuan-testing/test-results-*+ ${{ github.workspace }}/siyuan-testing/kernel-logs+ if-no-files-found: ignore+ retention-days: 14++ - name: Install RPM build tools+ if: fromJSON(inputs.config).goos == 'linux'+ run: sudo apt-get install -y rpm++ - name: Building Electron App+ run: pnpm run ${{ fromJSON(inputs.config).electron_args }}+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app++ - name: Verify RPM Package Contents+ if: fromJSON(inputs.config).goos == 'linux'+ working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app+ run: |+ for package in build/*.rpm; do+ test -f "$package"+ build_id_entries="$(rpm -qpl "$package" | awk '/^\/usr\/lib\/\.build-id(\/|$)/')"+ if [ -n "$build_id_entries" ]; then+ echo "Unexpected build-id entries in $package:"+ echo "$build_id_entries"+ exit 1+ fi+ done++ - name: Upload Build Artifacts (Non-Linux)+ if: fromJSON(inputs.config).goos != 'linux'+ uses: actions/upload-artifact@v7+ with:+ name: siyuan-${{ fromJSON(inputs.config).suffix }}+ path: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build/siyuan-*-${{ fromJSON(inputs.config).suffix }}++ - name: Upload Build Artifacts (Linux)+ if: fromJSON(inputs.config).goos == 'linux'+ uses: actions/upload-artifact@v7+ with:+ name: siyuan-linux+ path: |+ ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build/siyuan-*-linux.AppImage+ ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build/siyuan-*-linux.tar.gz+ ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build/siyuan-*-linux.deb+ ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build/siyuan-*-linux.rpmdiff --git a/scripts/editor-e2e-durations.json b/scripts/editor-e2e-durations.jsonnew file mode 100644index 0000000000..e99872bfc3--- /dev/null+++ b/scripts/editor-e2e-durations.json@@ -0,0 +1,34 @@+{+ "source": "https://github.com/siyuan-note/siyuan/actions/runs/37083275136",+ "testingCommit": "d4a2cfcb7a9ac36d19672229ec1e2edf6385fee8",+ "durationsMs": {+ "editor-assets.spec.ts": 23678,+ "editor-block-batch.spec.ts": 61367,+ "editor-block-embed.spec.ts": 41358,+ "editor-block-reference.spec.ts": 30187,+ "editor-block-split-merge.spec.ts": 168059,+ "editor-block-transform.spec.ts": 35270,+ "editor-composition.spec.ts": 15801,+ "editor-concurrent-input.spec.ts": 9640,+ "editor-copy-paste.spec.ts": 103266,+ "editor-cross-document.spec.ts": 12726,+ "editor-font-size.spec.ts": 8712,+ "editor-inline-code-wrap.spec.ts": 80874,+ "editor-inline-direction.spec.ts": 6601,+ "editor-inline-element-boundary.spec.ts": 97206,+ "editor-inline-element-mixed-wrap.spec.ts": 37371,+ "editor-inline-element-remove.spec.ts": 34275,+ "editor-inline-element-words.spec.ts": 15832,+ "editor-inline-element-wrap.spec.ts": 155613,+ "editor-list-drag.spec.ts": 116642,+ "editor-list-mindmap-integrations.spec.ts": 49431,+ "editor-list-mindmap.spec.ts": 53359,+ "editor-long-text-wrap.spec.ts": 153962,+ "editor-readiness.spec.ts": 5339,+ "editor-super-block.spec.ts": 23188,+ "editor-table-virtualization.spec.ts": 82563,+ "editor-table.spec.ts": 213847,+ "editor-touch-block-selection.spec.ts": 3703,+ "editor.spec.ts": 23607+ }+}diff --git a/scripts/prepare-editor-e2e-groups.mjs b/scripts/prepare-editor-e2e-groups.mjsnew file mode 100644index 0000000000..8e836b6749--- /dev/null+++ b/scripts/prepare-editor-e2e-groups.mjs@@ -0,0 +1,194 @@+import assert from "node:assert/strict";+import {spawnSync} from "node:child_process";+import {createHash} from "node:crypto";+import {readFileSync, writeFileSync} from "node:fs";+import {createRequire} from "node:module";+import path from "node:path";+import {fileURLToPath} from "node:url";++const compare = (left, right) => left < right ? -1 : left > right ? 1 : 0;+const hash = values => createHash("sha256").update(JSON.stringify([...values].sort(compare))).digest("hex");+const unique = (values, label) => {+ assert.equal(new Set(values).size, values.length, `Duplicate ${label}`);+};++// 只读取 Playwright 实际发现的测试,避免固定文件清单遗漏新增用例。+export function readListing(report) {+ assert.deepEqual(report.errors ?? [], [], "Playwright listing contains errors");+ assert.ok(Array.isArray(report.suites), "Missing Playwright suites");+ const tests = [];+ const visit = suite => {+ for (const spec of suite.specs ?? []) {+ for (const test of spec.tests ?? []) {+ assert.ok(spec.id && spec.file && test.projectName, "Invalid Playwright test identity");+ tests.push({+ id: JSON.stringify([test.projectName, spec.id, spec.file]),+ file: spec.file,+ project: test.projectName,+ });+ }+ }+ for (const child of suite.suites ?? []) {+ visit(child);+ }+ };+ report.suites.forEach(visit);+ unique(tests.map(test => test.id), "test identities");+ assert.ok(tests.some(test => test.project === "editor"), "No editor tests discovered");+ return tests;+}++export function partitionFiles(tests, durations = {}) {+ const counts = new Map();+ for (const test of tests.filter(test => test.project === "editor")) {+ counts.set(test.file, (counts.get(test.file) ?? 0) + 1);+ }+ assert.ok(counts.size >= 2, "Two editor groups require at least two spec files");+ unique(tests.map(test => test.id), "test identities");+ for (const [file, duration] of Object.entries(durations)) {+ assert.ok(Number.isFinite(duration) && duration > 0, `Invalid duration for ${file}`);+ }+ // 新文件按历史单用例中位耗时估算;没有历史数据时按用例数均衡。+ const rates = [...counts].filter(([file]) => Object.hasOwn(durations, file))+ .map(([file, count]) => durations[file] / count).sort((left, right) => left - right);+ const fallback = rates.length ? rates[Math.floor(rates.length / 2)] : 1;+ const files = [...counts].map(([file, testCount]) => ({+ file,+ testCount,+ weight: durations[file] ?? fallback * testCount,+ estimated: !Object.hasOwn(durations, file),+ })).sort((left, right) => right.weight - left.weight || compare(left.file, right.file));+ const groups = [{files: [], weight: 0}, {files: [], weight: 0}];+ for (const file of files) {+ const group = groups[0].weight <= groups[1].weight ? groups[0] : groups[1];+ group.files.push(file);+ group.weight += file.weight;+ }+ for (const group of groups) {+ group.files.sort((left, right) => compare(left.file, right.file));+ }+ return groups;+}++export function validateGroups(original, listings, groups) {+ assert.equal(listings.length, 2, "Expected two editor listings");+ assert.equal(groups.length, 2, "Expected two editor groups");+ const expected = original.filter(test => test.project === "editor");+ const dependencies = original.filter(test => test.project !== "editor").map(test => test.id).sort(compare);+ unique(original.map(test => test.id), "original test identities");+ const combined = [];+ const files = new Set();+ listings.forEach((listing, index) => {+ unique(listing.map(test => test.id), `group ${index + 1} test identities`);+ const editor = listing.filter(test => test.project === "editor");+ assert.ok(editor.length, `Editor group ${index + 1} is empty`);+ assert.deepEqual(listing.filter(test => test.project !== "editor").map(test => test.id).sort(compare),+ dependencies, `Setup/cleanup coverage changed in group ${index + 1}`);+ const selected = groups[index].files.map(entry => entry.file).sort(compare);+ unique(selected, `group ${index + 1} files`);+ assert.deepEqual([...new Set(editor.map(test => test.file))].sort(compare), selected,+ `File selection differs in group ${index + 1}`);+ for (const file of selected) {+ assert.ok(!files.has(file), `Spec file appears in both groups: ${file}`);+ files.add(file);+ }+ const selectedSet = new Set(selected);+ assert.deepEqual(editor.map(test => test.id).sort(compare),+ expected.filter(test => selectedSet.has(test.file)).map(test => test.id).sort(compare),+ `Incomplete spec file in group ${index + 1}`);+ combined.push(...editor.map(test => test.id));+ });+ unique(combined, "editor tests across groups");+ assert.deepEqual(combined.sort(compare), expected.map(test => test.id).sort(compare),+ "Editor coverage has missing or unexpected tests");+}++export function createConfig(files, testRoot) {+ assert.ok(files.length, "Cannot create an empty editor group");+ unique(files, "config files");+ const matches = files.map(file => {+ const absolute = path.resolve(testRoot, file);+ const relative = path.relative(testRoot, absolute);+ assert.ok(relative && !relative.startsWith(`..${path.sep}`) && relative !== ".." &&+ !path.isAbsolute(relative), `Spec file is outside test root: ${file}`);+ // 完整路径正则只匹配选中的文件,不让 glob 元字符扩大匹配范围。+ return `new RegExp(${JSON.stringify(`^${absolute.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`)})`;+ });+ return `// 此配置由 SiYuan 的 prepare-editor-e2e-groups.mjs 生成。\n` ++ `import focused from "./playwright.focused.config";\n\n` ++ `if (process.env.SIYUAN_E2E_SHARD !== "editor" ||\n` ++ ` focused.projects?.filter(project => project.name === "editor").length !== 1) {\n` ++ ` throw new Error("Editor group requires SIYUAN_E2E_SHARD=editor and one editor project");\n` ++ `}\n\n` ++ `export default {\n` ++ ` ...focused,\n` ++ ` projects: focused.projects.map(project => project.name === "editor" ? {\n` ++ ` ...project,\n` ++ ` testMatch: [\n ${matches.join(",\n ")},\n ],\n` ++ ` } : project),\n` ++ `};\n`;+}++function listTests(root, cli, config) {+ const env = {...process.env, SIYUAN_E2E_SHARD: "editor", FORCE_COLOR: "0"};+ // 始终从标准输出解析 JSON,不受 CI 上层配置的报告输出文件影响。+ delete env.PLAYWRIGHT_JSON_OUTPUT_FILE;+ delete env.PLAYWRIGHT_JSON_OUTPUT_DIR;+ delete env.PLAYWRIGHT_JSON_OUTPUT_NAME;+ const result = spawnSync(process.execPath,+ [cli, "test", `--config=${config}`, "--list", "--reporter=json", "--workers=1"],+ {cwd: root, env, encoding: "utf8", maxBuffer: 64 * 1024 * 1024});+ if (result.error || result.status !== 0) {+ throw new Error(`Unable to list ${config}: ${result.error?.message ?? result.stderr}\n${result.stdout}`);+ }+ const report = JSON.parse(result.stdout);+ return {report, tests: readListing(report)};+}++export function main(args) {+ assert.equal(args.length, 1, "Usage: node scripts/prepare-editor-e2e-groups.mjs <testing-repo>");+ const root = path.resolve(args[0]);+ const require = createRequire(path.join(root, "package.json"));+ const cli = require.resolve("@playwright/test/cli");+ const baseline = listTests(root, cli, "config/playwright.focused.config.ts");+ const history = JSON.parse(readFileSync(new URL("editor-e2e-durations.json", import.meta.url), "utf8"));+ const groups = partitionFiles(baseline.tests, history.durationsMs);+ const listings = groups.map((group, index) => {+ group.config = `config/playwright.editor-group-${index + 1}.config.ts`;+ writeFileSync(path.join(root, group.config),+ createConfig(group.files.map(entry => entry.file), baseline.report.config.rootDir));+ return listTests(root, cli, group.config).tests;+ });+ validateGroups(baseline.tests, listings, groups);+ const editor = baseline.tests.filter(test => test.project === "editor");+ const manifest = {+ durationSource: history.source,+ weightUnit: groups.some(group => group.files.some(file => !file.estimated)) ? "estimated milliseconds" : "test count",+ testCount: editor.length,+ fileCount: new Set(editor.map(test => test.file)).size,+ testsSha256: hash(editor.map(test => test.id)),+ groups: groups.map((group, index) => ({+ group: index + 1,+ config: group.config,+ weight: group.weight,+ testCount: group.files.reduce((total, file) => total + file.testCount, 0),+ testsSha256: hash(listings[index].filter(test => test.project === "editor").map(test => test.id)),+ files: group.files,+ })),+ };+ writeFileSync(path.join(root, "editor-e2e-groups.json"), JSON.stringify(manifest, null, 2) + "\n");+ for (const group of manifest.groups) {+ console.log(`editor-${group.group}: ${group.files.length} files, ${group.testCount} tests, ` ++ `weight ${Math.round(group.weight)}; ${group.testsSha256}`);+ }+ console.log(`Editor coverage verified: ${manifest.fileCount} files, ${editor.length} tests; ${manifest.testsSha256}`);+}++if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {+ try {+ main(process.argv.slice(2));+ } catch (error) {+ console.error(error.message);+ process.exitCode = 1;+ }+}diff --git a/scripts/test-prepare-editor-e2e-groups.mjs b/scripts/test-prepare-editor-e2e-groups.mjsnew file mode 100644index 0000000000..c1bc142b46--- /dev/null+++ b/scripts/test-prepare-editor-e2e-groups.mjs@@ -0,0 +1,129 @@+import assert from "node:assert/strict";+import path from "node:path";+import test from "node:test";+import {createConfig, partitionFiles, readListing, validateGroups} from "./prepare-editor-e2e-groups.mjs";++const editorTest = (file, id = file) => ({file, id, project: "editor"});+const dependencies = [+ {file: "global.setup.ts", id: "setup", project: "setup"},+ {file: "global.teardown.ts", id: "cleanup", project: "cleanup"},+];+const original = [+ ...dependencies,+ editorTest("editor-a.spec.ts", "a1"),+ editorTest("editor-a.spec.ts", "a2"),+ editorTest("editor-b.spec.ts", "b1"),+ editorTest("editor-c.spec.ts", "c1"),+];+const select = (tests, groups) => groups.map(group => {+ const files = new Set(group.files.map(entry => entry.file));+ return tests.filter(entry => entry.project !== "editor" || files.has(entry.file));+});+const spec = (file, id, project = "editor") => ({+ id, file, tests: [{projectName: project}],+});++test("reads nested Playwright suites and preserves dependency projects", () => {+ const report = {errors: [], suites: [+ {specs: [spec("global.setup.ts", "setup", "setup")]},+ {suites: [{specs: [spec("editor-a.spec.ts", "a1"), spec("editor-a.spec.ts", "a2")]}]},+ {specs: [spec("global.teardown.ts", "cleanup", "cleanup")]},+ ]};+ const listing = readListing(report);+ assert.equal(listing.length, 4);+ assert.deepEqual(listing.map(entry => entry.project), ["setup", "editor", "editor", "cleanup"]);+});++test("rejects empty, errored, malformed and duplicate listings", () => {+ assert.throws(() => readListing({suites: []}), /No editor tests/);+ assert.throws(() => readListing({suites: [], errors: [{message: "broken import"}]}), /contains errors/);+ assert.throws(() => readListing({}), /Missing Playwright suites/);+ assert.throws(() => readListing({suites: [{specs: [{tests: [{}]}]}]}), /Invalid Playwright/);+ assert.throws(() => readListing({suites: [{specs: [+ spec("editor-a.spec.ts", "a1"), spec("editor-a.spec.ts", "a1"),+ ]}]}), /Duplicate test identities/);+});++test("balances historical durations without splitting files", () => {+ const groups = partitionFiles(original, {+ "editor-a.spec.ts": 100,+ "editor-b.spec.ts": 60,+ "editor-c.spec.ts": 40,+ });+ assert.deepEqual(groups.map(group => group.weight), [100, 100]);+ assert.deepEqual(groups.map(group => group.files.map(entry => entry.file)), [+ ["editor-a.spec.ts"], ["editor-b.spec.ts", "editor-c.spec.ts"],+ ]);+ validateGroups(original, select(original, groups), groups);+});++test("includes new specs automatically and ignores deleted historical specs", () => {+ const tests = [...original, editorTest("editor-new.spec.ts", "new1"), editorTest("editor-new.spec.ts", "new2")];+ const groups = partitionFiles(tests, {"editor-a.spec.ts": 100, "editor-deleted.spec.ts": 500});+ const added = groups.flatMap(group => group.files).find(entry => entry.file === "editor-new.spec.ts");+ assert.deepEqual(added, {file: "editor-new.spec.ts", testCount: 2, weight: 100, estimated: true});+ assert.ok(!groups.flatMap(group => group.files).some(entry => entry.file === "editor-deleted.spec.ts"));+ validateGroups(tests, select(tests, groups), groups);+});++test("falls back to test counts and stays deterministic across discovery order", () => {+ const first = partitionFiles(original);+ const second = partitionFiles([...original].reverse());+ assert.deepEqual(first, second);+ assert.deepEqual(first.map(group => group.weight), [2, 2]);+ validateGroups(original, select(original, first), first);+});++test("rejects insufficient files, duplicate identities and invalid weights", () => {+ assert.throws(() => partitionFiles([]), /at least two/);+ assert.throws(() => partitionFiles([editorTest("editor-a.spec.ts")]), /at least two/);+ assert.throws(() => partitionFiles([...original, original[2]]), /Duplicate test identities/);+ for (const weight of [0, -1, NaN, Infinity, "100"]) {+ assert.throws(() => partitionFiles(original, {"editor-a.spec.ts": weight}), /Invalid duration/);+ }+});++test("rejects empty groups, missing or unexpected tests and missing dependencies", () => {+ const groups = partitionFiles(original);+ const listings = select(original, groups);+ assert.throws(() => validateGroups(original, [[], listings[1]], groups), /is empty/);+ assert.throws(() => validateGroups(original, [listings[0].filter(entry => entry.id !== "a1"), listings[1]], groups),+ /Incomplete spec file/);+ assert.throws(() => validateGroups(original, [[...listings[0], editorTest("editor-a.spec.ts", "extra")], listings[1]], groups),+ /Incomplete spec file/);+ assert.throws(() => validateGroups(original, [listings[0].filter(entry => entry.project !== "setup"), listings[1]], groups),+ /Setup\/cleanup coverage changed/);+ assert.throws(() => validateGroups(original, [[...listings[0], listings[0][0]], listings[1]], groups),+ /Duplicate group 1 test identities/);+});++test("rejects files duplicated between groups even when whole file listings match", () => {+ const groups = partitionFiles(original);+ groups[1].files.push(groups[0].files[0]);+ assert.throws(() => validateGroups(original, select(original, groups), groups), /Spec file appears in both groups/);+});++test("rejects a missing whole spec file", () => {+ const groups = partitionFiles(original);+ groups[1].files.pop();+ assert.throws(() => validateGroups(original, select(original, groups), groups), /coverage has missing/);+});++test("creates exact full-path matches and preserves focused configuration", () => {+ const root = path.resolve("test-root [special]");+ const file = "nested/editor-a+[1].spec.ts";+ const config = createConfig([file], root);+ const serializedPattern = config.match(/new RegExp\((.+)\)/)[1];+ const pattern = new RegExp(JSON.parse(serializedPattern));+ assert.ok(pattern.test(path.resolve(root, file)));+ assert.ok(!pattern.test(path.resolve(root, "nested/editor-aa1.spec.ts")));+ assert.ok(!pattern.test(path.resolve(root, `${file}.backup`)));+ assert.match(config, /import focused from "\.\/playwright.focused.config"/);+ assert.match(config, /\.\.\.focused/);+ assert.match(config, /\.\.\.project/);+ assert.match(config, /\} : project/);+ assert.ok(!config.includes("workers:"));+ assert.throws(() => createConfig([], root), /empty editor group/);+ assert.throws(() => createConfig([file, file], root), /Duplicate config files/);+ assert.throws(() => createConfig(["../outside.spec.ts"], root), /outside test root/);+});diff --git a/scripts/test_editor_e2e_workflow.py b/scripts/test_editor_e2e_workflow.pynew file mode 100644index 0000000000..295c74fc5f--- /dev/null+++ b/scripts/test_editor_e2e_workflow.py@@ -0,0 +1,103 @@+"""编辑器分组工作流的发布门禁和运行时快照回归测试。"""++import itertools+import os+from pathlib import Path+import re+import shutil+import subprocess+import tarfile+import tempfile+import unittest+++ROOT = Path(__file__).resolve().parents[1]+CD = (ROOT / ".github/workflows/cd.yml").read_text(encoding="utf-8")+DESKTOP = (ROOT / ".github/workflows/desktop-build.yml").read_text(encoding="utf-8")+++def job(name):+ return re.search(rf"^ {name}:\n(.*?)(?=^ \w+:\n|\Z)", CD, re.M | re.S).group(1)+++def snapshot_command():+ step = DESKTOP.split(" - name: Snapshot raw ARM editor runtime\n", 1)[1]+ command = step.split(" run: |\n", 1)[1].split(" working-directory:", 1)[0]+ return "\n".join(line[10:] for line in command.splitlines())+++class EditorWorkflowTests(unittest.TestCase):+ def test_release_waits_for_editor_but_ignores_test_failure(self):+ release = job("create_release")+ self.assertIn("needs: [prepare, build, build_macos_arm64, build_android, editor_e2e]", release)+ expression = re.search(r"if: >-\s*\$\{\{(.*?)\}\}", release, re.S).group(1)+ expression = expression.replace("always()", "True").replace("!cancelled()", "not cancelled")+ expression = expression.replace("&&", " and ")+ expression = re.sub(r"needs\.(\w+)\.result", r'results["\1"]', expression)+ expression = " ".join(expression.split())+ states = ["success", "failure", "skipped", "cancelled"]+ for values in itertools.product(states, repeat=5):+ results = dict(zip(["prepare", "build", "build_macos_arm64", "build_android", "editor_e2e"], values))+ for cancelled in [False, True]:+ expected = not cancelled and all(value == "success" for value in values[:4]) and values[4] != "cancelled"+ actual = eval(expression, {"__builtins__": {}}, {"results": results, "cancelled": cancelled})+ self.assertEqual(actual, expected, (results, cancelled))++ def test_independent_editor_runners_and_serial_workers(self):+ editor = job("editor_e2e")+ self.assertIn("needs: [prepare, build_macos_arm64]", editor)+ self.assertIn("fail-fast: false", editor)+ self.assertIn("group: [1, 2]", editor)+ self.assertIn("--workers=1", editor)+ self.assertIn('--workspace="$HOME/SiYuan-Testing"', editor)+ self.assertNotIn("continue-on-error: true\n run: >-", editor)+ for name in ["Stop editor kernel", "Record editor outcome and collect logs", "Upload editor reports and logs"]:+ self.assertIn(f"- name: {name}\n if: always()", editor)+ self.assertIn("NOT RUN (test prerequisites did not complete)", editor)++ @unittest.skipUnless(os.name == "posix" and all(shutil.which(tool) for tool in ["bash", "node", "tar", "shasum"]),+ "Snapshot command requires Unix tools")+ def test_snapshot_round_trip_and_checksum(self):+ with tempfile.TemporaryDirectory() as temporary:+ root = Path(temporary)+ app = root / "app"+ kernel = app / "kernel-darwin-arm64/SiYuan-Kernel"+ kernel.parent.mkdir(parents=True)+ kernel.write_bytes(b"kernel fixture")+ kernel.chmod(0o755)+ desktop = app / "stage/build/desktop/index.html"+ desktop.parent.mkdir(parents=True)+ desktop.write_text("fixture", encoding="utf-8")+ dependency = app / "node_modules/.pnpm/example/index.js"+ dependency.parent.mkdir(parents=True)+ dependency.write_text("fixture", encoding="utf-8")+ (app / "node_modules/example").symlink_to(".pnpm/example", target_is_directory=True)+ bin_dir = root / "bin"+ bin_dir.mkdir()+ sha = "a" * 40+ for name, value in [("uname", "arm64"), ("git", sha)]:+ executable = bin_dir / name+ executable.write_text(f"#!/bin/sh\nprintf '%s\\n' '{value}'\n", encoding="utf-8")+ executable.chmod(0o755)+ env = {**os.environ, "PATH": f"{bin_dir}:{os.environ['PATH']}", "RUNNER_TEMP": str(root / "temp"),+ "GITHUB_SHA": sha, "TESTING_REF": "b" * 40}+ result = subprocess.run(["bash", "-euo", "pipefail", "-c", snapshot_command()], cwd=root,+ env=env, text=True, capture_output=True)+ self.assertEqual(result.returncode, 0, result.stderr)+ runtime = root / "temp/editor-runtime"+ with tarfile.open(runtime / "runtime.tar.gz") as archive:+ self.assertTrue(archive.getmember("app/kernel-darwin-arm64/SiYuan-Kernel").mode & 0o111)+ self.assertEqual(archive.getmember("app/node_modules/example").linkname, ".pnpm/example")+ self.assertEqual(archive.extractfile("app/node_modules/.pnpm/example/index.js").read(), b"fixture")+ check = ["shasum", "-a", "256", "--check", "SHA256SUMS"]+ self.assertEqual(subprocess.run(check, cwd=runtime, capture_output=True).returncode, 0)+ with (runtime / "runtime.tar.gz").open("ab") as archive:+ archive.write(b"tampered")+ self.assertNotEqual(subprocess.run(check, cwd=runtime, capture_output=True).returncode, 0)+ env["TESTING_REF"] = ""+ self.assertNotEqual(subprocess.run(["bash", "-euo", "pipefail", "-c", snapshot_command()],+ cwd=root, env=env, capture_output=True).returncode, 0)+++if __name__ == "__main__":+ unittest.main()