Add resilient rule version diff fallback
This commit is contained in:
1 parent
c1aebc13b1
commit
3812625c30
11 files changed
+525
-303
No files matched your search
@@ -35,6 +35,7 @@ import {
|
||||
formatSyncVersionName,
|
||||
saveRuleMappingSnapshot
|
||||
} from "../../domains/seal/rule-mapping.js";
|
||||
import { savePublishedRuleVersionSnapshot } from "../../domains/seal/rule-version-snapshot.js";
|
||||
import { executeApprovalRunsReplay, type ReplayRecordsQuery } from "../../domains/seal/webhook-replay.js";
|
||||
import { resolveLiveSealEnterpriseConfig } from "../../domains/seal/source.js";
|
||||
import { selectCorp } from "../helpers.js";
|
||||
@@ -733,6 +734,9 @@ export async function handleCorpsCommand(action: string | undefined, maybeName:
|
||||
|
||||
// 6. Publish new version in test enterprise
|
||||
const published = await api.publishApprovalRuleVersion(testClient, versionName);
|
||||
try {
|
||||
savePublishedRuleVersionSnapshot(testCorp.id, published.version, createdRules);
|
||||
} catch {}
|
||||
|
||||
const publishedRules = published.version.rules ?? [];
|
||||
const ruleMapping = prodRules.rules.map((prodRule, idx) => {
|
||||
|
||||
@@ -112,12 +112,13 @@ export async function handleRulesCommand(
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "diff") {
|
||||
if (action === "diff" || action === "diff-one" || action === "rule-diff") {
|
||||
const from = stringOption(args.options.from) ?? maybeName;
|
||||
const to = stringOption(args.options.to) ?? args.command[3];
|
||||
if (!from || !to) {
|
||||
throw new Error("Usage: seal-use rules diff <fromVersion> <toVersion> [--rule-id <stableRuleId>]");
|
||||
throw new Error("Usage: seal-use rules diff <fromVersion> <toVersion> [--rule-id <stableRuleId>|--code <code>] [--full]");
|
||||
}
|
||||
const singleSelector = args.command[4];
|
||||
await runTool(
|
||||
"seal_approval_rule_version_diff",
|
||||
client,
|
||||
@@ -125,8 +126,10 @@ export async function handleRulesCommand(
|
||||
{
|
||||
from,
|
||||
to,
|
||||
ruleId: stringOption(args.options.ruleId) ?? stringOption(args.options["rule-id"]),
|
||||
ruleId: stringOption(args.options.ruleId) ?? stringOption(args.options["rule-id"]) ?? (action !== "diff" ? singleSelector : undefined),
|
||||
code: stringOption(args.options.code),
|
||||
includeUnchanged: booleanOption(args.options.includeUnchanged) ?? booleanOption(args.options["include-unchanged"]),
|
||||
full: booleanOption(args.options.full),
|
||||
format: stringOption(args.options.format)
|
||||
},
|
||||
outputOptions(args.options)
|
||||
|
||||
+12
-4
@@ -245,14 +245,22 @@ export const HELP_REGISTRY: AreaHelp[] = [
|
||||
},
|
||||
{
|
||||
name: "diff",
|
||||
summary: "Compare two published rule versions by stable rule ID",
|
||||
usage: ["seal-use rules diff <fromVersion> <toVersion> [--rule-id <stableRuleId>] [--include-unchanged] [--format unified|json] [--corp <corpId>]"],
|
||||
summary: "Compare two published rule versions by persisted ID or code",
|
||||
usage: ["seal-use rules diff <fromVersion> <toVersion> [--rule-id <stableRuleId>|--code <code>] [--include-unchanged] [--full] [--corp <corpId>]"],
|
||||
options: [
|
||||
{ flag: "--rule-id <id>", description: "Compare only one stable rule ID; never fall back to code or position" },
|
||||
{ flag: "--rule-id <id>", description: "Compare only one stable rule ID" },
|
||||
{ flag: "--code <code>", description: "Compare only one rule code when stable ID mapping is unavailable" },
|
||||
{ flag: "--include-unchanged", description: "Include unchanged rules in the structured changes list" },
|
||||
{ flag: "--full", description: "Expand an oversized diff; small diffs are returned in full by default" },
|
||||
{ flag: "--format unified|json", description: "Return unified diff text together with structured metadata" }
|
||||
],
|
||||
description: "Compares published snapshots with stable rule IDs. The command refuses to guess when a snapshot lacks an ID, so code reordering cannot create a false match."
|
||||
description: "Uses locally persisted draft IDs when available and otherwise falls back to code. Output is truncated only when the total diff exceeds the safety limit; use --full to expand it."
|
||||
},
|
||||
{
|
||||
name: "diff-one",
|
||||
summary: "Inspect one rule change",
|
||||
usage: ["seal-use rules diff-one <fromVersion> <toVersion> <ruleId> [--full] [--corp <corpId>]"],
|
||||
description: "Single-rule alias for rules diff; use --code when the published snapshots have no stable ID."
|
||||
},
|
||||
{
|
||||
name: "get",
|
||||
|
||||
@@ -28,7 +28,7 @@ const AREA_ALIASES: Record<string, string> = {
|
||||
*/
|
||||
const READ_ONLY_COMMANDS: Record<string, string[]> = {
|
||||
corps: ["list", "search", "get", "current"],
|
||||
rules: ["count", "list", "versions", "version", "diff", "get", "search", "lint", "linters", "pull", "map"],
|
||||
rules: ["count", "list", "versions", "version", "diff", "diff-one", "get", "search", "lint", "linters", "pull", "map"],
|
||||
webhook: ["ready", "status", "list", "get", "resource-pack export", "resource-pack preview"],
|
||||
"approval-runs": [
|
||||
"summary",
|
||||
|
||||
Reference in new issue
Block a user