Clarify replay policies in skills and support force in replay-test
This commit is contained in:
1 parent
35a3374d27
commit
4bcb935d15
6 files changed
+121
-73
No files matched your search
@@ -857,6 +857,42 @@ describe("corps replay-test", () => {
|
||||
expect(parsed.targetCorp.id).toBe("corp-test");
|
||||
expect(parsed.document.documentSN).toBe("BX-PROD-001");
|
||||
});
|
||||
|
||||
test("allows replay within production if --force is explicitly provided even without bound test corp", async () => {
|
||||
setupTestEnv();
|
||||
const mockRun = {
|
||||
id: "run-prod-002",
|
||||
sourceDocumentSN: "BX-PROD-002",
|
||||
document: { id: "DOC-002", sn: "BX-PROD-002", fields: [] }
|
||||
};
|
||||
|
||||
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
||||
const requestUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
if (requestUrl.includes("/api/v1/approvals")) {
|
||||
return jsonResponse({ data: { records: [mockRun] } });
|
||||
}
|
||||
return jsonResponse({
|
||||
data: {
|
||||
integrations: [
|
||||
{
|
||||
type: "webhook",
|
||||
id: "wh-prod",
|
||||
name: "生产通道",
|
||||
mode: "assisted",
|
||||
incomingDocumentWebhook: { id: "wh-prod", url: "https://prod.example/wh" }
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}) as any;
|
||||
|
||||
const result = await runCli(["corps", "replay-test", "corp-prod", "--force", "--dry-run"]);
|
||||
expect(result.isError).toBe(false);
|
||||
expect(result.exitCode).toBe(0);
|
||||
const parsed = JSON.parse(result.stdout);
|
||||
expect(parsed.sourceCorp.id).toBe("corp-prod");
|
||||
expect(parsed.targetCorp.id).toBe("corp-prod");
|
||||
});
|
||||
});
|
||||
|
||||
function mockSealSyncRequests(options: {
|
||||
|
||||
+19
-13
@@ -789,19 +789,25 @@ export async function handleCorpsCommand(action: string | undefined, maybeName:
|
||||
stringOption(args.options["prod-corp"]);
|
||||
const prodCorp = selectCorp(targetCorpId);
|
||||
|
||||
if (!prodCorp.testCorpId) {
|
||||
throw usageError(
|
||||
`Production enterprise '${prodCorp.name}' (${prodCorp.id}) has no bound test enterprise.\n` +
|
||||
`Run 'seal-use corps bind-test ${prodCorp.id} <testCorpId> --confirm' first to establish a verified 1-to-1 association,\n` +
|
||||
`or use 'seal-use webhook replay <recordId> --force' if you explicitly intend to replay directly within production.`
|
||||
);
|
||||
}
|
||||
const force = booleanOption(args.options.force) === true;
|
||||
let testCorp: CorpConfig;
|
||||
|
||||
const testCorp = selectCorp(prodCorp.testCorpId);
|
||||
if (testCorp.environment !== "test") {
|
||||
throw new Error(
|
||||
`Target enterprise '${testCorp.name}' (${testCorp.id}) is marked as '${testCorp.environment}', NOT 'test'. Aborting replay to protect non-test environments.`
|
||||
);
|
||||
if (!prodCorp.testCorpId) {
|
||||
if (!force) {
|
||||
throw usageError(
|
||||
`Production enterprise '${prodCorp.name}' (${prodCorp.id}) has no bound test enterprise.\n` +
|
||||
`Run 'seal-use corps bind-test ${prodCorp.id} <testCorpId> --confirm' first to establish a verified 1-to-1 association,\n` +
|
||||
`or add '--force' (or use 'seal-use webhook replay <recordId> --force') if you explicitly intend to replay directly within production.`
|
||||
);
|
||||
}
|
||||
testCorp = prodCorp;
|
||||
} else {
|
||||
testCorp = selectCorp(prodCorp.testCorpId);
|
||||
if (testCorp.environment !== "test" && !force) {
|
||||
throw new Error(
|
||||
`Target enterprise '${testCorp.name}' (${testCorp.id}) is marked as '${testCorp.environment}', NOT 'test'. Aborting replay to protect non-test environments (use --force to override).`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const recordId =
|
||||
@@ -824,7 +830,7 @@ export async function handleCorpsCommand(action: string | undefined, maybeName:
|
||||
const endDate = stringOption(args.options.endDate) ?? stringOption(args.options["end-date"]);
|
||||
|
||||
const prodClient = await createSealClient(prodCorp);
|
||||
const testClient = await createSealClient(testCorp);
|
||||
const testClient = prodCorp.id === testCorp.id ? prodClient : await createSealClient(testCorp);
|
||||
|
||||
const selector = stringOption(args.options.webhook) ?? stringOption(args.options.selector);
|
||||
const snSuffix = stringOption(args.options.snSuffix) ?? stringOption(args.options["sn-suffix"]);
|
||||
|
||||
Reference in new issue
Block a user