@fuzdev/fuz_app 0.185.0 → 0.186.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 (114) 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 +11 -5
  7. package/dist/auth/account_queries.d.ts +53 -40
  8. package/dist/auth/account_queries.d.ts.map +1 -1
  9. package/dist/auth/account_queries.js +57 -50
  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_queries.d.ts +13 -13
  25. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  26. package/dist/auth/role_grant_offer_queries.js +12 -13
  27. package/dist/auth/role_grant_queries.d.ts +16 -9
  28. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  29. package/dist/auth/role_grant_queries.js +16 -9
  30. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  31. package/dist/auth/self_service_role_actions.js +15 -0
  32. package/dist/auth/session_queries.d.ts +24 -0
  33. package/dist/auth/session_queries.d.ts.map +1 -1
  34. package/dist/auth/session_queries.js +28 -0
  35. package/dist/db/CLAUDE.md +3 -3
  36. package/dist/db/cell_ddl.d.ts +8 -3
  37. package/dist/db/cell_ddl.d.ts.map +1 -1
  38. package/dist/db/cell_ddl.js +10 -5
  39. package/dist/http/body_limit.d.ts +4 -4
  40. package/dist/http/body_limit.js +4 -4
  41. package/dist/testing/CLAUDE.md +126 -27
  42. package/dist/testing/app_server.d.ts +5 -7
  43. package/dist/testing/app_server.d.ts.map +1 -1
  44. package/dist/testing/app_server.js +5 -7
  45. package/dist/testing/auth_apps.d.ts +3 -1
  46. package/dist/testing/auth_apps.d.ts.map +1 -1
  47. package/dist/testing/auth_apps.js +22 -5
  48. package/dist/testing/cross_backend/backend_config.d.ts +8 -0
  49. package/dist/testing/cross_backend/backend_config.d.ts.map +1 -1
  50. package/dist/testing/cross_backend/backend_log.d.ts +71 -0
  51. package/dist/testing/cross_backend/backend_log.d.ts.map +1 -0
  52. package/dist/testing/cross_backend/backend_log.js +134 -0
  53. package/dist/testing/cross_backend/backend_swap.d.ts +41 -0
  54. package/dist/testing/cross_backend/backend_swap.d.ts.map +1 -0
  55. package/dist/testing/cross_backend/backend_swap.js +431 -0
  56. package/dist/testing/cross_backend/body_size_smuggling.js +3 -3
  57. package/dist/testing/cross_backend/bootstrap_backend.js +4 -4
  58. package/dist/testing/cross_backend/conformance_case.d.ts +11 -6
  59. package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
  60. package/dist/testing/cross_backend/conformance_case.js +4 -0
  61. package/dist/testing/cross_backend/conformance_principal.d.ts +2 -2
  62. package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -1
  63. package/dist/testing/cross_backend/conformance_principal.js +27 -10
  64. package/dist/testing/cross_backend/default_backend_configs.d.ts +38 -5
  65. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  66. package/dist/testing/cross_backend/default_backend_configs.js +50 -15
  67. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  68. package/dist/testing/cross_backend/in_process_setup.js +52 -30
  69. package/dist/testing/cross_backend/revocation_drivers.d.ts +14 -2
  70. package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
  71. package/dist/testing/cross_backend/revocation_drivers.js +36 -8
  72. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +7 -0
  73. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
  74. package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +4 -2
  75. package/dist/testing/cross_backend/setup.d.ts +44 -43
  76. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  77. package/dist/testing/cross_backend/setup.js +64 -62
  78. package/dist/testing/cross_backend/spawn_backend.d.ts +7 -3
  79. package/dist/testing/cross_backend/spawn_backend.d.ts.map +1 -1
  80. package/dist/testing/cross_backend/spawn_backend.js +86 -7
  81. package/dist/testing/cross_backend/spine_suites.d.ts +1 -1
  82. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  83. package/dist/testing/cross_backend/spine_suites.js +4 -2
  84. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  85. package/dist/testing/cross_backend/sse_round_trip.js +4 -2
  86. package/dist/testing/cross_backend/testing_reset_actions.d.ts +7 -6
  87. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  88. package/dist/testing/cross_backend/testing_reset_actions.js +10 -8
  89. package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
  90. package/dist/testing/cross_backend/testing_server_bun.js +7 -31
  91. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  92. package/dist/testing/cross_backend/ws_round_trip.js +4 -3
  93. package/dist/testing/data_exposure.d.ts +4 -1
  94. package/dist/testing/data_exposure.d.ts.map +1 -1
  95. package/dist/testing/data_exposure.js +93 -25
  96. package/dist/testing/db_invariants.d.ts +5 -5
  97. package/dist/testing/db_invariants.js +5 -5
  98. package/dist/testing/logged_errors.d.ts +61 -0
  99. package/dist/testing/logged_errors.d.ts.map +1 -0
  100. package/dist/testing/logged_errors.js +285 -0
  101. package/dist/testing/middleware_gate_probes.d.ts.map +1 -1
  102. package/dist/testing/middleware_gate_probes.js +15 -8
  103. package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
  104. package/dist/testing/rpc_attack_surface.js +41 -16
  105. package/dist/testing/stubs.d.ts +5 -1
  106. package/dist/testing/stubs.d.ts.map +1 -1
  107. package/dist/testing/stubs.js +6 -3
  108. package/dist/testing/test_app.d.ts +40 -11
  109. package/dist/testing/test_app.d.ts.map +1 -1
  110. package/dist/testing/test_app.js +66 -9
  111. package/dist/testing/transports/fetch_transport.d.ts +10 -0
  112. package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
  113. package/dist/testing/transports/fetch_transport.js +13 -0
  114. package/package.json +4 -3
