Skip to content

refactor(domain): Typed StrategyConfig Value Object - Phase 2 - #62

Merged
amodelandme merged 8 commits into
devfrom
refactor/typed-strategy-config
May 7, 2026
Merged

amodelandme merged 8 commits into
devfrom
refactor/typed-strategy-config

Conversation

@amodelandme

Copy link
Copy Markdown
Owner

Summary

Flag.StrategyConfig was converted from a raw string to a typed StrategyConfig sealed record Value Object. The Flag entity now enforces that config and strategy type are always consistent — a Flag with mismatched strategy type and config shape cannot exist. An IStrategyConfigValidator registry pattern validates raw JSON into typed VOs at the application boundary, and an EF Core Value Converter handles persistence without schema changes.

Changes in this PR

  • Typed StrategyConfig VO with ValidatedFor/RawJson and internal trusted constructor
  • IStrategyConfigValidator interface + three implementations (None, Percentage, RoleBased)
  • StrategyConfigFactory registry dispatch keyed on RolloutStrategy
  • Flag constructor/Update/UpdateStrategy enforce config/strategy type match
  • EF Core StrategyConfigConverter — no migration needed
  • 43 new unit tests (VO, validators, factory, guard clauses)
  • All 158 existing unit tests updated and passing
  • Skill updates: worktree isolation for /implement, Docs/ casing fix, /git-workflow script automation

Spec

Docs/Decisions/refactor-typed-strategy-config/spec.md

Implementation Notes

Docs/Decisions/refactor-typed-strategy-config/implementation-notes.md

Definition of Done

  • StrategyConfig sealed record in Banderas.Domain/ValueObjects/
  • internal trusted constructor for EF Core and seed data
  • IStrategyConfigValidator interface in Banderas.Domain/Interfaces/
  • Three validator implementations in Banderas.Application/Validators/
  • StrategyConfigFactory with registry dispatch
  • All validators and factory registered in DI
  • Flag.StrategyConfig property type is StrategyConfig
  • Guard clauses on constructor, Update(), UpdateStrategy()
  • Strategies read from flag.StrategyConfig.RawJson
  • FlagMappings.ToResponse() maps .RawJson
  • BanderasService calls factory before Flag construction/update
  • EF Core Value Converter — no migration
  • DatabaseSeeder uses valid VOs
  • FlagBuilder updated
  • 158/158 unit tests passing
  • dotnet build -p:TreatWarningsAsErrors=true — 0 warnings
  • CSharpier check passes

Testing

dotnet test Banderas.Tests/Banderas.Tests.csproj
dotnet build Banderas.sln -p:TreatWarningsAsErrors=true
dotnet csharpier check .

Developer and others added 8 commits May 7, 2026 00:53
… registry

StrategyConfig is now a sealed record with ValidatedFor and RawJson.
Flag enforces config/strategy type consistency at construction and
mutation — mismatches throw FlagDomainException. IStrategyConfigValidator
registry mirrors the IRolloutStrategy dispatch pattern. Adding a new
strategy requires: implement IRolloutStrategy, implement
IStrategyConfigValidator, register both in DI.
ValueConverter<StrategyConfig, string> handles persistence without
schema changes. Flag uses a backing field with lazy reconciliation
to set ValidatedFor from StrategyType after EF Core materialization.
DatabaseSeeder uses the trusted internal constructor.
43 new tests: StrategyConfig construction and equality (5),
Flag guard clause mismatch rejection (3), PercentageConfigValidator (12),
RoleBasedConfigValidator (9), NoneConfigValidator (7),
StrategyConfigFactory dispatch (7). All existing tests updated for
typed StrategyConfig signatures. 158/158 passing.
…workflow

/implement: Step 0 creates an isolated git worktree for all implementation
work. Worktree cleanup instructions added to HITL gate.
/git-workflow: rewritten to produce a single self-destructing bash script
instead of copy-paste command blocks.
All skills: docs/ references corrected to Docs/ to match repo structure.
Spec: Docs/Decisions/refactor-typed-strategy-config/spec.md
…ll test data

Replace 11 var usages with explicit StrategyConfig type to comply with
.editorconfig csharp_style_var_elsewhere=false (IDE0008). Fix two
integration tests passing null for StrategyConfig in Flag constructors,
which caused NullReferenceException on the ValidatedFor guard clause.
212/212 tests passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…w-up

Record integration test fix, IDE0008 var compliance, and lessons learned
about auditing test files after introducing typed VOs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@amodelandme
amodelandme marked this pull request as ready for review May 7, 2026 01:26
@amodelandme
amodelandme merged commit 3fd494c into dev May 7, 2026
9 checks passed
@amodelandme
amodelandme deleted the refactor/typed-strategy-config branch May 7, 2026 01:26
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