All checks were successful
CI/CD / go-lint (push) Has been skipped
CI/CD / python-lint (push) Has been skipped
CI/CD / nodejs-lint (push) Has been skipped
CI/CD / test-go-ai-compliance (push) Successful in 44s
CI/CD / test-python-backend-compliance (push) Successful in 33s
CI/CD / test-python-document-crawler (push) Successful in 22s
CI/CD / test-python-dsms-gateway (push) Successful in 19s
CI/CD / validate-canonical-controls (push) Successful in 13s
CI/CD / Deploy (push) Successful in 4s
Implements Phases 1-4 of the IACE Hazard-Matching-Engine: - 120 machine components (C001-C120) in 11 categories - 20 energy sources (EN01-EN20) - ~85 tag taxonomy across 5 domains - 44 hazard patterns with AND/NOT matching logic - Pattern engine with tag resolution and confidence scoring - 8 new API endpoints (component-library, energy-sources, tags, patterns, match/apply) - Completeness gate G09 for pattern matching - 320 tests passing (36 new) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
127 lines
4.1 KiB
Go
127 lines
4.1 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
|
|
}
|
|
|
|
for _, p := range GetBuiltinHazardPatterns() {
|
|
for _, cat := range p.GeneratedHazardCats {
|
|
if !validCategories[cat] {
|
|
t.Errorf("pattern %s references unknown hazard category %q", p.ID, cat)
|
|
}
|
|
}
|
|
}
|
|
}
|