修复构建测试隔离并对齐 Direct 消息契约
Project CI / AI game creator shell Rust shard 2/4 (push) Successful in 5m25s
Project CI / AI game creator shell Rust shard 4/4 (push) Failing after 5m24s
Project CI / AI game creator shell Rust shard 3/4 (push) Failing after 5m45s
Project CI / AI game creator shell Rust shard 1/4 (push) Successful in 5m48s
Project CI / AI game creator shell Rust smoke (push) Successful in 1m36s
Project CI / AI game creator shell Rust crates (push) Successful in 2m1s
Project CI / Frontend tests (push) Failing after 3m5s
Project CI / Repository checks (push) Failing after 3m22s
Project CI / Native shell tests (push) Successful in 6m27s
Project CI / AI game creator shell web tests (push) Successful in 2m35s
Project CI / Backend tests (push) Successful in 7m6s

隔离 Git hook 测试子进程环境并验证外层仓库不变
恢复被测试污染的完整 ESLint 与 Prettier 配置并清除测试产物
撤销无依据的聊天参数和资源初始化时序变更
严格验证 canonical userItem 和现行历史切片契约
同步开发运维文档与共享排障约定
This commit is contained in:
2026-09-16 01:40:58 +08:00
parent ca9cde1b91
commit e72a2da733
15 changed files with 708 additions and 160 deletions
+110 -6
View File
@@ -9,7 +9,7 @@ import {
symlinkSync,
writeFileSync,
} from 'node:fs';
import { tmpdir } from 'node:os';
import { homedir } from 'node:os';
import { delimiter, dirname, join, resolve } from 'node:path';
import { test } from 'node:test';
import { fileURLToPath } from 'node:url';
@@ -34,7 +34,7 @@ test('pre-commit hook fixes staged imports and formatting without swallowing uns
'npm run format:staged\n',
);
const tempRepo = mkdtempSync(join(tmpdir(), 'genarrative-git-hooks-'));
const tempRepo = createTempDirectory('genarrative-git-hooks-');
try {
git(tempRepo, 'init', '--quiet');
git(tempRepo, 'config', 'user.email', 'git-hooks-test@example.invalid');
@@ -128,7 +128,7 @@ test('pre-commit hook fixes staged imports and formatting without swallowing uns
cwd: tempRepo,
encoding: 'utf8',
env: {
...process.env,
...isolatedGitEnvironment(),
PATH: `${join(repoRoot, 'node_modules', '.bin')}${delimiter}${process.env.PATH ?? ''}`,
},
input: JSON.stringify(lintStagedConfig),
@@ -162,7 +162,7 @@ test('pre-commit hook fixes staged imports and formatting without swallowing uns
});
test('pre-push runs repository parity only for master updates', () => {
const tempDir = mkdtempSync(join(tmpdir(), 'genarrative-pre-push-'));
const tempDir = createTempDirectory('genarrative-pre-push-');
try {
const npmLog = join(tempDir, 'repo', 'npm.log');
const tempRepo = join(tempDir, 'repo');
@@ -214,7 +214,7 @@ exit 1
{
cwd: tempRepo,
encoding: 'utf8',
env: process.env,
env: isolatedGitEnvironment(),
},
);
};
@@ -237,6 +237,92 @@ exit 1
}
});
test('hook fixtures do not mutate the calling linked worktree or its index', () => {
const tempDir = createTempDirectory('genarrative-hook-isolation-');
try {
const outerRepo = join(tempDir, 'outer');
const worktree = join(tempDir, 'worktree');
mkdirSync(outerRepo);
git(outerRepo, 'init', '--quiet');
git(outerRepo, 'config', 'user.email', 'outer@example.invalid');
git(outerRepo, 'config', 'user.name', 'Outer Repository');
writeFileSync(join(outerRepo, 'sentinel.txt'), 'committed\n');
git(outerRepo, 'add', 'sentinel.txt');
git(
outerRepo,
'-c',
'commit.gpgsign=false',
'commit',
'--quiet',
'-m',
'sentinel',
);
git(
outerRepo,
'worktree',
'add',
'--quiet',
'-b',
'fixture-caller',
worktree,
);
writeFileSync(join(worktree, 'sentinel.txt'), 'staged\n');
git(worktree, 'add', 'sentinel.txt');
writeFileSync(join(worktree, 'sentinel.txt'), 'unstaged\n');
const gitDir = git(worktree, 'rev-parse', '--absolute-git-dir').trim();
const indexPath = join(gitDir, 'index');
const before = {
refs: git(outerRepo, 'show-ref'),
config: readFileSync(join(outerRepo, '.git', 'config'), 'utf8'),
index: readFileSync(indexPath),
status: git(worktree, 'status', '--porcelain'),
};
const result = spawnSync(
process.execPath,
[
'--test',
'--test-reporter=tap',
'--test-name-pattern=^pre-(commit|push)',
fileURLToPath(import.meta.url),
],
{
cwd: worktree,
encoding: 'utf8',
env: {
...isolatedGitEnvironment(),
NODE_TEST_CONTEXT: undefined,
GIT_DIR: gitDir,
GIT_COMMON_DIR: join(outerRepo, '.git'),
GIT_WORK_TREE: worktree,
GIT_INDEX_FILE: indexPath,
GIT_CONFIG_COUNT: '1',
GIT_CONFIG_KEY_0: 'core.worktree',
GIT_CONFIG_VALUE_0: worktree,
},
},
);
assert.equal(
result.status,
0,
`${result.stdout ?? ''}${result.stderr ?? ''}`,
);
assert.match(result.stdout, /# pass 2\b/u);
assert.equal(git(outerRepo, 'show-ref'), before.refs);
assert.equal(
readFileSync(join(outerRepo, '.git', 'config'), 'utf8'),
before.config,
);
assert.deepEqual(readFileSync(indexPath), before.index);
assert.equal(git(worktree, 'status', '--porcelain'), before.status);
assert.equal(
readFileSync(join(worktree, 'sentinel.txt'), 'utf8'),
'unstaged\n',
);
} finally {
rmSync(tempDir, { force: true, recursive: true });
}
});
test('Gitea Repository checks and master pre-push share the same repository command', () => {
const workflow = readFileSync(
join(repoRoot, '.gitea', 'workflows', 'project-ci.yml'),
@@ -290,5 +376,23 @@ function toBashPath(path) {
}
function git(cwd, ...args) {
return execFileSync('git', args, { cwd, encoding: 'utf8' });
return execFileSync('git', args, {
cwd,
encoding: 'utf8',
env: isolatedGitEnvironment(),
});
}
function isolatedGitEnvironment() {
// Git hooks export repository/index paths that override cwd, including in
// linked worktrees. Fixture Git and lint-staged must never inherit them.
return Object.fromEntries(
Object.entries(process.env).filter(([name]) => !/^GIT_/iu.test(name)),
);
}
function createTempDirectory(prefix) {
const tempRoot = join(homedir(), 'data', 'tmp');
mkdirSync(tempRoot, { recursive: true });
return mkdtempSync(join(tempRoot, prefix));
}