fix(GOV-009): 完成最终复审整改
This commit is contained in:
@@ -8,6 +8,18 @@ import { fileURLToPath } from 'node:url';
|
||||
* 避免用户其他工作区改动干扰契约门禁。
|
||||
*/
|
||||
export function assertGeneratedContractsUnchanged(repositoryRoot, contractFiles) {
|
||||
for (const contractFile of contractFiles) {
|
||||
try {
|
||||
execFileSync('git', ['ls-files', '--error-unmatch', '--', contractFile], {
|
||||
cwd: repositoryRoot,
|
||||
encoding: 'utf8',
|
||||
stdio: ['ignore', 'ignore', 'pipe'],
|
||||
});
|
||||
} catch {
|
||||
throw new Error(`生成契约未纳入 Git 跟踪:${contractFile}`);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
execFileSync('git', ['diff', '--exit-code', '--', ...contractFiles], {
|
||||
cwd: repositoryRoot,
|
||||
|
||||
@@ -34,3 +34,13 @@ test('生成契约发生漂移时以明确错误阻断', () => {
|
||||
/生成契约与 Git 提交版本不一致:contract\.json/,
|
||||
);
|
||||
});
|
||||
|
||||
test('生成文件未纳入 Git 跟踪时阻断', () => {
|
||||
const repositoryRoot = createGitFixture();
|
||||
writeFileSync(path.join(repositoryRoot, 'untracked-contract.json'), '{"version":1}\n');
|
||||
|
||||
assert.throws(
|
||||
() => assertGeneratedContractsUnchanged(repositoryRoot, ['untracked-contract.json']),
|
||||
/生成契约未纳入 Git 跟踪:untracked-contract\.json/,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user