@mitre/hdf-diff 3.7.2 → 3.8.0-next.42533588944.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { computeEffectiveStatus as computeEffectiveStatus$1, formatTimestamp, governingOverrideIndex, parseCvssVector, parseTimestamp, sha256 } from "@mitre/hdf-utilities";
2
2
  import { validateComparison as validateComparison$1 } from "@mitre/hdf-validators";
3
- //#region src/status.ts
3
+ // src/status.ts
4
4
  /** Statuses that count as "passing" for fixed/regressed classification */
5
5
  const PASSING_STATUSES = /* @__PURE__ */ new Set(["passed"]);
6
6
  /** Statuses that count as "failing" for fixed/regressed classification */
@@ -90,8 +90,7 @@ function classifyDiffStatus(oldEffectiveStatus, newEffectiveStatus) {
90
90
  if (oldIsPassing && newIsFailing) return "regressed";
91
91
  return "updated";
92
92
  }
93
- //#endregion
94
- //#region src/summary.ts
93
+ // src/summary.ts
95
94
  /**
96
95
  * Compute summary counts from an array of RequirementDiff entries.
97
96
  */
@@ -135,8 +134,7 @@ function computeSummary(requirements) {
135
134
  }
136
135
  return summary;
137
136
  }
138
- //#endregion
139
- //#region src/normalize.ts
137
+ // src/normalize.ts
140
138
  /**
141
139
  * Normalize InSpec exec-json v1 format to HDF v2 structure for diffing.
142
140
  *
@@ -239,8 +237,7 @@ function normalizeResult(result) {
239
237
  if (result.message !== void 0) normalized["message"] = result.message;
240
238
  return normalized;
241
239
  }
242
- //#endregion
243
- //#region src/matching/exact-id.ts
240
+ // src/matching/exact-id.ts
244
241
  /**
245
242
  * Create an exact ID matching strategy.
246
243
  *
@@ -306,8 +303,7 @@ function createExactIdStrategy() {
306
303
  }
307
304
  };
308
305
  }
309
- //#endregion
310
- //#region src/matching/mapped-id.ts
306
+ // src/matching/mapped-id.ts
311
307
  /**
312
308
  * Create a mapped ID matching strategy.
313
309
  *
@@ -386,8 +382,7 @@ function createMappedIdStrategy(mapping) {
386
382
  }
387
383
  };
388
384
  }
389
- //#endregion
390
- //#region src/matching/cci-match.ts
385
+ // src/matching/cci-match.ts
391
386
  /**
392
387
  * Extract CCI identifiers from a requirement's tags.
393
388
  * Looks for `tags.cci` as an array of strings.
@@ -508,8 +503,7 @@ function createCciMatchStrategy() {
508
503
  }
509
504
  };
510
505
  }
511
- //#endregion
512
- //#region src/matching/fuzzy-match.ts
506
+ // src/matching/fuzzy-match.ts
513
507
  /** Common English stop words to exclude from tokenization */
514
508
  const STOP_WORDS = /* @__PURE__ */ new Set([
515
509
  "a",
@@ -693,8 +687,7 @@ function createFuzzyTitleStrategy(minConfidence) {
693
687
  }
694
688
  };
695
689
  }
696
- //#endregion
697
- //#region src/matching/srg-deterministic.ts
690
+ // src/matching/srg-deterministic.ts
698
691
  /**
699
692
  * Extract the SRG-OS ID from a requirement's tags.gtitle field.
700
693
  * Returns null if missing or not a string.
@@ -786,8 +779,7 @@ function createSrgDeterministicStrategy() {
786
779
  }
787
780
  };
788
781
  }
789
- //#endregion
790
- //#region src/matching/srg-cci-tiebreak.ts
782
+ // src/matching/srg-cci-tiebreak.ts
791
783
  /** Composite score weights matching SAF CLI's Tier 2. */
792
784
  const CCI_WEIGHT = .7;
793
785
  const TITLE_WEIGHT = .3;
@@ -956,8 +948,7 @@ function createSrgCciTiebreakStrategy() {
956
948
  }
957
949
  };
958
950
  }
959
- //#endregion
960
- //#region src/matching/vendor-fuzzy-title.ts
951
+ // src/matching/vendor-fuzzy-title.ts
961
952
  /** Default threshold for accepting a Levenshtein match. */
962
953
  const DEFAULT_ACCEPT_THRESHOLD = .45;
963
954
  const MAX_LEVENSHTEIN_LENGTH = 4096;
