AGC 壳 Rust 套件改为「一片一个 job」,客户端 Rust 关键路径压到 7 分钟以内
Project CI / AI game creator shell Rust shard 2/4 (push) Successful in 3m53s
Project CI / AI game creator shell Rust shard 1/4 (push) Successful in 4m11s
Project CI / AI game creator shell Rust shard 3/4 (push) Successful in 4m6s
Project CI / AI game creator shell Rust shard 4/4 (push) Successful in 4m2s
Project CI / AI game creator shell Rust smoke (push) Successful in 1m26s
Project CI / AI game creator shell Rust crates (push) Successful in 2m21s
Project CI / Backend tests (push) Successful in 6m22s
Project CI / Native shell tests (push) Successful in 5m25s
Project CI / Repository checks (push) Successful in 2m17s
Project CI / Frontend tests (push) Successful in 2m58s
Project CI / AI game creator shell web tests (push) Successful in 2m6s

上一轮把 2466 条 bin target 单测切成 4 片放在同一个 job 内多进程并行,run 2102 证明这条路
不通:门禁步骤跑满 18 分钟仍未结束,比整套串行的 507 秒还慢——同一容器内这几片共享
HOME、target 目录与固定临时路径,会互相拖慢。这一轮改成按 job 拆分。

- run-rust-shell-test-shards.mjs 新增 --shard-index=<i>:只跑第 i 片,供 CI 的每个分片 job
  使用;覆盖自校验(片并集等于 --list 全集且互斥)仍针对全集执行,所以每个 job 都会
  发现分片规则改动,不会被"只跑一片"绕过。负例 --shard-index 超出 --shards 立即失败。
  不传 --shard-index 时行为不变(一条命令把 N 片放进程里并行),留给本地全量自测。
- project-ci.yml 由 7 个 job 变 11 个:原 AGC Rust job 拆成 AI game creator shell Rust
  shard 1/4 ~ 4/4 与 AI game creator shell Rust smoke,加上已有的 Rust crates,AGC 相关
  门禁共 6 个 job。4 个片 job 只预热 AGC 壳自己那份锁定依赖,且与 smoke、crates 一样都是
  纯 cargo 门禁,因此这 6 个 job 都不再执行 npm ci(每个省 1~3 分钟)。
- check-native-shells.mjs 分组由五个变十个:agc-rust-shard-1 ~ agc-rust-shard-4 与
  agc-rust-smoke 取代 agc-rust-shell;每个分片分组的命令是
  `npm run ai-game-creator-shell:check:rust:shell -- --shard-index=<i>`。
- project-ci-workflow.test.ts 相应更新:11 个 job、6 个 job 免 npm ci、10 个分组各被一个
  job 恰好调用一次,并新增「每个分片 job 都落到 --shard-index」「4 个 index 各一次」
  「分片运行器保留覆盖自校验」等断言。
- 同步运维文档、development-workflow、decision-log、pitfalls 与 gitea-ci-triage 技能到
  job 级分片口径,并记录 run 2102 的反面实验,避免以后又改回单 job 内并行。

验证:npx vitest run scripts/project-ci-workflow.test.ts(12 passed)、eslint、prettier、
check:encoding(13330 文件)、check:doc-index、--groups=contract、mobile check-config 全绿;
分片运行器本地以 agent-runtime-core(7 条 → 2/2/2/1)验证 --shard-index 四个 index 各自
只跑一片、片 TMPDIR 隔离、无 index 时全量模式不变。Gitea master 分支保护需补 6 个新
context(共十一个),其中含 4 个分片 job、smoke job 与 crates job。

