@fuzdev/fuz_app 0.185.0 → 0.187.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 (131) hide show
  1. package/dist/actions/CLAUDE.md +14 -2
  2. package/dist/actions/perform_action.d.ts.map +1 -1
  3. package/dist/actions/perform_action.js +36 -5
  4. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  5. package/dist/actions/ws_socket_session.js +3 -1
  6. package/dist/auth/CLAUDE.md +17 -6
  7. package/dist/auth/account_queries.d.ts +60 -44
  8. package/dist/auth/account_queries.d.ts.map +1 -1
  9. package/dist/auth/account_queries.js +64 -54
  10. package/dist/auth/account_routes.d.ts.map +1 -1
  11. package/dist/auth/account_routes.js +59 -25
  12. package/dist/auth/admin_actions.d.ts.map +1 -1
  13. package/dist/auth/admin_actions.js +26 -9
  14. package/dist/auth/audit_emitter.js +2 -2
  15. package/dist/auth/audit_log_queries.d.ts +11 -3
  16. package/dist/auth/audit_log_queries.d.ts.map +1 -1
  17. package/dist/auth/audit_log_queries.js +4 -4
  18. package/dist/auth/audit_log_schema.js +1 -1
  19. package/dist/auth/auth_ddl.d.ts.map +1 -1
  20. package/dist/auth/auth_ddl.js +4 -0
  21. package/dist/auth/cleanup.js +1 -1
  22. package/dist/auth/migrations.d.ts.map +1 -1
  23. package/dist/auth/migrations.js +35 -0
  24. package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
  25. package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
  26. package/dist/auth/role_grant_offer_action_specs.js +2 -1
  27. package/dist/auth/role_grant_offer_actions.d.ts +12 -0
  28. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  29. package/dist/auth/role_grant_offer_actions.js +48 -20
  30. package/dist/auth/role_grant_offer_queries.d.ts +28 -15
  31. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  32. package/dist/auth/role_grant_offer_queries.js +35 -16
  33. package/dist/auth/role_grant_queries.d.ts +118 -20
  34. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  35. package/dist/auth/role_grant_queries.js +145 -24
  36. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  37. package/dist/auth/self_service_role_actions.js +15 -0
  38. package/dist/auth/session_queries.d.ts +24 -0
  39. package/dist/auth/session_queries.d.ts.map +1 -1
  40. package/dist/auth/session_queries.js +28 -0
  41. package/dist/db/CLAUDE.md +3 -3
  42. package/dist/db/cell_ddl.d.ts +8 -3
  43. package/dist/db/cell_ddl.d.ts.map +1 -1
  44. package/dist/db/cell_ddl.js +10 -5
  45. package/dist/db/migrate.d.ts +46 -22
  46. package/dist/db/migrate.d.ts.map +1 -1
  47. package/dist/db/migrate.js +103 -85
  48. package/dist/http/body_limit.d.ts +4 -4
  49. package/dist/http/body_limit.js +4 -4
  50. package/dist/server/app_backend.d.ts.map +1 -1
  51. package/dist/server/app_backend.js +1 -4
  52. package/dist/testing/CLAUDE.md +161 -27
  53. package/dist/testing/app_server.d.ts +5 -7
  54. package/dist/testing/app_server.d.ts.map +1 -1
  55. package/dist/testing/app_server.js +5 -7
  56. package/dist/testing/auth_apps.d.ts +3 -1
  57. package/dist/testing/auth_apps.d.ts.map +1 -1
  58. package/dist/testing/auth_apps.js +22 -5
  59. package/dist/testing/cross_backend/backend_both_live.d.ts +47 -0
  60. package/dist/testing/cross_backend/backend_both_live.d.ts.map +1 -0
  61. package/dist/testing/cross_backend/backend_both_live.js +566 -0
  62. package/dist/testing/cross_backend/backend_config.d.ts +8 -0
  63. package/dist/testing/cross_backend/backend_config.d.ts.map +1 -1
  64. package/dist/testing/cross_backend/backend_log.d.ts +71 -0
  65. package/dist/testing/cross_backend/backend_log.d.ts.map +1 -0
  66. package/dist/testing/cross_backend/backend_log.js +134 -0
  67. package/dist/testing/cross_backend/backend_swap.d.ts +41 -0
  68. package/dist/testing/cross_backend/backend_swap.d.ts.map +1 -0
  69. package/dist/testing/cross_backend/backend_swap.js +267 -0
  70. package/dist/testing/cross_backend/body_size_smuggling.js +3 -3
  71. package/dist/testing/cross_backend/bootstrap_backend.js +4 -4
  72. package/dist/testing/cross_backend/conformance_case.d.ts +11 -6
  73. package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
  74. package/dist/testing/cross_backend/conformance_case.js +4 -0
  75. package/dist/testing/cross_backend/conformance_principal.d.ts +2 -2
  76. package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -1
  77. package/dist/testing/cross_backend/conformance_principal.js +27 -10
  78. package/dist/testing/cross_backend/default_backend_configs.d.ts +38 -5
  79. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  80. package/dist/testing/cross_backend/default_backend_configs.js +50 -15
  81. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  82. package/dist/testing/cross_backend/in_process_setup.js +52 -30
  83. package/dist/testing/cross_backend/revocation_drivers.d.ts +14 -2
  84. package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
  85. package/dist/testing/cross_backend/revocation_drivers.js +36 -8
  86. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +7 -0
  87. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
  88. package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +4 -2
  89. package/dist/testing/cross_backend/setup.d.ts +44 -43
  90. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  91. package/dist/testing/cross_backend/setup.js +64 -62
  92. package/dist/testing/cross_backend/shared_database_backends.d.ts +175 -0
  93. package/dist/testing/cross_backend/shared_database_backends.d.ts.map +1 -0
  94. package/dist/testing/cross_backend/shared_database_backends.js +298 -0
  95. package/dist/testing/cross_backend/spawn_backend.d.ts +7 -3
  96. package/dist/testing/cross_backend/spawn_backend.d.ts.map +1 -1
  97. package/dist/testing/cross_backend/spawn_backend.js +86 -7
  98. package/dist/testing/cross_backend/spine_suites.d.ts +1 -1
  99. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  100. package/dist/testing/cross_backend/spine_suites.js +5 -2
  101. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  102. package/dist/testing/cross_backend/sse_round_trip.js +4 -2
  103. package/dist/testing/cross_backend/testing_reset_actions.d.ts +7 -6
  104. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  105. package/dist/testing/cross_backend/testing_reset_actions.js +10 -8
  106. package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
  107. package/dist/testing/cross_backend/testing_server_bun.js +7 -31
  108. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  109. package/dist/testing/cross_backend/ws_round_trip.js +4 -3
  110. package/dist/testing/data_exposure.d.ts +4 -1
  111. package/dist/testing/data_exposure.d.ts.map +1 -1
  112. package/dist/testing/data_exposure.js +93 -25
  113. package/dist/testing/db_invariants.d.ts +5 -5
  114. package/dist/testing/db_invariants.js +5 -5
  115. package/dist/testing/logged_errors.d.ts +61 -0
  116. package/dist/testing/logged_errors.d.ts.map +1 -0
  117. package/dist/testing/logged_errors.js +285 -0
  118. package/dist/testing/middleware_gate_probes.d.ts.map +1 -1
  119. package/dist/testing/middleware_gate_probes.js +15 -8
  120. package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
  121. package/dist/testing/rpc_attack_surface.js +41 -16
  122. package/dist/testing/stubs.d.ts +5 -1
  123. package/dist/testing/stubs.d.ts.map +1 -1
  124. package/dist/testing/stubs.js +6 -3
  125. package/dist/testing/test_app.d.ts +40 -11
  126. package/dist/testing/test_app.d.ts.map +1 -1
  127. package/dist/testing/test_app.js +66 -9
  128. package/dist/testing/transports/fetch_transport.d.ts +10 -0
  129. package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
  130. package/dist/testing/transports/fetch_transport.js +13 -0
  131. package/package.json +5 -3
