testing/error_coverage.ts

Error reachability coverage tracking.

Tracks which declared error statuses are actually exercised in tests. ErrorCoverageCollector records status codes observed during test runs, then assert_error_coverage compares against declared error schemas to find uncovered error paths.

Declarations
#

4 declarations

view source

assert_error_coverage
#

testing/error_coverage.ts view source

(collector: ErrorCoverageCollector, route_specs: RouteSpec[], options?: ErrorCoverageOptions | undefined): void

Assert error coverage meets a minimum threshold.

Computes the ratio of exercised error statuses to total declared error statuses. When min_coverage is 0 (default), logs coverage info without failing. When > 0, fails if coverage is below the threshold.

collector

the coverage collector with recorded observations

route_specs

route specs to check coverage against

type RouteSpec[]

options?

threshold and exclusion configuration

type ErrorCoverageOptions | undefined
optional

returns

void

DEFAULT_INTEGRATION_ERROR_COVERAGE
#

testing/error_coverage.ts view source

0.2

Default minimum error coverage threshold for the standard integration and admin test suites. Conservative — not all error paths are exercisable in the composable suites. Consumers should increase as their test suites mature.

ErrorCoverageCollector
#

testing/error_coverage.ts view source

Tracks which route × status combinations have been exercised in tests.

Use record() to log an observed status, or assert_and_record() to combine response validation with tracking. After all tests, call uncovered() to find declared error statuses never exercised.

observed

Observed route × status keys: "METHOD /spec-path:STATUS".

type Set<string>

readonly

record

Record an observed error status for a route.

Resolves the concrete request path back to the spec template path (e.g., /api/accounts/abc/api/accounts/:id).

type (route_specs: RouteSpec[], method: string, path: string, status: number): void

route_specs

route specs for path resolution

type RouteSpec[]
method

HTTP method

type string
path

request path (may be concrete)

type string
status

observed HTTP status code

type number
returns void

assert_and_record

Validate a response against its route spec and record the status.

Wraps assert_response_matches_spec and records the status code.

type (route_specs: RouteSpec[], method: string, path: string, response: Response): Promise<void>

route_specs

route specs for schema lookup and path resolution

type RouteSpec[]
method

HTTP method

type string
path

request path

type string
response

the Response to validate and record

type Response
returns Promise<void>

uncovered

Find declared error statuses that were never observed.

Computes the declared set from merge_error_schemas for each route spec, then subtracts observed keys.

type (route_specs: RouteSpec[]): { method: string; path: string; status: number; }[]

route_specs

route specs to check coverage against

type RouteSpec[]
returns { method: string; path: string; status: number; }[]

uncovered entries with method, path, and status

ErrorCoverageOptions
#

testing/error_coverage.ts view source

ErrorCoverageOptions

min_coverage

Minimum coverage ratio (0–1). Default 0 (informational only).

type number

ignore_routes

Routes to skip, in 'METHOD /path' format.

type Array<string>

ignore_statuses

HTTP status codes to skip.

type Array<number>

Depends on
#

Imported by
#