Fix outbound confirmation and verification safety
This commit is contained in:
1 parent
b17bd09194
commit
67a461452c
20 files changed
+313
-74
No files matched your search
@@ -126,7 +126,8 @@ export async function handleCorpSync(
|
||||
snSuffix: stringOption(args.options.snSuffix) ?? stringOption(args.options["sn-suffix"]),
|
||||
docIdPrefix: stringOption(args.options.docIdPrefix) ?? stringOption(args.options["doc-id-prefix"]),
|
||||
docIdSuffix: stringOption(args.options.docIdSuffix) ?? stringOption(args.options["doc-id-suffix"]),
|
||||
dryRun
|
||||
dryRun,
|
||||
confirm: confirmed
|
||||
});
|
||||
if (dryRun) {
|
||||
console.error(`[corps-replay-test] 预览模式:已成功从 ${prodCorp.name} 提取单据并转换为 Webhook Payload(未实际推送)。`);
|
||||
|
||||
@@ -189,7 +189,8 @@ export async function handleDeployCommand(
|
||||
nodeId,
|
||||
rejectionNum,
|
||||
corporationId,
|
||||
dryRun
|
||||
dryRun,
|
||||
confirm: booleanOption(args.options.yes) === true || booleanOption(args.options.confirm) === true
|
||||
},
|
||||
outputOptions(args.options)
|
||||
);
|
||||
|
||||
@@ -288,7 +288,7 @@ describe("seal-use webhook replay CLI", () => {
|
||||
return new Response("Not found", { status: 404 });
|
||||
}) as any;
|
||||
|
||||
const result = await runCli(["webhook", "replay", "run-001"]);
|
||||
const result = await runCli(["webhook", "replay", "run-001", "--yes"]);
|
||||
|
||||
expect(result.isError).toBe(false);
|
||||
expect(result.exitCode).toBe(0);
|
||||
@@ -569,5 +569,66 @@ describe("seal-use webhook replay CLI", () => {
|
||||
expect(parsed.safetyGuards.targetModeAssisted).toBe(true);
|
||||
expect(parsed.safetyGuards.nodeId412Blocked).toBe(true);
|
||||
});
|
||||
|
||||
test("webhook replay requires confirmation before provisioning or pushing", async () => {
|
||||
setupMockEnv();
|
||||
let mutations = 0;
|
||||
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const method = init?.method ?? (input instanceof Request ? input.method : "GET");
|
||||
if (method !== "GET") mutations++;
|
||||
return new Response(JSON.stringify({ data: mockApprovalRun }), {
|
||||
status: 200, headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}) as typeof fetch;
|
||||
const result = await runCli(["approval-runs", "replay", "run-001"]);
|
||||
expect(result.exitCode).toBe(10);
|
||||
expect(result.stderr).toContain("--yes or --confirm");
|
||||
expect(mutations).toBe(0);
|
||||
});
|
||||
|
||||
test("outbound CLI gates both entry points and passes either confirmation flag", async () => {
|
||||
setupMockEnv();
|
||||
let pushes = 0;
|
||||
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
||||
const requestUrl = input instanceof Request ? input.url : input.toString();
|
||||
if (requestUrl.includes("/api/hosecloud/outbound")) {
|
||||
pushes++;
|
||||
return new Response(JSON.stringify({ data: { success: true } }), {
|
||||
status: 200, headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
return new Response(JSON.stringify({ data: { integrations: [{
|
||||
type: "hosecloud", signKey: "key", mode: "assisted", corporationId: "corp"
|
||||
}] } }), { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
}) as typeof fetch;
|
||||
for (const command of [
|
||||
["approval-runs", "replay", "--sn", "SN", "--channel", "hose-outbound"],
|
||||
["deploy", "hosecloud", "test-outbound"]
|
||||
]) {
|
||||
const args = [...command, "--flow-id", "flow", "--message-id", "message"];
|
||||
for (const flags of [[], ["--yes=false"], ["--force"]]) {
|
||||
const before = pushes;
|
||||
const result = await runCli([...args, ...flags]);
|
||||
expect(result.exitCode).toBe(10);
|
||||
expect(pushes).toBe(before);
|
||||
}
|
||||
for (const flag of ["--yes", "--confirm"]) {
|
||||
const before = pushes;
|
||||
const result = await runCli([...args, flag]);
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(pushes).toBe(before + 1);
|
||||
const parsed = JSON.parse(result.stdout);
|
||||
expect(parsed.consumptionVerified).toBe(false);
|
||||
expect(parsed.recordId).toBeUndefined();
|
||||
}
|
||||
|
||||
const before = pushes;
|
||||
const preview = await runCli([...args, "--node-id", "FLOW:real-node", "--dry-run"]);
|
||||
expect(preview.exitCode).toBe(0);
|
||||
expect(pushes).toBe(before);
|
||||
const parsed = JSON.parse(preview.stdout);
|
||||
expect((parsed.safetyGuards ?? parsed.safetyCheck).nodeId412Blocked).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -148,6 +148,7 @@ export async function handleWebhookCommand(
|
||||
const docIdSuffix = stringOption(args.options.docIdSuffix) ?? stringOption(args.options["doc-id-suffix"]);
|
||||
const docIdPrefix = stringOption(args.options.docIdPrefix) ?? stringOption(args.options["doc-id-prefix"]);
|
||||
const dryRun = booleanOption(args.options.dryRun) ?? booleanOption(args.options["dry-run"]);
|
||||
const confirm = booleanOption(args.options.yes) === true || booleanOption(args.options.confirm) === true;
|
||||
|
||||
const channel =
|
||||
stringOption(args.options.channel) ??
|
||||
@@ -178,6 +179,7 @@ export async function handleWebhookCommand(
|
||||
rejectionNum,
|
||||
targetSignKey,
|
||||
dryRun,
|
||||
confirm,
|
||||
force
|
||||
});
|
||||
|
||||
@@ -207,7 +209,8 @@ export async function handleWebhookCommand(
|
||||
snSuffix,
|
||||
docIdPrefix,
|
||||
docIdSuffix,
|
||||
dryRun
|
||||
dryRun,
|
||||
confirm
|
||||
});
|
||||
|
||||
if (dryRun) {
|
||||
|
||||
Reference in new issue
Block a user