@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
@@ -133,16 +133,12 @@
133
133
  import { open } from 'node:fs/promises';
134
134
  import { Readable } from 'node:stream';
135
135
  import { join } from 'node:path';
136
- import { FactHashSchema, Uuid } from '../primitive_schemas.js';
137
- import { ActingActor } from '../primitive_schemas_fuz.js';
138
- import { z } from 'zod';
139
- import { object } from '@fuzdev/fuz_schema/schema.ts';
136
+ import { ActingActor, FactHashSchema, Uuid } from '../primitive_schemas_fuz.js';
137
+ import { literal, object } from '@fuzdev/fuz_schema/schema.ts';
140
138
  import { build_request_context, get_public_account_id, get_request_context, has_scoped_role } from '../auth/request_context.js';
141
139
  import { ROLE_ADMIN } from '../auth/role_schema.js';
142
140
  import { query_active_actors_by_account } from '../auth/account_queries.js';
143
141
  import { get_route_params } from '../http/route_spec.js';
144
- import { ERROR_INVALID_ROUTE_PARAMS } from '../http/error_schemas.js';
145
- import { WireIssue } from '../schema_issues.js';
146
142
  import { query_get_fact, query_get_fact_meta } from '../db/fact_queries.js';
147
143
  import { to_uint8 } from '../db/fact_store.js';
148
144
  import { query_cell_get } from '../db/cell_queries.js';
@@ -157,30 +153,13 @@ import { FACT_CACHE_CONTROL, FACT_SECURITY_HEADERS } from './fact_security_heade
157
153
  * standard params-validation error shape (`ERROR_INVALID_ROUTE_PARAMS`),
158
154
  * which the round-trip validator expects.
159
155
  */
160
- const bare_hash_params_schema = z.strictObject({
161
- hash: FactHashSchema
162
- });
156
+ const bare_hash_params_schema = object({ hash: FactHashSchema });
163
157
  /**
164
158
  * Path-param schema for the cell-scoped route. `cell_id` validates as a
165
159
  * `Uuid`; `hash` as the canonical fact-hash form. Malformed values 400 via
166
160
  * the standard params-validation shape.
167
161
  */
168
- const cell_fact_params_schema = z.strictObject({
169
- cell_id: Uuid,
170
- hash: FactHashSchema
171
- });
172
- /**
173
- * Shared error-schema entry: tighten the auto-derived 400 to the literal
174
- * emitted by params validation. `issues` is optional because the framework
175
- * emits it through `dev_only` — a production body carries the `error`
176
- * literal alone.
177
- */
178
- const params_400_error = {
179
- 400: z.looseObject({
180
- error: z.literal(ERROR_INVALID_ROUTE_PARAMS),
181
- issues: z.array(WireIssue).optional()
182
- })
183
- };
162
+ const cell_fact_params_schema = object({ cell_id: Uuid, hash: FactHashSchema });
184
163
  /**
185
164
  * Serve a fact's bytes by hash, after the caller has been authorized for it.
186
165
  *
@@ -325,10 +304,9 @@ export const create_serve_cell_fact_route_spec = (options) => {
325
304
  reads_credential: true,
326
305
  description: "Serve content-addressed fact bytes through a named referencing cell. 404 unless the cell admits the caller via can_view_cell (or the steward arm: the governing root's manager reading a pending or rejected contribution) AND references the hash (per-reference, never union-of-referrers).",
327
306
  params: cell_fact_params_schema,
328
- input: z.null(),
307
+ input: literal(null),
329
308
  // The body is a binary stream; no JSON output schema applies.
330
- output: z.null(),
331
- errors: params_400_error,
309
+ output: literal(null),
332
310
  handler: async (c, route) => {
333
311
  const { cell_id, hash } = get_route_params(c);
334
312
  // Resolve the named cell. Missing / soft-deleted → 404 (masked).
@@ -409,10 +387,9 @@ export const create_serve_fact_route_spec = (options) => {
409
387
  // invariant 2 requires the `acting?` slot. On a GET it lives on
410
388
  // `query` (a multi-actor admin disambiguates via `?acting=<actor>`).
411
389
  query: object({ acting: ActingActor }),
412
- input: z.null(),
390
+ input: literal(null),
413
391
  // The body is a binary stream; no JSON output schema applies.
414
- output: z.null(),
415
- errors: params_400_error,
392
+ output: literal(null),
416
393
  handler: async (c, route) => {
417
394
  const { hash } = get_route_params(c);
418
395
  // Defense-in-depth: the auth phase already gated this on the admin
@@ -1 +1 @@
1
- {"version":3,"file":"surface_route.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/surface_route.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,8CAA8C;AAC9C,MAAM,WAAW,mBAAmB;IACnC,2GAA2G;IAC3G,OAAO,EAAE,UAAU,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,GAAI,SAAS,mBAAmB,KAAG,SAmBvE,CAAC"}
1
+ {"version":3,"file":"surface_route.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/surface_route.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,8CAA8C;AAC9C,MAAM,WAAW,mBAAmB;IACnC,2GAA2G;IAC3G,OAAO,EAAE,UAAU,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,GAAI,SAAS,mBAAmB,KAAG,SAmBvE,CAAC"}
@@ -7,8 +7,7 @@
7
7
  *
8
8
  * @module
9
9
  */
