Skip to content

Replace ErrorSim with runtime fault injection that composes with the CI fixtures #125

Closed

Description

@zhollis21

Problem

ErrorSim cannot test the thing it exists to test. Three structural reasons, none of which is the
error kind it simulates:

It replaces the client instead of decorating it. MauiProgram.cs:119-126 selects stubs with
#if CI / #elif ERROR_SIM, so fixtures and faults are mutually exclusive, and
FailingAniListClient answers all 23 of its IAniListClient methods with throw Fail(). Every call
fails, so you can never reach the screen whose error state you wanted to see. This blocked the
device pass on #120: the details-page error and retry states could not be verified because My Anime
and Discover died first, leaving nothing to navigate through. That path is covered by unit tests and
has never been seen on a device.

It injects below the HTTP pipeline. Sitting at IAniListClient bypasses
AniListRateLimitHandler, LoggingHandler, AniListClient.SendAsync's retry-once, and
AniListErrorClassifier. The code that actually handles real-world failure is precisely the code
ErrorSim cannot reach.

Changing the error costs a rebuild. FailingAniListClient.cs:24 is
private const ApiErrorKind SimulatedError. Roughly three minutes per variation, which is why it
doesn't get reached for.

What this makes untestable today

  • Retry succeeding. With every call failing, Retry always fails again. The recovery path — on all
    four details pages, plus FavouriteToggleRunner's rollback snackbar and ListOperationRunner's —
    has never run on a device.
  • Partial failure. Media details loading while LoadMediaCharactersPageAsync fails on Load More,
    or DiscoverSections succeeding while a row's BrowseAnime paging fails. That is where
    ListOperationRunner's swallow-and-snackbar contract lives.
  • Anything living in a timing window. Cancellation on navigate-away via PageLoadScope, the
    IsBusy / CanLoadMore interlocks, the Search and Discover debounce races. The CI stub returns
    instantly, so on device those windows are zero-width. The six Replace hamburger flyout with a bottom tab bar (#43) #116 defects were all in this family.
  • Rate-limit handling. Rehearsing AniListRateLimitHandler's adaptive spacing and Retry-After
    path currently means actually getting 429'd by AniList.

Options

Recorded as the intended direction when this was filed, rather than as a settled design. It is the
shape that was subsequently built — see the #125 commits on
feature/125-130-132-fault-injection-name-language-lifecycle — so this section is now a record of
what was chosen, not an open question.

Two seams, because they test genuinely different things. Decorator first.

1. FaultInjectingAniListClient (decorator)

Wraps whichever IAniListClient is registered — CI stub or the real caching client — and decides per
call whether to fail, delay, or pass through. Composes with the fixtures, so you load a real screen
and then break the next call. Disarmed by default, so a build with it present behaves exactly like a
build without it.

The armed state:

sealed record FaultProfile(
    string? OperationPrefix,   // null = any; else e.g. "GetStudio"
    ApiErrorKind Kind,
    FaultScope Scope,         // Next | EveryNth(n) | FirstN(n) | Always
    TimeSpan Delay);          // latency, independent of whether it fails

Deterministic scopes only — no randomness. Next / EveryNth / FirstN / Always cover every
scenario worth arming and are reproducible by construction; a random fault you saw once is one you
cannot re-run. If chaos/soak testing ever justifies randomness, seed it then and log the seed.

Delay matters independently of failure: it is the only way to open the cancellation and interlock
windows listed above.

2. Fault-injecting DelegatingHandler (follow-up)

Injects synthetic 429 / 503 / timeout into the HTTP pipeline so the real
AniListRateLimitHandler, the SendAsync retry-once, and AniListErrorClassifier all run. Full
fidelity, and it rehearses the rate-limit path without spending budget against AniList. Needs the
real client and a signed-in session, so it does not compose with the CI fixtures — which is exactly
why it is the second seam rather than a replacement for the first.

3. Arm it over adb, not over a rebuild

A [BroadcastReceiver] (attribute-generated, no manifest editing) reads the profile:

adb shell am broadcast -a com.RainbowSprinkles.FAULT \
  --es op GetStudio --es kind NotFound --es scope next
adb shell am broadcast -a com.RainbowSprinkles.FAULT --ez clear true

driver.ps1 gains fault <op> <kind> <scope> / fault clear, which is what turns error states from
a manual rebuild into three lines of the normal device pass — and lets the CI screenshot job capture
them, where today it only ever sees happy paths.

The receiver has to be exported for am broadcast to reach it. That is acceptable here: a Debug
build is already debuggable, so anyone with adb access can run-as the package regardless, and the
receiver cannot exist in Release.

4. Retire -p:ErrorSim=true

The flag exists because the current design makes a fault build useless for anything else. A decorator
that is disarmed by default removes that problem, so gate the machinery on plain #if DEBUG and drop
the flag, the _BlockErrorSimInRelease target (AniSprinkles.csproj:93-100), and the #elif ERROR_SIM arm. FailingAniListClient and SimAuthService both get deleted rather than ported: with
the decorator, data comes from the CI stubs or a real session, so neither has a job left.

This also removes the last rebuild from the loop — you arm faults in the build you are already
running.

Constraint

  • Fault injection is armable and clearable at runtime with no rebuild, and defaults to off.
  • With CI stubs plus an armed fault, each of the four details pages can be driven to its error state
    and back to Content via Retry — the scope next case, which is what proves retry recovery works.
  • Services/ErrorSimulation/ no longer contains a whole-interface throwing stub.
  • -p:ErrorSim=true is gone from AniSprinkles.csproj and AGENTS.md.
  • driver.ps1 fault documented in /run-anisprinkles, and the fault verbs in /ani-debug.
  • Nothing in the fault path compiles into a Release build.

Related

Activity

  1. added
    enhancement
    p3-medium
    Tech Debt
    on Aug 23, 2026
  2. zhollis21 commented on Aug 25, 2026

    @zhollis21
    OwnerAuthor

    Verified against fe4dbad (main, after #133 merged). Every claim in the body still holds; line
    numbers have shifted since filing.

    • The #if CI / #elif ERROR_SIM / #else selection is now MauiProgram.cs:128-150 (body says
      :119-126).
    • FailingAniListClient.cs:24 is still private const ApiErrorKind SimulatedError = ApiErrorKind.ServiceOutage;,
      and the file is 149 lines of throw Fail() across the interface.
    • _BlockErrorSimInRelease is at AniSprinkles.csproj:98-100, the ERROR_SIM DefineConstants
      PropertyGroup at :95-97.
    • SimAuthService.cs and FailingAniListClient.cs are the only two files under
      src/AniSprinkles/Services/ErrorSimulation/.
    • AniSprinkles.csproj:139-142 is a second DefineConstants;ERROR_SIM block, but it is commented
      out, as is the CI one above it at :136-138.

    -p:ErrorSim=true has a fourth reference the acceptance list does not name. The body asks for it
    to be gone from AniSprinkles.csproj and AGENTS.md (AGENTS.md:86). DEVELOPER_NOTES.md:9-24 is a
    whole section titled "Option 1: ErrorSim build flag (recommended)" documenting the flag, the VS
    conditional-compilation-symbol alternative, both stub classes, and the edit-and-rebuild loop for
    changing the error kind. .claude/skills/project-architecture/SKILL.md:19 and AGENTS.md:14 both list
    "the CI/ErrorSim stubs" in the src/AniSprinkles/ description.

    Related, for ordering. #132 is a lifecycle bug whose repro needs a load held open long enough to
    tab away mid-flight; the Delay half of the proposed FaultProfile is the only way to open that
    window on demand. #131 is the "nothing can catch pushed-page lifecycle bugs" issue.

  3. zhollis21 commented on Aug 27, 2026

    @zhollis21
    OwnerAuthor

    Shipped in #135 (925d79f). Verified on main: src/AniSprinkles.Core/Services/FaultInjection/ contains both seams the issue asked for — FaultInjectingAniListClient.cs (decorator) and FaultInjectingHttpHandler.cs (HTTP layer) — plus FaultProfile.cs, FaultState.cs, and Platforms/Android/FaultBroadcastReceiver.cs for arming at runtime. FailingAniListClient.cs is deleted and the remaining ErrorSim mentions are comments recording its removal (AniSprinkles.csproj:93, MauiProgram.cs:124).

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