feat: 完善工作流工具链与大结果保护
- 工作流节点描述增加服务端托管黑名单,仅代码节点保留自定义 desc - 工作流保存新增 --in-place,并改进版本冲突提示 - platform records 新增 --page 分页,--all 强制走 ndjson 文件流 - platform schema 展示 ownerId/submitterId 等系统字段 - 更新 Agent Skill 的代码节点 agent use 标记规范 - 补充对应测试与文档
This commit is contained in:
1 parent
37643da254
commit
7423e166a1
10 files changed
+123
-20
No files matched your search
@@ -597,7 +597,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"auth": "permissions",
|
||||
"import-jobs": "imports"
|
||||
},
|
||||
flags: { ...flagList("a active active-only activeOnly all flat ndjson normalize normalized profile raw state stats stream w workbench", "boolean"), ...flagList("aggregate baseline c check-continuous check-fields checkContinuous checkFields concurrency continuous count d data expect expect-value expectValue f field fields file filter filter-by filterBy form group-by groupBy id ids keyword lang language limit name offset page-size pageSize q query search-field searchField search-fields searchFields select seq sequence set start sum where", "value") }
|
||||
flags: { ...flagList("a active active-only activeOnly all flat ndjson normalize normalized profile raw state stats stream w workbench", "boolean"), ...flagList("aggregate baseline c check-continuous check-fields checkContinuous checkFields concurrency continuous count d data expect expect-value expectValue f field fields file filter filter-by filterBy form group-by groupBy id ids keyword lang language limit name offset page page-size pageSize q query search-field searchField search-fields searchFields select seq sequence set start sum where", "value") }
|
||||
},
|
||||
"app": {
|
||||
"summary": "桌面端工作台应用管理",
|
||||
|
||||
@@ -514,6 +514,18 @@ describe("CLI - platform 命令与 record 动作", () => {
|
||||
expect(row1.fields["自定义字段"]).toBe("测试值");
|
||||
});
|
||||
|
||||
it("platform records --all 拒绝直接全量输出,要求分页或流式文件", async () => {
|
||||
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
|
||||
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
|
||||
spies.push(spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any));
|
||||
await expect(
|
||||
handlePlatformCommand(
|
||||
{ area: "platform", action: "records", args: ["platform-1", "entity-1"], options: { all: true }, raw: ["platform", "records", "platform-1", "entity-1", "--all"] },
|
||||
dummyRuntime
|
||||
)
|
||||
).rejects.toThrow("--all 不再直接返回全量");
|
||||
});
|
||||
|
||||
it("rejects malformed batch predicates before fetching all records or calling the writer", async () => {
|
||||
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
|
||||
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
|
||||
|
||||
@@ -11,6 +11,14 @@ import { printJson, printTable } from "../../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { cell, resolveAppAndEntity } from "./shared.js";
|
||||
|
||||
const SYSTEM_FIELD_INFO = [
|
||||
{ fieldKey: "ownerId", label: "负责人", type: "staff", role: "system" },
|
||||
{ fieldKey: "submitterId", label: "提交人", type: "staff", role: "system" },
|
||||
{ fieldKey: "createTime", label: "创建时间", type: "date", role: "system" },
|
||||
{ fieldKey: "updateTime", label: "更新时间", type: "date", role: "system" },
|
||||
{ fieldKey: "active", label: "启停状态", type: "boolean", role: "system" },
|
||||
];
|
||||
|
||||
export async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const clients = await createClientsForCorp(runtime.selectedCorp!);
|
||||
const isAll = booleanOption(parsed.options, ["all", "a"], false);
|
||||
@@ -60,7 +68,7 @@ export async function handleSchema(parsed: CliParsedArgs, runtime: CliRuntime):
|
||||
)
|
||||
: entity.fields,
|
||||
}));
|
||||
if (runtime.jsonMode) return { stdout: printJson({ platform: resolved.platform, count: output.length, entities: output }, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
if (runtime.jsonMode) return { stdout: printJson({ platform: resolved.platform, count: output.length, systemFields: SYSTEM_FIELD_INFO, entities: output }, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
const rows = output.flatMap((entity) =>
|
||||
entity.fields.map((field): Array<string | number | boolean | null | undefined> => {
|
||||
const roleTag =
|
||||
@@ -86,16 +94,21 @@ export async function handleSchema(parsed: CliParsedArgs, runtime: CliRuntime):
|
||||
["业务对象", "物理字段键 (fieldKey / 接口参数名)", "界面名称 (label)", "类型", "角色说明", "必填性", "引用对象"],
|
||||
rows
|
||||
);
|
||||
const systemTable = printTable(
|
||||
["系统字段键", "界面名称", "类型", "说明"],
|
||||
SYSTEM_FIELD_INFO.map((field) => [field.fieldKey, field.label, field.type, "系统字段,不在业务 fields 列表中"])
|
||||
);
|
||||
const tips = [
|
||||
"",
|
||||
"💡 字段命名与工作流配置避坑提示:",
|
||||
" 1. 物理字段键 (fieldKey / 接口参数名): 在工作流节点映射 (如 ekuaibao-datalink-create) 和 API 请求中,必须使用此键 (例如 E_..._费用金额),切勿使用中文显示名。",
|
||||
" 2. 结尾 _name: 代表实体的业务主名称/标题 (界面通常显示为单据/计划名称);",
|
||||
" 3. 结尾 _code: 代表业务编号/单号 (界面通常显示为单据/计划编码);若设置了 autoNumber 规则,创建时会自动生成流水号。",
|
||||
" 4. 系统字段不在业务字段列表中:ownerId = 负责人/记录所有者,submitterId = 提交人;工作流创建/修改节点的字段映射可直接使用 ownerId,不能把自定义「人员」当作负责人。",
|
||||
"",
|
||||
].join("\n");
|
||||
return {
|
||||
stdout: `====== 应用 [${resolved.platform.name}] 字段定义 (共 ${rows.length} 个字段) ======\n${table}\n${tips}`,
|
||||
stdout: `====== 应用 [${resolved.platform.name}] 字段定义 (共 ${rows.length} 个业务字段) ======\n${table}\n\n── 系统字段(不在业务 fields 中) ──\n${systemTable}\n${tips}`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
|
||||
@@ -54,11 +54,21 @@ export async function handleRecords(parsed: CliParsedArgs, runtime: CliRuntime):
|
||||
const isAll = booleanOption(parsed.options, ["all", "a"], false);
|
||||
const groupBy = stringOption(parsed.options, ["group-by", "groupBy"]);
|
||||
const fetchAll = isAll || Boolean(sumOption || isProfileStats);
|
||||
const start = numberOption(parsed.options, ["start", "offset"], 0);
|
||||
const count = numberOption(parsed.options, ["count", "limit"], 20);
|
||||
const pageSize = numberOption(parsed.options, ["page-size", "pageSize"], 500);
|
||||
const count = numberOption(parsed.options, ["count", "limit"], 20) ?? 20;
|
||||
const page = Math.max(1, numberOption(parsed.options, ["page"], 1) ?? 1);
|
||||
const start = numberOption(parsed.options, ["start", "offset"], (page - 1) * count) ?? 0;
|
||||
const pageSize = numberOption(parsed.options, ["page-size", "pageSize"], 500) ?? 500;
|
||||
const fields = splitFields(stringOption(parsed.options, ["fields", "select"]));
|
||||
|
||||
// 全量 JSON/表格很容易把几十万条记录倒进 stdout 或内存;全量导出必须显式走文件流。
|
||||
if (isAll && !isProfileStats && !sumOption) {
|
||||
if (!isStream || !runtime.outputOptions?.outputFile) {
|
||||
throw usageError(
|
||||
"--all 不再直接返回全量 JSON/表格。请使用 --page/--count 分页查询,或使用 --ndjson --output-file <path> 流式导出;大范围检索建议交给脚本处理。"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 高性能流式下发模式 (--ndjson / --stream,内存开销 O(pageSize),专为海量数据外部脚本管道设计)
|
||||
if (isStream) {
|
||||
let streamCount = 0;
|
||||
|
||||
@@ -14,7 +14,7 @@ import { createClientsForCorp, createPiperClientForCorp } from "../../helpers.js
|
||||
import { printJson } from "../../printer.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { PLATFORM_ID_OPTION_KEYS } from "./shared.js";
|
||||
import { PLATFORM_ID_OPTION_KEYS, formatWorkflowVersion } from "./shared.js";
|
||||
|
||||
export async function handlePatch(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipelineId"]);
|
||||
@@ -78,7 +78,7 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
if (!pipelineId || !file) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose-use workflow save <pipelineId> --file=<workflow.json> [--force-write]\n",
|
||||
stderr: "用法: hose-use workflow save <pipelineId> --file=<workflow.json> [--force-write] [--in-place]\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
@@ -96,6 +96,7 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
}
|
||||
|
||||
const forceWrite = booleanOption(parsed.options, ["force-write", "forceWrite"]);
|
||||
const syncFile = booleanOption(parsed.options, ["in-place", "inPlace"]);
|
||||
requireMutationConfirmation(
|
||||
parsed,
|
||||
runtime,
|
||||
@@ -105,8 +106,10 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, "保存工作流草稿到远端", pipelineId, {
|
||||
file,
|
||||
version: parsedWorkflow.version,
|
||||
tasksVersion: parsedWorkflow.tasksVersion,
|
||||
forceWrite,
|
||||
syncFile,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -124,28 +127,48 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
|
||||
if (!forceWrite && hasWorkflowVersionConflict(state, remote)) {
|
||||
throw new Error(
|
||||
`工作流版本已变化,拒绝覆盖:远端 tasksVersion=${remote.tasksVersion}, 文件 tasksVersion=${parsedWorkflow.tasksVersion}。确认来源后使用 --force-write。`
|
||||
`工作流版本已变化,拒绝覆盖:远端 tasksVersion=${remote.tasksVersion}, 文件 tasksVersion=${parsedWorkflow.tasksVersion}。请重新导出最新工作流后再改;后续保存可加 --in-place 自动同步本地文件版本。确认要覆盖时使用 --force-write。`
|
||||
);
|
||||
}
|
||||
|
||||
state = beginWorkflowSave(state);
|
||||
const localWorkflowForSync = state.workflow;
|
||||
try {
|
||||
const payload = state.workflow.inputs?.length
|
||||
? state.workflow
|
||||
: { ...state.workflow, inputs: [{ key: "$platformId", value: platformId }] };
|
||||
const saved = await updateWorkflow(piperClient, payload);
|
||||
state = commitWorkflowSave(state, saved);
|
||||
let fileSynced = false;
|
||||
let fileSyncWarning = "";
|
||||
if (syncFile) {
|
||||
try {
|
||||
const syncedWorkflow = {
|
||||
...localWorkflowForSync,
|
||||
version: saved.version,
|
||||
tasksVersion: saved.tasksVersion,
|
||||
updateTime: saved.updateTime,
|
||||
};
|
||||
writeFileSync(file, `${JSON.stringify(syncedWorkflow, null, 2)}\n`, "utf8");
|
||||
fileSynced = true;
|
||||
} catch (error) {
|
||||
fileSyncWarning = `本地文件同步失败: ${error instanceof Error ? error.message : String(error)}`;
|
||||
}
|
||||
}
|
||||
const result = {
|
||||
success: true,
|
||||
pipelineId,
|
||||
status: state.status,
|
||||
version: saved.version,
|
||||
tasksVersion: saved.tasksVersion,
|
||||
updateTime: saved.updateTime,
|
||||
fileSynced,
|
||||
...(fileSyncWarning ? { fileSyncWarning } : {}),
|
||||
};
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: fileSyncWarning, exitCode: 0 };
|
||||
return {
|
||||
stdout: `✅ 工作流 [${pipelineId}] 草稿保存成功,tasksVersion=${saved.tasksVersion}。\n`,
|
||||
stderr: "",
|
||||
stdout: `✅ 工作流 [${pipelineId}] 草稿保存成功:${formatWorkflowVersion(saved)}。${fileSynced ? "\n📝 已同步更新本地文件。" : ""}${fileSyncWarning ? `\n⚠️ ${fileSyncWarning}` : ""}\n`,
|
||||
stderr: fileSyncWarning,
|
||||
exitCode: 0,
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
@@ -14,12 +14,13 @@ import {
|
||||
GRAY_NODES_CATALOG,
|
||||
findGrayNode,
|
||||
} from "../../../domains/platform/workflow/nodes/gray-nodes-catalog.js";
|
||||
import { isServerManagedDescType } from "../../../domains/platform/workflow/nodes/mutations.js";
|
||||
import { stringOption } from "../../parser.js";
|
||||
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { createPiperClientForCorp } from "../../helpers.js";
|
||||
import { createWorkflowDetailClient } from "./shared.js";
|
||||
import { createWorkflowDetailClient, formatWorkflowVersion } from "./shared.js";
|
||||
|
||||
const SUB_ACTIONS = new Set(["list", "ls", "get", "show", "info", "add", "append", "insert", "edit", "update", "set", "map", "rm", "remove", "delete", "del"]);
|
||||
const CORP_LEVEL_ACTIONS = new Set(["available", "list-available", "catalog", "probe", "grant", "open"]);
|
||||
@@ -334,6 +335,7 @@ async function handleAddNode(
|
||||
"节点显示名 (displayName)": newTask.displayName || "-",
|
||||
"所属位置": parent ? `容器 [${parent}] 内部` : after ? `节点 [${after}] 之后` : "工作流顶级末尾",
|
||||
"节点总数": String(saveResult.tasks?.length || updatedWorkflow.tasks?.length || 0),
|
||||
"工作流版本": formatWorkflowVersion(saveResult),
|
||||
}),
|
||||
].join("\n");
|
||||
|
||||
@@ -420,6 +422,7 @@ async function handleEditNode(
|
||||
code,
|
||||
set: Object.keys(customSet).length > 0 ? customSet : undefined,
|
||||
});
|
||||
const descManaged = desc !== undefined && isServerManagedDescType(editedTask.type);
|
||||
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, "修改工作流节点", `${pipelineId}:${editedTask.name}`, {
|
||||
@@ -429,7 +432,8 @@ async function handleEditNode(
|
||||
updatedFields: {
|
||||
...(label ? { label } : {}),
|
||||
...(displayName !== undefined ? { displayName } : {}),
|
||||
...(desc ? { desc } : {}),
|
||||
...(desc && !descManaged ? { desc } : {}),
|
||||
...(descManaged ? { desc: "服务端托管,已跳过" } : {}),
|
||||
...(code !== undefined ? { code: `${code.length} 字符${!codeFile && code.length > 300 ? " [TIP: 建议使用 --code-file=<path> 从本地文件载入以规避转义错误并节省 Token]" : ""}` } : {}),
|
||||
...customSet,
|
||||
},
|
||||
@@ -440,7 +444,7 @@ async function handleEditNode(
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({ success: true, pipelineId, editedTask, workflow: saveResult }, runtime.outputOptions),
|
||||
stdout: printJson({ success: true, pipelineId, editedTask, workflow: saveResult, descIgnored: descManaged }, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -453,9 +457,12 @@ async function handleEditNode(
|
||||
const labelTip = label
|
||||
? "\n💡 提示: --label 是节点类型标题,服务端保存时可能重新生成;要修改设计器标题请使用 --display-name。\n"
|
||||
: "";
|
||||
const descTip = descManaged
|
||||
? "\n💡 提示: 该节点描述由服务端按配置自动生成,--desc 已忽略;如需稳定说明,请使用代码节点或在创建节点上写业务说明。\n"
|
||||
: "";
|
||||
|
||||
return {
|
||||
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.displayName || editedTask.label}) 修改已保存至工作流 [${pipelineId}]。\n${codeTip}${labelTip}`,
|
||||
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.displayName || editedTask.label}) 修改已保存至工作流 [${pipelineId}]。\n📌 ${formatWorkflowVersion(saveResult)}\n${codeTip}${labelTip}${descTip}`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -545,7 +552,7 @@ async function handleMapNode(
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.label}) 已批量应用映射: ${changedKeys.join(", ")},并已保存至工作流 [${pipelineId}]。\n`,
|
||||
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.label}) 已批量应用映射: ${changedKeys.join(", ")},并已保存至工作流 [${pipelineId}]。\n📌 ${formatWorkflowVersion(saveResult)}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -598,7 +605,7 @@ async function handleRemoveNode(
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: `🗑️ 节点 [${removedTask.name}] (${removedTask.label || removedTask.type}) 已从工作流 [${pipelineId}] 中安全移除。\n`,
|
||||
stdout: `🗑️ 节点 [${removedTask.name}] (${removedTask.label || removedTask.type}) 已从工作流 [${pipelineId}] 中安全移除。\n📌 ${formatWorkflowVersion(saveResult)}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
|
||||
@@ -5,6 +5,17 @@ import type { CliParsedArgs, CliRuntime } from "../../types.js";
|
||||
|
||||
export const PLATFORM_ID_OPTION_KEYS = ["platform", "platform-id", "platformId", "app", "app-id", "appId"];
|
||||
|
||||
export function formatWorkflowVersion(workflow: {
|
||||
version?: string | null;
|
||||
tasksVersion?: number | null;
|
||||
updateTime?: string | null;
|
||||
}): string {
|
||||
const version = workflow.version || "-";
|
||||
const tasksVersion = workflow.tasksVersion ?? "-";
|
||||
const updateTime = workflow.updateTime ? `,更新时间 ${workflow.updateTime}` : "";
|
||||
return `版本 ${version}(tasksVersion ${tasksVersion})${updateTime}`;
|
||||
}
|
||||
|
||||
export async function createWorkflowDetailClient(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime,
|
||||
|
||||
@@ -30,7 +30,7 @@ hose-use platform list
|
||||
hose-use platform get <应用 ID|名称>
|
||||
hose-use platform entities <应用 ID|名称>
|
||||
hose-use platform schema <应用 ID|名称> [对象 ID|名称] [--keyword <字段关键词>]
|
||||
hose-use platform records <应用 ID|名称> <对象 ID|名称> [--all] [--keyword <关键词>] [--search-fields <字段列表>] [--filter <表达式>] [--where <条件>] [--sum <字段1,字段2>] [--group-by <字段>] [--fields <字段列表>] [--flat] [--ndjson] [--stats]
|
||||
hose-use platform records <应用 ID|名称> <对象 ID|名称> [--page <页码>] [--count <每页条数>] [--all] [--keyword <关键词>] [--search-fields <字段列表>] [--filter <表达式>] [--where <条件>] [--sum <字段1,字段2>] [--group-by <字段>] [--fields <字段列表>] [--flat] [--ndjson] [--stats]
|
||||
hose-use platform record get [<应用> <业务对象>] <记录ID>
|
||||
hose-use platform record toggle <应用> <业务对象> <记录ID> [--state=true|false] [--dry-run|--yes]
|
||||
hose-use platform record edit <应用> <业务对象> <记录ID> [--set="字段=值" | --data='{"field": "val"}'] [--raw] [--dry-run|--yes]
|
||||
@@ -47,6 +47,8 @@ hose-use platform imports <应用 ID|名称> <对象 ID|名称>
|
||||
- `records --ndjson`(或 `--stream`):针对万级~十万级海量记录,采用 AsyncGenerator 分页流式生成,逐行向 `stdout` 发射 NDJSON。内存恒定为 $O(\text{pageSize})$,严防大报文撑爆内存或终端,无缝对接下游 `jq`、Python 处理流水线。
|
||||
- 终端入口提供显式输出回调并等待写入完成以响应背压;`--ndjson -o <path>` 写入真正的 NDJSON 文件,返回文件路径、字节数和记录数摘要。
|
||||
- MCP / HTTP 默认不提供终端输出通道;未指定文件时拒绝直接流式输出,避免污染协议 stdout 或返回空的成功响应。输出逐行执行统一脱敏。
|
||||
- `records --page=<页码> --count=<每页>`:分页查询,默认 `count=20`;用于替代无边界全量拉取。
|
||||
- `records --all`:不再直接返回全量 JSON/表格。普通查询请用 `--page/--count`;确实需要全量时只允许 `--ndjson --output-file <path>` 流式导出,避免几十万条记录进入 stdout 或一次性载入内存。大范围检索建议由 Agent 编写脚本处理。
|
||||
- `records --stats`(或 `records stats <应用> <对象>` / `records profile`):宏观结构与特征聚类画像。输出总记录数、启用/停用分布及占比、唯一标题数与重名分布、编码生成规则聚类(自动提取 `${groupIndex}-${formCode}-month-${idx}` 等动态模板分布)、最早与最新维护时间,毫秒级洞察数据特征。
|
||||
- `records --flat`:自动剥离底层动态物理前缀(如 `E_<entityId>_`),提取关联引用对象的名称/编码,将复杂元数据规整为 `{ id, code, name, active, createTime, updateTime, fields }` 干净对象。
|
||||
- `records --sum="字段1,字段2" [--group-by="分组字段"]`:台账数学聚合核算,自动解析纯数值、金额对象(`{ standard: 100 }`)与货币符号字符串(`¥12,500.00`),输出样本数、总合计(SUM)、均值(AVG)、最小值(MIN)、最大值(MAX)以及指定字段的分组小计。
|
||||
|
||||
@@ -264,6 +264,18 @@ describe("workflow-nodes - 任务节点声明式编排纯函数", () => {
|
||||
expect(() => editWorkflowTask(mockWorkflow, "action_js_1", { set: { displayName: "一".repeat(21) } })).toThrow("最多 20 个字符");
|
||||
});
|
||||
|
||||
it("skips desc for server-managed nodes while allowing code node descriptions", () => {
|
||||
const { editedTask: managedTask } = editWorkflowTask(mockWorkflow, "control_every_1", {
|
||||
desc: "服务端会覆盖这段描述",
|
||||
});
|
||||
expect(managedTask.desc).toBe("依次遍历每张发票");
|
||||
|
||||
const { editedTask: codeTask } = editWorkflowTask(mockWorkflow, "action_js_1", {
|
||||
desc: "Agent 生成的数据清洗脚本",
|
||||
});
|
||||
expect(codeTask.desc).toBe("Agent 生成的数据清洗脚本");
|
||||
});
|
||||
|
||||
it("removeWorkflowTask safely removes task and guards trigger node", () => {
|
||||
// 1. Remove child task in container
|
||||
const { workflow: wfRemoved, removedTask } = removeWorkflowTask(mockWorkflow, "action_js_1");
|
||||
|
||||
@@ -38,6 +38,16 @@ export function generateNodeName(type: string): string {
|
||||
|
||||
export const MAX_NODE_DISPLAY_NAME_LENGTH = 20;
|
||||
|
||||
/**
|
||||
* 服务端会按节点配置重建 desc 的节点类型。只有代码节点的 desc 可以稳定保留;
|
||||
* 其它节点的描述写入后会在保存时被服务端覆盖,因此本地直接跳过,避免无效修改。
|
||||
*/
|
||||
const CODE_DESC_TYPES = new Set(["code", "code-js2"]);
|
||||
|
||||
export function isServerManagedDescType(type: string): boolean {
|
||||
return !CODE_DESC_TYPES.has(type);
|
||||
}
|
||||
|
||||
/** 设计器节点标题按 Unicode 字符计数(中文与 emoji 均算 1 个字符)。 */
|
||||
export function displayNameLength(name: string): number {
|
||||
return Array.from(name.trim()).length;
|
||||
@@ -304,7 +314,7 @@ export function editWorkflowTask(
|
||||
const { task } = target;
|
||||
if (updates.label !== undefined) task.label = updates.label;
|
||||
if (updates.displayName !== undefined) applyDisplayName(task, updates.displayName);
|
||||
if (updates.desc !== undefined) task.desc = updates.desc;
|
||||
if (updates.desc !== undefined && !isServerManagedDescType(task.type)) task.desc = updates.desc;
|
||||
if (updates.code !== undefined) (task as any).code = updates.code;
|
||||
|
||||
if (updates.set && typeof updates.set === "object") {
|
||||
@@ -383,6 +393,9 @@ export function applyNodeMapping(
|
||||
for (const [key, value] of Object.entries(mapping)) {
|
||||
if (key === "displayName") {
|
||||
applyDisplayName(task, typeof value === "string" ? value : value == null ? "" : String(value));
|
||||
} else if (key === "desc" && isServerManagedDescType(task.type)) {
|
||||
changedKeys.push("desc (服务端托管,已跳过)");
|
||||
continue;
|
||||
} else {
|
||||
(task as any)[key] = value;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user