@@ -1,10 +1,19 @@
1
1
  import './assert_dev_env.js';
2
+ import { onTestFinished, TestRunner } from 'vitest';
2
3
  import { DEFAULT_TEST_PASSWORD } from './test_credentials.js';
3
4
  import { create_app_server } from '../server/app_server.js';
5
+ import { shutdown_gave_up } from '../server/shutdown_drain.js';
4
6
  import { generate_daemon_token, DAEMON_TOKEN_HEADER } from '../auth/daemon_token.js';
5
7
  import { create_test_request_headers } from './test_origin.js';
6
8
  import { create_loopback_app_server_options, create_test_account_with_credentials, create_test_app_server, stub_password_deps } from './app_server.js';
7
- import { announce_db_invariant_exclusions, assert_db_invariants, register_db_invariants_check } from './db_invariants.js';
9
+ import { announce_db_invariant_exclusions, assert_db_invariants } from './db_invariants.js';
10
+ /**
11
+ * The bound on a test app's shutdown drain (`shutdown_drain_timeout_ms`), in
12
+ * ms: under vitest's per-test timeout, so a test whose app gives up fails on
13
+ * the give-up rather than timing out, and short, since a test's work in
14
+ * flight is milliseconds. Override through `app_options`.
15
+ */
16
+ export const TEST_SHUTDOWN_DRAIN_TIMEOUT_MS = 1000;
8
17
  /**
9
18
  * The `create_app_server` options both test-app builders share — a fresh
10
19
  * object per call, spread ahead of the per-builder options and `app_options`.
@@ -18,8 +27,12 @@ const test_app_options = () => ({
18
27
  // off: a background pass would delete rows and write audit rows mid-test.
19
28
  // A suite that opts in through `app_options` has the schedule stopped by
20
29
  // `cleanup`.
21
- auth_cleanup: 'off'
30
+ auth_cleanup: 'off',
31
+ shutdown_drain_timeout_ms: TEST_SHUTDOWN_DRAIN_TIMEOUT_MS
22
32
  });
33
+ /** The error a test app's close that gave up throws, naming the report. */
34
+ const format_close_given_up = (closer, given_up) => `create_test_app: ${closer} gave up on work still in flight ${JSON.stringify(given_up)} — ` +
35
+ 'a request, WS message or audit write the test left running';
23
36
  /** Build request headers carrying `session_cookie` in the `cookie_name` cookie. */
24
37
  const create_session_headers_builder = (cookie_name, session_cookie) => (extra) => create_test_request_headers({ cookie: `${cookie_name}=${session_cookie}`, ...extra });
25
38
  /** Build request headers carrying `api_token` as a Bearer token. */
