Skip to content

Unit-test the reachable core: browse, filtering, logging, and the client (#52) - #142

Merged
zhollis21 merged 6 commits into
mainfrom
feature/52-unit-test-coverage
Aug 27, 2026
Merged

zhollis21 merged 6 commits into
mainfrom
feature/52-unit-test-coverage

Conversation

@zhollis21

Copy link
Copy Markdown
Owner

Closes out the coverage #52 tracks that is actually reachable from the net10.0 test project. 984 → 1171 tests, zero warnings, Core clean in Debug and Release.

Half of #52's "Remaining" list turned out to be already done — #126 landed the day after the issue was last rewritten, and #129/#133 after that. The body and the verified findings were corrected during planning, so what is left here is the work that was genuinely outstanding.

Coverage added

  • MediaBrowsePageModel — the last page model in Core with no test file. The badge sort (the section is seeded with a placeholder sort, so badging off PaginatedSection.Sort would label every section "popularity"), rank continuation across pages, the Load More interlock, the Adult-content setting commits 1.5s late and notifies nobody, leaving 18+ results on screen #118 adult-content pin, the revisit short-circuit for sign-in and toggle changes, view mode, and navigation.
  • MyAnimePageModel — the search filter and sort picker, the last uncovered slice. List loading and section ordering were already exercised by MyAnimeAdultFilterReloadTests and friends.
  • AniListClient — split in two. The shared envelope once (bearer header, GraphQL errors on HTTP 200, redaction ordering, outage reporting, the single transient retry), then per-operation request shape and deserialization.
  • FileLoggerProvider — rotation, retention, the size cap, level filtering.
  • Pure helpers — MediaMetricBadges.ForMediaSort, AniListMarkdownProcessor, ListViewModePreference.

Two production changes

Both fix bugs the tests surfaced, and both are small.

FileLoggerProvider.Dispose discarded the queued backlog instead of flushing it. It set _disposed and cancelled the read token before waiting on the writer task, and the drain loop returned as soon as it saw _disposed — so even a single write followed immediately by Dispose never reached the file. Every one of the first-draft logger tests failed against the old code; they pass against the new one, which completes the channel writer, waits for the drain, then cancels only as a backstop for a writer wedged on IO.

Worth being clear about the limits: this helps an orderly dispose only. Android usually kills the process instead, so on its own this is not enough to make a diagnostic report contain the moments before a crash — that would need a flush on a lifecycle event like OnStop, which is a separate change.

LongPressTapSuppressor gains a pure IsWithinWindow and an internal Reset. Its test stamped process-wide state that stays set for 800ms, and ShouldSuppressTap gates every navigate command — so it could suppress a navigation in any test class running alongside it, and neither DetailsSpineTests nor the new MediaBrowsePageModelTests is serialised against it. The comparison is now tested as a pure function and the one test that still stamps clears it immediately. This also covers the case where suppression has to end, which nothing asserted before: an always-true ShouldSuppressTap would have passed the old suite.

Notes for review

  • AniListClient coverage is risk-ordered, not exhaustive — mutations first (they can corrupt the user's real list), then the paged readers where a dropped pageInfo silently ends paging, then the viewer and settings round trip. The detail-page pagers share the same helpers and are not individually covered.
  • The three retry tests pay real wall-clock time, because RetryDelay is a literal Task.Delay(750ms). Injecting a TimeProvider would fix that but ripples into the caching, fault-injecting and CI client wrappers — too much blast radius for test speed.
  • ScriptedGraphQlHandler is a new shared fake. Its responder must build a fresh HttpResponseMessage per call, since AniListClient disposes what it receives.
  • Not device-verified. The FileLoggerProvider change is only observable on an orderly dispose, which Android does not reliably provide, so the unit tests are the stronger evidence here.

Related

…ent (#52)

Closes out the coverage #52 tracks that is actually reachable from the net10.0
test project. 984 to 1171 tests.

Covered:

- MediaBrowsePageModel, the last page model in Core with no tests at all: the
  badge sort (it is seeded with a placeholder, so badging off
  PaginatedSection.Sort would label every section "popularity"), rank
  continuation across pages, the Load More interlock, the #118 adult-content pin,
  the revisit short-circuit, view mode, and navigation.
- MyAnimePageModel's search filter and sort picker, the last uncovered slice.
  List loading and section ordering were already exercised elsewhere.
- AniListClient, split into the shared envelope (bearer header, GraphQL errors on
  HTTP 200, redaction ordering, outage reporting, the single transient retry) and
  per-operation request shape and deserialization, risk-ordered rather than
  exhaustive: mutations first, then the paged readers, then viewer and settings.
- FileLoggerProvider rotation, retention and level filtering.
- MediaMetricBadges.ForMediaSort, AniListMarkdownProcessor, ListViewModePreference.

Two production changes, both fixing bugs the tests surfaced:

FileLoggerProvider.Dispose discarded whatever was still queued instead of
flushing it. It set _disposed and cancelled the read token before waiting on the
writer task, and the drain loop returned as soon as it saw _disposed, so even a
single write followed immediately by Dispose never reached the file. It now
completes the channel writer, waits for the drain, and cancels only as a
backstop for a writer wedged on IO. This helps an orderly dispose only; Android
usually kills the process instead, so it is not by itself enough to make a
diagnostic report contain the moments before a crash.

LongPressTapSuppressor gains a pure IsWithinWindow and an internal Reset. Its
test stamped process-wide state that stays set for 800ms, which could suppress a
navigate command in any test class running alongside it, and neither
DetailsSpineTests nor MediaBrowsePageModelTests is serialised against it. The
window comparison is now tested as a pure function, and the one test that still
stamps clears it immediately. This also covers the case where suppression has to
end, which nothing asserted before.

Split out as #141: the airing-notification logic stays out of reach, since it
lives in the MAUI app project. That issue also records the four preference keys
duplicated as independent literals on both sides of the test boundary, where a
rename compiles, keeps the suite green, and silently stops notifications.
Copilot AI lite review requested due to automatic review settings August 27, 2026 04:14

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.

🟢 Approval recommended

The production changes are small and well-covered by the new suite, and the only noted follow-ups are minor test-helper performance nits.

Pull request overview

Expands the net10.0 unit-test suite to cover the remaining “reachable core” logic (browse/view-all paging, library filtering/sorting, AniList client request/response contracts, markdown processing, and file logging), while making two small production fixes uncovered by the new tests.

Changes:

  • Add coverage for MediaBrowsePageModel and the remaining filter/sort slice of MyAnimePageModel, including paging interlocks, adult-filter pinning, revisit short-circuit behavior, view-mode persistence, and navigation guards.
  • Add contract-style tests for AniListClient (shared envelope + risk-ordered operation shapes/deserialization) using a new scripted HttpMessageHandler fake.
  • Fix two production issues surfaced by tests: FileLoggerProvider.Dispose now drains the queued backlog before canceling, and LongPressTapSuppressor gains testable pure logic + a reset for isolation.
File summaries
File Description
tests/AniSprinkles.UnitTests/MyAnimeFilterAndSortTests.cs New tests for My Anime search filtering + sort picker persistence/application.
tests/AniSprinkles.UnitTests/MediaMetricBadgesTests.cs New tests for metric badge rendering across sort modes and fallbacks.
tests/AniSprinkles.UnitTests/MediaBrowsePageModelTests.cs New comprehensive tests for “View All” browse paging, filtering pinning, revisit behavior, view mode, and navigation.
tests/AniSprinkles.UnitTests/ListViewModePreferenceTests.cs New tests for view-mode preference key stability and round-trip behavior.
tests/AniSprinkles.UnitTests/FileLoggerProviderTests.cs New tests for log flushing-on-dispose, level filtering, rotation, and retention.
tests/AniSprinkles.UnitTests/Fakes/ScriptedGraphQlHandler.cs New HTTP handler fake to script/record GraphQL requests by operation name.
tests/AniSprinkles.UnitTests/CoreSeamTests.cs Update long-press suppression tests to avoid cross-test leakage by using pure comparison + reset.
tests/AniSprinkles.UnitTests/AniListMarkdownProcessorTests.cs New tests for AniList markdown-to-HTML conversion ordering and stripping rules.
tests/AniSprinkles.UnitTests/AniListClientTests.cs New tests for shared AniList client envelope: auth header, error classification/redaction, outage reporting, retry.
tests/AniSprinkles.UnitTests/AniListClientOperationsTests.cs New tests for per-operation variable shapes and deserialization (mutations, paging, viewer/settings).
src/AniSprinkles.Core/Services/FileLoggerProvider.cs Fix dispose ordering to flush queued log lines; add bounded flush timeout + drain-loop behavior change.
src/AniSprinkles.Core/PageModels/LongPressTapSuppressor.cs Add pure window comparison + reset to enable deterministic tests and avoid process-wide leakage.
Review details

Suppressed comments (1)

tests/AniSprinkles.UnitTests/Fakes/ScriptedGraphQlHandler.cs:47

  • CallCount/CallsTo also go through Requests, which clones the whole list on each call. Since access is already synchronized by _gate, these can count the backing _requests directly under the lock to avoid repeated list allocations.
    public int CallCount => Requests.Count;

    public int CallsTo(string operationName)
        => Requests.Count(r => string.Equals(r.OperationName, operationName, StringComparison.Ordinal));
  • Files reviewed: 12/12 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Aug 27, 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 →

Library Discover View All (Browse) Search One Piece Details Toei Animation (Studio) Luffy (Character) Mayumi Tanaka (Staff) Settings
Library Discover View All (Browse) Search One Piece Details Toei Animation (Studio) Luffy (Character) Mayumi Tanaka (Staff) Settings

…ning

Last, CallCount and CallsTo went through the Requests snapshot, so each one copied the whole list to reach a single value. They now read it under the same lock. Requests itself still returns a copy, which is what lets a caller enumerate while the handler appends.

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.

🟡 Changes recommended

The new ScriptedGraphQlHandler/CapturedGraphQlRequest retains JsonDocument instances without a disposal path, which should be corrected to avoid unnecessary pooled-buffer retention across longer test runs.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

tests/AniSprinkles.UnitTests/Fakes/ScriptedGraphQlHandler.cs:117

  • CapturedGraphQlRequest stores a JsonDocument but never disposes it. JsonDocument uses pooled buffers, so keeping many captured requests around across the test run can inflate memory usage. Implement IDisposable on CapturedGraphQlRequest so the handler (or a test) can deterministically release the document.
{
    private readonly JsonDocument? _document;

    public CapturedGraphQlRequest(
        HttpMethod method, Uri? uri, string? authScheme, string? bearerToken, string body)
  • Files reviewed: 12/21 changed files
  • Comments generated: 1
  • Review effort level: Lite

github-actions Bot and others added 3 commits August 27, 2026 11:13
CapturedGraphQlRequest held a JsonDocument for the life of the handler, so the buffer it rents from ArrayPool was only reclaimed by GC. It now parses inside a using block and stores RootElement.Clone(), which owns its own memory. The buffer goes back at capture time, the type stops being disposable, and there is no way for an assertion to reach an element whose document has gone.
@zhollis21
zhollis21 merged commit 7313ecb into main Aug 27, 2026
3 checks passed
@zhollis21
zhollis21 deleted the feature/52-unit-test-coverage branch August 27, 2026 12:45
zhollis21 added a commit that referenced this pull request Nov 19, 2026
…ent (#52) (#142)

* Unit-test the reachable core: browse, filtering, logging, and the client (#52)

Closes out the coverage #52 tracks that is actually reachable from the net10.0
test project. 984 to 1171 tests.

Covered:

- MediaBrowsePageModel, the last page model in Core with no tests at all: the
  badge sort (it is seeded with a placeholder, so badging off
  PaginatedSection.Sort would label every section "popularity"), rank
  continuation across pages, the Load More interlock, the #118 adult-content pin,
  the revisit short-circuit, view mode, and navigation.
- MyAnimePageModel's search filter and sort picker, the last uncovered slice.
  List loading and section ordering were already exercised elsewhere.
- AniListClient, split into the shared envelope (bearer header, GraphQL errors on
  HTTP 200, redaction ordering, outage reporting, the single transient retry) and
  per-operation request shape and deserialization, risk-ordered rather than
  exhaustive: mutations first, then the paged readers, then viewer and settings.
- FileLoggerProvider rotation, retention and level filtering.
- MediaMetricBadges.ForMediaSort, AniListMarkdownProcessor, ListViewModePreference.

Two production changes, both fixing bugs the tests surfaced:

FileLoggerProvider.Dispose discarded whatever was still queued instead of
flushing it. It set _disposed and cancelled the read token before waiting on the
writer task, and the drain loop returned as soon as it saw _disposed, so even a
single write followed immediately by Dispose never reached the file. It now
completes the channel writer, waits for the drain, and cancels only as a
backstop for a writer wedged on IO. This helps an orderly dispose only; Android
usually kills the process instead, so it is not by itself enough to make a
diagnostic report contain the moments before a crash.

LongPressTapSuppressor gains a pure IsWithinWindow and an internal Reset. Its
test stamped process-wide state that stays set for 800ms, which could suppress a
navigate command in any test class running alongside it, and neither
DetailsSpineTests nor MediaBrowsePageModelTests is serialised against it. The
window comparison is now tested as a pure function, and the one test that still
stamps clears it immediately. This also covers the case where suppression has to
end, which nothing asserted before.

Split out as #141: the airing-notification logic stays out of reach, since it
lives in the MAUI app project. That issue also records the four preference keys
duplicated as independent literals on both sides of the test boundary, where a
rename compiles, keeps the suite green, and silently stops notifications.

* CI: Update UI screenshots [skip ci]

* Read the single-value accessors on ScriptedGraphQlHandler without cloning

Last, CallCount and CallsTo went through the Requests snapshot, so each one copied the whole list to reach a single value. They now read it under the same lock. Requests itself still returns a copy, which is what lets a caller enumerate while the handler appends.

* CI: Update UI screenshots [skip ci]

* Clone the captured GraphQL root so no JsonDocument outlives its parse

CapturedGraphQlRequest held a JsonDocument for the life of the handler, so the buffer it rents from ArrayPool was only reclaimed by GC. It now parses inside a using block and stores RootElement.Clone(), which owns its own memory. The buffer goes back at capture time, the type stops being disposable, and there is no way for an assertion to reach an element whose document has gone.

* CI: Update UI screenshots [skip ci]
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.

Add unit test suite for PageModels, Services, and Converters

2 participants