test_helper library

diene_api_engine test helpers — a DEPENDENCY-LIGHT sub-library (package:diene_api_engine/test_helper.dart). It ships fakes, plain-throw assertions, and builders with NO test-framework dependency, so it adds nothing to a consumer's production graph.

Classes

FakeAuth
A fake per-resource token retriever implementing the real IAuth seam. Tokens are keyed by ResourceKey.mapKey so tests prove per-resource resolution with NO cross-backend bleed. Unknown keys fail closed (Err).
FakeClock
A monotonic fake clock (milliseconds) advanced explicitly or by a sleep.
FakeHttpTransport
A scriptable, dependency-light fake transport implementing the real HttpTransport seam, so a contract-parity suite runs the SAME behaviour against this fake and a real transport. Records every request.
FakeRescueStore
A rescue store exposing its backing map + write log for assertions.
HangingTransport
A transport whose probes NEVER complete — used to prove the rescue scan's per-candidate/global budget bounds a hanging probe.

Functions

check(bool condition, String message) → void
Assert a condition, throwing AssertionError with message on failure.
expectErr<T>(Result<T> result, {String? because}) Problem
Assert result is Err and return its problem; throws otherwise.
expectOk<T>(Result<T> result, {String? because}) → T
Plain-throw assertion helpers (dependency-light: AssertionError is dart:core, no test/matcher import). Consumers get the same unwrap-or-fail ergonomics in every test without per-test boilerplate. Assert result is Ok and return its value; throws otherwise.
expectProblemType<T>(Result<T> result, String type) Problem
Assert result is an Err whose problem has type; returns the problem.
networkFailure([String reason = 'connection refused']) NetworkFailure
An opaque network failure outcome.
noJitter() Duration
Zero jitter — deterministic rescue-scan ordering.
nonJsonResponse({int status = 502, String body = 'Bad Gateway'}) Received
A non-JSON / status-only failure response.
nonProblemJson(Map<String, Object?> body, {int status = 400}) Received
A non-2xx JSON body that is NOT a problem (missing type/status).
noSleep(Duration duration) Future<void>
A no-op sleep for deterministic rescue tests.
okJson(Map<String, Object?> body, {int status = 200}) Received
A 2xx JSON success response.
problemFixture({String type = 'urn:diene:problem:test', String title = 'Test problem', int status = 400, String? detail, bool recoverable = false, Map<String, Object?> data = const <String, Object?>{}}) Problem
Builders for the reconciliation matrix. Dependency-light — plain values, no test framework. A well-formed RFC 9457 problem fixture.
problemResponse(Problem problem) Received
A non-2xx response whose body IS a problem envelope.