@fuzdev/fuz_app 0.163.0 → 0.165.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/actions/action_event_data.d.ts +1 -1
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +4 -0
- package/dist/actions/action_spec.d.ts +3 -3
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/auth/CLAUDE.md +1 -1
- package/dist/auth/account_route_schema.d.ts +3 -27
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +6 -20
- package/dist/auth/admin_action_specs.d.ts +56 -56
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_route_schema.js +4 -5
- package/dist/auth/audit_log_schema.d.ts +18 -18
- package/dist/auth/bootstrap_route_schema.d.ts +1 -30
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +3 -8
- package/dist/auth/daemon_token.d.ts +4 -4
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token.js +3 -3
- package/dist/auth/daemon_token_middleware.d.ts +1 -1
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +5 -5
- package/dist/auth/middleware.js +4 -4
- package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +3 -7
- package/dist/db/CLAUDE.md +2 -1
- package/dist/db/file_fact_url.d.ts +11 -6
- package/dist/db/file_fact_url.d.ts.map +1 -1
- package/dist/db/file_fact_url.js +5 -5
- package/dist/db/schema_ready.d.ts +0 -5
- package/dist/db/schema_ready.d.ts.map +1 -1
- package/dist/db/schema_ready.js +0 -5
- package/dist/http/CLAUDE.md +105 -71
- package/dist/http/auth_shape.d.ts +48 -29
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +12 -85
- package/dist/http/body_limit.d.ts +12 -0
- package/dist/http/body_limit.d.ts.map +1 -1
- package/dist/http/body_limit.js +15 -0
- package/dist/http/body_limit_schema.d.ts +20 -0
- package/dist/http/body_limit_schema.d.ts.map +1 -0
- package/dist/http/body_limit_schema.js +20 -0
- package/dist/http/common_routes.d.ts +1 -1
- package/dist/http/common_routes.d.ts.map +1 -1
- package/dist/http/common_routes.js +11 -14
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +59 -69
- package/dist/http/dev_route_error_check.d.ts +70 -0
- package/dist/http/dev_route_error_check.d.ts.map +1 -0
- package/dist/http/dev_route_error_check.js +119 -0
- package/dist/http/error_schemas.d.ts +365 -189
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +256 -149
- package/dist/http/health_schema.d.ts +10 -6
- package/dist/http/health_schema.d.ts.map +1 -1
- package/dist/http/health_schema.js +3 -3
- package/dist/http/middleware_spec.d.ts +8 -3
- package/dist/http/middleware_spec.d.ts.map +1 -1
- package/dist/http/origin.d.ts +12 -43
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +10 -6
- package/dist/http/route_error_check.d.ts +179 -0
- package/dist/http/route_error_check.d.ts.map +1 -0
- package/dist/http/route_error_check.js +283 -0
- package/dist/http/route_errors.d.ts +80 -0
- package/dist/http/route_errors.d.ts.map +1 -0
- package/dist/http/route_errors.js +83 -0
- package/dist/http/route_spec.d.ts +33 -17
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +48 -62
- package/dist/http/schema_helpers.d.ts +15 -34
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +11 -47
- package/dist/http/surface.d.ts +19 -12
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +25 -38
- package/dist/http/surface_query.d.ts +11 -2
- package/dist/http/surface_query.d.ts.map +1 -1
- package/dist/http/surface_query.js +7 -1
- package/dist/primitive_schemas_fuz.d.ts +17 -3
- package/dist/primitive_schemas_fuz.d.ts.map +1 -1
- package/dist/primitive_schemas_fuz.js +13 -3
- package/dist/rate_limiter.d.ts +13 -0
- package/dist/rate_limiter.d.ts.map +1 -1
- package/dist/rate_limiter.js +20 -2
- package/dist/schema_issues.d.ts +29 -11
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +11 -10
- package/dist/schema_meta.d.ts +8 -1
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +2 -1
- package/dist/server/app_server.d.ts +3 -1
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +24 -10
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +8 -31
- package/dist/server/surface_route.d.ts.map +1 -1
- package/dist/server/surface_route.js +5 -6
- package/dist/server/x_accel.d.ts +12 -7
- package/dist/server/x_accel.d.ts.map +1 -1
- package/dist/server/x_accel.js +7 -9
- package/dist/testing/CLAUDE.md +105 -61
- package/dist/testing/admin_integration.js +2 -2
- package/dist/testing/adversarial_404.d.ts +4 -18
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +20 -52
- package/dist/testing/adversarial_headers.d.ts +3 -4
- package/dist/testing/adversarial_headers.d.ts.map +1 -1
- package/dist/testing/adversarial_headers.js +8 -6
- package/dist/testing/adversarial_input.d.ts.map +1 -1
- package/dist/testing/adversarial_input.js +20 -19
- package/dist/testing/assertions.d.ts +46 -14
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +73 -16
- package/dist/testing/attack_surface.d.ts +17 -35
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/attack_surface.js +36 -95
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +2 -1
- package/dist/testing/cross_backend/action_manifest.d.ts +126 -56
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +11 -11
- package/dist/testing/cross_backend/action_manifest_parity.d.ts +1 -1
- package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.js +2 -1
- package/dist/testing/cross_backend/conformance_table.js +1 -1
- package/dist/testing/cross_backend/fact_serving.js +3 -3
- package/dist/testing/cross_backend/in_process_setup.d.ts +7 -3
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +11 -4
- package/dist/testing/cross_backend/origin_conformance.d.ts +278 -102
- package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
- package/dist/testing/cross_backend/origin_conformance.js +21 -21
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +7 -1
- package/dist/testing/cross_backend/setup.d.ts +13 -0
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +24 -7
- package/dist/testing/cross_backend/spine_suites.d.ts +3 -2
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +5 -2
- package/dist/testing/cross_backend/standard.d.ts +31 -0
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.js +9 -3
- package/dist/testing/cross_backend/testing_origin_check.d.ts +147 -71
- package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_origin_check.js +16 -13
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +70 -27
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/data_exposure.d.ts +7 -0
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +8 -7
- package/dist/testing/error_coverage.d.ts +53 -61
- package/dist/testing/error_coverage.d.ts.map +1 -1
- package/dist/testing/error_coverage.js +86 -119
- package/dist/testing/integration.d.ts +28 -1
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +54 -29
- package/dist/testing/integration_helpers.d.ts +37 -9
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +75 -40
- package/dist/testing/middleware.d.ts +3 -5
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +5 -4
- package/dist/testing/middleware_gate_probes.d.ts +90 -0
- package/dist/testing/middleware_gate_probes.d.ts.map +1 -0
- package/dist/testing/middleware_gate_probes.js +179 -0
- package/dist/testing/rate_limiting.d.ts +1 -1
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +5 -4
- package/dist/testing/round_trip.d.ts +7 -0
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +8 -5
- package/dist/testing/schema_generators.d.ts +40 -11
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +71 -17
- package/dist/testing/stubs.d.ts +10 -1
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +15 -5
- package/dist/testing/surface_invariants.d.ts +36 -115
- package/dist/testing/surface_invariants.d.ts.map +1 -1
- package/dist/testing/surface_invariants.js +106 -269
- package/dist/testing/transports/raw_http.d.ts +10 -2
- package/dist/testing/transports/raw_http.d.ts.map +1 -1
- package/dist/testing/transports/raw_http.js +10 -4
- package/dist/ui/CLAUDE.md +4 -2
- package/dist/ui/auth_state.svelte.d.ts.map +1 -1
- package/dist/ui/auth_state.svelte.js +2 -8
- package/dist/ui/backend_probe.svelte.js +3 -3
- package/dist/ui/table_state.svelte.d.ts.map +1 -1
- package/dist/ui/table_state.svelte.js +1 -8
- package/dist/ui/ui_fetch.d.ts +12 -2
- package/dist/ui/ui_fetch.d.ts.map +1 -1
- package/dist/ui/ui_fetch.js +22 -4
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import './assert_dev_env.js';
|
|
2
2
|
import { type AuthPrincipal } from './integration_helpers.js';
|
|
3
|
+
import { type RouteParamValues } from './schema_generators.js';
|
|
3
4
|
import type { SetupTest, TestFixture } from './cross_backend/setup.js';
|
|
4
5
|
import type { AppSurfaceSpec } from '../http/surface.js';
|
|
5
6
|
/** Options for `describe_round_trip_validation`. */
|
|
@@ -20,6 +21,12 @@ export interface RoundTripTestOptions {
|
|
|
20
21
|
skip_routes?: Array<string>;
|
|
21
22
|
/** Override generated bodies for specific routes (`'METHOD /path'` → body). */
|
|
22
23
|
input_overrides?: Map<string, Record<string, unknown>>;
|
|
24
|
+
/**
|
|
25
|
+
* Path param values for specific routes (`'METHOD /path'` → param name →
|
|
26
|
+
* value), used before the generated ones — needed for a `{re}` param whose
|
|
27
|
+
* pattern refuses the generated value. See `RouteParamValues`.
|
|
28
|
+
*/
|
|
29
|
+
param_values?: RouteParamValues;
|
|
23
30
|
/**
|
|
24
31
|
* Success-case fixtures for routes whose **populated success body** the
|
|
25
32
|
* generic nil-id input can't reach — referential REST routes whose path
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"round_trip.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/round_trip.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"round_trip.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/round_trip.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AA8B7B,OAAO,EAON,KAAK,aAAa,EAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAIN,KAAK,gBAAgB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,oDAAoD;AACpD,MAAM,WAAW,oBAAoB;IACpC;;;;;OAKG;IACH,UAAU,EAAE,SAAS,CAAC;IACtB;;;OAGG;IACH,cAAc,EAAE,cAAc,CAAC;IAC/B,kDAAkD;IAClD,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,+EAA+E;IAC/E,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACvD;;;;OAIG;IACH,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CAAC,EAAE,GAAG,CACrB,MAAM,EACN,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CACnF,CAAC;CACF;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,0BAA0B,GACtC,WAAW,MAAM,EACjB,QAAQ,MAAM,EACd,MAAM,OAAO,EACb,WAAW,aAAa,KACtB,IAUF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,8BAA8B,GAAI,SAAS,oBAAoB,KAAG,IAkK9E,CAAC"}
|
|
@@ -22,6 +22,7 @@ import './assert_dev_env.js';
|
|
|
22
22
|
*/
|
|
23
23
|
import { describe, test, beforeAll, assert } from 'vitest';
|
|
24
24
|
import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
25
|
+
import { format_route_key } from '../http/surface_query.js';
|
|
25
26
|
import { needs_actor, input_schema_declares_acting } from '../http/auth_shape.js';
|
|
26
27
|
import { assert_response_matches_spec, is_unauthenticated_refusal, pick_auth_headers, pick_auth_principal, round_trip_uses_fresh_account, to_principal_headers } from './integration_helpers.js';
|
|
27
28
|
import { resolve_valid_path, generate_valid_body, to_route_content_type } from './schema_generators.js';
|
|
@@ -64,6 +65,7 @@ export const assert_route_authenticated = (route_key, status, body, principal) =
|
|
|
64
65
|
*/
|
|
65
66
|
export const describe_round_trip_validation = (options) => {
|
|
66
67
|
const describe_time_specs = options.surface_source.route_specs;
|
|
68
|
+
const route_error_maps = options.surface_source.route_error_maps;
|
|
67
69
|
const skip_set = new Set(options.skip_routes);
|
|
68
70
|
describe('round-trip validation', () => {
|
|
69
71
|
let fixture;
|
|
@@ -99,7 +101,7 @@ export const describe_round_trip_validation = (options) => {
|
|
|
99
101
|
}
|
|
100
102
|
};
|
|
101
103
|
test.each(describe_time_specs)('$method $path produces schema-valid response', async (spec) => {
|
|
102
|
-
const route_key =
|
|
104
|
+
const route_key = format_route_key(spec);
|
|
103
105
|
if (skip_set.has(route_key))
|
|
104
106
|
return;
|
|
105
107
|
// Raw-byte / streaming routes (git smart-HTTP, binary upload/download)
|
|
@@ -108,7 +110,7 @@ export const describe_round_trip_validation = (options) => {
|
|
|
108
110
|
// every consumer hand-list them in `skip_routes`.
|
|
109
111
|
if (spec.raw_body)
|
|
110
112
|
return;
|
|
111
|
-
const url = resolve_valid_path(spec.path, spec.params);
|
|
113
|
+
const url = resolve_valid_path(spec.path, spec.params, options.param_values?.[route_key]);
|
|
112
114
|
const override = options.input_overrides?.get(route_key);
|
|
113
115
|
let body = override ?? generate_valid_body(spec.input);
|
|
114
116
|
// a mutation called as the authed account runs on a fresh one, so a
|
|
@@ -150,7 +152,7 @@ export const describe_round_trip_validation = (options) => {
|
|
|
150
152
|
.catch(() => undefined);
|
|
151
153
|
assert_route_authenticated(route_key, res.status, body, principal);
|
|
152
154
|
}
|
|
153
|
-
await assert_response_matches_spec(describe_time_specs, spec.method, url, res);
|
|
155
|
+
await assert_response_matches_spec(describe_time_specs, spec.method, url, res, route_error_maps);
|
|
154
156
|
}
|
|
155
157
|
catch (e) {
|
|
156
158
|
throw new Error(`Round-trip validation failed for ${route_key} (status ${res.status}): ${e.message}`);
|
|
@@ -167,7 +169,8 @@ export const describe_round_trip_validation = (options) => {
|
|
|
167
169
|
const spec = describe_time_specs.find((s) => s.method === method && s.path === path);
|
|
168
170
|
assert.ok(spec, `success_fixtures references unknown route '${route_key}'`);
|
|
169
171
|
const seeded = await build(fixture);
|
|
170
|
-
const url = seeded.url ??
|
|
172
|
+
const url = seeded.url ??
|
|
173
|
+
resolve_valid_path(spec.path, spec.params, options.param_values?.[route_key]);
|
|
171
174
|
const body = seeded.body;
|
|
172
175
|
const headers = pick_auth_headers(spec, fixture, authed_account, admin_account);
|
|
173
176
|
const res = await fixture.transport(url, {
|
|
@@ -180,7 +183,7 @@ export const describe_round_trip_validation = (options) => {
|
|
|
180
183
|
.clone()
|
|
181
184
|
.text()
|
|
182
185
|
.catch(() => '<unreadable>')}`);
|
|
183
|
-
await assert_response_matches_spec(describe_time_specs, spec.method, url, res);
|
|
186
|
+
await assert_response_matches_spec(describe_time_specs, spec.method, url, res, route_error_maps);
|
|
184
187
|
}
|
|
185
188
|
catch (e) {
|
|
186
189
|
throw new Error(`Round-trip success-fixture failed for ${route_key} (status ${res.status}): ${e.message}`);
|
|
@@ -167,12 +167,30 @@ export declare const to_body_input: (input_schema: ValidationSchema, label: stri
|
|
|
167
167
|
export declare const to_route_content_type: (route: {
|
|
168
168
|
raw_body?: boolean;
|
|
169
169
|
}) => string;
|
|
170
|
+
/**
|
|
171
|
+
* Caller-supplied path param values, keyed by route key (`format_route_key`,
|
|
172
|
+
* `'METHOD /path'`) and then by param name — what the suites that resolve a
|
|
173
|
+
* route's path (`resolve_valid_path`) fill a param with before generating
|
|
174
|
+
* one. A route needs an entry when a param of it is a `:name{re}` whose
|
|
175
|
+
* pattern refuses every value the generator reaches, as a `{.+\.git}` refuses
|
|
176
|
+
* `test_<name>`. Each value is the param as the handler reads it, unencoded.
|
|
177
|
+
* Values are always percent-encoded, so a `{re}` that needs a literal `/` can't
|
|
178
|
+
* be met by a supplied value: its `/` arrives as `%2F`.
|
|
179
|
+
*/
|
|
180
|
+
export type RouteParamValues = Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
170
181
|
/**
|
|
171
182
|
* Resolve a route path with valid-ish param values so params validation passes.
|
|
172
183
|
* Used when testing input on routes that also have params.
|
|
173
184
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
185
|
+
* The template is read as Hono reads it (`split_route_template`,
|
|
186
|
+
* `parse_route_param`): only a whole param segment — `:name` or `:name{re}`,
|
|
187
|
+
* optional or not — is filled, so a `:` inside a literal segment
|
|
188
|
+
* (`/v1/files:upload`) stays, and a `{re}` goes with its param. An optional
|
|
189
|
+
* param is filled too.
|
|
190
|
+
*
|
|
191
|
+
* A value in `param_values` is used first, percent-encoded. Otherwise,
|
|
192
|
+
* without a params schema (or for a param the schema doesn't name) each
|
|
193
|
+
* param becomes `test_<name>` — fine for an unconstrained segment. With
|
|
176
194
|
* one, `test_<name>` is still preferred wherever the field schema accepts
|
|
177
195
|
* it, because the param name in the URL is what makes a failure message
|
|
178
196
|
* readable. Only a segment that refuses it falls through: a `uuid` param
|
|
@@ -180,17 +198,28 @@ export declare const to_route_content_type: (route: {
|
|
|
180
198
|
* anything else is synthesized by `generate_valid_string`, so a
|
|
181
199
|
* format-constrained segment (a `blake3:…` fact hash, a `tok_…` id)
|
|
182
200
|
* resolves to a value its schema accepts instead of a `test_<name>` that
|
|
183
|
-
* 400s before the route's real gates run.
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
201
|
+
* 400s before the route's real gates run. The synthesized value is
|
|
202
|
+
* percent-encoded, and a value containing `/` is refused (it would silently
|
|
203
|
+
* add a path segment and route elsewhere) — both fall back to `test_<name>`.
|
|
204
|
+
*
|
|
205
|
+
* A `{re}` param's value, supplied or not, must match its pattern, grouped
|
|
206
|
+
* and anchored as Hono's RegExpRouter reads it — the stricter of its
|
|
207
|
+
* routers' readings, as TrieRouter leaves a top-level alternation ungrouped
|
|
208
|
+
* (`compile_route_param_pattern`, over the value as Hono decodes it,
|
|
209
|
+
* `decode_route_path`) — or the request would reach no route; no value is
|
|
210
|
+
* guessed from the pattern. A supplied value the URL would normalize away
|
|
211
|
+
* (`''`, `.`, `..`) is refused by name.
|
|
212
|
+
*
|
|
213
|
+
* @param path - the route's path template
|
|
190
214
|
* @param params_schema - the route's params schema, a Zod or `@fuzdev/fuz_schema` object schema
|
|
191
|
-
* @
|
|
215
|
+
* @param param_values - the route's supplied param values by name, its entry of `RouteParamValues`
|
|
216
|
+
* @throws Error when `params_schema` is no object schema, or of neither library;
|
|
217
|
+
* when `param_values` names no param of the path; when a supplied value is
|
|
218
|
+
* `''`, `.` or `..`, or holds a lone surrogate, which can't be encoded; and
|
|
219
|
+
* when a `{re}` param's value is one its pattern refuses, naming the route
|
|
220
|
+
* and the param
|
|
192
221
|
*/
|
|
193
|
-
export declare const resolve_valid_path: (path: string, params_schema?: ValidationSchema) => string;
|
|
222
|
+
export declare const resolve_valid_path: (path: string, params_schema?: ValidationSchema, param_values?: Readonly<Record<string, string>>) => string;
|
|
194
223
|
/**
|
|
195
224
|
* Generate a valid request body for a route's or action's input schema.
|
|
196
225
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema_generators.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/schema_generators.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAsB7B,OAAO,EAKN,KAAK,eAAe,EACpB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"schema_generators.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/schema_generators.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAsB7B,OAAO,EAKN,KAAK,eAAe,EACpB,MAAM,WAAW,CAAC;AASnB,OAAO,EAIN,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;;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MAAM,EAAE,OAAO,CAAC,GAAG,IA8B5B,CAAC;AAIF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,2BAA2B,GACvC,OAAO,eAAe,EACtB,cAAc,gBAAgB,KAC5B,MAAM,GAAG,IA2BX,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GACzB,cAAc,gBAAgB,EAC9B,OAAO,MAAM,KACX,gBAAgB,GAAG,IAgBrB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,KAAG,MACL,CAAC;AAElE;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAE1F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,kBAAkB,GAC9B,MAAM,MAAM,EACZ,gBAAgB,gBAAgB,EAChC,eAAe,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,KAC7C,MAgEF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAC/B,cAAc,gBAAgB,KAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAW5B,CAAC"}
|
|
@@ -16,6 +16,7 @@ import { get_schema_entries, get_schema_fields, unwrap_schema } from '@fuzdev/fu
|
|
|
16
16
|
import { to_json_schema } from '@fuzdev/fuz_schema/json_schema.ts';
|
|
17
17
|
import { zod_unwrap_def, zod_get_base_type, zod_unwrap_to_object, zod_extract_fields } from '../zod.js';
|
|
18
18
|
import { is_null_schema, is_void_schema } from '../http/schema_helpers.js';
|
|
19
|
+
import { compile_route_param_pattern, decode_route_path, parse_route_param, split_route_template } from '../http/route_error_check.js';
|
|
19
20
|
import { assert_zod_schema, format_issues, parse_any } from '../schema_issues.js';
|
|
20
21
|
/**
|
|
21
22
|
* The JSON Schema of a field's input side — where its format, pattern and
|
|
@@ -663,8 +664,15 @@ export const to_route_content_type = (route) => route.raw_body ? 'application/oc
|
|
|
663
664
|
* Resolve a route path with valid-ish param values so params validation passes.
|
|
664
665
|
* Used when testing input on routes that also have params.
|
|
665
666
|
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
667
|
+
* The template is read as Hono reads it (`split_route_template`,
|
|
668
|
+
* `parse_route_param`): only a whole param segment — `:name` or `:name{re}`,
|
|
669
|
+
* optional or not — is filled, so a `:` inside a literal segment
|
|
670
|
+
* (`/v1/files:upload`) stays, and a `{re}` goes with its param. An optional
|
|
671
|
+
* param is filled too.
|
|
672
|
+
*
|
|
673
|
+
* A value in `param_values` is used first, percent-encoded. Otherwise,
|
|
674
|
+
* without a params schema (or for a param the schema doesn't name) each
|
|
675
|
+
* param becomes `test_<name>` — fine for an unconstrained segment. With
|
|
668
676
|
* one, `test_<name>` is still preferred wherever the field schema accepts
|
|
669
677
|
* it, because the param name in the URL is what makes a failure message
|
|
670
678
|
* readable. Only a segment that refuses it falls through: a `uuid` param
|
|
@@ -672,27 +680,37 @@ export const to_route_content_type = (route) => route.raw_body ? 'application/oc
|
|
|
672
680
|
* anything else is synthesized by `generate_valid_string`, so a
|
|
673
681
|
* format-constrained segment (a `blake3:…` fact hash, a `tok_…` id)
|
|
674
682
|
* resolves to a value its schema accepts instead of a `test_<name>` that
|
|
675
|
-
* 400s before the route's real gates run.
|
|
683
|
+
* 400s before the route's real gates run. The synthesized value is
|
|
684
|
+
* percent-encoded, and a value containing `/` is refused (it would silently
|
|
685
|
+
* add a path segment and route elsewhere) — both fall back to `test_<name>`.
|
|
676
686
|
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
687
|
+
* A `{re}` param's value, supplied or not, must match its pattern, grouped
|
|
688
|
+
* and anchored as Hono's RegExpRouter reads it — the stricter of its
|
|
689
|
+
* routers' readings, as TrieRouter leaves a top-level alternation ungrouped
|
|
690
|
+
* (`compile_route_param_pattern`, over the value as Hono decodes it,
|
|
691
|
+
* `decode_route_path`) — or the request would reach no route; no value is
|
|
692
|
+
* guessed from the pattern. A supplied value the URL would normalize away
|
|
693
|
+
* (`''`, `.`, `..`) is refused by name.
|
|
680
694
|
*
|
|
681
|
-
* @param path - the route path
|
|
695
|
+
* @param path - the route's path template
|
|
682
696
|
* @param params_schema - the route's params schema, a Zod or `@fuzdev/fuz_schema` object schema
|
|
683
|
-
* @
|
|
697
|
+
* @param param_values - the route's supplied param values by name, its entry of `RouteParamValues`
|
|
698
|
+
* @throws Error when `params_schema` is no object schema, or of neither library;
|
|
699
|
+
* when `param_values` names no param of the path; when a supplied value is
|
|
700
|
+
* `''`, `.` or `..`, or holds a lone surrogate, which can't be encoded; and
|
|
701
|
+
* when a `{re}` param's value is one its pattern refuses, naming the route
|
|
702
|
+
* and the param
|
|
684
703
|
*/
|
|
685
|
-
export const resolve_valid_path = (path, params_schema) => {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
const
|
|
692
|
-
const field_schema = view.field_schema(name);
|
|
704
|
+
export const resolve_valid_path = (path, params_schema, param_values) => {
|
|
705
|
+
const view = params_schema
|
|
706
|
+
? to_object_schema_view(params_schema, `resolve_valid_path(${path}): the params schema`)
|
|
707
|
+
: null;
|
|
708
|
+
const generate = (name) => {
|
|
709
|
+
const fallback = encodeURIComponent(`test_${name}`);
|
|
710
|
+
const field_schema = view?.field_schema(name);
|
|
693
711
|
if (!field_schema)
|
|
694
712
|
return fallback;
|
|
695
|
-
if (accepts(field_schema,
|
|
713
|
+
if (accepts(field_schema, `test_${name}`))
|
|
696
714
|
return fallback;
|
|
697
715
|
if (to_base_type(field_schema) === 'uuid')
|
|
698
716
|
return NIL_UUID;
|
|
@@ -703,7 +721,43 @@ export const resolve_valid_path = (path, params_schema) => {
|
|
|
703
721
|
if (generated.includes('/'))
|
|
704
722
|
return fallback;
|
|
705
723
|
return encodeURIComponent(generated);
|
|
724
|
+
};
|
|
725
|
+
const encode_supplied = (name, supplied) => {
|
|
726
|
+
// the URL drops an empty segment's meaning and resolves `.` and `..` away
|
|
727
|
+
if (supplied === '' || supplied === '.' || supplied === '..') {
|
|
728
|
+
throw new Error(`resolve_valid_path: the value supplied for the param \`${name}\` of \`${path}\` is ${JSON.stringify(supplied)}, which the URL normalizes away, so the request would not reach the route`);
|
|
729
|
+
}
|
|
730
|
+
try {
|
|
731
|
+
return encodeURIComponent(supplied);
|
|
732
|
+
}
|
|
733
|
+
catch (error) {
|
|
734
|
+
if (!(error instanceof URIError))
|
|
735
|
+
throw error;
|
|
736
|
+
throw new Error(`resolve_valid_path: the value supplied for the param \`${name}\` of \`${path}\` holds a lone surrogate, which can't be percent-encoded`);
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
const names = new Set();
|
|
740
|
+
const segments = split_route_template(path).map((segment) => {
|
|
741
|
+
const param = parse_route_param(segment);
|
|
742
|
+
if (!param)
|
|
743
|
+
return segment;
|
|
744
|
+
const { name, pattern } = param;
|
|
745
|
+
names.add(name);
|
|
746
|
+
const supplied = param_values && Object.hasOwn(param_values, name) ? param_values[name] : undefined;
|
|
747
|
+
const value = supplied === undefined ? generate(name) : encode_supplied(name, supplied);
|
|
748
|
+
if (pattern !== null && !compile_route_param_pattern(pattern).test(decode_route_path(value))) {
|
|
749
|
+
throw new Error(`resolve_valid_path: the param \`${name}\` of \`${path}\` resolves to ${JSON.stringify(value)}${supplied === undefined ? ',' : ', the value supplied for it,'} which its pattern \`{${pattern}}\` refuses, so the request would reach no route — supply a value the pattern accepts in the suite's \`param_values\`, under the route's key (\`'METHOD ${path}'\`) and then \`${name}\``);
|
|
750
|
+
}
|
|
751
|
+
return value;
|
|
706
752
|
});
|
|
753
|
+
if (param_values) {
|
|
754
|
+
for (const name of Object.keys(param_values)) {
|
|
755
|
+
if (!names.has(name)) {
|
|
756
|
+
throw new Error(`resolve_valid_path: \`param_values\` names \`${name}\`, which is no param of \`${path}\``);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return (path.startsWith('/') ? '/' : '') + segments.join('/');
|
|
707
761
|
};
|
|
708
762
|
/**
|
|
709
763
|
* Generate a valid request body for a route's or action's input schema.
|
package/dist/testing/stubs.d.ts
CHANGED
|
@@ -207,6 +207,13 @@ export interface CreateTestAppSurfaceSpecOptions {
|
|
|
207
207
|
* @default false
|
|
208
208
|
*/
|
|
209
209
|
daemon_token?: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Symmetric with `AppServerOptions.max_body_size` — `null` leaves out the
|
|
212
|
+
* body limit's spec, which `create_app_server` mounts ahead of the other
|
|
213
|
+
* middleware unless the limit is disabled. Only whether it is `null` is
|
|
214
|
+
* read: the spec's handler here is a stub.
|
|
215
|
+
*/
|
|
216
|
+
max_body_size?: number | null;
|
|
210
217
|
}
|
|
211
218
|
/**
|
|
212
219
|
* Create an `AppSurfaceSpec` for the standard testing suites.
|
|
@@ -231,7 +238,9 @@ export interface CreateTestAppSurfaceSpecOptions {
|
|
|
231
238
|
* one: a stub `trusted_proxy` spec at `'*'`, then the stub auth stack (with
|
|
232
239
|
* `daemon_token` when `options.daemon_token` is set). If
|
|
233
240
|
* `create_app_server` changes how it wires routes, update this helper
|
|
234
|
-
* to stay in sync (single source of truth for all consumers).
|
|
241
|
+
* to stay in sync (single source of truth for all consumers). The body
|
|
242
|
+
* limit's spec heads the list unless `max_body_size` is `null`, as it does on
|
|
243
|
+
* the live server.
|
|
235
244
|
*
|
|
236
245
|
* @param options - surface spec options
|
|
237
246
|
* @returns the surface spec for the standard suites
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stubs.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/stubs.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,C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AAM,4BAA4B,GACxC,SAAS,+BAA+B,KACtC,cA+GF,CAAC"}
|
package/dist/testing/stubs.js
CHANGED
|
@@ -8,7 +8,8 @@ import './assert_dev_env.js';
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
import { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
11
|
-
import {
|
|
11
|
+
import { REST_FORBIDDEN_ORIGIN } from '../http/error_schemas.js';
|
|
12
|
+
import { body_limit_middleware_shape } from '../http/body_limit_schema.js';
|
|
12
13
|
import { create_realtime_closer } from '../actions/connection_closer.js';
|
|
13
14
|
import { Db } from '../db/db.js';
|
|
14
15
|
import { prefix_route_specs } from '../http/route_spec.js';
|
|
@@ -188,7 +189,7 @@ export const create_stub_api_middleware = (options) => {
|
|
|
188
189
|
name: 'origin',
|
|
189
190
|
path: ORIGIN_MIDDLEWARE_PATH,
|
|
190
191
|
handler: create_stub_mw(),
|
|
191
|
-
errors:
|
|
192
|
+
errors: [REST_FORBIDDEN_ORIGIN],
|
|
192
193
|
...(origin_carve_outs.length > 0 && { carve_outs: origin_carve_outs })
|
|
193
194
|
},
|
|
194
195
|
...(options?.include_daemon_token
|
|
@@ -197,7 +198,7 @@ export const create_stub_api_middleware = (options) => {
|
|
|
197
198
|
name: 'daemon_token',
|
|
198
199
|
path: AUTH_MIDDLEWARE_PATH,
|
|
199
200
|
handler: create_stub_mw(),
|
|
200
|
-
errors:
|
|
201
|
+
errors: []
|
|
201
202
|
}
|
|
202
203
|
]
|
|
203
204
|
: []),
|
|
@@ -207,7 +208,7 @@ export const create_stub_api_middleware = (options) => {
|
|
|
207
208
|
name: 'bearer_auth',
|
|
208
209
|
path: AUTH_MIDDLEWARE_PATH,
|
|
209
210
|
handler: create_stub_mw(),
|
|
210
|
-
errors:
|
|
211
|
+
errors: []
|
|
211
212
|
}
|
|
212
213
|
];
|
|
213
214
|
return specs;
|
|
@@ -274,7 +275,9 @@ const assert_self_resolved_ws_origins = (endpoint) => {
|
|
|
274
275
|
* one: a stub `trusted_proxy` spec at `'*'`, then the stub auth stack (with
|
|
275
276
|
* `daemon_token` when `options.daemon_token` is set). If
|
|
276
277
|
* `create_app_server` changes how it wires routes, update this helper
|
|
277
|
-
* to stay in sync (single source of truth for all consumers).
|
|
278
|
+
* to stay in sync (single source of truth for all consumers). The body
|
|
279
|
+
* limit's spec heads the list unless `max_body_size` is `null`, as it does on
|
|
280
|
+
* the live server.
|
|
278
281
|
*
|
|
279
282
|
* @param options - surface spec options
|
|
280
283
|
* @returns the surface spec for the standard suites
|
|
@@ -369,6 +372,13 @@ export const create_test_app_surface_spec = (options) => {
|
|
|
369
372
|
middleware_specs = options.transform_middleware(stack_specs.map((spec) => ({ ...spec })));
|
|
370
373
|
assert_middleware_stack_mounted(stack_specs, middleware_specs);
|
|
371
374
|
}
|
|
375
|
+
// mirrors `create_app_server`'s body limit spec, ahead of the transformed stack
|
|
376
|
+
if (options.max_body_size !== null) {
|
|
377
|
+
middleware_specs = [
|
|
378
|
+
{ ...body_limit_middleware_shape, handler: create_stub_mw() },
|
|
379
|
+
...middleware_specs
|
|
380
|
+
];
|
|
381
|
+
}
|
|
372
382
|
const surface_spec = create_app_surface_spec({
|
|
373
383
|
middleware_specs,
|
|
374
384
|
route_specs,
|
|
@@ -15,15 +15,16 @@ export declare const assert_protected_routes_declare_401: (surface: AppSurface)
|
|
|
15
15
|
*/
|
|
16
16
|
export declare const assert_role_routes_declare_403: (surface: AppSurface) => void;
|
|
17
17
|
/**
|
|
18
|
-
* Every route with non-null `input_schema`
|
|
18
|
+
* Every route with a body — a non-null `input_schema` on a method other than
|
|
19
|
+
* `GET`, which reads no body — declares a 400 naming `invalid_request_body`.
|
|
19
20
|
*/
|
|
20
21
|
export declare const assert_input_routes_declare_400: (surface: AppSurface) => void;
|
|
21
22
|
/**
|
|
22
|
-
* Every route with non-null `params_schema`
|
|
23
|
+
* Every route with non-null `params_schema` declares a 400 naming `invalid_route_params`.
|
|
23
24
|
*/
|
|
24
25
|
export declare const assert_params_routes_declare_400: (surface: AppSurface) => void;
|
|
25
26
|
/**
|
|
26
|
-
* Every route with non-null `query_schema`
|
|
27
|
+
* Every route with non-null `query_schema` declares a 400 naming `invalid_query_params`.
|
|
27
28
|
*/
|
|
28
29
|
export declare const assert_query_routes_declare_400: (surface: AppSurface) => void;
|
|
29
30
|
/**
|
|
@@ -37,71 +38,45 @@ export declare const assert_no_duplicate_routes: (surface: AppSurface) => void;
|
|
|
37
38
|
/**
|
|
38
39
|
* Every applicable middleware that declares errors must have those status codes
|
|
39
40
|
* present in the route's `error_schemas`.
|
|
41
|
+
*
|
|
42
|
+
* Holds by construction for a surface `generate_app_surface` builds: each
|
|
43
|
+
* route's error map (`resolve_route_error_map`) already unions every applying
|
|
44
|
+
* layer's definitions. It earns its place only on a surface built another
|
|
45
|
+
* way — a committed snapshot read back, or one written by hand.
|
|
40
46
|
*/
|
|
41
47
|
export declare const assert_middleware_errors_propagated: (surface: AppSurface) => void;
|
|
42
48
|
/**
|
|
43
|
-
* Every
|
|
44
|
-
* (
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* is checked, not just the top-level wrapper.
|
|
49
|
+
* Every error a route or middleware layer declares names its code exactly:
|
|
50
|
+
* each body at each status (each branch of an `anyOf` or `oneOf`) is an
|
|
51
|
+
* object whose `error` is a `const` or an `enum` — what a definition built by
|
|
52
|
+
* `rest_error` writes. A bare string `error`, or a body with no `error`, is a
|
|
53
|
+
* contract a client can't key on.
|
|
49
54
|
*
|
|
50
|
-
*
|
|
51
|
-
* read `.error` from error responses.
|
|
55
|
+
* @throws AssertionError naming the route or layer, the status, and the body
|
|
52
56
|
*/
|
|
53
|
-
export declare const
|
|
57
|
+
export declare const assert_error_codes_specific: (surface: AppSurface) => void;
|
|
54
58
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
59
|
+
* Every declared `error` code is a code — `REST_ERROR_CODE_PATTERN`, a
|
|
60
|
+
* lowercase letter then lowercase letters, digits, and `_` — never prose,
|
|
61
|
+
* which belongs in `message`. `rest_error` refuses one off the pattern; this
|
|
62
|
+
* holds a surface built another way (a snapshot, a hand-written layer) to the
|
|
63
|
+
* same rule.
|
|
57
64
|
*
|
|
58
|
-
*
|
|
59
|
-
* `z.literal()` in the Zod source). Walks union branches (`anyOf` from `z.union`,
|
|
60
|
-
* `oneOf` from `z.discriminatedUnion`) so literal codes nested inside merged unions
|
|
61
|
-
* (e.g. validation 400 + actor-resolution 400) are still tracked. Flags when the
|
|
62
|
-
* same literal appears at different status codes — e.g., `ERROR_INVALID_CREDENTIALS`
|
|
63
|
-
* at both 401 and 403 would be a bug.
|
|
64
|
-
*
|
|
65
|
-
* Only checks `const` values (literal schemas). Generic `z.string()` schemas
|
|
66
|
-
* (which produce `{type: 'string'}`) and `z.enum()` schemas are ignored — the
|
|
67
|
-
* literal-only narrow keeps the check unambiguous.
|
|
65
|
+
* @throws AssertionError naming the route or layer, the status, and the code
|
|
68
66
|
*/
|
|
69
|
-
export declare const
|
|
67
|
+
export declare const assert_error_codes_well_formed: (surface: AppSurface) => void;
|
|
70
68
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* declaring 404 for other reasons (e.g., bootstrap not configured) may legitimately
|
|
81
|
-
* use generic schemas.
|
|
69
|
+
* One error code at one HTTP status: the same code declared at two statuses
|
|
70
|
+
* across the surface's routes and middleware layers fails — e.g.
|
|
71
|
+
* `invalid_credentials` at both 401 and 403 would be a bug.
|
|
72
|
+
*
|
|
73
|
+
* Reads each body's `error` `const` (what `rest_error` writes), through every
|
|
74
|
+
* branch of an `anyOf` or `oneOf` — the surface writes a status with several
|
|
75
|
+
* definitions as an `anyOf` — and nested unions within them. An `error` with
|
|
76
|
+
* no `const` (an `enum`, a bare string) is not read; `assert_error_codes_specific`
|
|
77
|
+
* refuses the bare string.
|
|
82
78
|
*/
|
|
83
|
-
export declare const
|
|
84
|
-
/** Specificity level of an error schema's `error` field. */
|
|
85
|
-
export type ErrorSchemaSpecificity = 'literal' | 'enum' | 'generic';
|
|
86
|
-
/** A single entry in the error schema tightness audit report. */
|
|
87
|
-
export interface ErrorSchemaAuditEntry {
|
|
88
|
-
method: string;
|
|
89
|
-
route_path: string;
|
|
90
|
-
status: string;
|
|
91
|
-
specificity: ErrorSchemaSpecificity;
|
|
92
|
-
/** The literal value or enum values, if specific. */
|
|
93
|
-
error_codes: Array<string> | null;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Audit error schema tightness across all routes in a surface.
|
|
97
|
-
*
|
|
98
|
-
* Reports which route x status code combinations use generic `ApiError`
|
|
99
|
-
* (`z.string()`) vs specific `z.literal()` or `z.enum()` error codes.
|
|
100
|
-
* Use the output to prioritize progressive tightening of error schemas.
|
|
101
|
-
*
|
|
102
|
-
* @returns audit entries for every route x status combination
|
|
103
|
-
*/
|
|
104
|
-
export declare const audit_error_schema_tightness: (surface: AppSurface) => Array<ErrorSchemaAuditEntry>;
|
|
79
|
+
export declare const assert_error_code_status_consistency: (surface: AppSurface) => void;
|
|
105
80
|
/**
|
|
106
81
|
* Every RPC method on every endpoint has a non-empty `description`.
|
|
107
82
|
*
|
|
@@ -242,68 +217,14 @@ export declare const assert_mutation_routes_use_post: (surface: AppSurface) => v
|
|
|
242
217
|
* (e.g., a keeper route at `/health` or `/admin/` instead of `/api/...`).
|
|
243
218
|
*/
|
|
244
219
|
export declare const assert_keeper_routes_under_prefix: (surface: AppSurface, prefixes?: Array<string>) => void;
|
|
245
|
-
/** Options for `assert_error_schema_tightness`. */
|
|
246
|
-
export interface ErrorSchemaTightnessOptions {
|
|
247
|
-
/** Minimum specificity level. Error schemas below this threshold fail. Default: `'enum'`. */
|
|
248
|
-
min_specificity?: ErrorSchemaSpecificity;
|
|
249
|
-
/** HTTP status codes to skip (e.g., middleware-injected codes). */
|
|
250
|
-
ignore_statuses?: Array<number>;
|
|
251
|
-
/** Routes to skip, in `'METHOD /path'` format. */
|
|
252
|
-
allowlist?: Array<string>;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Routes shipped by fuz_app whose error schemas require a tightness exemption.
|
|
256
|
-
*
|
|
257
|
-
* Currently empty — every fuz_app-shipped route (account login/password/
|
|
258
|
-
* bootstrap/signup, db health/tables/:name/tables/:name/rows/:id) was tightened
|
|
259
|
-
* in place to `z.enum([...])` / `z.literal(...)` against every emit-site error
|
|
260
|
-
* code.
|
|
261
|
-
*
|
|
262
|
-
* Kept as a forward-compatibility hook: when new stock routes ship with
|
|
263
|
-
* heterogeneous error surfaces that need an interim generic schema, add
|
|
264
|
-
* them here instead of forcing every consumer to hand-maintain the entry.
|
|
265
|
-
*
|
|
266
|
-
* Paths assume the standard `/api/account` + `/api/db` prefixes used by every
|
|
267
|
-
* fuz_app consumer. Merged into `default_error_schema_tightness.allowlist` so
|
|
268
|
-
* consumers calling `assert_error_schema_tightness` directly inherit the
|
|
269
|
-
* exemptions; the standard attack-surface suite also prepends these entries
|
|
270
|
-
* underneath any consumer-supplied allowlist so project-specific entries are
|
|
271
|
-
* additive.
|
|
272
|
-
*/
|
|
273
|
-
export declare const fuz_app_stock_route_tightness_allowlist: ReadonlyArray<string>;
|
|
274
|
-
/**
|
|
275
|
-
* Baseline error schema tightness applied by
|
|
276
|
-
* `describe_standard_attack_surface_tests` when no config is passed.
|
|
277
|
-
*
|
|
278
|
-
* Uses `min_specificity: 'enum'` (the assertion default) with `ignore_statuses`
|
|
279
|
-
* for middleware-derived status codes that are commonly generic (auth middleware
|
|
280
|
-
* produces multiple error codes at 401/403, and 429 comes from rate limiters),
|
|
281
|
-
* and `allowlist` seeded with `fuz_app_stock_route_tightness_allowlist` so
|
|
282
|
-
* fuz_app-shipped routes with heterogeneous generic schemas don't force every
|
|
283
|
-
* consumer to hand-maintain an identical allowlist. Consumers can pass a
|
|
284
|
-
* narrower config with project-specific `allowlist` entries, or pass `null`
|
|
285
|
-
* to skip the assertion entirely.
|
|
286
|
-
*/
|
|
287
|
-
export declare const default_error_schema_tightness: ErrorSchemaTightnessOptions;
|
|
288
|
-
/**
|
|
289
|
-
* Assert that all error schemas meet a minimum specificity threshold.
|
|
290
|
-
*
|
|
291
|
-
* Calls `audit_error_schema_tightness` and fails on any entry below
|
|
292
|
-
* the configured threshold. Use `allowlist` and `ignore_statuses` to exclude
|
|
293
|
-
* known exceptions during progressive tightening.
|
|
294
|
-
*
|
|
295
|
-
* @throws AssertionError listing every route × status combination whose error
|
|
296
|
-
* schema specificity is below `min_specificity` (default `'enum'`) and is
|
|
297
|
-
* not in `allowlist` or `ignore_statuses`.
|
|
298
|
-
*/
|
|
299
|
-
export declare const assert_error_schema_tightness: (surface: AppSurface, options?: ErrorSchemaTightnessOptions) => void;
|
|
300
220
|
/**
|
|
301
221
|
* Run all structural invariants. Options-free — applies universally.
|
|
302
222
|
*
|
|
303
223
|
* Catches schema/surface generation bugs: missing 401/403/400 declarations,
|
|
304
224
|
* empty descriptions, duplicate routes, middleware-injected error codes
|
|
305
|
-
* unpropagated to routes
|
|
306
|
-
*
|
|
225
|
+
* unpropagated to routes (by construction on a generated surface, so a
|
|
226
|
+
* snapshot's check), an error that doesn't name its code or whose code is
|
|
227
|
+
* not one, and error codes appearing at multiple statuses.
|
|
307
228
|
*
|
|
308
229
|
* @throws AssertionError on the first invariant violation; the message names
|
|
309
230
|
* the offending route and the missing/inconsistent field.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface_invariants.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/surface_invariants.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAuB7B,OAAO,KAAK,EAAE,UAAU,EAAwB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"surface_invariants.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/surface_invariants.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