testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_descriptions_present} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every route has a non-empty description.
surface
returns
void Surface invariant assertions for AppSurface data.
Two categories:
Structural invariants catch schema/surface generation bugs. Policy invariants catch security misconfigurations. Both propagate automatically to consumers via assert_surface_invariants.
25 declarations
testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_descriptions_present} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every route has a non-empty description.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_error_code_status_consistency} from '@fuzdev/fuz_app/testing/surface_invariants.js'; One error code at one HTTP status: the same code declared at two statuses
across the surface's routes and middleware layers fails — e.g.
invalid_credentials at both 401 and 403 would be a bug.
Reads each body's error const (what rest_error writes), through every
branch of an anyOf or oneOf — the surface writes a status with several
definitions as an anyOf — and nested unions within them. An error with
no const (an enum, a bare string) is not read; assert_error_codes_specific
refuses the bare string.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_error_codes_specific} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every error a route or middleware layer declares names its code exactly:
each body at each status (each branch of an anyOf or oneOf) is an
object whose error is a const or an enum — what a definition built by
rest_error writes. A bare string error, or a body with no error, is a
contract a client can't key on.
surfacevoid AssertionError - naming the route or layer, the status, and the bodytesting/surface_invariants.ts view source
(surface: AppSurface): void import {assert_error_codes_well_formed} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every declared error code is a code — REST_ERROR_CODE_PATTERN, a
lowercase letter then lowercase letters, digits, and _ — never prose,
which belongs in message. rest_error refuses one off the pattern; this
holds a surface built another way (a snapshot, a hand-written layer) to the
same rule.
surfacevoid AssertionError - naming the route or layer, the status, and the codetesting/surface_invariants.ts view source
(surface: AppSurface): void import {assert_input_routes_declare_400} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every route with a body — a non-null input_schema on a method other than
GET, which reads no body — declares a 400 naming invalid_request_body.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface, prefixes?: string[]): void import {assert_keeper_routes_under_prefix} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Keeper-protected routes must be under expected path prefixes.
Catches keeper routes accidentally placed outside the API namespace
(e.g., a keeper route at /health or /admin/ instead of /api/...).
surfaceprefixes?string[]DEFAULT_KEEPER_ROUTE_PREFIXESvoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_middleware_errors_propagated} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every applicable middleware that declares errors must have those status codes
present in the route's error_schemas.
Holds by construction for a surface generate_app_surface builds: each route's error map (resolve_route_error_map) already unions every applying layer's definitions. It earns its place only on a surface built another way — a committed snapshot read back, or one written by hand.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_mutation_routes_use_post} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Routes with non-null input schemas should use POST (or other mutation methods), not GET.
GET routes with request bodies are technically allowed by HTTP but semantically suspicious — they bypass browser security assumptions about GET being idempotent. Query-string-driven filtering (audit log, list endpoints) should use params schemas or query string parsing, not input schemas.
Note: RPC endpoints (create_rpc_endpoint) use input: literal(null) on their
route specs — the dispatcher handles body/query parsing internally. Real input
schemas live in rpc_endpoints surface, not on routes; see
assert_rpc_ws_surface_invariants for the parallel checks over RPC/WS
method shapes.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_no_duplicate_routes} from '@fuzdev/fuz_app/testing/surface_invariants.js'; No duplicate method+path pairs.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_no_testing_methods} from '@fuzdev/fuz_app/testing/surface_invariants.js'; No _testing_* backdoor action ever appears as a method on the declared
surface (RPC or WS).
The test-backdoor actions (_testing_reset et al.) are daemon-token-gated
privileged actions a consumer's test binary appends to its live RPC
endpoint at assembly time — but they are deliberately excluded from
surface generation (spine_rpc_endpoints and every consumer's
create_*_app_surface_spec omit them) so the published attack surface,
the committed *_attack_surface.json snapshot, and codegen never carry
a backdoor. This invariant is the structural guard against a future
wiring change that folds create_testing_actions(...) into the *declared*
registry instead of the live-only append — the surface stays the
authoritative "what the server exposes" map only if a backdoor can never
hide in it.
Pairs with the wire-level negative-credential check (describe_testing_backdoor_cross_tests, cross-process) and the spec-level gate check: this one pins absence-from-surface, those pin the daemon-token gate and the 401/403 behavior.
surfacevoid AssertionError - naming the offending endpoint + method.testing/surface_invariants.ts view source
(surface: AppSurface, allowlist?: string[]): void import {assert_no_unexpected_public_mutations} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Public mutation routes (auth: none + is_mutation) must be in the allowlist.
Catches accidentally unprotected POST/PUT/DELETE routes. Routes like login and bootstrap are public mutations by design — they go in the allowlist.
surfaceallowlist?string[][]void testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_params_routes_declare_400} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every route with non-null params_schema declares a 400 naming invalid_route_params.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_protected_routes_declare_401} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every protected route has 401 in error_schemas.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_query_routes_declare_400} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every route with non-null query_schema declares a 400 naming invalid_query_params.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_role_routes_declare_403} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every route with an authority gate that can answer 403 declares one — a role gate, or a credential-channel gate of any kind (keeper included).
The credential half is not just the keeper routes: the session-only gates point the same axis the other way and refuse with the same status, so a route carrying one and no 403 schema would have its denial body go unvalidated by the DEV-only error-schema check.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_rpc_method_descriptions_present} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every RPC method on every endpoint has a non-empty description.
Parallel of assert_descriptions_present over surface.rpc_endpoints.
Empty descriptions on RPC methods leak through library.json codegen and
consumer-facing docs without the route-level check catching them.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_rpc_ws_surface_invariants} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Run all RPC / WS structural invariants. Options-free — applies
universally to the surface.rpc_endpoints and surface.ws_endpoints
slots produced by generate_app_surface.
Parallel of assert_surface_invariants for the non-REST surfaces.
Within-endpoint duplicate method names and the auth-shape biconditional
are already enforced at startup by compile_action_registry (see
actions/CLAUDE.md §Registry compile) — these assertions cover only
the contract-surface concerns that a runtime registration check
cannot: empty descriptions, missing protocol-action spread on WS
endpoints, kind ⇔ auth drift on WS methods, and a _testing_*
backdoor action leaking onto the declared surface.
surfacevoid AssertionError - on the first invariant violation; the message
names the offending endpoint, method, and field.testing/surface_invariants.ts view source
(surface: AppSurface, sensitive_patterns?: (string | RegExp)[]): void import {assert_sensitive_routes_rate_limited} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Sensitive routes must declare rate limiting (rate_limit_key is non-null)
or have 429 in their error schemas.
Matches routes against sensitive patterns and flags any that lack rate limit declarations. Catches forgotten rate limiting on credential-handling routes.
surfacesensitive_patterns?(string | RegExp)[]DEFAULT_SENSITIVE_PATTERNSvoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_surface_invariants} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Run all structural invariants. Options-free — applies universally.
Catches schema/surface generation bugs: missing 401/403/400 declarations, empty descriptions, duplicate routes, middleware-injected error codes unpropagated to routes (by construction on a generated surface, so a snapshot's check), an error that doesn't name its code or whose code is not one, and error codes appearing at multiple statuses.
surfacevoid AssertionError - on the first invariant violation; the message names
the offending route and the missing/inconsistent field.testing/surface_invariants.ts view source
(surface: AppSurface, options?: SurfaceSecurityPolicyOptions): void import {assert_surface_security_policy} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Run security policy invariants. Configurable with sensible defaults.
Checks:
surfaceoptions?{}void AssertionError - on the first policy violation; the message names
the offending route.testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_ws_endpoints_include_protocol_actions} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every WS endpoint's methods includes every protocol action method
(heartbeat, cancel).
Consumers register WS endpoints by spreading protocol_actions from actions/protocol.ts before their own actions:
ws_endpoints: [{path: '/api/ws', actions: [...protocol_actions, ...consumer_actions], ...}]Forgetting the spread compiles cleanly but breaks at runtime: client-side
heartbeats and cancel notifications get method_not_found from the
dispatcher, so disconnect detection silently regresses and per-request
cancel never aborts the matching handler. Catch the mistake at the
surface layer rather than at runtime.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_ws_method_descriptions_present} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Every WS method on every endpoint has a non-empty description.
Parallel of assert_descriptions_present over surface.ws_endpoints.
Same rationale as assert_rpc_method_descriptions_present — codegen +
surface explorer consume the description, blank values surface as ''.
surfacevoid testing/surface_invariants.ts view source
(surface: AppSurface): void import {assert_ws_notifications_have_null_auth} from '@fuzdev/fuz_app/testing/surface_invariants.js'; WS methods follow the kind ⇔ auth biconditional emitted by surface
generation: kind === 'remote_notification' ⟺ auth === null.
generate_app_surface produces this shape directly from the action
spec union (notifications carry auth: null per ActionSpecUnion;
request_response carries a RouteAuth). The assertion guards against
drift if a future surface emitter, transform, or test fixture violates
it — and gives consumers a clear failure message when a hand-built
surface mocks the shape incorrectly.
surfacevoid testing/surface_invariants.ts view source
SurfaceSecurityPolicyOptions import type {SurfaceSecurityPolicyOptions} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Configuration for security policy invariants.
All fields have sensible defaults. Pass overrides for project-specific needs.
sensitive_route_patterns?Path patterns for routes that should be rate-limited.
Default: common sensitive REST patterns (login, password, bootstrap).
account_token_create lives on the RPC surface; per-method RPC rate
limiting is a separate invariant if consumers want it.
type (string | RegExp)[]
public_mutation_allowlist?Routes explicitly allowed to be public mutations (e.g., webhooks, bootstrap).
Format: 'METHOD /path' (e.g., 'POST /api/account/login').
type string[]
keeper_route_prefixes?Allowed path prefixes for keeper-protected routes.
Default: ['/api/']. Catches keeper routes outside expected namespaces.
type string[]
testing/surface_invariants.ts view source
"_testing_" import {TESTING_METHOD_PREFIX} from '@fuzdev/fuz_app/testing/surface_invariants.js'; Reserved method-name prefix for the daemon-token-gated test-backdoor
actions (_testing_reset, _testing_mint_session, _testing_put_fact,
_testing_drain_effects, _testing_schema_snapshot). Test binaries
live-mount these on their RPC endpoint but they must never appear on a
declared surface.