@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
@@ -1,29 +1,13 @@
1
1
  import './assert_dev_env.js';
2
2
  import type { RouteSpec } from '../http/route_spec.js';
3
- import type { ValidationSchema } from '../schema_issues.js';
4
- /**
5
- * Extract declared error code values from an error response schema.
6
- *
7
- * Recognizes schemas shaped like `z.object({error: z.literal(...)})` or
8
- * `z.object({error: z.enum([...])})` (incl. `looseObject`/`strictObject`),
9
- * and the `@fuzdev/fuz_schema` forms `object({error: literal(...)})` or
10
- * `object({error: one_of([...])})` (any object kind, under any wrappers —
11
- * `get_schema_entries`; the `error` entry itself read as given, as the Zod
12
- * field is). Returns the set of declared code values, or `null` if the schema
13
- * doesn't expose a literal/enum `error` field (e.g., bare `ApiError` with
14
- * `z.string()`).
15
- *
16
- * Used by coverage reporting to split a single declared status into per-code
17
- * rows when the route's error schema names specific codes.
18
- */
19
- export declare const extract_declared_error_codes: (schema: ValidationSchema) => Array<string> | null;
20
- /** Uncovered entry — either a status-level row (no `code`) or a specific-code row. */
3
+ import { type RouteErrorMap } from '../http/route_errors.js';
4
+ /** Uncovered entry — a declared code at a status of a route, never observed. */
21
5
  export interface UncoveredEntry {
22
6
  method: string;
23
7
  path: string;
24
8
  status: number;
25
- /** Declared code value missing, when the status's error schema names specific codes. */
26
- code?: string;
9
+ /** The declared code missing. */
10
+ code: string;
27
11
  }
28
12
  /** Options controlling which routes/statuses are considered for coverage. */
