testing/stubs.ts

Stub factories for auth surface testing.

Provides throwing stubs (catch unexpected access), no-op stubs (allow access without side effects), and pre-built bundles for AppDeps.

Declarations
#

12 declarations

view source

create_noop_stub
#

testing/stubs.ts view source

<T = any>(_label: string, overrides?: Record<string, unknown> | undefined): T

Create a Proxy where every method access returns a no-op async function.

Use for deps that may be reached during "correct auth passes guard" tests but whose return values don't matter. Unlike the explicit method listing, this auto-updates when interfaces change.

_label

type string

overrides?

explicit properties to set (e.g. {db: stub_db})

type Record<string, unknown> | undefined
optional

returns

T

create_stub_api_middleware
#

testing/stubs.ts view source

(options?: { include_daemon_token?: boolean | undefined; } | undefined): MiddlewareSpec[]

Create the API middleware stub array matching create_auth_middleware_specs output.

options?

type { include_daemon_token?: boolean | undefined; } | undefined
optional

returns

MiddlewareSpec[]

create_stub_app_deps
#

create_stub_app_server_context
#

testing/stubs.ts view source

(session_options: SessionOptions<string>): AppServerContext

Create a stub AppServerContext for attack surface testing.

Provides sensible defaults for all fields. Pass session_options since it varies per consumer; other fields use stubs/nulls.

session_options

consumer's session config (required — varies per app)

type SessionOptions<string>

returns

AppServerContext

create_stub_db
#

testing/stubs.ts view source

(): Db

Create a stub Db for handler tests that use apply_route_specs with declarative transactions.

Returns a real Db instance with: - query returns empty rows (safety net for unmocked query functions) - query_one returns undefined - transaction(fn) calls fn(db) synchronously (no real transaction)

returns

Db

create_test_app_surface_spec
#

testing/stubs.ts view source

(options: CreateTestAppSurfaceSpecOptions): AppSurfaceSpec

Create an AppSurfaceSpec for attack surface testing.

Mirrors create_app_server's route assembly: consumer routes + factory-managed bootstrap routes + surface generation. If create_app_server changes how it wires routes, update this helper to stay in sync (single source of truth for all consumers).

options

surface spec options

returns

AppSurfaceSpec

the surface spec for snapshot and adversarial testing

create_throwing_stub
#

testing/stubs.ts view source

<T = any>(label: string): T

Create a Proxy that throws descriptive errors on any property access or method call.

Use for deps that should never be reached during a test. If a test accidentally calls through to a throwing stub, the error message identifies exactly which stub was hit, catching test bugs that would silently pass with {} as any.

label

descriptive name for error messages (e.g. 'keyring', 'db')

type string

returns

T

CreateTestAppSurfaceSpecOptions
#

testing/stubs.ts view source

CreateTestAppSurfaceSpecOptions

session_options

Consumer's session config (required — varies per app).

type SessionOptions<string>

create_route_specs

Consumer's route factory — receives the same AppServerContext as production.

type (ctx: AppServerContext) => Array<RouteSpec>

env_schema

Env schema for surface generation (default: BaseServerEnv).

type z.ZodObject

event_specs

SSE event specs for surface generation.

type Array<SseEventSpec>

transform_middleware

Transform middleware array (e.g., tx's extend_middleware_for_tx_binary).

type (specs: Array<MiddlewareSpec>) => Array<MiddlewareSpec>

bootstrap_route_prefix

Bootstrap route prefix (default: '/api/account').

type string

stub
#

stub_app_deps
#

stub_handler
#

stub_mw
#

testing/stubs.ts view source

(_c: any, next: any): Promise<void>

Stub middleware that passes through.

_c

type any

next

type any

returns

Promise<void>

Depends on
#

Imported by
#