Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix duplicated conditions when AS exists #515

Merged
merged 4 commits into from
Feb 22, 2024

Conversation

jmle
Copy link
Contributor

@jmle jmle commented Feb 21, 2024

The parser was generating a duplicate entry in the list of conditions.

Signed-off-by: Juan Manuel Leflet Estrada <[email protected]>
Signed-off-by: Juan Manuel Leflet Estrada <[email protected]>
Signed-off-by: Juan Manuel Leflet Estrada <[email protected]>
Signed-off-by: Juan Manuel Leflet Estrada <[email protected]>
Copy link
Contributor

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the system safer and fixing this bug!

@jmle jmle merged commit 51af72b into konveyor:main Feb 22, 2024
7 checks passed
@aufi
Copy link
Member

aufi commented Feb 22, 2024

It looks I worked on fixing similar issue in MTA-2006 (patch below), but fixing it directly in rule parsing instead of evaluating seems to be much better.

diff --git a/engine/conditions.go b/engine/conditions.go
index 59936c8..facd4e4 100644
--- a/engine/conditions.go
+++ b/engine/conditions.go
@@ -277,10 +277,11 @@ func incidentsToFilepaths(incident []IncidentContext) []string {
 
 func sortConditionEntries(entries []ConditionEntry) []ConditionEntry {
        sorted := []ConditionEntry{}
-       for _, e := range entries {
+       for i, e := range entries {
                // entries without chaining or that begin a chain come first
                if e.From == "" {
-                       sorted = append(sorted, gatherChain(e, entries)...)
+                       subEntries := append(entries[:i], entries[i+1:]...)
+                       sorted = append(sorted, gatherChain(e, subEntries)...)
                }
        }
 
@@ -289,9 +290,14 @@ func sortConditionEntries(entries []ConditionEntry) []ConditionEntry {
 
 func gatherChain(start ConditionEntry, entries []ConditionEntry) []ConditionEntry {
        chain := []ConditionEntry{start}
-       for _, d := range entries {
-               if start.As == d.From && start.As != "" {
-                       chain = append(chain, gatherChain(d, entries)...)
+       haveNext := false
+       for i, d := range entries {
+               if start.As == d.From && start.As != "" && !haveNext {
+                       subEntries := append(entries[:i], entries[i+1:]...)
+                       if d.From != start.From && d.As != start.As {
+                               chain = append(chain, gatherChain(d, subEntries)...)
+                               haveNext = true
+                       }
                }
        }
        return chain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants