Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

#### Eventless/Automatic Transitions

- **Eventless Transitions**: Full W3C SCXML support for transitions without event attributes that fire automatically
- **Automatic Transition Processing**: Microstep loop processes chains of eventless transitions until stable configuration
- **Cycle Detection**: Prevents infinite loops with configurable iteration limits (100 iterations default)
- **Parallel Region Preservation**: Proper SCXML semantics for transitions within and across parallel regions
- **Conflict Resolution**: Child state transitions take priority over ancestor transitions per W3C specification

#### Enhanced Parallel State Support

- **Parallel State Transitions**: Fixed regression where transitions within parallel regions affected unrelated parallel regions
- **Cross-Parallel Boundaries**: Proper exit semantics when transitions cross parallel region boundaries
- **SCXML Exit State Calculation**: Implements correct W3C exit set computation for complex state hierarchies
- **Sibling State Management**: Automatic exit of parallel siblings when transitions leave their shared parent

### Fixed

- **Regression Test**: Fixed parallel state test failure (`test/scion_tests/more_parallel/test1_test.exs`)
- **SCION Test Suite**: All 4 `cond_js` tests now pass (previously 3/4)
- **Parallel Interrupt Tests**: Fixed 6 parallel interrupt test failures in regression suite
- **Code Quality**: Resolved all `mix credo --strict` issues (predicate naming, unused variables, aliases)

### Technical Improvements

- **SCXML Terminology Alignment**: Updated codebase to use proper SCXML specification terminology
- **Microstep/Macrostep Processing**: Execute microsteps (single transition sets) until stable macrostep completion
- **Exit Set Computation**: Implements W3C SCXML exit set calculation algorithm for proper state exit semantics
- **LCCA Computation**: Full Least Common Compound Ancestor algorithm for accurate transition conflict resolution
- **NULL Transitions**: Added SCXML specification references while maintaining "eventless transitions" terminology
- **Feature Detection**: Added `eventless_transitions: :supported` to feature registry
- **Performance**: Optimized ancestor/descendant lookup using existing parent attributes
- **Test Coverage**: Enhanced with 10 comprehensive edge case tests covering LCCA, exit sets, and complex hierarchies
- **Total Tests**: 444 tests (up from 434), including deep hierarchy and parallel region edge cases
- **Coverage Improvement**: Interpreter module coverage increased from 70.4% to 83.0%
- **Project Coverage**: Overall coverage improved from 89.0% to 92.3% (exceeds 90% minimum requirement)
- **Regression Testing**: All 63 regression tests pass (up from 62)

## [0.1.0] - 2025-08-20

