Add Hose outbound replay with CloseAPI log matching and safety guards
This commit is contained in:
1 parent
042d223704
commit
2fc88e208c
10 files changed
+988
-19
No files matched your search
@@ -2,7 +2,7 @@ import { readFileSync } from "node:fs";
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
import type { createSealClient } from "../../core/http/factory.js";
|
||||
import { runCapability } from "../helpers.js";
|
||||
import { booleanOption, jsonObject, stringOption } from "../parser.js";
|
||||
import { booleanOption, jsonObject, numberOption, stringOption } from "../parser.js";
|
||||
import { outputOptions } from "../printer.js";
|
||||
import type { ParsedArgs } from "../types.js";
|
||||
import * as api from "../../domains/seal/api.js";
|
||||
@@ -166,5 +166,35 @@ export async function handleDeployCommand(
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(`Unknown deploy hosecloud action: ${action ?? ""}. Available: requirements, list, get, status, configure, sync.`);
|
||||
if (action === "test-outbound" || action === "outbound-test") {
|
||||
const signKey = target ?? stringOption(args.options.signKey) ?? stringOption(args.options["sign-key"]);
|
||||
const flowId = stringOption(args.options.flowId) ?? stringOption(args.options["flow-id"]);
|
||||
const sn = stringOption(args.options.sn) ?? stringOption(args.options.sourceDocumentSN);
|
||||
const messageId = stringOption(args.options.messageId) ?? stringOption(args.options["message-id"]);
|
||||
const nodeId = stringOption(args.options.nodeId) ?? stringOption(args.options["node-id"]);
|
||||
const rejectionNum = numberOption(args.options.rejectionNum) ?? numberOption(args.options["rejection-num"]);
|
||||
const corporationId = stringOption(args.options.corporationId) ?? stringOption(args.options["corporation-id"]);
|
||||
const dryRun = booleanOption(args.options.dryRun) ?? booleanOption(args.options["dry-run"]);
|
||||
|
||||
await runCapability(
|
||||
"sealDeployHosecloudTestOutbound",
|
||||
client,
|
||||
corp,
|
||||
{
|
||||
signKey,
|
||||
flowId,
|
||||
sn,
|
||||
messageId,
|
||||
nodeId,
|
||||
rejectionNum,
|
||||
corporationId,
|
||||
dryRun
|
||||
},
|
||||
outputOptions(args.options)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(`Unknown deploy hosecloud action: ${action ?? ""}. Available: requirements, list, get, status, configure, sync, test-outbound.`);
|
||||
}
|
||||
|
||||
@@ -513,4 +513,61 @@ describe("seal-use webhook replay CLI", () => {
|
||||
const parsed = JSON.parse(forceResult.stdout);
|
||||
expect(parsed.targetCorp.id).toBe("prod-corp-target");
|
||||
});
|
||||
|
||||
test("approval-runs replay --channel hose-outbound executes dry-run preview with safety guards", async () => {
|
||||
setupMockEnv();
|
||||
|
||||
const mockHoseIntegrations = [
|
||||
{
|
||||
type: "hosecloud",
|
||||
signKey: "sign-key-xyz",
|
||||
outboundName: "测试出站通道",
|
||||
mode: "assisted",
|
||||
corporationId: "corp-id-123"
|
||||
}
|
||||
];
|
||||
|
||||
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
||||
const requestUrl =
|
||||
typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
|
||||
if (
|
||||
requestUrl.includes("api/v1/system/preferences/approval-style") ||
|
||||
requestUrl.includes("api/v1/agent/ai-approval/config")
|
||||
) {
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
data: { integrations: mockHoseIntegrations }
|
||||
}),
|
||||
{ status: 200, headers: { "Content-Type": "application/json" } }
|
||||
);
|
||||
}
|
||||
return new Response("Not found", { status: 404 });
|
||||
}) as any;
|
||||
|
||||
const result = await runCli([
|
||||
"approval-runs",
|
||||
"replay",
|
||||
"--sn",
|
||||
"S26002992",
|
||||
"--channel",
|
||||
"hose-outbound",
|
||||
"--message-id",
|
||||
"ID01Wh05v0In3F",
|
||||
"--flow-id",
|
||||
"ID01Wah1FQ9faf",
|
||||
"--dry-run"
|
||||
]);
|
||||
|
||||
expect(result.isError).toBe(false);
|
||||
expect(result.exitCode).toBe(0);
|
||||
const parsed = JSON.parse(result.stdout);
|
||||
expect(parsed.preview).toBe(true);
|
||||
expect(parsed.channel).toBe("hose-outbound");
|
||||
expect(parsed.payload.messageId).toBe("ID01Wh05v0In3F");
|
||||
expect(parsed.payload.nodeId).toBe("FLOW:测试模拟节点_禁止流转");
|
||||
expect(parsed.safetyGuards.targetModeAssisted).toBe(true);
|
||||
expect(parsed.safetyGuards.nodeId412Blocked).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
resolveReplayCorpPair,
|
||||
type ReplayRecordsQuery
|
||||
} from "../../domains/seal/webhook-replay.js";
|
||||
import { executeHoseOutboundReplay } from "../../domains/seal/hose-outbound-replay.js";
|
||||
import {
|
||||
checkWebhookReadiness,
|
||||
exportApprovalRunsToResourcePack,
|
||||
@@ -148,6 +149,42 @@ export async function handleWebhookCommand(
|
||||
const docIdPrefix = stringOption(args.options.docIdPrefix) ?? stringOption(args.options["doc-id-prefix"]);
|
||||
const dryRun = booleanOption(args.options.dryRun) ?? booleanOption(args.options["dry-run"]);
|
||||
|
||||
const channel =
|
||||
stringOption(args.options.channel) ??
|
||||
(booleanOption(args.options["hose-outbound"]) || booleanOption(args.options.outbound) ? "hose-outbound" : undefined);
|
||||
|
||||
if (channel === "hose-outbound" || channel === "outbound") {
|
||||
const flowId = stringOption(args.options.flowId) ?? stringOption(args.options["flow-id"]);
|
||||
const messageId = stringOption(args.options.messageId) ?? stringOption(args.options["message-id"]);
|
||||
const nodeId = stringOption(args.options.nodeId) ?? stringOption(args.options["node-id"]);
|
||||
const corporationId = stringOption(args.options.corporationId) ?? stringOption(args.options["corporation-id"]);
|
||||
const rejectionNum = numberOption(args.options.rejectionNum) ?? numberOption(args.options["rejection-num"]);
|
||||
const targetSignKey =
|
||||
stringOption(args.options.signKey) ??
|
||||
stringOption(args.options["sign-key"]) ??
|
||||
stringOption(args.options.webhook);
|
||||
|
||||
const result = await executeHoseOutboundReplay({
|
||||
sourceCorp,
|
||||
targetCorp,
|
||||
sourceClient,
|
||||
targetClient,
|
||||
sn,
|
||||
recordId,
|
||||
flowId,
|
||||
messageId,
|
||||
nodeId,
|
||||
corporationId,
|
||||
rejectionNum,
|
||||
targetSignKey,
|
||||
dryRun,
|
||||
force
|
||||
});
|
||||
|
||||
printJson(result, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
const query: ReplayRecordsQuery = {
|
||||
recordId,
|
||||
recordIds,
|
||||
|
||||
Reference in new issue
Block a user