Skip to content

fix(hottesting): give mocked view models a messenger - #3214

Merged
rajamatt merged 6 commits into
mainfrom
dev/mara/mock-create-messenger
Oct 14, 2026
Merged

rajamatt merged 6 commits into
mainfrom
dev/mara/mock-create-messenger

Conversation

@rajamatt

@rajamatt rajamatt commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): related to https://github.com/unoplatform/studio.live/issues/4074

PR Type

  • Bugfix

What is the current behavior?

{Vm}Mock.Create passes a typed default! for every constructor parameter. The MVUX messaging pattern observes a messenger in the model's constructor (messenger.Observe(Items, x => x.Id)), so for such a model Create throws ArgumentNullException (parameter messenger) from IMessengerExtensions.Register, and the model gets no mock at all.

What is the new behavior?

  • Create passes a fresh WeakReferenceMessenger for a constructor parameter typed CommunityToolkit.Mvvm.Messaging.IMessenger, matched by symbol. Every other parameter keeps its typed default.
  • When the compilation doesn't reference CommunityToolkit.Mvvm, nothing naming it is emitted.
  • Why a fresh weak messenger:
    • a messenger of its own means a preview never receives the app's messages;
    • WeakReferenceMessenger is what the messaging docs register;
    • the recipient Observe creates is owned by the state, so it goes away with the view-model.

Reviewer's guide

  • Start here: FeedsMockGenerator.CtorArgument.
  • Tests that prove it:
    • Given_GeneratedMock.When_ModelObservesAMessengerInItsCtor_Then_CreateSucceedsAndInputFlows fails on main with the ArgumentNullException;
    • Given_FeedsMockGenerator.When_CtorTakesAMessenger_Then_CreatePassesAFreshOne pins the emitted argument;
    • When_CtorTakesAnotherTypeNamedIMessenger_Then_CreateNullInjectsIt guards the match by symbol, not by name.
  • Test-only references: the MockingApp fixture now references Messaging, and Uno.HotTesting.Reactive.Tests references CommunityToolkit.Mvvm.
  • Docs commit: rules.md, testing.md, and spec 013 (architecture, history v18).
  • The end-to-end test reads the mocked input through a derived feed: on main, a mocked state input isn't swapped on the state itself. That is a separate fix.

PR Checklist

  • Unit Tests for the changes have been added: 3 tests.
  • Contains NO breaking changes: the generated code changes only for a messenger parameter.
  • Tested code with current supported SDKs: unit tests (Uno.Extensions.Reactive.Tests, 1470 pass, 19 skipped; Uno.HotTesting.Reactive.Tests, 36 pass).
  • Associated with an issue

Other information

  • The touched files are identical on servicing/7.4, so the backport should be clean.
  • Spec 013's history entry is numbered v18; two other mocking fixes in flight may want the same number.
  • A possible follow-up, not done here: a small table of known parameter types with safe values, such as ILogger<T> → NullLogger<T>.Instance.

🤖 Generated with Claude Code

rajamatt and others added 2 commits October 8, 2026 12:41
- Create passed default! for every constructor parameter, so a model calling
  messenger.Observe(...) in its constructor threw ArgumentNullException and got no mock
- Pass a fresh WeakReferenceMessenger for a parameter typed
  CommunityToolkit.Mvvm.Messaging.IMessenger, matched by symbol; typed default otherwise
- Nothing naming the toolkit is emitted when the compilation does not reference it
- Fixture NoteModel observes a state on its messenger; the mocked input reaches a derived feed
- Generator tests pin the emitted argument and a same-named IMessenger left null-injected

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- rules.md (MOCK0001) and testing.md no longer say every parameter is null-injected
- Spec 013 architecture notes the messenger argument; history gains a v18 entry

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rajamatt rajamatt self-assigned this Oct 8, 2026
rajamatt and others added 2 commits October 8, 2026 13:53
- a parameter typed IMessenger? also gets a fresh messenger, cast to IMessenger
- the messenger test no longer claims a state input's own value is not swapped,
  which stops being true once state inputs are swapped where they are read

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- spec 013 architecture and history v18: Create passes typed defaults, and the R1 guard
  on CtorDependency(Eager=true) is still not built, so other eager parameters still throw
- rules.md and testing.md: the messenger goes to a parameter typed IMessenger

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rajamatt
rajamatt requested a review from dr1rrb October 8, 2026 18:19
@rajamatt
rajamatt marked this pull request as ready for review October 13, 2026 16:39

@dr1rrb dr1rrb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving: the fix works, and the new tests fail on main and pass here.

➡️ Medium: 2 medium, 1 low.

The main concern is design rather than correctness: handling one specific third-party type (IMessenger) inside the mock generator is a special case that does not scale to the other eagerly used ctor dependencies, which spec 013 R1 already plans to cover through [CtorDependency(Eager = true)]. Please mark it as a stopgap in the spec.

  • Record the messenger special case as a stopgap until R1.
  • Keep one generator test without CommunityToolkit.Mvvm.
  • Qualify IMessenger in rules.md and testing.md.

Comment thread doc/Reference/Reactive/rules.md Resolved
rajamatt and others added 2 commits October 14, 2026 13:25
- Run() references CommunityToolkit.Mvvm only when a test opts in, so the generator
  tests stand for a consumer without the toolkit again
- a compilation without the toolkit, even with its own IMessenger, gets a mock that
  names nothing from it
- the messenger tests opt in

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- spec 013 architecture and history v18: the messenger is a stopgap until R1, not a
  list of known types; R1 can make a fresh messenger the default of an IMessenger argument
- the generator's CtorArgument says not to add other known types
- rules.md and testing.md: every parameter typed CommunityToolkit.Mvvm.Messaging.IMessenger

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mergify

mergify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@rajamatt
rajamatt merged commit 93308af into main Oct 14, 2026
26 of 27 checks passed
@rajamatt
rajamatt deleted the dev/mara/mock-create-messenger branch October 14, 2026 17:54
@rajamatt

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport servicing/7.4

@mergify

mergify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

backport servicing/7.4

✅ Backports have been created

Details

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.

3 participants