Skip to content

fix(hottesting): let derived feeds observe mocked inputs - #3192

Merged
rajamatt merged 11 commits into
mainfrom
dev/mara/mocking-derived-feeds-hottesting
Oct 2, 2026
Merged

rajamatt merged 11 commits into
mainfrom
dev/mara/mocking-derived-feeds-hottesting

Conversation

@rajamatt

@rajamatt rajamatt commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Refs unoplatform/studio.live#4074

PR Type

  • Bugfix

Current behavior

Generated MVUX mocks replace a state above the context-shared subscription. Derived feeds (Select, Where, Combine, list operators, Messages(), and dynamic feeds) therefore continue to read the real input, which can reach null-injected services and fail.

New behavior

  • FeedSubscription owns the optional HotSwapFeed and is the single source-replacement point shared by states and operators.
  • Hot reload and mocking use that same subscription-level mechanism.
  • Hot reload aliases a replacement feed identity to the existing subscription, so incremental updates keep the same shared stream.
  • StateImpl no longer owns a generic source hot-swap. Its narrow HotSwap(replacement) redirects future writes to the replacement state.
  • State and subscription caches remain separate, so local state edits do not leak into operator subscribers.
  • HotSwapFeed always enumerates its wrapped feed with GetSource; resolving it through the context would return the same subscription recursively.
  • Every subscription, including a state's internal UpdateFeed, uses the same wrapper. Eager states and updates without a subscriber explicitly connect their subscription.
  • Subscription identity aliases use the same StateStore insertion path as normal subscription creation.

Verification

  • Focused subscription/state/mocking coverage: 34 passed.
  • Every non-UI unit-test project: 1,652 passed, 19 skipped.
  • No public API changes.

Review notes

Start with FeedSubscription, HotSwapFeed, StateStore, StateImpl.HotSwap, MockingService, and BindableViewModelBase.HotReload. Given_FeedSubscription covers direct enumeration, explicit eager activation, existing-subscriber replacement, and feed-identity aliasing. Given_StateImpl covers updates without subscribers, including redirected lazy states. Spec 013 records the selected architecture and self-resolution guard.

@rajamatt
rajamatt marked this pull request as draft September 28, 2026 23:08
@rajamatt
rajamatt requested a review from dr1rrb September 28, 2026 23:40
@rajamatt
rajamatt marked this pull request as ready for review September 28, 2026 23:40
rajamatt and others added 6 commits October 1, 2026 19:33
- in a mocking context, SourceContext.GetOrCreateSource asks the mocking layer which source to subscribe to; core only gains that hook (IMockingSourceResolver, registered by MockingService next to the activation probe), also used by FeedDependency for dynamic feeds
- Uno.HotTesting.Reactive resolves each observed feed to one swap layer per state store, and SwapFeed/SwapListFeed swap it together with the state (a list feed under both its keys), so Select, Where, list operators and dynamic feeds see a mocked input
- derivations observe the layer below the state's own updates, so a state edit stays local as in a live app; the resolver takes none of the store's locks
- live (non-mocking) contexts never consult the resolver and keep the existing subscription path
- tests: derived member computes over the mock and recomputes on re-swap, list Where computes over the mock, override still wins, state edits stay local, dynamic feed recomputes over a swapped list, a live context subscribes to its input directly

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… derived feeds

- spec 013 architecture, implementation and spec text now describe the resolver hook and the per-feed swap layer instead of the factory-cache wrap that was never built
- history v16 records the fix, the drafts dropped in review, and the D6 row update

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… of the resolver

- the state observes the layer of its feed like the feeds derived from it, so SwapFeed/SwapListFeed now point that one layer at the mock, through an UnroutedFeed; a list feed no longer needs a second key
- a mock that is the member's own feed now restores the real feed instead of making the layer observe itself, and a replacement no longer gets a layer of its own on every SetMock
- the resolver leaves every state as-is, list states included (IListState is not an IState<IImmutableList<T>>)
- the resolver is registered before the activation probe; its contract and the mocking behaviour of GetOrCreateSource are documented
- tests: a two-level scalar chain computes over the mock and recomputes on re-swap, the member's own feed restores the real input, the live-context guard now asserts the resolver is never consulted, and LongItems is classified optional

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rivations observe