29
13
  export interface CoverageFilterOptions {
@@ -46,9 +30,19 @@ export interface CoverageFilterOptions {
46
30
  * requirements for the same status — i.e., if a caller records just the status,
47
31
  * all declared codes for that status are considered covered. Per-code tracking
48
32
  * is additive: callers who know the body's `error` value should pass it to get
49
- * precise per-code gap reporting on routes with literal/enum error schemas.
33
+ * precise per-code gap reporting.
50
34
  */
51
35
  export declare class ErrorCoverageCollector {
36
+ /**
37
+ * Each route's error map, keyed `METHOD path` (`AppSurfaceSpec.route_error_maps`),
38
+ * which the declared paths and the response checks read; without one, a
39
+ * route's own map without middleware.
40
+ */
41
+ readonly route_error_maps: ReadonlyMap<string, RouteErrorMap> | null;
42
+ /**
43
+ * @param route_error_maps - each route's error map, keyed `METHOD path` (`AppSurfaceSpec.route_error_maps`)
44
+ */
45
+ constructor(route_error_maps?: ReadonlyMap<string, RouteErrorMap> | null);
52
46
  /**
53
47
  * Observed keys: `"METHOD /spec-path:STATUS"` or `"METHOD /spec-path:STATUS:CODE"`.
54
48
  *
@@ -64,8 +58,7 @@ export declare class ErrorCoverageCollector {
64
58
  * it is stored alongside the status for per-code coverage tracking.
65
59
  *
66
60
  * @param path - request path (may be concrete)
67
- * @param code - observed body `error` code (pass when the route's error
68
- * schema declares specific codes via `z.literal` or `z.enum`)
61
+ * @param code - observed body `error` code, for per-code coverage
69
62
  * @mutates `this.observed` - adds the resolved `"METHOD /spec-path:STATUS"`
70
63
  * key (and the `:CODE` variant when `code` is provided).
71
64
  */
@@ -91,11 +84,10 @@ export declare class ErrorCoverageCollector {
91
84
  /**
92
85
  * Find declared error paths that were never observed.
93
86
  *
94
- * Computes the declared set from `merge_error_schemas` for each route spec.
95
- * For statuses whose error schema names specific codes (via `z.literal` or
96
- * `z.enum`), reports per-code rows; otherwise reports one row per status.
97
- * A status-only observation (no code) satisfies all declared codes for that
98
- * status — the "any-code" rule.
87
+ * Computes the declared set from each route's error map
88
+ * (`resolve_route_error_map`, `this.route_error_maps`): one row per declared code
89
+ * at each status. A status-only observation (no code) satisfies all
90
+ * declared codes for that status — the "any-code" rule.
99
91
  */
100
92
  uncovered(route_specs: Array<RouteSpec>, options?: CoverageFilterOptions): Array<UncoveredEntry>;
101
93
  }
@@ -113,12 +105,10 @@ export interface ErrorCoverageOptions extends CoverageFilterOptions {
113
105
  /**
114
106
  * Assert error coverage meets a minimum threshold.
115
107
  *
116
- * Computes the ratio of exercised error paths to total declared error paths.
117
- * For routes whose status error schema names specific codes (`z.literal` or
118
- * `z.enum`), each declared code counts as one coverage path; for schemas
119
- * without declared codes (`ApiError`/`z.string()`), the status counts as one
120
- * path. A status-only observation covers all declared codes for that status
121
- * (the "any-code" rule).
108
+ * Computes the ratio of exercised error paths to total declared error paths,
109
+ * each declared code at each status of a route's error map
110
+ * (`collector.route_error_maps`) one path. A status-only observation covers all
111
+ * declared codes for that status (the "any-code" rule).
122
112
  *
123
113
  * When `min_coverage` is 0 (default), logs coverage info without failing.
124
114
  * When > 0, fails if coverage is below the threshold.
@@ -1 +1 @@
1
- {"version":3,"file":"error_coverage.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/error_coverage.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAoB7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,4BAA4B,GAAI,QAAQ,gBAAgB,KAAG,KAAK,CAAC,MAAM,CAAC,GAAG,IAoBvF,CAAC;AAEF,sFAAsF;AACtF,MAAM,WAAW,cAAc;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,wFAAwF;IACxF,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,6EAA6E;AAC7E,MAAM,WAAW,qBAAqB;IACrC,kDAAkD;IAClD,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,iCAAiC;IACjC,eAAe,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAChC;AAqDD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,sBAAsB;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAa;IAE3C;;;;;;;;;;;;OAYG;IACH,MAAM,CACL,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,EAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,GACX,IAAI;IAUP;;;;;;;;;;;;;;;;OAgBG;IACG,iBAAiB,CACtB,WAAW,EAAE,KAAK,CAAC,SAAS,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racking.
4
4
  *
5
- * Tracks which declared error statuses (and specific error codes) are
6
- * actually exercised in tests. `ErrorCoverageCollector` records status
7
- * codes (optionally with body `error` codes) observed during test runs,
8
- * then `assert_error_coverage` compares against declared error schemas
9
- * to find uncovered error paths — reporting per-code when the declared
10
- * schema is a literal or enum, per-status otherwise.
5
+ * Tracks which declared error codes are actually exercised in tests.
6
+ * `ErrorCoverageCollector` records status codes (optionally with body
7
+ * `error` codes) observed during test runs, then `assert_error_coverage`
8
+ * compares against each route's error map (`resolve_route_error_map`) to find
9
+ * uncovered error paths — one per declared code at each status, read from
10
+ * the map's definitions.
11
11
  *
12
12
  * @module
13
13
  */
14
- import { z } from 'zod';
15
14
  import { assert } from 'vitest';
16
- import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
17
- import { get_schema_entries } from '@fuzdev/fuz_schema/introspect.ts';
18
- import { merge_error_schemas } from '../http/schema_helpers.js';
15
+ import { format_route_key } from '../http/surface_query.js';
16
+ import { get_route_error_map } from '../http/route_errors.js';
19
17
  import { find_route_spec, assert_response_matches_spec } from './integration_helpers.js';
20
- /**
21
- * Extract declared error code values from an error response schema.
22
- *
23
- * Recognizes schemas shaped like `z.object({error: z.literal(...)})` or
24
- * `z.object({error: z.enum([...])})` (incl. `looseObject`/`strictObject`),
25
- * and the `@fuzdev/fuz_schema` forms `object({error: literal(...)})` or
26
- * `object({error: one_of([...])})` (any object kind, under any wrappers —
27
- * `get_schema_entries`; the `error` entry itself read as given, as the Zod
28
- * field is). Returns the set of declared code values, or `null` if the schema
29
- * doesn't expose a literal/enum `error` field (e.g., bare `ApiError` with
30
- * `z.string()`).
31
- *
32
- * Used by coverage reporting to split a single declared status into per-code
33
- * rows when the route's error schema names specific codes.
34
- */
35
- export const extract_declared_error_codes = (schema) => {
36
- if (is_schema(schema)) {
37
- const error_field = get_schema_entries(schema)?.error;
38
- if (!error_field)
39
- return null;
40
- if (error_field.kind === 'literal')
41
- return [String(error_field.def)];
42
- if (error_field.kind === 'one_of') {
43
- return error_field.def.map(String);
44
- }
45
- return null;
46
- }
47
- if (!(schema instanceof z.ZodObject))
48
- return null;
49
- const error_field = schema.shape.error;
50
- if (!error_field)
51
- return null;
52
- if (error_field instanceof z.ZodLiteral) {
53
- return [...error_field.values].map(String);
54
- }
55
- if (error_field instanceof z.ZodEnum) {
56
- return error_field.options.map(String);
57
- }
58
- return null;
59
- };
60
18
  /**
61
19
  * Shared walk over declared error paths.
62
20
  *
63
21
  * Single source of truth for the route → status → code traversal used by
64
22
  * both `uncovered()` and `assert_error_coverage`. Yields one entry per
65
- * declared coverage path with a `covered` flag, applying the "any-code"
66
- * rule (status-only observation covers all declared codes).
23
+ * declared (status, code) of each route's error map, read from its
24
+ * definitions, with a `covered` flag, applying the "any-code" rule
25
+ * (status-only observation covers all declared codes).
67
26
  */
68
27
  const walk_coverage = (collector, route_specs, options) => {
69
28
  const ignore_routes = new Set(options?.ignore_routes);
70
29
  const ignore_statuses = new Set(options?.ignore_statuses);
71
30
  const entries = [];
72
31
  for (const spec of route_specs) {
73
- const route_key = `${spec.method} ${spec.path}`;
32
+ const route_key = format_route_key(spec);
74
33
  if (ignore_routes.has(route_key))
75
34
  continue;
76
- const merged = merge_error_schemas(spec);
77
- if (!merged)
78
- continue;
79
- for (const status_str of Object.keys(merged)) {
80
- const status = Number(status_str);
35
+ // a code with two shapes at one status is one path
36
+ const seen = new Set();
37
+ for (const { status, code } of get_route_error_map(collector.route_error_maps, spec).defs) {
81
38
  if (ignore_statuses.has(status))
82
39
  continue;
83
- const error_schema = merged[status];
84
- if (!error_schema)
85
- continue;
86
40
  const status_key = `${spec.method} ${spec.path}:${status}`;
87
- const status_observed = collector.observed.has(status_key);
88
- const codes = extract_declared_error_codes(error_schema);
89
- if (codes && codes.length > 0) {
90
- for (const code of codes) {
91
- const covered = status_observed || collector.observed.has(`${status_key}:${code}`);
92
- entries.push({ method: spec.method, path: spec.path, status, code, covered });
93
- }
94
- }
95
- else {
96
- entries.push({ method: spec.method, path: spec.path, status, covered: status_observed });
97
- }
41
+ const code_key = `${status_key}:${code}`;
42
+ if (seen.has(code_key))
43
+ continue;
44
+ seen.add(code_key);
45
+ const covered = collector.observed.has(status_key) || collector.observed.has(code_key);
46
+ entries.push({ method: spec.method, path: spec.path, status, code, covered });
98
47
  }
99
48
  }
100
49
  return entries;
@@ -113,9 +62,21 @@ const walk_coverage = (collector, route_specs, options) => {
113
62
  * requirements for the same status — i.e., if a caller records just the status,
114
63
  * all declared codes for that status are considered covered. Per-code tracking
115
64
  * is additive: callers who know the body's `error` value should pass it to get
116
- * precise per-code gap reporting on routes with literal/enum error schemas.
65
+ * precise per-code gap reporting.
117
66
  */
118
67
  export class ErrorCoverageCollector {
68
+ /**
69
+ * Each route's error map, keyed `METHOD path` (`AppSurfaceSpec.route_error_maps`),
70
+ * which the declared paths and the response checks read; without one, a
71
+ * route's own map without middleware.
72
+ */
73
+ route_error_maps;
74
+ /**
75
+ * @param route_error_maps - each route's error map, keyed `METHOD path` (`AppSurfaceSpec.route_error_maps`)
76
+ */
77
+ constructor(route_error_maps) {
78
+ this.route_error_maps = route_error_maps ?? null;
79
+ }
119
80
  /**
120
81
  * Observed keys: `"METHOD /spec-path:STATUS"` or `"METHOD /spec-path:STATUS:CODE"`.
121
82
  *
@@ -131,8 +92,7 @@ export class ErrorCoverageCollector {
131
92
  * it is stored alongside the status for per-code coverage tracking.
132
93
  *
133
94
  * @param path - request path (may be concrete)
134
- * @param code - observed body `error` code (pass when the route's error
135
- * schema declares specific codes via `z.literal` or `z.enum`)
95
+ * @param code - observed body `error` code, for per-code coverage
136
96
  * @mutates `this.observed` - adds the resolved `"METHOD /spec-path:STATUS"`
137
97
  * key (and the `:CODE` variant when `code` is provided).
138
98
  */
@@ -163,7 +123,7 @@ export class ErrorCoverageCollector {
163
123
  * schemas (propagated from `assert_response_matches_spec`).
164
124
  */
165
125
  async assert_and_record(route_specs, method, path, response, code) {
166
- await assert_response_matches_spec(route_specs, method, path, response);
126
+ await assert_response_matches_spec(route_specs, method, path, response, this.route_error_maps);
167
127
  let resolved_code = code;
168
128
  if (resolved_code === undefined && !response.ok && !response.bodyUsed) {
169
129
  try {
@@ -181,16 +141,15 @@ export class ErrorCoverageCollector {
181
141
  /**
182
142
  * Find declared error paths that were never observed.
183
143
  *
184
- * Computes the declared set from `merge_error_schemas` for each route spec.
185
- * For statuses whose error schema names specific codes (via `z.literal` or
186
- * `z.enum`), reports per-code rows; otherwise reports one row per status.
187
- * A status-only observation (no code) satisfies all declared codes for that
188
- * status — the "any-code" rule.
144
+ * Computes the declared set from each route's error map
145
+ * (`resolve_route_error_map`, `this.route_error_maps`): one row per declared code
146
+ * at each status. A status-only observation (no code) satisfies all
147
+ * declared codes for that status — the "any-code" rule.
189
148
  */
190
149
  uncovered(route_specs, options) {
191
150
  return walk_coverage(this, route_specs, options)
192
151
  .filter((entry) => !entry.covered)
193
- .map(({ method, path, status, code }) => ({ method, path, status, ...(code && { code }) }));
152
+ .map(({ method, path, status, code }) => ({ method, path, status, code }));
194
153
  }
195
154
  }
196
155
  /**
@@ -205,16 +164,14 @@ export const DEFAULT_INTEGRATION_ERROR_COVERAGE = 0.2;
205
164
  * Uses `status (code)` — spaces around the code make `:` unambiguous as
206
165
  * the route_key / status separator.
207
166
  */
208
- const format_uncovered = (entry) => `${entry.method} ${entry.path} → ${entry.status}${entry.code ? ` (${entry.code})` : ''}`;
167
+ const format_uncovered = (entry) => `${entry.method} ${entry.path} → ${entry.status} (${entry.code})`;
209
168
  /**
210
169
  * Assert error coverage meets a minimum threshold.
211
170
  *
212
- * Computes the ratio of exercised error paths to total declared error paths.
213
- * For routes whose status error schema names specific codes (`z.literal` or
214
- * `z.enum`), each declared code counts as one coverage path; for schemas
215
- * without declared codes (`ApiError`/`z.string()`), the status counts as one
216
- * path. A status-only observation covers all declared codes for that status
217
- * (the "any-code" rule).
171
+ * Computes the ratio of exercised error paths to total declared error paths,
172
+ * each declared code at each status of a route's error map
173
+ * (`collector.route_error_maps`) one path. A status-only observation covers all
174
+ * declared codes for that status (the "any-code" rule).
218
175
  *
219
176
  * When `min_coverage` is 0 (default), logs coverage info without failing.
220
177
  * When > 0, fails if coverage is below the threshold.
@@ -1 +1 @@
1
- {"version":3,"file":"integration.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/integration.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAuB7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAMhE,OAAO,EAKN,KAAK,uBAAuB,EAC5B,MAAM,kBAAkB,CAAC;AAkB1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAW,KAAK,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAKpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAK1D;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC9C;;;;OAIG;IACH,UAAU,EAAE,SAAS,CAAC;IACtB;;;;;;;;;OASG;IACH,cAAc,EAAE,cAAc,CAAC;IAC/B,kEAAkE;IAClE,YAAY,EAAE,mBAAmB,CAAC;IAClC;;;;OAIG;IACH,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IACxC;;;;;;;;;;;;OAYG;IACH,aAAa,EAAE,uBAAuB,CAAC;IACvC;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,mCAAmC,GAC/C,SAAS,8BAA8B,KACrC,IA28CF,CAAC"}
1
+ {"version":3,"file":"integration.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/integration.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAuB7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAMhE,OAAO,EAKN,KAAK,uBAAuB,EAC5B,MAAM,kBAAkB,CAAC;AAkB1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAW,KAAK,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAKpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAK1D;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC9C;;;;OAIG;IACH,UAAU,EAAE,SAAS,CAAC;IACtB;;;;;;;;;OASG;IACH,cAAc,EAAE,cAAc,CAAC;IAC/B,kEAAkE;IAClE,YAAY,EAAE,mBAAmB,CAAC;IAClC;;;;OAIG;IACH,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IACxC;;;;;;;;;;;;OAYG;IACH,aAAa,EAAE,uBAAuB,CAAC;IACvC;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,mCAAmC,GAC/C,SAAS,8BAA8B,KACrC,IAq9CF,CAAC"}
@@ -74,7 +74,7 @@ export const describe_standard_integration_tests = (options) => {
74
74
  describe('standard_integration', () => {
75
75
  const { cookie_name } = options.session_options;
76
76
  // Error coverage tracking across test groups
77
- const error_collector = new ErrorCoverageCollector();
77
+ const error_collector = new ErrorCoverageCollector(options.surface_source.route_error_maps);
78
78
  // the auth routes this suite drives: login / logout / password, signup
79
79
  // (when wired), and the shared RPC endpoint — admin-role routes belong to
80
80
  // the admin suite
@@ -98,15 +98,7 @@ export const describe_standard_integration_tests = (options) => {
98
98
  // the admin suite instead.
99
99
  const auth_routes = route_specs.filter(is_suite_auth_route);
100
100
  assert_error_coverage(error_collector, auth_routes.length > 0 ? auth_routes : route_specs, {
101
- min_coverage: options.error_coverage_min ?? DEFAULT_INTEGRATION_ERROR_COVERAGE,
102
- // Authorization denials (403) on these scoped auth routes — the
103
- // credential-channel gate on /logout + /password, the invite gate on
104
- // /signup — are exercised by the conformance + attack-surface suites,
105
- // not this lifecycle suite. Drop 403 from this collector's denominator
106
- // (same spirit as the [401, 403, 429] ignore in the attack-surface
107
- // tightness defaults); otherwise #10 adding /logout's 403 to the spine
108
- // surface tips the ratio under threshold here though the gate is tested.
109
- ignore_statuses: [403]
101
+ min_coverage: options.error_coverage_min ?? DEFAULT_INTEGRATION_ERROR_COVERAGE
110
102
  });
111
103
  });
112
104
  // --- 1. Login/logout lifecycle ---
@@ -868,7 +860,7 @@ export const describe_standard_integration_tests = (options) => {
868
860
  })
869
861
  });
870
862
  assert.strictEqual(res.status, 401);
871
- await assert_response_matches_spec(route_specs, 'POST', login_route.path, res);
863
+ await assert_response_matches_spec(route_specs, 'POST', login_route.path, res, options.surface_source.route_error_maps);
872
864
  });
873
865
  test('POST /logout 200 response matches output schema', async () => {
874
866
  const fixture = await options.setup_test();
@@ -880,7 +872,7 @@ export const describe_standard_integration_tests = (options) => {
880
872
  body: JSON.stringify({})
881
873
  });
882
874
  assert.strictEqual(res.status, 200);
883
- await assert_response_matches_spec(route_specs, 'POST', logout_route.path, res);
875
+ await assert_response_matches_spec(route_specs, 'POST', logout_route.path, res, options.surface_source.route_error_maps);
884
876
  });
885
877
  test('POST /logout 401 response matches declared error schema', async () => {
886
878
  const fixture = await options.setup_test();
@@ -894,7 +886,7 @@ export const describe_standard_integration_tests = (options) => {
894
886
  body: JSON.stringify({})
895
887
  });
896
888
  assert.strictEqual(res.status, 401);
897
- await assert_response_matches_spec(route_specs, 'POST', logout_route.path, res);
889
+ await assert_response_matches_spec(route_specs, 'POST', logout_route.path, res, options.surface_source.route_error_maps);
898
890
  });
899
891
  });
900
892
  // Rate-limit behavior is covered end-to-end by
@@ -1,13 +1,22 @@
1
1
  import './assert_dev_env.js';
2
2
  import type { RouteSpec, RouteMethod } from '../http/route_spec.js';
3
+ import { type RouteErrorMap } from '../http/route_errors.js';
3
4
  import { type RouteAuth } from '../http/auth_shape.js';
4
5
  import type { TestAccount } from './app_server.js';
5
6
  /**
6
- * Find a route spec matching the given method and path.
7
+ * Find the route spec a request reaches: the first in list (mount) order
8
+ * whose method and path template match it, `HEAD` read as `GET` — the order
9
+ * Hono dispatches by, which the DEV error check reads through Hono's own
10
+ * router (`create_route_lookup`). This lookup is hono-free
11
+ * (`find_mounted_route`), pinned against Hono by the route-lookup tests. The
12
+ * path is read as Hono reads it: its pathname, percent-decoded.
7
13
  *
8
- * Supports both exact matches and parameterized paths (`:param` segments).
14
+ * A path template passed as the path (`/api/things/:id`, a segment that is
15
+ * `*` or starts with `:`) finds its own spec first, outranking mount order.
9
16
  *
10
- * @param path - request path (exact or with concrete param values)
17
+ * @param specs - the route specs, in mount order
18
+ * @param method - the request method
19
+ * @param path - request path, concrete or a route's own template
11
20
  */
12
21
  export declare const find_route_spec: (specs: Array<RouteSpec>, method: string, path: string) => RouteSpec | undefined;
13
22
  /**
@@ -33,14 +42,33 @@ export declare const find_auth_route: (specs: Array<RouteSpec>, suffix: RestAuth
33
42
  /**
34
43
  * Validate a response body against the route spec's declared schemas.
35
44
  *
36
- * For 2xx responses, validates against `spec.output`.
37
- * For error responses, validates against the merged error schema for that status code.
45
+ * For 2xx responses, validates against `spec.output`. For an error response
46
+ * (400 and up), checks it against the route's error map
47
+ * (`resolve_route_error_map`) — the one in `route_error_maps`, an
48
+ * `AppSurfaceSpec`'s, built with the app's middleware, or without one the
49
+ * route's own — through `assert_error_response_declared`, by the rule the DEV
50
+ * error check runs (`check_route_error`): the status must be
51
+ * declared and the body must parse against it. A 500 `internal_error` and a
52
+ * 503 `service_unavailable` are always accepted, and on a `jsonrpc` route (the
53
+ * RPC endpoint's) a JSON-RPC error envelope is not a REST error body; on any
54
+ * other route it is checked like any error body.
38
55
  *
39
- * @throws Error if no route spec matches `method` + `path`, if the response
40
- * body fails to parse against the declared output / error schema, or if the
41
- * response is non-JSON despite a declared schema for that status.
56
+ * The route is the one `find_route_spec` finds, the request's as Hono
57
+ * dispatches it. A failure reads as the DEV check logs it
58
+ * (`format_route_error_check`), then `: ` and the issues or the body as JSON.
59
+ *
60
+ * Only a JSON response, by its `Content-Type` (`is_json_response`, the DEV
61
+ * check's gate), has a body to check. A non-JSON response passes only where
62
+ * no schema applies: a 2xx on a route with a null output, or an error status
63
+ * the map doesn't declare.
64
+ *
65
+ * @param route_error_maps - each route's error map, keyed `METHOD path` (`AppSurfaceSpec.route_error_maps`)
66
+ * @throws Error if no route spec matches `method` + `path`, if the body fails
67
+ * its output schema, if a JSON error is at a status the route's map lacks or
68
+ * off its schema, or if the response is non-JSON despite a declared schema
69
+ * for its status.
42
70
  */
43
- export declare const assert_response_matches_spec: (route_specs: Array<RouteSpec>, method: string, path: string, response: Response) => Promise<void>;
71
+ export declare const assert_response_matches_spec: (route_specs: Array<RouteSpec>, method: string, path: string, response: Response, route_error_maps?: ReadonlyMap<string, RouteErrorMap> | null) => Promise<void>;
44
72
  /**
45
73
  * Assert that an error response contains no leaky field values.
46
74
  *
@@ -1 +1 @@
1
- {"version":3,"file":"integration_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/integration_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAU7B,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC3B,OAAO,KAAK,CAAC,SAAS,CAAC,EACvB,QAAQ,MAAM,EACd,MAAM,MAAM,KACV,SAAS,GAAG,SAad,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,iFAO3B,CAAC;AACX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5E;;;;;;;;;;GAUG;AACH,eAAO,MAAM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AI,QAAQ,MAAM,EAAE,QAAQ,OAAO,KAAG,OACQ,CAAC"}
@@ -5,34 +5,64 @@ import './assert_dev_env.js';
5
5
  * @module
6
6
  */
7
7
  import { assert } from 'vitest';
8
- import { is_null_schema, merge_error_schemas } from '../http/schema_helpers.js';
8
+ import { is_null_schema } from '../http/schema_helpers.js';
9
+ import { get_route_error_map } from '../http/route_errors.js';
9
10
  import { is_public_auth } from '../http/auth_shape.js';
10
11
  import { ERROR_AUTHENTICATION_REQUIRED } from '../http/error_schemas.js';
11
12
  import { ROLE_ADMIN } from '../auth/role_schema.js';
12
13
  import { create_test_request_headers } from './test_origin.js';
13
14
  import { parse_any } from '../schema_issues.js';
15
+ import { find_mounted_route, is_json_response, to_mounted_routes } from '../http/route_error_check.js';
16
+ import { assert_error_response_declared } from './assertions.js';
17
+ /** Each spec list's compiled routes, so a list is compiled once. */
18
+ const mounted_routes_cache = new WeakMap();
14
19
  /**
15
- * Find a route spec matching the given method and path.
20
+ * A request path as Hono reads it: the URL's pathname (a query string
21
+ * dropped, `.` and `..` segments resolved), percent-decoded by `decodeURI`
22
+ * with `%25` kept, or the raw path when decoding fails.
23
+ */
24
+ const to_hono_path = (path) => {
25
+ let pathname = new URL(path, 'http://localhost').pathname;
26
+ if (pathname.includes('%')) {
27
+ try {
28
+ pathname = decodeURI(pathname.replaceAll('%25', '%2525'));
29
+ }
30
+ catch {
31
+ // a malformed escape: Hono matches the raw path
32
+ }
33
+ }
34
+ return pathname;
35
+ };
36
+ /**
37
+ * Find the route spec a request reaches: the first in list (mount) order
38
+ * whose method and path template match it, `HEAD` read as `GET` — the order
39
+ * Hono dispatches by, which the DEV error check reads through Hono's own
40
+ * router (`create_route_lookup`). This lookup is hono-free
41
+ * (`find_mounted_route`), pinned against Hono by the route-lookup tests. The
42
+ * path is read as Hono reads it: its pathname, percent-decoded.
16
43
  *
17
- * Supports both exact matches and parameterized paths (`:param` segments).
44
+ * A path template passed as the path (`/api/things/:id`, a segment that is
45
+ * `*` or starts with `:`) finds its own spec first, outranking mount order.
18
46
  *
19
- * @param path - request path (exact or with concrete param values)
47
+ * @param specs - the route specs, in mount order
48
+ * @param method - the request method
49
+ * @param path - request path, concrete or a route's own template
20
50
  */
21
51
  export const find_route_spec = (specs, method, path) => {
22
- // exact match first
23
- const exact = specs.find((s) => s.method === method && s.path === path);
24
- if (exact)
25
- return exact;
26
- // parameterized match — `:param` segments match any value
27
- return specs.find((s) => {
28
- if (s.method !== method)
29
- return false;
30
- const spec_parts = s.path.split('/');
31
- const path_parts = path.split('/');
32
- if (spec_parts.length !== path_parts.length)
33
- return false;
34
- return spec_parts.every((sp, i) => sp.startsWith(':') || sp === path_parts[i]);
35
- });
52
+ // a template names its own spec; only a whole param or wildcard segment
53
+ // makes one, as a concrete path can hold a `:` mid-segment
54
+ if (path.split('/').some((segment) => segment === '*' || segment.startsWith(':'))) {
55
+ const read_method = method === 'HEAD' ? 'GET' : method;
56
+ const own = specs.find((s) => s.method === read_method && s.path === path);
57
+ if (own)
58
+ return own;
59
+ }
60
+ let routes = mounted_routes_cache.get(specs);
61
+ if (!routes) {
62
+ routes = to_mounted_routes(specs, (spec) => spec);
63
+ mounted_routes_cache.set(specs, routes);
64
+ }
65
+ return find_mounted_route(routes, method, to_hono_path(path));
36
66
  };
37
67
  /**
38
68
  * REST auth route suffixes on the account/bootstrap surface — the only
@@ -68,24 +98,50 @@ export const find_auth_route = (specs, suffix, method) => {
68
98
  /**
69
99
  * Validate a response body against the route spec's declared schemas.
70
100
  *
71
- * For 2xx responses, validates against `spec.output`.
72
- * For error responses, validates against the merged error schema for that status code.
101
+ * For 2xx responses, validates against `spec.output`. For an error response
102
+ * (400 and up), checks it against the route's error map
103
+ * (`resolve_route_error_map`) — the one in `route_error_maps`, an
104
+ * `AppSurfaceSpec`'s, built with the app's middleware, or without one the
105
+ * route's own — through `assert_error_response_declared`, by the rule the DEV
106
+ * error check runs (`check_route_error`): the status must be
107
+ * declared and the body must parse against it. A 500 `internal_error` and a
108
+ * 503 `service_unavailable` are always accepted, and on a `jsonrpc` route (the
109
+ * RPC endpoint's) a JSON-RPC error envelope is not a REST error body; on any
110
+ * other route it is checked like any error body.
111
+ *
112
+ * The route is the one `find_route_spec` finds, the request's as Hono
113
+ * dispatches it. A failure reads as the DEV check logs it
114
+ * (`format_route_error_check`), then `: ` and the issues or the body as JSON.
73
115
  *
74
- * @throws Error if no route spec matches `method` + `path`, if the response
75
- * body fails to parse against the declared output / error schema, or if the
76
- * response is non-JSON despite a declared schema for that status.
116
+ * Only a JSON response, by its `Content-Type` (`is_json_response`, the DEV
117
+ * check's gate), has a body to check. A non-JSON response passes only where
118
+ * no schema applies: a 2xx on a route with a null output, or an error status
119
+ * the map doesn't declare.
120
+ *
121
+ * @param route_error_maps - each route's error map, keyed `METHOD path` (`AppSurfaceSpec.route_error_maps`)
122
+ * @throws Error if no route spec matches `method` + `path`, if the body fails
123
+ * its output schema, if a JSON error is at a status the route's map lacks or
124
+ * off its schema, or if the response is non-JSON despite a declared schema
125
+ * for its status.
77
126
  */
78
- export const assert_response_matches_spec = async (route_specs, method, path, response) => {
127
+ export const assert_response_matches_spec = async (route_specs, method, path, response, route_error_maps) => {
79
128
  const spec = find_route_spec(route_specs, method, path);
80
129
  if (!spec) {
81
130
  throw new Error(`No route spec found for ${method} ${path}`);
82
131
  }
83
- const cloned = response.clone();
132
+ // the DEV error check's gate: only a JSON response has a body to check
84
133
  let body;
85
- try {
86
- body = await cloned.json();
134
+ let parsed = false;
135
+ if (is_json_response(response)) {
136
+ try {
137
+ body = await response.clone().json();
138
+ parsed = true;
139
+ }
140
+ catch {
141
+ // a body claiming JSON that isn't — read as non-JSON below
142
+ }
87
143
  }
88
- catch {
144
+ if (!parsed) {
89
145
  // Non-JSON response — only acceptable when no schema applies.
90
146
  // If the spec declares an output or error schema for this status,
91
147
  // getting non-JSON is a real bug.
@@ -93,8 +149,7 @@ export const assert_response_matches_spec = async (route_specs, method, path, re
93
149
  throw new Error(`${method} ${path} (${response.status}) returned non-JSON but has output schema`);
94
150
  }
95
151
  if (!response.ok) {
96
- const merged = merge_error_schemas(spec);
97
- if (merged?.[response.status]) {
152
+ if (get_route_error_map(route_error_maps, spec).schemas[response.status]) {
98
153
  throw new Error(`${method} ${path} (${response.status}) returned non-JSON but has error schema for status ${response.status}`);
99
154
  }
100
155
  }
@@ -107,16 +162,7 @@ export const assert_response_matches_spec = async (route_specs, method, path, re
107
162
  }
108
163
  }
109
164
  else {
110
- const merged = merge_error_schemas(spec);
111
- if (merged) {
112
- const status_schema = merged[response.status];
113
- if (status_schema) {
114
- const result = parse_any(status_schema, body);
115
- if (!result.ok) {
116
- throw new Error(`Error schema mismatch for ${method} ${path} (${response.status}): ${JSON.stringify(result.issues)}`);
117
- }
118
- }
119
- }
165
+ await assert_error_response_declared(get_route_error_map(route_error_maps, spec), spec.jsonrpc ?? false, response, `${method} ${path}`);
120
166
  }
121
167
  };
122
168
  /** Fields in error responses that indicate information leakage. */