Skip to content

fix(hottesting): mock state and list-state inputs where the state is read (backport #3216) - #3234

Merged
rajamatt merged 10 commits into
servicing/7.4from
mergify/bp/servicing/7.4/pr-3216
Oct 15, 2026
Merged

rajamatt merged 10 commits into
servicing/7.4from
mergify/bp/servicing/7.4/pr-3216

Conversation

@mergify

@mergify mergify Bot commented Oct 14, 2026

Copy link
Copy Markdown

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

PR Type

  • Bugfix

What is the current behavior?

A model input declared as a state is not mocked where the state itself is read:

  • IListState<T> (ListState.Async(this, …)), the usual shape for a list edited elsewhere: {Vm}Mock.Create with ListFeedMock.Value(...) never reaches the view-model. The list's only message has no data and a NullReferenceException from the real loader, which runs against the null-injected service. Every preview of that list shows the error template.
  • IState<T>: feeds derived from the state see the mock, but reading the state itself, as its binding does, runs the real loader.

Cause: every reader of a state ends up at the state's own subscription, over its UpdateFeed. SwapFeed swapped only the context's subscription to the state, which no reader goes through. SwapListFeed swapped the context's subscription keyed on the ListStateImpl, which the list state's own reads, its bindable's included, never go through either. This was a regression of spec 013 v17.

What is the new behavior?

  • For a state input, what is swapped is the feed its UpdateFeed reads, at the context's subscription to it. That subscription is already swappable under mocking, and hot reload uses the same mechanism.
    • The real loader never runs.
    • The state keeps its own updates, so an edit applies over the mock, as it would over a service result in a live app. The bindable and the feeds derived from the state see it.
  • Each SetMock clears the state's updates (UpdateFeed.Clear), so the state starts over from its mock, even when the same mock is re-applied ({Model}Mock.Empty is a single shared instance).
  • A mock that is itself a state also takes the member's writes. Passing the member's own state restores its real loader.
  • A list state is swapped through the state it wraps.
  • Plain feed inputs are unchanged.
  • Rejected alternatives:
    • swapping the state's own subscription straight to the mock makes writes hang;
    • reading a separate state built over the mock for each swap (an earlier commit of this PR) adds a second replacement point next to the shared one, a process-wide table of the built states, and a fire-and-forget dispose.

Reviewer's guide

  • Start here: MockingService.SwapStateSource.
  • Core changes, internal only:
    • UpdateFeed.Clear drops the active updates, and UpdateFeed.Source exposes the feed the updates apply on;
    • StateImpl.Source and StateImpl.ClearUpdates expose them on the state;
    • ListStateImpl.Implementation exposes the state a list state wraps.
  • Commit history: 0f8e3dadb (a state built over the mock for each swap) is superseded by 7cb36e01b.
  • Tests that prove it:
    • the first commit, a43842163, adds tests only: 9 of its 10 tests fail without the fix, with no data and a NullReferenceException. They cover a list state carrying mocked items, re-swap, Loading and Error, restore, an edit kept over the mock, another list state as the mock, and a scalar state read directly. The 10th, a feed derived from a list state, already passed and is kept because the fix changes the path it reads through;
    • 3e9da13a4 adds re-applying the same mock drops an earlier edit (list and scalar), an edit reaches the derived feed, and a scalar re-swap;
    • d243e1d6e covers UpdateFeed.Clear and StateImpl.ClearUpdates directly.
  • Docs: spec 013 architecture, history v19 and decision D6; a paragraph in testing.md.

PR Checklist

  • Unit Tests for the changes have been added: 16 tests (Given_GeneratedMock, Given_SingleProjectMock, Given_UpdateFeed).
  • Contains NO breaking changes: no public API change. Behaviour change: an edit made through a mocked state now shows on the page and in feeds derived from it, as in a live app, and each SetMock starts a state input over from its mock; before, the edit was dropped from what the page showed.
  • Tested code with current supported SDKs: unit tests (rebased on main with fix(hottesting): give mocked view models a messenger #3214: Uno.Extensions.Reactive.Tests, 1486 pass, 19 skipped; Uno.HotTesting.Reactive.Tests, 38 pass; mocking, UpdateFeed and hot-reload tests stable over 3 runs). UI runtime tests not run locally, and not yet checked in a Studio preview.
  • Associated with an issue

Other information

🤖 Generated with Claude Code


This is an automatic backport of pull request #3216 done by [Mergify](https://mergify.com).

@mergify mergify Bot added the conflicts label Oct 14, 2026
@mergify

mergify Bot commented Oct 14, 2026

Copy link
Copy Markdown
Author

Cherry-pick of 78d351f has failed:

On branch mergify/bp/servicing/7.4/pr-3216
Your branch is ahead of 'origin/servicing/7.4' by 5 commits.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit 78d351f.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   doc/Reference/Reactive/testing.md
	modified:   specs/013-mvux-mocking-previews/architecture.md

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   specs/013-mvux-mocking-previews/history.md

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 239579 has failed on uno.extensions.

rajamatt and others added 10 commits October 14, 2026 16:02
- add TasksModel: a service-dependent IListState input and a feed derived from it
- the list state carries mocked items through the view model, re-swaps, pins Loading and Error, restores its own loader, keeps an edit, and accepts another list state as its mock
- a scalar state input read directly carries the mocked value and keeps an edit
- all but the derived-feed test fail on the current code: the state still reads the real, null-injected loader

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit a438421)
- every reader of a state reads the state's own subscription, directly or through the context's subscription to the state; SwapFeed swapped only the latter, and SwapListFeed swapped the context's subscription to the list state, which the list state's own reads (its bindable's included) never go through
- a state input's own subscription now reads a state over the mock, and the member's writes are redirected to that state, so edits apply over the mock and the real loader never runs
- a list state is swapped through the state it wraps; a mock that is the member itself restores its own updates
- StateImpl exposes its subscription and ListStateImpl the state it wraps; ListStateImpl.HotSwap had no caller left and is removed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit d8f6705)
- Spec 013 architecture: a state input is swapped at the state's own subscription,
  over a state built on the mock that also takes the member's writes

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 0ad5bf5)
- re-applying the same mock to a list or scalar state input must drop an earlier edit;
  both fail on the current code, which reuses the state built over that mock instance
