Skip to content

feat: support inheritance split and cast statements#365

Open
hjotha wants to merge 2 commits intomendixlabs:mainfrom
hjotha:submit/microflow-inheritance-split-cast
Open

feat: support inheritance split and cast statements#365
hjotha wants to merge 2 commits intomendixlabs:mainfrom
hjotha:submit/microflow-inheritance-split-cast

Conversation

@hjotha
Copy link
Copy Markdown
Contributor

@hjotha hjotha commented Apr 27, 2026

Summary

Adds first-class MDL support for type-based microflow decisions and cast actions:

split type $Input
case Sample.SpecializedInput
  cast $SpecificInput;
else
  return false;
end split;

Root Cause

The SDK layer could parse InheritanceSplit and CastAction objects from MPRs, but MDL had no AST or grammar nodes for them. The writer also did not serialize inheritance split/case/cast data back to valid microflow BSON, so describe/exec round-trips could not preserve these graphs.

Fix

  • Adds InheritanceSplitStmt, InheritanceSplitCase, and CastObjectStmt to the microflow AST.
  • Extends the grammar and visitor to parse split type branches and cast actions.
  • Builds InheritanceSplit graphs with InheritanceCase sequence flows.
  • Describes existing inheritance split graphs back to MDL by resolving case entity names.
  • Serializes inheritance split objects, inheritance case values, and cast actions in the MPR writer.
  • Updates validation, layout, reference walking, docs, skill guidance, and doctype examples.

Validation

  • go test ./mdl/visitor -run 'TestMicroflowParsing_(Inheritance|Cast)' -count=1
  • go test ./mdl/executor -run 'Test(FormatActivity_InheritanceSplit|FormatAction_CastAction|Builder_InheritanceSplit|TraverseFlow_InheritanceSplit|LastStmtIsReturn_InheritanceSplit|ValidateMicroflow_InheritanceSplit)' -count=1
  • go test ./sdk/mpr -run 'Test(BuildSequenceFlowCase_InheritanceCase|SerializeMicroflowObject_InheritanceSplit|CastAction_RoundtripVariableName)' -count=1
  • ./bin/mxcli check mdl-examples/doctype-tests/inheritance_split_statement.test.mdl
  • make build
  • make lint-go
  • make test

Closes #348
Part of #332

Symptom: type-based microflow decisions and cast actions could be read from MPRs but had no first-class MDL representation, so describe/exec round-trips could not preserve InheritanceSplit and CastAction graphs.

Root cause: the microflow AST, grammar, visitor, builder, describer, validator, and MPR writer only modeled boolean exclusive splits and regular actions. InheritanceCase sequence flows and CastAction BSON were not emitted back to valid project data.

Fix: add split type and cast statements, parse and build inheritance branches, describe existing InheritanceSplit graphs by resolving case entity names, serialize inheritance split/case/cast BSON, and recurse through type-split bodies in validation/reference/layout code.

Tests: added parser, builder, describer, terminality, validation, and MPR writer regressions plus a doctype fixture checked with mxcli check. Also ran make build, make lint-go, and make test.
Symptom: an inheritance split branch containing a nested empty-then decision
could lose the boolean case value on the continuation flow when the branch
joined a shared split merge.

Root cause: addStructuredInheritanceSplit consumed flowBuilder.nextConnectionPoint
from the nested decision but did not carry flowBuilder.nextFlowCase through branch
tail wiring.

Fix: preserve the pending case value on inheritance branch tails and reapply it
when connecting to the next statement, parent continuation, or shared merge.

Tests: add a builder regression for nested empty-then inheritance branches that
must keep CaseValue=true on continuation flows.
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.

Preserve inheritance split and cast-action microflow roundtrips

2 participants