@fuzdev/fuz_app 0.163.0 → 0.164.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.
Files changed (181) hide show
  1. package/README.md +2 -1
  2. package/dist/actions/action_event_data.d.ts +1 -1
  3. package/dist/actions/action_rpc.d.ts.map +1 -1
  4. package/dist/actions/action_rpc.js +4 -0
  5. package/dist/actions/action_spec.d.ts +3 -3
  6. package/dist/actions/action_spec.d.ts.map +1 -1
  7. package/dist/auth/CLAUDE.md +1 -1
  8. package/dist/auth/account_route_schema.d.ts +3 -27
  9. package/dist/auth/account_route_schema.d.ts.map +1 -1
  10. package/dist/auth/account_route_schema.js +6 -20
  11. package/dist/auth/admin_action_specs.d.ts +56 -56
  12. package/dist/auth/audit_log_route_schema.d.ts +1 -1
  13. package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
  14. package/dist/auth/audit_log_route_schema.js +4 -5
  15. package/dist/auth/audit_log_schema.d.ts +18 -18
  16. package/dist/auth/bootstrap_route_schema.d.ts +1 -30
  17. package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
  18. package/dist/auth/bootstrap_route_schema.js +3 -8
  19. package/dist/auth/daemon_token.d.ts +4 -4
  20. package/dist/auth/daemon_token.d.ts.map +1 -1
  21. package/dist/auth/daemon_token.js +3 -3
  22. package/dist/auth/daemon_token_middleware.d.ts +1 -1
  23. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  24. package/dist/auth/daemon_token_middleware.js +5 -5
  25. package/dist/auth/middleware.js +4 -4
  26. package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
  27. package/dist/auth/signup_route_schema.d.ts.map +1 -1
  28. package/dist/auth/signup_route_schema.js +3 -7
  29. package/dist/db/CLAUDE.md +2 -1
  30. package/dist/db/file_fact_url.d.ts +11 -6
  31. package/dist/db/file_fact_url.d.ts.map +1 -1
  32. package/dist/db/file_fact_url.js +5 -5
  33. package/dist/db/schema_ready.d.ts +0 -5
  34. package/dist/db/schema_ready.d.ts.map +1 -1
  35. package/dist/db/schema_ready.js +0 -5
  36. package/dist/http/CLAUDE.md +104 -71
  37. package/dist/http/auth_shape.d.ts +48 -29
  38. package/dist/http/auth_shape.d.ts.map +1 -1
  39. package/dist/http/auth_shape.js +12 -85
  40. package/dist/http/body_limit.d.ts +12 -0
  41. package/dist/http/body_limit.d.ts.map +1 -1
  42. package/dist/http/body_limit.js +15 -0
  43. package/dist/http/body_limit_schema.d.ts +20 -0
  44. package/dist/http/body_limit_schema.d.ts.map +1 -0
  45. package/dist/http/body_limit_schema.js +20 -0
  46. package/dist/http/common_routes.d.ts +1 -1
  47. package/dist/http/common_routes.d.ts.map +1 -1
  48. package/dist/http/common_routes.js +11 -14
  49. package/dist/http/db_routes.d.ts.map +1 -1
  50. package/dist/http/db_routes.js +59 -69
  51. package/dist/http/dev_route_error_check.d.ts +70 -0
  52. package/dist/http/dev_route_error_check.d.ts.map +1 -0
  53. package/dist/http/dev_route_error_check.js +119 -0
  54. package/dist/http/error_schemas.d.ts +365 -189
  55. package/dist/http/error_schemas.d.ts.map +1 -1
  56. package/dist/http/error_schemas.js +256 -149
  57. package/dist/http/health_schema.d.ts +10 -6
  58. package/dist/http/health_schema.d.ts.map +1 -1
  59. package/dist/http/health_schema.js +3 -3
  60. package/dist/http/middleware_spec.d.ts +8 -3
  61. package/dist/http/middleware_spec.d.ts.map +1 -1
  62. package/dist/http/origin.d.ts +12 -43
  63. package/dist/http/origin.d.ts.map +1 -1
  64. package/dist/http/origin.js +10 -6
  65. package/dist/http/route_error_check.d.ts +158 -0
  66. package/dist/http/route_error_check.d.ts.map +1 -0
  67. package/dist/http/route_error_check.js +247 -0
  68. package/dist/http/route_errors.d.ts +80 -0
  69. package/dist/http/route_errors.d.ts.map +1 -0
  70. package/dist/http/route_errors.js +83 -0
  71. package/dist/http/route_spec.d.ts +33 -17
  72. package/dist/http/route_spec.d.ts.map +1 -1
  73. package/dist/http/route_spec.js +48 -62
  74. package/dist/http/schema_helpers.d.ts +0 -33
  75. package/dist/http/schema_helpers.d.ts.map +1 -1
  76. package/dist/http/schema_helpers.js +0 -45
  77. package/dist/http/surface.d.ts +19 -12
  78. package/dist/http/surface.d.ts.map +1 -1
  79. package/dist/http/surface.js +25 -38
  80. package/dist/http/surface_query.d.ts +11 -2
  81. package/dist/http/surface_query.d.ts.map +1 -1
  82. package/dist/http/surface_query.js +7 -1
  83. package/dist/primitive_schemas_fuz.d.ts +17 -3
  84. package/dist/primitive_schemas_fuz.d.ts.map +1 -1
  85. package/dist/primitive_schemas_fuz.js +13 -3
  86. package/dist/rate_limiter.d.ts +13 -0
  87. package/dist/rate_limiter.d.ts.map +1 -1
  88. package/dist/rate_limiter.js +20 -2
  89. package/dist/schema_issues.d.ts +29 -11
  90. package/dist/schema_issues.d.ts.map +1 -1
  91. package/dist/schema_issues.js +11 -10
  92. package/dist/schema_meta.d.ts +8 -1
  93. package/dist/schema_meta.d.ts.map +1 -1
  94. package/dist/schema_meta.js +2 -1
  95. package/dist/server/app_server.d.ts +3 -1
  96. package/dist/server/app_server.d.ts.map +1 -1
  97. package/dist/server/app_server.js +24 -10
  98. package/dist/server/serve_fact_route.d.ts.map +1 -1
  99. package/dist/server/serve_fact_route.js +8 -31
  100. package/dist/server/surface_route.d.ts.map +1 -1
  101. package/dist/server/surface_route.js +5 -6
  102. package/dist/server/x_accel.d.ts +12 -7
  103. package/dist/server/x_accel.d.ts.map +1 -1
  104. package/dist/server/x_accel.js +7 -9
  105. package/dist/testing/CLAUDE.md +33 -39
  106. package/dist/testing/admin_integration.js +1 -1
  107. package/dist/testing/adversarial_404.d.ts +4 -18
  108. package/dist/testing/adversarial_404.d.ts.map +1 -1
  109. package/dist/testing/adversarial_404.js +19 -51
  110. package/dist/testing/adversarial_headers.d.ts +3 -4
  111. package/dist/testing/adversarial_headers.d.ts.map +1 -1
  112. package/dist/testing/adversarial_headers.js +8 -6
  113. package/dist/testing/adversarial_input.d.ts.map +1 -1
  114. package/dist/testing/adversarial_input.js +18 -17
  115. package/dist/testing/assertions.d.ts +33 -11
  116. package/dist/testing/assertions.d.ts.map +1 -1
  117. package/dist/testing/assertions.js +52 -12
  118. package/dist/testing/attack_surface.d.ts +5 -35
  119. package/dist/testing/attack_surface.d.ts.map +1 -1
  120. package/dist/testing/attack_surface.js +29 -91
  121. package/dist/testing/auth_apps.d.ts.map +1 -1
  122. package/dist/testing/auth_apps.js +2 -1
  123. package/dist/testing/cross_backend/action_manifest.d.ts +126 -56
  124. package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
  125. package/dist/testing/cross_backend/action_manifest.js +11 -11
  126. package/dist/testing/cross_backend/action_manifest_parity.d.ts +1 -1
  127. package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
  128. package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
  129. package/dist/testing/cross_backend/cell_crud.js +2 -1
  130. package/dist/testing/cross_backend/conformance_table.js +1 -1
  131. package/dist/testing/cross_backend/fact_serving.js +3 -3
  132. package/dist/testing/cross_backend/origin_conformance.d.ts +278 -102
  133. package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
  134. package/dist/testing/cross_backend/origin_conformance.js +21 -21
  135. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  136. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +7 -1
  137. package/dist/testing/cross_backend/setup.d.ts +13 -0
  138. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  139. package/dist/testing/cross_backend/setup.js +24 -7
  140. package/dist/testing/cross_backend/testing_origin_check.d.ts +147 -71
  141. package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
  142. package/dist/testing/cross_backend/testing_origin_check.js +16 -13
  143. package/dist/testing/cross_backend/testing_reset_actions.d.ts +70 -27
  144. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  145. package/dist/testing/data_exposure.d.ts.map +1 -1
  146. package/dist/testing/data_exposure.js +5 -4
  147. package/dist/testing/error_coverage.d.ts +24 -34
  148. package/dist/testing/error_coverage.d.ts.map +1 -1
  149. package/dist/testing/error_coverage.js +46 -89
  150. package/dist/testing/integration.d.ts.map +1 -1
  151. package/dist/testing/integration.js +5 -13
  152. package/dist/testing/integration_helpers.d.ts +37 -9
  153. package/dist/testing/integration_helpers.d.ts.map +1 -1
  154. package/dist/testing/integration_helpers.js +86 -40
  155. package/dist/testing/middleware.d.ts +3 -5
  156. package/dist/testing/middleware.d.ts.map +1 -1
  157. package/dist/testing/middleware.js +5 -4
  158. package/dist/testing/rate_limiting.d.ts +1 -1
  159. package/dist/testing/rate_limiting.d.ts.map +1 -1
  160. package/dist/testing/rate_limiting.js +5 -4
  161. package/dist/testing/round_trip.d.ts.map +1 -1
  162. package/dist/testing/round_trip.js +5 -3
  163. package/dist/testing/schema_generators.d.ts +10 -3
  164. package/dist/testing/schema_generators.d.ts.map +1 -1
  165. package/dist/testing/schema_generators.js +23 -11
  166. package/dist/testing/stubs.d.ts +10 -1
  167. package/dist/testing/stubs.d.ts.map +1 -1
  168. package/dist/testing/stubs.js +15 -5
  169. package/dist/testing/surface_invariants.d.ts +36 -115
  170. package/dist/testing/surface_invariants.d.ts.map +1 -1
  171. package/dist/testing/surface_invariants.js +106 -269
  172. package/dist/ui/CLAUDE.md +4 -2
  173. package/dist/ui/auth_state.svelte.d.ts.map +1 -1
  174. package/dist/ui/auth_state.svelte.js +2 -8
  175. package/dist/ui/backend_probe.svelte.js +3 -3
  176. package/dist/ui/table_state.svelte.d.ts.map +1 -1
  177. package/dist/ui/table_state.svelte.js +1 -8
  178. package/dist/ui/ui_fetch.d.ts +12 -2
  179. package/dist/ui/ui_fetch.d.ts.map +1 -1
  180. package/dist/ui/ui_fetch.js +22 -4
  181. package/package.json +1 -1
@@ -16,7 +16,8 @@ import './assert_dev_env.js';
16
16
  * @module
17
17
  */
18
18
  import { test, assert, describe } from 'vitest';
19
- import { ApiError, ERROR_FORBIDDEN_ORIGIN } from '../http/error_schemas.js';
19
+ import { parse_any } from '../schema_issues.js';
20
+ import { REST_FORBIDDEN_ORIGIN } from '../http/error_schemas.js';
20
21
  import { create_test_middleware_stack_app, TEST_MIDDLEWARE_PATH } from './middleware.js';
21
22
  import { create_test_raw_api_token } from './entities.js';
22
23
  /**
@@ -45,7 +46,7 @@ export const create_standard_adversarial_cases = (allowed_origin) => [
45
46
  Origin: 'https://attacker.com'
46
47
  },
47
48
  expected_status: 403,
48
- expected_error: ERROR_FORBIDDEN_ORIGIN,
49
+ expected_error: REST_FORBIDDEN_ORIGIN,
49
50
  validate_expectation: 'not_called'
50
51
  },
51
52
  {
@@ -70,7 +71,7 @@ export const create_standard_adversarial_cases = (allowed_origin) => [
70
71
  Origin: ''
71
72
  },
72
73
  expected_status: 403,
73
- expected_error: ERROR_FORBIDDEN_ORIGIN,
74
+ expected_error: REST_FORBIDDEN_ORIGIN,
74
75
  validate_expectation: 'not_called'
75
76
  },
76
77
  {
@@ -129,9 +130,10 @@ export const describe_standard_adversarial_headers = (suite_name, options, allow
129
130
  assert.strictEqual(res.status, tc.expected_status);
130
131
  const body = await res.json();
131
132
  if (tc.expected_error) {
132
- assert.strictEqual(body.error, tc.expected_error);
133
- const error_schema = tc.expected_error_schema ?? ApiError;
134
- error_schema.parse(body);
133
+ assert.strictEqual(body.error, tc.expected_error.code);
134
+ assert.strictEqual(res.status, tc.expected_error.status);
135
+ const parsed = parse_any(tc.expected_error.schema, body);
136
+ assert.ok(parsed.ok, `error body fails its schema: ${JSON.stringify(body)}`);
135
137
  }
136
138
  if (tc.expected_status === 200) {
137
139
  assert.strictEqual(body.ok, true, 'expected ok to be true for 200 response');
@@ -1 +1 @@
1
- {"version":3,"file":"adversarial_input.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_input.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AA0B7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AA2BlE;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GAAI,SAAS,sBAAsB,KAAG,IAyN5E,CAAC"}
1
+ {"version":3,"file":"adversarial_input.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_input.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AA6B7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AA4BlE;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GAAI,SAAS,sBAAsB,KAAG,IAuN5E,CAAC"}
@@ -3,14 +3,17 @@ import './assert_dev_env.js';
3
3
  * Adversarial input validation testing for route specs.
4
4
  *
5
5
  * Fires the payloads `adversarial_input_cases.ts` generates against a test
6
- * app and asserts 400 responses before handlers are reached.
6
+ * app and asserts 400 responses before handlers are reached, each with a
7
+ * code the route's own error map declares at 400 and a body its schema there
8
+ * accepts.
7
9
  *
8
10
  * @module
9
11
  */