- an edit through a mocked list state reaches the feed derived from it
- a scalar state input re-swapped carries the new value
- WaitForMessage joins WaitForData in the shared recorder helpers and reads the count
  once per pass, so a message recorded after the check is not skipped

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 3e9da13)
- each swap of a state input reads a state built for that swap only, so it starts over
  from its mock even when the instance is reused ({Model}Mock.Empty) or given to two members
- the state built by the previous swap is disposed once nothing reads it
- a mock that is itself a state still takes the writes directly; any other IState
  no longer hits an InvalidCastException

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 0f8e3da)
- architecture: an edit of a state built over a feed input stays local; a state input's
  edit reaches its derived feeds, and its mock state lives for one swap
- history v19 explains the move and why v16's lock-ordering objection no longer applies,
  with the remaining limits; D6 names the state input's anchor
- testing.md notes how a mocked state input behaves

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 78d351f)
- the note sat right before the IMPORTANT admonition, and two blockquotes split by a
  blank line fail markdownlint (MD028); it is now a plain paragraph

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit aa992a1)
The swap of a state input built a state over the mock for each swap and read it through
the state's own subscription. That is a second replacement point next to the shared
FeedSubscription hot reload uses, plus a process-wide table of the built states and a
fire-and-forget dispose.

A state input now keeps its own UpdateFeed, and what is swapped is the feed its updates
apply on, through the context's subscription to it. The bindable and the feeds derived from
the state see the mock with the edits over it. SetMock clears the state's updates through
UpdateFeed.Clear, so re-applying the same mock starts over from it. The tests of this PR are
kept unchanged; spec 013 v19, architecture and testing.md describe the new swap.

Limit: a state built over another member feed shares that feed's subscription, so mocking
the state also mocks that feed.

(cherry picked from commit 7cb36e0)
- Clear drops the active updates; once the source has completed, a compacted update
  is undone only if it can roll itself back, so a state's own edit stays applied
- clearing is meant for a source still running, like a mocked one

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 359639a)
- Clear reverts every active update and the feed shows its source again
- a state over a source still running shows that source again once its updates are cleared,
  which is what SetMock relies on

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit d243e1d)
@rajamatt
rajamatt force-pushed the mergify/bp/servicing/7.4/pr-3216 branch from 2c70f58 to d5a8365 Compare October 14, 2026 20:03
@rajamatt
rajamatt enabled auto-merge October 14, 2026 20:11
@mergify

mergify Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Author

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 cd71ba8 into servicing/7.4 Oct 15, 2026
23 checks passed
@rajamatt
rajamatt deleted the mergify/bp/servicing/7.4/pr-3216 branch October 15, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants