@fuzdev/fuz_app 0.156.0 → 0.158.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 (50) hide show
  1. package/dist/actions/CLAUDE.md +1 -0
  2. package/dist/actions/compile_action_registry.d.ts +5 -1
  3. package/dist/actions/compile_action_registry.d.ts.map +1 -1
  4. package/dist/actions/compile_action_registry.js +8 -1
  5. package/dist/auth/CLAUDE.md +2 -1
  6. package/dist/auth/actor_lookup_action_specs.d.ts +184 -40
  7. package/dist/auth/actor_lookup_action_specs.d.ts.map +1 -1
  8. package/dist/auth/actor_lookup_action_specs.js +16 -14
  9. package/dist/auth/actor_search_action_specs.d.ts +180 -40
  10. package/dist/auth/actor_search_action_specs.d.ts.map +1 -1
  11. package/dist/auth/actor_search_action_specs.js +12 -15
  12. package/dist/http/CLAUDE.md +26 -11
  13. package/dist/http/auth_shape.d.ts +5 -8
  14. package/dist/http/auth_shape.d.ts.map +1 -1
  15. package/dist/http/auth_shape.js +5 -8
  16. package/dist/http/error_schemas.d.ts +12 -4
  17. package/dist/http/error_schemas.d.ts.map +1 -1
  18. package/dist/http/route_spec.d.ts +38 -18
  19. package/dist/http/route_spec.d.ts.map +1 -1
  20. package/dist/http/route_spec.js +60 -21
  21. package/dist/http/schema_helpers.d.ts +24 -7
  22. package/dist/http/schema_helpers.d.ts.map +1 -1
  23. package/dist/http/schema_helpers.js +34 -4
  24. package/dist/http/surface.d.ts +2 -0
  25. package/dist/http/surface.d.ts.map +1 -1
  26. package/dist/http/surface.js +13 -5
  27. package/dist/primitive_schemas.d.ts +10 -6
  28. package/dist/primitive_schemas.d.ts.map +1 -1
  29. package/dist/primitive_schemas.js +20 -6
  30. package/dist/primitive_schemas_fuz.d.ts +22 -9
  31. package/dist/primitive_schemas_fuz.d.ts.map +1 -1
  32. package/dist/primitive_schemas_fuz.js +25 -9
  33. package/dist/schema_issues.d.ts +11 -0
  34. package/dist/schema_issues.d.ts.map +1 -1
  35. package/dist/schema_issues.js +15 -0
  36. package/dist/testing/CLAUDE.md +6 -6
  37. package/dist/testing/admin_integration.d.ts.map +1 -1
  38. package/dist/testing/admin_integration.js +3 -2
  39. package/dist/testing/adversarial_404.d.ts +2 -2
  40. package/dist/testing/adversarial_404.d.ts.map +1 -1
  41. package/dist/testing/adversarial_404.js +8 -5
  42. package/dist/testing/adversarial_input.js +1 -1
  43. package/dist/testing/assertions.d.ts +6 -5
  44. package/dist/testing/assertions.d.ts.map +1 -1
  45. package/dist/testing/assertions.js +9 -4
  46. package/dist/testing/error_coverage.d.ts +9 -17
  47. package/dist/testing/error_coverage.d.ts.map +1 -1
  48. package/dist/testing/error_coverage.js +20 -3
  49. package/dist/testing/integration_helpers.js +3 -3
  50. package/package.json +1 -1
@@ -182,15 +182,29 @@ export const Email = z
182
182
  });
183
183
  /** Returns a new random (v4) `Uuid`. */
184
184
  export const create_uuid = () => crypto.randomUUID();
