保留工作流节点开通测试环境选项
- 增加可选 --is-test 配置并路由到测试 Piper - 默认仍使用标准 Piper,dry-run 与结果显示所选环境 - 更新命令帮助、Skill 与接口目录
This commit is contained in:
1 parent
e562ae9227
commit
e58841e164
13 files changed
+56
-13
No files matched your search
@@ -29,7 +29,7 @@ hose-use workflow nodes grant code risk --corp=<corpId> --dry-run
|
||||
hose-use workflow nodes grant code risk --corp=<corpId> --yes
|
||||
```
|
||||
|
||||
工作流节点开通的 CLI 命令保持不变。先用 `--dry-run` 预览目标和节点,再对同一命令使用 `--yes` 执行。
|
||||
工作流节点开通的默认 CLI 命令保持不变。先用 `--dry-run` 预览目标和节点,再对同一命令使用 `--yes` 执行。只有目标接口确实使用测试 Piper 时才显式添加 `--is-test`;此选项不会根据企业名或 `env=test` 自动开启。
|
||||
|
||||
## 结果处理
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ specs/hose-close-api/
|
||||
| `EKB` | `https://app.ekuaibao.com`(按企业集群可能是 `wx2` 等) | 主站业务、模板、OpenAPI、自建应用列表 |
|
||||
| `EASO` | `https://unity.ekuaibao.com` | EASO 平台、协助平台网关 |
|
||||
| `PIPER` | `https://piper.ekuaibao.com` | 工作流(pipeline)与 Job 执行 |
|
||||
| `PIPER_TEST` | `https://piper-test.ekuaibao.net` | 显式 `isTest: true` 时使用的工作流测试环境 |
|
||||
| `ASSIST` | `https://unity.ekuaibao.com/api` | 协助平台客户端前缀 |
|
||||
|
||||
## 响应包装约定
|
||||
|
||||
@@ -74,7 +74,7 @@ staffId, userId, sourceChannel?, baseUrl?, external?, needAuth?
|
||||
| P27 | POST | `PIPER /api/easo/pipelines/{id}/debugSource` | `{number,pageSize,keywords?}` | `{code,msg,data:{type,total,items:[{id,title,flowState}],fields:[{key,label}],label}}` | `src/domains/platform/workflow/transport/debug/api.ts:28` | 否 |
|
||||
| P28 | POST | `PIPER /api/easo/jobs` | `{pipelineId,inputs:{id,data?,$autoPublish},dataLimit}` | `{code,msg,data:<jobId>|{id}|{jobId}}` | `src/domains/platform/workflow/transport/debug/api.ts:43` | 否 |
|
||||
| P29 | POST | `PIPER /api/easo/dsl/condition/select/EKB_ENUM` | Query `{thirdId}`;body `{}` 或 `{$platformId}` | `{code,msg,data:[{label,code,name?}]}` | `src/domains/platform/workflow/transport/catalog/api.ts:57` | 否 |
|
||||
| P30 | POST | `PIPER /api/easo/dsl/corporation` | `{corporationId,dslTypes:[type],"recalculate-the-approval-flow":true,"ui-notification":true,start:0}`;Authorization: Bearer EASO JWT | `{code,msg,data?}`;成功必须 `code:200` | `src/domains/platform/workflow/transport/catalog/api.ts:130` | 否 |
|
||||
| P30 | POST | `PIPER` / `PIPER_TEST` `/api/easo/dsl/corporation` | `{corporationId,dslTypes:[type],"recalculate-the-approval-flow":true,"ui-notification":true,start:0}`;Authorization: Bearer EASO JWT;`--is-test` 选择 `PIPER_TEST` | `{code,msg,data?}`;成功必须 `code:200` | `src/domains/platform/workflow/transport/catalog/api.ts:134` | 否 |
|
||||
|
||||
`Platform` 代码字段(`src/domains/platform/workflow/models/nodes.ts:5`):
|
||||
|
||||
|
||||
@@ -286,6 +286,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"--parent=<executionId> 展开循环/分支子节点",
|
||||
"--logs=<executionId> 查看节点执行日志",
|
||||
"--dry-run 只预览写操作",
|
||||
"--is-test 使用测试 Piper 环境",
|
||||
"--yes/--confirm 确认写操作"
|
||||
],
|
||||
"aliases": [
|
||||
@@ -334,7 +335,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"url": "link",
|
||||
"web": "link"
|
||||
},
|
||||
flags: { ...flagList("all allow-prod allow-production auto-publish autoPublish compare detail diff empty errors f fail fail-on-alert failOnAlert failed failed-only failedOnly follow force force-write forceWrite full has-error hasError in-place inPlace includeDetail json none once publish snapshot v value-json valueJson verbose with-tasks withTasks timeline progress steps", "boolean"), ...flagList("a admin-key adminKey after app app-id appId b bill body c choose-serialization code code-file container count d data desc description display display-name displayName end-time endTime entity execution-logs field file filter flow flow-code flowCode from i id input input-file insert-after interval job job-id job1 job2 jobA jobB jobId json-file keyword l label limit log logs mapping mapping-file max-jobs maxJobs n name node node-id nodeId nodes output output-file outputFile p page page-size pageSize parent parent-id parentId password path payload pipeline pipeline-id pipelineId platform platform-id platformId pwd q query record s sample sample-id sampleId seconds set size sleep-time sleepTime snapshot1 snapshot2 snapshotA snapshotB source start-time startTime state state-file stateFile t target targetName targetPlatformId task taskType third-id thirdId timeout timeout-ms timeoutMs to trigger type types value workflowId", "value") }
|
||||
flags: { ...flagList("all allow-prod allow-production auto-publish autoPublish compare detail diff empty errors f fail fail-on-alert failOnAlert failed failed-only failedOnly follow force force-write forceWrite full has-error hasError in-place inPlace includeDetail is-test json none once publish snapshot v value-json valueJson verbose with-tasks withTasks timeline progress steps", "boolean"), ...flagList("a admin-key adminKey after app app-id appId b bill body c choose-serialization code code-file container count d data desc description display display-name displayName end-time endTime entity execution-logs field file filter flow flow-code flowCode from i id input input-file insert-after interval job job-id job1 job2 jobA jobB jobId json-file keyword l label limit log logs mapping mapping-file max-jobs maxJobs n name node node-id nodeId nodes output output-file outputFile p page page-size pageSize parent parent-id parentId password path payload pipeline pipeline-id pipelineId platform platform-id platformId pwd q query record s sample sample-id sampleId seconds set size sleep-time sleepTime snapshot1 snapshot2 snapshotA snapshotB source start-time startTime state state-file stateFile t target targetName targetPlatformId task taskType third-id thirdId timeout timeout-ms timeoutMs to trigger type types value workflowId", "value") }
|
||||
},
|
||||
"bill": {
|
||||
"summary": "单据检索、表单规格诊断与审批动作",
|
||||
|
||||
@@ -12,7 +12,12 @@ test("node grant previews without a gateway call and requires explicit confirmat
|
||||
expect(JSON.parse(result.stdout).dryRun).toBe(true);
|
||||
expect(JSON.parse(result.stdout).changes.nodes).toEqual(["code-js2"]);
|
||||
expect(grant).not.toHaveBeenCalled();
|
||||
const testPreview = await handleWorkflowCommand(parseArgs(["workflow", "nodes", "grant", "code", "--is-test", "--dry-run", "--yes"]), runtime);
|
||||
expect(JSON.parse(testPreview.stdout).changes.isTest).toBe(true);
|
||||
expect(grant).not.toHaveBeenCalled();
|
||||
await handleWorkflowCommand(parseArgs(["workflow", "nodes", "grant", "code-js2", "--confirm"]), runtime);
|
||||
expect(grant).toHaveBeenCalledTimes(1);
|
||||
await handleWorkflowCommand(parseArgs(["workflow", "nodes", "grant", "code", "--is-test", "--yes"]), runtime);
|
||||
expect(grant).toHaveBeenLastCalledWith(expect.anything(), expect.objectContaining({ nodes: ["code"], isTest: true }));
|
||||
} finally { grant.mockRestore(); }
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getWorkflowAvailableNodes, grantWorkflowNodes } from "../../../domains/platform/workflow/services.js";
|
||||
import { GRAY_NODES_CATALOG, findGrayNode } from "../../../domains/platform/workflow/nodes/gray-nodes-catalog.js";
|
||||
import { stringOption } from "../../parser.js";
|
||||
import { booleanOption, 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";
|
||||
@@ -134,9 +134,11 @@ export async function handleGrantNodes(
|
||||
}
|
||||
|
||||
requireMutationConfirmation(parsed, runtime, "开通企业工作流灰度节点", "hose-use workflow nodes grant <type...> --yes");
|
||||
const isTest = booleanOption(parsed.options, ["is-test"]);
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, "开通企业工作流灰度节点", corp.corpId || corp.credentials.corpId || corp.id, {
|
||||
nodes: targetNodes.map(node => findGrayNode(node)?.type || node.trim()),
|
||||
isTest,
|
||||
adminPasswordRequired: Boolean(process.env.HOSE_ADMIN_PASSWORD),
|
||||
});
|
||||
}
|
||||
@@ -146,6 +148,7 @@ export async function handleGrantNodes(
|
||||
const result = await grantWorkflowNodes(corp, {
|
||||
nodes: targetNodes,
|
||||
password,
|
||||
isTest,
|
||||
});
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
@@ -156,16 +159,17 @@ export async function handleGrantNodes(
|
||||
};
|
||||
}
|
||||
if (!result.success) {
|
||||
return { stdout: "", stderr: `灰度节点开通失败: ${result.rawMessage || "网关拒绝了开通请求"}\n`, exitCode: 1 };
|
||||
return { stdout: "", stderr: `灰度节点开通失败: ${result.rawMessage || "Piper 拒绝了开通请求"}\n`, exitCode: 1 };
|
||||
}
|
||||
|
||||
const lines = [
|
||||
`====== 灰度节点开通结果 [${corp.name}] ======`,
|
||||
printKeyValue({
|
||||
"申请开通节点": targetNodes.join(", "),
|
||||
"Piper 环境": result.isTest ? "测试 Piper" : "标准 Piper",
|
||||
"新开通成功": result.saved.length ? result.saved.join(", ") : "无 (已处于开通状态)",
|
||||
"跳过(已开通)": result.skipped.length ? result.skipped.join(", ") : "无",
|
||||
"网关反馈": result.rawMessage || "处理成功",
|
||||
"Piper 反馈": result.rawMessage || "处理成功",
|
||||
}),
|
||||
"",
|
||||
"✅ 节点权限已生效!工作流设计器与 hose-use workflow analyze 将立即支持该节点。",
|
||||
|
||||
@@ -89,12 +89,13 @@ export async function handleNodeCommand(
|
||||
"",
|
||||
"子命令 (企业灰度节点级别):",
|
||||
" nodes [list] [--all] 列出当前企业已开通的节点字典 (别名: probe, catalog)",
|
||||
" nodes grant <type...> 为当前企业开通灰度节点",
|
||||
" nodes grant <type...> [--is-test] 为当前企业开通灰度节点",
|
||||
"",
|
||||
"示例:",
|
||||
" hose-use workflow nodes",
|
||||
" hose-use workflow nodes --all",
|
||||
" hose-use workflow nodes grant code-js2",
|
||||
" hose-use workflow nodes grant code-js2 --is-test",
|
||||
" hose-use workflow node list 896398895352487950",
|
||||
].join("\n") + "\n",
|
||||
exitCode: 1,
|
||||
|
||||
@@ -30,7 +30,7 @@ hose-use workflow create [--name=<名称>] [--trigger=webhook|clock|datalink|flo
|
||||
hose-use workflow copy <pipelineId> [--name=<名称>] [--platform-id=<应用ID>] [--dry-run|--yes]
|
||||
hose-use workflow delete <pipelineId> [--dry-run|--yes]
|
||||
hose-use workflow nodes [list] [--all]
|
||||
hose-use workflow nodes grant <type...> [--password=<pwd>] [--dry-run|--yes]
|
||||
hose-use workflow nodes grant <type...> [--password=<pwd>] [--is-test] [--dry-run|--yes]
|
||||
hose-use workflow node list <pipelineId>
|
||||
hose-use workflow node get <pipelineId> <节点name或#序号>
|
||||
hose-use workflow node add <pipelineId> --type=code-js2 --label="清洗" --display-name="清洗节点" --code="..." [--after=<节点>] [--parent=<容器>] [--dry-run|--yes]
|
||||
@@ -171,7 +171,7 @@ MVEL 本地仿真支持的是转译子集:零参 `HashMap` / `ArrayList` 及 `
|
||||
|
||||
灰度节点开通以 Piper 响应中的业务 `code` 判定结果;非 200 业务码时 CLI 保留失败详情并返回非零退出码,HTTP 200 本身不会被视为成功。这样可以避免开通未生效却误报成功、下游仍报 `PERMISSION_MISSING_NODE` 的情况。
|
||||
|
||||
灰度节点开通不再依赖第三方网关:CLI 使用企业 `baseUrl` 换取 EASO JWT,再直连项目现有的标准 Piper 地址请求 `/api/easo/dsl/corporation`。当前统一使用 `SCRIPT_ENGINE_BASE_URL`,不会仅因 `env=test` 自动切换到 `piper-test`;详见 [transport/README.transport.md](./transport/README.transport.md)。
|
||||
灰度节点开通不再依赖第三方网关:CLI 使用企业 `baseUrl` 换取 EASO JWT,再直连 Piper 的 `/api/easo/dsl/corporation`。默认使用 `SCRIPT_ENGINE_BASE_URL`;需要测试 Piper 时显式添加 `--is-test`。本地企业的 `env=test` 不会自动切换 Piper,避免把企业分类误当作服务端令牌环境;详见 [transport/README.transport.md](./transport/README.transport.md)。
|
||||
|
||||
监听结果区分完成、超时、快照和取消:只有到达终态才发送 `job_completed`;超时发送 `timeout` 并设置 `timedOut`,取消设置 `cancelled`。CLI 超时或取消返回非零退出码;`--once` 的运行中快照仍可成功返回,且不冒充完成。持续监听的总超时预算覆盖正在跟踪的 Job。
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ export async function grantWorkflowNodes(
|
||||
staffId,
|
||||
nodes: normalizedNodes,
|
||||
baseUrl,
|
||||
isTest: options.isTest,
|
||||
});
|
||||
|
||||
return result;
|
||||
|
||||
@@ -46,6 +46,8 @@ export interface AvailableWorkflowNodes {
|
||||
export interface GrantWorkflowNodesOptions {
|
||||
nodes: string[];
|
||||
password?: string;
|
||||
/** 显式选择 piper-test.ekuaibao.net;默认使用标准 Piper。 */
|
||||
isTest?: boolean;
|
||||
}
|
||||
|
||||
export interface GrantWorkflowNodesResult {
|
||||
@@ -53,6 +55,7 @@ export interface GrantWorkflowNodesResult {
|
||||
saved: string[];
|
||||
skipped: string[];
|
||||
rawMessage: string;
|
||||
isTest?: boolean;
|
||||
}
|
||||
|
||||
// ── 员工 ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
| 项目 | 说明 |
|
||||
|---|---|
|
||||
| 换票 | 通过企业 `baseUrl` 的 `/api/engine/realm/$EASO/actions/jwt` 获取 EASO JWT;复用 `fetchEasoJwt`,去除 `baseUrl` 末尾斜线 |
|
||||
| 开通请求 | 携带 EASO JWT 直接 POST 到 `SCRIPT_ENGINE_BASE_URL/api/easo/dsl/corporation`,目标与其他 Piper 工作流接口一致 |
|
||||
| 开通请求 | 携带 EASO JWT 直接 POST 到 Piper 的 `/api/easo/dsl/corporation`;默认使用 `SCRIPT_ENGINE_BASE_URL`,`isTest: true` 时使用 `https://piper-test.ekuaibao.net` |
|
||||
| 成功判定 | 检查 Piper 响应业务码 `code === 200`;HTTP 200 本身不作为成功依据 |
|
||||
| 结果 | 保留服务端消息,并将新开通节点映射到 `saved`、已开通节点映射到 `skipped` |
|
||||
| 凭证 | access token 与 EASO JWT 只用于本机直连请求,不写入日志或返回结果 |
|
||||
@@ -81,6 +81,8 @@ const WorkflowNodeGrantResponseSchema = z.object({
|
||||
}).passthrough().nullable().optional(),
|
||||
}).passthrough();
|
||||
|
||||
export const SCRIPT_ENGINE_TEST_BASE_URL = "https://piper-test.ekuaibao.net";
|
||||
|
||||
function normalizeEkbBaseUrl(baseUrl?: string): string {
|
||||
return (baseUrl || "https://app.ekuaibao.com").trim().replace(/\/+$/, "");
|
||||
}
|
||||
@@ -98,6 +100,7 @@ export async function grantWorkflowNodesApi(options: {
|
||||
corpId: string;
|
||||
staffId: string;
|
||||
nodes: string[];
|
||||
isTest?: boolean;
|
||||
/** 目标企业合思地址,用于 EASO JWT 换票。 */
|
||||
baseUrl?: string;
|
||||
}): Promise<import("../../types.js").GrantWorkflowNodesResult> {
|
||||
@@ -127,7 +130,8 @@ export async function grantWorkflowNodesApi(options: {
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await ky.post(`${SCRIPT_ENGINE_BASE_URL}/api/easo/dsl/corporation`, {
|
||||
const piperBaseUrl = options.isTest ? SCRIPT_ENGINE_TEST_BASE_URL : SCRIPT_ENGINE_BASE_URL;
|
||||
const response = await ky.post(`${piperBaseUrl}/api/easo/dsl/corporation`, {
|
||||
json: payload,
|
||||
headers: { Authorization: `Bearer ${easoJwt}` },
|
||||
timeout: 15000,
|
||||
@@ -146,6 +150,7 @@ export async function grantWorkflowNodesApi(options: {
|
||||
saved,
|
||||
skipped,
|
||||
rawMessage,
|
||||
isTest: Boolean(options.isTest),
|
||||
};
|
||||
} catch (err: any) {
|
||||
const message = err?.message || String(err);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { afterEach, describe, expect, it, spyOn } from "bun:test";
|
||||
import ky from "ky";
|
||||
import { grantWorkflowNodesApi } from "./catalog/api.js";
|
||||
import { grantWorkflowNodesApi, SCRIPT_ENGINE_TEST_BASE_URL } from "./catalog/api.js";
|
||||
|
||||
describe("grantWorkflowNodesApi direct Piper request", () => {
|
||||
let spies: ReturnType<typeof spyOn>[] = [];
|
||||
@@ -41,6 +41,7 @@ describe("grantWorkflowNodesApi direct Piper request", () => {
|
||||
saved: ["recalculate-the-approval-flow"],
|
||||
skipped: [],
|
||||
rawMessage: "新开通的节点:recalculate-the-approval-flow",
|
||||
isTest: false,
|
||||
});
|
||||
expect(ky.get).toHaveBeenCalledWith(
|
||||
"https://app.ekuaibao.com/api/engine/realm/$EASO/actions/jwt",
|
||||
@@ -80,6 +81,27 @@ describe("grantWorkflowNodesApi direct Piper request", () => {
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.saved).toEqual([]);
|
||||
expect(result.skipped).toEqual(["code"]);
|
||||
expect(result.isTest).toBe(false);
|
||||
});
|
||||
|
||||
it("uses the test Piper endpoint only when isTest is explicitly enabled", async () => {
|
||||
mockJwt();
|
||||
let requestedUrl = "";
|
||||
spies.push(spyOn(ky, "post").mockImplementation((async (url: string) => {
|
||||
requestedUrl = url;
|
||||
return { json: async () => ({ code: 200, msg: "新开通的节点:code" }) };
|
||||
}) as never));
|
||||
|
||||
const result = await grantWorkflowNodesApi({
|
||||
token: "access-token",
|
||||
corpId: "corp-1",
|
||||
staffId: "corp-1:staff-1",
|
||||
nodes: ["code"],
|
||||
isTest: true,
|
||||
});
|
||||
|
||||
expect(requestedUrl).toBe(`${SCRIPT_ENGINE_TEST_BASE_URL}/api/easo/dsl/corporation`);
|
||||
expect(result.isTest).toBe(true);
|
||||
});
|
||||
|
||||
it("does not treat an HTTP 200 with a failing business code as success", async () => {
|
||||
@@ -95,7 +117,7 @@ describe("grantWorkflowNodesApi direct Piper request", () => {
|
||||
nodes: ["code"],
|
||||
});
|
||||
|
||||
expect(result).toEqual({ success: false, saved: [], skipped: [], rawMessage: "JWT 签名无效" });
|
||||
expect(result).toEqual({ success: false, saved: [], skipped: [], rawMessage: "JWT 签名无效", isTest: false });
|
||||
});
|
||||
|
||||
it("maps EASO exchange transport failures to a domain API error", async () => {
|
||||
|
||||
Reference in new issue
Block a user