Skip to content

Tech debt: logging reach, test-project abstractions, merger batching (#23, #52, #59) - #61

Merged
zhollis21 merged 19 commits into
mainfrom
chore/logging-tests-batching
Apr 19, 2026
Merged

zhollis21 merged 19 commits into
mainfrom
chore/logging-tests-batching

Conversation

@zhollis21

Copy link
Copy Markdown
Owner

Umbrella branch for three follow-up items from PR #58 (pull-to-refresh fix). Four commits, each green on its own.

Summary

Commit 1 — Bridge ILogger to logcat on Android (#23)

  • New AndroidLogcatLoggerProvider registered in MauiProgram.cs; all ILogger<T> writes now surface in adb logcat in both Debug and Release.
  • Inline comment on MainActivity.cs / AiringCheckWorker.cs documenting why they still call Android.Util.Log directly (pre-DI lifecycle).

Commit 2 — Release file logging + docs (#23)

  • FileLoggerProvider now runs in Release too (256 KB × 3 at LogLevel.Warning); Debug unchanged (1 MB × 3 at LogLevel.Debug).
  • AGENTS.md and /ani-debug skill updated to document the expanded logging reach.

Commit 3 — PageModel DI abstractions (#52, partial)

  • New INavigationService (+ MauiShellNavigationService adapter); PageModels now depend on IPreferences, IDispatcher, INavigationService / TimeProvider via ctor DI instead of Shell.Current, Preferences.Default, MainThread.BeginInvokeOnMainThread.
  • Test project adds Microsoft.Maui.Essentials / Microsoft.Maui.Core / NSubstitute and link-compiles Services/Abstractions/*.cs.
  • Phase-1 PageModel tests deferred: Microsoft.Maui.Controls and CommunityToolkit.Maui have no net10.0 target, so the PageModels themselves still can't be link-compiled into the unit-test project. Unblocking them requires either splitting PageModels into non-UX partials or extracting an AniSprinkles.Core class library — both out of scope for this umbrella. Rationale documented in AGENTS.md.

Commit 4 — Merger batching (#59)

  • New IDisposable BeginBulkUpdate() scope on MediaListSection; per-call UpdateItems() is deferred while the scope is alive and runs once on Dispose.
  • MediaListSectionsMerger.Merge opens a scope per touched section lazily and disposes them in a finally block — one Reset per affected section instead of one per mutation.
  • Five new tests cover bulk-remove, cross-section move, untouched-section no-op, nested scopes, and empty-scope no-op.

Tradeoffs

  • Release file logging adds synchronous file I/O on the warning path. Sentry already captures Warning+; the file is the offline/share-by-email fallback. Tight rotation caps (256 KB × 3) keep storage bounded.
  • The abstraction migration churned three PageModels. Each was rebuilt and CI-checked separately. No behavior changes.
  • The bulk-update scope is internal to MediaListSection — callers that don't opt in (cold-path BuildSections, RefreshVisibleItems) keep the original per-call behavior.

Test plan

  • dotnet build src/AniSprinkles.csproj -c Debug -f net10.0-android — zero errors
  • dotnet build src/AniSprinkles.csproj -c Release -f net10.0-android — zero errors
  • dotnet build src/AniSprinkles.csproj -c Debug -f net10.0-android -p:CiBuild=true — zero errors
  • dotnet test tests/AniSprinkles.UnitTests — 43 / 43 pass (38 existing + 5 new batching tests)
  • Emulator smoke: pull-to-refresh on MyAnime, navigate to details, flip settings toggles — parity with today
  • Emulator smoke: /ani-debug after a status-change burst shows one Reset per affected section (was N per mutation)
  • Release install: adb shell run-as com.RainbowSprinkles.AniSprinkles cat files/logs/anisprinkles.log shows warning+ entries

Closes #23
Closes #59
Partially addresses #52 (abstractions landed; PageModel test coverage follow-up)

Zach Hollis added 4 commits April 18, 2026 00:49
Add AndroidLogcatLoggerProvider so Microsoft.Extensions.Logging output
reaches adb logcat on device. AddDebug() does not bridge to logcat on
.NET MAUI Android (verified empirically — zero ILogger lines visible in
logcat pre-fix despite plenty of output in the file log).

Registered under #if ANDROID for all build configs so device diagnostics
work in Release too. Framework namespaces stay filtered at Warning to
avoid firehose output.

Left MainActivity and AiringCheckWorker on Android.Util.Log directly —
both run before the DI container is guaranteed to be ready (lifecycle
callbacks; post-reboot WorkManager). Added inline comments documenting
the convention.
Move FileLoggerProvider registration outside the #if DEBUG block so
Release installs also keep a bounded local ring buffer for user-shared
diagnostics. Debug preserves current behavior (1 MB × 3 at Debug); Release
gets a tighter 256 KB × 3 at Warning so the log cannot grow silently on
long-running installs. Sentry still handles the cloud side at Warning+;
the file log is the offline/share-by-email fallback.

Update AGENTS.md with the full ILogger convention: DI-injected
ILogger<T> is the only sanctioned path, the two Android.Util.Log
exceptions (MainActivity, AiringCheckWorker) are documented with the
pre-DI rationale, and the on-device log file path is called out for
anyone grabbing diagnostics from a release build.
…52)

PageModels no longer reach for MAUI statics (Shell.Current.GoToAsync,
Preferences.Default, MainThread.BeginInvokeOnMainThread) on their state paths —
those go through constructor-injected abstractions so the state machines can be
exercised without a live MAUI shell. UX-only sites (DisplayAlertAsync,
ShowPopupAsync, Browser.Default) stay on MAUI statics; they never run outside a
view-attached path and pulling Popup/dialog types into the abstractions would
bloat them for no test coverage gain.

- New INavigationService abstraction + MauiShellNavigationService adapter.
- TimeProvider.System registered via TryAddSingleton so tests can swap in
  FakeTimeProvider without the app discovering a default.
- Test project picks up Microsoft.Maui.Essentials + Microsoft.Maui.Core
  (IPreferences / IDispatcher resolve on plain net10.0) and NSubstitute 5.3.0.

Phase-1 PageModel tests from the umbrella plan are deferred: the PageModel
source files transitively reference CommunityToolkit.Maui (Popup) and
Microsoft.Maui.Controls (Shell, Keyboard), which don't have net10.0 targets
and block link-compile. The abstractions here are the precondition for that
work once PageModels are split into non-UX partials or an AniSprinkles.Core
class library is extracted.
MediaListSectionsMerger.Merge previously called section mutators one
item at a time, each triggering UpdateItems() -> ReplaceItems() ->
NotifyCollectionChanged Reset. A bulk scenario (e.g. 20 cross-section
status-change moves) fired ~20 Resets per affected section, each
forcing RecyclerView to rebind every visible cell.

Introduce an IDisposable BeginBulkUpdate() scope on MediaListSection:
per-call UpdateItems() is deferred while the scope is alive, and runs
once on Dispose (skipped entirely if no mutation actually occurred
between Begin and End). Nested scopes are supported via a depth
counter; only the outermost Dispose triggers the rebuild.

Merge() opens a scope per touched section lazily via ScopeFor(), and
disposes them in a finally block. Sections not mutated by a merge pay
zero cost. try/finally keeps scopes from leaking if the merge throws.

Add 5 tests covering: bulk remove -> one Reset, cross-section move ->
one Reset per side, unchanged sections -> zero Resets, nested scopes,
and empty-scope no-op.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR bundles three follow-ups to the pull-to-refresh work: expanding Android logging visibility (logcat + Release file logs), introducing DI-friendly abstractions for PageModel testability, and batching MediaListSection updates during merges to reduce redundant collection Resets.

Changes:

  • Add an Android ILogger → logcat bridge and enable on-device file logging in Release with tighter rotation/levels.
  • Introduce INavigationService (+ MauiShellNavigationService) and migrate select PageModels to DI for navigation/preferences/dispatching.
  • Add a bulk-update scope to MediaListSection, update the merger to use it, and add tests for batching behavior.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/AniSprinkles.UnitTests/MediaListSectionsMergerTests.cs Adds 5 new tests validating bulk-update batching/reset coalescing.
tests/AniSprinkles.UnitTests/AniSprinkles.UnitTests.csproj Adds MAUI Core/Essentials + NSubstitute; link-compiles service abstractions.
src/Services/Maui/MauiShellNavigationService.cs Implements INavigationService via Shell.Current.GoToAsync.
src/Services/Abstractions/INavigationService.cs Adds route-based navigation abstraction for PageModels.
src/Platforms/Android/MainActivity.cs Documents why Android lifecycle logging stays on Android.Util.Log.
src/Platforms/Android/AndroidLogcatLoggerProvider.cs New custom logging provider bridging ILogger to logcat.
src/Platforms/Android/AiringCheckWorker.cs Documents why WorkManager path logs directly to logcat pre-DI.
src/PageModels/SettingsPageModel.cs Switches to injected IPreferences/IDispatcher for testability.
src/PageModels/MyAnimePageModel.cs Switches to injected IPreferences/INavigationService.
src/PageModels/MediaListSectionsMerger.cs Uses per-section bulk-update scopes to batch resets during merge.
src/PageModels/MediaListSection.cs Adds BeginBulkUpdate() batching scope with nested-depth + dirty flag.
src/PageModels/MediaDetailsPageModel.cs Switches navigation to injected INavigationService.
src/MauiProgram.cs Wires new logging providers + DI registrations (TimeProvider, INavigationService).
src/GlobalUsings.cs Adds global using for AniSprinkles.Services.Abstractions.
AGENTS.md Updates architecture/docs for logging reach and test project constraints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/MauiProgram.cs Resolved
@github-actions

github-actions Bot commented Apr 18, 2026 •

Copy link
Copy Markdown
Contributor

📱 UI Screenshots

✅ Authenticated UI — screenshots rendered via compile-time CI stub services with hardcoded data. No OAuth token required.

View Workflow Run →

My Anime One Piece Details Settings
My Anime One Piece Details Settings

Zach Hollis and others added 3 commits April 18, 2026 23:48
Fix startup crash from missing IPreferences registration (MAUI exposes it
as a static only; DI had no default). Add explicit filter for the logcat
provider so app-category logs honor the per-config minimum. Log a warning
when Shell.Current is null during navigation instead of silently no-op'ing.
Correct XML doc cref that didn't resolve to a type.
Add generic review items that apply to any change: tests, build & test
health, dead code, scope discipline, error handling, logging, conventions,
public API surface, TODOs, commit-readiness. Scope discipline explicitly
carves out tracked issues for half-finished work and unrelated fixups.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 19 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

When the merger creates a brand-new section, seed AddItems/ApplySort/
ApplyFilter inside a narrow using-scope that disposes before existing.Add
publishes the section. Previously the section was added to the outer
ObservableCollection while its bulk-update scope was still open, exposing
an empty visible collection and a stale FilteredCount/DisplayCount until
the outer finally block ran.
@zhollis21
zhollis21 requested a review from Copilot April 19, 2026 05:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 19 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

github-actions Bot and others added 3 commits April 19, 2026 05:10
Asserts TotalCount, FilteredCount, DisplayCount, and visible Count on the
newly-added MediaListSection at the moment it fires Add on the outer
ObservableCollection. Fails without the publish-after-scope-dispose fix.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 19 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zhollis21
zhollis21 requested a review from Copilot April 19, 2026 16:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 19 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/MauiProgram.cs Resolved
Comment thread src/PageModels/MediaListSection.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 19 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/PageModels/MediaListSection.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 19 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zhollis21
zhollis21 merged commit b96e96c into main Apr 19, 2026
3 checks passed
@zhollis21
zhollis21 deleted the chore/logging-tests-batching branch April 19, 2026 18:29
zhollis21 added a commit that referenced this pull request Nov 19, 2026
…23, #52, #59) (#61)

* Bridge ILogger to logcat on Android (#23)

Add AndroidLogcatLoggerProvider so Microsoft.Extensions.Logging output
reaches adb logcat on device. AddDebug() does not bridge to logcat on
.NET MAUI Android (verified empirically — zero ILogger lines visible in
logcat pre-fix despite plenty of output in the file log).

Registered under #if ANDROID for all build configs so device diagnostics
work in Release too. Framework namespaces stay filtered at Warning to
avoid firehose output.

Left MainActivity and AiringCheckWorker on Android.Util.Log directly —
both run before the DI container is guaranteed to be ready (lifecycle
callbacks; post-reboot WorkManager). Added inline comments documenting
the convention.

* Enable Release file logging + document ILogger conventions (#23)

Move FileLoggerProvider registration outside the #if DEBUG block so
Release installs also keep a bounded local ring buffer for user-shared
diagnostics. Debug preserves current behavior (1 MB × 3 at Debug); Release
gets a tighter 256 KB × 3 at Warning so the log cannot grow silently on
long-running installs. Sentry still handles the cloud side at Warning+;
the file log is the offline/share-by-email fallback.

Update AGENTS.md with the full ILogger convention: DI-injected
ILogger<T> is the only sanctioned path, the two Android.Util.Log
exceptions (MainActivity, AiringCheckWorker) are documented with the
pre-DI rationale, and the on-device log file path is called out for
anyone grabbing diagnostics from a release build.

* Inject INavigationService, IPreferences, IDispatcher into PageModels (#52)

PageModels no longer reach for MAUI statics (Shell.Current.GoToAsync,
Preferences.Default, MainThread.BeginInvokeOnMainThread) on their state paths —
those go through constructor-injected abstractions so the state machines can be
exercised without a live MAUI shell. UX-only sites (DisplayAlertAsync,
ShowPopupAsync, Browser.Default) stay on MAUI statics; they never run outside a
view-attached path and pulling Popup/dialog types into the abstractions would
bloat them for no test coverage gain.

- New INavigationService abstraction + MauiShellNavigationService adapter.
- TimeProvider.System registered via TryAddSingleton so tests can swap in
  FakeTimeProvider without the app discovering a default.
- Test project picks up Microsoft.Maui.Essentials + Microsoft.Maui.Core
  (IPreferences / IDispatcher resolve on plain net10.0) and NSubstitute 5.3.0.

Phase-1 PageModel tests from the umbrella plan are deferred: the PageModel
source files transitively reference CommunityToolkit.Maui (Popup) and
Microsoft.Maui.Controls (Shell, Keyboard), which don't have net10.0 targets
and block link-compile. The abstractions here are the precondition for that
work once PageModels are split into non-UX partials or an AniSprinkles.Core
class library is extracted.

* Batch MediaListSection mutations during pull-to-refresh merge (#59)

MediaListSectionsMerger.Merge previously called section mutators one
item at a time, each triggering UpdateItems() -> ReplaceItems() ->
NotifyCollectionChanged Reset. A bulk scenario (e.g. 20 cross-section
status-change moves) fired ~20 Resets per affected section, each
forcing RecyclerView to rebind every visible cell.

Introduce an IDisposable BeginBulkUpdate() scope on MediaListSection:
per-call UpdateItems() is deferred while the scope is alive, and runs
once on Dispose (skipped entirely if no mutation actually occurred
between Begin and End). Nested scopes are supported via a depth
counter; only the outermost Dispose triggers the rebuild.

Merge() opens a scope per touched section lazily via ScopeFor(), and
disposes them in a finally block. Sections not mutated by a merge pay
zero cost. try/finally keeps scopes from leaking if the merge throws.

Add 5 tests covering: bulk remove -> one Reset, cross-section move ->
one Reset per side, unchanged sections -> zero Resets, nested scopes,
and empty-scope no-op.

* CI: Update UI screenshots [skip ci]

* Register IPreferences in DI + address PR #61 review feedback

Fix startup crash from missing IPreferences registration (MAUI exposes it
as a static only; DI had no default). Add explicit filter for the logcat
provider so app-category logs honor the per-config minimum. Log a warning
when Shell.Current is null during navigation instead of silently no-op'ing.
Correct XML doc cref that didn't resolve to a type.

* Expand ani-review checklist with engineering hygiene sections

Add generic review items that apply to any change: tests, build & test
health, dead code, scope discipline, error handling, logging, conventions,
public API surface, TODOs, commit-readiness. Scope discipline explicitly
carves out tracked issues for half-finished work and unrelated fixups.

* CI: Update UI screenshots [skip ci]

* Materialize new MediaListSection before publishing to observers

When the merger creates a brand-new section, seed AddItems/ApplySort/
ApplyFilter inside a narrow using-scope that disposes before existing.Add
publishes the section. Previously the section was added to the outer
ObservableCollection while its bulk-update scope was still open, exposing
an empty visible collection and a stale FilteredCount/DisplayCount until
the outer finally block ran.

* CI: Update UI screenshots [skip ci]

* Add regression test for new-section materialization

Asserts TotalCount, FilteredCount, DisplayCount, and visible Count on the
newly-added MediaListSection at the moment it fires Add on the outer
ObservableCollection. Fails without the publish-after-scope-dispose fix.

* CI: Update UI screenshots [skip ci]

* Enhance bulk update handling in MediaListSection and improve test assertions for section removal

* CI: Update UI screenshots [skip ci]

* Enhance logging in AndroidLogcatLoggerProvider and improve bulk update handling in MediaListSection tests

* CI: Update UI screenshots [skip ci]

* Enhance documentation for ApplyFilter method and improve resource management in MediaListSectionsMerger

* CI: Update UI screenshots [skip ci]

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
zhollis21 added a commit that referenced this pull request Nov 19, 2026
Removing screenshots/ from main's history gave every commit a new SHA. The
four commits the create-issue and kickoff skills cite as examples now read
3fb0aa3 (#123), 3707476 (#135), 18d252a (#143) and 30ff33c (#61).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Tech Debt Cleanup, refactoring, or architectural improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Batch MediaListSection mutations during merge to reduce redundant Resets Improve Logging for our App

2 participants