185
+ /**
186
+ * The UUID grammar of RFC 9562, in either case: five groups of hex digits,
187
+ * 8-4-4-4-12, with a version from 1 to 8 and the RFC's variant, or the nil or
188
+ * the max UUID. It is `z.uuid()`'s own but for the max UUID, which `z.uuid()`
189
+ * spells in lowercase only, where RFC 9562 §4 reads a UUID case-insensitively.
190
+ * The same source as the pattern fuz_schema's `uuid` renders to JSON Schema,
191
+ * which a test holds it to, and the grammar of the Rust spine's
192
+ * `is_valid_uuid`.
193
+ */
194
+ const UUID_REGEX = /^(?:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|[fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})$/;
185
195
  /**
186
196
  * Branded UUID schema. Accepts either case and outputs lowercase — the form
187
197
  * Postgres renders a `uuid` in and every id the server mints — so a parsed id
188
198
  * compares equal to the same id read back from the database. The Rust spine
189
- * canonicalizes the same way. One exception: `z.uuid()` takes the max UUID
190
- * (`ffffffff-ffff-ffff-ffff-ffffffffffff`) only in lowercase, and
191
- * `.toLowerCase()` runs after the check, so the uppercase max is refused,
192
- * where the fuz_schema twin in `primitive_schemas_fuz.ts` and the Rust spine
193
- * accept it.
199
+ * canonicalizes the same way, and its grammar is this one, the fuz_schema
200
+ * twin's in `primitive_schemas_fuz.ts`: `z.uuid()` with the max UUID taken in
201
+ * any case. Issues and JSON Schema keep `format: 'uuid'`; only the `pattern`
202
+ * differs from a bare `z.uuid()`'s, rendered or on a Zod issue (the wire
203
+ * issue drops it).
204
+ *
205
+ * `pattern` is a `$ZodUUIDDef` field that `z.uuid()` honors (its default
206
+ * applies only when none is given) but whose public params type omits it,
207
+ * hence the cast on the params.
194
208
  *
195
209
  * `.toLowerCase()` rather than `.transform()`: an overwrite keeps the output
196
210
  * type and stays invisible to `z.toJSONSchema`, where a transform would leave
@@ -201,7 +215,7 @@ export const create_uuid = () => crypto.randomUUID();
201
215
  * brand, which a fuz_schema `Uuid` isn't assignable to.
202
216
  */
203
217
  export const Uuid = z
204
- .uuid()
218
+ .uuid({ pattern: UUID_REGEX })
205
219
  .toLowerCase();
206
220
  /** `Uuid` that defaults to a fresh `create_uuid()` when the input is `undefined`. */
207
221
  export const UuidWithDefault = Uuid.default(create_uuid);
@@ -1,24 +1,37 @@
1
1
  /**
2
- * `@fuzdev/fuz_schema` twins of the Zod `Uuid`, `UuidWithDefault`
3
- * (`primitive_schemas.ts`), and `ActingActor` (`http/auth_shape.ts`), under the
4
- * same names, for inputs written in fuz_schema.
2
+ * `@fuzdev/fuz_schema` twins of the Zod `bounded_string`, `Uuid`,
3
+ * `UuidWithDefault` (`primitive_schemas.ts`), and `ActingActor`
4
+ * (`http/auth_shape.ts`), under the same names, for schemas written in
5
+ * fuz_schema.
5
6
  *
6
7
  * The output type is shared: the Zod `Uuid` outputs fuz_schema's
7
8
  * `Branded<string, 'Uuid'>` too, so a value parsed by either twin goes where
8
9
  * the other's is taken.
9
10
  *
10
- * One declared difference: this `Uuid` takes the max UUID in any case, as RFC
11
- * 9562 §4 reads a UUID case-insensitively, and lowercases it; the Zod `Uuid`
12
- * refuses the uppercase max, as `z.uuid()` spells that alternative in
13
- * lowercase only. Every other string gets the same verdict and output from
14
- * both.
11
+ * Both twins have one grammar, RFC 9562's read case-insensitively as its §4
12
+ * says, the max UUID included, and the Rust spine's: every input gets the same
13
+ * verdict and output from both, and their JSON Schema is the same.
15
14
  *
16
15
  * The exports are `@nodocs` while the Zod schemas of the same names stay, as
17
16
  * the docs build refuses two exports of one name.
18
17
  *
19
18
  * @module
20
19
  */
