Skip to content

Commit 5720eb0

Browse files
hjothahjothamendix
authored andcommitted
fix: parse legacy NewCaseValue sequence flows
Older Mendix project versions store a sequence flow's branch value in a single inline `NewCaseValue` document, while newer versions use the `CaseValues` array ([marker, case_object]). `parseSequenceFlow` only handled the new form, so opening a legacy MPR lost all true/false labels on decisions and every subsequent describe -> exec cycle rewrote them as default-case flows. Fall back to `parseCaseValue` on `NewCaseValue` when `CaseValues` is absent. Regression tests (parser_microflow_test.go) construct both shapes and assert the CaseValue makes it through parsing.
1 parent a2bc5b3 commit 5720eb0

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

sdk/mpr/parser_microflow.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,13 @@ func parseSequenceFlow(raw map[string]any) *microflows.SequenceFlow {
157157
flow.IsErrorHandler = isErr
158158
}
159159

160-
// Parse CaseValues if present (note: plural, stored as array [count, case_object, ...])
160+
// Parse decision branch values. Newer Mendix versions store branch data
161+
// in CaseValues ([marker, case]), while older projects use a single
162+
// inline NewCaseValue document.
161163
if caseVals := raw["CaseValues"]; caseVals != nil {
162164
flow.CaseValue = parseCaseValues(caseVals)
165+
} else if caseVal := raw["NewCaseValue"]; caseVal != nil {
166+
flow.CaseValue = parseCaseValue(caseVal)
163167
}
164168

165169
// Parse BezierCurve control vectors from Line

sdk/mpr/parser_microflow_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
package mpr
4+
5+
import (
6+
"testing"
7+
8+
"github.com/mendixlabs/mxcli/sdk/microflows"
9+
"go.mongodb.org/mongo-driver/bson/primitive"
10+
)
11+
12+
func TestParseSequenceFlow_NewCaseValueEnumerationCase(t *testing.T) {
13+
flow := parseSequenceFlow(map[string]any{
14+
"$ID": "flow-1",
15+
"OriginPointer": "start-1",
16+
"DestinationPointer": "dest-1",
17+
"OriginConnectionIndex": int32(1),
18+
"DestinationConnectionIndex": int32(2),
19+
"NewCaseValue": primitive.D{
20+
{Key: "$ID", Value: "case-1"},
21+
{Key: "$Type", Value: "Microflows$EnumerationCase"},
22+
{Key: "Value", Value: "true"},
23+
},
24+
})
25+
26+
got, ok := flow.CaseValue.(*microflows.EnumerationCase)
27+
if !ok {
28+
t.Fatalf("expected *EnumerationCase, got %T", flow.CaseValue)
29+
}
30+
if got.Value != "true" {
31+
t.Fatalf("expected true branch, got %q", got.Value)
32+
}
33+
}
34+
35+
func TestParseSequenceFlow_NewCaseValueNoCase(t *testing.T) {
36+
flow := parseSequenceFlow(map[string]any{
37+
"$ID": "flow-1",
38+
"OriginPointer": "start-1",
39+
"DestinationPointer": "dest-1",
40+
"NewCaseValue": primitive.D{
41+
{Key: "$ID", Value: "case-1"},
42+
{Key: "$Type", Value: "Microflows$NoCase"},
43+
},
44+
})
45+
46+
if _, ok := flow.CaseValue.(*microflows.NoCase); !ok {
47+
t.Fatalf("expected *NoCase, got %T", flow.CaseValue)
48+
}
49+
}

0 commit comments

Comments
 (0)