Skip to content

Commit 767b9f8

Browse files
committed
test: use distinct IDs in nested sub-flow test to ensure recursive path
1 parent 7047e58 commit 767b9f8

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

mdl/backend/mpr/workflow_mutator_test.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,16 @@ func TestWorkflowMutator_SetActivityProperty_Page_MissingKey(t *testing.T) {
11791179
func TestWorkflowMutator_SetActivityProperty_Page_MissingKey_NestedSubFlow(t *testing.T) {
11801180
// Exercises the recursive replaceActivity path: the target activity lives
11811181
// inside an outcome's sub-flow, not at the top level.
1182-
nestedAct := makeWfActivity("Workflows$UserTask", "NestedReview", "nested1")
1182+
// Use distinct $IDs so replaceActivity cannot accidentally match the parent.
1183+
parentID := primitive.Binary{Subtype: 0x04, Data: []byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
1184+
nestedID := primitive.Binary{Subtype: 0x04, Data: []byte{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
1185+
1186+
nestedAct := bson.D{
1187+
{Key: "$ID", Value: nestedID},
1188+
{Key: "$Type", Value: "Workflows$UserTask"},
1189+
{Key: "Caption", Value: "NestedReview"},
1190+
{Key: "Name", Value: "nested1"},
1191+
}
11831192
// No TaskPage field at all on the nested activity.
11841193

11851194
outcome := bson.D{
@@ -1191,8 +1200,13 @@ func TestWorkflowMutator_SetActivityProperty_Page_MissingKey_NestedSubFlow(t *te
11911200
{Key: "Activities", Value: bson.A{int32(3), nestedAct}},
11921201
}},
11931202
}
1194-
parentAct := makeWfActivity("Workflows$Decision", "Check", "decision1")
1195-
parentAct = append(parentAct, bson.E{Key: "Outcomes", Value: bson.A{int32(3), outcome}})
1203+
parentAct := bson.D{
1204+
{Key: "$ID", Value: parentID},
1205+
{Key: "$Type", Value: "Workflows$Decision"},
1206+
{Key: "Caption", Value: "Check"},
1207+
{Key: "Name", Value: "decision1"},
1208+
{Key: "Outcomes", Value: bson.A{int32(3), outcome}},
1209+
}
11961210
m := newMutator(makeWorkflowDoc(parentAct))
11971211

11981212
if err := m.SetActivityProperty("NestedReview", 0, "PAGE", "MyModule.NestedPage"); err != nil {
@@ -1207,6 +1221,15 @@ func TestWorkflowMutator_SetActivityProperty_Page_MissingKey_NestedSubFlow(t *te
12071221
if got := dGetString(taskPage, "Page"); got != "MyModule.NestedPage" {
12081222
t.Errorf("Page = %q, want MyModule.NestedPage", got)
12091223
}
1224+
1225+
// Verify parent decision still has its Outcomes intact.
1226+
parentDoc, _ := m.findActivityByCaption("Check", 0)
1227+
if parentDoc == nil {
1228+
t.Fatal("parent decision activity should still exist")
1229+
}
1230+
if outcomes := dGet(parentDoc, "Outcomes"); outcomes == nil {
1231+
t.Fatal("parent decision Outcomes should still be present")
1232+
}
12101233
}
12111234

12121235
func TestWorkflowMutator_SetActivityProperty_Page_Existing(t *testing.T) {

0 commit comments

Comments
 (0)