Files
Genarrative/apps/ai-game-creator-shell/scripts/run-rust-shell-test-shards.test.mjs
T
lhk229 d69668e078 清理提示词脆弱测试并修复分片失败日志
删除绑定提示词措辞的断言和测试专用的重复 Direct 回合编排
通过生产函数验证消息转发、文件登记和版本幂等行为
保留参数修复和上下文压缩测试并更新提示词来源校验
保留分片失败详情并区分选中用例数与失败数,补充脚本测试
同步测试边界和定向验证文档
2026-09-20 17:25:57 +08:00

71 lines
2.2 KiB
JavaScript

import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import test from 'node:test';
import { fileURLToPath } from 'node:url';
const runner = fileURLToPath(
new URL('./run-rust-shell-test-shards.mjs', import.meta.url),
);
function runFixture(t, source) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agc-shard-output-'));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
fs.mkdirSync(path.join(root, 'src'));
fs.writeFileSync(
path.join(root, 'Cargo.toml'),
'[package]\nname = "shard-output-fixture"\nversion = "0.1.0"\nedition = "2021"\n',
);
fs.writeFileSync(path.join(root, 'src/lib.rs'), source);
const result = spawnSync(
process.execPath,
[
runner,
`--manifest=${path.join(root, 'Cargo.toml')}`,
'--target-kind=lib',
'--no-locked',
'--shards=1',
`--shard-tmp-root=${path.join(root, 'tmp')}`,
],
{
encoding: 'utf8',
timeout: 60_000,
windowsHide: true,
env: { ...process.env, CARGO_TARGET_DIR: path.join(root, 'target') },
},
);
assert.ifError(result.error);
return { status: result.status, output: result.stdout + result.stderr };
}
test('failed shard retains panic details and separates selected count from failures', (t) => {
const result = runFixture(
t,
`
#[test]
fn passing_case() {}
#[test]
fn failing_case() {
assert_eq!(1, 2, "shard panic evidence");
}
`,
);
assert.equal(result.status, 1, result.output);
assert.match(result.output, /FAILED \(selected 2 test\(s\)\)/);
assert.match(result.output, /failing_case/);
assert.match(result.output, /panicked at src[\\/]lib\.rs:/);
assert.match(result.output, /shard panic evidence/);
assert.match(result.output, /left: 1/);
assert.match(result.output, /right: 2/);
assert.match(result.output, /1 passed; 1 failed/);
});
test('successful shard keeps its compact summary', (t) => {
const result = runFixture(t, '#[test]\nfn passing_case() {}\n');
assert.equal(result.status, 0, result.output);
assert.match(result.output, /shard 1\/1 ok: 1 test\(s\)/);
assert.doesNotMatch(result.output, /test passing_case \.\.\. ok/);
});