@@ -1126,8 +1117,7 @@ function createVendorFuzzyTitleStrategy(acceptThreshold) {
1126
1117
  }
1127
1118
  };
1128
1119
  }
1129
- //#endregion
1130
- //#region src/matching/index.ts
1120
+ // src/matching/index.ts
1131
1121
  /**
1132
1122
  * Create a strategy instance by name, using the provided options for
1133
1123
  * strategies that require configuration.
@@ -1178,8 +1168,7 @@ function matchRequirements(oldReqs, newReqs, options) {
1178
1168
  unmatchedNew: currentUnmatchedNew
1179
1169
  };
1180
1170
  }
1181
- //#endregion
1182
- //#region src/validate.ts
1171
+ // src/validate.ts
1183
1172
  /**
1184
1173
  * Validate a document against the hdf-comparison schema.
1185
1174
  *
@@ -1197,8 +1186,7 @@ function validateComparison(doc) {
1197
1186
  errors: result.errors.map((e) => e.field === "(root)" ? e.message : `${e.field}: ${e.message}`)
1198
1187
  };
1199
1188
  }
1200
- //#endregion
1201
- //#region src/diff.ts
1189
+ // src/diff.ts
1202
1190
  const DEFAULT_TRACKED_FIELDS = [
1203
1191
  "impact",
1204
1192
  "severity",
@@ -1392,6 +1380,27 @@ function diffFleet(referenceDoc, newResults, trackedFields, matchOpts) {
1392
1380
  function extractDrift(requirementDiffs) {
1393
1381
  return requirementDiffs.filter((r) => r.state === "unchanged" && r.changeReasons.length > 0).map((r) => ({ ...r }));
1394
1382
  }
1383
+ /** An id that sits in more than one baseline; parity: Go baselineMultiple. */
1384
+ const BASELINE_MULTIPLE = "(multiple)";
1385
+ /** Shared batch/fold attribution: differing baseline names are ambiguous. */
1386
+ function recordRequirementBaseline(map, id, name) {
1387
+ const existing = map.get(id);
1388
+ if (existing === void 0) map.set(id, name);
1389
+ else if (existing !== name && existing !== BASELINE_MULTIPLE) map.set(id, BASELINE_MULTIPLE);
1390
+ }
1391
+ function requirementBaselineMap(baselines) {
1392
+ const map = /* @__PURE__ */ new Map();
1393
+ for (const baseline of baselines) for (const req of baseline.requirements) {
1394
+ const id = req["id"];
1395
+ if (typeof id !== "string") continue;
1396
+ recordRequirementBaseline(map, id, baseline.name);
1397
+ }
1398
+ return map;
1399
+ }
1400
+ /** The new document's baseline for the id, else the old one's; undefined if neither. */
1401
+ function resolveBaseline(id, newMap, oldMap) {
1402
+ return newMap.get(id) ?? oldMap.get(id);
1403
+ }
1395
1404
  /**
1396
1405
  * Core pairwise comparison between two normalized HDF documents.
1397
1406
  * Returns baseline diffs and requirement diffs without sorting or wrapping.
@@ -1429,6 +1438,8 @@ function comparePair(oldNormalized, newNormalized, oldTimestamp, newTimestamp, t
1429
1438
  state: "new"
1430
1439
  });
1431
1440
  }
1441
+ const oldReqBaseline = requirementBaselineMap(oldBaselines);
1442
+ const newReqBaseline = requirementBaselineMap(newBaselines);
1432
1443
  const oldReqs = [];
1433
1444
  for (const baseline of oldBaselines) for (const req of baseline.requirements) oldReqs.push(req);
1434
1445
  const newReqs = [];
@@ -1448,6 +1459,7 @@ function comparePair(oldNormalized, newNormalized, oldTimestamp, newTimestamp, t
1448
1459
  requirementDiffs.push({
1449
1460
  id,
1450
1461
  title: newReq.title ?? oldReq.title,
1462
+ baseline: resolveBaseline(id, newReqBaseline, oldReqBaseline),
1451
1463
  state: diffState,
1452
1464
  oldEffectiveStatus: oldStatus,
1453
1465
  newEffectiveStatus: newStatus,
@@ -1468,6 +1480,7 @@ function comparePair(oldNormalized, newNormalized, oldTimestamp, newTimestamp, t
1468
1480
  requirementDiffs.push({
1469
1481
  id,
1470
1482
  title: oldReq.title,
1483
+ baseline: resolveBaseline(id, newReqBaseline, oldReqBaseline),
1471
1484
  state: "absent",
1472
1485
  oldEffectiveStatus: oldStatus,
1473
1486
  changeReasons: [],
@@ -1484,6 +1497,7 @@ function comparePair(oldNormalized, newNormalized, oldTimestamp, newTimestamp, t
1484
1497
  requirementDiffs.push({
1485
1498
  id,
1486
1499
  title: newReq.title,
1500
+ baseline: resolveBaseline(id, newReqBaseline, oldReqBaseline),
1487
1501
  state: "new",
1488
1502
  newEffectiveStatus: newStatus,
1489
1503
  changeReasons: [],
@@ -2124,7 +2138,7 @@ function diffSystems(oldSystem, newSystem, options) {
2124
2138
  if (systemFieldChanges.length > 0) extensions["systemFieldChanges"] = systemFieldChanges;
2125
2139
  const dataFlowChanges = diffDataFlows(oldSystem, newSystem);
2126
2140
  if (dataFlowChanges.length > 0) extensions["dataFlowChanges"] = dataFlowChanges;
2127
- if (Object.keys(extensions).length > 0) comparison.extensions = extensions;
2141
+ if (Object.keys(extensions).length > 0) comparison.extensions = { passthrough: extensions };
2128
2142
  if (options?.validateOutput) {
2129
2143
  const result = validateComparison(comparison);
2130
2144
  /* c8 ignore start */
