fix(diagnostics): 處理 ai review findings #32
+15
-4
@@ -29,6 +29,19 @@ function redactSecrets(text) {
|
|||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 將 AI CLI 失敗輸出整理成單行、遮罩且限長的診斷片段。
|
||||||
|
*
|
||||||
|
* @param {string[]} parts - 要附加診斷片段的陣列。
|
||||||
|
* @param {string} label - 診斷欄位名稱(如 stderr/stdout)。
|
||||||
|
* @param {*} value - 原始診斷輸出。
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function appendRedactedOutput(parts, label, value) {
|
||||||
|
const redacted = redactSecrets(String(value || '').slice(0, AGENT_DIAGNOSTIC_INPUT_LIMIT));
|
||||||
|
if (redacted) parts.push(`${label}:${redacted.slice(0, AGENT_DIAGNOSTIC_OUTPUT_LIMIT)}`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 從 `runAgent` 的失敗結果組出可診斷的一行摘要:退出碼/訊號為主,原始輸出預設隱藏。
|
* 從 `runAgent` 的失敗結果組出可診斷的一行摘要:退出碼/訊號為主,原始輸出預設隱藏。
|
||||||
*
|
*
|
||||||
@@ -52,10 +65,8 @@ function agentFailureDetail(agentResult) {
|
|||||||
}
|
}
|
||||||
// 失敗輸出可能含 token 或 PII,預設不寫入長期 CI log;debug 模式才輸出遮罩後片段。
|
// 失敗輸出可能含 token 或 PII,預設不寫入長期 CI log;debug 模式才輸出遮罩後片段。
|
||||||
if (process.env.ACTIONS_STEP_DEBUG === 'true') {
|
if (process.env.ACTIONS_STEP_DEBUG === 'true') {
|
||||||
const stderr = redactSecrets(String((agentResult && agentResult.stderr) || '').slice(0, AGENT_DIAGNOSTIC_INPUT_LIMIT));
|
appendRedactedOutput(parts, 'stderr', agentResult && agentResult.stderr);
|
||||||
if (stderr) parts.push(`stderr:${stderr.slice(0, AGENT_DIAGNOSTIC_OUTPUT_LIMIT)}`);
|
appendRedactedOutput(parts, 'stdout', agentResult && agentResult.output);
|
||||||
const stdout = redactSecrets(String((agentResult && agentResult.output) || '').slice(0, AGENT_DIAGNOSTIC_INPUT_LIMIT));
|
|
||||||
if (stdout) parts.push(`stdout:${stdout.slice(0, AGENT_DIAGNOSTIC_OUTPUT_LIMIT)}`);
|
|
||||||
}
|
}
|
||||||
if (parts.length === 0) {
|
if (parts.length === 0) {
|
||||||
parts.push((err && err.message && redactSecrets(err.message)) || 'AI CLI 執行失敗(無診斷輸出)');
|
parts.push((err && err.message && redactSecrets(err.message)) || 'AI CLI 執行失敗(無診斷輸出)');
|
||||||
|
|||||||
+2
-3
@@ -300,8 +300,7 @@ function commitAndPushFindings(cwd, { headRef, headSha, message, files, token, s
|
|||||||
);
|
);
|
||||||
const refspec = `HEAD:refs/heads/${headRef}`;
|
const refspec = `HEAD:refs/heads/${headRef}`;
|
||||||
const remoteUrl = `${serverUrl}/${repository}.git`;
|
const remoteUrl = `${serverUrl}/${repository}.git`;
|
||||||
// 一律以 token 的身分明確認證推送(不走 origin 的自動 token)——只要 token 是能觸發 CI 的 PAT,
|
// 一律以 token 的身分明確認證推送,不沿用 origin 的自動 token。
|
||||||
// 結果 commit 就會讓 PR 的 synchronize 事件再觸發 CI,由步驟 1 快速回報把結果蓋到新 head。
|
|
||||||
pushWithCredential(cwd, remoteUrl, token, refspec, serverUrl);
|
pushWithCredential(cwd, remoteUrl, token, refspec, serverUrl);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -348,7 +347,7 @@ function pushWithCredential(cwd, remoteUrl, token, refspec, serverUrl) {
|
|||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
GIT_TERMINAL_PROMPT: '0',
|
GIT_TERMINAL_PROMPT: '0',
|
||||||
// 兩筆同 scope 設定:先空值清掉 checkout 的自動 token,再注入 PAT 的 Authorization。
|
// 先清空 checkout extraheader,再注入本次 PAT header。
|
||||||
GIT_CONFIG_COUNT: '2',
|
GIT_CONFIG_COUNT: '2',
|
||||||
GIT_CONFIG_KEY_0: headerScope,
|
GIT_CONFIG_KEY_0: headerScope,
|
||||||
GIT_CONFIG_VALUE_0: '',
|
GIT_CONFIG_VALUE_0: '',
|
||||||
|
|||||||
Reference in New Issue
Block a user