Skip to content

Conversation

@johnnyt
Copy link
Member

@johnnyt johnnyt commented Sep 2, 2025

Adds comprehensive expression compilation during document validation and makes all actions pipeline-friendly for better Elixir ergonomics.

Expression Compilation Improvements

  • Moves compilation to validation phase: All expressions (transitions, actions) are now compiled during document validation rather than at creation time
  • Adds ExpressionCompiler module: Centralized compilation logic with detailed warning collection and source location tracking
  • Supports all action types: SendAction, AssignAction, IfAction, ForeachAction with compiled expression fields
  • Provides runtime fallbacks: Maintains backward compatibility with runtime compilation when validation-time compilation is unavailable
  • Collects compilation warnings: Detailed error context with line/column information for debugging

Pipeline-Friendly Architecture

  • Reorders function arguments: All action execute functions now take state_chart as the first argument
  • Enables pipeline composition: Actions can now be chained idiomatically with the |> operator
  • Updates ActionExecutor: All action calls updated to match new argument order
  • Maintains compatibility: Function clauses ensure type safety with new signature

Code Quality Improvements

  • Resolves Credo issues: Reduces cyclomatic complexity and fixes naming consistency
  • Improves maintainability: Cleaner abstractions and better separation of concerns
  • Comprehensive test coverage: All changes covered with updated test suites (112 action tests pass)

Performance Benefits

  • Pre-compiled expressions: Significant performance improvement by compiling expressions once during validation
  • Optimized evaluation: Expressions are compiled with Predicator once rather than on every execution
  • Better error handling: Compilation errors are caught early with detailed warnings

Example Usage

# Pipeline-friendly action execution
state_chart
|> AssignAction.execute(assign_action)
|> LogAction.execute(log_action)
|> SendAction.execute(send_action)

# Expressions compiled during validation with warnings
{warnings, compiled_document} = ExpressionCompiler.compile_document(document)

johnnyt and others added 3 commits September 2, 2025 04:51
- Moves ExpressionCompiler to validator/ folder for better organization
- Adds comprehensive ExpressionCompiler tests with >90% coverage (91.2%)
- Replaces `assert not` with `refute` in tests for proper Elixir conventions
- Moves all expression compilation from creation-time to validation-time
- Adds compilation warning collection with detailed error context
- Implements fallback runtime compilation for backward compatibility
- Supports all action types: transitions, SendAction, AssignAction, IfAction, ForeachAction
- Adds source location tracking for better debugging

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Refactors SendAction evaluation functions to reduce cyclomatic complexity from 11 to <3
- Extracts common expression evaluation logic into reusable helper functions
- Reorders function arguments to put state_chart first for better pipeline support
- Uses pattern matching with guards instead of cond for cleaner control flow
- Fixes unused variable naming consistency (uses _meaningful_name instead of _)
- Maintains all existing functionality and test coverage
- Improves maintainability through DRY principles and cleaner abstractions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Updates all action execute functions to take state_chart as the first
argument, enabling better pipeline composition with the |> operator.

- Updates execute function signatures in all action modules
- Updates ActionExecutor calls to match new argument order
- Updates all action tests to use new calling convention
- Maintains full backward compatibility through function clauses
- Enables idiomatic Elixir pipeline patterns for state chart threading

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Sep 2, 2025

Codecov Report

❌ Patch coverage is 87.37864% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/statifier/actions/send_action.ex 75.00% 6 Missing ⚠️
lib/statifier/actions/action_executor.ex 66.66% 3 Missing ⚠️
lib/statifier/actions/if_action.ex 62.50% 3 Missing ⚠️
lib/statifier/validator/expression_compiler.ex 98.24% 1 Missing ⚠️
Files with missing lines Coverage Δ
lib/statifier/actions/assign_action.ex 100.00% <ø> (+7.14%) ⬆️
lib/statifier/actions/foreach_action.ex 93.87% <ø> (-0.47%) ⬇️
lib/statifier/actions/log_action.ex 83.33% <ø> (ø)
lib/statifier/actions/raise_action.ex 100.00% <ø> (ø)
lib/statifier/feature_detector.ex 94.02% <ø> (ø)
lib/statifier/parser/scxml/element_builder.ex 100.00% <ø> (ø)
lib/statifier/validator.ex 100.00% <100.00%> (ø)
lib/statifier/validator/expression_compiler.ex 98.24% <98.24%> (ø)
lib/statifier/actions/action_executor.ex 68.33% <66.66%> (-0.52%) ⬇️
lib/statifier/actions/if_action.ex 77.77% <62.50%> (-11.12%) ⬇️
... and 1 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@johnnyt johnnyt merged commit 748a187 into main Sep 2, 2025
10 checks passed
@johnnyt johnnyt deleted the send-target-exprs branch September 2, 2025 11:28
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.

2 participants