Skip to content

feat: statemachine first class - #126

Merged
Theauxm merged 4 commits into
mainfrom
feat/statemachine-first-class
Aug 13, 2026
Merged

feat: statemachine first class#126
Theauxm merged 4 commits into
mainfrom
feat/statemachine-first-class

Conversation

@Theauxm

@Theauxm Theauxm commented Aug 13, 2026

Copy link
Copy Markdown
Member

No description provided.

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.16058% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...hine.Persistence/StateMachinesBuilderExtensions.cs 87.23% 4 Missing and 2 partials ⚠️
src/Trax.Effect.StateMachine/Rules/IrExporter.cs 90.90% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@Theauxm
Theauxm force-pushed the feat/statemachine-first-class branch from 71b8917 to 6f170fa Compare August 13, 2026 14:48
…an IR differential block

Add IMachineBuilder.Differential(d => d.Sample/Seed/Probe/EmptySample) so a machine's cross-language
differential inputs (representative per-trigger samples, per-state seed contexts, dense probe contexts) are
authored on the C# machine itself. The IR exporter emits them as an optional "differential" block (omitted
when empty, so shape-only machines' IR is byte-identical). This makes the C# machine the single source for
the differential harness, which can enumerate off the exported IR instead of a hand-written machine.json.
Typed overloads serialize records with camelCase names (nulls kept); raw JsonObject overloads give exact
control. Only valid on a declaratively-authored machine (it rides the IR).
…ters the SnapshotDbContext + mutations

Make state-machine persistence a first-class Trax subsystem. trax.AddStateMachines(assemblies), a step in the
AddTrax builder chain, discovers the machines, wires the store/ledger/runner/registry and the four generic
stateMachine mutation routes, AUTO-registers the SnapshotDbContext against the provider configured in
AddEffects, and contributes the mutations' assembly to the mediator scan. The host no longer calls
AddDbContext<SnapshotDbContext> or names StateMachineMutations.Assembly.

The DbContext auto-registration uses a new provider-agnostic seam, ITraxFeatureDbConfigurator, registered by
UsePostgres/UseSqlite/UseInMemory, so a feature keeps its own change tracker (isolated from the effect
journal) while binding to the app's database. TraxBuilder gains ContributedMediatorAssemblies (merged by
AddMediator) and a MediatorConfigured flag; AddStateMachines guards on a missing data provider and on being
called after AddMediator. The old IServiceCollection AddTraxStateMachines(...) is kept functional but marked
[Obsolete] (it cannot auto-wire the DbContext or the mediator scan). Public API baselines updated.
…AddStateMachines builder

Unit-cover the .Differential(...) surface (typed and raw samples/seeds/probes, the serialization guard, the
declarative-only guard) and its IR export (samples/seeds/contexts), plus DifferentialModel.IsEmpty. Add
integration tests for trax.AddStateMachines: the happy path over Postgres (subsystem resolves, the
SnapshotDbContext auto-registers and round-trips, the mutations' assembly is contributed to the mediator
scan) and the before-AddMediator ordering guard. Closes the patch-coverage gaps on the new code.
Delete the IServiceCollection AddTraxStateMachines(...) overloads outright rather than deprecating them.
trax.AddStateMachines(...) replaces them and does strictly more (auto-registers the SnapshotDbContext,
contributes the mutations to the mediator scan); the only consumers are ours (samples, E2E host, nwyc),
all already migrated, so this is a non-breaking removal, not a 2.0.0. The shared registration helper moves
into StateMachinesBuilderExtensions as a private method, and the back-compat test and stale doc/comment
references go with it.
@Theauxm
Theauxm force-pushed the feat/statemachine-first-class branch from 6f170fa to f4e4e80 Compare August 13, 2026 15:06
@Theauxm
Theauxm merged commit 093ba41 into main Aug 13, 2026
3 checks passed
@Theauxm
Theauxm deleted the feat/statemachine-first-class branch August 13, 2026 15:09
@github-actions

Copy link
Copy Markdown

This PR is included in version 1.49.0

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.

1 participant