Co-authored-by: DotCraft <273930855+dotcraft-ai@users.noreply.github.com>
This commit is contained in:
2026-09-14 17:32:06 +08:00
parent 86b830cf2d
commit 2566ae705f
9 changed files with 354 additions and 90 deletions
+57 -13
View File
@@ -87,16 +87,22 @@ const aiGameCreatorViteConfigSource = fs.readFileSync(
// - agc-web:AI 游戏创作壳的前端门禁(typecheck 与壳内测试,不触碰 Cargo)。
// - agc-rust-crates:AGC 壳依赖的共享 / 平台 crate 测试(server-rs workspace 加两个
// 无锁独立 crate),只需 server-rs 侧的依赖预热。
// - agc-rust-shell:AGC 壳自身的 Rust 门禁(bin target 单测按名单分片并行、片内保持
// `--test-threads=1`)与会用 `src-tauri/Cargo.toml` spawn `cargo run` 的 agent-run
// smoke,只需 AGC 壳自己的依赖预热。
// - agc-rust-shard-1..4:AGC 壳自身的 Rust bin target 单测,按名单切成 4 片,一片一个
// 分组(CI 里就是一个 job),片内仍保持 `--test-threads=1`;每个分片分组都会做一次
// 「片并集等于全集且互斥」的自校验。
// - agc-rust-smoke:会用 `src-tauri/Cargo.toml` spawn `cargo run` 的 agent-run smoke。
// 与分片分开,免得把已经压到 4 分钟级的片 job 拖长。
// - release:发布构建 smoke 和依赖发布产物的落盘断言。
const nativeShellGateGroups = [
'contract',
'shells',
'agc-web',
'agc-rust-crates',
'agc-rust-shell',
'agc-rust-shard-1',
'agc-rust-shard-2',
'agc-rust-shard-3',
'agc-rust-shard-4',
'agc-rust-smoke',
'release',
];
const requestedNativeShellGroups = readRequestedNativeShellGroups(
@@ -2314,9 +2320,9 @@ const steps = [
},
// AI 游戏创作壳原先一步串完 typecheck、壳内测试、共享 / 平台 crate 测试和
// 串行壳测试,CI 因此只有一条 10 分钟以上的长尾。这里按同一组命令切成
// web、rust-crates、rust-shell 三段,顺序与 `npm run ai-game-creator-shell:check`
// 完全一致,但允许 CI 把三段放进不同的 job 并行执行;本地全量运行仍然是
// web -> rust(crates -> shell) -> smoke 原顺序。
// web、rust-crates、rust 分片、smoke 四段,整体顺序与 `npm run ai-game-creator-shell:check`
// 完全一致;CI 把每段(以及每个 rust 分片)放进不同 job 并行执行,本地全量运行仍然是
// web -> rust(crates -> shards) -> smoke 原顺序。
{
group: 'agc-web',
label: 'ai-game-creator-shell-check-web',
@@ -2330,15 +2336,53 @@ const steps = [
args: ['run', 'ai-game-creator-shell:check:rust:crates'],
},
{
group: 'agc-rust-shell',
label: 'ai-game-creator-shell-check-rust-shell',
group: 'agc-rust-shard-1',
label: 'ai-game-creator-shell-check-rust-shard-1',
command: npmCommand,
args: ['run', 'ai-game-creator-shell:check:rust:shell'],
args: [
'run',
'ai-game-creator-shell:check:rust:shell',
'--',
'--shard-index=1',
],
},
// agent-run smoke 会用 `src-tauri/Cargo.toml` spawn `cargo run`,因此与壳测试同组,
// 保证它落在已经预热 AGC 壳 Cargo 依赖的 job 里。
{
group: 'agc-rust-shell',
group: 'agc-rust-shard-2',
label: 'ai-game-creator-shell-check-rust-shard-2',
command: npmCommand,
args: [
'run',
'ai-game-creator-shell:check:rust:shell',
'--',
'--shard-index=2',
],
},
{
group: 'agc-rust-shard-3',
label: 'ai-game-creator-shell-check-rust-shard-3',
command: npmCommand,
args: [
'run',
'ai-game-creator-shell:check:rust:shell',
'--',
'--shard-index=3',
],
},
{
group: 'agc-rust-shard-4',
label: 'ai-game-creator-shell-check-rust-shard-4',
command: npmCommand,
args: [
'run',
'ai-game-creator-shell:check:rust:shell',
'--',
'--shard-index=4',
],
},
// agent-run smoke 会用 `src-tauri/Cargo.toml` spawn `cargo run`,因此单独一个分组,
// 落在同样预热了 AGC 壳 Cargo 依赖的 job 里。
{
group: 'agc-rust-smoke',
label: 'ai-game-creator-shell-agent-run-smoke',
command: npmCommand,
args: ['run', 'ai-game-creator-shell:agent-run:smoke'],
+57 -16
View File
@@ -41,16 +41,24 @@ const jobNames = [
'backend-tests',
'native-shell-tests',
'ai-game-creator-shell-web-tests',
'ai-game-creator-shell-rust-tests',
'ai-game-creator-shell-rust-shard-1',
'ai-game-creator-shell-rust-shard-2',
'ai-game-creator-shell-rust-shard-3',
'ai-game-creator-shell-rust-shard-4',
'ai-game-creator-shell-rust-smoke',
'ai-game-creator-shell-rust-crates',
] as const;
// 这两个 job 是纯 cargo 门禁:AGC 壳的 Rust 套件与 agent-run smoke 只用 cargo 与
// 这几个 job 是纯 cargo 门禁:AGC 壳的 Rust 分片与 agent-run smoke 只用 cargo 与
// node 内建模块(smoke 脚本只 import `node:*`),crate 级测试只跑 cargo 命令,
// 都不需要 node_modules。省掉两份 `npm ci`(各 1~3 分钟)是把客户端 Rust 关键路径
// 都不需要 node_modules。省掉这些 `npm ci`(各 1~3 分钟)是把客户端 Rust 关键路径
// 压到 7 分钟以内的前提,因此这里显式允许它们不装 npm 依赖。
const jobsWithoutNpmInstall: readonly string[] = [
'ai-game-creator-shell-rust-tests',
'ai-game-creator-shell-rust-shard-1',
'ai-game-creator-shell-rust-shard-2',
'ai-game-creator-shell-rust-shard-3',
'ai-game-creator-shell-rust-shard-4',
'ai-game-creator-shell-rust-smoke',
'ai-game-creator-shell-rust-crates',
];
@@ -69,7 +77,11 @@ const nativeShellGateGroupScripts = {
shells: 'npm run check:native-shells:shells',
'agc-web': 'npm run check:native-shells:agc-web',
'agc-rust-crates': 'npm run check:native-shells:agc-rust-crates',
'agc-rust-shell': 'npm run check:native-shells:agc-rust-shell',
'agc-rust-shard-1': 'npm run check:native-shells:agc-rust-shard-1',
'agc-rust-shard-2': 'npm run check:native-shells:agc-rust-shard-2',
'agc-rust-shard-3': 'npm run check:native-shells:agc-rust-shard-3',
'agc-rust-shard-4': 'npm run check:native-shells:agc-rust-shard-4',
'agc-rust-smoke': 'npm run check:native-shells:agc-rust-smoke',
release: 'npm run check:native-shells:release',
} as const;
@@ -391,7 +403,7 @@ describe('project CI workflow', () => {
nativeShellGateScript.indexOf('const nativeShellGateGroups = ['),
),
)
.matchAll(/'([a-z-]+)'/gu),
.matchAll(/'([a-z0-9-]+)'/gu),
].map((match) => match[1]);
expect(declaredGroups).toEqual(Object.keys(nativeShellGateGroupScripts));
@@ -405,16 +417,40 @@ describe('project CI workflow', () => {
expect(webJob).toContain('run: npm run check:native-shells:agc-web');
expect(webJob).not.toContain('cargo fetch');
const rustJob = jobSection('ai-game-creator-shell-rust-tests');
expect(rustJob).toContain(
'run: npm run check:native-shells:agc-rust-shell',
// 壳 bin 单测按名单分 4 片,一片一个 job:每个片 job 只跑自己那片,且只预热 AGC 壳
// 自己那份锁定依赖(server-rs 那份归 crate 级 job)。
for (const [index, jobName] of [
[1, 'ai-game-creator-shell-rust-shard-1'],
[2, 'ai-game-creator-shell-rust-shard-2'],
[3, 'ai-game-creator-shell-rust-shard-3'],
[4, 'ai-game-creator-shell-rust-shard-4'],
] as const) {
const shardJob = jobSection(jobName);
expect(shardJob).toContain(
`run: npm run check:native-shells:agc-rust-shard-${index}`,
);
expect(shardJob).toContain(
'apps/ai-game-creator-shell/src-tauri/Cargo.toml',
);
expect(shardJob).toContain('cargo fetch --locked');
expect(shardJob).not.toContain('server-rs/Cargo.toml');
}
// 整套用例不能再作为一条命令串行跑完:每个片 job 都必须落到分片运行器的
// `--shard-index` 上,4 个 index 各一次。
for (const index of [1, 2, 3, 4]) {
expect(nativeShellGateScript).toContain(`'--shard-index=${index}'`);
}
expect(
nativeShellGateScript.match(/ai-game-creator-shell:check:rust:shell/gu),
).toHaveLength(4);
const smokeJob = jobSection('ai-game-creator-shell-rust-smoke');
expect(smokeJob).toContain(
'run: npm run check:native-shells:agc-rust-smoke',
);
expect(rustJob).toContain(
'apps/ai-game-creator-shell/src-tauri/Cargo.toml',
);
expect(rustJob).toContain('cargo fetch --locked');
// 壳 job 只预热 AGC 壳自己那份锁定依赖:server-rs 那份归 crate 级 job。
expect(rustJob).not.toContain('server-rs/Cargo.toml');
expect(smokeJob).toContain('cargo fetch --locked');
expect(smokeJob).not.toContain('server-rs/Cargo.toml');
const cratesJob = jobSection('ai-game-creator-shell-rust-crates');
expect(cratesJob).toContain(
@@ -445,8 +481,9 @@ describe('project CI workflow', () => {
'node apps/ai-game-creator-shell/scripts/run-rust-shell-test-shards.mjs --shards=4',
);
// 整套用例不再作为一条 `cargo test -- --test-threads=1` 命令串行跑:CI 与本地都走
// 分片运行器,片内串行、片间并行。
// 分片运行器,片内串行,片与片之间靠 job 级并发摊开。
expect(workflow).not.toContain('-- --test-threads=1');
expect(workflow).not.toMatch(/^ {8}run: .*--test-threads/mu);
});
it('keeps the shell shard runner exhaustive over discovered tests', () => {
@@ -464,6 +501,10 @@ describe('project CI workflow', () => {
expect(shardRunner).toContain("'--test-threads=1'");
expect(shardRunner).toContain('TMPDIR: shardTmpDirectory');
expect(shardRunner).toContain("'--exact'");
// `--shard-index` 是 CI 的「一个 job 一片」入口:只跑指定片,但覆盖自校验照旧
// 针对 `--list` 全集执行,所以改分片规则仍然会在每个 job 上暴露。
expect(shardRunner).toContain("case 'shard-index':");
expect(shardRunner).toContain('must be within --shards');
});
it('prefetches the excluded standalone Rust crates before the shared crate gates', () => {