Skip to content

Commit ebac593

Browse files
authored
Merge pull request #307 from hjotha/audit/describer-skip-annotations-for-unsupported
fix: do not emit annotations before unsupported-action comments
2 parents 82d6de1 + b68092a commit ebac593

3 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
-- ============================================================================
2+
-- Bug #306: Annotations emitted before unsupported-activity comments
3+
-- ============================================================================
4+
--
5+
-- Symptom (before fix):
6+
-- Activities whose BSON type isn't yet implemented in mxcli's describer
7+
-- render as `-- unsupported: <Type>` comments. Before the fix, the
8+
-- describer still prefixed these comment lines with `@position`,
9+
-- `@anchor`, etc. The grammar only accepts annotations as prefixes of
10+
-- real microflow statements (not comments), so the resulting MDL failed
11+
-- to re-parse with errors like:
12+
-- line N:0 mismatched input '@' expecting {...}
13+
--
14+
-- After fix:
15+
-- When a formatted statement begins with `--`, `emitObjectAnnotations`
16+
-- is skipped — only the comment is emitted. Annotations on SUPPORTED
17+
-- activities continue to be emitted as before.
18+
--
19+
-- Reproducibility note:
20+
-- The unsupported-activity branch can only be triggered by an .mpr
21+
-- containing a BSON activity type that mxcli does not yet describe
22+
-- (typical examples are very new or rarely-used activity types). Pure
23+
-- MDL cannot create such an activity. The Go-side regression
24+
-- `TestTraverseFlow_UnsupportedActivitySkipsAnnotations` covers that
25+
-- path directly.
26+
--
27+
-- This script provides a POSITIVE CONTROL: a microflow whose every
28+
-- activity carries position / caption / anchor annotations. Its describe
29+
-- output must (a) parse with `mxcli check`, and (b) round-trip cleanly,
30+
-- confirming the annotation-emission codepath still works for the
31+
-- common case.
32+
--
33+
-- Usage:
34+
-- mxcli exec mdl-examples/bug-tests/306-describer-annotations-before-unsupported-comment.mdl -p app.mpr
35+
-- mxcli -p app.mpr -c "describe microflow BugTest306.MF_AnnotatedFlow"
36+
-- The output must re-execute cleanly against the same project.
37+
-- ============================================================================
38+
39+
create module BugTest306;
40+
41+
create microflow BugTest306.MF_AnnotatedFlow (
42+
$input: string
43+
)
44+
returns string as $result
45+
begin
46+
declare $result string = empty;
47+
48+
@caption 'log entry'
49+
log info node 'BugTest306' 'flow started';
50+
51+
@caption 'guard'
52+
if $input != empty then
53+
@caption 'happy path'
54+
set $result = 'value: ' + $input;
55+
else
56+
set $result = 'no value';
57+
end if;
58+
59+
return $result;
60+
end;
61+
/

mdl/executor/cmd_microflows_show_helpers.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,18 @@ func emitActivityStatement(
387387
return
388388
}
389389

390+
// When the activity is unsupported by the describer (e.g. CallWebServiceAction,
391+
// CastAction, InheritanceSplit placeholder) we fall back to emitting just an
392+
// MDL line comment. Decorating that comment with @position/@anchor/@annotation
393+
// leaves the annotations orphaned — the grammar only accepts `annotation*`
394+
// as a prefix of a real microflowStatement, so line comments preceded by
395+
// annotations cause "no viable alternative at input '@position...end'" during
396+
// exec. Emit the comment on its own instead.
397+
if strings.HasPrefix(strings.TrimSpace(stmt), "--") {
398+
*lines = append(*lines, indentStr+stmt)
399+
return
400+
}
401+
390402
// Emit @ annotations before the statement
391403
emitObjectAnnotations(obj, lines, indentStr, annotationsByTarget, flowsByOrigin, flowsByDest)
392404

mdl/executor/cmd_microflows_traverse_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,47 @@ func TestTraverseFlow_IfWithoutElse(t *testing.T) {
183183
}
184184
}
185185

186+
// TestTraverseFlow_UnsupportedActivitySkipsAnnotations verifies that when the
187+
// describer falls back to a `-- Unsupported action type: ...` placeholder, it
188+
// does NOT also emit @position / @anchor before the comment. Annotations are
189+
// only valid as a prefix of real MDL statements; orphaning them above a pure
190+
// line comment triggers `no viable alternative at input '@position...end'`
191+
// during `exec`.
192+
func TestTraverseFlow_UnsupportedActivitySkipsAnnotations(t *testing.T) {
193+
e := newTestExecutor()
194+
195+
activityMap := map[model.ID]microflows.MicroflowObject{
196+
mkID("start"): &microflows.StartEvent{BaseMicroflowObject: mkObj("start")},
197+
mkID("soap"): &microflows.ActionActivity{
198+
BaseActivity: microflows.BaseActivity{BaseMicroflowObject: mkObj("soap")},
199+
Action: &microflows.UnknownAction{TypeName: "Microflows$CallWebServiceAction"},
200+
},
201+
mkID("end"): &microflows.EndEvent{BaseMicroflowObject: mkObj("end")},
202+
}
203+
204+
flowsByOrigin := map[model.ID][]*microflows.SequenceFlow{
205+
mkID("start"): {mkFlow("start", "soap")},
206+
mkID("soap"): {mkFlow("soap", "end")},
207+
}
208+
209+
var lines []string
210+
visited := make(map[model.ID]bool)
211+
e.traverseFlow(mkID("start"), activityMap, flowsByOrigin, nil, visited, nil, nil, &lines, 0, nil, 0, nil)
212+
213+
found := false
214+
for idx, line := range lines {
215+
if contains(line, "Unsupported action type") {
216+
found = true
217+
if idx > 0 && contains(lines[idx-1], "@") {
218+
t.Errorf("expected no annotation prefix before unsupported-action comment, got: %v", lines)
219+
}
220+
}
221+
}
222+
if !found {
223+
t.Errorf("expected unsupported-action comment, got: %v", lines)
224+
}
225+
}
226+
186227
// =============================================================================
187228
// collectErrorHandlerStatements
188229
// =============================================================================

0 commit comments

Comments
 (0)