@@ -5,8 +5,9 @@ import '../assert_dev_env.js';
5
5
  * The daemon-token-authed actions bundled by `create_testing_actions`:
6
6
  * **`_testing_reset`** (DB wipe + keeper re-seed), **`_testing_drain_effects`**
7
7
  * (effects barrier), **`_testing_mint_session`** (forge an
8
- * expired-by-construction server-side session for the expiry conformance
9
- * cases), **`_testing_put_fact`** (seed an embedded fact for the fact-serving
8
+ * expired-by-construction server-side session on any account, a dead session
9
+ * no wire path leaves — the database-invariant twin check's session on a
10
+ * deleted account), **`_testing_put_fact`** (seed an embedded fact for the fact-serving
10
11
  * suite), **`_testing_schema_snapshot`** (introspect the live schema for
11
12
  * cross-impl parity diffing against a Rust backend's `fuz_db` snapshot),
12
13
  * **`_testing_migration_tracker`** (dump the `schema_version` tracker rows for
@@ -231,10 +232,10 @@ export const testing_drain_effects_action_spec = {
231
232
  * auth resolution therefore passes the
232
233
  * cookie-payload gate (`parse_session_from_cookies`) and is refused by the authoritative
233
234
  * DB-row gate (`query_session_get_valid` — `WHERE expires_at > NOW()`) —
234
- * the gate the in-process payload-expiry tests never reach and the one that
235
- * structurally needs a server-side mint (the cross-process driver has no
236
- * keyring / DB access). The `expired_session` conformance principal drives
237
- * this.
235
+ * the gate the in-process payload-expiry tests never reach. It forges a dead
236
+ * session no wire path leaves (the database-invariant twin check's session on
237
+ * a deleted account); a session that lived and then expired is the
238
+ * `expired_session` principal's, over `_testing_shorten_credential_expiry`.
238
239
  *
239
240
  * `auth` gates on the daemon-token credential, matching `_testing_reset` —
240
241
  * effectively keeper-only. Like its siblings the action is internally
@@ -624,8 +625,9 @@ export const testing_shorten_credential_expiry_action_spec = {
624
625
  * and `api_token` row of the account gets `LEAST(expires_at, NOW() + seconds)`,
625
626
  * so nothing moves later and an eternal token gains an expiry.
626
627
  *
627
- * Shared by the action and the in-process fixture's `mint_expired_token`, so
628
- * both fixtures expire a token with one statement. Unbounded here; the
628
+ * Shared by the action and the in-process fixture's `mint_expired_token` and
629
+ * `mint_expired_session`, so both fixtures expire a credential with one
630
+ * statement. Unbounded here; the
629
631
  * action's input holds `seconds` to its range.
630
632
  *
631
633
  * @param db - the database, a request transaction or the pool
@@ -1 +1 @@
1
- {"version":3,"file":"testing_server_bun.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/testing_server_bun.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AA4B9B,OAAO,KAAK,EAAe,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AA0BlF,4CAA4C;AAC5C,eAAO,MAAM,0BAA0B,QAAO,oBAoE7C,CAAC"}
1
+ {"version":3,"file":"testing_server_bun.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/testing_server_bun.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AA4B9B,OAAO,KAAK,EAAe,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AA0BlF,4CAA4C;AAC5C,eAAO,MAAM,0BAA0B,QAAO,oBA4C7C,CAAC"}
@@ -61,37 +61,13 @@ export const create_bun_testing_adapter = () => {
61
61
  }
62
62
  });
63
63
  const handle = {
64
- // Bun bug (1.3.14): after a *server-initiated* WebSocket close
65
- // (`ServerWebSocket.close()` / `@hono/bun`'s `WSContext.close()`),
66
- // `server.stop()` never resolves — Bun doesn't decrement its
67
- // active-connection count for a server-closed socket, so the stop
68
- // waits forever for a connection it already closed. The trigger is
69
- // orthogonal to HTTP load, hono-vs-raw `Bun.serve`, in-vs-cross
70
- // process, the force flag (`stop()`/`stop(false)`/`stop(true)` all
71
- // hang), and the client runtime — a single server-closed WS is
72
- // necessary and sufficient. Client-initiated close or leaving the
73
- // socket open both stop cleanly in ~0ms. In this suite the trigger is
74
- // any server-initiated WS close — a revocation's (the WS round-trip suite's
75
- // close-on-revoke cases), a cap eviction's, an oversized message's —
76
- // which is why teardown hangs after those and not under HTTP-only or
77
- // client-closed WS traffic.
78
- //
79
- // So initiate a force-close (`true` drops active connections, no
80
- // drain) but DON'T await it: awaiting hangs `start_testing_server`'s
81
- // shutdown forever — the core's exit never runs, and the spawning
82
- // harness blocks on a child that never exits (observed as a
83
- // multi-minute hang needing SIGKILL). The force-close still tears the
84
- // live sockets down; the exit the core fires once `built.close()`
85
- // returns (`0`, or `1` when it gave up) does the real teardown. Node
86
- // doesn't need this — its
87
- // `close()` resolves normally. The `.catch` guards a
88
- // future Bun that rejects rather than hangs; if a future Bun resolves
89
- // the promise after a server-initiated close, revert to
90
- // `await server.stop(true)` to mirror the Node adapter.
91
- shutdown: () => {
92
- void Promise.resolve(server.stop(true)).catch(() => { });
93
- return Promise.resolve();
94
- }
64
+ // `false` stops accepting and lets the requests in flight finish, as
65
+ // Node's `server.close()` does; `true` would reset them, losing a
66
+ // response the shutdown drain is waiting to send. It settles once
67
+ // every connection is gone: the core's `built.close()` ends the live
68
+ // WebSockets, and a shutdown that gave up skips the wait. Verified on
69
+ // Bun 1.4.4, the tested floor.
70
+ shutdown: () => Promise.resolve(server.stop(false))
95
71
  };
96
72
  return handle;
97
73
  },
@@ -1 +1 @@
1
- {"version":3,"file":"ws_round_trip.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/ws_round_trip.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AA2H9B,OAAO,EAAE,KAAK,mBAAmB,EAAW,MAAM,mBAAmB,CAAC;AAItE,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AAOzD,OAAO,EAGN,KAAK,gBAAgB,EACrB,MAAM,kBAAkB,CAAC;AAK1B,2DAA2D;AAC3D,MAAM,WAAW,yBAA0B,SAAQ,gBAAgB;IAClE;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;IAC/B,uEAAuE;IACvE,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC;IAC3C;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,wFAAwF;IACxF,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,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;;;;;OAMG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAClD;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,+BAA+B,GAAI,SAAS,yBAAyB,KAAG,IAmiBpF,CAAC"}
@@ -56,7 +56,8 @@ import '../assert_dev_env.js';
56
56
  * a socket on the account's other token open; `admin_token_revoke_all`,
57
57
  * `POST /password`, and `account_purge` (also gated on
58
58
  * `capabilities.account_lifecycle`) close the account's bearer and session
59
- * sockets, and `POST /logout` closes only the socket of the session it ends,
59
+ * sockets, and `POST /logout` and `account_session_revoke` of the caller's own
60
+ * session close only the socket of the session they end,
60
61
  * the account's bearer socket and a second session's socket each answering a
61
62
  * request after it — the rows `create_account_revocations` shares with the SSE
62
63
  * suite;
@@ -383,8 +384,8 @@ export const describe_cross_process_ws_tests = (options) => {
383
384
  });
