fix: address Codex PR review findings

This commit is contained in:
gitea committed 2026-10-25 22:32:45 +08:00
1 parent 0f164b6de5
commit a7974abb08
44 files changed
+3317 -667

No files matched your search

+8 -5
View File
@@ -39,18 +39,21 @@ export async function handleLogs(parsed: CliParsedArgs, runtime: CliRuntime): Pr
});
const stateOption = stringOption(parsed.options, ["state"]);
const hasErrorFilter = booleanOption(parsed.options, ["has-error", "hasError", "errors"]);
const isJobError = (job: any): boolean => {
const s = (job.status || "").toUpperCase();
if (s === "STARTED" || s === "RUNNING") return false;
const hasJobError = (job: any): boolean => {
if (job.hasError === true || job.hasError === "存在" || job.hasError === "true") return true;
if (typeof job.errorTaskCount === "number" && job.errorTaskCount > 0) return true;
if (job.state === "FAILED" || job.status === "FAILED") return true;
return false;
};
// Preserve the existing terminal-state filters while --has-error also sees in-flight errors.
const isJobError = (job: any): boolean => {
const s = (job.status || "").toUpperCase();
return s !== "STARTED" && s !== "RUNNING" && hasJobError(job);
};
let filteredJobList = rawResult.jobList;
if (hasErrorFilter) {
filteredJobList = filteredJobList.filter(isJobError);
filteredJobList = filteredJobList.filter(hasJobError);
} else if (stateOption) {
const norm = stateOption.trim().toUpperCase();
if (norm === "FAILED" || norm === "FAIL" || norm === "ERROR") {
@@ -115,8 +118,8 @@ export async function handleLogs(parsed: CliParsedArgs, runtime: CliRuntime): Pr
const formatErrorColumn = (job: any): string => {
const s = (job.status || "").toUpperCase();
if (hasJobError(job)) return "⚠️ 包含错误";
if (s === "STARTED" || s === "RUNNING") return "⏳ 执行中";
if (isJobError(job)) return "⚠️ 包含错误";
return "正常";
};
+11 -4
View File
@@ -404,6 +404,13 @@ export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Pro
})),
]);
const workflowDetail = await getWorkflowDetail(client, job.pipelineId).catch(() => undefined);
const workflowStateLabel = !workflowDetail
? "未知(无法读取工作流详情)"
: workflowDetail.state === 1
? "🟢 启用中"
: workflowDetail.state === 0
? "⚪ 已停用"
: "未知";
const failedExecutions = await enrichFailedExecutions(client, jobId, failedPage.items);
const conditionDiagnoses = explainConditionBranches(tree);
@@ -451,7 +458,7 @@ export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Pro
jobId,
pipelineId: job.pipelineId,
workflowName: workflowDetail?.pipelineName || workflowDetail?.label,
workflowState: workflowDetail?.state === 1 ? "🟢 启用中" : "⚪ 已停用",
workflowState: workflowStateLabel,
jobStatus: job.state ?? job.status,
totalTasks: timeline.length,
executedTasks: tree.length,
@@ -480,7 +487,7 @@ export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Pro
"Job ID": job.id,
"工作流 ID": job.pipelineId,
...(workflowDetail ? { "工作流名称": workflowDetail.pipelineName || workflowDetail.label } : {}),
"工作流状态": workflowDetail?.state === 1 ? "🟢 启用中" : "⚪ 已停用",
"工作流状态": workflowStateLabel,
"Job 状态": job.state ?? job.status,
"定义总步骤数": timeline.length,
"已调度步骤数": tree.length,
@@ -509,7 +516,7 @@ export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Pro
id: workflowDetail.id,
name: workflowDetail.pipelineName || workflowDetail.label,
state: workflowDetail.state,
stateLabel: workflowDetail.state === 1 ? "🟢 启用中" : "⚪ 已停用",
stateLabel: workflowStateLabel,
totalTasks: workflowDetail.tasks?.length ?? tree.length,
}
: undefined,
@@ -571,7 +578,7 @@ export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Pro
"Job ID": job.id,
"工作流 ID (pipelineId)": job.pipelineId,
...(workflowDetail ? { "工作流名称": workflowDetail.pipelineName || workflowDetail.label } : {}),
"工作流状态": workflowDetail?.state === 1 ? "🟢 启用中" : "⚪ 已停用",
"工作流状态": workflowStateLabel,
"Job 状态 (state)": formatJobStatusLabel(job.status, job.state),
"开始时间": job.startTime || "-",
"结束时间": job.endTime || "-",
@@ -0,0 +1,18 @@
import { expect, test } from "bun:test";
import { parseArgs } from "../../parser.js";
import { handleWorkflowEvalScript } from "./script.js";
test("MVEL CLI JSON returns the terminal expression and preserves failure exit codes", async () => {
for (const [code, success] of [
['Map result = new java.util.HashMap(); result.put("value", 7); result;', true],
['new java.util.Date();', false],
['if (true) { 7; }', false],
] as const) {
const result = await handleWorkflowEvalScript(parseArgs(["workflow", "eval-script", "--type", "code", "--code", code, "--json"]), { jsonMode: true } as any);
const report = JSON.parse(result.stdout);
expect(result.exitCode).toBe(success ? 0 : 1);
expect(report.success).toBe(success);
if (success) expect(report.returnValue).toEqual({ value: 7 });
else expect(report.error.name).toBe("UnsupportedMvelSyntax");
}
});
+1 -1
View File
@@ -387,7 +387,7 @@ async function handleEditNode(
}
}
const mappingFile = stringOption(parsed.options, ["mapping-file", "mapping", "file", "json-file"]);
const mappingFile = stringOption(parsed.options, ["mapping-file", "mapping", "json-file"]);
if (mappingFile) {
const fs = await import("fs/promises");
const rawContent = await fs.readFile(mappingFile, "utf-8");
+2 -2
View File
@@ -1,4 +1,4 @@
import { listAllWorkflows } from "../../../domains/platform/services.js";
import { flattenExecutionTree, listAllWorkflows } from "../../../domains/platform/services.js";
import { stringOption } from "../../parser.js";
import { createClientsForCorp, createPiperClientForCorp } from "../../helpers.js";
import type { CliParsedArgs, CliRuntime } from "../../types.js";
@@ -71,7 +71,7 @@ export function extractCodeNodeSummaries(
nodes: Array<any>,
flattenExecutionTreeFn?: (nodes: any[]) => any[]
): CodeNodeSummary[] {
const flattened = flattenExecutionTreeFn ? flattenExecutionTreeFn(nodes) : nodes;
const flattened = (flattenExecutionTreeFn ?? flattenExecutionTree)(nodes);
const summaries: CodeNodeSummary[] = [];
for (const node of flattened) {
@@ -0,0 +1,15 @@
import { expect, test } from "bun:test";
import { extractCodeNodeSummaries } from "./shared.js";
import { flattenExecutionTree } from "../../../domains/platform/services.js";
test("test and job summaries retain nested execution containers and repeated loop executions", () => {
const tree = [{ id: "loop", type: "every", children: [
{ id: "iteration-1", type: "condition", tasks: [{ id: "a", name: "script", type: "code", output: { count: 3 } }] },
{ id: "iteration-2", type: "condition", subTasks: [{ id: "b", name: "script", type: "code-js2", output: [1, 2] }] },
{ id: "iteration-3", type: "condition", items: [{ id: "c", name: "script", type: "code", output: 7 }] },
] }];
const summaries = extractCodeNodeSummaries(tree);
expect(summaries.map(item => item.id)).toEqual(["a", "b", "c"]);
expect(summaries[0].rawOutput).toEqual({ count: 3 });
expect(summaries).toEqual(extractCodeNodeSummaries(tree, flattenExecutionTree as any));
});