fix(iace): set-based measure-category filter + 235 pattern-author fixes

Two-part nachhaltiger fix replacing the previous "fill to 5 mitigations
no matter what" behavior that the GT-Bremse benchmark proved
unfaithful (e.g. HP1625 "scharfe Kanten" returning M005 "Rotations-
bewegung vermeiden" via category fallback; HP1651 "Wiederanlauf
Roboter" returning M054 "Sichere thermische Auslegung" via
mismatched pattern reference).

PART A — Set-based category filter (handlers package):
- acceptableMeasureCategories: replaces 1:1 patternCatToMeasureCat
  with a curated set per pattern category, so e.g.
  safety_function_failure now accepts software_control measures
  (watchdogs, plausibility checks) and emc_hazard accepts both
  electrical and software_control measures
- isCategoryCompatible: gate every measure id against the accepted
  set before creating a mitigation; mismatches log MEASURE-SKIP
- The old category fallback is REMOVED. A hazard whose pattern has
  no category-compatible measure is now created with zero mitigations
  and logged as COVERAGE-GAP — the operator must consult an expert.
  No more silent invention of generic defaults.

PART B — 235 pattern author-error fixes across 26 files:
- HP040-HP044 (AI): M101/M102/M103 (Auffangwanne/Absauganlage) ->
  M133 Anomalieerkennung + M214 Plausibilitaet + M213 Sensor-Redundanz
  + M044 Zweikanalige Steuerung + others
- HP011-HP015, HP104-HP109, HP1085-HP1095, HP1281-HP1334 (electrical):
  M001-M005/M054/M061 placeholders -> M481/M482 Isolation +
  M511-M522 PE/Schutzleiter/RCD/Hauptschalter
- HP110-HP1331 (material_environmental): M101-M103 -> M384-M395
  Brandschutz/Laserschutz + M533/M408 SDB/PSA
- HP800-HP858, HP1178-HP1264 (software/sensor/hmi):
  M101/M104 -> M105/M106/M107/M214 SPS/Watchdog/Plausibilitaet
- HP026, HP611-HP1690 (ergonomic): M001/M082 -> M353-M360 +
  M530-M532 Hebehilfe/ergonomische Hoehe
- HP201-HP1697 (mechanical): M054/M051 -> M002/M008/M061/M141 +
  M487/M488 Tueroeffnung-Stillsetzung/Wiederanlauf
- Plus EMF/Strahlung/Brand/Lärm/Vibration/Kommunikation/Cyber

Coverage shift (Pattern-Author-Fehler bei aktiviertem Set-Filter):
   start:         237 patterns with zero category-compatible measures
   after Stufe 1A:   5 (AI)
   after Stufe 1B:  20 (mechanical Bestand)
   after Stufe 1C:  35 (electrical Bestand)
   after Stufe 1D:  29 (material_environmental)
   after Stufe 1E:  29 (software/sensor/hmi)
   after Stufe 1F:  20 (ergonomic)
   after Stufe 1G:  80 (thermal/comm/radiation/fire/safety)
   final:           0  (28 extended.go/extended2.go duplicates fixed)

New regression tests:
- TestEveryPattern_HasCategoryCompatibleMeasure: every pattern in
  collectAllPatterns() must reference at least one category-compatible
  measure; gaps must be explicitly listed in AllowlistKnownGaps
  (currently empty). Fails CI for any new pattern that drifts.
- TestAcceptableMeasureCategories: pins the set-mapping for the
  7 most-bug-prone pattern categories.
- TestIsCategoryCompatible_EmptyMeasureCat: protects legacy entries.