@@ -2264,8 +2278,7 @@ function computeComponentFieldChanges(oldObj, newObj, trackedFields) {
2264
2278
  }
2265
2279
  return changes;
2266
2280
  }
2267
- //#endregion
2268
- //#region src/effective-checksum.ts
2281
+ // src/effective-checksum.ts
2269
2282
  /** Maps overrides onto the shared neutral selection shape (applied/expiry
2270
2283
  * window only; eligibility is passed separately). */
2271
2284
  function overrideWindows(overrides) {
@@ -2337,8 +2350,7 @@ async function computeEffectiveChecksum(requirement, referenceTimestamp) {
2337
2350
  value: await sha256(canonical)
2338
2351
  };
2339
2352
  }
2340
- //#endregion
2341
- //#region src/change-event.ts
2353
+ // src/change-event.ts
2342
2354
  /** Batch ChangeReason → event-vocabulary mapping; unmapped reasons are batch-only. */
2343
2355
  const EVENT_REASON_FOR = {
2344
2356
  resultChanged: "resultChanged",
@@ -2423,8 +2435,7 @@ async function changeEventFromPrevious(prev, newReq, prevReq, inputs) {
2423
2435
  after: newReq
2424
2436
  };
2425
2437
  }
2426
- //#endregion
2427
- //#region src/event-stream-common.ts
2438
+ // src/event-stream-common.ts
2428
2439
  /** Extract the priorChecksum hex from an event ('' when null/absent). */
2429
2440
  function eventPriorValue(ev) {
2430
2441
  return ev["priorChecksum"]?.value ?? "";
@@ -2497,8 +2508,7 @@ async function verifyEventChain(chain, seedReq, inSeed, keyWarn) {
2497
2508
  expected = await requirementChecksum(ev["after"], ev["timestamp"]);
2498
2509
  }
2499
2510
  }