21
- import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
20
+ import { string, type Infer, type PipeSchema } from '@fuzdev/fuz_schema/schema.ts';
21
+ import { type BoundedStringOptions } from './primitive_schemas.js';
22
+ /**
23
+ * A string schema whose length is bounded in UTF-16 code units, the twin of
24
+ * the Zod `bounded_string`: fuz_schema's `min_length` / `max_length` read
25
+ * `String.length`, the unit the Rust spine counts too, so no check beside them
26
+ * is needed. Its JSON Schema carries `minLength` / `maxLength` as the Zod
27
+ * one's does; `max_message` replaces fuz_schema's message on the over-`max`
28
+ * issue.
29
+ *
30
+ * @param options - the bounds, in UTF-16 code units, and the max message
31
+ * @returns the bounded string schema
32
+ * @nodocs
33
+ */
34
+ export declare const bounded_string: (options: BoundedStringOptions) => PipeSchema<string, typeof string>;
22
35
  /**
23
36
  * Branded UUID schema: a UUID of RFC 9562 in either case, output in
24
37
  * lowercase, the form Postgres renders a `uuid` in and every id the server
@@ -1 +1 @@
1
- {"version":3,"file":"primitive_schemas_fuz.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/primitive_schemas_fuz.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAQN,KAAK,KAAK,EACV,MAAM,8BAA8B,CAAC;AAItC;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI;;;;;CAAmD,CAAC;AACrE,cAAc;AAC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K,CAAC,OAAO,WAAW,CAAC,CAAC"}
@@ -1,17 +1,16 @@
1
1
  /**
2
- * `@fuzdev/fuz_schema` twins of the Zod `Uuid`, `UuidWithDefault`
3
- * (`primitive_schemas.ts`), and `ActingActor` (`http/auth_shape.ts`), under the
4
- * same names, for inputs written in fuz_schema.
2
+ * `@fuzdev/fuz_schema` twins of the Zod `bounded_string`, `Uuid`,
3
+ * `UuidWithDefault` (`primitive_schemas.ts`), and `ActingActor`
4
+ * (`http/auth_shape.ts`), under the same names, for schemas written in
5
+ * fuz_schema.
5
6
  *
6
7
  * The output type is shared: the Zod `Uuid` outputs fuz_schema's
7
8
  * `Branded<string, 'Uuid'>` too, so a value parsed by either twin goes where
8
9
  * the other's is taken.
9
10
  *
10
- * One declared difference: this `Uuid` takes the max UUID in any case, as RFC
11
- * 9562 §4 reads a UUID case-insensitively, and lowercases it; the Zod `Uuid`
12
- * refuses the uppercase max, as `z.uuid()` spells that alternative in
13
- * lowercase only. Every other string gets the same verdict and output from
14
- * both.
11
+ * Both twins have one grammar, RFC 9562's read case-insensitively as its §4
12
+ * says, the max UUID included, and the Rust spine's: every input gets the same
13
+ * verdict and output from both, and their JSON Schema is the same.
15
14
  *
16
15
  * The exports are `@nodocs` while the Zod schemas of the same names stay, as
17
16
  * the docs build refuses two exports of one name.
@@ -19,8 +18,25 @@
19
18
  * @module
20
19
  */
21
20
  import { meta } from '@fuzdev/fuz_schema/meta.ts';
22
- import { brand, optional, pipe, string, to_lower_case, uuid, with_default_fn } from '@fuzdev/fuz_schema/schema.ts';
21
+ import { brand, max_length, message, min_length, optional, pipe, string, to_lower_case, uuid, with_default_fn } from '@fuzdev/fuz_schema/schema.ts';
23
22
  import { create_uuid } from './primitive_schemas.js';
23
+ /**
24
+ * A string schema whose length is bounded in UTF-16 code units, the twin of
25
+ * the Zod `bounded_string`: fuz_schema's `min_length` / `max_length` read
26
+ * `String.length`, the unit the Rust spine counts too, so no check beside them
27
+ * is needed. Its JSON Schema carries `minLength` / `maxLength` as the Zod
28
+ * one's does; `max_message` replaces fuz_schema's message on the over-`max`
29
+ * issue.
30
+ *
31
+ * @param options - the bounds, in UTF-16 code units, and the max message
32
+ * @returns the bounded string schema
33
+ * @nodocs
34
+ */
35
+ export const bounded_string = (options) => {
36
+ const { min, max, max_message } = options;
37
+ const max_step = max_message === undefined ? max_length(max) : message(max_length(max), max_message);
38
+ return min === undefined ? pipe(string, max_step) : pipe(string, min_length(min), max_step);
39
+ };
24
40
  /**
25
41
  * Branded UUID schema: a UUID of RFC 9562 in either case, output in
26
42
  * lowercase, the form Postgres renders a `uuid` in and every id the server
@@ -32,6 +32,17 @@ export declare const is_zod_schema: (value: unknown) => value is z.ZodType;
32
32
  * @throws Error when `value` is not a Zod schema, saying it is of neither library
33
33
  */