@@ -40,19 +53,31 @@ const create_bearer_headers_builder = (api_token) => (extra) => ({
40
53
  * server's deps (db, keyring), so reuse across servers is unsafe.
41
54
  * The expensive resource (the WASM database) is cached separately in `testing/db.ts`.
42
55
  *
43
- * Built inside a running test, it registers the database invariant check
44
- * (`register_db_invariants_check`) to run when the test finishes; built in
45
- * `beforeAll`, nothing is registered, and the suite calls
46
- * `check_db_invariants_after_all(() => test_app)`, or, when the describe
56
+ * Built inside a running test (its body or a `beforeEach`), it registers one
57
+ * hook for when the test finishes: the database invariant check (skipped when
58
+ * the test already failed, as `register_db_invariants_check` does), then the
59
+ * close. The close throws when it gave up on work still in flight, unless the
60
+ * test failed or closed the app itself (`cleanup`, or `server.close()`, whose
61
+ * outcome is the test's). So an app built in a test lives only for that test.
62
+ * Built in `beforeAll`, nothing is registered: the suite closes the app, and
63
+ * calls `check_db_invariants_after_all(() => test_app)`, or, when the describe
47
64
  * closes the app in its own `afterAll`, `check_db_invariants_after_suite(suite,
48
65
  * test_app)` inside that hook ahead of the close.
49
66
  *
50
67
  * @param options - test app configuration
51
68
  * @returns a `TestApp` ready for HTTP testing
69
+ * @throws Error when called inside a concurrent test, whose finish vitest
70
+ * can't tell from a sibling's — build the app in `beforeAll` instead
52
71
  * @throws Error on an `exclude_db_invariants` entry naming no invariant or
53
72
  * carrying no reason
54
73
  */
55
74
  export const create_test_app = async (options) => {
75
+ const current_test = TestRunner.getCurrentTest();
76
+ // vitest names whichever concurrent test started last current, so the
77
+ // close at a concurrent test's finish would land on a sibling's app
78
+ if (current_test?.concurrent) {
79
+ throw new Error('create_test_app: built in a concurrent test, whose finish would close the app under a sibling — build it in `beforeAll` and close it in `afterAll`');
80
+ }
56
81
  const { exclude_db_invariants } = options;
57
82
  announce_db_invariant_exclusions(exclude_db_invariants, 'create_test_app');
58
83
  const test_server = await create_test_app_server(options);
@@ -104,11 +129,39 @@ export const create_test_app = async (options) => {
104
129
  };
105
130
  };
106
131
  const check_db_invariants = () => assert_db_invariants({ db: test_server.deps.db }, 'in-process', exclude_db_invariants);
107
- register_db_invariants_check(check_db_invariants);
132
+ // a test that closes the app itself owns the outcome
133
+ let closed_by_test = false;
134
+ const close = () => {
135
+ closed_by_test = true;
136
+ return result.close();
137
+ };
138
+ // one hook, so the check runs ahead of the close
139
+ if (current_test) {
140
+ onTestFinished(async ({ task }) => {
141
+ const failed = task.result?.state === 'fail';
142
+ // the close runs whatever the check found; a violation is the report
143
+ let violation = null;
144
+ if (!failed) {
145
+ try {
146
+ await check_db_invariants();
147
+ }
148
+ catch (error) {
149
+ violation = { error };
150
+ }
151
+ }
152
+ const owned_by_test = closed_by_test;
153
+ const given_up = await result.close();
154
+ if (violation)
155
+ throw violation.error;
156
+ if (!failed && !owned_by_test && shutdown_gave_up(given_up)) {
157
+ throw new Error(format_close_given_up('the close when the test finished', given_up));
158
+ }
159
+ });
160
+ }
108
161
  return {
109
162
  app,
110
163
  backend: test_server,
111
- server: result,
164
+ server: { ...result, close },
112
165
  surface_spec,
113
166
  surface: surface_spec.surface,
114
167
  route_specs: surface_spec.route_specs,
@@ -119,6 +172,10 @@ export const create_test_app = async (options) => {
119
172
  assert_db_invariants: check_db_invariants,
120
173
  // the server's `close`, not the backend's: it also stops an auth cleanup
121
174
  // schedule a suite opted into
122
- cleanup: () => result.close()
175
+ cleanup: async () => {
176
+ const given_up = await close();
177
+ if (shutdown_gave_up(given_up))
178
+ throw new Error(format_close_given_up('cleanup', given_up));
179
+ }
123
180
  };
124
181
  };
@@ -23,6 +23,13 @@ import '../assert_dev_env.js';
23
23
  * a cleared session cookie kept as `name=` would be re-sent as an invalid
24
24
  * cookie, which both spines answer by clearing it again.
25
25
  *
26
+ * A request naming a credential of its own (`Authorization`, `X-Daemon-Token`)
27
+ * while the jar holds a cookie throws unless it names its `Cookie` too: the
28
+ * jar would ride along, so a dead token beside it would authenticate as the
29
+ * jar's principal and a refusal the test expects would never be reached. A
30
+ * test sends such a request over a cookie-free transport, or both credentials
31
+ * on purpose by passing `Cookie` itself.
32
+ *
26
33
  * @module
27
34
  */
28
35
  import type { RpcTestTransport } from '../rpc_helpers.js';
@@ -79,6 +86,9 @@ export interface FetchTransport extends RpcTestTransport {
79
86
  * - `Origin` is set to `options.origin ?? base_url` unless the caller
80
87
  * already provided one.
81
88
  * - `Cookie` is set from the jar unless the caller already provided one.
89
+ *
90
+ * @throws Error when a request names `Authorization` or `X-Daemon-Token`,
91
+ * no `Cookie`, and the jar is non-empty
82
92
  */
83
93
  export declare const create_fetch_transport: (options: FetchTransportOptions) => FetchTransport;
84
94
  //# sourceMappingURL=fetch_transport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch_transport.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/transports/fetch_transport.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,yDAAyD;AACzD,MAAM,WAAW,qBAAqB;IACrC,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACjD;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACvD;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC;CAC9C;AAsCD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,GAAI,SAAS,qBAAqB,KAAG,cAmCvE,CAAC"}
1
+ {"version":3,"file":"fetch_transport.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/transports/fetch_transport.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAK1D,yDAAyD;AACzD,MAAM,WAAW,qBAAqB;IACrC,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACjD;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACvD;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC;CAC9C;AAsCD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,sBAAsB,GAAI,SAAS,qBAAqB,KAAG,cA6CvE,CAAC"}
@@ -1,4 +1,6 @@
1
1
  import '../assert_dev_env.js';
2
+ /** The request headers that carry a credential of their own, besides `Cookie`. */
3
+ const CREDENTIAL_HEADERS = ['Authorization', 'X-Daemon-Token'];
2
4
  /**
3
5
  * Parse a `Set-Cookie` value: its `name=value` head, and whether it deletes
4
6
  * the cookie — a `Max-Age` of zero or less, which is how both spines clear
@@ -49,6 +51,9 @@ const apply_set_cookie = (jar, raw) => {
49
51
  * - `Origin` is set to `options.origin ?? base_url` unless the caller
50
52
  * already provided one.
51
53
  * - `Cookie` is set from the jar unless the caller already provided one.
54
+ *
55
+ * @throws Error when a request names `Authorization` or `X-Daemon-Token`,
56
+ * no `Cookie`, and the jar is non-empty
52
57
  */
53
58
  export const create_fetch_transport = (options) => {
54
59
  const { base_url, initial_cookies, origin } = options;
@@ -66,6 +71,14 @@ export const create_fetch_transport = (options) => {
66
71
  headers.set('Origin', default_origin);
67
72
  }
68
73
  if (!headers.has('Cookie') && jar.size > 0) {
74
+ const named = CREDENTIAL_HEADERS.find((name) => headers.has(name));
75
+ if (named !== undefined) {
76
+ throw new Error(`fetch_transport: ${init.method ?? 'GET'} ${url} names its own credential (${named}) ` +
77
+ `but no Cookie, and the jar holds ${Array.from(jar.keys()).join(', ')} — ` +
78
+ 'the jar would ride along and the request could authenticate as its principal. ' +
79
+ 'Send it over a cookie-free transport (`fixture.fresh_transport()`), ' +
80
+ 'or pass `Cookie` explicitly to send both credentials on purpose');
81
+ }
69
82
  headers.set('Cookie', Array.from(jar.values()).join('; '));
70
83
  }
71
84
  const response = await fetch(target, { ...init, headers });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuzdev/fuz_app",
3
- "version": "0.185.0",
3
+ "version": "0.186.0",
4
4
  "description": "fullstack app library",
5
5
  "glyph": "🗝",
6
6
  "logo": "logo.svg",
@@ -21,6 +21,7 @@
21
21
  "test:cross:security": "FUZ_TEST_CROSS_BACKEND=1 vitest run --project cross_backend_security",
22
22
  "test:cross:timing": "FUZ_TEST_CROSS_BACKEND=1 vitest run --project cross_backend_timing",
23
23
  "test:cross:ts-differential": "FUZ_TEST_CROSS_BACKEND=1 vitest run --project cross_backend_ts_differential",
24
+ "test:cross:swap": "FUZ_TEST_CROSS_BACKEND=1 vitest run --project cross_backend_swap",
24
25
  "benchmark:cross-impl": "gro run src/benchmarks/cross_impl.bench.ts",
25
26
  "preview": "vite preview",
26
27
  "deploy": "gro deploy"
@@ -40,7 +41,7 @@
40
41
  "@fuzdev/fuz_schema": ">=0.5.7",
41
42
  "@fuzdev/fuz_ui": ">=0.231.0",
42
43
  "@fuzdev/fuz_util": ">=0.83.0",
43
- "@fuzdev/pglet-wasm": ">=0.1.2",
44
+ "@fuzdev/pglet-wasm": ">=0.2.0",
44
45
  "@hono/bun": ">=1",
45
46
  "@hono/node-server": ">=2",
46
47
  "@node-rs/argon2": ">=2",
@@ -96,7 +97,7 @@
96
97
  "@fuzdev/fuz_util": "^0.83.0",
97
98
  "@fuzdev/gro": "^0.239.0",
98
99
  "@fuzdev/mdz": "^0.11.0",
99
- "@fuzdev/pglet-wasm": "^0.1.2",
100
+ "@fuzdev/pglet-wasm": "^0.2.0",
100
101
  "@hono/bun": "^1.0.1",
101
102
  "@hono/node-server": "^2.1.9",
102
103
  "@node-rs/argon2": "^2.0.2",