feat(iace): add hazard-matching-engine with component library, tag system, and pattern engine
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
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>
This commit is contained in:
131
ai-compliance-sdk/internal/iace/component_library_test.go
Normal file
131
ai-compliance-sdk/internal/iace/component_library_test.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package iace
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestGetComponentLibrary_EntryCount verifies the component library has exactly 120 entries.
|
||||
func TestGetComponentLibrary_EntryCount(t *testing.T) {
|
||||
entries := GetComponentLibrary()
|
||||
if len(entries) != 120 {
|
||||
t.Fatalf("GetComponentLibrary returned %d entries, want 120", len(entries))
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetComponentLibrary_UniqueIDs verifies all component IDs are unique.
|
||||
func TestGetComponentLibrary_UniqueIDs(t *testing.T) {
|
||||
entries := GetComponentLibrary()
|
||||
seen := make(map[string]bool)
|
||||
for _, e := range entries {
|
||||
if e.ID == "" {
|
||||
t.Errorf("component has empty ID: %s", e.NameDE)
|
||||
}
|
||||
if seen[e.ID] {
|
||||
t.Errorf("duplicate component ID: %s", e.ID)
|
||||
}
|
||||
seen[e.ID] = true
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetComponentLibrary_ValidCategories verifies all categories are valid.
|
||||
func TestGetComponentLibrary_ValidCategories(t *testing.T) {
|
||||
validCats := make(map[string]bool)
|
||||
for _, c := range ValidComponentLibraryCategories() {
|
||||
validCats[c] = true
|
||||
}
|
||||
for _, e := range GetComponentLibrary() {
|
||||
if !validCats[e.Category] {
|
||||
t.Errorf("component %s has invalid category %q", e.ID, e.Category)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetComponentLibrary_NonEmptyFields verifies required fields are filled.
|
||||
func TestGetComponentLibrary_NonEmptyFields(t *testing.T) {
|
||||
for _, e := range GetComponentLibrary() {
|
||||
if e.NameDE == "" {
|
||||
t.Errorf("component %s: NameDE is empty", e.ID)
|
||||
}
|
||||
if e.NameEN == "" {
|
||||
t.Errorf("component %s: NameEN is empty", e.ID)
|
||||
}
|
||||
if e.MapsToComponentType == "" {
|
||||
t.Errorf("component %s: MapsToComponentType is empty", e.ID)
|
||||
}
|
||||
if len(e.Tags) == 0 {
|
||||
t.Errorf("component %s: Tags is empty", e.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetComponentLibrary_CategoryDistribution verifies expected category counts.
|
||||
func TestGetComponentLibrary_CategoryDistribution(t *testing.T) {
|
||||
counts := make(map[string]int)
|
||||
for _, e := range GetComponentLibrary() {
|
||||
counts[e.Category]++
|
||||
}
|
||||
expected := map[string]int{
|
||||
"mechanical": 20,
|
||||
"structural": 10,
|
||||
"drive": 10,
|
||||
"hydraulic": 10,
|
||||
"pneumatic": 10,
|
||||
"electrical": 10,
|
||||
"control": 10,
|
||||
"sensor": 10,
|
||||
"actuator": 10,
|
||||
"safety": 10,
|
||||
"it_network": 10,
|
||||
}
|
||||
for cat, want := range expected {
|
||||
got := counts[cat]
|
||||
if got != want {
|
||||
t.Errorf("category %s: got %d entries, want %d", cat, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetEnergySources_EntryCount verifies the energy source library has exactly 20 entries.
|
||||
func TestGetEnergySources_EntryCount(t *testing.T) {
|
||||
entries := GetEnergySources()
|
||||
if len(entries) != 20 {
|
||||
t.Fatalf("GetEnergySources returned %d entries, want 20", len(entries))
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetEnergySources_UniqueIDs verifies all energy source IDs are unique.
|
||||
func TestGetEnergySources_UniqueIDs(t *testing.T) {
|
||||
entries := GetEnergySources()
|
||||
seen := make(map[string]bool)
|
||||
for _, e := range entries {
|
||||
if e.ID == "" {
|
||||
t.Errorf("energy source has empty ID: %s", e.NameDE)
|
||||
}
|
||||
if seen[e.ID] {
|
||||
t.Errorf("duplicate energy source ID: %s", e.ID)
|
||||
}
|
||||
seen[e.ID] = true
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetEnergySources_NonEmptyFields verifies required fields are filled.
|
||||
func TestGetEnergySources_NonEmptyFields(t *testing.T) {
|
||||
for _, e := range GetEnergySources() {
|
||||
if e.NameDE == "" {
|
||||
t.Errorf("energy source %s: NameDE is empty", e.ID)
|
||||
}
|
||||
if e.NameEN == "" {
|
||||
t.Errorf("energy source %s: NameEN is empty", e.ID)
|
||||
}
|
||||
if len(e.Tags) == 0 {
|
||||
t.Errorf("energy source %s: Tags is empty", e.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetEnergySources_AllHaveTags verifies every energy source has at least one tag.
|
||||
func TestGetEnergySources_AllHaveTags(t *testing.T) {
|
||||
for _, e := range GetEnergySources() {
|
||||
if len(e.Tags) == 0 {
|
||||
t.Errorf("energy source %s has no tags", e.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user