34
34
  export declare function assert_zod_schema(value: unknown, label: string): asserts value is z.ZodType;
35
+ /**
36
+ * Throw unless `value` is a schema of either library (`is_schema` or
37
+ * `is_zod_schema`), naming `label` — what spec registration runs on each
38
+ * schema slot, so a value of neither library fails at registration rather
39
+ * than at request time.
40
+ *
41
+ * @param value - the value a spec declares as a schema
42
+ * @param label - names the spec and slot in the error, e.g. `` `RPC action "foo": input` ``
43
+ * @throws Error when `value` is neither a Zod nor a fuz_schema schema
44
+ */
45
+ export declare function assert_validation_schema(value: unknown, label: string): asserts value is ValidationSchema;
35
46
  /**
36
47
  * The output type of a `ValidationSchema`: fuz_schema's `Infer` or Zod's
37
48
  * `z.output`. The test narrows `T` itself: `Infer<T & Schema>` would read as
@@ -1 +1 @@
1
- {"version":3,"file":"schema_issues.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/schema_issues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAIN,WAAW,EACX,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,MAAM,8BA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;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,cAAc,GAC1B,QAAQ,aAAa,CAAC,QAAQ,CAAC,EAC/B,OAAO,OAAO,KACZ,KAAK,CAAC,SAAS,CAgBjB,CAAC"}
@@ -33,6 +33,21 @@ export function assert_zod_schema(value, label) {
33
33
  return;
34
34
  throw new Error(`${label} is neither a Zod schema nor a @fuzdev/fuz_schema schema`);
35
35
  }
36
+ /**
37
+ * Throw unless `value` is a schema of either library (`is_schema` or
38
+ * `is_zod_schema`), naming `label` — what spec registration runs on each
39
+ * schema slot, so a value of neither library fails at registration rather
40
+ * than at request time.
41
+ *
42
+ * @param value - the value a spec declares as a schema
43
+ * @param label - names the spec and slot in the error, e.g. `` `RPC action "foo": input` ``
44
+ * @throws Error when `value` is neither a Zod nor a fuz_schema schema
45
+ */
46
+ export function assert_validation_schema(value, label) {
47
+ if (is_schema(value))
48
+ return;
49
+ assert_zod_schema(value, label);
50
+ }
36
51
  /**
37
52
  * Parse `value` with a schema of either library: `parse` for a fuz_schema
38
53
  * schema (`is_schema`), `safeParse` for a Zod one.
@@ -403,8 +403,8 @@ or Postgres and runs in the `cross-ts` CI job.
403
403
  - `assert_surface_deterministic(build_surface)` — build twice, `deepStrictEqual` results; catches nondeterminism in surface generation.
404
404
  - `assert_only_expected_public_routes(surface, list)` — bidirectional: no unexpected public routes, no missing expected ones. Format: `['GET /health', 'POST /api/account/login']`.
405
405
  - `assert_full_middleware_stack(surface, prefix, mws)` — every route under `prefix` has exactly `mws` as its middleware chain.
406
- - `get_route_error_schema(lookup, route, status)` — reads from a pre-built merged-error-schema map.
407
- - `assert_error_schema_valid(lookup, route, status, body)` — assert a schema exists + parses the body.
406
+ - `get_route_error_schema(lookup, route, status)` — reads from a pre-built merged-error-schema map; the schema is Zod or fuz_schema (`ValidationSchema`).
407
+ - `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.
408
408
 
409
409
  ### `surface_invariants.ts` — structural + policy invariants
410
410
 
@@ -474,7 +474,7 @@ Methods:
474
474
 
475
475
  Support functions:
476
476
 
477
- - `extract_declared_error_codes(schema)` — reads `schema.shape.error`; returns the literal value(s) for `z.literal` / `z.enum`, `null` otherwise.
477
+ - `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.
478
478
  - `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.
479
479
  - `DEFAULT_INTEGRATION_ERROR_COVERAGE = 0.2` — conservative baseline for the standard integration/admin suites; consumers tighten as their own test coverage matures.
480
480
 
@@ -564,9 +564,9 @@ rather than `ERROR_INVALID_JSON_BODY`.
564
564
 
565
565
  `describe_adversarial_404({build, roles})` — for every route with `params` +
566
566
  404 in `error_schemas` + an extractable error code (`z.literal` or first
567
- `z.enum`), replaces the handler with a stub returning `{error: <code>}`,
568
- fires with nil-UUID params, asserts 404 + body matches the declared 404 Zod
569
- schema. No DB needed. The code comes from `extract_404_error_code(schema)`,
567
+ `z.enum`, fuz_schema `literal` or first `one_of`), replaces the handler with a
568
+ stub returning `{error: <code>}`, fires with nil-UUID params, asserts 404 +
569
+ body matches the declared 404 schema, Zod or fuz_schema (`parse_any`). No DB needed. The code comes from `extract_404_error_code(schema)`,
570
570
  which reads the output-side JSON Schema of a Zod or fuz_schema schema with
571
571
  `unrepresentable: 'any'`, so a field JSON Schema can't say beside `error`
572
572
  (a transform) no longer drops the route from the suite.
@@ -1 +1 @@
1
- {"version":3,"file":"admin_integration.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/admin_integration.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAgC7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAY3E,OAAO,EAMN,KAAK,uBAAuB,EAC5B,MAAM,kBAAkB,CAAC;AA4B1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,0BAA0B,CAAC;AAavE;;GAEG;AACH,MAAM,WAAW,mCAAmC;IACnD;;;;OAIG;IACH,UAAU,EAAE,SAAS,CAAC;IACtB;;;;OAIG;IACH,cAAc,EAAE,cAAc,CAAC;IAC/B,uFAAuF;IACvF,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IACxC,4GAA4G;IAC5G,KAAK,EAAE,gBAAgB,CAAC;IACxB;;;OAGG;IACH,aAAa,EAAE,uBAAuB,CAAC;IACvC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAiBD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yCAAyC,GACrD,SAAS,mCAAmC,KAC1C,IA+9BF,CAAC"}
1
+ {"version":3,"file":"admin_integration.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/admin_integration.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAgC7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAY3E,OAAO,EAMN,KAAK,uBAAuB,EAC5B,MAAM,kBAAkB,CAAC;AA4B1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,0BAA0B,CAAC;AAavE;;GAEG;AACH,MAAM,WAAW,mCAAmC;IACnD;;;;OAIG;IACH,UAAU,EAAE,SAAS,CAAC;IACtB;;;;OAIG;IACH,cAAc,EAAE,cAAc,CAAC;IAC/B,uFAAuF;IACvF,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IACxC,4GAA4G;IAC5G,KAAK,EAAE,gBAAgB,CAAC;IACxB;;;OAGG;IACH,aAAa,EAAE,uBAAuB,CAAC;IACvC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAiBD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yCAAyC,GACrD,SAAS,mCAAmC,KAC1C,IAg+BF,CAAC"}
@@ -510,8 +510,9 @@ export const describe_standard_admin_integration_tests = (options) => {
510
510
  });
511
511
  test('admin session revoke-all 404 emits failure audit', async () => {
512
512
  const fixture = await options.setup_test();
513
- // `Uuid = z.uuid()` is v4-strict; use a valid v4 shape so we hit the
514
- // handler's account lookup rather than failing at param validation.
513
+ // `Uuid` checks the RFC 9562 version and variant; use a valid v4 shape
514
+ // so we hit the handler's account lookup rather than failing at param
515
+ // validation.
515
516
  const missing_id = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaa01';
516
517
  const res = await rpc_call_for_spec({
517
518
  app: { request: fixture.transport },
@@ -1,5 +1,5 @@
1
1
  import './assert_dev_env.js';
2
- import type { ValidationSchema } from '../schema_issues.js';
2
+ import { type ValidationSchema } from '../schema_issues.js';
3
3
  import type { AdversarialTestOptions } from './attack_surface.js';
4
4
  /**
5
5
  * Extract the error code from a 404 error schema, Zod or `@fuzdev/fuz_schema`,
@@ -22,7 +22,7 @@ export declare const extract_404_error_code: (schema: ValidationSchema) => strin
22
22
  * 1. Creates a stub handler returning 404 with the declared error code
23
23
  * 2. Fires a request with valid-format params (nil UUIDs for UUID params)
24
24
  * 3. Validates response status is 404
25
- * 4. Validates response body matches the declared 404 Zod schema
25
+ * 4. Validates response body matches the declared 404 schema (`parse_any`)
26
26
  */