10
- import { z } from 'zod';
11
- import { object } from '@fuzdev/fuz_schema/schema.ts';
10
+ import { array, literal, loose_object, object } from '@fuzdev/fuz_schema/schema.ts';
12
11
  import { ActingActor } from '../primitive_schemas_fuz.js';
13
12
  import { ROLE_ADMIN } from '../auth/role_schema.js';
14
13
  /**
@@ -39,9 +38,9 @@ export const create_surface_route_spec = (options) => ({
39
38
  handler: (c) => c.json(options.surface),
40
39
  description: 'Application surface (routes, middleware, schemas) — admin only',
41
40
  query: object({ acting: ActingActor }),
42
- input: z.null(),
43
- output: z.looseObject({
44
- routes: z.array(z.looseObject({})),
45
- middleware: z.array(z.looseObject({}))
41
+ input: literal(null),
42
+ output: loose_object({
43
+ routes: array(loose_object({})),
44
+ middleware: array(loose_object({}))
46
45
  })
47
46
  });
@@ -122,7 +122,7 @@
122
122
  *
123
123
  * @module
124
124
  */
125
- import { z } from 'zod';
125
+ import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
126
126
  /** Result of the facts-location check. */
127
127
  export interface NginxFactsValidation {
128
128
  /** `true` when every rule passes. */
@@ -149,13 +149,18 @@ export declare const validate_facts_internal_location: (config: string, facts_lo
149
149
  * X-Accel serving is impossible to enable without proving at boot that the
150
150
  * facts location is `internal;` and carries the fact hardening headers — a
151
151
  * public facts location would bypass every cell-visibility check. A
152
- * Zod-branded type: the brand can't be forged without an explicit cast, so the
153
- * factory is the only ordinary construction path.
152
+ * branded `@fuzdev/fuz_schema` `object`: the brand can't be forged without an
153
+ * explicit cast, so the factory is the only ordinary construction path.
154
154
  */
155
- export declare const XAccelConfig: z.core.$ZodBranded<z.ZodObject<{
156
- redirect_prefix: z.ZodString;
157
- }, z.core.$strict>, "XAccelConfig", "out">;
158
- export type XAccelConfig = z.infer<typeof XAccelConfig>;
155
+ export declare const XAccelConfig: import("@fuzdev/fuz_schema/schema.ts").Schema<import("@fuzdev/fuz_schema/schema.ts").Branded<{
156
+ redirect_prefix: string;
157
+ }, "XAccelConfig">, {
158
+ redirect_prefix: string;
159
+ }, "object", {
160
+ /** The validated redirect prefix the serving path prepends (e.g. `/_facts/`). */
161
+ redirect_prefix: import("@fuzdev/fuz_schema/schema.ts").Schema<string, string, "string", undefined>;
162
+ }>;
163
+ export type XAccelConfig = Infer<typeof XAccelConfig>;
159
164
  /**
160
165
  * A misconfigured X-Accel facts location — a fail-loud boot error thrown by
161
166
  * `create_x_accel_config`.
@@ -1 +1 @@
1
- {"version":3,"file":"x_accel.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/x_accel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2HG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,0CAA0C;AAC1C,MAAM,WAAW,oBAAoB;IACpC,qCAAqC;IACrC,EAAE,EAAE,OAAO,CAAC;IACZ,wDAAwD;IACxD,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,gCAAgC,GAC5C,QAAQ,MAAM,EACd,gBAAgB,MAAM,KACpB,oBAYF,CAAC;AA+IF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY;;0CAKF,CAAC;AACxB,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;gBACnB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;CAKjC;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,GACjC,iBAAiB,MAAM,EACvB,cAAc,MAAM,KAClB,YAMF,CAAC"}
1
+ {"version":3,"file":"x_accel.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/x_accel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2HG;AAEH,OAAO,EAAyC,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAIjG,0CAA0C;AAC1C,MAAM,WAAW,oBAAoB;IACpC,qCAAqC;IACrC,EAAE,EAAE,OAAO,CAAC;IACZ,wDAAwD;IACxD,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,gCAAgC,GAC5C,QAAQ,MAAM,EACd,gBAAgB,MAAM,KACpB,oBAYF,CAAC;AA+IF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY;;;;;IAEvB,iFAAiF;;EAIlF,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAEtD;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;gBACnB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;CAKjC;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,GACjC,iBAAiB,MAAM,EACvB,cAAc,MAAM,KAClB,YAMF,CAAC"}
@@ -122,7 +122,7 @@
122
122
  *
123
123
  * @module
124
124
  */
125
- import { z } from 'zod';
125
+ import { brand, object, parse_or_throw, string } from '@fuzdev/fuz_schema/schema.ts';
126
126
  import { FACT_SECURITY_HEADERS, fact_security_header_directives } from './fact_security_headers.js';
127
127
  /**
128
128
  * Assert the nginx config serves the X-Accel facts prefix only from `internal;`
@@ -275,15 +275,13 @@ const collect_errors = (config, facts_location) => {
275
275
  * X-Accel serving is impossible to enable without proving at boot that the
276
276
  * facts location is `internal;` and carries the fact hardening headers — a
277
277
  * public facts location would bypass every cell-visibility check. A
278
- * Zod-branded type: the brand can't be forged without an explicit cast, so the
279
- * factory is the only ordinary construction path.
278
+ * branded `@fuzdev/fuz_schema` `object`: the brand can't be forged without an
279
+ * explicit cast, so the factory is the only ordinary construction path.
280
280
  */
281
- export const XAccelConfig = z
282
- .strictObject({
281
+ export const XAccelConfig = brand(object({
283
282
  /** The validated redirect prefix the serving path prepends (e.g. `/_facts/`). */
284
- redirect_prefix: z.string()
285
- })
286
- .brand('XAccelConfig');
283
+ redirect_prefix: string
284
+ }), 'XAccelConfig');
287
285
  /**
288
286
  * A misconfigured X-Accel facts location — a fail-loud boot error thrown by
289
287
  * `create_x_accel_config`.
@@ -317,7 +315,7 @@ export const create_x_accel_config = (redirect_prefix, nginx_config) => {
317
315
  if (!validation.ok) {
318
316
  throw new XAccelConfigError(validation.errors);
319
317
  }
320
- return XAccelConfig.parse({ redirect_prefix });
318
+ return parse_or_throw(XAccelConfig, { redirect_prefix });
321
319
  };
322
320
  /** Strip every trailing `/` so `/_facts/` and `/_facts` compare equal. */
323
321
  const trim_trailing_slashes = (value) => value.replace(/\/+$/, '');
@@ -38,7 +38,7 @@ time (never runtime), where a throwing guard would break `vite build`.
38
38
  - `create_stub_api_middleware({include_daemon_token?, origin_carve_outs?})` — stub `MiddlewareSpec[]` matching `create_auth_middleware_specs`'s output (origin, optional daemon_token, session, request_context, bearer_auth) for surface generation without booting real auth — the same names, paths, order, and declared `errors` (`origin` declares a 403; `bearer_auth` and `daemon_token` declare none, since both soft-fail through `next()`), pinned against the real factory by `auth/middleware.mounted.test.ts`. The surface merges middleware errors into every route under the path, so a stub declaring more would widen the test surface with statuses the live server never returns. Each spec gets its own pass-through handler (not the shared `stub_mw`), so `assert_middleware_stack_mounted` tells the layers apart. See `auth/CLAUDE.md` §Middleware for the real stack.
39
39
  - `create_stub_app_backend(options?)` — stub `AppBackend` with no database: `create_stub_app_deps()` (or `options.deps`), no migration results, a `close` that does nothing (or `options.close`). For assembling a server in tests that never reach the database.
40
40
  - `create_stub_app_server_context(session_options)` — stub `AppServerContext` over `create_stub_app_backend()`; rate limiters null, `bootstrap_status.available: false`.
41
- - `create_test_app_surface_spec(options)` — builds an `AppSurfaceSpec` mirroring `create_app_server`'s route assembly, in its order (consumer routes, then bootstrap routes, RPC endpoint routes, and `GET /api/surface`, + stub middleware + surface generation). `GET /api/surface` is listed only with `surface_route: true`, as `create_app_server` mounts it only when opted in — pass the same value to both so the surface-derived suites probe it exactly when the live server serves it. `daemon_token: true` lists the `daemon_token` layer `create_app_server` mounts when given a `daemon_token_state` (`create_test_app` always passes one, and `default_in_process_suite_options` sets it, along with `app_options.surface_route`); `testing/test_app_server.db.test.ts` pins the stub's routes (order, auth, error schemas, applicable middleware) and middleware names against `create_test_app`'s for every `surface_route` setting. Its middleware list mirrors the real one — a stub `trusted_proxy` spec at `'*'`, then the stub auth stack — so every route's `applicable_middleware` starts with `trusted_proxy` (a route outside `/api/*` lists `['trusted_proxy', 'origin']`, since the origin check covers every path, and a route under an origin carve-out drops `origin`), as on the live server. `CreateTestAppSurfaceSpecOptions`: `session_options`, `create_route_specs`, `env_schema?`, `event_specs?`, `rpc_endpoints?`, `ws_endpoints?`, `allowed_origins?`, `origin_carve_outs?`, `transform_middleware?`, `bootstrap?`, `surface_route?`, `daemon_token?`. Throws, like `create_app_server`, on an endpoint path outside `AUTH_MIDDLEWARE_PATH` (`assert_endpoint_in_auth_scope`), on a route that reads or mints a credential outside it (`assert_credential_routes_in_auth_scope`), on an origin carve-out that overlaps that scope (`assert_origin_carve_outs_valid`), and on a `transform_middleware` that moves, drops, duplicates, reorders, wraps, or replaces the stub proxy spec or a stub auth spec (`assert_middleware_stack_mounted`); the transform receives shallow copies in a fresh array, so an in-place mutation can't slip past the check. Throws on a `ws_endpoints` spec with no `allowed_origins` of its own when no `allowed_origins` option is given (there is no server list to default from). Bootstrap is opt-in (symmetric with `create_app_server` — omit to skip; pass the same value as prod to mount routes at `bootstrap.route_prefix ?? '/api/account'`). Single source of truth for attack-surface tests — track `create_app_server` wiring changes here.
41
+ - `create_test_app_surface_spec(options)` — builds an `AppSurfaceSpec` mirroring `create_app_server`'s route assembly, in its order (consumer routes, then bootstrap routes, RPC endpoint routes, and `GET /api/surface`, + stub middleware + surface generation). `GET /api/surface` is listed only with `surface_route: true`, as `create_app_server` mounts it only when opted in — pass the same value to both so the surface-derived suites probe it exactly when the live server serves it. `daemon_token: true` lists the `daemon_token` layer `create_app_server` mounts when given a `daemon_token_state` (`create_test_app` always passes one, and `default_in_process_suite_options` sets it, along with `app_options.surface_route`); `testing/test_app_server.db.test.ts` pins the stub's routes (order, auth, error schemas, applicable middleware) and middleware names against `create_test_app`'s for every `surface_route` setting. Its middleware list mirrors the real one — the body limit's shape at `'*'` (`body_limit_middleware_shape` with a stub handler, left out with `max_body_size: null`), a stub `trusted_proxy` spec at `'*'`, then the stub auth stack — so every route's `applicable_middleware` starts with `body_limit`, `trusted_proxy` (a route outside `/api/*` lists `['body_limit', 'trusted_proxy', 'origin']`, since the origin check covers every path, and a route under an origin carve-out drops `origin`), as on the live server, and every route's error map carries the limit's 413 and 400 and the origin check's 403 `forbidden_origin`. `CreateTestAppSurfaceSpecOptions`: `session_options`, `create_route_specs`, `env_schema?`, `event_specs?`, `rpc_endpoints?`, `ws_endpoints?`, `allowed_origins?`, `origin_carve_outs?`, `transform_middleware?`, `bootstrap?`, `surface_route?`, `daemon_token?`, `max_body_size?`. Throws, like `create_app_server`, on an endpoint path outside `AUTH_MIDDLEWARE_PATH` (`assert_endpoint_in_auth_scope`), on a route that reads or mints a credential outside it (`assert_credential_routes_in_auth_scope`), on an origin carve-out that overlaps that scope (`assert_origin_carve_outs_valid`), and on a `transform_middleware` that moves, drops, duplicates, reorders, wraps, or replaces the stub proxy spec or a stub auth spec (`assert_middleware_stack_mounted`); the transform receives shallow copies in a fresh array, so an in-place mutation can't slip past the check. Throws on a `ws_endpoints` spec with no `allowed_origins` of its own when no `allowed_origins` option is given (there is no server list to default from). Bootstrap is opt-in (symmetric with `create_app_server` — omit to skip; pass the same value as prod to mount routes at `bootstrap.route_prefix ?? '/api/account'`). Single source of truth for attack-surface tests — track `create_app_server` wiring changes here.
42
42
 
43
43
  Throwing stubs surface mock escape: a test that accidentally reaches into
44
44
  stub territory breaks immediately with a label-scoped error rather than
@@ -417,8 +417,9 @@ or Postgres and runs in the `cross-ts` CI job.
417
417
  - `assert_surface_deterministic(build_surface)` — build twice, `deepStrictEqual` results; catches nondeterminism in surface generation.
418
418
  - `assert_only_expected_public_routes(surface, list)` — bidirectional: no unexpected public routes, no missing expected ones. Format: `['GET /health', 'POST /api/account/login']`.
419
419
  - `assert_full_middleware_stack(surface, prefix, mws)` — every route under `prefix` has exactly `mws` as its middleware chain.
420
- - `get_route_error_schema(lookup, route, status)` — reads from a pre-built merged-error-schema map; the schema is Zod or fuz_schema (`ValidationSchema`).
421
- - `assert_error_schema_valid(lookup, route, status, body)` — assert a schema exists + parses the body (`parse_any`); a mismatch throws an `Error` carrying the issues.
420
+ - `get_route_error_schema(lookup, route, status)` — reads the route's error map (`lookup` is `AppSurfaceSpec.route_error_maps`) at a status, a fuz_schema schema.
421
+ - `assert_error_schema_valid(lookup, route, status, body)` — assert the route declares the status, and the body parses against the status's schema (`parse_any`), a union of its definitions' `literal(code)` bodies, so a code the route doesn't declare at the status fails the parse; a mismatch throws an `Error` carrying the issues. Every adversarial refusal runs through it.
422
+ - `assert_error_response_declared(errors, jsonrpc, response, label)` — a JSON error response (400 and up) is one the route's map declares, by `check_route_error` (the DEV error check's rule: 500 `internal_error` / 503 `service_unavailable` always accepted, a JSON-RPC envelope on a `jsonrpc` route skipped, a success or non-JSON response passing); what the attack-surface suite's `correct auth passes guard` holds each answer to.
422
423
 
423
424
  ### `surface_invariants.ts` — structural + policy invariants
424
425
 
@@ -431,10 +432,10 @@ Structural invariants (options-free, universal):
431
432
  - `assert_query_routes_declare_400` — every route with query has 400.
432
433
  - `assert_descriptions_present` — every route has a non-empty description.
433
434
  - `assert_no_duplicate_routes` — no duplicate method+path pairs.
434
- - `assert_middleware_errors_propagated` — every middleware-declared error status appears on every applicable route.
435
- - `assert_error_schemas_structurally_valid` — every declared error schema has an `error` property at the top level (matches `ApiError`).
436
- - `assert_error_code_status_consistency` — the same `z.literal()` error code never appears at two different HTTP statuses.
437
- - `assert_404_schemas_use_specific_errors` — routes with params declaring 404 must use `z.literal()` or `z.enum()`, not generic `z.string()`.
435
+ - `assert_middleware_errors_propagated` — every middleware-declared error status appears on every applicable route. Holds by construction on a generated surface (the route error map unions the layers); it checks a snapshot or a hand-built surface.
436
+ - `assert_error_codes_specific` — every declared error body (each union branch, routes and middleware) has an `error` that is a `const` or an `enum` — a definition built by `rest_error`; the one tightness invariant.
437
+ - `assert_error_codes_well_formed` — every declared `error` code matches `REST_ERROR_CODE_PATTERN` (`^[a-z][a-z0-9_]*$`): a code, never prose, which goes in `message`.
438
+ - `assert_error_code_status_consistency` — the same `const` error code (a definition's `literal`) never appears at two different HTTP statuses, read through every `anyOf` / `oneOf` branch.
438
439
 
439
440
  RPC / WS structural invariants (options-free, apply over `surface.rpc_endpoints`
440
441
 
@@ -458,14 +459,6 @@ Policy invariants (configurable, sensible defaults):
458
459
  - `assert_mutation_routes_use_post` — routes with input schemas must not be GET (bypasses browser GET idempotency assumptions).
459
460
  - `assert_keeper_routes_under_prefix` — keeper routes must be under `keeper_route_prefixes` (default `['/api/']`).
460
461
 
461
- Tightness audit:
462
-
463
- - `audit_error_schema_tightness(surface) => Array<ErrorSchemaAuditEntry>` — classifies every route × status combination as `'literal' | 'enum' | 'generic'`.
464
- - `assert_error_schema_tightness(surface, options?)` — fails routes below a threshold (`min_specificity`, default `'enum'`) with `allowlist` + `ignore_statuses` escape hatches.
465
- - `fuz_app_stock_route_tightness_allowlist` — currently empty. Every fuz_app-shipped route (account login/password/bootstrap/signup, db health/tables/:name/tables/:name/rows/:id) has been tightened in place to `z.enum([...])` / `z.literal(...)` against every emit-site code. Kept as a forward-compatibility hook for future stock routes that need an interim exemption; paths assume the standard `/api/account` + `/api/db` prefixes.
466
- - `default_error_schema_tightness` — `{ignore_statuses: [401, 403, 429], allowlist: fuz_app_stock_route_tightness_allowlist}`. Applied by `describe_standard_attack_surface_tests` when `error_schema_tightness` is omitted; pass an override config or `null` to opt out.
467
- - **Merge semantics in `describe_standard_attack_surface_tests`**: consumer-supplied `allowlist` and `ignore_statuses` are concatenated underneath the defaults (stock entries first, consumer entries last), so consumer allowlists are additive rather than replacing. Scalar fields like `min_specificity` are overwritten by the consumer. Exported as `resolve_standard_error_schema_tightness(consumer_options)` for consumers calling `assert_error_schema_tightness` directly outside the suite.
468
-
469
462
  Aggregate runners (called by the standard attack-surface suite):
470
463
 
471
464
  - `assert_surface_invariants(surface)` — runs all route-level structural assertions.
@@ -474,7 +467,12 @@ Aggregate runners (called by the standard attack-surface suite):
474
467
 
475
468
  ### `error_coverage.ts` — reachability tracking
476
469
 
477
- `ErrorCoverageCollector` tracks which declared error paths get exercised.
470
+ `ErrorCoverageCollector` tracks which declared error paths get exercised:
471
+ each code of each route's error map (`resolve_route_error_map`), one path per
472
+ (status, code), read from its definitions. `new ErrorCoverageCollector(route_error_maps?)`
473
+ takes the maps (`AppSurfaceSpec.route_error_maps`, middleware included); without
474
+ them a route's own map is read. The standard suites pass
475
+ `surface_source.route_error_maps`.
478
476
  Observations live in a `Set<string>` keyed by `"METHOD /spec-path:STATUS"` or
479
477
  `"METHOD /spec-path:STATUS:CODE"` — the two shapes coexist and a status-only
480
478
  observation satisfies the "any-code" coverage rule for all declared codes at
@@ -484,11 +482,10 @@ Methods:
484
482
 
485
483
  - `record(specs, method, path, status, code?)` — resolves concrete paths back to spec templates (e.g. `/api/accounts/abc` → `/api/accounts/:id`).
486
484
  - `assert_and_record(specs, method, path, response, code?)` — wraps `assert_response_matches_spec` and auto-extracts `body.error` from the JSON body via `response.clone()`. Pass an explicit `code` when the body was already consumed.
487
- - `uncovered(specs, options?)` — per-status rows for generic schemas, per-code rows for `z.literal` / `z.enum` schemas.
485
+ - `uncovered(specs, options?)` — one `{method, path, status, code}` row per declared code never observed.
488
486
 
489
487
  Support functions:
490
488
 
491
- - `extract_declared_error_codes(schema)` — reads the object's `error` field, Zod (`schema.shape.error`) or fuz_schema (`get_schema_entries`, any object kind under any wrappers); returns the literal value(s) for `z.literal` / `z.enum` / `literal` / `one_of`, `null` otherwise.
492
489
  - `assert_error_coverage(collector, specs, options?)` — logs `[error coverage] covered/total (N.M%)` with uncovered list; fails when `min_coverage > 0` and the ratio falls below.
493
490
  - `DEFAULT_INTEGRATION_ERROR_COVERAGE = 0.2` — conservative baseline for the standard integration/admin suites; consumers tighten as their own test coverage matures.
494
491
 
@@ -505,7 +502,7 @@ naming it.
505
502
  - `detect_format(field_schema)` — `detect_json_schema_format` over `to_field_json_schema`: the `format`, `'pattern'` for a regex, or `null`.
506
503
  - `generate_valid_value(field, field_schema)` — base-type switch producing a valid sample (UUIDs → nil UUID, strings → `'xxxxxxxxxx'`, numbers → `1`, objects → `generate_valid_object` against the field schema, so a nested refinement is satisfied too, enums → first entry, records → `{}`, a void field → `undefined`, etc.). For branded-string refinements, walks a fallback chain synthesized from the `pattern` string the JSON Schema representation exposes: fixed-length hex (`^[0-9a-f]{N}$` — blake3 / sha256 / md5 digests; `0`.repeat(N)), prefix-lengthed slug (`^<prefix>_[A-Za-z0-9_-]{N}$` — `ApiTokenId`-style ids; `<prefix>_` + `x`.repeat(N)), absolute path prefix, URL prefix, two `/`-joined segments (an `owner/name` slug). First candidate the field accepts is used.
507
504
  - `generate_valid_string_param(field, field_schema)` — a string a URL-sourced field (route param, query value) accepts: the nil UUID for a UUID field, else the first of `test_value`, the generated valid value as a string, `1`, `0`, `true`, `false`, the field's JSON Schema `default` or lower bound as a string (a preprocessed integer whose minimum is above one) and a synthesized string the field accepts; `null` when none does. The params and query case generators build their base from it.
508
- - `resolve_valid_path(path, params_schema?)` — swaps `:param` for a value the params schema accepts. Prefers `test_<name>` wherever the field schema admits it (the param name keeps failure messages readable); otherwise a UUID param takes the nil UUID and anything else is synthesized from the schema, percent-encoded. A synthesized value containing `/` is refused (it would route elsewhere) and falls back to `test_<name>`.
505
+ - `resolve_valid_path(path, params_schema?)` — swaps each whole param segment (`:name`, `:name{re}`, optional or not, read as Hono reads a template: `split_route_template` / `parse_route_param`) for a value the params schema accepts; a `:` inside a literal segment (`files:upload`) stays. Prefers `test_<name>` wherever the field schema admits it (the param name keeps failure messages readable); otherwise a UUID param takes the nil UUID and anything else is synthesized from the schema, percent-encoded. A synthesized value containing `/` is refused (it would route elsewhere) and falls back to `test_<name>`.
509
506
  - `to_route_content_type(route)` — the `Content-Type` a well-formed request to the route sends: `application/json`, or `application/octet-stream` for a `raw_body` route. Every `POST` route refuses anything else with 415 before its other gates, so every probe in the harnesses (auth, params and query fuzz, 404, data exposure, round trip) sends it, body or not.
510
507
  - `generate_valid_object(object_schema, schema) => {value, result}` — required and defaulted fields; when `schema` (refinements included) refuses those, each optional field alone in declaration order, the first that parses; failing that, the optional fields added cumulatively until it parses. Covers a `.refine()` over optional fields (at least one of, exactly one of, both of) at any depth, and, where one optional field suffices, keeps the others (an `acting` declared first) out. Returns the last `parse_any` result (`GeneratedObject`) and leaves the throw to the caller, which renders its issues with `format_issues` (`schema_issues.ts`).
511
508
  - `generate_valid_object_with_field(object_schema, schema, base, field)` — a valid object carrying `field`, built from the valid `base`: `base` itself when it carries the field; else the field joins `base`, with the optional fields `base` omits filled as `generate_valid_object` fills them (a pair rule: `scope_kind` needs `scope_id`); failing that, the field replaces `base`'s optional fields, refilled around it (exactly one of: adding `slug` drops `id`). `null` when no object the generator builds carries the field. The body a single-fault case on a field the base omits changes.
@@ -513,9 +510,9 @@ naming it.
513
510
 
514
511
  ### `integration_helpers.ts` — route lookup + body checks
515
512
 
516
- - `find_route_spec(specs, method, path)` — exact match then parameterized match (`:foo` matches any segment).
513
+ - `find_route_spec(specs, method, path)` — the first spec in list (mount) order whose method and path template match, as Hono dispatches (the hono-free `find_mounted_route`; the DEV check reads Hono's own router), `HEAD` read as `GET`, the path read as Hono reads it (pathname, percent-decoded); a template passed as the path (a segment that is `*` or starts with `:`) finds its own spec first, outranking mount order.
517
514
  - `find_auth_route(specs, suffix, method)` — suffix-ending match for REST auth routes; decouples tests from consumer prefix. `suffix` is typed as `RestAuthRouteSuffix` and throws at runtime on unknown values (only login/logout/password/verify/signup/bootstrap remain on REST).
518
- - `assert_response_matches_spec(specs, method, path, response)` — 2xx → validates against `spec.output`; non-2xx → validates against merged error schemas for that status. Non-JSON responses allowed only when no schema applies.
515
+ - `assert_response_matches_spec(specs, method, path, response, route_error_maps?)` — 2xx → validates against `spec.output`; an error status (400 and up) → `assert_error_response_declared` against the route's error map — the one in `route_error_maps` (`AppSurfaceSpec.route_error_maps`, middleware included), else the route's own: a status the map lacks throws (`Undeclared error status (S): METHOD path: …`), as does a body off its schema, with the DEV error check's exemptions (500 `internal_error`, 503 `service_unavailable`, a JSON-RPC envelope on a `jsonrpc` route). Non-JSON responses allowed only when no schema applies. The round trips and `ErrorCoverageCollector.assert_and_record` run through it.
519
516
  - `assert_no_error_info_leakage(body, context)` — rejects field-name patterns (`stack`, `trace`, `sql`, …) + value patterns (`node_modules`, stack-like `at …`, `.ts:NN`).
520
517
  - `assert_rate_limit_retry_after_header(response, body)` — `Retry-After` numeric header equals `Math.ceil(body.retry_after)`.
521
518
  - `sensitive_field_blocklist` — `['password_hash', 'token_hash']`; never in any response body.
@@ -532,12 +529,12 @@ Single-call bundle of 5 top-level groups (10 named tests + every adversarial
532
529
  case per route):
533
530
 
534
531
  1. **attack surface snapshot** — `matches committed snapshot`, `is deterministic`.
535
- 2. **attack surface structure** — `only expected public routes`, `full middleware stack on API routes`, `surface invariants`, `rpc/ws surface invariants`, `security policy`, `error schema tightness` (logs counts and asserts against `default_error_schema_tightness` by default; pass an override config or `null` via `error_schema_tightness`).
536
- 3. **adversarial HTTP auth enforcement** — `unauthenticated → 401`, `wrong role → 403` × roles, `authenticated without role → 403`, `credential-gated routes reject a disallowed credential → 403`, `correct auth passes guard`. The role blocks cover role routes the session-credentialed role apps reach (a keeper route's channel gate answers first); the credential block probes every `auth.credential_types` route on the first builtin channel its allowlist omits, using `AuthTestApps.by_credential_type` (one keeper-role app per builtin channel; `keeper` is its `daemon_token` entry).
532
+ 2. **attack surface structure** — `only expected public routes`, `full middleware stack on API routes`, `surface invariants`, `rpc/ws surface invariants`, `security policy`.
533
+ 3. **adversarial HTTP auth enforcement** — `unauthenticated → 401`, `wrong role → 403` × roles, `authenticated without role → 403`, `credential-gated routes reject a disallowed credential → 403`, `correct auth passes guard`. Every refusal is held to the route's own error map (`assert_error_schema_valid`: the status, the code at it, the body), and `correct auth passes guard`, which takes any status but the gates' from a handler on stub deps, holds a JSON error it answers to the map too (`assert_error_response_declared`). The role blocks cover role routes the session-credentialed role apps reach (a keeper route's channel gate answers first); the credential block probes every `auth.credential_types` route on the first builtin channel its allowlist omits, using `AuthTestApps.by_credential_type` (one keeper-role app per builtin channel; `keeper` is its `daemon_token` entry).
537
534
  4. **adversarial input validation** — delegated to `describe_adversarial_input`.
538
535
  5. **adversarial 404 response validation** — delegated to `describe_adversarial_404`.
539
536
 
540
- Options: `{build: () => AppSurfaceSpec, snapshot_path, expected_public_routes, expected_api_middleware, roles, api_path_prefix?, security_policy?, error_schema_tightness?, skip_routes?}`.
537
+ Options: `{build: () => AppSurfaceSpec, snapshot_path, expected_public_routes, expected_api_middleware, roles, api_path_prefix?, security_policy?, skip_routes?}`.
541
538
 
542
539
  `skip_routes` is a list of `'METHOD /path'` surface keys the three
543
540
  adversarial sub-suites drop, forwarded to each of them (it also sits on
@@ -556,7 +553,9 @@ Also exported: `describe_adversarial_auth(options)` (group 3 on its own).
556
553
  query validation failures at every route with correct-auth credentials so
557
554
  validation middleware is actually exercised (not short-circuited by 401).
558
555
  All cases expect 400 with one of `ERROR_INVALID_REQUEST_BODY` /
559
- `_INVALID_JSON_BODY` / `_INVALID_ROUTE_PARAMS` / `_INVALID_QUERY_PARAMS`.
556
+ `_INVALID_JSON_BODY` / `_INVALID_ROUTE_PARAMS` / `_INVALID_QUERY_PARAMS`, a
557
+ code the route's own error map declares at 400, and a body its schema there
558
+ accepts (`assert_error_schema_valid`).
560
559
 
561
560
  The generators live in the hono-free `adversarial_input_cases.ts`, so the
562
561
  cross-process suites reuse them:
@@ -574,14 +573,11 @@ rather than `ERROR_INVALID_JSON_BODY`.
574
573
 
575
574
  ### `adversarial_404.ts` — 404 schema conformance
576
575
 
577
- `describe_adversarial_404({build, roles})` — for every route with `params` +
578
- 404 in `error_schemas` + an extractable error code (`z.literal` or first
579
- `z.enum`, fuz_schema `literal` or first `one_of`), replaces the handler with a
580
- stub returning `{error: <code>}`, fires with nil-UUID params, asserts 404 +
581
- body matches the declared 404 schema, Zod or fuz_schema (`parse_any`). No DB needed. The code comes from `extract_404_error_code(schema)`,
582
- which reads the output-side JSON Schema of a Zod or fuz_schema schema with
583
- `unrepresentable: 'any'`, so a field JSON Schema can't say beside `error`
584
- (a transform) no longer drops the route from the suite.
576
+ `describe_adversarial_404({build, roles})` — for every route with `params` and
577
+ a 404 definition of its own in `errors`, replaces the handler with a stub
578
+ returning `{error: <code>}` (the first 404 definition's code), fires with
579
+ nil-UUID params, asserts 404, a code the route error map declares at 404, and a body its 404
580
+ accepts (`assert_error_schema_valid`, `AppSurfaceSpec.route_error_maps`). No DB needed.
585
581
 
586
582
  ### `adversarial_headers.ts` — header injection suite
587
583
 
@@ -806,7 +802,7 @@ as `'/path method_name'`, and pushed WS params as `'/path method_name params'`
806
802
 
807
803
  Two test groups:
808
804
 
809
- 1. IP rate limiting on login — fires `max_attempts + 1` requests; last should be 429 with `RateLimitError` body + valid `Retry-After` header.
805
+ 1. IP rate limiting on login — fires `max_attempts + 1` requests; last should be 429 with a `REST_RATE_LIMIT_EXCEEDED` body + valid `Retry-After` header.
810
806
  2. Per-account rate limiting on login — same username exhausts the bucket; a different username is not blocked.
811
807
 
812
808
  No bearer group — the bearer path carries no rate limiter on either spine
@@ -849,11 +845,9 @@ auth-related routes (login/logout/verify/sessions/tokens/password/signup)
849
845
  and asserts `DEFAULT_INTEGRATION_ERROR_COVERAGE` (20%). Bootstrap is
850
846
  excluded because no describe block in this suite drives it — its declared
851
847
  codes would always be uncovered. Consumer-specific routes aren't exercised
852
- here either — they don't count against the baseline. 403 authorization
853
- denials (the credential-channel gate on `/logout` + `/password`, the invite
854
- gate on `/signup`) are likewise excluded via `ignore_statuses: [403]` — they're
855
- exercised by the conformance + attack-surface suites, not this lifecycle suite.
856
- Override with
848
+ here either — they don't count against the baseline. The declared paths are
849
+ the route error maps of `surface_source`, middleware included (the origin
850
+ check's 403, the body limit's 413 and 400). Override with
857
851
  `error_coverage_min?: number` (set to `0` to skip the assertion — useful for
858
852
  minimal route sets whose declared error codes outpace the suite's
859
853
  denial-path drivers).
@@ -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"}