### Added
Expand Down
50 changes: 33 additions & 17 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ When verifying code changes, always follow this sequence (also automated via pre

**Testing:**

- `mix test` - Run all internal tests (excludes SCION/W3C by default)
- `mix test` - Run all internal tests (excludes SCION/W3C by default) - 444 tests
- `mix test --include scion --include scxml_w3` - Run all tests including SCION and W3C tests
- `mix test.regression` - Run regression tests that should always pass
- `mix test.regression` - Run regression tests that should always pass - 63 tests (critical functionality)
- `mix test.baseline` - Check which tests are currently passing (for updating regression suite)
- `mix test --cover` - Run all tests with coverage reporting (maintain 95%+ coverage)
- `mix test --cover` - Run all tests with coverage reporting (maintain 90%+ coverage - currently 92.3%)
- `mix coveralls` - Alternative coverage command
- `mix coveralls.detail` - Run tests with detailed coverage report showing uncovered lines
- `mix test test/sc/location_test.exs` - Run location tracking tests
- `mix test test/sc/parser/scxml_test.exs` - Run specific SCXML parser tests (uses pattern matching)
- `mix test test/sc/interpreter/compound_state_test.exs` - Run compound state tests
- `mix test test/sc/interpreter/eventless_transitions_test.exs` - Run eventless transition tests

**Development:**

Expand Down Expand Up @@ -106,12 +107,18 @@ Also use this initial Elixir implementation as reference: <https://github.com/ca

### Interpreter and Runtime

- **`SC.Interpreter`** - Core SCXML interpreter with synchronous API
- Initializes state charts from validated + optimized documents
- **`SC.Interpreter`** - Core SCXML interpreter with W3C-compliant processing model
- **Microstep/Macrostep Execution**: Implements SCXML event processing model where microsteps (single transition set execution) are processed until stable macrostep completion
- **Exit Set Computation**: Uses W3C SCXML exit set calculation algorithm for determining which states to exit during transitions
- **LCCA Algorithm**: Full Least Common Compound Ancestor computation for accurate transition conflict resolution and exit set calculation
- **Eventless Transitions**: Automatic transitions without event attributes (also called NULL transitions in SCXML spec)
- **Optimal Transition Set**: SCXML-compliant transition conflict resolution where child state transitions take priority over ancestors
- **Compound state support**: Automatically enters initial child states recursively
- **Parallel state support**: Proper concurrent execution with cross-boundary exit semantics and parallel region preservation
- **Conditional transitions**: Full `cond` attribute support with Predicator v2.0 expression evaluation and SCXML `In()` function
- **Cycle Detection**: Prevents infinite loops in eventless transitions with configurable iteration limits (100 iterations default)
- **O(1 lookups**: Uses `Document.find_state/2` and `Document.get_transitions_from_state/2`
- Separates `active_states()` (leaf only) from `active_ancestors()` (includes parents)
- Processes events and manages state transitions
- Provides `{:ok, result}` or `{:error, reason}` responses
- **`SC.StateChart`** - Runtime container for SCXML state machines
- Combines document, configuration, and event queues
Expand Down Expand Up @@ -239,13 +246,18 @@ XML content within triple quotes uses 4-space base indentation.

## SCION Test Results

**Current Status:** 107/225 tests passing (47.6% pass rate)
**Current Status:** 34/127 tests passing (26.8% pass rate) - ✅ +4 with eventless transitions and SCXML-compliant processing

**Working Features:**

- ✅ Basic state transitions (basic1, basic2 tests pass)
- ✅ **Compound states** with automatic initial child entry
- ✅ **Initial state elements** (`<initial>` with transitions) - W3C compliant
- ✅ **Parallel states** with concurrent execution and proper exit semantics
- ✅ **SCXML-compliant processing** - Proper microstep/macrostep execution model with exit set computation and LCCA algorithms
- ✅ **Eventless transitions** - Automatic transitions without event attributes (also called NULL transitions in SCXML spec)
- ✅ **Conditional transitions** - Full `cond` attribute support with Predicator v2.0 expression evaluation and SCXML `In()` function
- ✅ **Optimal Transition Set** - SCXML-compliant transition conflict resolution where child state transitions take priority over ancestors
- ✅ Hierarchical states with O(1) optimized lookups
- ✅ Event-driven state changes
- ✅ Initial state configuration (both `initial="id"` attributes and `<initial>` elements)
Expand All @@ -255,11 +267,11 @@ XML content within triple quotes uses 4-space base indentation.

**Main Failure Categories:**

- **Document parsing failures**: Complex SCXML with parallel states, history states, executable content
- **Document parsing failures**: Complex SCXML with history states, executable content
- **Validation too strict**: Rejecting valid but complex SCXML documents
- **Missing SCXML features**: Parallel states, conditional transitions, targetless transitions, internal transitions
- **Missing SCXML features**: Targetless transitions, internal transitions
- **Missing executable content**: `<script>`, `<assign>`, `<send>`, `<raise>`, `<onentry>`, `<onexit>`
- **Incomplete hierarchy handling**: Initial state resolution for compound states
- **Missing datamodel features**: Enhanced expression evaluation, additional functions

## Implementation Status

Expand All @@ -270,8 +282,15 @@ XML content within triple quotes uses 4-space base indentation.
- **Parse → Validate → Optimize architecture** with clean separation of concerns
- Complete interpreter infrastructure (Interpreter, StateChart, Configuration, Event, Validator)
- **Compound state support** with automatic initial child entry recursion
- **Parallel state support** with concurrent execution and proper cross-boundary exit semantics
- **SCXML-compliant processing model** with proper microstep/macrostep execution, exit set computation, and LCCA algorithms
- **Eventless transitions** - Automatic transitions without event attributes (also called NULL transitions in SCXML spec)
- **Conditional transitions** - Full `cond` attribute support with Predicator v2.0 expression evaluation and SCXML `In()` function
- **Optimal Transition Set** - SCXML-compliant transition conflict resolution where child state transitions take priority over ancestors
- **Exit Set Computation** - W3C SCXML exit set calculation algorithm for proper state exit semantics
- **LCCA Algorithm** - Full Least Common Compound Ancestor computation for accurate transition conflict resolution
- **O(1 performance optimizations** via state and transition lookup maps
- Comprehensive test suite integration (SCION + W3C)
- Comprehensive test suite integration (SCION + W3C) - 444 tests, 63 regression tests, 92.3% coverage
- Test infrastructure with SC.Case module using interpreter
- **Pattern matching in tests** instead of multiple individual assertions
- XML parsing with namespace support and precise source location tracking
Expand All @@ -282,20 +301,17 @@ XML content within triple quotes uses 4-space base indentation.
- Document validation with finalize callback building optimization structures
- Active state tracking with hierarchical ancestor computation using O(1) lookups
- **Git pre-push hook** for automated local validation workflow
- 95%+ test coverage maintained
- **Enhanced test coverage** - 92.3% overall coverage (exceeds 90% minimum), interpreter module at 83.0%
- **Initial state elements** (`<initial>` with `<transition>`) with comprehensive validation
- **Modular validator architecture** - refactored from 386-line monolith into focused modules
- **Full Credo compliance** - all 43 alias-related issues resolved
- **Full Credo compliance** - all code quality issues resolved

🚧 **Future Extensions:**

- Parallel states (`<parallel>`) - major gap in current implementation
- History states (`<history>`) - missing from parser and interpreter
- Conditional transitions with `cond` attribute evaluation
- Internal transitions (`type="internal"`) and targetless transitions
- Executable content elements (`<onentry>`, `<onexit>`, `<raise>`, `<assign>`, `<script>`, `<send>`)
- Proper SCXML exit/entry sequence with Least Common Ancestor (LCA) computation
- Expression evaluation and datamodel support
- Enhanced datamodel support with more expression functions
- Enhanced validation for complex SCXML constructs
- Additional parser formats (JSON, YAML) leveraging same validation/optimization pipeline

Expand Down
107 changes: 97 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ An Elixir implementation of SCXML (State Chart XML) state charts with a focus on
- ✅ **Compound States** - Support for hierarchical states with automatic initial child entry
- ✅ **Initial State Elements** - Full support for `<initial>` elements with transitions (W3C compliant)
- ✅ **Parallel States** - Support for concurrent state regions with simultaneous execution
- ✅ **Eventless Transitions** - Automatic transitions without event attributes (W3C compliant)
- ✅ **Conditional Transitions** - Full support for `cond` attributes with expression evaluation
- ✅ **O(1) Performance** - Optimized state and transition lookups via Maps
- ✅ **Event Processing** - Internal and external event queues per SCXML specification
- ✅ **Parse → Validate → Optimize Architecture** - Clean separation of concerns
Expand All @@ -24,16 +26,21 @@ An Elixir implementation of SCXML (State Chart XML) state charts with a focus on

## Current Status

**SCION Test Results:** 30/127 tests passing (23.6% pass rate)
**SCION Test Results:** 34/127 tests passing (26.8% pass rate) - ✅ +4 with eventless transitions
**W3C Test Results:** 0/59 tests passing (0% pass rate)
**Regression Suite:** 22 tests (all critical functionality)
**Regression Suite:** 63 tests (all critical functionality) - ✅ +41 additional tests validated
**Test Coverage:** 92.3% overall (exceeds 90% minimum) - ✅ Interpreter module: 83.0% coverage

### Working Features

- ✅ **Basic state transitions** and event-driven changes
- ✅ **Hierarchical states** with optimized O(1) state lookup and automatic initial child entry
- ✅ **Initial state elements** - Full `<initial>` element support with transitions and comprehensive validation
- ✅ **Parallel states** with concurrent execution of multiple regions
- ✅ **Parallel states** with concurrent execution of multiple regions and proper cross-boundary exit semantics
- ✅ **Eventless transitions** - Automatic transitions without event attributes (also called NULL transitions in SCXML spec), with cycle detection and microstep processing
- ✅ **Conditional transitions** - Full `cond` attribute support with Predicator v2.0 expression evaluation and SCXML `In()` function
- ✅ **Transition conflict resolution** - Child state transitions take priority over ancestor transitions per W3C specification
- ✅ **SCXML-compliant processing** - Proper microstep/macrostep execution model with exit set computation and LCCA algorithms
- ✅ **Modular validation** - Refactored from 386-line monolith into focused sub-validators
- ✅ **Feature detection** - Automatic SCXML feature detection prevents false positive test results
- ✅ **SAX-based XML parsing** with accurate location tracking for error reporting
Expand All @@ -44,14 +51,36 @@ An Elixir implementation of SCXML (State Chart XML) state charts with a focus on
### Planned Features

- History states (`<history>`)
- Conditional transitions with expression evaluation (`cond` attribute)
- Internal and targetless transitions
- Executable content (`<script>`, `<assign>`, `<send>`, `<onentry>`, `<onexit>`, etc.)
- Expression evaluation and datamodel support
- Enhanced datamodel support with more expression functions
- Enhanced validation for complex SCXML constructs

## Recent Completions

### **✅ SCXML-Compliant Processing Engine**

**COMPLETED** - Full W3C SCXML specification compliance with proper domain terminology:

- **`Microstep/Macrostep Execution`** - Implements SCXML event processing model with microstep (single transition set execution) and macrostep (series of microsteps until stable)
- **`Eventless Transitions`** - Transitions without event attributes (called NULL transitions in SCXML spec) that fire automatically upon state entry
- **`Exit Set Computation`** - Implements W3C SCXML exit set calculation algorithm for determining which states to exit during transitions
- **`LCCA Algorithm`** - Full Least Common Compound Ancestor computation for accurate transition conflict resolution and exit set calculation
- **`Cycle Detection`** - Prevents infinite loops with configurable iteration limits (100 iterations default)
- **`Parallel Region Preservation`** - Proper SCXML exit semantics for transitions within and across parallel regions
- **`Optimal Transition Set`** - SCXML-compliant transition conflict resolution where child state transitions take priority over ancestors
- **`Test Coverage`** - 18+ comprehensive test scenarios covering all eventless transition patterns, LCCA edge cases, and complex hierarchies

### **✅ Enhanced Parallel State Support**

**COMPLETED** - Fixed critical regression and enhanced parallel state semantics:

- **`Cross-Parallel Boundaries`** - Proper exit semantics when transitions leave parallel regions
- **`Sibling State Management`** - Automatic exit of parallel siblings when transitions exit their shared parent
- **`Self-Transitions`** - Transitions within parallel regions preserve unaffected parallel regions
- **`SCION Compatibility`** - All 4 `cond_js` tests now pass, 6 parallel interrupt tests fixed
- **`Regression Prevention`** - 62 regression tests now validate all critical functionality

### **✅ Feature-Based Test Validation System**

**COMPLETED** - Improves test accuracy by validating that tests actually exercise intended SCXML functionality:
Expand Down Expand Up @@ -145,6 +174,64 @@ active_states = SC.Interpreter.active_states(new_state_chart)
# Returns: MapSet.new(["end"])
```

### Eventless Transitions Example

```elixir
# Automatic transitions without events fire immediately
xml = """
<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="start">
<state id="start">
<transition target="processing"/> <!-- No event - fires automatically -->
</state>
<state id="processing">
<transition target="done" cond="ready == true"/> <!-- Conditional eventless -->
</state>
<state id="done"/>
</scxml>
"""

{:ok, document} = SC.Parser.SCXML.parse(xml)
{:ok, state_chart} = SC.Interpreter.initialize(document)

# Eventless transitions processed automatically during initialization
active_states = SC.Interpreter.active_states(state_chart)
# Returns: MapSet.new(["processing"]) - automatically moved from start
```

### Parallel States Example

```elixir
xml = """
<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0">
<parallel id="app">
<state id="ui" initial="idle">
<state id="idle">
<transition event="click" target="busy"/>
</state>
<state id="busy">
<transition event="done" target="idle"/>
</state>
</state>
<state id="network" initial="offline">
<state id="offline">
<transition event="connect" target="online"/>
</state>
<state id="online"/>
</state>
</parallel>
</scxml>
"""

{:ok, document} = SC.Parser.SCXML.parse(xml)
{:ok, state_chart} = SC.Interpreter.initialize(document)

# Both parallel regions active simultaneously
active_states = SC.Interpreter.active_states(state_chart)
# Returns: MapSet.new(["idle", "offline"])
```

### Document Validation

```elixir
Expand Down Expand Up @@ -192,7 +279,7 @@ mix dialyzer # Type checking
The project uses automated regression testing to prevent breaking existing functionality:

```bash
# Run only tests that should always pass (22 tests)
# Run only tests that should always pass (63 tests)
mix test.regression

# Check which tests are currently passing to update regression suite
Expand All @@ -204,8 +291,8 @@ mix test.baseline

The regression suite tracks:

- **Internal tests**: All `test/sc/**/*_test.exs` files (supports wildcards)
- **SCION tests**: 8 known passing tests (basic + hierarchy + parallel)
- **Internal tests**: All `test/sc/**/*_test.exs` files (supports wildcards) - includes edge case coverage tests
- **SCION tests**: 8 known passing tests (basic + hierarchy + parallel + conditional)
- **W3C tests**: Currently none passing

### Running Tests
Expand All @@ -217,7 +304,7 @@ mix test
# All tests including SCION and W3C test suites
mix test --include scion --include scxml_w3

# Only regression tests (22 critical tests)
# Only regression tests (63 critical tests)
mix test.regression

# With coverage reporting
Expand Down Expand Up @@ -324,7 +411,7 @@ The project includes a sophisticated regression testing system to ensure stabili

- Regression tests run before full test suite in CI
- Prevents merging code that breaks core functionality
- Fast feedback loop (22 tests vs 290 total tests)
- Fast feedback loop (63 tests vs 444 total tests)

### **Local Development**

Expand Down
Loading