fix: 标明工作流扫描与分析证据完整性

保留不完整扫描中的既有告警指纹,并展示分页和分析证据不足。
This commit is contained in:
gitea committed 2026-10-30 17:37:05 +08:00
1 parent c6d71843b7
commit c813498da2
8 files changed
+84 -22

No files matched your search

+11 -8
View File
@@ -21,6 +21,7 @@ export async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime):
const detail = await getWorkflowDetail(client, pipelineId);
const specIds = extractWorkflowSpecificationIds(detail);
const specifications: Record<string, WorkflowFormSpecLike | undefined> = {};
const evidenceErrors: Array<{ source: string; message: string }> = [];
if (specIds.length > 0) {
const corpId = runtime.selectedCorp!.corpId || runtime.selectedCorp!.id;
await Promise.all(
@@ -28,8 +29,9 @@ export async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime):
try {
const spec = await getFormSpecification(clients.ekbClient, corpId, specId);
if (spec) specifications[specId] = spec;
} catch {
// Ignore specification fetch failure in offline or restricted environments
else evidenceErrors.push({ source: `specification:${specId}`, message: "未返回表单规格" });
} catch (error) {
evidenceErrors.push({ source: `specification:${specId}`, message: error instanceof Error ? error.message : String(error) });
}
})
);
@@ -38,8 +40,8 @@ export async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime):
try {
const available = await getWorkflowAvailableNodes(client);
availableNodeTypes = available.allTypes;
} catch {
// 离线或受限网络环境下忽略探针失败
} catch (error) {
evidenceErrors.push({ source: "availableNodeTypes", message: error instanceof Error ? error.message : String(error) });
}
let openedPowerCodes: Set<string> | undefined;
@@ -60,22 +62,22 @@ export async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime):
}
}
openedPowerCodes = codes;
} catch {
// 离线或无商店应用查询权限时忽略
} catch (error) {
evidenceErrors.push({ source: "openedPowerCodes", message: error instanceof Error ? error.message : String(error) });
}
const result = analyzeWorkflow(detail, { specifications, availableNodeTypes, openedPowerCodes });
const failOnAlert = booleanOption(parsed.options, ["fail", "fail-on-alert", "failOnAlert"]);
const exitCode = failOnAlert && !result.summary.passed ? 2 : 0;
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode };
if (runtime.jsonMode) return { stdout: printJson({ ...result, evidenceComplete: evidenceErrors.length === 0, evidenceErrors }, runtime.outputOptions), stderr: "", exitCode };
const gateDecision =
result.summary.hardBlocks > 0
? `❌ 发现 ${result.summary.hardBlocks} 项硬门禁阻断 (禁止发布上线)`
: result.summary.softAdvices > 0
? `⚠️ 硬门禁全通过,存在 ${result.summary.softAdvices} 项优化建议`
: "✅ 全部门禁通过,可安全发布上线";
: "✅ 已执行的静态检查未发现阻断项";
const diagnosticRows = result.diagnostics.map((item) => [
item.category === "hard_block" ? "⛔ 硬门禁" : "💡 软建议",
@@ -100,6 +102,7 @@ export async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime):
}),
`\n依赖引用:\n${dependencyRows.length ? printTable(["节点路径", "类型", "引用"], dependencyRows) : "暂无代码引用"}`,
`\n诊断列表 (硬门禁 ⛔ / 软建议 💡):\n${diagnosticRows.length ? printTable(["分类", "级别", "代码", "节点路径", "说明"], diagnosticRows) : "未发现明显配置问题"}`,
...(evidenceErrors.length ? [`\n⚠️ 分析证据不完整:${evidenceErrors.map((item) => `${item.source}: ${item.message}`).join(";")}`] : []),
"",
].join("\n"),
stderr: "",
+5 -4
View File
@@ -20,7 +20,7 @@ export async function handleCheck(parsed: CliParsedArgs, runtime: CliRuntime): P
}));
const logErrors = logResults.filter((item): item is typeof item & { error: string } => Boolean(item.error)).map((item) => ({ platformId: item.workflow.platformId, platformName: item.workflow.platformName, error: item.error }));
const activeAlerts = logResults
.filter(({ errorCount }) => errorCount > 0)
.filter(({ errorCount, error }) => !error && errorCount > 0)
.map(({ workflow, errorCount }) => ({
id: `${runtime.selectedCorp!.id}:${workflow.platformId}:${workflow.id}`,
pipelineId: workflow.id,
@@ -32,12 +32,13 @@ export async function handleCheck(parsed: CliParsedArgs, runtime: CliRuntime): P
}));
const explicitStateFile = stringOption(parsed.options, ["state-file", "stateFile"]);
const stateFile = explicitStateFile || `sqlite:workflow_error_alerts:${runtime.selectedCorp!.id}`;
const check = new WorkflowAlertStore(explicitStateFile || `corp:${runtime.selectedCorp!.id}`).observe(activeAlerts);
const output = { corpId: runtime.selectedCorp!.id, observedAt, stateFile, activeAlerts: check.activeAlerts, newAlerts: check.newAlerts, scanErrors: [...result.errors, ...logErrors] };
const complete = result.complete === true && logErrors.length === 0;
const check = new WorkflowAlertStore(explicitStateFile || `corp:${runtime.selectedCorp!.id}`).observe(activeAlerts, { complete });
const output = { corpId: runtime.selectedCorp!.id, observedAt, stateFile, activeAlerts: check.activeAlerts, newAlerts: check.newAlerts, scanErrors: [...result.errors, ...logErrors], complete, pages: result.pages };
if (runtime.jsonMode) return { stdout: printJson(output, runtime.outputOptions), stderr: "", exitCode: booleanOption(parsed.options, ["fail-on-alert", "failOnAlert"]) && check.newAlerts.length > 0 ? 2 : 0 };
const rows = check.activeAlerts.map((alert) => [alert.pipelineId, alert.pipelineName || "-", alert.errorCount, alert.state === 1 ? "启用" : "停用", check.newAlerts.some((item) => item.id === alert.id) ? "🔔 新提醒" : "已记录"]);
const warning = check.newAlerts.length ? `\n🔔 新错误管道提醒 ${check.newAlerts.length} 条` : "\n暂无新的错误管道提醒";
const scanErrorCount = result.errors.length + logErrors.length;
const scanWarning = scanErrorCount ? `\n⚠️ 工作流扫描失败 ${scanErrorCount} 个` : "";
const scanWarning = !complete ? `\n⚠️ 扫描不完整(失败 ${scanErrorCount} 个或存在未扫描分页),保留既有告警状态` : "";
return { stdout: `====== 工作流健康检查 [${runtime.selectedCorp!.name}] ======\n${rows.length ? printTable(["工作流 ID", "名称", "错误次数", "状态", "提醒"], rows) : "未发现错误管道"}${warning}${scanWarning}\n状态存储: ${stateFile}\n`, stderr: "", exitCode: booleanOption(parsed.options, ["fail-on-alert", "failOnAlert"]) && check.newAlerts.length > 0 ? 2 : 0 };
}
+12 -4
View File
@@ -52,12 +52,16 @@ export async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Pr
return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
}
const scanWarning = rawResult.complete === false || rawResult.errors.length
? `⚠️ 结果不完整:仅查询指定页,或有 ${rawResult.errors.length} 个应用查询失败。\n`
: "";
if (workflows.length === 0) {
const emptyMsg = keyword
? `企业 [${runtime.selectedCorp!.name}] 下未找到包含关键词 "${keyword}" 的工作流\n`
: `企业 [${runtime.selectedCorp!.name}] 下暂无工作流\n`;
return {
stdout: emptyMsg,
stdout: scanWarning + emptyMsg,
stderr: "",
exitCode: 0,
};
@@ -85,7 +89,7 @@ export async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Pr
const titleSuffix = filterDesc ? ` (过滤: ${filterDesc}, 共 ${workflows.length} 条)` : ` (共 ${workflows.length} 条)`;
return {
stdout: `====== [${runtime.selectedCorp!.name}] 工作流列表${titleSuffix} ======\n${table}\n`,
stdout: `${scanWarning}====== [${runtime.selectedCorp!.name}] 工作流列表${titleSuffix} ======\n${table}\n`,
stderr: "",
exitCode: 0,
};
@@ -163,9 +167,13 @@ export async function handleFind(parsed: CliParsedArgs, runtime: CliRuntime): Pr
return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
}
const scanWarning = result.complete === false || result.errors.length
? `⚠️ 搜索结果不完整:仅查询指定页,或有 ${result.errors.length} 个查询失败。\n`
: "";
if (result.workflows.length === 0) {
return {
stdout: `未找到包含节点类型 [${taskType}] 的工作流\n`,
stdout: `${scanWarning}未找到包含节点类型 [${taskType}] 的工作流\n`,
stderr: "",
exitCode: 0,
};
@@ -185,7 +193,7 @@ export async function handleFind(parsed: CliParsedArgs, runtime: CliRuntime): Pr
);
return {
stdout: `====== 匹配节点类型 [${taskType}] 的工作流 (共 ${result.workflows.length} 条) ======\n${table}\n`,
stdout: `${scanWarning}====== 匹配节点类型 [${taskType}] 的工作流 (共 ${result.workflows.length} 条) ======\n${table}\n`,
stderr: "",
exitCode: 0,
};