A separate task #11 tracks 58 HP-ID duplicates between
extended.go/extended2.go and cobot.go/press.go/operational.go —
patterns are semantically different and TestGetBuiltinHazardPatterns_-
UniqueIDs misses them because it only checks HP001-HP044.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-05-16 21:11:02 +02:00
parent 938f9a6c51
commit 6a3e96d54c
36 changed files with 549 additions and 273 deletions
@@ -17,7 +17,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"electrical_energy"},
RequiredLifecycles: []string{"maintenance"},
GeneratedHazardCats: []string{"mechanical_hazard"},
SuggestedMeasureIDs: []string{"M121"},
SuggestedMeasureIDs: []string{"M141"},
SuggestedEvidenceIDs: []string{"E21"},
Priority: 80,
// Source: R341
@@ -28,7 +28,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"kinetic"},
RequiredLifecycles: []string{"operation"},
GeneratedHazardCats: []string{"mechanical_hazard"},
SuggestedMeasureIDs: []string{"M106"},
SuggestedMeasureIDs: []string{"M141"},
SuggestedEvidenceIDs: []string{"E08"},
Priority: 80,
// Source: R340
@@ -39,7 +39,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{},
RequiredLifecycles: []string{"operation"},
GeneratedHazardCats: []string{"ai_misclassification"},
SuggestedMeasureIDs: []string{"M103"},
SuggestedMeasureIDs: []string{"M133", "M227", "M141"},
SuggestedEvidenceIDs: []string{"E15"},
Priority: 75,
// Source: R590, R1090
@@ -50,7 +50,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"electrical_energy"},
RequiredLifecycles: []string{"installation", "operation"},
GeneratedHazardCats: []string{"electrical_hazard"},
SuggestedMeasureIDs: []string{"M062"},
SuggestedMeasureIDs: []string{"M481", "M141"},
SuggestedEvidenceIDs: []string{"E20"},
Priority: 80,
// Source: R065, R570, R1070
@@ -61,7 +61,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"electrical_energy"},
RequiredLifecycles: []string{"installation", "operation"},
GeneratedHazardCats: []string{"electrical_hazard"},
SuggestedMeasureIDs: []string{"M062"},
SuggestedMeasureIDs: []string{"M481", "M141"},
SuggestedEvidenceIDs: []string{"E20"},
Priority: 80,
// Source: R317, R318
@@ -72,7 +72,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"electrical_energy"},
RequiredLifecycles: []string{"operation"},
GeneratedHazardCats: []string{"ai_misclassification"},
SuggestedMeasureIDs: []string{"M082"},
SuggestedMeasureIDs: []string{"M133", "M227", "M141"},
SuggestedEvidenceIDs: []string{"E20"},
Priority: 75,
// Source: R074, R328
@@ -105,7 +105,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"electrical_energy"},
RequiredLifecycles: []string{"maintenance", "operation"},
GeneratedHazardCats: []string{"electrical_hazard"},
SuggestedMeasureIDs: []string{"M061", "M063", "M121"},
SuggestedMeasureIDs: []string{"M481", "M482", "M141"},
SuggestedEvidenceIDs: []string{"E10", "E20"},
Priority: 80,
// Source: R061, R062, R315, R316, R566, R567, R1066, R1067
@@ -127,7 +127,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"electrical_energy"},
RequiredLifecycles: []string{"restart"},
GeneratedHazardCats: []string{"mechanical_hazard"},
SuggestedMeasureIDs: []string{"M106"},
SuggestedMeasureIDs: []string{"M061", "M141"},
SuggestedEvidenceIDs: []string{"E08"},
Priority: 80,
// Source: R339, R598, R1098
@@ -138,7 +138,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"kinetic"},
RequiredLifecycles: []string{"automatic_operation", "cleaning", "operation"},
GeneratedHazardCats: []string{"mechanical_hazard"},
SuggestedMeasureIDs: []string{"M051", "M054", "M121"},
SuggestedMeasureIDs: []string{"M061", "M002", "M141"},
SuggestedEvidenceIDs: []string{"E20", "E21"},
Priority: 80,
// Source: R053, R054, R556, R557, R1056, R1057
@@ -149,7 +149,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"kinetic"},
RequiredLifecycles: []string{"cleaning", "operation"},
GeneratedHazardCats: []string{"mechanical_hazard"},
SuggestedMeasureIDs: []string{"M051", "M054", "M121"},
SuggestedMeasureIDs: []string{"M061", "M002", "M141"},
SuggestedEvidenceIDs: []string{"E20", "E21"},
Priority: 80,
// Source: R305, R306
@@ -160,7 +160,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"thermal"},
RequiredLifecycles: []string{"operation"},
GeneratedHazardCats: []string{"thermal_hazard"},
SuggestedMeasureIDs: []string{"M022"},
SuggestedMeasureIDs: []string{"M141"},
SuggestedEvidenceIDs: []string{"E14"},
Priority: 70,
// Source: R581, R1081
@@ -182,7 +182,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{},
RequiredLifecycles: []string{"operation"},
GeneratedHazardCats: []string{"software_fault"},
SuggestedMeasureIDs: []string{"M103"},
SuggestedMeasureIDs: []string{"M105", "M141"},
SuggestedEvidenceIDs: []string{"E14"},
Priority: 70,
// Source: R596, R1096
@@ -193,7 +193,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{},
RequiredLifecycles: []string{"operation"},
GeneratedHazardCats: []string{"unauthorized_access"},
SuggestedMeasureIDs: []string{"M116"},
SuggestedMeasureIDs: []string{"M188", "M186", "M141"},
SuggestedEvidenceIDs: []string{"E16"},
Priority: 85,
// Source: R587, R1087
@@ -204,7 +204,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{},
RequiredLifecycles: []string{"software_update"},
GeneratedHazardCats: []string{"update_failure"},
SuggestedMeasureIDs: []string{"M104"},
SuggestedMeasureIDs: []string{"M188", "M186", "M141"},
SuggestedEvidenceIDs: []string{"E18"},
Priority: 70,
// Source: R338, R597, R1097
@@ -215,7 +215,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"thermal"},
RequiredLifecycles: []string{"operation"},
GeneratedHazardCats: []string{"thermal_hazard"},
SuggestedMeasureIDs: []string{"M015"},
SuggestedMeasureIDs: []string{"M141"},
SuggestedEvidenceIDs: []string{"E20"},
Priority: 70,
// Source: R326, R580, R1080
@@ -226,7 +226,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"thermal"},
RequiredLifecycles: []string{"operation"},
GeneratedHazardCats: []string{"thermal_hazard"},
SuggestedMeasureIDs: []string{"M015"},
SuggestedMeasureIDs: []string{"M141"},
SuggestedEvidenceIDs: []string{"E20"},
Priority: 70,
// Source: R072
@@ -248,7 +248,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"thermal"},
RequiredLifecycles: []string{"operation"},
GeneratedHazardCats: []string{"thermal_hazard"},
SuggestedMeasureIDs: []string{"M015"},
SuggestedMeasureIDs: []string{"M141"},
SuggestedEvidenceIDs: []string{"E10"},
Priority: 70,
// Source: R071, R325, R579, R1079
@@ -325,7 +325,7 @@ func getExtendedHazardPatternsA() []HazardPattern {
RequiredEnergyTags: []string{"hydraulic_pressure"},
RequiredLifecycles: []string{"operation"},
GeneratedHazardCats: []string{"pneumatic_hydraulic"},
SuggestedMeasureIDs: []string{"M022"},
SuggestedMeasureIDs: []string{"M522", "M539", "M141"},
SuggestedEvidenceIDs: []string{"E14"},
Priority: 70,
// Source: R574, R1074