Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

ci: 并行拆分 Linux 单元测试 (#2177)

fmfsaisai28ad06d094cb
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b1f763ac32..3c267f5c9a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -24,7 +24,9 @@ env:
NODE_OPTIONS: '--max-old-space-size=8192'
jobs:
- verify:
+ # 静态检查、类型检查和 runner 自测与 Linux 单测分片并行。这里不装
+ # bundled ripgrep;它只在 Desktop 单测收集时需要,由单测分片自行安装。
+ verify-checks:
runs-on: ubuntu-latest
timeout-minutes: 40
@@ -53,7 +55,7 @@ jobs:
fi
echo "cindy-protocol submodule 来源校验通过: $actual_url"
- # 本 job 只做本仓 typecheck / 单测 / 各类 guard。cindy-protocol 是公开的
+ # 本 job 只做本仓 typecheck / runner 自测 / 各类 guard。cindy-protocol 是公开的
# workspace 依赖,需要 checkout 以供 pnpm install 解析,但不在本 job 运行
# 协议仓自己的 CI。
# 公开客户端不包含内建插件种子;相关单测只在 os.tmpdir 里自造夹具。
@@ -90,14 +92,10 @@ jobs:
- name: Build model-access protocol
run: pnpm --filter @cindy/model-access-protocol build
- # XDT_SKIP_AGENT_BIN_INSTALL 跳过了 postinstall 的全部 agent 二进制,但
- # runtime-configs.ts 模块顶层的 bundledRipgrepDir() 缺 rg 时直接 throw,
- # 会让 apps/desktop 单测在收集阶段全挂——ripgrep 必须单独装回来。
- # install:ripgrep 不带 --best-effort,不受上面的 skip 环境变量影响。
- - name: Install bundled ripgrep
- env:
- GITHUB_TOKEN: ${{ github.token }}
- run: pnpm install:ripgrep
+ # test:unit 的 runner 自测不能跟着 Vitest 分片重复执行;在检查 job 中跑一次,
+ # 两个 Linux 单测分片只负责 workspace unit tier。
+ - name: Run test runner self-tests
+ run: pnpm test:runner
- name: Check endpoint literals
run: pnpm check:endpoints
@@ -132,15 +130,106 @@ jobs:
XDT_MIGRATION_BASE_REF: ${{ github.event.pull_request.base.sha || github.event.before || 'origin/main' }}
run: pnpm --filter desktop db:validate
- - name: Run client and package unit tests
- run: pnpm test:unit
-
- name: Run scheduler architecture guard
run: pnpm ci:scheduler-guard
- name: Run mobile scope guard
run: pnpm --filter mobile test:scope
+ # Linux 单测使用与 Windows 相同的确定性 Vitest 分片。两个分片分别覆盖每个
+ # workspace 经 Vitest 切分后的测试文件,并集等于完整 unit tier;不重复 test:runner。
+ linux-unit-shards:
+ name: Linux unit tests (${{ matrix.shard }}/2)
+ runs-on: ubuntu-latest
+ timeout-minutes: 40
+ strategy:
+ fail-fast: false
+ matrix:
+ shard: [1, 2]
+ env:
+ XDT_UNIT_TEST_SHARD: ${{ matrix.shard }}/2
+
+ steps:
+ - name: Checkout client
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ fetch-depth: 0
+ lfs: true
+
+ - name: Verify cindy-protocol submodule source
+ run: |
+ set -euo pipefail
+ expected_url='https://github.com/makecindy/cindy-protocol.git'
+ expected_path='cindy-protocol'
+ actual_url="$(git config -f .gitmodules --get submodule.cindy-protocol.url || true)"
+ actual_path="$(git config -f .gitmodules --get submodule.cindy-protocol.path || true)"
+ if [ "$actual_url" != "$expected_url" ] || [ "$actual_path" != "$expected_path" ]; then
+ echo "::error file=.gitmodules::cindy-protocol source mismatch: url='$actual_url' path='$actual_path' (expected url='$expected_url' path='$expected_path')"
+ exit 1
+ fi
+ echo "cindy-protocol submodule source verified: $actual_url"
+
+ - name: Fetch cindy-protocol submodule
+ run: |
+ git submodule sync -- cindy-protocol
+ git submodule update --init --force --recursive -- cindy-protocol
+
+ # 分片会安装并执行 submodule 代码,不能只依赖并行的 verify-checks 最终阻断;
+ # 每个分片都必须在安装依赖前独立拒绝回滚、分叉或未发布的 gitlink。
+ - name: Reject cindy-protocol rollback or divergence
+ if: ${{ github.event_name == 'pull_request' }}
+ env:
+ CINDY_PROTOCOL_BASE_REF: ${{ github.event.pull_request.base.sha }}
+ run: node scripts/check-submodule-forward.mjs
+
+ - name: Setup pnpm
+ uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6
+ with:
+ run_install: false
+
+ - name: Setup Node.js
+ uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
+ with:
+ node-version: 22
+ cache: pnpm
+ cache-dependency-path: pnpm-lock.yaml
+
+ - name: Install dependencies
+ run: pnpm install --frozen-lockfile
+
+ - name: Build model-access protocol
+ run: pnpm --filter @cindy/model-access-protocol build
+
+ # XDT_SKIP_AGENT_BIN_INSTALL 跳过了 postinstall 的全部 agent 二进制,但
+ # runtime-configs.ts 模块顶层的 bundledRipgrepDir() 缺 rg 时直接 throw,
+ # 会让 apps/desktop 单测在收集阶段全挂——每个分片都必须单独装回来。
+ - name: Install bundled ripgrep
+ env:
+ GITHUB_TOKEN: ${{ github.token }}
+ run: pnpm install:ripgrep
+
+ - name: Run client and package unit test shard
+ # 通过 pnpm 启动 runner,保留当前 pnpm 入口;否则嵌套的 protocol
+ # workspace 无法从主仓根 node_modules 解析 Vitest。
+ run: pnpm exec node scripts/test-workspaces.mjs --tier unit
+
+ # 保留原 required check 名 verify;检查 job 或任一 Linux 分片失败、取消都阻断。
+ verify:
+ name: verify
+ if: ${{ always() }}
+ needs:
+ - verify-checks
+ - linux-unit-shards
+ runs-on: ubuntu-latest
+ steps:
+ - name: Require checks and both Linux unit shards
+ env:
+ VERIFY_CHECKS_RESULT: ${{ needs.verify-checks.result }}
+ LINUX_UNIT_SHARDS_RESULT: ${{ needs.linux-unit-shards.result }}
+ run: |
+ test "$VERIFY_CHECKS_RESULT" = "success"
+ test "$LINUX_UNIT_SHARDS_RESULT" = "success"
+
# Linux 全绿不能覆盖 path separator、盘符、大小写和文件系统能力差异。两个
# Windows 分片并行运行,分片并集仍完整覆盖 test:unit,不能缩成少量 smoke。
windows-unit-shards:
diff --git a/scripts/__tests__/dev-docs-contract.test.mjs b/scripts/__tests__/dev-docs-contract.test.mjs
index 1ab7bfd08f..0efc49018f 100644
--- a/scripts/__tests__/dev-docs-contract.test.mjs
+++ b/scripts/__tests__/dev-docs-contract.test.mjs
@@ -198,3 +198,37 @@ test("client CI keeps the complete two-shard unit gate on Windows", () => {
assert.match(gate, /^ WINDOWS_UNIT_SHARDS_RESULT: \$\{\{ needs\.windows-unit-shards\.result \}\}$/m);
assert.match(gate, /^ run: test "\$WINDOWS_UNIT_SHARDS_RESULT" = "success"$/m);
});
+
+test("client CI runs Linux checks and complete unit shards in parallel behind stable verify", () => {
+ const workflow = readText(".github/workflows/ci.yml");
+ const checks = workflowJob(workflow, "verify-checks");
+ assert.ok(checks, "client CI must define independent Linux verification checks");
+ assert.doesNotMatch(checks, /^ needs:/m);
+ assert.match(checks, /^ run: pnpm test:runner$/m);
+ assert.doesNotMatch(checks, /node scripts\/test-workspaces\.mjs --tier unit/);
+
+ const shards = workflowJob(workflow, "linux-unit-shards");
+ assert.ok(shards, "client CI must define Linux unit shards");
+ assert.match(shards, /^ runs-on: ubuntu-latest$/m);
+ assert.doesNotMatch(shards, /^ needs:/m);
+ assert.match(shards, /^ fail-fast: false$/m);
+ assert.match(shards, /^ shard: \[1, 2\]$/m);
+ assert.match(shards, /^ XDT_UNIT_TEST_SHARD: \$\{\{ matrix\.shard \}\}\/2$/m);
+ assert.match(shards, /^ - name: Reject cindy-protocol rollback or divergence$/m);
+ assert.match(shards, /^ if: \$\{\{ github\.event_name == 'pull_request' \}\}$/m);
+ assert.match(shards, /^ CINDY_PROTOCOL_BASE_REF: \$\{\{ github\.event\.pull_request\.base\.sha \}\}$/m);
+ assert.match(shards, /^ run: node scripts\/check-submodule-forward\.mjs$/m);
+ assert.match(shards, /^ run: pnpm exec node scripts\/test-workspaces\.mjs --tier unit$/m);
+ assert.doesNotMatch(shards, /pnpm test:(?:unit|runner)/);
+
+ const gate = workflowJob(workflow, "verify");
+ assert.ok(gate, "client CI must preserve the stable verify check");
+ assert.match(gate, /^ name: verify$/m);
+ assert.match(gate, /^ if: \$\{\{ always\(\) \}\}$/m);
+ assert.match(gate, /^ - verify-checks$/m);
+ assert.match(gate, /^ - linux-unit-shards$/m);
+ assert.match(gate, /^ VERIFY_CHECKS_RESULT: \$\{\{ needs\.verify-checks\.result \}\}$/m);
+ assert.match(gate, /^ LINUX_UNIT_SHARDS_RESULT: \$\{\{ needs\.linux-unit-shards\.result \}\}$/m);
+ assert.match(gate, /^ test "\$VERIFY_CHECKS_RESULT" = "success"$/m);
+ assert.match(gate, /^ test "\$LINUX_UNIT_SHARDS_RESULT" = "success"$/m);
+});
diff --git a/scripts/__tests__/test-workspaces.test.mjs b/scripts/__tests__/test-workspaces.test.mjs
index 9eb3c41ca6..f357e13177 100644
--- a/scripts/__tests__/test-workspaces.test.mjs
+++ b/scripts/__tests__/test-workspaces.test.mjs
@@ -124,10 +124,15 @@ test("client CI builds model-access protocol before consumer checks", () => {
).replace(/\r\n/g, "\n");
const jobs = [
{
- name: "verify",
- body: workflow.match(/\n verify:\n([\s\S]*?)\n windows-unit-shards:/)?.[1],
+ name: "verify-checks",
+ body: workflow.match(/\n verify-checks:\n([\s\S]*?)\n linux-unit-shards:/)?.[1],
consumerCommand: "run: pnpm --filter desktop typecheck",
},
+ {
+ name: "linux-unit-shards",
+ body: workflow.match(/\n linux-unit-shards:\n([\s\S]*?)\n verify:/)?.[1],
+ consumerCommand: "run: pnpm exec node scripts/test-workspaces.mjs --tier unit",
+ },
{
name: "windows-unit-shards",
body: workflow.match(/\n windows-unit-shards:\n([\s\S]*?)\n windows-unit:/)?.[1],
@@ -151,6 +156,21 @@ test("client CI builds model-access protocol before consumer checks", () => {
}
});
+test("Linux unit shards reject unsafe protocol gitlinks before installing dependencies", () => {
+ const workflow = fs.readFileSync(
+ path.join(ROOT, ".github", "workflows", "ci.yml"),
+ "utf8",
+ ).replace(/\r\n/g, "\n");
+ const body = workflow.match(/\n linux-unit-shards:\n([\s\S]*?)\n verify:/)?.[1];
+ assert.ok(body, "client CI must define Linux unit shards");
+ const fetchIndex = body.indexOf("git submodule update --init --force --recursive -- cindy-protocol");
+ const guardIndex = body.indexOf("run: node scripts/check-submodule-forward.mjs");
+ const installIndex = body.indexOf("run: pnpm install --frozen-lockfile");
+ assert.ok(fetchIndex >= 0, "Linux unit shards must fetch cindy-protocol");
+ assert.ok(guardIndex > fetchIndex, "Linux unit shards must validate the fetched protocol gitlink");
+ assert.ok(installIndex > guardIndex, "Linux unit shards must reject unsafe gitlinks before install");
+});
+
test("help groups copyable desktop, binary, and Mobile workflows", async () => {
const { printHelp } = await import("../help.mjs");
const lines = [];