384
385
  // The revocations of `revocation_drivers.ts`, shared with the SSE suite.
385
386
  // An account-wide one closes the account's connections — its bearer
386
- // socket, and its session socket too. A session-scoped one (logout)
387
- // closes the socket of the session it was sent on, and leaves the
387
+ // socket, and its session socket too. A session-scoped one (logout, a
388
+ // revoke of the current session) closes the socket of the session it was sent on, and leaves the
388
389
  // account's bearer socket and another session's socket open, each proven
389
390
  // by a reply after the close.
390
391
  // Without `rpc_path` the rows still register, as skipped cases, and never
@@ -78,7 +78,10 @@ export interface DataExposureTestOptions {
78
78
  * 1. Schema-level — walk route, RPC, and WebSocket output schemas (both sides
79
79
  * of a transform), pushed WebSocket params, and route error schemas for
80
80
  * sensitive field names, and non-admin route outputs for admin-only ones
81
- * 2. Runtime — fire real requests and check response bodies against blocklists
81
+ * 2. Runtime — fire real requests and check response bodies against blocklists,
82
+ * a public route both anonymously and as an authenticated account; fails
83
+ * when no 2xx JSON answer carried data, since a sweep that saw none checked
84
+ * nothing
82
85
  * 3. Cross-privilege — admin routes return 403 for non-admin, error responses
83
86
  * contain no sensitive fields
84
87
  */
@@ -1 +1 @@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+7,9 @@ import './assert_dev_env.js';
7
7
  * output (both sides of a transform), the params the server pushes over
8
8
  * WebSocket, and every route error schema for sensitive property names,
9
9
  * and non-admin route outputs for admin-only ones
10
- * - Runtime: fires real requests and checks response bodies against field blocklists
10
+ * - Runtime: fires real requests and checks response bodies against field
11
+ * blocklists — a public route as anonymous and as an authenticated account —
12
+ * failing when no 2xx answer carried data to check
11
13
  * - Cross-privilege: verifies admin routes return 403 for non-admin users,
12
14
  * and non-admin responses exclude admin-only fields
13
15
  *
@@ -26,7 +28,7 @@ import { create_test_request_headers } from './test_origin.js';
26
28
  import { resolve_valid_path, generate_valid_body, to_route_content_type } from './schema_generators.js';
27
29
  import { is_null_schema, is_strict_object_schema, schema_to_surface } from '../http/schema_helpers.js';
28
30
  import { is_keeper_auth, is_public_auth } from '../http/auth_shape.js';
29
- import { sensitive_field_blocklist, admin_only_field_blocklist, assert_no_sensitive_fields_in_json, pick_auth_headers, pick_auth_principal, to_principal_transport } from './integration_helpers.js';
31
+ import { sensitive_field_blocklist, admin_only_field_blocklist, assert_no_sensitive_fields_in_json, collect_json_keys_recursive, is_unauthenticated_refusal, pick_auth_headers, pick_auth_principal, round_trip_uses_fresh_account, to_principal_transport } from './integration_helpers.js';
30
32
  // --- Schema introspection ---
31
33
  /**
32
34
  * Recursively collect all property names from a JSON Schema.
@@ -81,6 +83,13 @@ export const collect_json_schema_property_names = (schema) => {
81
83
  // any-of roles gate only admins and the keeper when every role is one of them
82
84
  const is_elevated_roles = (roles) => !!roles?.length && roles.every((r) => r === ROLE_ADMIN || r === ROLE_KEEPER);
83
85
  const is_elevated_auth = (auth) => auth !== null && (is_keeper_auth(auth) || is_elevated_roles(auth.roles));
86
+ /**
87
+ * Whether a 2xx JSON body carries data the blocklists can check: a key besides
88
+ * `ok` at any depth (`collect_json_keys_recursive`, what the blocklists walk).
89
+ * An `{ok: true}` acknowledgment, a scalar, and an array of scalars or empty
90
+ * objects carry no field that could leak.
91
+ */
92
+ const is_data_bearing_body = (body) => [...collect_json_keys_recursive(body)].some((key) => key !== 'ok');
84
93
  // every schema a caller can receive: route outputs, RPC method outputs, and
85
94
  // over WS the method outputs plus the params the server pushes — a
86
95
  // `remote_notification`'s payload, and the request of a `request_response`
@@ -207,7 +216,10 @@ export const assert_non_admin_schemas_no_admin_fields = (surface_source, admin_o
207
216
  * 1. Schema-level — walk route, RPC, and WebSocket output schemas (both sides
208
217
  * of a transform), pushed WebSocket params, and route error schemas for
209
218
  * sensitive field names, and non-admin route outputs for admin-only ones
210
- * 2. Runtime — fire real requests and check response bodies against blocklists
219
+ * 2. Runtime — fire real requests and check response bodies against blocklists,
220
+ * a public route both anonymously and as an authenticated account; fails
221
+ * when no 2xx JSON answer carried data, since a sweep that saw none checked
222
+ * nothing
211
223
  * 3. Cross-privilege — admin routes return 403 for non-admin, error responses
212
224
  * contain no sensitive fields
213
225
  */
@@ -322,42 +334,98 @@ export const describe_data_exposure_tests = (options) => {
322
334
  return 1;
323
335
  return 0;
324
336
  });
325
- for (const spec of sorted_specs) {
326
- const route_key = format_route_key(spec);
327
- if (skip_set.has(route_key))
328
- continue;
329
- // keeper auth (daemon token) is strictly more privileged than admin
330
- const is_elevated = is_elevated_auth(spec.auth);
331
- const url = resolve_valid_path(spec.path, spec.params, options.param_values?.[route_key]);
332
- const body = generate_valid_body(spec.input);
333
- const headers = pick_auth_headers(spec, fixture, authed_account, admin_account);
334
- const request_init = {
335
- method: spec.method,
336
- headers: { ...headers, 'content-type': to_route_content_type(spec) },
337
- ...(body ? { body: JSON.stringify(body) } : {})
338
- };
339
- const res = await to_principal_transport(pick_auth_principal(spec.auth), fixture)(url, request_init);
337
+ // the 2xx answers whose body carried data, which the sweep must see one of
338
+ let data_bearing_count = 0;
339
+ const check_response = async (res, spec, label) => {
340
340
  if (res.headers.get('Content-Type')?.includes('text/event-stream')) {
341
341
  await res.body?.cancel();
342
- continue;
342
+ return;
343
343
  }
344
344
  if (!res.ok)
345
- continue;
345
+ return;
346
346
  let response_body;
347
347
  try {
348
348
  response_body = await res.clone().json();
349
349
  }
350
350
  catch {
351
- continue;
351
+ return;
352
352
  }
353
- assert_no_sensitive_fields_in_json(response_body, sensitive_fields, `${route_key} (${res.status})`);
354
- // Admin-only field check applies to non-elevated routes with strict
353
+ if (is_data_bearing_body(response_body))
354
+ data_bearing_count++;
355
+ assert_no_sensitive_fields_in_json(response_body, sensitive_fields, label);
356
+ // Admin-only field check applies to non-elevated routes (keeper auth,
357
+ // the daemon token, is strictly more privileged than admin) with strict
355
358
  // output schemas. Loose schemas (e.g. surface route returning JSON
356
359
  // Schema representations) may contain admin field names as metadata.
357
- if (!is_elevated && !is_null_schema(spec.output) && is_strict_object_schema(spec.output)) {
358
- assert_no_sensitive_fields_in_json(response_body, admin_only_fields, `non-admin ${route_key} (${res.status})`);
360
+ if (!is_elevated_auth(spec.auth) &&
361
+ !is_null_schema(spec.output) &&
362
+ is_strict_object_schema(spec.output)) {
363
+ assert_no_sensitive_fields_in_json(response_body, admin_only_fields, `non-admin ${label}`);
364
+ }
365
+ };
366
+ // a credential the sweep sent to a route that requires one must
367
+ // authenticate: a request refused as unauthenticated
368
+ // (`is_unauthenticated_refusal`) checked nothing of the route it was sent to
369
+ const assert_credential_authenticated = async (res, label) => {
370
+ if (res.status !== 401)
371
+ return;
372
+ const refusal = (await res
373
+ .clone()
374
+ .json()
375
+ .catch(() => undefined));
376
+ assert.ok(!is_unauthenticated_refusal(res.status, refusal?.error), `${label}: the credential did not authenticate, so the route went unchecked ` +
377
+ `(${JSON.stringify(refusal)})`);
378
+ };
379
+ for (const spec of sorted_specs) {
380
+ const route_key = format_route_key(spec);
381
+ if (skip_set.has(route_key))
382
+ continue;
383
+ const url = resolve_valid_path(spec.path, spec.params, options.param_values?.[route_key]);
384
+ const body = generate_valid_body(spec.input);
385
+ const content_type = to_route_content_type(spec);
386
+ const body_init = body ? { body: JSON.stringify(body) } : {};
387
+ const principal = pick_auth_principal(spec.auth);
388
+ // a mutation as the authed principal runs on a fresh account, so one
389
+ // that ends its session (logout) leaves the shared account's alone —
390
+ // the round trip's rule
391
+ const account = round_trip_uses_fresh_account(principal, spec.method !== 'GET')
392
+ ? await fixture.create_account({ roles: [] })
393
+ : authed_account;
394
+ const headers = pick_auth_headers(spec, fixture, account, admin_account);
395
+ const res = await to_principal_transport(principal, fixture)(url, {
396
+ method: spec.method,
397
+ headers: { ...headers, 'content-type': content_type },
398
+ ...body_init
399
+ });
400
+ // only a route that requires a credential: a public one may answer a
401
+ // 401 of its own, which reads like an unauthenticated refusal
402
+ if (principal !== 'public') {
403
+ await assert_credential_authenticated(res, `${route_key} as ${principal}`);
359
404
  }
405
+ await check_response(res, spec, `${route_key} (${res.status})`);
406
+ // a public route answers an authenticated caller too, often with more
407
+ // (the status route names the account), so it is swept as the authed
408
+ // account as well — on a fresh transport, so a cookie it clears leaves
409
+ // the fixture's jar alone, and for a mutation on a fresh account, so
410
+ // one that ends its session leaves the shared account's alone
411
+ if (!is_public_auth(spec.auth))
412
+ continue;
413
+ const caller = round_trip_uses_fresh_account('authed', spec.method !== 'GET')
414
+ ? await fixture.create_account({ roles: [] })
415
+ : authed_account;
416
+ const authed_res = await fixture.fresh_transport()(url, {
417
+ method: spec.method,
418
+ headers: { ...caller.create_session_headers(), 'content-type': content_type },
419
+ ...body_init
420
+ });
421
+ // no liveness check on this pass: a public route reads no credential
422
+ // of the spine's, so a 401 is its own answer (a git route asking for
423
+ // HTTP Basic, say), not a dead session
424
+ await check_response(authed_res, spec, `authed ${route_key} (${authed_res.status})`);
360
425
  }
426
+ assert.ok(data_bearing_count > 0, 'the 2xx sweep saw no 2xx JSON response carrying data, so it checked nothing — ' +
427
+ 'every route refused, answered no JSON, or answered `{ok}` alone ' +
428
+ '(check the credentials and `param_values`, or `skip_routes`)');
361
429
  });
362
430
  });
