Generated mock-factory registry (085-003): defining a factory IS registering it#272
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Kanban 085-003 — second accepted inference-removal candidate: replace
MockWebApiService's hand-maintainedDictionary<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 theGetMockResponseFactory()convention and emits a sortedGeneratedMockResponseFactories.Create()registry. Emission is gated on the compilation declaring aMockWebApiServiceclass, so server projects that also reference contracts get nothing.Design notes
UseRealApiexclusion set in the hand-written file.Proof it was needed
The generator's first real output has 8 entries; the hand dictionary had 7 —
GetSignInTokendefined a factory that was never registered. Exactly the agreement-by-memory drift this candidate predicted.Verification
dev build0/0 · sourcegen tests 16/16 (2 new) · web-spa compiles withMOCK_WEB_APIdefined · analyzer 26/26 · contracts 7/7 · web-server integration 22 passed. Incidental: two pre-existing brace-lessifs inModalContainer.razor.cssurfaced by full re-analysis; fixed to repo style.🤖 Generated with Claude Code