Files
breakpilot-compliance/ai-compliance-sdk/internal/iace/hazard_patterns_test.go
T
Benjamin Admin 71d31c914b feat(iace): ISO 12100 Anhang B mapping — split noise/vibration + section identifier
Phase 16 of the Klaerungen / risk-assessment polish. Sources from
EN ISO 12100 Anhang B Tabelle B.1 are now first-class:

A) HazardPattern.ISO12100Section identifier (string), persisted only as
   the section number (e.g. "6.3.5.5") — not the norm text. Keeps the
   library urheberrechtlich neutral (DIN/Beuth license). 57 patterns
   labeled today; rest will follow on touch.

B) Category split per ISO 12100 Nr. 4 vs Nr. 5:
   - 16 patterns reclassified noise_vibration -> noise_hazard
   - 7  patterns reclassified noise_vibration -> vibration_hazard
   - 1  pattern (HP228 UV-/Laermexposition) kept multi-cat
   acceptableMeasureCategories now accepts both new aliases plus the
   legacy noise_vibration. Coverage test recognises both as valid.

C) 5 new ISO-12100-Annex-B gap patterns (HP1900-HP1904):
   - HP1900 Vakuum-Verletzung (6.3.5.5)
   - HP1901 Federenergie / elastische Elemente (6.2.10)
   - HP1902 Rutschen/Stolpern auf rauer Oberflaeche (6.3.5.6)
   - HP1903 Hochdruckinjektion (6.3.5.4) — includes clarifying
            "no hand-locating of leaks" question
   - HP1904 Ersticken durch Brustkorbquetschung (6.3.5.2)

The library now mirrors the ISO 12100 Annex B structure for the gaps
the Bremse benchmark surfaced.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-17 01:59:16 +02:00

134 lines
4.5 KiB
Go

package iace
import "testing"
// TestGetBuiltinHazardPatterns_UniqueIDs verifies all pattern IDs are unique.
func TestGetBuiltinHazardPatterns_UniqueIDs(t *testing.T) {
patterns := GetBuiltinHazardPatterns()
seen := make(map[string]bool)
for _, p := range patterns {
if p.ID == "" {
t.Errorf("pattern has empty ID: %s", p.NameDE)
}
if seen[p.ID] {
t.Errorf("duplicate pattern ID: %s", p.ID)
}
seen[p.ID] = true
}
}
// TestGetBuiltinHazardPatterns_Count verifies the expected number of patterns.
func TestGetBuiltinHazardPatterns_Count(t *testing.T) {
patterns := GetBuiltinHazardPatterns()
if len(patterns) < 40 {
t.Fatalf("expected at least 40 patterns, got %d", len(patterns))
}
}
// TestGetBuiltinHazardPatterns_AllHaveRequiredTags verifies every pattern has at
// least one required component tag or energy tag.
func TestGetBuiltinHazardPatterns_AllHaveRequiredTags(t *testing.T) {
for _, p := range GetBuiltinHazardPatterns() {
if len(p.RequiredComponentTags) == 0 && len(p.RequiredEnergyTags) == 0 {
t.Errorf("pattern %s (%s) has no required component or energy tags", p.ID, p.NameDE)
}
}
}
// TestGetBuiltinHazardPatterns_AllHaveGeneratedHazardCats verifies every pattern
// generates at least one hazard category.
func TestGetBuiltinHazardPatterns_AllHaveGeneratedHazardCats(t *testing.T) {
for _, p := range GetBuiltinHazardPatterns() {
if len(p.GeneratedHazardCats) == 0 {
t.Errorf("pattern %s (%s) has no generated hazard categories", p.ID, p.NameDE)
}
}
}
// TestGetBuiltinHazardPatterns_AllHaveSuggestedMeasures verifies every pattern
// suggests at least one measure.
func TestGetBuiltinHazardPatterns_AllHaveSuggestedMeasures(t *testing.T) {
for _, p := range GetBuiltinHazardPatterns() {
if len(p.SuggestedMeasureIDs) == 0 {
t.Errorf("pattern %s (%s) has no suggested measure IDs", p.ID, p.NameDE)
}
}
}
// TestGetBuiltinHazardPatterns_AllHaveSuggestedEvidence verifies every pattern
// suggests at least one evidence type.
func TestGetBuiltinHazardPatterns_AllHaveSuggestedEvidence(t *testing.T) {
for _, p := range GetBuiltinHazardPatterns() {
if len(p.SuggestedEvidenceIDs) == 0 {
t.Errorf("pattern %s (%s) has no suggested evidence IDs", p.ID, p.NameDE)
}
}
}
// TestGetBuiltinHazardPatterns_ValidPriorities verifies all priorities are 1-100.
func TestGetBuiltinHazardPatterns_ValidPriorities(t *testing.T) {
for _, p := range GetBuiltinHazardPatterns() {
if p.Priority < 1 || p.Priority > 100 {
t.Errorf("pattern %s has invalid priority %d (want 1-100)", p.ID, p.Priority)
}
}
}
// TestGetBuiltinHazardPatterns_ReferencedMeasuresExist verifies all referenced
// measure IDs exist in the protective measures library.
func TestGetBuiltinHazardPatterns_ReferencedMeasuresExist(t *testing.T) {
measureIDs := make(map[string]bool)
for _, m := range GetProtectiveMeasureLibrary() {
measureIDs[m.ID] = true
}
for _, p := range GetBuiltinHazardPatterns() {
for _, mid := range p.SuggestedMeasureIDs {
if !measureIDs[mid] {
t.Errorf("pattern %s references non-existent measure ID %s", p.ID, mid)
}
}
}
}
// TestGetBuiltinHazardPatterns_ReferencedEvidenceExist verifies all referenced
// evidence IDs exist in the evidence type library.
func TestGetBuiltinHazardPatterns_ReferencedEvidenceExist(t *testing.T) {
evidenceIDs := make(map[string]bool)
for _, e := range GetEvidenceTypeLibrary() {
evidenceIDs[e.ID] = true
}
for _, p := range GetBuiltinHazardPatterns() {
for _, eid := range p.SuggestedEvidenceIDs {
if !evidenceIDs[eid] {
t.Errorf("pattern %s references non-existent evidence ID %s", p.ID, eid)
}
}
}
}
// TestGetBuiltinHazardPatterns_HazardCategoriesValid verifies all generated
// hazard categories match known categories in the hazard library.
func TestGetBuiltinHazardPatterns_HazardCategoriesValid(t *testing.T) {
validCategories := make(map[string]bool)
for _, h := range GetBuiltinHazardLibrary() {
validCategories[h.Category] = true
}
// ISO 12100 Annex B splits Nr. 4 Laerm and Nr. 5 Vibration into two
// top-level groups. Patterns adopted this in 2026-05 but the hazard
// library still carries entries under the legacy combined "noise_-
// vibration" key. Until the library is split, both new aliases are
// recognised as valid pattern categories.
validCategories["noise_hazard"] = true
validCategories["vibration_hazard"] = true
for _, p := range GetBuiltinHazardPatterns() {
for _, cat := range p.GeneratedHazardCats {
if !validCategories[cat] {
t.Errorf("pattern %s references unknown hazard category %q", p.ID, cat)
}
}
}
}