27
27
  export declare const describe_adversarial_404: (options: AdversarialTestOptions) => void;
28
28
  //# 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;AAqB7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,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,IA+E1E,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;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"}
@@ -4,7 +4,8 @@ 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 Zod schemas.
7
+ * and validates response bodies against the declared 404 schemas, Zod or
8
+ * `@fuzdev/fuz_schema`.
8
9
  *
9
10
  * No DB needed — tests schema conformance of 404 responses, not real handlers.
10
11
  *
@@ -15,6 +16,7 @@ import { z } from 'zod';
15
16
  import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
16
17
  import { to_json_schema } from '@fuzdev/fuz_schema/json_schema.ts';
17
18
  import { is_null_schema } from '../http/schema_helpers.js';
19
+ import { parse_any } from '../schema_issues.js';
18
20
  import { create_auth_test_apps, create_route_skip_filter, select_auth_app } from './auth_apps.js';
19
21
  import { resolve_valid_path, generate_valid_body, to_route_content_type } from './schema_generators.js';
20
22
  /**
@@ -53,13 +55,13 @@ export const extract_404_error_code = (schema) => {
53
55
  * 1. Creates a stub handler returning 404 with the declared error code
54
56
  * 2. Fires a request with valid-format params (nil UUIDs for UUID params)
55
57
  * 3. Validates response status is 404
56
- * 4. Validates response body matches the declared 404 Zod schema
58
+ * 4. Validates response body matches the declared 404 schema (`parse_any`)
57
59
  */
