Skip to content

Generated mock-factory registry (085-003): defining a factory IS registering it#272

Merged
StevenTCramer merged 1 commit into
masterfrom
dev
Jul 2, 2026
Merged

Generated mock-factory registry (085-003): defining a factory IS registering it#272
StevenTCramer merged 1 commit into
masterfrom
dev

Conversation

@StevenTCramer

Copy link
Copy Markdown
Contributor

Summary

Kanban 085-003 — second accepted inference-removal candidate: replace MockWebApiService's hand-maintained Dictionary<Type, Delegate> with a source-generated registry.

The generator

MockResponseFactoryRegistryGenerator (in the existing generator assembly; web-spa already references it — zero new wiring) scans referenced *contracts* assemblies for the GetMockResponseFactory() convention and emits a sorted GeneratedMockResponseFactories.Create() registry. Emission is gated on the compilation declaring a MockWebApiService class, so server projects that also reference contracts get nothing.

Design notes

  • The manual registration step is deleted, not checked: defining a factory on a contract is registering it. New contracts appear in mock mode automatically.
  • The old "comment a dictionary line out to hit the real API during UI development" affordance survives as an explicit UseRealApi exclusion set in the hand-written file.

Proof it was needed

The generator's first real output has 8 entries; the hand dictionary had 7GetSignInToken defined a factory that was never registered. Exactly the agreement-by-memory drift this candidate predicted.

Verification

dev build 0/0 · sourcegen tests 16/16 (2 new) · web-spa compiles with MOCK_WEB_API defined · analyzer 26/26 · contracts 7/7 · web-server integration 22 passed. Incidental: two pre-existing brace-less ifs in ModalContainer.razor.cs surfaced by full re-analysis; fixed to repo style.

🤖 Generated with Claude Code

MockResponseFactoryRegistryGenerator (in the existing generator assembly —
web-spa already wires it as an analyzer) scans referenced *contracts*
assemblies for public static parameterless GetMockResponseFactory() with a
nested Query/Command and emits a sorted GeneratedMockResponseFactories
registry. Gated on the compilation declaring MockWebApiService, so server
projects referencing contracts get nothing.

The hand-maintained Dictionary<Type, Delegate> is gone: defining a factory on
a contract IS registering it. The per-feature "use the real API while
developing" affordance is preserved as an explicit UseRealApi exclusion set.

First real output caught live drift: the hand dict had 7 entries, the
generated registry has 8 — GetSignInToken defined a factory that was never
registered. Exactly the agreement-by-memory failure this task predicted.

Verified: sourcegen tests 16/16 (2 new); mock mode compiles with MOCK_WEB_API
defined; dev build 0/0; analyzer 26, contracts 7, web-server integration 22.
Incidental: two pre-existing brace-less ifs in ModalContainer.razor.cs
surfaced by full re-analysis; fixed to repo style.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@StevenTCramer StevenTCramer merged commit 95e86d8 into master Jul 2, 2026
1 check failed
@StevenTCramer StevenTCramer deleted the dev branch July 2, 2026 15:33
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