fix(Step9): 還原嚴重問題失敗流程
AI / 計算版本號 (pull_request) Successful in 2s
AI / Code Review (pull_request) Successful in 35s

This commit is contained in:
2026-06-22 15:48:19 +00:00
parent e443096325
commit 47b5b7ea5c
4 changed files with 4 additions and 55 deletions
+1 -26
View File
@@ -1,7 +1,7 @@
import { describe, it, afterEach, mock } from 'node:test';
import assert from 'node:assert/strict';
import axios from 'axios';
import { getPRDiff, filterDiff, postComment, postPullReviewComment, postPullReview, getCommitMessageBySha, getBranchHeadCommitMessage, shouldSkipBotCommit, getBotReviewOutcome, blockPRMergeWithStatus } from './gitea.js';
import { getPRDiff, filterDiff, postComment, postPullReviewComment, postPullReview, getCommitMessageBySha, getBranchHeadCommitMessage, shouldSkipBotCommit, getBotReviewOutcome } from './gitea.js';
afterEach(() => mock.restoreAll());
@@ -57,31 +57,6 @@ describe('gitea', () => {
await assert.rejects(() => postComment('test'), /api error/);
});
it('blockPRMergeWithStatus creates a failure commit status on the PR head sha', async () => {
let capturedUrl, capturedBody, capturedOpts;
mock.method(axios, 'post', async (url, body, opts) => {
capturedUrl = url;
capturedBody = body;
capturedOpts = opts;
return { data: { id: 12 } };
});
const result = await blockPRMergeWithStatus({ sha: 'abc/123', criticalCount: 3 });
assert.deepEqual(result, { id: 12 });
assert.ok(capturedUrl.includes('/api/v1/repos/'));
assert.ok(capturedUrl.endsWith('/statuses/abc%2F123'));
assert.equal(capturedBody.state, 'failure');
assert.equal(capturedBody.context, 'ai-code-review/critical');
assert.ok(capturedBody.description.includes('3 個嚴重問題'));
assert.ok(capturedBody.target_url.includes('/pulls/'));
assert.ok(capturedOpts.headers['Authorization'].startsWith('token '));
});
it('blockPRMergeWithStatus rejects when commit sha is missing', async () => {
await assert.rejects(() => blockPRMergeWithStatus({ sha: '', criticalCount: 1 }), /缺少 PR head commit sha/);
});
it('postPullReviewComment posts an inline review comment to the pulls reviews API', async () => {
let capturedUrl, capturedBody, capturedOpts;
mock.method(axios, 'post', async (url, body, opts) => {