58
60
  export const describe_adversarial_404 = (options) => {
59
61
  const { build, roles } = options;
60
62
  const { surface, route_specs } = build();
61
63
  const is_skipped = create_route_skip_filter(options.skip_routes);
62
- // Build spec lookup for Zod schema access
64
+ // Build spec lookup for schema access
63
65
  const spec_lookup = new Map();
64
66
  for (const spec of route_specs) {
65
67
  spec_lookup.set(`${spec.method} ${spec.path}`, spec);
@@ -120,8 +122,9 @@ export const describe_adversarial_404 = (options) => {
120
122
  assert.strictEqual(res.status, 404, `Expected 404 for ${key}, got ${res.status}`);
121
123
  const body = await res.json();
122
124
  assert.strictEqual(body.error, error_code, `Expected error '${error_code}' for ${key}, got: ${body.error}`);
123
- // Validate against declared 404 Zod schema
124
- spec.errors[404].parse(body);
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)}`);
125
128
  });
126
129
  }
127
130
  });
@@ -46,7 +46,7 @@ export const describe_adversarial_input = (options) => {
46
46
  routes_with_params.length === 0 &&
47
47
  routes_with_query.length === 0)
48
48
  return;
49
- // lookup RouteSpec by method+path for Zod schema access
49
+ // lookup RouteSpec by method+path for schema access
50
50
  const spec_lookup = new Map();
51
51
  for (const spec of route_specs) {
52
52
  spec_lookup.set(`${spec.method} ${spec.path}`, spec);
@@ -1,7 +1,7 @@
1
1
  import './assert_dev_env.js';
2
- import type { z } from 'zod';
3
2
  import type { AppSurface, AppSurfaceRoute } from '../http/surface.js';
4
3
  import type { RouteErrorSchemas } from '../http/error_schemas.js';
4
+ import { type ValidationSchema } from '../schema_issues.js';
5
5
  /**
6
6
  * Resolve an absolute path relative to the caller's module.
7
7
  *
@@ -42,10 +42,10 @@ export declare const assert_only_expected_public_routes: (surface: AppSurface, e
42
42
  * @param lookup - map from `"METHOD /path"` to merged error schemas
43
43
  * @param route - the surface route to look up
44
44
  * @param status - HTTP status code
45
- * @returns the Zod schema for that route+status, or `undefined` when no error
46
- * schema is declared for the status code
45
+ * @returns the Zod or `@fuzdev/fuz_schema` schema for that route+status, or
46
+ * `undefined` when no error schema is declared for the status code
47
47
  */
48
- export declare const get_route_error_schema: (lookup: Map<string, RouteErrorSchemas>, route: AppSurfaceRoute, status: number) => z.ZodType | undefined;
48
+ export declare const get_route_error_schema: (lookup: Map<string, RouteErrorSchemas>, route: AppSurfaceRoute, status: number) => ValidationSchema | undefined;
49
49
  /**
50
50
  * Assert that an error schema exists for a route+status and validate the body against it.
51
51
  *
@@ -57,7 +57,8 @@ export declare const get_route_error_schema: (lookup: Map<string, RouteErrorSche
57
57
  * @param status - expected HTTP status code
58
58
  * @param body - the parsed response body to validate
59
59
  * @throws AssertionError if no schema is declared for the route+status pair.
60
- * @throws ZodError if the body does not satisfy the declared schema.
60
+ * @throws Error if the body does not satisfy the declared schema, its message
61
+ * carrying the failed parse's issues (`parse_any`).
61
62
  */
62
63
  export declare const assert_error_schema_valid: (lookup: Map<string, RouteErrorSchemas>, route: AppSurfaceRoute, status: number, body: unknown) => void;
63
64
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"assertions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/assertions.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAe7B,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,K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AAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,UAAU,MAAM,EAAE,iBAAiB,MAAM,KAAG,MACtB,CAAC;AAE5D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,+BAA+B,GAC3C,SAAS,UAAU,EACnB,eAAe,MAAM,KACnB,IAOF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,4BAA4B,GAAI,eAAe,MAAM,UAAU,KAAG,IAE9E,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kCAAkC,GAC9C,SAAS,UAAU,EACnB,iBAAiB,KAAK,CAAC,MAAM,CAAC,KAC5B,IAWF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,GAClC,QAAQ,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,EACtC,OAAO,eAAe,EACtB,QAAQ,MAAM,KACZ,gBAAgB,GAAG,SAGrB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,GACrC,QAAQ,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,EACtC,OAAO,eAAe,EACtB,QAAQ,MAAM,EACd,MAAM,OAAO,KACX,IAWF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,GACxC,SAAS,UAAU,EACnB,aAAa,MAAM,EACnB,qBAAqB,KAAK,CAAC,MAAM,CAAC,KAChC,IAUF,CAAC"}
@@ -12,6 +12,7 @@ import { resolve, dirname } from 'node:path';
12
12
  import { fileURLToPath } from 'node:url';
13
13
  import { assert } from 'vitest';
14
14
  import { is_public_auth } from '../http/auth_shape.js';
15
+ import { parse_any } from '../schema_issues.js';
15
16
  /**
16
17
  * Resolve an absolute path relative to the caller's module.
17
18
  *
@@ -66,8 +67,8 @@ export const assert_only_expected_public_routes = (surface, expected_public) =>
66
67
  * @param lookup - map from `"METHOD /path"` to merged error schemas
67
68
  * @param route - the surface route to look up
68
69
  * @param status - HTTP status code
69
- * @returns the Zod schema for that route+status, or `undefined` when no error
70
- * schema is declared for the status code
70
+ * @returns the Zod or `@fuzdev/fuz_schema` schema for that route+status, or
71
+ * `undefined` when no error schema is declared for the status code
71
72
  */
72
73
  export const get_route_error_schema = (lookup, route, status) => {
73
74
  const key = `${route.method} ${route.path}`;
@@ -84,12 +85,16 @@ export const get_route_error_schema = (lookup, route, status) => {
84
85
  * @param status - expected HTTP status code
85
86
  * @param body - the parsed response body to validate
86
87
  * @throws AssertionError if no schema is declared for the route+status pair.
87
- * @throws ZodError if the body does not satisfy the declared schema.
88
+ * @throws Error if the body does not satisfy the declared schema, its message
89
+ * carrying the failed parse's issues (`parse_any`).
88
90
  */
89
91
  export const assert_error_schema_valid = (lookup, route, status, body) => {
90
92
  const schema = get_route_error_schema(lookup, route, status);
91
93
  assert.ok(schema, `missing error schema for ${status} on ${route.method} ${route.path}`);
92
- schema.parse(body);
94
+ const result = parse_any(schema, body);
95
+ if (!result.ok) {
96
+ throw new Error(`error schema mismatch for ${status} on ${route.method} ${route.path}: ${JSON.stringify(result.issues)}`);
97
+ }
93
98
  };
94
99
  /**
95
100
  * Verify every route under a path prefix has the exact expected middleware stack.
@@ -1,30 +1,22 @@
1
1
  import './assert_dev_env.js';
2
- /**
3
- * Error reachability coverage tracking.
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.
11
- *
12
- * @module
13
- */
14
- import { z } from 'zod';
15
2
  import type { RouteSpec } from '../http/route_spec.js';
3
+ import type { ValidationSchema } from '../schema_issues.js';
16
4
  /**
17
5
  * Extract declared error code values from an error response schema.
18
6
  *
19
7
  * Recognizes schemas shaped like `z.object({error: z.literal(...)})` or
20
- * `z.object({error: z.enum([...])})` (incl. `looseObject`/`strictObject`).
21
- * Returns the set of declared code values, or `null` if the schema doesn't
22
- * expose a literal/enum `error` field (e.g., bare `ApiError` with `z.string()`).
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()`).
23
15
  *
