Skip to content

feat: thread expression mode through evaluation (expression v3) - #337

Merged
santiagocardo merged 2 commits into
developfrom
feat/expression-3-mode-threading
Jul 29, 2026
Merged

feat: thread expression mode through evaluation (expression v3)#337
santiagocardo merged 2 commits into
developfrom
feat/expression-3-mode-threading

Conversation

@santiagocardo

@santiagocardo santiagocardo commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Purpose

Resolve expression mode at evaluation runtime. flow_runner evaluates expressions itself (Case-block conditions, exits, logs, simulator output), so when consumers start selecting expression mode dynamically (on expression v2 → v3 transition), flow_runner's internal evaluations must honor the same mode — otherwise, they would evaluate its conditions under one semantics and its messages under another.

Approach

Mode carrier: context.private[:expression_mode] (:v2 | :v3). Users stamp it when building the context. A missing stamp — old serialized contexts, third-party callers — degrades safely to :v2 (today's behavior).

  • Bumps expression to v3 and adapts to its API (this part was already done — the dep resolves 3.0.0-rc.0's removals cleanly since flow_runner never used the removed surfaces; evaluate_expression_block's rescue now speaks Expression.Error).
  • FlowRunner.evaluate_expression/2, evaluate_expression_as_string!/2, evaluate_expression_block/2 accept a %FlowRunner.Context{} (evaluates context.vars under the stamped mode). Contract callback specs temporarily changed to FlowRunner.Context.t().
  • New public FlowRunner.expression_opts/1 translating a Context-or-map into expression options ([mode: :v2] or []).
  • Internal callers now pass the Context: spec/exit, blocks/case, blocks/log, send_content_message directly; select_one_response and dynamic_select_one_response pass their ad-hoc test vars via %{context | vars: ...} so the mode is kept; the webhook block and 18 simulator sites pass expression_opts(...) explicitly (simulator via a nil-safe private helper). Sites that evaluate static config with no vars (whatsapp_template_message default_language, one simulator pipe) are mode-independent and unchanged.

Verification

  • New test/flow_runner/expression_mode_test.exs (8 tests): mode resolution from private data, :v2/:v3/unstamped/bare-map behavior through each contract function, including the v2 datetime-coercion rendering.
  • Full suite: 193 tests, 0 failures. mix credo --strict and mix format --check-formatted clean, compile with --warnings-as-errors.

🤖 Generated with Claude Code

santiagocardo and others added 2 commits July 28, 2026 16:05
Bump expression to v3 and thread the per-session expression mode
(context.private[:expression_mode], stamped by the consumer) into every
internal evaluation: contract entry points accept a FlowRunner.Context
(or a bare vars map for backwards compatibility, evaluating under :v2),
and direct Expression call sites pass FlowRunner.expression_opts/1. A
missing stamp degrades safely to :v2.

This keeps flow_runner's Case/exit/log/simulator evaluations under the
same per-journey semantics engage selects once expression v3 rolls out.
The expression dep is temporarily a git pin on release/3-0-0 until the
v2-compat mode ships in a tagged hex release (pre-publish TODO in
mix.exs).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Santiago <santiagocardo80@gmail.com>
@santiagocardo santiagocardo changed the title feat: thread expression-language mode through evaluation (expression v3) feat: thread expression mode through evaluation (expression v3) Jul 28, 2026
@santiagocardo santiagocardo self-assigned this Jul 28, 2026
@santiagocardo
santiagocardo requested review from Arp-G, fedme and smn July 28, 2026 22:45

@smn smn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay!

@santiagocardo
santiagocardo merged commit 96cb6bf into develop Jul 29, 2026
2 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants