@fuzdev/fuz_app 0.162.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 (280) 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 +39 -36
  8. package/dist/auth/account_action_specs.d.ts +441 -115
  9. package/dist/auth/account_action_specs.d.ts.map +1 -1
  10. package/dist/auth/account_action_specs.js +47 -46
  11. package/dist/auth/account_route_schema.d.ts +98 -62
  12. package/dist/auth/account_route_schema.d.ts.map +1 -1
  13. package/dist/auth/account_route_schema.js +45 -45
  14. package/dist/auth/account_routes.js +1 -1
  15. package/dist/auth/account_schema.d.ts +54 -27
  16. package/dist/auth/account_schema.d.ts.map +1 -1
  17. package/dist/auth/account_schema.js +16 -18
  18. package/dist/auth/admin_action_specs.d.ts +76 -76
  19. package/dist/auth/admin_action_specs.js +2 -4
  20. package/dist/auth/admin_actions.d.ts +4 -4
  21. package/dist/auth/admin_actions.d.ts.map +1 -1
  22. package/dist/auth/admin_actions.js +3 -3
  23. package/dist/auth/all_cell_actions.d.ts +3 -3
  24. package/dist/auth/all_cell_actions.d.ts.map +1 -1
  25. package/dist/auth/all_cell_actions.js +1 -1
  26. package/dist/auth/api_token.d.ts +4 -4
  27. package/dist/auth/api_token.d.ts.map +1 -1
  28. package/dist/auth/api_token.js +3 -3
  29. package/dist/auth/audit_log_route_schema.d.ts +1 -1
  30. package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
  31. package/dist/auth/audit_log_route_schema.js +4 -5
  32. package/dist/auth/audit_log_schema.d.ts +46 -66
  33. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  34. package/dist/auth/audit_log_schema.js +34 -30
  35. package/dist/auth/bootstrap_route_schema.d.ts +146 -52
  36. package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
  37. package/dist/auth/bootstrap_route_schema.js +33 -19
  38. package/dist/auth/cell_grant_action_specs.d.ts +1 -1
  39. package/dist/auth/cell_grant_action_specs.js +1 -1
  40. package/dist/auth/cell_grant_actions.d.ts +4 -4
  41. package/dist/auth/cell_grant_actions.d.ts.map +1 -1
  42. package/dist/auth/cell_grant_actions.js +1 -1
  43. package/dist/auth/credential_type_schema.d.ts +16 -29
  44. package/dist/auth/credential_type_schema.d.ts.map +1 -1
  45. package/dist/auth/credential_type_schema.js +14 -18
  46. package/dist/auth/daemon_token.d.ts +4 -4
  47. package/dist/auth/daemon_token.d.ts.map +1 -1
  48. package/dist/auth/daemon_token.js +3 -3
  49. package/dist/auth/daemon_token_middleware.d.ts +1 -1
  50. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  51. package/dist/auth/daemon_token_middleware.js +5 -5
  52. package/dist/auth/grant_path_schema.d.ts +15 -29
  53. package/dist/auth/grant_path_schema.d.ts.map +1 -1
  54. package/dist/auth/grant_path_schema.js +13 -17
  55. package/dist/auth/middleware.js +4 -4
  56. package/dist/auth/migrations.js +1 -1
  57. package/dist/auth/name_schema.d.ts +7 -6
  58. package/dist/auth/name_schema.d.ts.map +1 -1
  59. package/dist/auth/name_schema.js +8 -9
  60. package/dist/auth/password.d.ts +15 -7
  61. package/dist/auth/password.d.ts.map +1 -1
  62. package/dist/auth/password.js +16 -9
  63. package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
  64. package/dist/auth/role_grant_offer_action_specs.js +2 -2
  65. package/dist/auth/role_grant_offer_actions.d.ts +4 -4
  66. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  67. package/dist/auth/role_grant_offer_actions.js +3 -3
  68. package/dist/auth/role_grant_offer_notifications.js +2 -2
  69. package/dist/auth/role_grant_offer_schema.d.ts +2 -2
  70. package/dist/auth/role_grant_offer_schema.js +2 -2
  71. package/dist/auth/role_schema.d.ts +47 -55
  72. package/dist/auth/role_schema.d.ts.map +1 -1
  73. package/dist/auth/role_schema.js +29 -35
  74. package/dist/auth/scope_kind_schema.d.ts +22 -26
  75. package/dist/auth/scope_kind_schema.d.ts.map +1 -1
  76. package/dist/auth/scope_kind_schema.js +19 -19
  77. package/dist/auth/self_service_role_action_specs.js +1 -1
  78. package/dist/auth/self_service_role_actions.d.ts +6 -6
  79. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  80. package/dist/auth/self_service_role_actions.js +7 -6
  81. package/dist/auth/signup_route_schema.d.ts +71 -21
  82. package/dist/auth/signup_route_schema.d.ts.map +1 -1
  83. package/dist/auth/signup_route_schema.js +17 -19
  84. package/dist/auth/standard_rpc_actions.d.ts +1 -1
  85. package/dist/auth/standard_rpc_actions.js +1 -1
  86. package/dist/auth/token_lifetime.d.ts +33 -9
  87. package/dist/auth/token_lifetime.d.ts.map +1 -1
  88. package/dist/auth/token_lifetime.js +8 -7
  89. package/dist/auth/token_scope.d.ts +99 -25
  90. package/dist/auth/token_scope.d.ts.map +1 -1
  91. package/dist/auth/token_scope.js +57 -35
  92. package/dist/db/CLAUDE.md +2 -1
  93. package/dist/db/file_fact_url.d.ts +11 -6
  94. package/dist/db/file_fact_url.d.ts.map +1 -1
  95. package/dist/db/file_fact_url.js +5 -5
  96. package/dist/db/schema_ready.d.ts +0 -5
  97. package/dist/db/schema_ready.d.ts.map +1 -1
  98. package/dist/db/schema_ready.js +0 -5
  99. package/dist/http/CLAUDE.md +104 -71
  100. package/dist/http/auth_shape.d.ts +48 -29
  101. package/dist/http/auth_shape.d.ts.map +1 -1
  102. package/dist/http/auth_shape.js +12 -85
  103. package/dist/http/body_limit.d.ts +12 -0
  104. package/dist/http/body_limit.d.ts.map +1 -1
  105. package/dist/http/body_limit.js +15 -0
  106. package/dist/http/body_limit_schema.d.ts +20 -0
  107. package/dist/http/body_limit_schema.d.ts.map +1 -0
  108. package/dist/http/body_limit_schema.js +20 -0
  109. package/dist/http/common_routes.d.ts +1 -1
  110. package/dist/http/common_routes.d.ts.map +1 -1
  111. package/dist/http/common_routes.js +11 -14
  112. package/dist/http/db_routes.d.ts.map +1 -1
  113. package/dist/http/db_routes.js +59 -69
  114. package/dist/http/dev_route_error_check.d.ts +70 -0
  115. package/dist/http/dev_route_error_check.d.ts.map +1 -0
  116. package/dist/http/dev_route_error_check.js +119 -0
  117. package/dist/http/error_schemas.d.ts +365 -189
  118. package/dist/http/error_schemas.d.ts.map +1 -1
  119. package/dist/http/error_schemas.js +256 -149
  120. package/dist/http/health_schema.d.ts +10 -6
  121. package/dist/http/health_schema.d.ts.map +1 -1
  122. package/dist/http/health_schema.js +3 -3
  123. package/dist/http/middleware_spec.d.ts +8 -3
  124. package/dist/http/middleware_spec.d.ts.map +1 -1
  125. package/dist/http/origin.d.ts +12 -43
  126. package/dist/http/origin.d.ts.map +1 -1
  127. package/dist/http/origin.js +10 -6
  128. package/dist/http/route_error_check.d.ts +158 -0
  129. package/dist/http/route_error_check.d.ts.map +1 -0
  130. package/dist/http/route_error_check.js +247 -0
  131. package/dist/http/route_errors.d.ts +80 -0
  132. package/dist/http/route_errors.d.ts.map +1 -0
  133. package/dist/http/route_errors.js +83 -0
  134. package/dist/http/route_spec.d.ts +33 -17
  135. package/dist/http/route_spec.d.ts.map +1 -1
  136. package/dist/http/route_spec.js +48 -62
  137. package/dist/http/schema_helpers.d.ts +0 -33
  138. package/dist/http/schema_helpers.d.ts.map +1 -1
  139. package/dist/http/schema_helpers.js +0 -45
  140. package/dist/http/surface.d.ts +19 -12
  141. package/dist/http/surface.d.ts.map +1 -1
  142. package/dist/http/surface.js +25 -38
  143. package/dist/http/surface_query.d.ts +11 -2
  144. package/dist/http/surface_query.d.ts.map +1 -1
  145. package/dist/http/surface_query.js +7 -1
  146. package/dist/primitive_schemas.d.ts +2 -19
  147. package/dist/primitive_schemas.d.ts.map +1 -1
  148. package/dist/primitive_schemas.js +2 -20
  149. package/dist/primitive_schemas_fuz.d.ts +39 -5
  150. package/dist/primitive_schemas_fuz.d.ts.map +1 -1
  151. package/dist/primitive_schemas_fuz.js +36 -7
  152. package/dist/rate_limiter.d.ts +13 -0
  153. package/dist/rate_limiter.d.ts.map +1 -1
  154. package/dist/rate_limiter.js +20 -2
  155. package/dist/schema_issues.d.ts +29 -11
  156. package/dist/schema_issues.d.ts.map +1 -1
  157. package/dist/schema_issues.js +11 -10
  158. package/dist/schema_meta.d.ts +8 -1
  159. package/dist/schema_meta.d.ts.map +1 -1
  160. package/dist/schema_meta.js +2 -1
  161. package/dist/server/app_server.d.ts +3 -1
  162. package/dist/server/app_server.d.ts.map +1 -1
  163. package/dist/server/app_server.js +24 -10
  164. package/dist/server/serve_fact_route.d.ts.map +1 -1
  165. package/dist/server/serve_fact_route.js +8 -31
  166. package/dist/server/surface_route.d.ts.map +1 -1
  167. package/dist/server/surface_route.js +5 -6
  168. package/dist/server/x_accel.d.ts +12 -7
  169. package/dist/server/x_accel.d.ts.map +1 -1
  170. package/dist/server/x_accel.js +7 -9
  171. package/dist/testing/CLAUDE.md +55 -44
  172. package/dist/testing/admin_integration.d.ts +3 -3
  173. package/dist/testing/admin_integration.d.ts.map +1 -1
  174. package/dist/testing/admin_integration.js +2 -2
  175. package/dist/testing/adversarial_404.d.ts +4 -18
  176. package/dist/testing/adversarial_404.d.ts.map +1 -1
  177. package/dist/testing/adversarial_404.js +19 -51
  178. package/dist/testing/adversarial_headers.d.ts +3 -4
  179. package/dist/testing/adversarial_headers.d.ts.map +1 -1
  180. package/dist/testing/adversarial_headers.js +8 -6
  181. package/dist/testing/adversarial_input.d.ts.map +1 -1
  182. package/dist/testing/adversarial_input.js +18 -17
  183. package/dist/testing/assertions.d.ts +33 -11
  184. package/dist/testing/assertions.d.ts.map +1 -1
  185. package/dist/testing/assertions.js +52 -12
  186. package/dist/testing/attack_surface.d.ts +5 -35
  187. package/dist/testing/attack_surface.d.ts.map +1 -1
  188. package/dist/testing/attack_surface.js +29 -91
  189. package/dist/testing/auth_apps.d.ts.map +1 -1
  190. package/dist/testing/auth_apps.js +2 -1
  191. package/dist/testing/cross_backend/action_manifest.d.ts +126 -56
  192. package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
  193. package/dist/testing/cross_backend/action_manifest.js +11 -11
  194. package/dist/testing/cross_backend/action_manifest_parity.d.ts +1 -1
  195. package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
  196. package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
  197. package/dist/testing/cross_backend/cell_crud.js +2 -1
  198. package/dist/testing/cross_backend/conformance_table.js +1 -1
  199. package/dist/testing/cross_backend/default_spine_surface.d.ts +2 -2
  200. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  201. package/dist/testing/cross_backend/default_spine_surface.js +2 -2
  202. package/dist/testing/cross_backend/fact_serving.js +3 -3
  203. package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
  204. package/dist/testing/cross_backend/identity_parity.js +39 -6
  205. package/dist/testing/cross_backend/origin_conformance.d.ts +278 -102
  206. package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
  207. package/dist/testing/cross_backend/origin_conformance.js +21 -21
  208. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -3
  209. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  210. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +7 -1
  211. package/dist/testing/cross_backend/setup.d.ts +14 -1
  212. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  213. package/dist/testing/cross_backend/setup.js +68 -48
  214. package/dist/testing/cross_backend/spine_suites.d.ts +3 -3
  215. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  216. package/dist/testing/cross_backend/standard.d.ts +4 -4
  217. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  218. package/dist/testing/cross_backend/testing_origin_check.d.ts +147 -71
  219. package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
  220. package/dist/testing/cross_backend/testing_origin_check.js +16 -13
  221. package/dist/testing/cross_backend/testing_reset_actions.d.ts +70 -27
  222. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  223. package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
  224. package/dist/testing/cross_backend/token_lifetime.js +34 -1
  225. package/dist/testing/data_exposure.d.ts.map +1 -1
  226. package/dist/testing/data_exposure.js +5 -4
  227. package/dist/testing/error_coverage.d.ts +24 -34
  228. package/dist/testing/error_coverage.d.ts.map +1 -1
  229. package/dist/testing/error_coverage.js +46 -89
  230. package/dist/testing/integration.d.ts.map +1 -1
  231. package/dist/testing/integration.js +6 -14
  232. package/dist/testing/integration_helpers.d.ts +37 -9
  233. package/dist/testing/integration_helpers.d.ts.map +1 -1
  234. package/dist/testing/integration_helpers.js +86 -40
  235. package/dist/testing/middleware.d.ts +3 -5
  236. package/dist/testing/middleware.d.ts.map +1 -1
  237. package/dist/testing/middleware.js +5 -4
  238. package/dist/testing/rate_limiting.d.ts +1 -1
  239. package/dist/testing/rate_limiting.d.ts.map +1 -1
  240. package/dist/testing/rate_limiting.js +5 -4
  241. package/dist/testing/round_trip.d.ts.map +1 -1
  242. package/dist/testing/round_trip.js +5 -3
  243. package/dist/testing/schema_generators.d.ts +10 -3
  244. package/dist/testing/schema_generators.d.ts.map +1 -1
  245. package/dist/testing/schema_generators.js +23 -11
  246. package/dist/testing/stubs.d.ts +10 -1
  247. package/dist/testing/stubs.d.ts.map +1 -1
  248. package/dist/testing/stubs.js +15 -5
  249. package/dist/testing/surface_invariants.d.ts +36 -115
  250. package/dist/testing/surface_invariants.d.ts.map +1 -1
  251. package/dist/testing/surface_invariants.js +106 -269
  252. package/dist/testing/token_scope_fixtures.d.ts +24 -0
  253. package/dist/testing/token_scope_fixtures.d.ts.map +1 -0
  254. package/dist/testing/token_scope_fixtures.js +49 -0
  255. package/dist/testing/transports/bootstrap.d.ts +1 -1
  256. package/dist/testing/transports/bootstrap.d.ts.map +1 -1
  257. package/dist/testing/transports/bootstrap.js +13 -12
  258. package/dist/ui/BootstrapForm.svelte +4 -2
  259. package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
  260. package/dist/ui/CLAUDE.md +4 -2
  261. package/dist/ui/SignupForm.svelte +4 -2
  262. package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
  263. package/dist/ui/auth_state.svelte.d.ts.map +1 -1
  264. package/dist/ui/auth_state.svelte.js +2 -8
  265. package/dist/ui/backend_probe.svelte.js +3 -3
  266. package/dist/ui/table_state.svelte.d.ts.map +1 -1
  267. package/dist/ui/table_state.svelte.js +1 -8
  268. package/dist/ui/ui_fetch.d.ts +12 -2
  269. package/dist/ui/ui_fetch.d.ts.map +1 -1
  270. package/dist/ui/ui_fetch.js +22 -4
  271. package/package.json +1 -1
  272. package/dist/auth/audit_log_schema_fuz.d.ts +0 -53
  273. package/dist/auth/audit_log_schema_fuz.d.ts.map +0 -1
  274. package/dist/auth/audit_log_schema_fuz.js +0 -50
  275. package/dist/auth/role_schema_fuz.d.ts +0 -30
  276. package/dist/auth/role_schema_fuz.d.ts.map +0 -1
  277. package/dist/auth/role_schema_fuz.js +0 -30
  278. package/dist/auth/scope_kind_schema_fuz.d.ts +0 -31
  279. package/dist/auth/scope_kind_schema_fuz.d.ts.map +0 -1
  280. package/dist/auth/scope_kind_schema_fuz.js +0 -31
@@ -1 +1 @@
1
- {"version":3,"file":"admin_integration.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/admin_integration.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAgC7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAY3E,OAAO,EAMN,KAAK,uBAAuB,EAC5B,MAAM,kBAAkB,CAAC;AA4B1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,0BAA0B,CAAC;AAavE;;GAEG;AACH,MAAM,WAAW,mCAAmC;IACnD;;;;OAIG;IACH,UAAU,EAAE,SAAS,CAAC;IACtB;;;;OAIG;IACH,cAAc,EAAE,cAAc,CAAC;IAC/B,uFAAuF;IACvF,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IACxC,4GAA4G;IAC5G,KAAK,EAAE,gBAAgB,CAAC;IACxB;;;OAGG;IACH,aAAa,EAAE,uBAAuB,CAAC;IACvC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAiBD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yCAAyC,GACrD,SAAS,mCAAmC,KAC1C,IAg+BF,CAAC"}
1
+ {"version":3,"file":"admin_integration.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/admin_integration.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAgC7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAYvE,OAAO,EAMN,KAAK,uBAAuB,EAC5B,MAAM,kBAAkB,CAAC;AA4B1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,0BAA0B,CAAC;AAavE;;GAEG;AACH,MAAM,WAAW,mCAAmC;IACnD;;;;OAIG;IACH,UAAU,EAAE,SAAS,CAAC;IACtB;;;;OAIG;IACH,cAAc,EAAE,cAAc,CAAC;IAC/B,uFAAuF;IACvF,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IACxC,yGAAyG;IACzG,KAAK,EAAE,YAAY,CAAC;IACpB;;;OAGG;IACH,aAAa,EAAE,uBAAuB,CAAC;IACvC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAiBD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yCAAyC,GACrD,SAAS,mCAAmC,KAC1C,IAg+BF,CAAC"}
@@ -7,7 +7,7 @@ import './assert_dev_env.js';
7
7
  * surface — see `role_grant_offer_create` / `role_grant_revoke`), session/token
8
8
  * management, and audit log routes against a real database.
9
9
  *
10
- * Consumers call it with their route factory, session config, role schema,
10
+ * Consumers call it with their route factory, session config, role registry,
11
11
  * and RPC endpoint specs — all admin route tests come for free.
12
12
  *
13
13
  * Scope: admin *semantics* — cross-admin isolation, role_grant grant/revoke
@@ -85,7 +85,7 @@ export const describe_standard_admin_integration_tests = (options) => {
85
85
  const { role_specs } = options.roles;
86
86
  const grantable_role = pick_grantable_role(role_specs);
87
87
  // Error coverage tracking across test groups
88
- const error_collector = new ErrorCoverageCollector();
88
+ const error_collector = new ErrorCoverageCollector(options.surface_source.route_error_maps);
89
89
  afterAll(() => {
90
90
  // Scope coverage to admin auth-related routes. Account listing,
91
91
  // session/token revoke-all, audit-log reads, and invite CRUD all
@@ -1,28 +1,14 @@
1
1
  import './assert_dev_env.js';
2
- import { type ValidationSchema } from '../schema_issues.js';
3
2
  import type { AdversarialTestOptions } from './attack_surface.js';
4
- /**
5
- * Extract the error code from a 404 error schema, Zod or `@fuzdev/fuz_schema`,
6
- * for use in the stub handler.
7
- *
8
- * Reads the schema's output-side JSON Schema with `unrepresentable: 'any'`,
9
- * so a field JSON Schema can't say (a transform, a `z.custom()`) beside
10
- * `error` doesn't hide the code. Supports a literal (`{const: '...'}`) and an
11
- * enum (`{enum: [...]}`, uses first value); `null` when `error` is neither.
12
- * A schema either emitter refuses outright throws.
13
- *
14
- * @param schema - a route's declared 404 error schema
15
- * @returns the code the stub handler answers with, or `null`
16
- */
17
- export declare const extract_404_error_code: (schema: ValidationSchema) => string | null;
18
3
  /**
19
4
  * Generate adversarial 404 response validation tests.
20
5
  *
21
- * For each route with `params` + 404 in `error_schemas`:
22
- * 1. Creates a stub handler returning 404 with the declared error code
6
+ * For each route with `params` and a 404 definition of its own in `errors`:
7
+ * 1. Creates a stub handler returning 404 with the first such definition's code
23
8
  * 2. Fires a request with valid-format params (nil UUIDs for UUID params)
24
9
  * 3. Validates response status is 404
25
- * 4. Validates response body matches the declared 404 schema (`parse_any`)
10
+ * 4. Validates the code is one the route's error map (`resolve_route_error_map`)
11
+ * declares at 404, and the body parses against its 404 (`assert_error_schema_valid`)
26
12
  */
27
13
  export declare const describe_adversarial_404: (options: AdversarialTestOptions) => void;
28
14
  //# sourceMappingURL=adversarial_404.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"adversarial_404.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_404.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAsB7B,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAOlE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB,GAAI,QAAQ,gBAAgB,KAAG,MAAM,GAAG,IAe1E,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,sBAAsB,KAAG,IAqF1E,CAAC"}
1
+ {"version":3,"file":"adversarial_404.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_404.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAqB7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAOlE;;;;;;;;;GASG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,sBAAsB,KAAG,IA8E1E,CAAC"}
@@ -4,69 +4,38 @@ import './assert_dev_env.js';
4
4
  *
5
5
  * Creates stub handlers that return 404 with the declared error code,
6
6
  * fires requests with valid-format-but-nonexistent params (nil UUIDs),
7
- * and validates response bodies against the declared 404 schemas, Zod or
8
- * `@fuzdev/fuz_schema`.
7
+ * and validates response bodies against the route's declared 404.
9
8
  *
10
9
  * No DB needed — tests schema conformance of 404 responses, not real handlers.
11
10
  *
12
11
  * @module
13
12
  */
14
13
  import { test, assert, describe } from 'vitest';
15
- import { z } from 'zod';
16
- import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
17
- import { to_json_schema } from '@fuzdev/fuz_schema/json_schema.ts';
14
+ import { format_route_key } from '../http/surface_query.js';
18
15
  import { is_null_schema } from '../http/schema_helpers.js';
19
- import { parse_any } from '../schema_issues.js';
16
+ import { assert_error_schema_valid } from './assertions.js';
20
17
  import { create_auth_test_apps, create_route_skip_filter, select_auth_app } from './auth_apps.js';
21
18
  import { resolve_valid_path, generate_valid_body, to_route_content_type } from './schema_generators.js';
22
- /**
23
- * Extract the error code from a 404 error schema, Zod or `@fuzdev/fuz_schema`,
24
- * for use in the stub handler.
25
- *
26
- * Reads the schema's output-side JSON Schema with `unrepresentable: 'any'`,
27
- * so a field JSON Schema can't say (a transform, a `z.custom()`) beside
28
- * `error` doesn't hide the code. Supports a literal (`{const: '...'}`) and an
29
- * enum (`{enum: [...]}`, uses first value); `null` when `error` is neither.
30
- * A schema either emitter refuses outright throws.
31
- *
32
- * @param schema - a route's declared 404 error schema
33
- * @returns the code the stub handler answers with, or `null`
34
- */
35
- export const extract_404_error_code = (schema) => {
36
- const json = (is_schema(schema)
37
- ? to_json_schema(schema, { unrepresentable: 'any' })
38
- : z.toJSONSchema(schema, { unrepresentable: 'any' }));
39
- if (json.type !== 'object' || !json.properties || typeof json.properties !== 'object')
40
- return null;
41
- const props = json.properties;
42
- if (!props.error || typeof props.error !== 'object')
43
- return null;
44
- const error_schema = props.error;
45
- if (typeof error_schema.const === 'string')
46
- return error_schema.const;
47
- if (Array.isArray(error_schema.enum) && typeof error_schema.enum[0] === 'string')
48
- return error_schema.enum[0];
49
- return null;
50
- };
51
19
  /**
52
20
  * Generate adversarial 404 response validation tests.
53
21
  *
54
- * For each route with `params` + 404 in `error_schemas`:
55
- * 1. Creates a stub handler returning 404 with the declared error code
22
+ * For each route with `params` and a 404 definition of its own in `errors`:
23
+ * 1. Creates a stub handler returning 404 with the first such definition's code
56
24
  * 2. Fires a request with valid-format params (nil UUIDs for UUID params)
57
25
  * 3. Validates response status is 404
58
- * 4. Validates response body matches the declared 404 schema (`parse_any`)
26
+ * 4. Validates the code is one the route's error map (`resolve_route_error_map`)
27
+ * declares at 404, and the body parses against its 404 (`assert_error_schema_valid`)
59
28
  */
60
29
  export const describe_adversarial_404 = (options) => {
61
30
  const { build, roles } = options;
62
- const { surface, route_specs } = build();
31
+ const { surface, route_specs, route_error_maps } = build();
63
32
  const is_skipped = create_route_skip_filter(options.skip_routes);
64
33
  // Build spec lookup for schema access
65
34
  const spec_lookup = new Map();
66
35
  for (const spec of route_specs) {
67
- spec_lookup.set(`${spec.method} ${spec.path}`, spec);
36
+ spec_lookup.set(format_route_key(spec), spec);
68
37
  }
69
- // Find testable routes: params + 404 + extractable error code
38
+ // Find testable routes: params + a 404 definition of the route's own
70
39
  const testable = [];
71
40
  for (const route of surface.routes) {
72
41
  if (route.params_schema === null)
@@ -75,14 +44,14 @@ export const describe_adversarial_404 = (options) => {
75
44
  continue;
76
45
  if (is_skipped(route))
77
46
  continue;
78
- const key = `${route.method} ${route.path}`;
47
+ const key = format_route_key(route);
79
48
  const spec = spec_lookup.get(key);
80
- if (!spec?.params || !spec.errors?.[404])
49
+ if (!spec?.params)
81
50
  continue;
82
- const error_code = extract_404_error_code(spec.errors[404]);
83
- if (!error_code)
51
+ const not_found = spec.errors?.find((def) => def.status === 404);
52
+ if (!not_found)
84
53
  continue;
85
- testable.push({ key, error_code, spec });
54
+ testable.push({ key, error_code: not_found.code, spec });
86
55
  }
87
56
  if (testable.length === 0)
88
57
  return;
@@ -93,7 +62,7 @@ export const describe_adversarial_404 = (options) => {
93
62
  error_code_by_key.set(entry.key, entry.error_code);
94
63
  }
95
64
  const stub_specs = route_specs.map((spec) => {
96
- const error_code = error_code_by_key.get(`${spec.method} ${spec.path}`);
65
+ const error_code = error_code_by_key.get(format_route_key(spec));
97
66
  if (!error_code)
98
67
  return spec;
99
68
  return {
@@ -104,7 +73,7 @@ export const describe_adversarial_404 = (options) => {
104
73
  const apps = create_auth_test_apps(stub_specs, roles);
105
74
  for (const { key, error_code, spec } of testable) {
106
75
  test(key, async () => {
107
- const route = surface.routes.find((r) => `${r.method} ${r.path}` === key);
76
+ const route = surface.routes.find((r) => format_route_key(r) === key);
108
77
  const app = select_auth_app(apps, route.auth);
109
78
  const url = resolve_valid_path(route.path, spec.params);
110
79
  const request_init = {
@@ -122,9 +91,8 @@ export const describe_adversarial_404 = (options) => {
122
91
  assert.strictEqual(res.status, 404, `Expected 404 for ${key}, got ${res.status}`);
123
92
  const body = await res.json();
124
93
  assert.strictEqual(body.error, error_code, `Expected error '${error_code}' for ${key}, got: ${body.error}`);
125
- // Validate against the declared 404 schema
126
- const parsed = parse_any(spec.errors[404], body);
127
- assert.ok(parsed.ok, `404 body for ${key} does not match its declared schema: ${parsed.ok ? '' : JSON.stringify(parsed.issues)}`);
94
+ // the code is the route's own at 404, and the body its schema there
95
+ assert_error_schema_valid(route_error_maps, route, 404, body);
128
96
  });
129
97
  }
130
98
  });
@@ -1,14 +1,13 @@
1
1
  import './assert_dev_env.js';
2
- import type { z } from 'zod';
2
+ import { type RestErrorDef } from '../http/error_schemas.js';
3
3
  import { type TestMiddlewareStackOptions } from './middleware.js';
4
4
  /** A header-level attack case for middleware stack testing. */
5
5
  export interface AdversarialHeaderCase {
6
6
  name: string;
7
7
  headers: Record<string, string>;
8
8
  expected_status: number;
9
- expected_error?: string;
10
- /** Zod schema to validate error response body against. Defaults to `ApiError` when `expected_error` is set. */
11
- expected_error_schema?: z.ZodType;
9
+ /** The error definition the JSON body must be — its code, and a body its schema accepts. */
10
+ expected_error?: RestErrorDef;
12
11
  /** Whether the request should reach token validation or be short-circuited by earlier middleware. */
13
12
  validate_expectation: 'called' | 'not_called';
14
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"adversarial_headers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_headers.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAoB7B,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,EAGN,KAAK,0BAA0B,EAC/B,MAAM,iBAAiB,CAAC;AAYzB,+DAA+D;AAC/D,MAAM,WAAW,qBAAqB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+GAA+G;IAC/G,qBAAqB,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;IAClC,qGAAqG;IACrG,oBAAoB,EAAE,QAAQ,GAAG,YAAY,CAAC;CAC9C;AAID;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iCAAiC,GAC7C,gBAAgB,MAAM,KACpB,KAAK,CAAC,qBAAqB,CAiE7B,CAAC;AAIF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qCAAqC,GACjD,YAAY,MAAM,EAClB,SAAS,0BAA0B,EACnC,gBAAgB,MAAM,EACtB,cAAc,KAAK,CAAC,qBAAqB,CAAC,KACxC,IAkCF,CAAC"}
1
+ {"version":3,"file":"adversarial_headers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_headers.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAsB7B,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAGN,KAAK,0BAA0B,EAC/B,MAAM,iBAAiB,CAAC;AAYzB,+DAA+D;AAC/D,MAAM,WAAW,qBAAqB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,4FAA4F;IAC5F,cAAc,CAAC,EAAE,YAAY,CAAC;IAC9B,qGAAqG;IACrG,oBAAoB,EAAE,QAAQ,GAAG,YAAY,CAAC;CAC9C;AAID;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iCAAiC,GAC7C,gBAAgB,MAAM,KACpB,KAAK,CAAC,qBAAqB,CAiE7B,CAAC;AAIF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qCAAqC,GACjD,YAAY,MAAM,EAClB,SAAS,0BAA0B,EACnC,gBAAgB,MAAM,EACtB,cAAc,KAAK,CAAC,qBAAqB,CAAC,KACxC,IAmCF,CAAC"}
@@ -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,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvE;;;;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,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,EACtC,OAAO,eAAe,EACtB,QAAQ,MAAM,KACZ,gBAAgB,GAAG,SAGrB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,GACrC,QAAQ,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,EACtC,OAAO,eAAe,EACtB,QAAQ,MAAM,EACd,MAAM,OAAO,KACX,IAWF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,GACxC,SAAS,UAAU,EACnB,aAAa,MAAM,EACnB,qBAAqB,KAAK,CAAC,MAAM,CAAC,KAChC,IAUF,CAAC"}
1
+ {"version":3,"file":"assertions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/assertions.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAe7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oBAAoB,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
  /**