fix: harden workflow analysis diagnostics

This commit is contained in:
gitea committed 2026-10-21 16:04:57 +08:00
1 parent 6ce83dd8a7
commit 88a0d97974
5 files changed
+83 -19

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
import { describe, expect, it } from "bun:test";
import { isClientGoodOpened } from "./analyze.js";
describe("workflow analyze enterprise application status", () => {
it("uses the enterprise opening status and ignores marketplace online status", () => {
expect(isClientGoodOpened({ status: "OPENED", onLineStatus: "OFFLINE" })).toBe(true);
expect(isClientGoodOpened({ status: "EXPIRE", onLineStatus: "ONLINE" })).toBe(false);
expect(isClientGoodOpened({ status: "CLOSED", onLineStatus: "ONLINE" })).toBe(false);
});
});
+5 -1
View File
@@ -10,6 +10,10 @@ import { printJson, printTable, printKeyValue } from "../../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
import { createWorkflowDetailClient } from "./shared.js";
export function isClientGoodOpened(item: { status?: string | null; onLineStatus?: string | null }): boolean {
return item.status?.toUpperCase() === "OPENED";
}
export async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
const pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipelineId"]);
if (!pipelineId) return { stdout: "", stderr: "用法: hose-use workflow analyze <pipelineId>\n", exitCode: 1 };
@@ -44,7 +48,7 @@ export async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime):
const goods = await fetchClientGoods(runtime.selectedCorp!, { isAll: true });
const codes = new Set<string>();
for (const item of goods) {
const isOpened = item.status?.toUpperCase() === "OPENED" || item.onLineStatus?.toUpperCase() === "ONLINE";
const isOpened = isClientGoodOpened(item);
if (isOpened && Array.isArray(item.powers)) {
for (const power of item.powers) {
if (typeof power === "string") {
@@ -156,6 +156,6 @@ hose-use workflow eval-script --code="return a + b;" --input='{"a":1,"b":2}'
## 工具链静态门禁与防御性保障 (Toolchain Defense & Linting)
1. **文档站点域名拦截 (`DOCS_DOMAIN_USED`)**:静态分析会阻断在 HTTP 任务节点配置 `docs.ekuaibao.com` 的行为(错误复制开放平台文档地址),指导修正为 `app.ekuaibao.com`;
2. **应用权限代码交叉核验 (`UNLICENSED_POWER_CODE`)**:扫描 HTTP 任务 URL 中的 `powerCode` 参数(如 `TICKET_AUDIT_switch`),与当前企业已开通应用交叉核验,未开通时产生硬门禁阻断,防止运行时直接返回 403 Forbidden;
2. **应用权限代码交叉核验 (`UNLICENSED_POWER_CODE`)**:扫描 HTTP 任务 URL 中的 `powerCode` 参数(如 `TICKET_AUDIT_switch`),与当前企业已开通应用交叉核验,未开通时产生硬门禁阻断;参数包含无效 URL 百分号转义时产生 `INVALID_POWER_CODE_ENCODING` 硬门禁诊断,避免权限探测异常中断其他节点分析;
3. **前端富文本 `$snapshot` 自动清洗**:在 SDK `updateWorkflow` 时,自动递归遍历 `$snapshot` 字典并将陈旧的 `docs.ekuaibao.com` 替换为 `app.ekuaibao.com`,避免 Web 控制台用户重新点开节点保存时产生配置倒退;
4. **Webhook 样本注入 (`workflow webhook send`)**:支持向工作流专属 Webhook 地址直接模拟打桩发送 JSON 报文或关联单据真实载荷,彻底解决新建/复制工作流后 Web 界面“获取更多数据样本”等待卡死的问题。
@@ -617,28 +617,42 @@ export function analyzeWorkflow(
// 6.3 权限代码 (powerCode) 开通状态校验 (UNLICENSED_POWER_CODE / POWER_CODE_DEPENDENCY)
const powerCodeMatch = url.match(/[?&]powerCode=([^&#]+)/);
if (powerCodeMatch) {
const powerCode = decodeURIComponent(powerCodeMatch[1]);
const powerCodeKey = powerCode.trim().toLowerCase();
const appName = WELL_KNOWN_POWER_CODES[powerCodeKey] || `权限代码 [${powerCode}] 对应的应用`;
let powerCode: string | undefined;
try {
powerCode = decodeURIComponent(powerCodeMatch[1]);
} catch {
addDiagnostic(diagnostics, {
severity: "error",
category: "hard_block",
code: "INVALID_POWER_CODE_ENCODING",
path,
message: `HTTP 任务 [${task.label || task.name}] (${task.name}) 的 URL 中 powerCode 参数包含无效的百分号转义 [${powerCodeMatch[1]}],无法校验功能权限。请修正为有效的 URL 编码。`,
});
}
if (openedPowerCodeSet !== undefined) {
if (!openedPowerCodeSet.has(powerCodeKey)) {
if (powerCode !== undefined) {
const powerCodeKey = powerCode.trim().toLowerCase();
const appName = WELL_KNOWN_POWER_CODES[powerCodeKey] || `权限代码 [${powerCode}] 对应的应用`;
if (openedPowerCodeSet !== undefined) {
if (!openedPowerCodeSet.has(powerCodeKey)) {
addDiagnostic(diagnostics, {
severity: "error",
category: "hard_block",
code: "UNLICENSED_POWER_CODE",
path,
message: `HTTP 任务 [${task.label || task.name}] (${task.name}) 携带了权限代码 'powerCode=${powerCode}',但当前企业尚未开通对应功能/应用(如 ${appName})。运行时合思开放平台网关将直接返回 403 Forbidden(未开通功能,无权访问)。请先在开放平台/应用商城中开通该应用,或更换为已开通的等价接口。`,
});
}
} else {
addDiagnostic(diagnostics, {
severity: "error",
category: "hard_block",
code: "UNLICENSED_POWER_CODE",
severity: "warning",
category: "soft_advice",
code: "POWER_CODE_DEPENDENCY",
path,
message: `HTTP 任务 [${task.label || task.name}] (${task.name}) 携带了权限代码 'powerCode=${powerCode}',但当前企业尚未开通对应功能/应用(如 ${appName})。运行时合思开放平台网关将直接返回 403 Forbidden(未开通功能,无权访问)。请先在开放平台/应用商城中开通该应用,或更换为已开通的等价接口。`,
message: `HTTP 任务 [${task.label || task.name}] (${task.name}) 携带了权限代码 'powerCode=${powerCode}'。调用此接口要求企业已开通 [${appName}],否则运行时将返回 403 Forbidden。`,
});
}
} else {
addDiagnostic(diagnostics, {
severity: "warning",
category: "soft_advice",
code: "POWER_CODE_DEPENDENCY",
path,
message: `HTTP 任务 [${task.label || task.name}] (${task.name}) 携带了权限代码 'powerCode=${powerCode}'。调用此接口要求企业已开通 [${appName}],否则运行时将返回 403 Forbidden。`,
});
}
}
}
@@ -361,5 +361,41 @@ describe("Workflow static analysis", () => {
expect(diag?.category).toBe("soft_advice");
expect(diag?.severity).toBe("warning");
});
it("diagnoses malformed powerCode encoding and continues checking later nodes", () => {
const wf = {
id: "wf-invalid-power-code-encoding",
label: "权限代码编码异常",
state: 1,
version: "1",
tasks: [
{
name: "action_invalid",
type: "http",
label: "无效权限代码",
url: "https://app.ekuaibao.com/api/openapi/v1/backlog/data/[{flowId}]?powerCode=bad%value",
},
{
name: "action_encoded",
type: "http",
label: "编码权限代码",
url: "https://app.ekuaibao.com/api/openapi/v1/backlog/data/[{flowId}]?powerCode=custom%20power",
},
],
};
const result = analyzeWorkflow(wf as any);
const invalidEncoding = result.diagnostics.find((d) => d.code === "INVALID_POWER_CODE_ENCODING");
const dependency = result.diagnostics.find((d) => d.code === "POWER_CODE_DEPENDENCY");
expect(invalidEncoding?.severity).toBe("error");
expect(invalidEncoding?.category).toBe("hard_block");
expect(invalidEncoding?.path).toBe("0");
expect(invalidEncoding?.message).toContain("无效的百分号转义");
expect(dependency?.path).toBe("1");
expect(dependency?.message).toContain("custom power");
expect(result.summary.hardBlocks).toBe(1);
expect(result.summary.softAdvices).toBe(1);
});
});