24
16
  * Used by coverage reporting to split a single declared status into per-code
25
17
  * rows when the route's error schema names specific codes.
26
18
  */
27
- export declare const extract_declared_error_codes: (schema: z.ZodType) => Array<string> | null;
19
+ export declare const extract_declared_error_codes: (schema: ValidationSchema) => Array<string> | null;
28
20
  /** Uncovered entry — either a status-level row (no `code`) or a specific-code row. */
29
21
  export interface UncoveredEntry {
30
22
  method: string;
@@ -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;AAE7B;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAIvD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,4BAA4B,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,KAAK,CAAC,MAAM,CAAC,GAAG,IAWhF,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,C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I,CAAC;IAgBhB;;;;;;;;OAQG;IACH,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,KAAK,CAAC,cAAc,CAAC;CAKhG;AAED;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,MAAM,CAAC;AAEtD,2CAA2C;AAC3C,MAAM,WAAW,oBAAqB,SAAQ,qBAAqB;IAClE,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAaD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,GACjC,WAAW,sBAAsB,EACjC,aAAa,KAAK,CAAC,SAAS,CAAC,EAC7B,UAAU,oBAAoB,KAC5B,IAsBF,CAAC"}
@@ -13,20 +13,37 @@ import './assert_dev_env.js';
13
13
  */
14
14
  import { z } from 'zod';
15
15
  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';
16
18
  import { merge_error_schemas } from '../http/schema_helpers.js';
17
19
  import { find_route_spec, assert_response_matches_spec } from './integration_helpers.js';
18
20
  /**
19
21
  * Extract declared error code values from an error response schema.
20
22
  *
21
23
  * Recognizes schemas shaped like `z.object({error: z.literal(...)})` or
22
- * `z.object({error: z.enum([...])})` (incl. `looseObject`/`strictObject`).
23
- * Returns the set of declared code values, or `null` if the schema doesn't
24
- * expose a literal/enum `error` field (e.g., bare `ApiError` with `z.string()`).
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()`).
25
31
  *
26
32
  * Used by coverage reporting to split a single declared status into per-code
27
33
  * rows when the route's error schema names specific codes.
28
34
  */
29
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
+ }
30
47
  if (!(schema instanceof z.ZodObject))
31
48
  return null;
32
49
  const error_field = schema.shape.error;
@@ -111,9 +111,9 @@ export const assert_response_matches_spec = async (route_specs, method, path, re
111
111
  if (merged) {
112
112
  const status_schema = merged[response.status];
113
113
  if (status_schema) {
114
- const result = status_schema.safeParse(body);
115
- if (!result.success) {
116
- throw new Error(`Error schema mismatch for ${method} ${path} (${response.status}): ${JSON.stringify(result.error.issues)}`);
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
117
  }
118
118
  }
119
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuzdev/fuz_app",
3
- "version": "0.156.0",
3
+ "version": "0.158.0",
4
4
  "description": "fullstack app library",
5
5
  "glyph": "🗝",
6
6
  "logo": "logo.svg",