forked from mendixlabs/mxcli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroundtrip_microflow_test.go
More file actions
631 lines (527 loc) · 19.1 KB
/
roundtrip_microflow_test.go
File metadata and controls
631 lines (527 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
// SPDX-License-Identifier: Apache-2.0
//go:build integration
package executor
import (
"fmt"
"strings"
"testing"
)
// --- CALL Statement Parameter Tests ---
// These tests verify the unified parameter syntax for CALL statements.
// TestRoundtripMicroflow_CallWithUnifiedParams tests CALL with parameter names without $.
func TestRoundtripMicroflow_CallWithUnifiedParams(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
microflowName := testModule + ".TestCallParamsMf"
env.registerCleanup("microflow", microflowName)
// First create a simple microflow to call
createMfMDL := `CREATE MICROFLOW ` + microflowName + ` ($Input: String) RETURNS String
BEGIN
RETURN $Input;
END;`
if err := env.executeMDL(createMfMDL); err != nil {
t.Fatalf("Failed to create microflow: %v", err)
}
// Create a calling microflow that uses unified parameter syntax (no $ on param names)
callerName := testModule + ".TestCallParamsCaller"
env.registerCleanup("microflow", callerName)
createCallerMDL := `CREATE MICROFLOW ` + callerName + ` () RETURNS String
BEGIN
$Result = CALL MICROFLOW ` + microflowName + ` (Input = 'Hello World');
RETURN $Result;
END;`
if err := env.executeMDL(createCallerMDL); err != nil {
t.Fatalf("Failed to create calling microflow with unified param syntax: %v", err)
}
// Describe the caller microflow to verify it was created
output, err := env.describeMDL(`DESCRIBE MICROFLOW ` + callerName + `;`)
if err != nil {
t.Fatalf("Failed to describe microflow: %v", err)
}
// Verify microflow was created (DESCRIBE may not fully output all activities)
if !containsProperty(output, "MICROFLOW") {
t.Error("Expected MICROFLOW in output")
}
// Note: DESCRIBE may not output all activities, so we just verify creation succeeded
if containsProperty(output, "CALL") {
t.Log("CALL activity found in DESCRIBE output (good!)")
} else {
t.Log("Note: CALL activity not shown in DESCRIBE output (known limitation)")
}
t.Logf("CALL with unified params roundtrip successful:\n%s", output)
}
// TestRoundtripMicroflow_LogWithTemplate tests LOG statement with WITH template syntax.
func TestRoundtripMicroflow_LogWithTemplate(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
microflowName := testModule + ".TestLogTemplate"
env.registerCleanup("microflow", microflowName)
// Create microflow with LOG using WITH syntax
createMDL := `CREATE MICROFLOW ` + microflowName + ` ($OrderNumber: String, $CustomerName: String) RETURNS Boolean
BEGIN
LOG INFO NODE 'OrderService' 'Processing order {1} for customer {2}' WITH ({1} = $OrderNumber, {2} = $CustomerName);
RETURN true;
END;`
if err := env.executeMDL(createMDL); err != nil {
t.Fatalf("Failed to create microflow with LOG template: %v", err)
}
// Describe the microflow
output, err := env.describeMDL(`DESCRIBE MICROFLOW ` + microflowName + `;`)
if err != nil {
t.Fatalf("Failed to describe microflow: %v", err)
}
// Verify LOG statement with WITH clause
if !containsProperty(output, "LOG INFO NODE") {
t.Error("Expected LOG INFO NODE in output")
}
if !containsProperty(output, "Processing order {1}") {
t.Error("Expected template text 'Processing order {1}' in output")
}
if !containsProperty(output, "WITH") {
t.Error("Expected WITH clause in output")
}
if !containsProperty(output, "$OrderNumber") {
t.Error("Expected $OrderNumber parameter in output")
}
if !containsProperty(output, "$CustomerName") {
t.Error("Expected $CustomerName parameter in output")
}
t.Logf("LOG with template roundtrip successful:\n%s", output)
}
// --- DESCRIBE MICROFLOW Roundtrip Tests ---
// These tests verify that DESCRIBE MICROFLOW produces correct output for various
// microflow patterns. They serve as regression guards for bugs in findBranchFlows
// and traverseFlowUntilMerge (commit 7459949a).
// assertMicroflowContains is a helper that creates a microflow, describes it,
// and asserts the output contains all expected strings.
func assertMicroflowContains(t *testing.T, env *testEnv, mfName, createMDL string, wantContains []string, wantNotContains []string) {
t.Helper()
if err := env.executeMDL(createMDL); err != nil {
t.Fatalf("Failed to create microflow %s: %v", mfName, err)
}
output, err := env.describeMDL(fmt.Sprintf("DESCRIBE MICROFLOW %s;", mfName))
if err != nil {
t.Fatalf("Failed to describe microflow %s: %v", mfName, err)
}
for _, want := range wantContains {
if !strings.Contains(output, want) {
t.Errorf("Expected %q in output, got:\n%s", want, output)
}
}
for _, notWant := range wantNotContains {
if strings.Contains(output, notWant) {
t.Errorf("Did not expect %q in output, got:\n%s", notWant, output)
}
}
t.Logf("DESCRIBE output for %s:\n%s", mfName, output)
}
// TestRoundtripMicroflow_IfElseWithBody is the primary regression test for the
// IF/ELSE body bugs: pointer type matching in findBranchFlows and shared visited
// map in traverseFlowUntilMerge.
func TestRoundtripMicroflow_IfElseWithBody(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
mfName := testModule + ".RT_IfElseBody"
createMDL := `CREATE MICROFLOW ` + mfName + ` ($Count: Integer) RETURNS String
BEGIN
DECLARE $Result String = 'unknown';
IF $Count > 10 THEN
SET $Result = 'high';
ELSE
SET $Result = 'low';
END IF;
RETURN $Result;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"IF", "THEN", "ELSE", "END IF", "'high'", "'low'", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_NestedIfElse exercises traverseFlowUntilMerge recursion
// with nested exclusive splits.
func TestRoundtripMicroflow_NestedIfElse(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
mfName := testModule + ".RT_NestedIf"
createMDL := `CREATE MICROFLOW ` + mfName + ` ($X: Integer) RETURNS String
BEGIN
DECLARE $Msg String = 'none';
IF $X > 0 THEN
IF $X > 100 THEN
SET $Msg = 'very high';
ELSE
SET $Msg = 'moderate';
END IF;
ELSE
SET $Msg = 'negative';
END IF;
RETURN $Msg;
END;`
if err := env.executeMDL(createMDL); err != nil {
t.Fatalf("Failed to create microflow: %v", err)
}
output, err := env.describeMDL(fmt.Sprintf("DESCRIBE MICROFLOW %s;", mfName))
if err != nil {
t.Fatalf("Failed to describe microflow: %v", err)
}
// Must have at least 2 END IF for the nested structure
if count := strings.Count(output, "END IF"); count < 2 {
t.Errorf("Expected at least 2 'END IF' occurrences, got %d in:\n%s", count, output)
}
for _, want := range []string{"'very high'", "'moderate'", "'negative'", "RETURN"} {
if !strings.Contains(output, want) {
t.Errorf("Expected %q in output, got:\n%s", want, output)
}
}
t.Logf("DESCRIBE output for %s:\n%s", mfName, output)
}
// TestRoundtripMicroflow_IfWithoutElse tests TRUE-only branch (no ELSE).
// Note: DESCRIBE always emits an empty ELSE block because Mendix stores both
// branches internally. The key assertion is that the TRUE branch body is present.
func TestRoundtripMicroflow_IfWithoutElse(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
mfName := testModule + ".RT_IfNoElse"
createMDL := `CREATE MICROFLOW ` + mfName + ` ($Active: Boolean) RETURNS Boolean
BEGIN
IF $Active THEN
LOG INFO NODE 'Test' 'Item is active';
END IF;
RETURN $Active;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"IF", "END IF", "LOG INFO", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_LinearDeclareSetReturn tests the simplest linear flow.
func TestRoundtripMicroflow_LinearDeclareSetReturn(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
mfName := testModule + ".RT_LinearFlow"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Integer
BEGIN
DECLARE $Value Integer = 0;
SET $Value = 42;
RETURN $Value;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"DECLARE", "$Value", "Integer", "SET $Value = 42", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_CreateChangeDelete tests entity CRUD in a microflow.
func TestRoundtripMicroflow_CreateChangeDelete(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
// Create prerequisite entity
if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY RoundtripTest.MfTestItem (Name: String(100));`); err != nil {
t.Fatalf("Failed to create entity: %v", err)
}
mfName := testModule + ".RT_CRUD"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
$Item = CREATE RoundtripTest.MfTestItem (Name = 'test');
CHANGE $Item (Name = 'updated');
DELETE $Item;
RETURN true;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"CREATE RoundtripTest.MfTestItem", "CHANGE $Item", "DELETE $Item", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_Retrieve tests database retrieve.
func TestRoundtripMicroflow_Retrieve(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
// Create prerequisite entity
if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY RoundtripTest.MfTestItem (Name: String(100));`); err != nil {
t.Fatalf("Failed to create entity: %v", err)
}
mfName := testModule + ".RT_Retrieve"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
RETRIEVE $Items FROM RoundtripTest.MfTestItem;
RETURN true;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"RETRIEVE", "RoundtripTest.MfTestItem", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_RetrieveWithLimit tests RETRIEVE with LIMIT clause roundtrip.
// Regression test for commit 584aa678 (parseRange LimitExpression extraction).
func TestRoundtripMicroflow_RetrieveWithLimit(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY RoundtripTest.MfTestItem (Name: String(100));`); err != nil {
t.Fatalf("Failed to create entity: %v", err)
}
mfName := testModule + ".RT_RetrieveLimit"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
RETRIEVE $Item FROM RoundtripTest.MfTestItem
LIMIT 1;
RETURN true;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"RETRIEVE", "RoundtripTest.MfTestItem", "LIMIT 1", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_RetrieveWithLimitOffset tests RETRIEVE with LIMIT and OFFSET roundtrip.
// Regression test for commit 584aa678 (parseRange OffsetExpression extraction).
func TestRoundtripMicroflow_RetrieveWithLimitOffset(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY RoundtripTest.MfTestItem (Name: String(100));`); err != nil {
t.Fatalf("Failed to create entity: %v", err)
}
mfName := testModule + ".RT_RetrieveLimitOffset"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
RETRIEVE $Items FROM RoundtripTest.MfTestItem
LIMIT 2
OFFSET 3;
RETURN true;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"RETRIEVE", "RoundtripTest.MfTestItem", "LIMIT 2", "OFFSET 3", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_RetrieveWithSortBy tests RETRIEVE with SORT BY roundtrip.
// Regression test for commit fd8610e1 (NewSortings BSON field name).
func TestRoundtripMicroflow_RetrieveWithSortBy(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY RoundtripTest.MfTestItem (Name: String(100));`); err != nil {
t.Fatalf("Failed to create entity: %v", err)
}
mfName := testModule + ".RT_RetrieveSort"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
RETRIEVE $Items FROM RoundtripTest.MfTestItem
SORT BY RoundtripTest.MfTestItem.Name ASC;
RETURN true;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"RETRIEVE", "RoundtripTest.MfTestItem", "SORT BY", "Name ASC", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_RetrieveWithWhereSortLimitOffset tests the full RETRIEVE
// pattern with WHERE, SORT BY, LIMIT, and OFFSET — matching the M028_DataForm_Getter pattern.
func TestRoundtripMicroflow_RetrieveWithWhereSortLimitOffset(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY RoundtripTest.MfTestItem (Name: String(100));`); err != nil {
t.Fatalf("Failed to create entity: %v", err)
}
mfName := testModule + ".RT_RetrieveFull"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
RETRIEVE $Items FROM RoundtripTest.MfTestItem
WHERE (starts-with(Name, 'a'))
SORT BY RoundtripTest.MfTestItem.Name ASC
LIMIT 2
OFFSET 3;
RETURN true;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{
"RETRIEVE", "RoundtripTest.MfTestItem",
"starts-with", "Name",
"SORT BY", "Name ASC",
"LIMIT 2", "OFFSET 3",
"RETURN",
},
nil,
)
}
// TestRoundtripMicroflow_LoopWithBody tests LOOP iteration with activities inside.
func TestRoundtripMicroflow_LoopWithBody(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
// Create prerequisite entity
if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY RoundtripTest.MfTestItem (Name: String(100));`); err != nil {
t.Fatalf("Failed to create entity: %v", err)
}
mfName := testModule + ".RT_Loop"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
RETRIEVE $Items FROM RoundtripTest.MfTestItem;
LOOP $Item IN $Items BEGIN
LOG INFO NODE 'Test' 'Processing item';
END LOOP;
RETURN true;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"LOOP", "$Items", "LOG INFO", "END LOOP", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_ValidationFeedback tests VALIDATION FEEDBACK statement
// which triggered a crash bug with nil settings.
func TestRoundtripMicroflow_ValidationFeedback(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
// Create prerequisite entity
if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY RoundtripTest.MfValItem (Email: String(200));`); err != nil {
t.Fatalf("Failed to create entity: %v", err)
}
mfName := testModule + ".RT_Validation"
createMDL := `CREATE MICROFLOW ` + mfName + ` ($ValItem: RoundtripTest.MfValItem) RETURNS Boolean
BEGIN
VALIDATION FEEDBACK $ValItem/Email MESSAGE 'Email is required';
RETURN false;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"VALIDATION FEEDBACK", "Email", "Email is required", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_MultipleReturnPaths tests RETURN in both IF/ELSE branches.
func TestRoundtripMicroflow_MultipleReturnPaths(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
mfName := testModule + ".RT_MultiReturn"
createMDL := `CREATE MICROFLOW ` + mfName + ` ($Flag: Boolean) RETURNS String
BEGIN
IF $Flag THEN
RETURN 'yes';
ELSE
RETURN 'no';
END IF;
END;`
if err := env.executeMDL(createMDL); err != nil {
t.Fatalf("Failed to create microflow: %v", err)
}
output, err := env.describeMDL(fmt.Sprintf("DESCRIBE MICROFLOW %s;", mfName))
if err != nil {
t.Fatalf("Failed to describe microflow: %v", err)
}
if count := strings.Count(output, "RETURN"); count < 2 {
t.Errorf("Expected at least 2 'RETURN' occurrences, got %d in:\n%s", count, output)
}
for _, want := range []string{"ELSE", "END IF"} {
if !strings.Contains(output, want) {
t.Errorf("Expected %q in output, got:\n%s", want, output)
}
}
t.Logf("DESCRIBE output for %s:\n%s", mfName, output)
}
// TestRoundtripMicroflow_CommitWithEvents tests COMMIT with WITH EVENTS flag.
func TestRoundtripMicroflow_CommitWithEvents(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
// Create prerequisite entity
if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY RoundtripTest.MfCommitItem (Status: String(50));`); err != nil {
t.Fatalf("Failed to create entity: %v", err)
}
mfName := testModule + ".RT_Commit"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
$Obj = CREATE RoundtripTest.MfCommitItem;
COMMIT $Obj WITH EVENTS;
RETURN true;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"COMMIT", "WITH EVENTS", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_ErrorHandlingContinue tests ON ERROR CONTINUE.
func TestRoundtripMicroflow_ErrorHandlingContinue(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
// Create prerequisite entity
if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY RoundtripTest.MfCommitItem (Status: String(50));`); err != nil {
t.Fatalf("Failed to create entity: %v", err)
}
mfName := testModule + ".RT_ErrorHandling"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
$Obj = CREATE RoundtripTest.MfCommitItem;
COMMIT $Obj ON ERROR CONTINUE;
RETURN true;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"COMMIT", "ON ERROR CONTINUE", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_Annotate tests @annotation roundtrip.
func TestRoundtripMicroflow_Annotate(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
mfName := testModule + ".RT_Annotate"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
@annotation 'This is a test annotation'
LOG INFO NODE 'Test' 'Hello';
RETURN true;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"@annotation", "test annotation", "LOG INFO", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_CaptionColor tests @caption and @color roundtrip.
func TestRoundtripMicroflow_CaptionColor(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
mfName := testModule + ".RT_CaptionColor"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
@caption 'Custom Caption'
@color Green
LOG INFO NODE 'Test' 'Hello';
RETURN true;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"@caption 'Custom Caption'", "@color Green", "LOG INFO", "RETURN"},
nil,
)
}
// TestRoundtripMicroflow_SystemEntityParameter tests that microflows with
// System.* built-in entity parameter types can be created (issue #29).
// System entities (System.Workflow, System.User, etc.) are not stored in the
// MPR domain models — they are serialized by qualified name at runtime.
func TestRoundtripMicroflow_SystemEntityParameter(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
mfName := testModule + ".RT_SystemEntityParam"
env.registerCleanup("microflow", mfName)
createMDL := `CREATE MICROFLOW ` + mfName + ` (
$Workflow: System.Workflow,
$Count: Integer
) RETURNS List of System.User
BEGIN
RETURN empty;
END;`
assertMicroflowContains(t, env, mfName, createMDL,
// "empty" is a reserved keyword — must round-trip as "RETURN empty", not "$empty"
[]string{"System.Workflow", "System.User", "RETURN empty"},
[]string{"RETURN $empty"},
)
}
// TestRoundtripMicroflow_Position tests @position is emitted in DESCRIBE output.
func TestRoundtripMicroflow_Position(t *testing.T) {
env := setupTestEnv(t)
defer env.teardown()
mfName := testModule + ".RT_Position"
createMDL := `CREATE MICROFLOW ` + mfName + ` () RETURNS Boolean
BEGIN
@position(500, 300)
LOG INFO NODE 'Test' 'Hello';
RETURN true;
END;`
// @position is always emitted but the exact coordinates depend on the BSON roundtrip
// (RelativeMiddle vs RelativeMiddlePoint key mismatch). Verify @position appears.
assertMicroflowContains(t, env, mfName, createMDL,
[]string{"@position(", "LOG INFO", "RETURN"},
nil,
)
}