fix(iace): accumulate SuggestedMeasureIDs across dedup'd patterns
When multiple patterns match the same category+zone, the first creates the hazard and later patterns add their SuggestedMeasureIDs to the existing hazard. This ensures KSS-specific measures (M420) reach the hazard even if a generic pattern created it first. seenCatZone changed from map[string]bool to map[string]uuid.UUID to track which hazard ID was created for each dedupKey. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -160,32 +160,35 @@ func (h *IACEHandler) InitializeProject(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
created := 0
|
created := 0
|
||||||
seenCatZone := make(map[string]bool)
|
seenCatZone := make(map[string]uuid.UUID) // dedupKey → hazardID
|
||||||
catCount := make(map[string]int)
|
catCount := make(map[string]int)
|
||||||
for _, mp := range matchOutput.MatchedPatterns {
|
for _, mp := range matchOutput.MatchedPatterns {
|
||||||
// Narrative relevance filter: skip patterns whose zone/scenario
|
// Narrative relevance filter
|
||||||
// mentions machine-specific terms that don't appear in our components
|
|
||||||
if !isPatternRelevant(mp, narrativeText, compNames) {
|
if !isPatternRelevant(mp, narrativeText, compNames) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cat := range mp.HazardCats {
|
for _, cat := range mp.HazardCats {
|
||||||
// Per-category cap: limit hazards per category based on relevance
|
|
||||||
maxForCat := categoryHazardCap(cat, len(comps))
|
maxForCat := categoryHazardCap(cat, len(comps))
|
||||||
if catCount[cat] >= maxForCat {
|
if catCount[cat] >= maxForCat {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dedup by category + normalized zone
|
|
||||||
zoneKey := normalizeZoneKey(mp.ZoneDE)
|
zoneKey := normalizeZoneKey(mp.ZoneDE)
|
||||||
if zoneKey == "" {
|
if zoneKey == "" {
|
||||||
zoneKey = mp.PatternID
|
zoneKey = mp.PatternID
|
||||||
}
|
}
|
||||||
dedupKey := cat + ":" + zoneKey
|
dedupKey := cat + ":" + zoneKey
|
||||||
if seenCatZone[dedupKey] {
|
|
||||||
|
// If this dedupKey already exists but current pattern has
|
||||||
|
// SuggestedMeasureIDs, add them to the existing hazard
|
||||||
|
if existingHzID, exists := seenCatZone[dedupKey]; exists {
|
||||||
|
if len(mp.SuggestedMeasureIDs) > 0 {
|
||||||
|
existing := hazardPatternMeasures[existingHzID]
|
||||||
|
hazardPatternMeasures[existingHzID] = append(existing, mp.SuggestedMeasureIDs...)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seenCatZone[dedupKey] = true
|
|
||||||
|
|
||||||
name := mp.PatternName
|
name := mp.PatternName
|
||||||
if name == "" {
|
if name == "" {
|
||||||
@@ -226,8 +229,8 @@ func (h *IACEHandler) InitializeProject(c *gin.Context) {
|
|||||||
if cerr == nil {
|
if cerr == nil {
|
||||||
created++
|
created++
|
||||||
catCount[cat]++
|
catCount[cat]++
|
||||||
|
seenCatZone[dedupKey] = hz.ID
|
||||||
hazardIDsByCategory[cat] = append(hazardIDsByCategory[cat], hz.ID)
|
hazardIDsByCategory[cat] = append(hazardIDsByCategory[cat], hz.ID)
|
||||||
// Remember this pattern's suggested measures for this hazard
|
|
||||||
if len(mp.SuggestedMeasureIDs) > 0 {
|
if len(mp.SuggestedMeasureIDs) > 0 {
|
||||||
hazardPatternMeasures[hz.ID] = mp.SuggestedMeasureIDs
|
hazardPatternMeasures[hz.ID] = mp.SuggestedMeasureIDs
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user