2500
- //#endregion
2501
- //#region src/apply-events.ts
2511
+ // src/apply-events.ts
2502
2512
  function findRequirement(doc, id) {
2503
2513
  const baselines = doc["baselines"] ?? [];
2504
2514
  for (const baseline of baselines) {
@@ -2628,8 +2638,7 @@ async function applyChangeEvents(seedJson, events, inputs) {
2628
2638
  warnings
2629
2639
  };
2630
2640
  }
2631
- //#endregion
2632
- //#region src/fold-events.ts
2641
+ // src/fold-events.ts
2633
2642
  function findSeedRequirement(doc, id) {
2634
2643
  const baselines = doc["baselines"] ?? [];
2635
2644
  for (const baseline of baselines) {
@@ -2659,6 +2668,16 @@ async function foldChangeEventsIntoComparison(seedJson, events) {
2659
2668
  let maxOccurredMs = Number.NEGATIVE_INFINITY;
2660
2669
  let asOfFromEvents = "";
2661
2670
  let systemRef = "";
2671
+ let firstBaselineName = "";
2672
+ const baselineByReq = /* @__PURE__ */ new Map();
2673
+ for (const [i, baseline] of (doc["baselines"] ?? []).entries()) {
2674
+ const name = baseline["name"] ?? "";
2675
+ if (i === 0) firstBaselineName = name;
2676
+ for (const req of baseline["requirements"] ?? []) {
2677
+ const id = req["id"];
2678
+ if (typeof id === "string") recordRequirementBaseline(baselineByReq, id, name);
2679
+ }
2680
+ }
2662
2681
  for (const id of keys) {
2663
2682
  const chain = byKey.get(id) ?? [];
2664
2683
  const winner = chain[chain.length - 1];
@@ -2692,6 +2711,7 @@ async function foldChangeEventsIntoComparison(seedJson, events) {
2692
2711
  diffs.push({
2693
2712
  id,
2694
2713
  title: seedReq["title"],
2714
+ baseline: baselineByReq.get(id),
2695
2715
  state: "absent",
2696
2716
  oldEffectiveStatus: computeEffectiveStatus(seedReq, seedRef),
2697
2717
  changeReasons: [],
@@ -2713,6 +2733,7 @@ async function foldChangeEventsIntoComparison(seedJson, events) {
2713
2733
  diffs.push({
2714
2734
  id,
2715
2735
  title: after["title"],
2736
+ baseline: firstBaselineName || void 0,
2716
2737
  state: "new",
2717
2738
  newEffectiveStatus: newStatus,
2718
2739
  changeReasons: [],
@@ -2726,6 +2747,7 @@ async function foldChangeEventsIntoComparison(seedJson, events) {
2726
2747
  diffs.push({
2727
2748
  id,
2728
2749
  title: after["title"] ?? seedReq["title"],
2750
+ baseline: baselineByReq.get(id),
2729
2751
  state: winner["state"],
2730
2752
  oldEffectiveStatus: computeEffectiveStatus(seedReq, seedRef),
2731
2753
  newEffectiveStatus: newStatus,
@@ -2762,11 +2784,15 @@ async function foldChangeEventsIntoComparison(seedJson, events) {
2762
2784
  warnings
2763
2785
  };
2764
2786
  }
2765
- //#endregion
2766
- //#region src/exit-codes.ts
2787
+ // src/exit-codes.ts
2767
2788
  /** GNU diff compatible exit codes (--exit-code mode) */
2768
2789
  const EXIT_IDENTICAL = 0;
2769
2790
  const EXIT_DIFFERENCES = 1;
2791
+ /**
2792
+ * GNU diff's trouble code. The hdf CLI does not return it: a diff that fails to
2793
+ * run exits 1 like any failed operation, and 2 there means a usage error. Kept
2794
+ * for a caller that wants GNU's convention instead.
2795
+ */
2770
2796
  const EXIT_ERROR = 2;
2771
2797
  /** Detailed exit codes (--detailed-exitcode mode) */
2772
2798
  const EXIT_DETAILED_IDENTICAL = 0;
@@ -2783,8 +2809,8 @@ const EXIT_DETAILED_DRIFT_ONLY = 14;
2783
2809
  * 0 = identical (no differences found)
2784
2810
  * 1 = differences found (any kind)
2785
2811
  *
2786
- * Note: error (exit code 2) is not computed from the summary — callers
2787
- * should return EXIT_ERROR directly when I/O or parse errors occur.
2812
+ * Never EXIT_ERROR: a summary cannot describe a run that failed to produce one.
2813
+ * A caller that follows the hdf CLI returns 1 for such a failure, not EXIT_ERROR.
2788
2814
  */
2789
2815
  function computeExitCode(summary) {
2790
2816
  if (hasDifferences(summary)) return 1;
@@ -2801,8 +2827,8 @@ function computeExitCode(summary) {
2801
2827
  * 13 = differences found, only new/absent controls (baseline changed)
2802
2828
  * 14 = differences found, only metadata drift (no status changes)
2803
2829
  *
2804
- * Note: error (exit code 1) is not computed from the summary — callers
2805
- * should return EXIT_DETAILED_ERROR directly when I/O or parse errors occur.
2830
+ * Never EXIT_DETAILED_ERROR: callers return that themselves when a diff fails
2831
+ * to run, which matches the hdf CLI's 1 for a failed operation.
2806
2832
  *
2807
2833
  * Priority order: mixed(12) > regressions(11) > fixes(10) > baseline(13) > drift(14)
2808
2834
  */
@@ -2820,8 +2846,7 @@ function computeDetailedExitCode(summary) {
2820
2846
  function hasDifferences(summary) {
2821
2847
  return summary.total !== summary.unchanged;
2822
2848
  }
2823
- //#endregion
2824
- //#region src/renderers/filter.ts
2849
+ // src/renderers/filter.ts
2825
2850
  /**
2826
2851
  * Filter requirement diffs based on render options.
2827
2852
  *
@@ -2846,8 +2871,7 @@ function filterRequirements(diffs, options) {
2846
2871
  }
2847
2872
  return filtered;
2848
2873
  }
2849
- //#endregion
2850
- //#region src/renderers/json.ts
2874
+ // src/renderers/json.ts
2851
2875
  /**
2852
2876
  * Strip `before` and `after` from a RequirementDiff, keeping only
2853
2877
  * the summary fields (id, state, title, statuses, changeReasons, fieldChanges).
@@ -2886,8 +2910,7 @@ function renderJson(comparison, options) {
2886
2910
  requirementDiffs: strippedDiffs
2887
2911
  }, null, 2);
2888
2912
  }
2889
- //#endregion
2890
- //#region src/renderers/markdown.ts
2913
+ // src/renderers/markdown.ts
2891
2914
  /**
2892
2915
  * Render the summary table in markdown format.
2893
2916
  */
@@ -3000,8 +3023,7 @@ function renderMarkdown(comparison, options) {
3000
3023
  }
3001
3024
  return parts.join("\n");
3002
3025
  }
3003
- //#endregion
3004
- //#region src/renderers/terminal.ts
3026
+ // src/renderers/terminal.ts
3005
3027
  const RESET = "\x1B[0m";
3006
3028
  const GREEN = "\x1B[32m";
3007
3029
  const RED = "\x1B[31m";
@@ -3135,8 +3157,7 @@ function renderTerminal(comparison, options) {
3135
3157
  lines.push(buildSummaryLine(comparison, useColor));
3136
3158
  return lines.join("\n");
3137
3159
  }
3138
- //#endregion
3139
- //#region src/renderers/csv.ts
3160
+ // src/renderers/csv.ts
3140
3161
  /**
3141
3162
  * Escape a value for CSV output.
3142
3163
  *
@@ -3201,8 +3222,7 @@ function renderCsv(comparison, options) {
3201
3222
  }
3202
3223
  return lines.join("\n");
3203
3224
  }
3204
- //#endregion
3205
- //#region src/renderers/index.ts
3225
+ // src/renderers/index.ts
3206
3226
  /**
3207
3227
  * Convenience function to render a comparison in any supported format.
3208
3228
  *
@@ -3219,8 +3239,7 @@ function render(comparison, format, options) {
3219
3239
  case "csv": return renderCsv(comparison, options);
3220
3240
  }
3221
3241
  }
3222
- //#endregion
3223
- //#region src/sbom.ts
3242
+ // src/sbom.ts
3224
3243
  /**
3225
3244
  * Compare two SBOM documents (CycloneDX or SPDX JSON strings) and return
3226
3245
  * package-level diffs.
@@ -3377,7 +3396,6 @@ function buildPackageMap(packages) {
3377
3396
  }
3378
3397
  return map;
3379
3398
  }
3380
- //#endregion
3381
3399
  export { EXIT_DETAILED_BASELINE_CHANGED, EXIT_DETAILED_DRIFT_ONLY, EXIT_DETAILED_ERROR, EXIT_DETAILED_FIXES_ONLY, EXIT_DETAILED_IDENTICAL, EXIT_DETAILED_MIXED, EXIT_DETAILED_REGRESSIONS_ONLY, EXIT_DIFFERENCES, EXIT_ERROR, EXIT_IDENTICAL, applyChangeEvents, changeEventFromPrevious, classifyChangeReasons, classifyDiffStatus, computeDetailedExitCode, computeDisposition, computeEffectiveChecksum, computeEffectiveImpact, computeEffectiveStatus, computeExitCode, computeSummary, createCciMatchStrategy, createExactIdStrategy, createFuzzyTitleStrategy, createMappedIdStrategy, createSrgCciTiebreakStrategy, createSrgDeterministicStrategy, createVendorFuzzyTitleStrategy, diffBaselines, diffHdf, diffSboms, diffSystems, foldChangeEventsIntoComparison, isV1Format, jaccardSimilarity, levenshteinDistance, matchRequirements, normalizeToV2, normalizedLevenshtein, render, renderCsv, renderJson, renderMarkdown, renderTerminal, tokenize, validateComparison };
3382
3400
 
3383
3401
  //# sourceMappingURL=index.js.map