10
12
  import { test, assert, describe } from 'vitest';
11
- import { filter_routes_with_input, filter_routes_with_params, filter_routes_with_query } from '../http/surface_query.js';
12
- import { ValidationError, ERROR_INVALID_REQUEST_BODY, ERROR_INVALID_JSON_BODY, ERROR_INVALID_ROUTE_PARAMS, ERROR_INVALID_QUERY_PARAMS } from '../http/error_schemas.js';
13
+ import { filter_routes_with_input, filter_routes_with_params, filter_routes_with_query, format_route_key } from '../http/surface_query.js';
14
+ import { ERROR_INVALID_REQUEST_BODY, ERROR_INVALID_JSON_BODY, ERROR_INVALID_ROUTE_PARAMS, ERROR_INVALID_QUERY_PARAMS } from '../http/error_schemas.js';
13
15
  import { create_auth_test_apps, create_route_skip_filter, select_auth_app } from './auth_apps.js';
16
+ import { assert_error_schema_valid } from './assertions.js';
14
17
  import { resolve_valid_path, to_route_content_type } from './schema_generators.js';
15
18
  import { generate_input_test_cases, generate_params_test_cases, generate_query_test_cases } from './adversarial_input_cases.js';
16
19
  // --- URL helpers ---
@@ -37,7 +40,7 @@ const build_query_url = (path, query) => {
37
40
  */
38
41
  export const describe_adversarial_input = (options) => {
39
42
  const { build, roles } = options;
40
- const { surface, route_specs } = build();
43
+ const { surface, route_specs, route_error_maps } = build();
41
44
  const is_skipped = create_route_skip_filter(options.skip_routes);
42
45
  const routes_with_input = filter_routes_with_input(surface).filter((r) => !is_skipped(r));
43
46
  const routes_with_params = filter_routes_with_params(surface).filter((r) => !is_skipped(r));
@@ -49,7 +52,7 @@ export const describe_adversarial_input = (options) => {
49
52
  // lookup RouteSpec by method+path for schema access
50
53
  const spec_lookup = new Map();
51
54
  for (const spec of route_specs) {
52
- spec_lookup.set(`${spec.method} ${spec.path}`, spec);
55
+ spec_lookup.set(format_route_key(spec), spec);
53
56
  }
54
57
  const apps = create_auth_test_apps(route_specs, roles);
55
58
  describe('adversarial input validation', () => {
@@ -57,7 +60,7 @@ export const describe_adversarial_input = (options) => {
57
60
  if (routes_with_input.length > 0) {
58
61
  // every surface route with input must have a matching RouteSpec
59
62
  const missing_specs = routes_with_input
60
- .map((r) => `${r.method} ${r.path}`)
63
+ .map((r) => format_route_key(r))
61
64
  .filter((key) => !spec_lookup.has(key));
62
65
  if (missing_specs.length > 0) {
63
66
  throw new Error(`adversarial_input: surface routes with input have no matching RouteSpec: ${missing_specs.join(', ')}`);
@@ -65,7 +68,7 @@ export const describe_adversarial_input = (options) => {
65
68
  let input_test_count = 0;
66
69
  describe('input body', () => {
67
70
  for (const route of routes_with_input) {
68
- const key = `${route.method} ${route.path}`;
71
+ const key = format_route_key(route);
69
72
  const spec = spec_lookup.get(key);
70
73
  const test_cases = generate_input_test_cases(spec.input);
71
74
  if (test_cases.length === 0)
@@ -99,10 +102,8 @@ export const describe_adversarial_input = (options) => {
99
102
  ? ERROR_INVALID_REQUEST_BODY
100
103
  : tc.expected_error;
101
104
  assert.strictEqual(body.error, expected_error, `Expected ${expected_error} for ${key} [${tc.label}], got: ${body.error}`);
102
- // validate response body structure matches error schema
103
- if (tc.expected_error === 'invalid_request_body') {
104
- ValidationError.parse(body);
105
- }
105
+ // the status and code are the route's own, and the body its schema there
106
+ assert_error_schema_valid(route_error_maps, route, 400, body);
106
107
  });
107
108
  }
108
109
  });
@@ -117,7 +118,7 @@ export const describe_adversarial_input = (options) => {
117
118
  let params_test_count = 0;
118
119
  describe('params', () => {
119
120
  for (const route of routes_with_params) {
120
- const key = `${route.method} ${route.path}`;
121
+ const key = format_route_key(route);
121
122
  const spec = spec_lookup.get(key);
122
123
  if (!spec?.params)
123
124
  continue;
@@ -137,8 +138,8 @@ export const describe_adversarial_input = (options) => {
137
138
  assert.strictEqual(res.status, 400, `Expected 400 for ${key} [${tc.label}], got ${res.status}`);
138
139
  const body = await res.json();
139
140
  assert.strictEqual(body.error, ERROR_INVALID_ROUTE_PARAMS, `Expected ${ERROR_INVALID_ROUTE_PARAMS} for ${key} [${tc.label}], got: ${body.error}`);
140
- // validate response body structure matches error schema
141
- ValidationError.parse(body);
141
+ // the status and code are the route's own, and the body its schema there
142
+ assert_error_schema_valid(route_error_maps, route, 400, body);
142
143
  });
143
144
  }
144
145
  });
@@ -157,7 +158,7 @@ export const describe_adversarial_input = (options) => {
157
158
  let query_test_count = 0;
158
159
  describe('query params', () => {
159
160
  for (const route of routes_with_query) {
160
- const key = `${route.method} ${route.path}`;
161
+ const key = format_route_key(route);
161
162
  const spec = spec_lookup.get(key);
162
163
  if (!spec?.query)
163
164
  continue;
@@ -178,8 +179,8 @@ export const describe_adversarial_input = (options) => {
178
179
  assert.strictEqual(res.status, 400, `Expected 400 for ${key} [${tc.label}], got ${res.status}`);
179
180
  const body = await res.json();
180
181
  assert.strictEqual(body.error, ERROR_INVALID_QUERY_PARAMS, `Expected ${ERROR_INVALID_QUERY_PARAMS} for ${key} [${tc.label}], got: ${body.error}`);
181
- // validate response body structure matches error schema
182
- ValidationError.parse(body);
182
+ // the status and code are the route's own, and the body its schema there
183
+ assert_error_schema_valid(route_error_maps, route, 400, body);
183
184
  });
184
185
  }
185
186
  });
@@ -1,7 +1,7 @@
1
1
  import './assert_dev_env.js';
2
+ import type { AnySchema } from '@fuzdev/fuz_schema/schema.ts';
2
3
  import type { AppSurface, AppSurfaceRoute } from '../http/surface.js';
3
- import type { RouteErrorSchemas } from '../http/error_schemas.js';
4
- import { type ValidationSchema } from '../schema_issues.js';
4
+ import type { RouteErrorMap } from '../http/route_errors.js';
5
5
  /**
6
6
  * Resolve an absolute path relative to the caller's module.
7
7
  *
@@ -37,30 +37,52 @@ export declare const assert_surface_deterministic: (build_surface: () => AppSurf
37
37
  */
38
38
  export declare const assert_only_expected_public_routes: (surface: AppSurface, expected_public: Array<string>) => void;
39
39
  /**
40
- * Look up the merged error schema for a route+status from a pre-built schema lookup.
40
+ * Look up the error schema for a route+status in its error map.
41
41
  *
42
- * @param lookup - map from `"METHOD /path"` to merged error schemas
42
+ * @param lookup - map from `"METHOD /path"` to each route's error map (`AppSurfaceSpec.route_error_maps`)
43
43
  * @param route - the surface route to look up
44
44
  * @param status - HTTP status code
45
- * @returns the Zod or `@fuzdev/fuz_schema` schema for that route+status, or
45
+ * @returns the `@fuzdev/fuz_schema` schema for that route+status, or
46
46
  * `undefined` when no error schema is declared for the status code
47
47
  */
48
- export declare const get_route_error_schema: (lookup: Map<string, RouteErrorSchemas>, route: AppSurfaceRoute, status: number) => ValidationSchema | undefined;
48
+ export declare const get_route_error_schema: (lookup: ReadonlyMap<string, RouteErrorMap>, route: AppSurfaceRoute, status: number) => AnySchema | undefined;
49
49
  /**
50
- * Assert that an error schema exists for a route+status and validate the body against it.
50
+ * Assert that a route declares an error — its status, and its `error` code
51
+ * at that status — and that the body parses against the route's schema there.
52
+ * The schema at a status is a union of its definitions' bodies, each
53
+ * `error` a `literal` of its code for a definition made by `rest_error`
54
+ * (`to_error_schemas`), so a code the route
55
+ * doesn't declare at the status fails the parse.
51
56
  *
52
57
  * Protected routes should always have auto-derived error schemas (401 for authenticated,
53
58
  * 403 for role-restricted). A missing schema indicates a gap in error schema derivation.
54
59
  *
55
- * @param lookup - map from `"METHOD /path"` to merged error schemas
60
+ * @param lookup - map from `"METHOD /path"` to each route's error map (`AppSurfaceSpec.route_error_maps`)
56
61
  * @param route - the surface route to validate against
57
62
  * @param status - expected HTTP status code
58
63
  * @param body - the parsed response body to validate
59
64
  * @throws AssertionError if no schema is declared for the route+status pair.
60
- * @throws Error if the body does not satisfy the declared schema, its message
61
- * carrying the failed parse's issues (`parse_any`).
65
+ * @throws Error if the body does not satisfy the declared schema, a code the
66
+ * route doesn't declare at the status included, its message carrying the
67
+ * failed parse's issues (`parse_any`).
62
68
  */
63
- export declare const assert_error_schema_valid: (lookup: Map<string, RouteErrorSchemas>, route: AppSurfaceRoute, status: number, body: unknown) => void;
69
+ export declare const assert_error_schema_valid: (lookup: ReadonlyMap<string, RouteErrorMap>, route: AppSurfaceRoute, status: number, body: unknown) => void;
70
+ /**
71
+ * Assert that a response is not an error its route leaves undeclared: a JSON
72
+ * body at an error status must be at a status the route's error map declares
73
+ * and parse against it, by the rule the DEV error check runs
74
+ * (`check_route_error` — a 500 `internal_error` and a 503
75
+ * `service_unavailable` always accepted, a JSON-RPC error envelope on a
76
+ * `jsonrpc` route not a REST error body). A success status or a non-JSON
77
+ * response passes.
78
+ *
79
+ * @param errors - the route's error map
80
+ * @param jsonrpc - whether the route answers JSON-RPC envelopes (`RouteSpec.jsonrpc`)
81
+ * @param response - the response, read through a clone
82
+ * @param label - what names the request in a failure
83
+ * @throws Error on a JSON error the route's map doesn't declare
84
+ */
85
+ export declare const assert_error_response_declared: (errors: RouteErrorMap, jsonrpc: boolean, response: Response, label: string) => Promise<void>;
64
86
  /**
65
87
  * Verify every route under a path prefix has the exact expected middleware stack.
66
88
  *
@@ -1 +1 @@
1
- {"version":3,"file":"assertions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/assertions.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAgB7B,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAA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oB,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAW7D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,UAAU,MAAM,EAAE,iBAAiB,MAAM,KAAG,MACtB,CAAC;AAE5D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,+BAA+B,GAC3C,SAAS,UAAU,EACnB,eAAe,MAAM,KACnB,IAOF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,4BAA4B,GAAI,eAAe,MAAM,UAAU,KAAG,IAE9E,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kCAAkC,GAC9C,SAAS,UAAU,EACnB,iBAAiB,KAAK,CAAC,MAAM,CAAC,KAC5B,IAWF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,GAClC,QAAQ,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,EAC1C,OAAO,eAAe,EACtB,QAAQ,MAAM,KACZ,SAAS,GAAG,SAEd,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,yBAAyB,GACrC,QAAQ,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,EAC1C,OAAO,eAAe,EACtB,QAAQ,MAAM,EACd,MAAM,OAAO,KACX,IAUF,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,8BAA8B,GAC1C,QAAQ,aAAa,EACrB,SAAS,OAAO,EAChB,UAAU,QAAQ,EAClB,OAAO,MAAM,KACX,OAAO,CAAC,IAAI,CAiBd,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,GACxC,SAAS,UAAU,EACnB,aAAa,MAAM,EACnB,qBAAqB,KAAK,CAAC,MAAM,CAAC,KAChC,IAUF,CAAC"}
@@ -11,8 +11,10 @@ import { readFileSync } from 'node:fs';
11
11
  import { resolve, dirname } from 'node:path';
12
12
  import { fileURLToPath } from 'node:url';
13
13
  import { assert } from 'vitest';
14
+ import { format_route_key } from '../http/surface_query.js';
14
15
  import { is_public_auth } from '../http/auth_shape.js';
15
16
  import { parse_any } from '../schema_issues.js';
17
+ import { check_route_error, format_route_error_check, is_error_status, is_json_response } from '../http/route_error_check.js';
16
18
  /**
17
19
  * Resolve an absolute path relative to the caller's module.
18
20
  *
@@ -55,45 +57,83 @@ export const assert_only_expected_public_routes = (surface, expected_public) =>
55
57
  const expected = new Set(expected_public);
56
58
  const actual_public = surface.routes
57
59
  .filter((r) => is_public_auth(r.auth))
58
- .map((r) => `${r.method} ${r.path}`);
60
+ .map((r) => format_route_key(r));
59
61
  const unexpected = actual_public.filter((r) => !expected.has(r));
60
62
  const missing = expected_public.filter((r) => !actual_public.includes(r));
61
63
  assert.strictEqual(unexpected.length, 0, `Unexpected public routes: ${unexpected.join(', ')}`);
62
64
  assert.strictEqual(missing.length, 0, `Expected public routes missing: ${missing.join(', ')}`);
63
65
  };
64
66
  /**
65
- * Look up the merged error schema for a route+status from a pre-built schema lookup.
67
+ * Look up the error schema for a route+status in its error map.
66
68
  *
67
- * @param lookup - map from `"METHOD /path"` to merged error schemas
69
+ * @param lookup - map from `"METHOD /path"` to each route's error map (`AppSurfaceSpec.route_error_maps`)
68
70
  * @param route - the surface route to look up
69
71
  * @param status - HTTP status code
70
- * @returns the Zod or `@fuzdev/fuz_schema` schema for that route+status, or
72
+ * @returns the `@fuzdev/fuz_schema` schema for that route+status, or
71
73
  * `undefined` when no error schema is declared for the status code
72
74
  */
73
75
  export const get_route_error_schema = (lookup, route, status) => {
74
- const key = `${route.method} ${route.path}`;
75
- return lookup.get(key)?.[status];
76
+ return lookup.get(format_route_key(route))?.schemas[status];
76
77
  };
77
78
  /**
78
- * Assert that an error schema exists for a route+status and validate the body against it.
79
+ * Assert that a route declares an error — its status, and its `error` code
80
+ * at that status — and that the body parses against the route's schema there.
81
+ * The schema at a status is a union of its definitions' bodies, each
82
+ * `error` a `literal` of its code for a definition made by `rest_error`
83
+ * (`to_error_schemas`), so a code the route
84
+ * doesn't declare at the status fails the parse.
79
85
  *
80
86
  * Protected routes should always have auto-derived error schemas (401 for authenticated,
81
87
  * 403 for role-restricted). A missing schema indicates a gap in error schema derivation.
82
88
  *
83
- * @param lookup - map from `"METHOD /path"` to merged error schemas
89
+ * @param lookup - map from `"METHOD /path"` to each route's error map (`AppSurfaceSpec.route_error_maps`)
84
90
  * @param route - the surface route to validate against
85
91
  * @param status - expected HTTP status code
86
92
  * @param body - the parsed response body to validate
87
93
  * @throws AssertionError if no schema is declared for the route+status pair.
88
- * @throws Error if the body does not satisfy the declared schema, its message
89
- * carrying the failed parse's issues (`parse_any`).
94
+ * @throws Error if the body does not satisfy the declared schema, a code the
95
+ * route doesn't declare at the status included, its message carrying the
96
+ * failed parse's issues (`parse_any`).
90
97
  */
91
98
  export const assert_error_schema_valid = (lookup, route, status, body) => {
99
+ const key = format_route_key(route);
92
100
  const schema = get_route_error_schema(lookup, route, status);
93
- assert.ok(schema, `missing error schema for ${status} on ${route.method} ${route.path}`);
101
+ assert.ok(schema, `missing error schema for ${status} on ${key}`);
94
102
  const result = parse_any(schema, body);
95
103
  if (!result.ok) {
96
- throw new Error(`error schema mismatch for ${status} on ${route.method} ${route.path}: ${JSON.stringify(result.issues)}`);
104
+ throw new Error(`error schema mismatch for ${status} on ${key} (error ${JSON.stringify(body?.error)}): ${JSON.stringify(result.issues)}`);
105
+ }
106
+ };
107
+ /**
108
+ * Assert that a response is not an error its route leaves undeclared: a JSON
109
+ * body at an error status must be at a status the route's error map declares
110
+ * and parse against it, by the rule the DEV error check runs
111
+ * (`check_route_error` — a 500 `internal_error` and a 503
112
+ * `service_unavailable` always accepted, a JSON-RPC error envelope on a
113
+ * `jsonrpc` route not a REST error body). A success status or a non-JSON
114
+ * response passes.
115
+ *
116
+ * @param errors - the route's error map
117
+ * @param jsonrpc - whether the route answers JSON-RPC envelopes (`RouteSpec.jsonrpc`)
118
+ * @param response - the response, read through a clone
119
+ * @param label - what names the request in a failure
120
+ * @throws Error on a JSON error the route's map doesn't declare
121
+ */
122
+ export const assert_error_response_declared = async (errors, jsonrpc, response, label) => {
123
+ if (!is_error_status(response.status))
124
+ return;
125
+ if (!is_json_response(response))
126
+ return;
127
+ let body;
128
+ try {
129
+ body = await response.clone().json();
130
+ }
131
+ catch {
132
+ return;
133
+ }
134
+ const check = check_route_error(errors, response.status, body, jsonrpc);
135
+ if (!check.ok) {
136
+ throw new Error(`${format_route_error_check(check, response.status, label)}: ${JSON.stringify(check.kind === 'schema_mismatch' ? check.issues : body)}`);
97
137
  }
98
138
  };
99
139
  /**
@@ -1,6 +1,6 @@
1
1
  import './assert_dev_env.js';
2
- import { type SurfaceSecurityPolicyOptions, type ErrorSchemaTightnessOptions } from './surface_invariants.js';
3
- import { type AppSurfaceSpec } from '../http/surface.js';
2
+ import { type SurfaceSecurityPolicyOptions } from './surface_invariants.js';
3
+ import type { AppSurfaceSpec } from '../http/surface.js';
4
4
  /** Options for adversarial test runners (auth enforcement and input validation). */
5
5
  export interface AdversarialTestOptions {
6
6
  /** Build the app surface bundle (surface + route specs + middleware specs). */
@@ -29,22 +29,6 @@ export interface AdversarialTestOptions {
29
29
  * - correct auth passes guard — every protected route, assert not 401/403
30
30
  */
31
31
  export declare const describe_adversarial_auth: (options: AdversarialTestOptions) => void;
32
- /**
33
- * Merge a consumer's `error_schema_tightness` option with
34
- * `default_error_schema_tightness` so `allowlist` and `ignore_statuses` are
35
- * additive rather than replacing.
36
- *
37
- * - `undefined` → return the default as-is.
38
- * - `null` → return `null` (opt out of the assertion).
39
- * - object → spread the default, then consumer overrides for scalar fields
40
- * (`min_specificity`), then concat stock-then-consumer for the list fields
41
- * (`allowlist`, `ignore_statuses`) so consumer entries extend rather than
42
- * replace.
43
- *
44
- * Exported for direct use when a consumer calls `assert_error_schema_tightness`
45
- * outside the standard suite but still wants the additive merge.
46
- */
47
- export declare const resolve_standard_error_schema_tightness: (consumer: ErrorSchemaTightnessOptions | null | undefined) => ErrorSchemaTightnessOptions | null;
48
32
  /** Options for the standard attack surface test suite. */
49
33
  export interface StandardAttackSurfaceOptions {
50
34
  /** Build the app surface bundle (surface + route specs + middleware specs). */
@@ -61,19 +45,6 @@ export interface StandardAttackSurfaceOptions {
61
45
  api_path_prefix?: string;
62
46
  /** Security policy configuration. Omit for sensible defaults. */
63
47
  security_policy?: SurfaceSecurityPolicyOptions;
64
- /**
65
- * Error schema tightness assertion config. Defaults to
66
- * `default_error_schema_tightness` (ignores 401/403/429,
67
- * `min_specificity: 'enum'`, allowlist seeded with
68
- * `fuz_app_stock_route_tightness_allowlist`).
69
- *
70
- * Consumer-supplied `allowlist` and `ignore_statuses` are **additive** —
71
- * the suite merges them underneath the stock defaults, so project-specific
72
- * entries don't need to re-list fuz_app's own stock routes. Pass a narrower
73
- * config to extend either list or tighten `min_specificity`; pass `null`
74
- * to skip the assertion and keep the audit log informational-only.
75
- */
76
- error_schema_tightness?: ErrorSchemaTightnessOptions | null;
77
48
  /**
78
49
  * Routes the three adversarial sub-suites skip, in `'METHOD /path'` form
79
50
  * — the escape hatch every sibling suite carries (`round_trip`,
@@ -94,10 +65,9 @@ export interface StandardAttackSurfaceOptions {
94
65
  * 5. Surface invariants — structural assertions over `surface.routes` (error schemas, descriptions, duplicates, consistency)
95
66
  * 6. RPC/WS surface invariants — structural assertions over `surface.rpc_endpoints` + `surface.ws_endpoints` (descriptions, protocol-action spread, kind ⇔ auth)
96
67
  * 7. Security policy — rate limiting on sensitive routes, no unexpected public mutations, method conventions
97
- * 8. Error schema tightness — informational log of generic vs specific error schemas, plus assertion against `default_error_schema_tightness` by default (opt out with `error_schema_tightness: null`)
98
- * 9. Adversarial auth — unauthenticated/wrong-role/correct-auth enforcement
99
- * 10. Adversarial input — input body and params validation
100
- * 11. Adversarial 404 — stub 404 handlers, validate response bodies against declared schemas
68
+ * 8. Adversarial auth — unauthenticated/wrong-role/correct-auth enforcement, every refusal a status and code of the route's own error map
69
+ * 9. Adversarial input — input body and params validation, each 400 a code of the route's own map
70
+ * 10. Adversarial 404 — stub 404 handlers, validate response bodies against the route's declared 404
101
71
  *
102
72
  * Consumer test files call this with project-specific options, then add
103
73
  * any project-specific assertions in additional `describe` blocks.
@@ -1 +1 @@
1
- {"version":3,"file":"attack_surface.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/attack_surface.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAoB7B,OAAO,EAQN,KAAK,4BAA4B,EACjC,KAAK,2BAA2B,EAChC,MAAM,yBAAyB,CAAC;AAejC,OAAO,EAA6B,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAwDpF,oFAAoF;AACpF,MAAM,WAAW,sBAAsB;IACtC,+EAA+E;IAC/E,KAAK,EAAE,MAAM,cAAc,CAAC;IAC5B,yDAAyD;IACzD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC5B;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,yBAAyB,GAAI,SAAS,sBAAsB,KAAG,IA6J3E,CAAC;AAIF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,uCAAuC,GACnD,UAAU,2BAA2B,GAAG,IAAI,GAAG,SAAS,KACtD,2BAA2B,GAAG,IAWhC,CAAC;AAEF,0DAA0D;AAC1D,MAAM,WAAW,4BAA4B;IAC5C,+EAA+E;IAC/E,KAAK,EAAE,MAAM,cAAc,CAAC;IAC5B,yDAAyD;IACzD,aAAa,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACjF,sBAAsB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,iIAAiI;IACjI,uBAAuB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACvC,yDAAyD;IACzD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrB,qEAAqE;IACrE,eAAe,CAAC,EAAE,MAA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