363
431
  };
@@ -42,11 +42,11 @@ export declare const assert_db_invariant_rows: (rows: ReadonlyArray<DbInvariantR
42
42
  */
43
43
  export declare const assert_db_invariants: (deps: QueryDeps, label: string, exclude?: DbInvariantExclusions) => Promise<void>;
44
44
  /**
45
- * Run `check` when the current test finishes — the per-test hook
46
- * `create_test_app` registers when it builds an app (in-process, and so every
47
- * `default_in_process_setup` fixture) and the cross-process setup registers
48
- * from `setup_test()`, with `check` the app's or fixture's
49
- * `assert_db_invariants`.
45
+ * Run `check` when the current test finishes — the per-test hook the
46
+ * cross-process setup registers from `setup_test()`, with `check` the
47
+ * fixture's `assert_db_invariants`. `create_test_app` runs the same check in a
48
+ * hook of its own, which closes the app after it (and so every
49
+ * `default_in_process_setup` fixture).
50
50
  *
51
51
  * Runs after the test body and its `afterEach` hooks, before the next test's
52
52
  * setup resets the database. A test that already failed is left as it
@@ -61,11 +61,11 @@ export const assert_db_invariants = async (deps, label, exclude) => {
61
61
  throw new Error(format_db_invariant_violations(violations, label));
62
62
  };
63
63
  /**
64
- * Run `check` when the current test finishes — the per-test hook
65
- * `create_test_app` registers when it builds an app (in-process, and so every
66
- * `default_in_process_setup` fixture) and the cross-process setup registers
67
- * from `setup_test()`, with `check` the app's or fixture's
68
- * `assert_db_invariants`.
64
+ * Run `check` when the current test finishes — the per-test hook the
65
+ * cross-process setup registers from `setup_test()`, with `check` the
66
+ * fixture's `assert_db_invariants`. `create_test_app` runs the same check in a
67
+ * hook of its own, which closes the app after it (and so every
68
+ * `default_in_process_setup` fixture).
69
69
  *
70
70
  * Runs after the test body and its `afterEach` hooks, before the next test's
71
71
  * setup resets the database. A test that already failed is left as it
@@ -0,0 +1,61 @@
1
+ import './assert_dev_env.js';
2
+ /** What a logged error is matched against: a substring, or a `RegExp` searched for. */
3
+ export type LoggedErrorPattern = string | RegExp;
4
+ /** A logged error the gate lets pass, and why. */
5
+ export interface LoggedErrorAllowance {
6
+ readonly pattern: LoggedErrorPattern;
7
+ /** Why the error is expected — required, and shown nowhere but the source. */
8
+ readonly reason: string;
9
+ }
10
+ /**
11
+ * The designed test-mode banners, allowed in every test: each is printed with
12
+ * `console.error`, once per module instance, when a test-only mode is on, so a
13
+ * production log that shows one is the alarm. In a test run they are the
14
+ * mode working.
15
+ */
16
+ export declare const LOGGED_ERROR_BANNERS: ReadonlyArray<LoggedErrorAllowance>;
17
+ /** Options for `install_logged_error_gate`. */
18
+ export interface InstallLoggedErrorGateOptions {
19
+ /**
20
+ * Errors allowed in every test of every file, beside `LOGGED_ERROR_BANNERS`
21
+ * — a consumer's own designed banners. Each needs its reason.
22
+ */
23
+ readonly allow?: ReadonlyArray<LoggedErrorAllowance>;
24
+ }
25
+ /**
26
+ * Install the gate for the current test file — call at the top level of a
27
+ * vitest `setupFiles` module, which vitest runs ahead of each test file. Wraps
28
+ * `Logger.prototype.error` and `console.error` once per process (each wrapper
29
+ * calls the original), resets the file's state, and registers the file's
30
+ * hooks: a `beforeEach` that starts the test's buffer and checks it in an
31
+ * `onTestFinished` hook, and an `afterAll` that checks what was logged outside
32
+ * any test.
33
+ *
34
+ * @param options - errors allowed in every test beside `LOGGED_ERROR_BANNERS`
35
+ * @throws Error on an allowance without its reason
36
+ */
37
+ export declare const install_logged_error_gate: (options?: InstallLoggedErrorGateOptions) => void;
38
+ /**
39
+ * Declare that the running test logs an error matching `pattern`, and fail
40
+ * the test when it ends unless one was logged: the error the test provokes is
41
+ * asserted, not just tolerated. Every error the pattern matches is allowed.
42
+ *
43
+ * @param pattern - a substring of the error's text, or a `RegExp` searched for
44
+ * @throws Error outside a test, in a concurrent test, or when no setup file installed the gate
45
+ */
46
+ export declare const expect_logged_error: (pattern: LoggedErrorPattern) => void;
47
+ /**
48
+ * Allow logged errors matching `pattern`, with the reason they are expected:
49
+ * inside a test, for that test; at collection, for every test of the
50
+ * enclosing `describe` (the whole file at its top level) and for what the
51
+ * file logs outside its tests or in its concurrent tests. It throws in a
52
+ * concurrent test, whose errors share the file's bucket with its siblings',
53
+ * so an allowance made there would hide theirs. Unlike `expect_logged_error`
54
+ * it asserts nothing. A no-op when no setup file installed the gate.
55
+ *
56
+ * @param pattern - a substring of the error's text, or a `RegExp` searched for
57
+ * @param reason - why the error is expected; required
58
+ * @throws Error on an empty reason or pattern, or in a concurrent test
59
+ */
60
+ export declare const allow_logged_error: (pattern: LoggedErrorPattern, reason: string) => void;
61
+ //# sourceMappingURL=logged_errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logged_errors.d.ts","sourceRoot":"","sources":["../../src/lib/testing/logged_errors.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAsD7B,uFAAuF;AACvF,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEjD,kDAAkD;AAClD,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,oBAAoB,CAapE,CAAC;AAEF,+CAA+C;AAC/C,MAAM,WAAW,6BAA6B;IAC7C;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAC;CACrD;AAoLD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,yBAAyB,GAAI,UAAS,6BAAkC,KAAG,IAsCvF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,kBAAkB,KAAG,IAkBjE,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,kBAAkB,EAAE,QAAQ,MAAM,KAAG,IAqBhF,CAAC"}