A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io
Rust ai-toolsclaude-codecodexdeepseek-harnessdesktop-appgrokgrokbuildhermeskimi-codemcpopen-sourceopencodepiprovider-managementrustskillsskills-managementtauriwsl-support
perf(ci): tier PR backend checks across OSes and speed up Rust compilation (#10017)
Allen Xudf82e192c621
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 770504fac..ca51b66ce 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -29,8 +29,9 @@ jobs:# readme / frontend_contracts 默认 false:定时或手动运行时 frontend 已是 true,# 会跑全量前端检查与测试,不需要再单独起轻量 job。frontend: ${{ steps.filter.outputs.frontend || 'true' }}- backend: ${{ steps.filter.outputs.backend || 'true' }}- wsl: ${{ steps.filter.outputs.wsl || 'true' }}+ backend: ${{ steps.scope.outputs.backend }}+ wsl: ${{ steps.scope.outputs.wsl }}+ macos_full: ${{ steps.scope.outputs.macos_full }}readme: ${{ steps.filter.outputs.readme || 'false' }}frontend_contracts: ${{ steps.filter.outputs.frontend_contracts || 'false' }}steps:@@ -64,9 +65,8 @@ jobs:readme:- "README*.md"frontend_contracts:- - "src-tauri/src/lib.rs"- - "src-tauri/src/omp_config.rs"- - "src-tauri/src/services/usage_stats.rs"+ # 纯 Rust PR 也检查 CI 路径覆盖,防止新增平台代码后静默漏检。+ - "src-tauri/**/*.rs"backend:- "src-tauri/**"- "tests/config/*.json"@@ -85,6 +85,101 @@ jobs:- "src-tauri/build.rs"- "rust-toolchain.toml"- ".github/workflows/ci.yml"+ # 命中 macOS 专属实现、集成测试或构建/依赖变更时,PR 自动升级为 macOS 全量 Clippy + nextest;+ # 同时下面还会扫描 PR diff 中新增/修改的 target_os = "macos" / objc2,兜底新文件。+ # 未命中时,普通 PR 在 macOS 上仅跑 cargo check --all-targets 守住编译,main/定时/手动或打 full-ci/test:macos 标签时跑全量。+ macos_full:+ - "src-tauri/src/agy_config.rs"+ - "src-tauri/src/auto_launch.rs"+ - "src-tauri/src/claude_desktop_config.rs"+ - "src-tauri/src/commands/agy_account.rs"+ - "src-tauri/src/commands/misc.rs"+ - "src-tauri/src/commands/terminal_launch.rs"+ - "src-tauri/src/commands/tool_*.rs"+ - "src-tauri/src/commands/tool_discovery/**"+ - "src-tauri/src/commands/workbuddy_account.rs"+ - "src-tauri/src/lib.rs"+ - "src-tauri/src/lightweight.rs"+ - "src-tauri/src/macos_tray_window.rs"+ - "src-tauri/src/mode/operation.rs"+ - "src-tauri/src/omp_config.rs"+ - "src-tauri/src/services/*_account/**"+ - "src-tauri/src/services/*_account.rs"+ - "src-tauri/src/services/provider/mod.rs"+ - "src-tauri/src/services/skill_repo_tokens.rs"+ - "src-tauri/src/services/subscription.rs"+ - "src-tauri/src/session_manager/terminal/**"+ - "src-tauri/src/tray*.rs"+ - "src-tauri/src/tray/**"+ - "src-tauri/tests/**"+ - "src-tauri/.config/nextest.toml"+ - "tests/fixtures/**"+ - "src-tauri/Cargo.toml"+ - "src-tauri/Cargo.lock"+ - "src-tauri/build.rs"+ - "rust-toolchain.toml"+ - ".github/workflows/ci.yml"++ # 实时拉取 PR 标签与 diff 中的 macOS 条件编译痕迹:+ # 1. Re-run all jobs 时 github.event.pull_request.labels 是冻结快照,必须走 API 才能读到新打的 full-ci / test:macos 标签;+ # 2. 不把 labeled 加进 on.pull_request.types,避免 labeler.yml 自动打标时误取消正在运行的 CI;+ # 3. 兜底扫描 diff 中的 target_os = "macos" / objc2,即使新文件不在静态列表里也会升级为 macOS 全量。+ - name: Fetch live PR labels and macOS diff guard+ id: pr_meta+ if: github.event_name == 'pull_request'+ shell: bash+ env:+ GH_TOKEN: ${{ github.token }}+ GH_REPO: ${{ github.repository }}+ PR_NUMBER: ${{ github.event.pull_request.number }}+ BACKEND_CHANGED: ${{ steps.filter.outputs.backend }}+ MACOS_FULL_FILTER: ${{ steps.filter.outputs.macos_full }}+ run: |+ set -euo pipefail+ labels=$(gh api "repos/${GH_REPO}/pulls/${PR_NUMBER}" --jq '[.labels[].name] | tojson')+ echo "labels=${labels}" >> "$GITHUB_OUTPUT"++ patch_touches_macos=false+ if [ "$BACKEND_CHANGED" = "true" ] && [ "$MACOS_FULL_FILTER" != "true" ]; then+ # API 失败必须让 job 失败;先完整读取再匹配,避免 grep -q 提前关闭管道造成 SIGPIPE。+ # GitHub 未提供 Rust 文件 patch(例如过大的 diff)时,保守升级为全量。+ patches=$(gh api --paginate "repos/${GH_REPO}/pulls/${PR_NUMBER}/files" \+ --jq '.[] | if (.filename | endswith(".rs")) and .patch == null then "CC_SWITCH_MISSING_RUST_PATCH" else .patch // empty end')+ if grep -qE 'target_os[[:space:]]*=[[:space:]]*"macos"|objc2|CC_SWITCH_MISSING_RUST_PATCH' <<< "$patches"; then+ patch_touches_macos=true+ fi+ fi+ echo "patch_touches_macos=${patch_touches_macos}" >> "$GITHUB_OUTPUT"++ # 在 job 路径门禁之前处理实时标签,backend 和所有 WSL 步骤使用同一份执行范围。+ - name: Resolve backend check scope+ id: scope+ shell: bash+ env:+ EVENT_NAME: ${{ github.event_name }}+ CHANGED_AREAS: ${{ toJSON(steps.filter.outputs) }}+ PR_LABELS: ${{ steps.pr_meta.outputs.labels || '[]' }}+ PATCH_TOUCHES_MACOS: ${{ steps.pr_meta.outputs.patch_touches_macos || 'false' }}+ run: |+ node <<'NODE'+ const fs = require('node:fs');+ const changed = JSON.parse(process.env.CHANGED_AREAS || '{}') || {};+ const labels = JSON.parse(process.env.PR_LABELS || '[]');+ // 定时 / 手动未执行过滤时按全量处理,字符串 'false' 必须保留为 false。+ const matches = area => changed[area] !== 'false';+ const full = labels.includes('full-ci');+ const macos = full || labels.includes('test:macos');+ const windows = full || labels.includes('test:windows');+ const nonPr = process.env.EVENT_NAME !== 'pull_request';+ const scope = {+ backend: matches('backend') || macos || windows,+ macos_full: nonPr || matches('macos_full') || macos || process.env.PATCH_TOUCHES_MACOS === 'true',+ wsl: nonPr || matches('wsl') || windows,+ };+ fs.appendFileSync(process.env.GITHUB_OUTPUT,+ Object.entries(scope).map(([key, value]) => `${key}=${value}\n`).join(''));+ console.log('Backend check scope:', scope);+ NODEfrontend:name: Frontend Checks@@ -218,7 +313,7 @@ jobs:- name: Run README parity testrun: pnpm test:unit --project=node-unisolated tests/config/readmeParity.test.ts- # 只改前端契约测试直接解析的 Rust 源文件时,补跑对应 3 个跨端契约测试,避免静默漂移。+ # 纯 Rust PR 补跑跨端契约和 CI 路径覆盖测试,避免配置与平台代码静默漂移。frontend-contracts:name: Frontend Contract Testsruns-on: ubuntu-latest@@ -240,8 +335,8 @@ jobs:- name: Install dependenciesrun: pnpm install --frozen-lockfile- - name: Run frontend contract tests- run: pnpm test:unit --project=node-unisolated tests/lib/registeredCommands.test.ts tests/config/ompProviderPresets.test.ts tests/components/usageProviderLabel.test.ts+ - name: Run frontend and CI contract tests+ run: pnpm test:unit --project=node-unisolated tests/lib/registeredCommands.test.ts tests/config/ompProviderPresets.test.ts tests/components/usageProviderLabel.test.ts tests/config/ciWorkflow.test.tsbackend:name: Backend Checks@@ -249,11 +344,47 @@ jobs:needs: changesif: needs.changes.outputs.backend == 'true'timeout-minutes: 45+ env:+ # CI 禁用调试信息(与 tauri-apps/tauri 一致):跳过 DWARF 生成以减少编译/链接耗时与 target 缓存体积;+ # 本地开发仍沿用 Cargo.toml 的 line-tables-only。+ CARGO_PROFILE_DEV_DEBUG: 0strategy:fail-fast: falsematrix:- os: [ubuntu-22.04, windows-latest, macos-latest]+ # 显式固定镜像版本(与 release.yml 的 macos-15、wsl2-nightly.yml 的 windows-2025 对齐),+ # 避免 *-latest 静默滚动引入性能或环境回归。+ os: [ubuntu-22.04, windows-2025, macos-15]steps:+ - name: Determine backend check scope+ id: scope+ shell: bash+ env:+ RUNNER_OS: ${{ runner.os }}+ MACOS_FULL: ${{ needs.changes.outputs.macos_full }}+ run: |+ run_clippy=false+ run_tests=false+ run_check_only=false++ if [ "$RUNNER_OS" = "Linux" ] || [ "$RUNNER_OS" = "Windows" ]; then+ run_clippy=true+ run_tests=true+ elif [ "$RUNNER_OS" = "macOS" ]; then+ if [ "$MACOS_FULL" = "true" ]; then+ run_clippy=true+ run_tests=true+ else+ run_check_only=true+ fi+ fi++ {+ echo "run_clippy=$run_clippy"+ echo "run_tests=$run_tests"+ echo "run_check_only=$run_check_only"+ } >> "$GITHUB_OUTPUT"+ echo "Backend check scope ($RUNNER_OS): clippy=$run_clippy tests=$run_tests check_only=$run_check_only"+- name: Checkoutuses: actions/checkout@v6@@ -270,7 +401,7 @@ jobs:uses: dtolnay/rust-toolchain@stablewith:toolchain: ${{ steps.rust-toolchain.outputs.channel }}- components: ${{ runner.os == 'Linux' && 'rustfmt, clippy' || 'clippy' }}+ components: ${{ runner.os == 'Linux' && 'rustfmt, clippy' || (steps.scope.outputs.run_clippy == 'true' && 'clippy' || '') }}# 格式和系统无关,只在 Linux 上查一次;放在装依赖、恢复缓存之前,格式不对几秒就报错- name: Check Rust formatting@@ -282,26 +413,39 @@ jobs:run: |sudo apt-get updatesudo apt-get install -y --no-install-recommends \- build-essential pkg-config libssl-dev \+ build-essential clang lld pkg-config libssl-dev \libgtk-3-dev librsvg2-dev libayatana-appindicator3-devsudo apt-get install -y --no-install-recommends libwebkit2gtk-4.1-dev \|| sudo apt-get install -y --no-install-recommends libwebkit2gtk-4.0-devsudo apt-get install -y --no-install-recommends libsoup-3.0-dev \|| sudo apt-get install -y --no-install-recommends libsoup2.4-dev+ echo "RUSTFLAGS=-C linker=clang -C link-arg=-fuse-ld=lld" >> "$GITHUB_ENV"++ # 一次性 CI 虚拟机上排除 target 与 CARGO_HOME,避免 Defender 实时扫描拖慢缓存解压、编译与 5,000+ 测试进程启动+ - name: Exclude Cargo dirs from Windows Defender+ if: runner.os == 'Windows'+ shell: pwsh+ run: |+ try {+ Add-MpPreference -ExclusionPath "${{ github.workspace }}\src-tauri\target", "$env:USERPROFILE\.cargo"+ } catch {+ Write-Warning "Failed to configure Windows Defender exclusions: $_"+ }# 只缓存依赖:本仓库的 crate 每次都要重编,缓存它只会让缓存变大、恢复变慢。# key 自带 OS、rustc 版本和 Cargo.lock;shared-key 让 wsl2-nightly 能读到 Windows 这份。- # backend-v2:对齐 [profile.dev.package] 优化依赖与 clippy --all-targets 的缓存指纹。- # 只有 main 保存:PR 能读 main 的缓存,PR 自己存的别人读不到,三个系统一份 3 GB 多,+ # backend-v3:对齐 CARGO_PROFILE_DEV_DEBUG=0 与 Linux lld 链接器后的缓存指纹。+ # 只有 main 保存:PR 能读 main 的缓存,PR 自己存的别人读不到,三个系统一份约 3 GB,# 存下来只会把 main 的缓存挤出仓库 10 GB 的配额。- name: Cache Rust dependenciesuses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2with:workspaces: src-tauri -> target- shared-key: backend-v2+ shared-key: backend-v3save-if: ${{ github.ref == 'refs/heads/main' }}- name: Install cargo-nextest+ if: steps.scope.outputs.run_tests == 'true'uses: taiki-e/install-action@e407f7bafb71fd004bc5c2da3032e5470cbb6ef0 # v2.87.24with:tool: cargo-nextest@@ -311,17 +455,31 @@ jobs:run: mkdir -p dist- name: Clippy+ if: steps.scope.outputs.run_clippy == 'true'run: cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings+ # 普通 PR 未命中 macos_full 路径时,在 macOS 上只做全目标类型/条件编译检查,不触发高内存全量代码生成与单测+ - name: Check macOS compilation+ if: steps.scope.outputs.run_check_only == 'true'+ run: cargo check --manifest-path src-tauri/Cargo.toml --all-targets++ # macOS runner 仅 3 vCPU / 7 GB RAM;先单独编 --lib 测试二进制再跑全量,+ # 避免 cc_switch_lib (rlib) 与 cc_switch_lib (--test) 两个 ~400k LOC rustc 进程并发争抢内存触发 swap,+ # 同时在冷缓存时仍保留外部依赖的并发编译能力。+ - name: Prebuild lib tests on macOS (avoid 7 GB RAM swap)+ if: runner.os == 'macOS' && steps.scope.outputs.run_tests == 'true'+ run: cargo nextest run --manifest-path src-tauri/Cargo.toml --profile ci --lib --no-run+# 每个测试一个进程,单测超时见 src-tauri/.config/nextest.toml。doctest 目前只有两个# ignored,nextest 不跑 doctest 也不漏。- name: Run tests+ if: steps.scope.outputs.run_tests == 'true'run: cargo nextest run --manifest-path src-tauri/Cargo.toml --profile ci# WSL2 契约测试并入 Windows backend,直接复用 nextest 刚编好的 cc_switch_lib 测试二进制,- # 省掉独立 Windows VM、缓存恢复和重复编译;PR 仅在命中 wsl 闭包时触发,push/定时/手动必跑。+ # PR 命中 wsl 路径或 full-ci/test:windows 标签时触发,push/定时/手动必跑。- name: Setup WSL2- if: runner.os == 'Windows' && (github.event_name != 'pull_request' || needs.changes.outputs.wsl == 'true')+ if: runner.os == 'Windows' && needs.changes.outputs.wsl == 'true'uses: Vampire/setup-wsl@d1da7f2c0322a5ee4f24975344f67fc0f5baf364 # v7with:distribution: Ubuntu-24.04@@ -332,7 +490,7 @@ jobs:# 直接定位 nextest 已编好的 cc_switch_lib-*.exe,不再调用 cargo test --lib --no-run,# 避免 tauri::generate_context! 共享 OUT_DIR 时间戳触发无谓重编与 UNC TEMP 下的 LNK1327。- name: Prepare WSL2-backed test environment & locate test binary- if: runner.os == 'Windows' && (github.event_name != 'pull_request' || needs.changes.outputs.wsl == 'true')+ if: runner.os == 'Windows' && needs.changes.outputs.wsl == 'true'shell: pwshrun: |$ErrorActionPreference = "Stop"@@ -360,7 +518,7 @@ jobs:"CC_SWITCH_WSL_TEST_TEMP=$testTemp" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append- name: Run Windows-to-WSL2 filesystem contract- if: runner.os == 'Windows' && (github.event_name != 'pull_request' || needs.changes.outputs.wsl == 'true')+ if: runner.os == 'Windows' && needs.changes.outputs.wsl == 'true'# Run the test binary built by nextest directly. Invoking cargo here# with TEMP pointing at a WSL UNC path can re-link the crate, and# link.exe/mt.exe cannot create manifest temp files on \\wsl.localhost.@@ -383,7 +541,7 @@ jobs:}- name: Run Hermes live WAL reads inside WSL2- if: runner.os == 'Windows' && (github.event_name != 'pull_request' || needs.changes.outputs.wsl == 'true')+ if: runner.os == 'Windows' && needs.changes.outputs.wsl == 'true'env:CC_SWITCH_WSL_DISTRO: Ubuntu-24.04shell: pwshdiff --git a/.github/workflows/wsl2-nightly.yml b/.github/workflows/wsl2-nightly.ymlindex 850ea6235..6fcc4b641 100644--- a/.github/workflows/wsl2-nightly.yml+++ b/.github/workflows/wsl2-nightly.yml@@ -30,6 +30,9 @@ jobs:timeout-minutes: 30permissions:contents: read+ env:+ # 与 ci.yml 的 backend-v3 缓存指纹对齐,确保直接复用 Windows 依赖缓存+ CARGO_PROFILE_DEV_DEBUG: 0steps:- name: Checkoutuses: actions/checkout@v6@@ -60,7 +63,7 @@ jobs:uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2with:workspaces: src-tauri -> target- shared-key: backend-v2+ shared-key: backend-v3save-if: false- name: Install cargo-nextestdiff --git a/package.json b/package.jsonindex 505c17fcc..b5cb20cd4 100644--- a/package.json+++ b/package.json@@ -26,6 +26,7 @@"@testing-library/react": "^16.0.1","@testing-library/user-event": "^14.5.2","@types/node": "^20.0.0",+ "@types/picomatch": "^2.3.4","@types/react": "^18.2.0","@types/react-dom": "^18.2.0","@vitejs/plugin-react": "^4.2.0",@@ -35,6 +36,7 @@"jsdom": "^25.0.0","knip": "6.46.1","msw": "^2.11.6",+ "picomatch": "^2.3.1","postcss": "^8.4.49","prettier": "^3.6.2","tailwindcss": "^3.4.17",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex f252f2826..7701bcc69 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -156,6 +156,9 @@ importers:'@types/node':specifier: ^20.0.0version: 20.19.9+ '@types/picomatch':+ specifier: ^2.3.4+ version: 2.3.4'@types/react':specifier: ^18.2.0version: 18.3.23@@ -183,6 +186,9 @@ importers:msw:specifier: ^2.11.6version: 2.11.6(@types/[email protected])([email protected])+ picomatch:+ specifier: ^2.3.1+ version: 2.3.1postcss:specifier: ^8.4.49version: 8.5.6@@ -1780,6 +1786,9 @@ packages:'@types/[email protected]':resolution: {integrity: sha512-cuVNgarYWZqxRJDQHEB58GEONhOK79QVR/qYx4S7kcUObQvUwvFnYxJuuHUKm2aieN9X3yZB4LZsuYNU1Qphsw==}+ '@types/[email protected]':+ resolution: {integrity: sha512-0so8lU8O5zatZS/2Fi4zrwks+vZv7e0dygrgEZXljODXBig97l4cPQD+9LabXfGJOWwoRkTVz6Q4edZvD12UOA==}+'@types/[email protected]':resolution: {integrity: sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==}@@ -4709,6 +4718,8 @@ snapshots:dependencies:undici-types: 6.21.0+ '@types/[email protected]': {}+'@types/[email protected]': {}'@types/[email protected](@types/[email protected])':diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.tomlindex 413e7d506..99d36eecc 100644--- a/src-tauri/Cargo.toml+++ b/src-tauri/Cargo.toml@@ -133,9 +133,10 @@ block2 = "0.6"objc2-foundation = { version = "0.3", default-features = false, features = ["std", "NSArray", "NSGeometry", "NSNotification", "NSOperation", "NSString", "block2"] }objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSAppearance", "NSGlassEffectView", "NSGraphics", "NSResponder", "NSScreen", "NSView", "NSVisualEffectView", "NSWindow"] }-# 本地 `cargo test` / `tauri dev` 和 CI 用同一份调试信息级别:只留行号表。-# panic 和回溯照样有文件名与行号;完整调试信息(变量、类型)占测试二进制体积的九成,-# 还拖慢编译和链接。要用调试器看变量时临时设 `CARGO_PROFILE_DEV_DEBUG=full`。+# 本地 `cargo test` / `tauri dev` 只留行号表:panic 和回溯照样有文件名与行号,+# 完整调试信息(变量、类型)占测试二进制体积的九成,还拖慢编译和链接。+# CI 通过 `CARGO_PROFILE_DEV_DEBUG=0` 进一步关闭行号表以压缩编译耗时与缓存体积;+# 本地要用调试器看变量时临时设 `CARGO_PROFILE_DEV_DEBUG=full`。[profile.dev]debug = "line-tables-only"diff --git a/tests/config/ciWorkflow.test.ts b/tests/config/ciWorkflow.test.tsnew file mode 100644index 000000000..1f4f80eba--- /dev/null+++ b/tests/config/ciWorkflow.test.ts@@ -0,0 +1,349 @@+import { execFileSync } from "node:child_process";+import { mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs";+import { tmpdir } from "node:os";+import path from "node:path";+import picomatch from "picomatch";+import { describe, expect, it } from "vitest";+import { parse } from "yaml";++interface Step {+ id?: string;+ name: string;+ run: string;+ if?: string;+ env?: Record<string, string>;+ with: Record<string, string>;+}++const root = path.resolve(__dirname, "../..");+const workflow = parse(+ readFileSync(path.join(root, ".github/workflows/ci.yml"), "utf8"),+) as {+ on: { pull_request: { types?: string[] } };+ jobs: {+ changes: { outputs: Record<string, string>; steps: Step[] };+ backend: { if: string; steps: Step[] };+ "frontend-contracts": { if: string; steps: Step[] };+ };+};+const filterStep = workflow.jobs.changes.steps.find((s) => s.id === "filter")!;+const filters = parse(filterStep.with.filters) as Record<string, string[]>;+const scopeStep = workflow.jobs.changes.steps.find((s) => s.id === "scope")!;+const metadataStep = workflow.jobs.changes.steps.find(+ (s) => s.id === "pr_meta",+)!;+const commandStep = workflow.jobs.backend.steps.find((s) => s.id === "scope")!;++// Exercise the workflow's scripts and the same matcher as dorny/paths-filter.+// No copied scope implementation: these cases also cover job/step gate wiring.+function executeStep(step: Step, env: Record<string, string>, prefix = "") {+ const dir = mkdtempSync(path.join(tmpdir(), "cc-switch-ci-scope-"));+ const output = path.join(dir, "outputs");+ try {+ execFileSync("bash", ["-e", "-c", `${prefix}\n${step.run}`], {+ cwd: root,+ env: { ...process.env, ...env, GITHUB_OUTPUT: output },+ stdio: "pipe",+ });+ return Object.fromEntries(+ readFileSync(output, "utf8")+ .trim()+ .split("\n")+ .map((line) => {+ const separator = line.indexOf("=");+ return [line.slice(0, separator), line.slice(separator + 1)];+ }),+ ) as Record<string, string>;+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+}++function runStep(step: Step, env: Record<string, string>) {+ return Object.fromEntries(+ Object.entries(executeStep(step, env)).map(([key, value]) => [+ key,+ value === "true",+ ]),+ );+}++function metadataFor(patches: string, env: Record<string, string> = {}) {+ return executeStep(+ metadataStep,+ {+ GH_REPO: "example/repo",+ PR_NUMBER: "1",+ BACKEND_CHANGED: "true",+ MACOS_FULL_FILTER: "false",+ MOCK_LABELS: '["full-ci"]',+ MOCK_PATCHES: patches,+ MOCK_LABEL_STATUS: "0",+ MOCK_PATCH_STATUS: "0",+ ...env,+ },+ `gh() {+ case "$*" in+ *"/files"*) printf '%s\\n' "$MOCK_PATCHES"; return "$MOCK_PATCH_STATUS" ;;+ *) printf '%s\\n' "$MOCK_LABELS"; return "$MOCK_LABEL_STATUS" ;;+ esac+ }`,+ );+}++function scopeFor(+ files: string[],+ labels: string[] = [],+ event = "pull_request",+ patchTouchesMacos = false,+) {+ const changed = ["pull_request", "push"].includes(event)+ ? Object.fromEntries(+ Object.entries(filters).map(([area, patterns]) => [+ area,+ String(files.some(picomatch(patterns, { dot: true }))),+ ]),+ )+ : {};+ return runStep(scopeStep, {+ EVENT_NAME: event,+ CHANGED_AREAS: JSON.stringify(changed),+ PR_LABELS: JSON.stringify(labels),+ PATCH_TOUCHES_MACOS: String(patchTouchesMacos),+ });+}++function commandsFor(scope: Record<string, boolean>, os: string) {+ return runStep(commandStep, {+ RUNNER_OS: os,+ MACOS_FULL: String(scope.macos_full),+ });+}++const ordinaryBackend = ["src-tauri/src/proxy/thinking_optimizer.rs"];+const fullScope = {+ backend: true,+ macos_full: true,+ wsl: true,+};++describe("CI backend scope", () => {+ it("uses live labels before path gating without adding labeler-triggered runs", () => {+ expect(metadataStep.if).toBe("github.event_name == 'pull_request'");+ expect(scopeStep.env?.PR_LABELS).toBe(+ "${{ steps.pr_meta.outputs.labels || '[]' }}",+ );+ expect(workflow.on.pull_request.types ?? []).not.toContain("labeled");+ const metadata = metadataFor("", {+ BACKEND_CHANGED: "false",+ MOCK_PATCH_STATUS: "1",+ });+ expect(scopeFor(["src/App.tsx"], JSON.parse(metadata.labels))).toEqual(+ fullScope,+ );+ });++ it("keeps ordinary backend PRs on the lighter platform checks", () => {+ const scope = scopeFor(ordinaryBackend);+ expect(scope).toEqual({+ backend: true,+ macos_full: false,+ wsl: false,+ });+ expect(commandsFor(scope, "Linux")).toEqual({+ run_clippy: true,+ run_tests: true,+ run_check_only: false,+ });+ expect(commandsFor(scope, "Windows")).toEqual({+ run_clippy: true,+ run_tests: true,+ run_check_only: false,+ });+ expect(commandsFor(scope, "macOS")).toEqual({+ run_clippy: false,+ run_tests: false,+ run_check_only: true,+ });+ });++ it.each([+ "src-tauri/src/lib.rs",+ "src-tauri/src/claude_desktop_config.rs",+ "src-tauri/src/services/dsh_account.rs",+ "src-tauri/tests/integration/profile_roundtrip.rs",+ "src-tauri/.config/nextest.toml",+ "src-tauri/Cargo.toml",+ "src-tauri/Cargo.lock",+ "src-tauri/build.rs",+ "rust-toolchain.toml",+ ".github/workflows/ci.yml",+ ])("upgrades platform checks for %s", (file) => {+ const scope = scopeFor([file]);+ expect(scope.backend).toBe(true);+ for (const os of ["macOS", "Windows"]) {+ expect(commandsFor(scope, os), os).toEqual({+ run_clippy: true,+ run_tests: true,+ run_check_only: false,+ });+ }+ });++ it.each([ordinaryBackend, ["src/App.tsx"], ["README.md"]])(+ "full-ci overrides path filtering for %j, including WSL",+ (...files) => {+ expect(scopeFor(files, ["full-ci"])).toEqual(fullScope);+ },+ );++ it.each([+ ["test:macos", true, false],+ ["test:windows", false, true],+ ] as const)(+ "%s can enable backend checks on a frontend-only PR",+ (label, macos, wsl) => {+ expect(scopeFor(["src/App.tsx"], [label])).toEqual({+ backend: true,+ macos_full: macos,+ wsl,+ });+ },+ );++ it("returns to path filtering after removing a label", () => {+ expect(scopeFor(["src/App.tsx"], ["full-ci"])).toEqual(fullScope);+ expect(scopeFor(["src/App.tsx"])).toEqual({+ backend: false,+ macos_full: false,+ wsl: false,+ });+ expect(scopeFor(ordinaryBackend, ["bug,full-ci"]).macos_full).toBe(false);+ });++ it.each(["push", "schedule", "workflow_dispatch"])(+ "%s runs all backend platform checks",+ (event) => {+ expect(scopeFor(ordinaryBackend, [], event)).toEqual(fullScope);+ },+ );++ it("still skips backend on a main push with no backend changes", () => {+ expect(scopeFor(["README.md"], [], "push").backend).toBe(false);+ });++ it("uses the resolved scope for the backend job and every WSL step", () => {+ for (const area of Object.keys(fullScope)) {+ expect(workflow.jobs.changes.outputs[area]).toBe(+ `\${{ steps.scope.outputs.${area} }}`,+ );+ }+ expect(workflow.jobs.backend.if).toBe(+ "needs.changes.outputs.backend == 'true'",+ );+ const wslSteps = workflow.jobs.backend.steps.filter((s) =>+ s.name.includes("WSL2"),+ );+ expect(wslSteps).toHaveLength(4);+ for (const step of wslSteps) {+ expect(step.if, step.name).toBe(+ "runner.os == 'Windows' && needs.changes.outputs.wsl == 'true'",+ );+ }+ });+});++describe("live PR metadata and macOS diff guard", () => {+ it("upgrades new macOS code outside the static path list", () => {+ const metadata = metadataFor('+#[cfg(target_os = "macos")]');+ expect(metadata.patch_touches_macos).toBe("true");+ const scope = scopeFor(+ ordinaryBackend,+ [],+ "pull_request",+ metadata.patch_touches_macos === "true",+ );+ expect(commandsFor(scope, "macOS").run_tests).toBe(true);+ });++ it("consumes a large diff without a grep SIGPIPE false negative", () => {+ expect(+ metadataFor(+ `+use objc2::rc::Retained;\n${"+ordinary change\n".repeat(6000)}`,+ ).patch_touches_macos,+ ).toBe("true");+ });++ it("keeps unrelated backend diffs on the lightweight macOS check", () => {+ expect(metadataFor("+ordinary change").patch_touches_macos).toBe("false");+ });++ it("upgrades when GitHub cannot provide a Rust patch", () => {+ expect(+ metadataFor("CC_SWITCH_MISSING_RUST_PATCH").patch_touches_macos,+ ).toBe("true");+ });++ it.each(["MOCK_LABEL_STATUS", "MOCK_PATCH_STATUS"])(+ "fails instead of silently downgrading when %s is nonzero",+ (key) => {+ expect(() => metadataFor("", { [key]: "1" })).toThrow();+ },+ );++ it("does not fetch a diff when static paths already require full macOS checks", () => {+ expect(+ metadataFor("", { MACOS_FULL_FILTER: "true", MOCK_PATCH_STATUS: "1" })+ .patch_touches_macos,+ ).toBe("false");+ });+});++function rustFiles(dir: string): string[] {+ return readdirSync(path.join(root, dir), { withFileTypes: true }).flatMap(+ (entry) => {+ const file = `${dir}/${entry.name}`;+ return entry.isDirectory()+ ? rustFiles(file)+ : file.endsWith(".rs")+ ? [file]+ : [];+ },+ );+}++describe("CI platform path coverage", () => {+ const sources = [+ ...rustFiles("src-tauri/src"),+ ...rustFiles("src-tauri/tests"),+ ].map((file) => ({+ file,+ source: readFileSync(path.join(root, file), "utf8"),+ }));++ it("runs the coverage check for Rust-only PRs, including new modules", () => {+ const matches = picomatch(filters.frontend_contracts, { dot: true });+ expect(matches("src-tauri/src/new_platform_module.rs")).toBe(true);+ expect(sources.filter(({ file }) => !matches(file))).toEqual([]);+ const job = workflow.jobs["frontend-contracts"];+ expect(job.if).toBe(+ "needs.changes.outputs.frontend_contracts == 'true' && needs.changes.outputs.frontend != 'true'",+ );+ expect(+ job.steps.some((step) =>+ step.run?.includes("tests/config/ciWorkflow.test.ts"),+ ),+ ).toBe(true);+ });++ it("covers existing macOS code even when a diff does not include its cfg", () => {+ const matches = picomatch(filters.macos_full, { dot: true });+ const platform =+ /target_os\s*=\s*"macos"|target_vendor\s*=\s*"apple"|std::os::macos/;+ const uncovered = sources+ .filter(({ source }) => platform.test(source))+ .map(({ file }) => file)+ .filter((file) => !matches(file));+ expect(uncovered).toEqual([]);+ });+});diff --git a/vitest.workspace.ts b/vitest.workspace.tsindex 44e486af8..6e720dc4d 100644--- a/vitest.workspace.ts+++ b/vitest.workspace.ts@@ -65,6 +65,7 @@ const NODE_UNISOLATED_INCLUDE = ["tests/config/appConfig.test.tsx","tests/config/appSpecs.test.ts","tests/config/backendConstants.test.ts",+ "tests/config/ciWorkflow.test.ts","tests/config/claudeDesktopProviderPresets.test.ts","tests/config/claudePresetKeyFields.test.ts","tests/config/claudeProviderPresets.test.ts",