- spec 013 now says SetMock is a typed swap of the member's layer, lists the resolver in the seams table, and records the accepted costs (no completion under mocking, one layer per observed feed)
- the remaining "reflection over IHotSwapState" wording and the D6 row are aligned with the implementation

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A member's state and the feeds derived from it already read the feed through one subscription of the context; the swap sat above it, in the state.
- In a mocking context, that subscription now reads its feed through a HotSwapFeed, and SetMock swaps it: the state and every derivation see the mock.
- A state input is still swapped as a state, and a state's UpdateFeed is never wrapped.
- Replaces the source resolver, so core no longer calls into the mocking package.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The state and every derivation read one subscription per feed, which a mocking context can swap.
- The source resolver moves to the dropped drafts in history v16.

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

dr1rrb commented Oct 1, 2026

Copy link
Copy Markdown
Member

Following a deeper pass through the history, I think this is a general hot-swap placement issue rather than a mocking-specific mechanism.

FeedSubscription was introduced by #711 in September 2022. That change deliberately replaced GetOrCreateStateCore(feed).GetSource(...) with a separate cached subscription so operators could share intermediate sources without sharing mutable state edits. Hot reload support came later in #1805 (August–October 2023), and injected HotSwapFeed only inside StateImpl. Consequently, swapping that state redirects the bindable branch, while Select/Where/other operators still consume the context's earlier shared subscription for the original feed.

I think the consistent design is:

  • make FeedSubscription own the optional HotSwapFeed, as the single replacement point shared by states and operators;
  • use that same mechanism for both hot reload and mocking;
  • remove the HotSwapFeed and generic hot-swap behavior from StateImpl entirely;
  • preserve the separate state/subscription caches so local mutable state edits do not leak into non-state subscriptions (we should still verify that this remains the intended semantic);
  • when hot reload replaces a feed, cache/alias the replacement feed to the existing subscription, just as it currently aliases the replacement to the existing state;
  • retain only the narrow state-to-state handoff needed to keep writes targeting the replacement state;
  • have the subscription-level wrapper enumerate the wrapped feed directly. Calling context.GetOrCreateSource(feed) there would resolve the same subscription recursively; this needs an explicit comment.

The current PR has most of the necessary subscription-level primitive, but keeping both the state-level and subscription-level hot-swap paths leaves two competing mechanisms. I am going to update the branch and spec around one subscription-owned mechanism, with coverage for derived feeds, hot reload, real state inputs, state-edit isolation, re-swap, and the self-resolution guard.

Use the context shared FeedSubscription as the only source-replacement point for hot reload and mocking. Preserve state update handoff and alias replacement feed identities for incremental hot reload.
@dr1rrb
dr1rrb force-pushed the dev/mara/mocking-derived-feeds-hottesting branch from 33cbb9d to 2d162f2 Compare October 1, 2026 20:13
@dr1rrb

dr1rrb commented Oct 1, 2026

Copy link
Copy Markdown
Member

Note: pushed an updated implementation based on my research, but it yet validated.

dr1rrb added 4 commits October 1, 2026 23:22
Remove the transitional dual-mode hot-swap path and keep subscription identity aliases behind StateStore shared cache insertion logic. Cover direct enumeration and replacement identity continuity at the FeedSubscription boundary.
Name state replacement after the operation while keeping UpdateFeed subscriptions direct so state updates activate before the first subscriber. Add a focused guard test and document the invariant.
Wrap UpdateFeed subscriptions consistently for hot reload and mocking. Connect eager subscriptions through FeedSubscription and activate the final redirected state before applying updates without a subscriber.
The SessionCurrentEnumerator GetSource wrapper only forwarded to the feed; fold it into GetEnumerator with a null-conditional call.
@mergify

mergify Bot commented Oct 2, 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 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@dr1rrb Verified and reviewed your additional changes, the fix still works. So now we can remove the "set every derived member" rule from the agent mocking skill

@rajamatt
rajamatt merged commit 8f03e82 into main Oct 2, 2026
24 of 25 checks passed
@rajamatt
rajamatt deleted the dev/mara/mocking-derived-feeds-hottesting branch October 2, 2026 14:24
@kazo0

kazo0 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@Mergifyio backport servicing/7.4

@mergify

mergify Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

backport servicing/7.4

✅ Backports have been created

Details

kazo0 added a commit that referenced this pull request Oct 7, 2026
…-3192

fix(hottesting): let derived feeds observe mocked inputs (backport #3192)
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