Skip to content

Extract AniSprinkles.Core class library to unblock PageModel/Services unit tests #62

Closed

Description

@zhollis21

Background

PR #61 (tech-debt umbrella) added DI abstractions (INavigationService, IPreferences, IDispatcher, TimeProvider) to the three PageModels so they can be exercised from unit tests. However, the Phase-1 PageModel tests from #52 did not ship in that PR.

Blocker

tests/AniSprinkles.UnitTests targets net10.0 (plain — no Android workload required) and link-compiles source files from src/ rather than project-referencing the MAUI app. This works for pure-algorithm code (e.g. MediaListSectionsMerger) but fails for PageModels.

Re-measured 2026-08-22 against the versions currently pinned; two of the three package claims below were wrong. Method and evidence in the verification comment on this issue.

  • Microsoft.Maui.Controls has no net10.0 target (platform-specific TFMs only), so Shell, Keyboard, VisualElement etc. don't resolve. It does have one — Microsoft.Maui.Controls.Core / .Xaml 10.0.60 ship net10.0, and Shell, Keyboard, VisualElement and DisplayPromptAsync all resolve.
  • CommunityToolkit.Maui (Popup types) has the same restriction. It does not — 14.2.0 ships lib/net10.0, and Popup, PopupOptions and ShowPopupAsync all resolve.
  • IconFont.Maui.FluentIcons 1.1.0 is platform-specific (net10.0-android36.0 / -ios26.0 / -maccatalyst26.0 only). This one still blocks.

What actually blocks the move:

  1. IconFont glyph constants — 15 files across PageModels/, Converters/ and Services/; 57 distinct members.
  2. XAML-backed popups in AniSprinkles.Views — EntryActionCoordinator, ListEntryStatusFlow, SettingsPageModel, MediaDetailsPageModel.
  3. Android platform types — AuthService (Android.Webkit) and AiringNotificationService (AndroidX.Work), both already behind interfaces and both staying in the app project.

Everything else in Models/, Utilities/, Services/ and PageModels/ compiles clean on net10.0 as it stands.

Proposal

Extract a new src/AniSprinkles.Core/ class library targeting net10.0 containing code that has no MAUI-UI dependency:

  • Models/ (AniList DTOs and domain types)
  • Services/ (non-platform services: AniListClient, AuthService body, ErrorReportService, FileLoggerProvider)
  • Services/Abstractions/ (INavigationService)
  • PageModels/ — all of it. The Popup / Shell / Browser call sites move behind new IDialogService and IExternalBrowser abstractions (see Risks below) rather than into partial files.

The MAUI app project references the Core library; the test project also references it. Both project-reference instead of link-compile, eliminating the source-file glob in the unit-tests csproj.

Benefits

Risks / open questions

  • IDialogService and IExternalBrowser are in scope, not deferred. The five XAML popups (ActionMenuPopup, MoveToListPopup, EditProgressPopup, ConfirmPopup, RatingPopup), Shell.Current.DisplayPromptAsync, and the four Browser.Default.OpenAsync sites go behind Core interfaces implemented in src/Services/Maui/, alongside the existing MauiShellNavigationService / MauiUserFeedback.
  • The IconFont glyph table is mirrored into Core as generated constants; the MAUI project and XAML keep the package. Add a test that validates x:Static icon glyph references in XAML #117's test is extended to assert the mirrored names and values against the package assembly, so the copy cannot drift.
  • FileLoggerProvider uses FileSystem.Current.AppDataDirectory — may need to inject a path resolver. It does not. It takes logDirectory as a constructor parameter; the path is resolved by the caller in MauiProgram.cs. No path resolver needed.
  • OutageStateService.DispatchOrInvoke calls MainThread.IsMainThread, which throws NotImplementedInReferenceAssemblyException on plain net10.0 — the existing catch (InvalidOperationException) does not cover it, despite the comment claiming it falls back safely in unit tests. Fixed as part of the move by routing through the injected IDispatcher.

Acceptance

