Repository navigation
Unit-test the reachable core: browse, filtering, logging, and the client (#52) - #142
Conversation
…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.
There was a problem hiding this comment.
🟢 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
MediaBrowsePageModeland the remaining filter/sort slice ofMyAnimePageModel, 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 scriptedHttpMessageHandlerfake. - Fix two production issues surfaced by tests:
FileLoggerProvider.Disposenow drains the queued backlog before canceling, andLongPressTapSuppressorgains 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/CallsToalso go throughRequests, which clones the whole list on each call. Since access is already synchronized by_gate, these can count the backing_requestsdirectly 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.
…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.
There was a problem hiding this comment.
🟡 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
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.
…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]









Closes out the coverage #52 tracks that is actually reachable from the
net10.0test 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 offPaginatedSection.Sortwould 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 byMyAnimeAdultFilterReloadTestsand 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.MediaMetricBadges.ForMediaSort,AniListMarkdownProcessor,ListViewModePreference.Two production changes
Both fix bugs the tests surfaced, and both are small.
FileLoggerProvider.Disposediscarded the queued backlog instead of flushing it. It set_disposedand 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 byDisposenever 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.LongPressTapSuppressorgains a pureIsWithinWindowand an internalReset. Its test stamped process-wide state that stays set for 800ms, andShouldSuppressTapgates every navigate command — so it could suppress a navigation in any test class running alongside it, and neitherDetailsSpineTestsnor the newMediaBrowsePageModelTestsis 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-trueShouldSuppressTapwould have passed the old suite.Notes for review
AniListClientcoverage is risk-ordered, not exhaustive — mutations first (they can corrupt the user's real list), then the paged readers where a droppedpageInfosilently ends paging, then the viewer and settings round trip. The detail-page pagers share the same helpers and are not individually covered.RetryDelayis a literalTask.Delay(750ms). Injecting aTimeProviderwould fix that but ripples into the caching, fault-injecting and CI client wrappers — too much blast radius for test speed.ScriptedGraphQlHandleris a new shared fake. Its responder must build a freshHttpResponseMessageper call, sinceAniListClientdisposes what it receives.FileLoggerProviderchange is only observable on an orderly dispose, which Android does not reliably provide, so the unit tests are the stronger evidence here.Related