Activity

  1. added
    enhancement
    p3-medium
    Tech Debt
    on Apr 18, 2026
  2. zhollis21 commented on Aug 22, 2026

    @zhollis21
    OwnerAuthor

    Evidence from #116 — six bugs this would have caught

    #116 (bottom tab bar) went through six review rounds. Every round found real defects, and all of them live in exactly the code this issue is about: PageModel state machines and async ordering. None were reachable by the current 391-test suite, which covers pure algorithms and XAML well-formedness only.

    Recording them here because the argument for this extraction is much stronger with specifics than in the abstract.

    # Defect Fixed in
    1 Search context recorded on fetch success rather than at issue time. A first search still in flight left the "nothing searched yet" flag set, so a user who tabbed away, flipped the adult toggle and returned had the new context baselined without cancelling the old request. Its response then landed and marked itself current — and no later appearance would ever invalidate it. 054c3f6
    2 Load More gated only on the in-flight window. A failed page 1 clears IsSearching in finally (that is what stops the spinner), re-arming Load More while the section still held the previous query's items and HasNextPage. Scrolling then appended page 2 of the new query onto the old query's results — one list silently mixing two searches. 121c8af
    3 _searchedAuthenticated written before the cancellation check, so a superseded search resuming late could clobber a newer search's recorded context. 48e5ca0
    4 An unconditional OperationCanceledException rethrow in AuthService turned a survivable cleanup failure into a crash. Ten call sites across six page models call GetAccessTokenAsync with no token from async void lifecycle paths; SignOutAsync can surface a cancellation of its own via MainThread.InvokeOnMainThreadAsync during teardown. 8ea0cbb
    5 The adult filter read live, per page, instead of being pinned to the result set. Settings debounces 1500 ms and only applies the value from the server response, so a user could toggle, return to Search inside that window (nothing detected as changed), and have the new value land in time for Load More to page a different policy onto results already on screen. Turning adult content off left 18+ page-1 items visible with SFW pages beneath. f575d36
    6 Discover's Load More guard covered only the window after IsBusy went up, but LoadAsync awaits the auth read before setting it — leaving that suspension open for a page fetched under a context the refresh was about to replace. f575d36

    Why this is the right evidence for this issue

    Three of the six were regressions introduced by the previous round's fix. #2 was a half-fix of #1's neighbouring problem, #4 was introduced by the fix in #3's round, and #6 was a hole in a guard added earlier in the same PR. That is the signature of code whose correctness rests on a reasoning argument with nothing executable to check it: each fix was defensible in isolation and each broke or missed something adjacent.

    Device verification cannot reach any of them. Every one needs a specific interleaving — a request failing at a precise moment, a superseded continuation resuming after a newer one, a debounced settings write landing between two reads. The /run-anisprinkles pass confirms the happy path and nothing more. Several were also explicitly not device-verifiable because the CI stubs replace AuthService entirely under CiBuild=true.

    None of them need MAUI to test. They are all decisions about ordering and flags:

    Each is a handful of lines against a fake IAniListClient once SearchPageModel / DiscoverPageModel are in a net10.0 library. That is precisely what the link-compile setup blocks today.

    Suggested scope note

    SearchPageModel and DiscoverPageModel are the highest-value first movers for #52 Phase 1 once this lands — they hold the debounce, the generation guarding, the context invalidation and the paging interlocks, which is where all six of the above concentrated.

  3. zhollis21 commented on Aug 22, 2026

    @zhollis21
    OwnerAuthor

    Verification notes (2026-08-22)

    Re-measured the blocker before planning. Two of the three package restrictions in the Blocker section above no longer hold on the versions this repo is currently pinned to.

    What the packages actually ship

    Package Version in src/AniSprinkles.csproj Has a plain net10.0 lib?
    Microsoft.Maui.Controls (via .Controls.Core / .Controls.Xaml) 10.0.60 Yes
    CommunityToolkit.Maui 14.2.0 Yes
    Microsoft.Maui.Essentials / Microsoft.Maui.Core 10.0.60 Yes
    IconFont.Maui.FluentIcons 1.1.0 No — net10.0-android36.0, -ios26.0, -maccatalyst26.0 only

    Confirmed by building a throwaway net10.0 project that references Microsoft.Maui.Controls 10.0.60 + CommunityToolkit.Maui 14.2.0 and compiles Shell.Current, Shell.DisplayPromptAsync(..., keyboard: Keyboard.Numeric), PopupOptions with a Shapes.RoundRectangle, and page.ShowPopupAsync<object>(...). Build succeeded, 0 warnings, 0 errors.

    Measured blocker inventory

    Link-compiled all of src/Models/, src/Utilities/, src/Services/, src/Services/Abstractions/, src/PageModels/ and src/Converters/ into a net10.0 probe project. Everything that fails does so for one of three reasons:

    1. IconFont.Maui.FluentIcons — 15 files, 57 distinct members (FluentIconsRegular.*, FluentIconsFilled.*): Converters/FavouriteHeartConverters.cs, Converters/MediaFormatIcons.cs, Services/AniListApiException.Icon.cs, Services/ListEntryStatusFlow.cs, and 11 files under PageModels/.
    2. XAML-backed popups in AniSprinkles.Views — PageModels/EntryActionCoordinator.cs:6, Services/ListEntryStatusFlow.cs:2, PageModels/SettingsPageModel.cs:665,754, PageModels/MediaDetailsPageModel.cs:1229 (ConfirmPopup, ActionMenuPopup, MoveToListPopup, EditProgressPopup, RatingPopup).
    3. Android platform types — Services/AuthService.cs:1 (Android.Webkit, Java.Lang) and Services/AiringNotificationService.cs:1-2 (AndroidX.Work, AniSprinkles.Platforms). Both already sit behind IAuthService / IAiringNotificationService.

    Nothing else fails. All of Models/, all of Utilities/ (including AppSettings.Storage.cs), AniListClient, CachingAniListClient, AniListRateLimitHandler, AniListErrorClassifier, ErrorReportService, FileLoggerProvider, LoggingHandler, OutageStateService and ListEntryStatusMutations compile clean on net10.0 as they stand.

    Two open questions in the body are already answered

    • FileLoggerProvider does not use FileSystem.Current.AppDataDirectory. It takes logDirectory as a constructor parameter (src/Services/FileLoggerProvider.cs:12); the path is resolved by the caller in src/MauiProgram.cs:42. No path-resolver injection needed.
    • AppSettings.Storage.cs compiles on net10.0 unchanged — Microsoft.Maui.Essentials 10.0.60 has a net10.0 target, so Preferences resolves.

    First-mover confirmation

    PageModels/SearchPageModel.cs has zero references to IconFont, popups or Shell. PageModels/DiscoverPageModel.cs has exactly one — the FluentIconsRegular.ErrorCircle24 fallback at line 265. The only thing stopping either from compiling on net10.0 today is the concrete EntryActionCoordinator field type (SearchPageModel.cs:32, DiscoverPageModel.cs:28).

    Measurement trap

    An unresolved using directive (CS0246) suppresses method-body binding errors elsewhere in the same compilation. A first pass that left AniListApiException.Icon.cs in the probe reported 19 errors and showed SettingsPageModel as clean; removing that one file surfaced its Views.ConfirmPopup and FluentIconsRegular failures. Anyone re-running this needs to drop the files with failing platform usings before trusting the error count.

  4. zhollis21 commented on Aug 22, 2026

    @zhollis21
    OwnerAuthor

    Updated during planning:

    • Blocker — the Microsoft.Maui.Controls and CommunityToolkit.Maui claims are struck; both ship net10.0 libs on the versions pinned here. Replaced the "~37 errors" figure with the measured blocker inventory (IconFont, XAML popups, Android types). Evidence in the verification comment above.
    • Proposal — PageModels/ moves wholesale rather than partially, so the "small cleanup pass / partial files" wording is gone.
    • Benefits — #if CI stubs stay in the app project, not Core; they are internal, so moving them would mean widening their visibility for no gain.
    • Risks — IDialogService / IExternalBrowser are in scope now rather than deferred; the FileLoggerProvider path-resolver concern is struck (it already takes logDirectory as a parameter); added the OutageStateService / MainThread defect found while verifying.
    • Acceptance — three items added for the above.

    Scope decided alongside this: move everything movable (not just Search/Discover), mirror the IconFont glyphs into Core as generated constants, and land #117 and a first slice of #52 on the same branch — #117 is what keeps the mirrored glyph table honest. #119 is not unblocked by this work: AuthService uses Android.Webkit and stays in the app project either way.

  5. zhollis21 commented on Aug 22, 2026

    @zhollis21
    OwnerAuthor

    Implementation notes, for whoever reviews the branch.

    Three things surfaced during the work that are tracked separately rather than folded in:

    Also fixed in passing, because the move exposed them: OutageStateService called MainThread.IsMainThread, whose NotImplementedInReferenceAssemblyException its catch (InvalidOperationException) never covered — so the comment promising an inline fallback in unit tests was never true; and SettingsPageModel read AppInfo.Current in a field initializer, so the type could not be constructed off-device at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Tech Debtenhancementp3-medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions