@fuzdev/fuz_app 0.182.0 → 0.183.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 (191) hide show
  1. package/README.md +2 -0
  2. package/dist/actions/CLAUDE.md +4 -4
  3. package/dist/auth/CLAUDE.md +58 -34
  4. package/dist/auth/account_routes.d.ts +5 -3
  5. package/dist/auth/account_routes.d.ts.map +1 -1
  6. package/dist/auth/account_routes.js +71 -66
  7. package/dist/auth/admin_actions.d.ts.map +1 -1
  8. package/dist/auth/admin_actions.js +22 -17
  9. package/dist/auth/audit_emitter.d.ts +75 -84
  10. package/dist/auth/audit_emitter.d.ts.map +1 -1
  11. package/dist/auth/audit_emitter.js +83 -71
  12. package/dist/auth/audit_log_schema.d.ts +10 -5
  13. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  14. package/dist/auth/audit_log_schema.js +22 -6
  15. package/dist/auth/bootstrap_account.d.ts +31 -13
  16. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  17. package/dist/auth/bootstrap_account.js +34 -15
  18. package/dist/auth/bootstrap_routes.d.ts +1 -1
  19. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  20. package/dist/auth/bootstrap_routes.js +7 -14
  21. package/dist/auth/deps.d.ts +8 -5
  22. package/dist/auth/deps.d.ts.map +1 -1
  23. package/dist/auth/deps.js +3 -2
  24. package/dist/auth/resolved_auth.d.ts +7 -7
  25. package/dist/auth/resolved_auth.d.ts.map +1 -1
  26. package/dist/auth/resolved_auth.js +4 -4
  27. package/dist/auth/role_grant_offer_actions.d.ts +25 -1
  28. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  29. package/dist/auth/role_grant_offer_actions.js +40 -33
  30. package/dist/auth/role_grant_offer_queries.d.ts +60 -4
  31. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  32. package/dist/auth/role_grant_offer_queries.js +79 -5
  33. package/dist/auth/role_grant_queries.d.ts +3 -52
  34. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  35. package/dist/auth/role_grant_queries.js +5 -80
  36. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  37. package/dist/auth/self_service_role_actions.js +11 -22
  38. package/dist/auth/session_queries.d.ts +6 -3
  39. package/dist/auth/session_queries.d.ts.map +1 -1
  40. package/dist/auth/session_queries.js +20 -11
  41. package/dist/auth/signup_routes.d.ts.map +1 -1
  42. package/dist/auth/signup_routes.js +90 -38
  43. package/dist/db/sql_columns.d.ts +1 -1
  44. package/dist/db/sql_columns.js +1 -1
  45. package/dist/http/CLAUDE.md +15 -10
  46. package/dist/http/db_routes.d.ts +7 -22
  47. package/dist/http/db_routes.d.ts.map +1 -1
  48. package/dist/http/db_routes.js +72 -72
  49. package/dist/http/pending_effects.d.ts +42 -4
  50. package/dist/http/pending_effects.d.ts.map +1 -1
  51. package/dist/http/pending_effects.js +34 -4
  52. package/dist/server/app_server.d.ts +43 -2
  53. package/dist/server/app_server.d.ts.map +1 -1
  54. package/dist/server/app_server.js +57 -3
  55. package/dist/testing/CLAUDE.md +255 -786
  56. package/dist/testing/adversarial_404.d.ts +6 -1
  57. package/dist/testing/adversarial_404.d.ts.map +1 -1
  58. package/dist/testing/adversarial_404.js +38 -17
  59. package/dist/testing/app_server.d.ts +20 -140
  60. package/dist/testing/app_server.d.ts.map +1 -1
  61. package/dist/testing/app_server.js +45 -124
  62. package/dist/testing/audit_drift_guard.d.ts +11 -6
  63. package/dist/testing/audit_drift_guard.d.ts.map +1 -1
  64. package/dist/testing/audit_drift_guard.js +15 -8
  65. package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
  66. package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
  67. package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
  68. package/dist/testing/cross_backend/capabilities.d.ts +9 -6
  69. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  70. package/dist/testing/cross_backend/capabilities.js +11 -7
  71. package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
  72. package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
  73. package/dist/testing/cross_backend/capability_mounts.js +423 -0
  74. package/dist/testing/cross_backend/cell_moderate.js +2 -2
  75. package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
  76. package/dist/testing/cross_backend/cell_relations.js +12 -11
  77. package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
  78. package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
  79. package/dist/testing/cross_backend/conformance_principal.js +283 -0
  80. package/dist/testing/cross_backend/conformance_table.d.ts +2 -50
  81. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  82. package/dist/testing/cross_backend/conformance_table.js +2 -270
  83. package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
  84. package/dist/testing/cross_backend/credential_deadline.js +2 -0
  85. package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
  86. package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
  87. package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
  88. package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
  89. package/dist/testing/cross_backend/db_state_diff.js +444 -0
  90. package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
  91. package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
  92. package/dist/testing/cross_backend/declared_skips.js +132 -0
  93. package/dist/testing/cross_backend/differential.d.ts +11 -2
  94. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  95. package/dist/testing/cross_backend/differential.js +35 -11
  96. package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
  97. package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
  98. package/dist/testing/cross_backend/differential_normalize.js +16 -0
  99. package/dist/testing/cross_backend/in_process_setup.d.ts +22 -12
  100. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  101. package/dist/testing/cross_backend/in_process_setup.js +151 -134
  102. package/dist/testing/cross_backend/login_security.d.ts +12 -0
  103. package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
  104. package/dist/testing/cross_backend/login_security.js +21 -4
  105. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
  106. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
  107. package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
  108. package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
  109. package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
  110. package/dist/testing/cross_backend/revocation_drivers.js +18 -10
  111. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
  112. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
  113. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  114. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
  115. package/dist/testing/cross_backend/role_grant_participation.js +4 -4
  116. package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
  117. package/dist/testing/cross_backend/session_cap.d.ts +2 -2
  118. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  119. package/dist/testing/cross_backend/session_cap.js +22 -11
  120. package/dist/testing/cross_backend/setup.d.ts +31 -1
  121. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  122. package/dist/testing/cross_backend/setup.js +32 -1
  123. package/dist/testing/cross_backend/spine_suites.d.ts +123 -12
  124. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  125. package/dist/testing/cross_backend/spine_suites.js +454 -57
  126. package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
  127. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  128. package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
  129. package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
  130. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  131. package/dist/testing/cross_backend/sse_round_trip.js +123 -27
  132. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  133. package/dist/testing/cross_backend/testing_backdoor.js +4 -2
  134. package/dist/testing/cross_backend/testing_reset_actions.d.ts +59 -27
  135. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  136. package/dist/testing/cross_backend/testing_reset_actions.js +66 -42
  137. package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
  138. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  139. package/dist/testing/cross_backend/transport_composition.js +7 -3
  140. package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
  141. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  142. package/dist/testing/cross_backend/ws_round_trip.js +54 -8
  143. package/dist/testing/data_exposure.d.ts.map +1 -1
  144. package/dist/testing/data_exposure.js +3 -0
  145. package/dist/testing/db.d.ts +0 -32
  146. package/dist/testing/db.d.ts.map +1 -1
  147. package/dist/testing/db.js +0 -86
  148. package/dist/testing/db_entities.d.ts +14 -0
  149. package/dist/testing/db_entities.d.ts.map +1 -1
  150. package/dist/testing/db_entities.js +17 -0
  151. package/dist/testing/db_invariant_queries.d.ts +259 -0
  152. package/dist/testing/db_invariant_queries.d.ts.map +1 -0
  153. package/dist/testing/db_invariant_queries.js +400 -0
  154. package/dist/testing/db_invariants.d.ts +106 -0
  155. package/dist/testing/db_invariants.d.ts.map +1 -0
  156. package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
  157. package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
  158. package/dist/testing/db_invariants.gen.sql.js +13 -0
  159. package/dist/testing/db_invariants.js +141 -0
  160. package/dist/testing/db_invariants.sql +152 -0
  161. package/dist/testing/describe_db.d.ts +36 -0
  162. package/dist/testing/describe_db.d.ts.map +1 -0
  163. package/dist/testing/describe_db.js +71 -0
  164. package/dist/testing/integration.d.ts +6 -9
  165. package/dist/testing/integration.d.ts.map +1 -1
  166. package/dist/testing/integration.js +9 -13
  167. package/dist/testing/integration_helpers.d.ts +1 -1
  168. package/dist/testing/integration_helpers.d.ts.map +1 -1
  169. package/dist/testing/rate_limiting.d.ts +1 -1
  170. package/dist/testing/rate_limiting.d.ts.map +1 -1
  171. package/dist/testing/rate_limiting.js +3 -2
  172. package/dist/testing/role_grant_helpers.d.ts +1 -1
  173. package/dist/testing/role_grant_helpers.d.ts.map +1 -1
  174. package/dist/testing/round_trip.d.ts.map +1 -1
  175. package/dist/testing/round_trip.js +3 -0
  176. package/dist/testing/rpc_attack_surface.d.ts +8 -6
  177. package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
  178. package/dist/testing/rpc_attack_surface.js +69 -6
  179. package/dist/testing/rpc_round_trip.d.ts +1 -1
  180. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  181. package/dist/testing/rpc_round_trip.js +3 -0
  182. package/dist/testing/sse_round_trip.d.ts +1 -1
  183. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  184. package/dist/testing/sse_round_trip.js +13 -4
  185. package/dist/testing/stubs.d.ts +4 -2
  186. package/dist/testing/stubs.d.ts.map +1 -1
  187. package/dist/testing/stubs.js +10 -5
  188. package/dist/testing/test_app.d.ts +166 -0
  189. package/dist/testing/test_app.d.ts.map +1 -0
  190. package/dist/testing/test_app.js +124 -0
  191. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"credential_deadline.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/credential_deadline.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAwD9B,OAAO,EAAE,KAAK,mBAAmB,EAAW,MAAM,mBAAmB,CAAC;AAEtE,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAsC,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAkB7F,oEAAoE;AACpE,MAAM,WAAW,kCAAmC,SAAQ,gBAAgB;IAC3E,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;IAC/B,6FAA6F;IAC7F,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC;IAC3C,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAClD;AAED;;;;GAIG;AACH,eAAO,MAAM,wCAAwC,GACpD,SAAS,kCAAkC,KACzC,IAiKF,CAAC"}
1
+ {"version":3,"file":"credential_deadline.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/credential_deadline.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AA0D9B,OAAO,EAAE,KAAK,mBAAmB,EAAW,MAAM,mBAAmB,CAAC;AAEtE,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAsC,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAkB7F,oEAAoE;AACpE,MAAM,WAAW,kCAAmC,SAAQ,gBAAgB;IAC3E,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;IAC/B,6FAA6F;IAC7F,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC;IAC3C,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAClD;AAED;;;;GAIG;AACH,eAAO,MAAM,wCAAwC,GACpD,SAAS,kCAAkC,KACzC,IAkKF,CAAC"}
@@ -40,6 +40,7 @@ import '../assert_dev_env.js';
40
40
  * @module
41
41
  */
42
42
  import { assert, beforeAll, describe } from 'vitest';
43
+ import { check_db_invariants_after_all } from '../db_invariants.js';
43
44
  import { heartbeat_action_spec } from '../../actions/heartbeat.js';
44
45
  import { WS_CLOSE_CREDENTIAL_EXPIRED_REASON, WS_CLOSE_SESSION_REVOKED } from '../../actions/transports.js';
45
46
  import { ROLE_ADMIN } from '../../auth/role_schema.js';
@@ -107,6 +108,7 @@ export const describe_credential_deadline_cross_tests = (options) => {
107
108
  // One reset for the suite: the cases share no state past it, since each
108
109
  // mints its own account and the seam touches only that account.
109
110
  let suite_fixture = null;
111
+ check_db_invariants_after_all(() => suite_fixture);
110
112
  beforeAll(async () => {
111
113
  if (capabilities.ws || capabilities.sse)
112
114
  suite_fixture = await setup_test();
@@ -1,6 +1,6 @@
1
1
  import '../assert_dev_env.js';
2
2
  import { type BuiltinCredentialType } from '../../auth/credential_type_schema.js';
3
- import type { TestAccount } from '../app_server.js';
3
+ import type { TestAccount } from '../test_app.js';
4
4
  import { type RawHttpResponse } from '../transports/raw_http.js';
5
5
  import { type RawWsClient } from '../transports/ws_raw_client.js';
6
6
  import type { CrossProcessSetupOptions, TestFixture } from './setup.js';
@@ -1 +1 @@
1
- {"version":3,"file":"credential_wire.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/credential_wire.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAqB9B,OAAO,EAIN,KAAK,qBAAqB,EAC1B,MAAM,sCAAsC,CAAC;AAG9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAMN,KAAK,eAAe,EACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAGN,KAAK,WAAW,EAChB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,mCAAmC,uBAAuB,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,mCAAmC,gCAAgC,C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AAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,uDAAuD;IACvD,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC7C;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,GAC3B,SAAS,qBAAqB,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,KAC5D,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAA;CAAE,CAahE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,GACzC,UAAU,eAAe,EACzB,UAAU,sBAAsB,EAChC,UAAU,MAAM,EAChB,OAAO,MAAM,KACX,uBAAuB,GAAG,IAW5B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC5B,SAAS,qBAAqB,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,KAC3D,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAA;CAAE,CAYhE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,GACpC,QAAQ,WAAW,EACnB,UAAU,sBAAsB,EAChC,SAAS,MAAM,EACf,OAAO,MAAM,KACX,OAAO,CAAC;IAAE,UAAU,EAAE,uBAAuB,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CA0BvE,CAAC"}
@@ -0,0 +1,72 @@
1
+ import '../assert_dev_env.js';
2
+ import { type DifferentialDiff } from './differential_normalize.js';
3
+ import { type ReconstructedBootstrappedBackendHandle } from './setup.js';
4
+ /**
5
+ * The order the canonical walk visits tables in, numbering their ids: each
6
+ * row a later table references is numbered first. A table the database holds
7
+ * and this list doesn't is walked after these, by name.
8
+ */
9
+ export declare const DB_STATE_TABLES: ReadonlyArray<string>;
10
+ /**
11
+ * Per table, the columns its rows sort by, compared normalized (a reference
12
+ * by the placeholder its row was numbered, a timestamp by rank) ahead of the
13
+ * whole row. `audit_log` sorts by `seq`, numerically. Each table's natural
14
+ * key, so rows tie only when they are alike but for an id — a tie falls back
15
+ * to the raw row, whose order differs per backend.
16
+ */
17
+ export declare const DB_STATE_SORT_KEYS: Readonly<Record<string, ReadonlyArray<string>>>;
18
+ /** Where the audit sequence stood before a test. */
19
+ export interface DbStateMark {
20
+ readonly audit_seq: number;
21
+ }
22
+ /** A dump as read: per table, each column's type and the rows as JSON. */
23
+ export interface RawDbState {
24
+ /** Per table, column name to `udt_name`. */
25
+ readonly columns: Readonly<Record<string, Readonly<Record<string, string>>>>;
26
+ readonly rows: Readonly<Record<string, ReadonlyArray<Record<string, unknown>>>>;
27
+ /** The audit sequence's value at the read less the mark's. */
28
+ readonly audit_seq_advance: number;
29
+ }
30
+ /** A dump normalized — what two backends' dumps are compared as. */
31
+ export interface DbState {
32
+ readonly tables: Record<string, Array<Record<string, unknown>>>;
33
+ readonly audit_seq_advance: number;
34
+ }
35
+ /** Reads one backend's database around a test. */
36
+ export interface DbStateProbe {
37
+ /** Where the audit sequence stands — call before the test's fixture. */
38
+ readonly mark: () => Promise<DbStateMark>;
39
+ /** Drain the backend's audit writes, then read and normalize the database. */
40
+ readonly read: (mark: DbStateMark) => Promise<DbState>;
41
+ /** Close the probe's connection. */
42
+ readonly close: () => Promise<void>;
43
+ }
44
+ /**
45
+ * Normalize a dump (module doc). Pure; numbering restarts for every call.
46
+ *
47
+ * @param raw - the rows and column types `create_db_state_probe` read
48
+ * @returns the normalized state
49
+ */
50
+ export declare const normalize_db_state: (raw: RawDbState) => DbState;
51
+ /**
52
+ * Every place two normalized states differ, under `db.`: each table's rows
53
+ * by position, then `db.audit_seq_advance`.
54
+ *
55
+ * @param a - one backend's state
56
+ * @param b - the other's
57
+ * @returns the differences, empty when the states are equal
58
+ */
59
+ export declare const diff_db_states: (a: DbState, b: DbState) => Array<DifferentialDiff>;
60
+ /**
61
+ * A probe over a backend's database, read directly — the backend's
62
+ * `env.DATABASE_URL` must be a PostgreSQL URL the test process reaches. The
63
+ * read drains the backend's in-flight detached writes (audit rows; on the
64
+ * Rust spine also the token touch and the bootstrap write) first
65
+ * (`_testing_drain_effects`, on the daemon token), so a WebSocket mutation's
66
+ * row has landed.
67
+ *
68
+ * @param handle - the backend
69
+ * @returns the probe; `close` it once its reads are done
70
+ */
71
+ export declare const create_db_state_probe: (handle: ReconstructedBootstrappedBackendHandle) => DbStateProbe;
72
+ //# sourceMappingURL=db_state_diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db_state_diff.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/db_state_diff.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAkF9B,OAAO,EAA4B,KAAK,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC9F,OAAO,EAEN,KAAK,sCAAsC,EAC3C,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,MAAM,CAmBjD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAkB9E,CAAC;AAmBF,oDAAoD;AACpD,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AAED,0EAA0E;AAC1E,MAAM,WAAW,UAAU;IAC1B,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7E,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAChF,8DAA8D;IAC9D,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACnC;AAED,oEAAoE;AACpE,MAAM,WAAW,OAAO;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAChE,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACnC;AAED,kDAAkD;AAClD,MAAM,WAAW,YAAY;IAC5B,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1C,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACvD,oCAAoC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAwGD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,UAAU,KAAG,OA8HpD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,KAAK,CAAC,gBAAgB,CAG7E,CAAC;AAWF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GACjC,QAAQ,sCAAsC,KAC5C,YA0DF,CAAC"}
@@ -0,0 +1,444 @@
1
+ import '../assert_dev_env.js';
2
+ /**
3
+ * The database a test leaves, read directly and normalized, so two backends
4
+ * driven through the same requests can be compared row for row.
5
+ *
6
+ * The differentials compare answers. A write one backend makes and the other
7
+ * doesn't — an audit field, a metadata key, a row inserted and rolled back —
8
+ * reaches no answer unless some test reads it back, so it is invisible there.
9
+ * `create_db_state_probe` reads a backend's database over its own
10
+ * connection (the backend must be on PostgreSQL the test process reaches),
11
+ * after draining the backend's in-flight detached writes (audit rows; on the
12
+ * Rust spine also the token touch and the bootstrap write), and
13
+ * `normalize_db_state` maps the rows onto a form both backends share when
14
+ * they wrote the same things:
15
+ *
16
+ * Every table of the `public` schema is read (`schema_version` aside), its
17
+ * columns and their types from `query_schema_snapshot`, so a new table or
18
+ * column joins with no edit here, under the rules its type takes:
19
+ *
20
+ * - **Ids** become positional placeholders (`<id:1>`, `<tok:1>`), numbered
21
+ * by a canonical walk: the tables in `DB_STATE_TABLES` order, then any
22
+ * other in name order; each table's rows sorted by its `DB_STATE_SORT_KEYS`
23
+ * columns (accounts by username, actors by account and name, audit rows by
24
+ * `seq`), then by the whole row with no unnumbered id; each row's columns
25
+ * and every JSON object's keys sorted. So a reference — a column or a UUID
26
+ * inside `metadata` naming another row — compares, while the values
27
+ * themselves differ per backend.
28
+ * - **Secrets and digests** — API tokens, bare 64-hex digests (a session's
29
+ * id, a token's hash) — become constants (`<token>`, `<hash>`): they are
30
+ * fresh per backend and nothing compares them. Sessions and tokens, sorted
31
+ * by account then content, compare as a multiset per account. A
32
+ * `password_hash` keeps its argon2 parameter prefix
33
+ * (`$argon2id$v=19$m=19456,t=2,p=1$<salt>$<hash>`), so the cost
34
+ * parameters compare and the salted digest doesn't. A `blake3:` content
35
+ * address and a `bytea` (hex) are compared as they are.
36
+ * - **Generated usernames** (`GENERATED_USERNAME_PATTERN`) become positional
37
+ * placeholders like ids; a username a test names stays as it is.
38
+ * - **Timestamps** — a timestamp column's value, and a second-precision ISO
39
+ * string inside a JSON value — become their dense rank among every
40
+ * timestamp in the dump (`<t:3>`); `null` stays `null`. Two writes in one
41
+ * transaction share a rank, a later write ranks after, and a backend
42
+ * setting a column the other leaves `null` differs.
43
+ * - **A token's last use** — `api_token.last_used_at` — becomes `<set>` or
44
+ * stays `null`, and joins no rank: the touch is a detached write that runs
45
+ * concurrently with its own request's transaction on both spines, so its
46
+ * order against that request's writes is promised by neither, and ranking
47
+ * it would shift every later rank. `last_used_ip` compares as it is.
48
+ * - **Expiries** — a column or JSON key named `expires_at`, in a row with a
49
+ * `created_at` — become their offset from that `created_at`, rounded to
50
+ * the minute (`+30d0h0m`), and join no rank: a rank keeps order and loses
51
+ * the duration, so a lifetime cut from 30 days to 7 would rank the same.
52
+ * - **`seq`** becomes the offset from the dump's smallest, and the dump
53
+ * carries `audit_seq_advance`: how far the audit sequence moved between
54
+ * `mark` and the read, so an audit insert that rolled back — no row left,
55
+ * a sequence value spent — differs too. Rows of successive requests take
56
+ * `seq` in request order because fuz_app's two test binaries (the TS
57
+ * spine binary and `testing_spine_stub`) settle an HTTP answer's writes
58
+ * before answering (`await_pending_effects: true` on TS, the stub's
59
+ * `await_background_writes_layer`); in production a refusal's row is
60
+ * written after its answer, and the next request's row can land first.
61
+ *
62
+ * `diff_db_states` lists every place two normalized states differ, as
63
+ * `DifferentialDiff`s under `db.` (`db.audit_log[2].metadata.reason`,
64
+ * `db.audit_seq_advance`), the paths a known-divergence ledger names.
65
+ *
66
+ * Rows compare by position after the sort, so a row one backend writes and
67
+ * the other doesn't shifts every later row of its table. Rows the sort can't
68
+ * tell apart but for an id are ordered by that id's raw value, which differs
69
+ * per backend; they then normalize equal unless something else references
70
+ * them.
71
+ *
72
+ * @module
73
+ */
74
+ import { create_db } from '../../db/create_db.js';
75
+ import { assert_valid_sql_identifier } from '../../db/sql_identifier.js';
76
+ import { query_schema_snapshot } from '../schema_introspect.js';
77
+ import { DAEMON_TOKEN_HEADER } from '../../auth/daemon_token.js';
78
+ import { create_fetch_transport } from '../transports/fetch_transport.js';
79
+ import { cross_drain_effects } from './audit_cross_helpers.js';
80
+ import { diff_differential_values } from './differential_normalize.js';
81
+ import { GENERATED_USERNAME_PATTERN } from './setup.js';
82
+ /**
83
+ * The order the canonical walk visits tables in, numbering their ids: each
84
+ * row a later table references is numbered first. A table the database holds
85
+ * and this list doesn't is walked after these, by name.
86
+ */
87
+ export const DB_STATE_TABLES = [
88
+ 'bootstrap_lock',
89
+ 'app_settings',
90
+ 'account',
91
+ 'actor',
92
+ 'role_grant_offer',
93
+ 'role_grant',
94
+ 'invite',
95
+ 'auth_session',
96
+ 'api_token',
97
+ 'cell',
98
+ 'cell_grant',
99
+ 'cell_field',
100
+ 'cell_item',
101
+ 'fact',
102
+ 'fact_holder',
103
+ 'fact_ref',
104
+ 'memo',
105
+ 'audit_log'
106
+ ];
107
+ /**
108
+ * Per table, the columns its rows sort by, compared normalized (a reference
109
+ * by the placeholder its row was numbered, a timestamp by rank) ahead of the
110
+ * whole row. `audit_log` sorts by `seq`, numerically. Each table's natural
111
+ * key, so rows tie only when they are alike but for an id — a tie falls back
112
+ * to the raw row, whose order differs per backend.
113
+ */
114
+ export const DB_STATE_SORT_KEYS = {
115
+ account: ['username'],
116
+ actor: ['account_id', 'name'],
117
+ role_grant_offer: ['created_at', 'to_account_id', 'role'],
118
+ role_grant: ['actor_id', 'created_at', 'role'],
119
+ invite: ['created_at', 'username', 'email'],
120
+ auth_session: ['account_id', 'created_at'],
121
+ api_token: ['account_id', 'created_at', 'name'],
122
+ cell: ['kind', 'created_at', 'path'],
123
+ cell_grant: ['cell_id', 'actor_id', 'role', 'scope_id', 'level', 'created_at'],
124
+ cell_field: ['source_id', 'name'],
125
+ cell_item: ['parent_id', 'position'],
126
+ // `blake3:` content addresses, compared verbatim, so they sort alike
127
+ fact: ['hash'],
128
+ fact_holder: ['hash', 'actor_id'],
129
+ fact_ref: ['source_hash', 'target_hash'],
130
+ memo: ['fn_id', 'input_hash'],
131
+ audit_log: ['seq']
132
+ };
133
+ /** Tables a dump leaves out: the migration tracker, which no request writes. */
134
+ const DB_STATE_EXCLUDED_TABLES = ['schema_version'];
135
+ /** The canonical walk's table order over the tables a dump holds. */
136
+ const walk_order = (tables) => {
137
+ const held = new Set(tables);
138
+ return [
139
+ ...DB_STATE_TABLES.filter((t) => held.has(t)),
140
+ ...[...held].filter((t) => !DB_STATE_TABLES.includes(t)).sort()
141
+ ];
142
+ };
143
+ /** Every generated username in a string. */
144
+ const GENERATED_USERNAMES = new RegExp(GENERATED_USERNAME_PATTERN.source, 'g');
145
+ const ARGON2_PREFIX = /^(\$argon2[a-z]+\$v=\d+\$[^$]+)\$[^$]+\$[^$]+$/;
146
+ const TIMESTAMP_UDTS = new Set(['timestamptz', 'timestamp']);
147
+ /** A Postgres JSON timestamp (`2026-11-21T18:01:31.12+00:00`) or a wire one, as epoch microseconds. */
148
+ const COLUMN_TIMESTAMP_PATTERN = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,6}))?(Z|[+-]\d{2}(?::?\d{2})?)?$/;
149
+ const timestamp_micros = (value) => {
150
+ const m = COLUMN_TIMESTAMP_PATTERN.exec(value);
151
+ if (!m)
152
+ return null;
153
+ const [, y, mo, d, h, mi, s, frac = '', zone = 'Z'] = m;
154
+ const ms = Date.UTC(Number(y), Number(mo) - 1, Number(d), Number(h), Number(mi), Number(s));
155
+ let offset_minutes = 0;
156
+ if (zone !== 'Z') {
157
+ const sign = zone.startsWith('-') ? -1 : 1;
158
+ const digits = zone.slice(1).replace(':', '');
159
+ offset_minutes = sign * (Number(digits.slice(0, 2)) * 60 + Number(digits.slice(2, 4) || '0'));
160
+ }
161
+ return BigInt(ms - offset_minutes * 60_000) * 1000n + BigInt(Number(frac.padEnd(6, '0')));
162
+ };
163
+ /** Second-precision ISO timestamps inside a JSON string (`ISO8601_SECONDS`, unanchored). */
164
+ const WIRE_TIMESTAMP_PATTERN = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/g;
165
+ const is_record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
166
+ /** Every string inside `value`, keys included — less an expiry's value when `skip_expiry`. */
167
+ const visit_strings = (value, on_string, skip_expiry) => {
168
+ if (typeof value === 'string')
169
+ on_string(value);
170
+ else if (Array.isArray(value))
171
+ for (const v of value)
172
+ visit_strings(v, on_string, skip_expiry);
173
+ else if (is_record(value)) {
174
+ for (const [k, v] of Object.entries(value)) {
175
+ on_string(k);
176
+ if (skip_expiry && is_expiry(k, v))
177
+ continue;
178
+ visit_strings(v, on_string, skip_expiry);
179
+ }
180
+ }
181
+ };
182
+ /**
183
+ * The column or JSON key holding an expiry, written as its offset from the
184
+ * row's `created_at` (`format_expiry_offset`) rather than ranked — by name,
185
+ * not by whether the instant lies after the read, which would turn on the
186
+ * clock: a backdated or shortened credential's expiry is already past when
187
+ * read.
188
+ */
189
+ const EXPIRY_KEY = 'expires_at';
190
+ /**
191
+ * Columns compared as set or not, never ranked — each written by a detached
192
+ * write. `api_token.last_used_at`: the bearer leg's touch runs concurrently
193
+ * with its own request's transaction on both spines, so its order against
194
+ * that request's writes is promised by neither.
195
+ */
196
+ const SET_ONLY_COLUMNS = new Set(['api_token.last_used_at']);
197
+ /** The marker a non-null `SET_ONLY_COLUMNS` value becomes. */
198
+ const SET_MARKER = '<set>';
199
+ /**
200
+ * Whether `key` and `value` are an expiry — the one test both the rank set's
201
+ * skip and the offset rewrite read, so a value is never in neither.
202
+ */
203
+ const is_expiry = (key, value) => key === EXPIRY_KEY && typeof value === 'string' && timestamp_micros(value) !== null;
204
+ /** The row's `created_at` as epoch microseconds, `null` for a row without one. */
205
+ const row_created_micros = (row, columns) => {
206
+ const created = row.created_at;
207
+ return TIMESTAMP_UDTS.has(columns.created_at ?? '') && typeof created === 'string'
208
+ ? timestamp_micros(created)
209
+ : null;
210
+ };
211
+ const MICROS_PER_MINUTE = 60000000n;
212
+ /**
213
+ * An expiry as its offset from the row's creation, rounded to the minute —
214
+ * `+30d0h0m`, `-0d0h1m` for one already past at creation. The minute is far
215
+ * coarser than one write's spread (an app clock against the database's, a
216
+ * second-precision metadata copy) and far finer than any lifetime.
217
+ */
218
+ const format_expiry_offset = (expires, created) => {
219
+ const delta = expires - created;
220
+ const sign = delta < 0n ? '-' : '+';
221
+ const magnitude = delta < 0n ? -delta : delta;
222
+ const minutes = (magnitude + MICROS_PER_MINUTE / 2n) / MICROS_PER_MINUTE;
223
+ return `${sign}${minutes / 1440n}d${(minutes % 1440n) / 60n}h${minutes % 60n}m`;
224
+ };
225
+ const compare_text = (x, y) => (x < y ? -1 : x > y ? 1 : 0);
226
+ /** A sort key with its numbers (ranks, placeholders, offsets) padded, so they sort by value. */
227
+ const sortable = (key) => key.replace(/\d+/g, (n) => n.padStart(12, '0'));
228
+ /**
229
+ * Normalize a dump (module doc). Pure; numbering restarts for every call.
230
+ *
231
+ * @param raw - the rows and column types `create_db_state_probe` read
232
+ * @returns the normalized state
233
+ */
234
+ export const normalize_db_state = (raw) => {
235
+ // the timestamps' dense ranks, over every timestamp the dump holds
236
+ const instants = new Set();
237
+ const add_instant = (s) => {
238
+ const micros = timestamp_micros(s);
239
+ if (micros !== null)
240
+ instants.add(micros);
241
+ };
242
+ const tables_walked = walk_order(Object.keys(raw.rows));
243
+ for (const table of tables_walked) {
244
+ const columns = raw.columns[table] ?? {};
245
+ for (const row of raw.rows[table] ?? []) {
246
+ const created = row_created_micros(row, columns);
247
+ for (const [column, value] of Object.entries(row)) {
248
+ if (created !== null && is_expiry(column, value))
249
+ continue;
250
+ if (SET_ONLY_COLUMNS.has(`${table}.${column}`))
251
+ continue;
252
+ if (TIMESTAMP_UDTS.has(columns[column] ?? '') && typeof value === 'string') {
253
+ add_instant(value);
254
+ }
255
+ else {
256
+ visit_strings(value, (s) => {
257
+ for (const m of s.matchAll(WIRE_TIMESTAMP_PATTERN))
258
+ add_instant(m[0]);
259
+ }, created !== null);
260
+ }
261
+ }
262
+ }
263
+ }
264
+ const ranks = new Map([...instants].sort((x, y) => (x < y ? -1 : x > y ? 1 : 0)).map((t, i) => [t, i + 1]));
265
+ const rank_of = (s) => {
266
+ const micros = timestamp_micros(s);
267
+ return micros === null ? s : `<t:${ranks.get(micros)}>`;
268
+ };
269
+ // positional placeholders, numbered as the walk first meets each value
270
+ const seen = new Map();
271
+ const placeholder = (kind, value, assign) => {
272
+ let values = seen.get(kind);
273
+ if (!values) {
274
+ values = new Map();
275
+ seen.set(kind, values);
276
+ }
277
+ const p = values.get(value);
278
+ if (p !== undefined)
279
+ return p;
280
+ if (!assign)
281
+ return `<${kind}:?>`;
282
+ const next = `<${kind}:${values.size + 1}>`;
283
+ values.set(value, next);
284
+ return next;
285
+ };
286
+ const normalize_string = (value, assign) => value
287
+ .replace(/secret_fuz_token_[A-Za-z0-9_-]+/g, '<token>')
288
+ .replace(/(?<![\w-])tok_[\w-]{12}(?![\w-])/g, (m) => placeholder('tok', m, assign))
289
+ .replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/g, (m) => placeholder('id', m, assign))
290
+ .replace(GENERATED_USERNAMES, (m) => placeholder('username', m, assign))
291
+ .replace(WIRE_TIMESTAMP_PATTERN, rank_of)
292
+ .replace(/(?<!\w|blake3:)[0-9a-f]{64}(?!\w)/g, '<hash>');
293
+ /** An expiry's offset from `created`, or `null` when it is no timestamp or the row has no creation. */
294
+ const expiry_offset = (key, value, created) => created !== null && is_expiry(key, value)
295
+ ? format_expiry_offset(timestamp_micros(value), created)
296
+ : null;
297
+ const normalize_json = (value, assign, created) => {
298
+ if (typeof value === 'string')
299
+ return normalize_string(value, assign);
300
+ if (Array.isArray(value))
301
+ return value.map((v) => normalize_json(v, assign, created));
302
+ if (is_record(value)) {
303
+ const out = {};
304
+ for (const key of Object.keys(value).sort(compare_text)) {
305
+ const offset = expiry_offset(key, value[key], created);
306
+ out[normalize_string(key, assign)] = offset ?? normalize_json(value[key], assign, created);
307
+ }
308
+ return out;
309
+ }
310
+ return value;
311
+ };
312
+ const tables = {};
313
+ for (const table of tables_walked) {
314
+ const columns = raw.columns[table] ?? {};
315
+ const rows = raw.rows[table] ?? [];
316
+ const seqs = rows.map((r) => r.seq).filter((s) => typeof s === 'number');
317
+ const seq_min = seqs.length > 0 ? Math.min(...seqs) : 0;
318
+ const normalize_row = (row, assign) => {
319
+ const out = {};
320
+ const created = row_created_micros(row, columns);
321
+ for (const column of Object.keys(row).sort(compare_text)) {
322
+ const value = row[column];
323
+ const offset = expiry_offset(column, value, created);
324
+ if (value === null)
325
+ out[column] = null;
326
+ else if (SET_ONLY_COLUMNS.has(`${table}.${column}`))
327
+ out[column] = SET_MARKER;
328
+ else if (offset !== null)
329
+ out[column] = offset;
330
+ else if (TIMESTAMP_UDTS.has(columns[column] ?? '') && typeof value === 'string') {
331
+ out[column] = rank_of(value);
332
+ }
333
+ else if (column === 'seq' && typeof value === 'number') {
334
+ out[column] = value - seq_min;
335
+ }
336
+ else if (column === 'password_hash' && typeof value === 'string') {
337
+ const argon2 = ARGON2_PREFIX.exec(value);
338
+ out[column] = argon2 ? `${argon2[1]}$<salt>$<hash>` : value;
339
+ }
340
+ else
341
+ out[column] = normalize_json(value, assign, created);
342
+ }
343
+ return out;
344
+ };
345
+ // the sort key: the table's sort columns, then the row with no id
346
+ // numbered yet, ranks and offsets padded so they sort as numbers; a tie
347
+ // falls back to the raw row, which differs per backend
348
+ const sort_columns = DB_STATE_SORT_KEYS[table] ?? [];
349
+ const keyed = rows.map((row) => {
350
+ const normalized = normalize_row(row, false);
351
+ return {
352
+ row,
353
+ key: sortable(JSON.stringify([sort_columns.map((c) => normalized[c] ?? null), normalized])),
354
+ tie: JSON.stringify(row)
355
+ };
356
+ });
357
+ keyed.sort((x, y) => compare_text(x.key, y.key) || compare_text(x.tie, y.tie));
358
+ tables[table] = keyed.map((k) => normalize_row(k.row, true));
359
+ }
360
+ return { tables, audit_seq_advance: raw.audit_seq_advance };
361
+ };
362
+ /**
363
+ * Every place two normalized states differ, under `db.`: each table's rows
364
+ * by position, then `db.audit_seq_advance`.
365
+ *
366
+ * @param a - one backend's state
367
+ * @param b - the other's
368
+ * @returns the differences, empty when the states are equal
369
+ */
370
+ export const diff_db_states = (a, b) => [
371
+ ...diff_differential_values('db', a.tables, b.tables),
372
+ ...diff_differential_values('db.audit_seq_advance', a.audit_seq_advance, b.audit_seq_advance)
373
+ ];
374
+ const read_audit_seq = async (db) => {
375
+ const [row] = await db.query(`SELECT last_value, is_called FROM audit_log_seq_seq`);
376
+ if (!row)
377
+ throw new Error('db state: audit_log_seq_seq has no row');
378
+ const last = Number(row.last_value);
379
+ return row.is_called ? last : last - 1;
380
+ };
381
+ /**
382
+ * A probe over a backend's database, read directly — the backend's
383
+ * `env.DATABASE_URL` must be a PostgreSQL URL the test process reaches. The
384
+ * read drains the backend's in-flight detached writes (audit rows; on the
385
+ * Rust spine also the token touch and the bootstrap write) first
386
+ * (`_testing_drain_effects`, on the daemon token), so a WebSocket mutation's
387
+ * row has landed.
388
+ *
389
+ * @param handle - the backend
390
+ * @returns the probe; `close` it once its reads are done
391
+ */
392
+ export const create_db_state_probe = (handle) => {
393
+ const { config } = handle;
394
+ const database_url = config.env.DATABASE_URL ?? '';
395
+ if (!/^postgres(ql)?:\/\//.test(database_url)) {
396
+ throw new Error(`db state (${config.name}): DATABASE_URL is not a PostgreSQL URL the test process can read`);
397
+ }
398
+ let opened = null;
399
+ let columns = null;
400
+ const open = () => (opened ??= create_db(database_url));
401
+ const drain_fixture = {
402
+ fresh_transport: (options) => create_fetch_transport({
403
+ base_url: config.base_url,
404
+ ...(options?.origin !== undefined && { origin: options.origin })
405
+ }),
406
+ create_session_headers: () => ({}),
407
+ create_daemon_token_headers: (extra) => ({
408
+ [DAEMON_TOKEN_HEADER]: handle.daemon_token,
409
+ ...extra
410
+ })
411
+ };
412
+ return {
413
+ mark: async () => ({ audit_seq: await read_audit_seq((await open()).db) }),
414
+ read: async (mark) => {
415
+ await cross_drain_effects(drain_fixture, config.rpc_path);
416
+ const { db } = await open();
417
+ if (!columns) {
418
+ const snapshot = await query_schema_snapshot(db, {
419
+ exclude_tables: DB_STATE_EXCLUDED_TABLES
420
+ });
421
+ const found = {};
422
+ for (const [table, t] of Object.entries(snapshot.tables)) {
423
+ found[table] = Object.fromEntries(Object.entries(t.columns).map(([column, c]) => [column, c.udt_name]));
424
+ }
425
+ columns = found;
426
+ }
427
+ const rows = {};
428
+ for (const table of Object.keys(columns)) {
429
+ assert_valid_sql_identifier(table);
430
+ const read = await db.query(`SELECT to_jsonb(t) AS row FROM ${table} t`);
431
+ rows[table] = read.map((r) => r.row);
432
+ }
433
+ const audit_seq_advance = (await read_audit_seq(db)) - mark.audit_seq;
434
+ return normalize_db_state({ columns, rows, audit_seq_advance });
435
+ },
436
+ close: async () => {
437
+ if (!opened)
438
+ return;
439
+ const { close } = await opened;
440
+ opened = null;
441
+ await close();
442
+ }
443
+ };
444
+ };
@@ -0,0 +1,68 @@
1
+ import '../assert_dev_env.js';
2
+ declare module 'vitest' {
3
+ interface TaskMeta {
4
+ /**
5
+ * Set on a test registered skipped because the backend lacks what it
6
+ * gates on (`test_skip_gated`) — the skips `check_declared_skips`
7
+ * holds to a declared list.
8
+ */
9
+ fuz_gated_skip?: true;
10
+ }
11
+ }
12
+ /** The name of the test `check_declared_skips` registers. */
13
+ export declare const DECLARED_SKIPS_CHECK_NAME = "every gated skip is declared";
14
+ /**
15
+ * Register `fn` as a skipped test, tagged as a gated skip — the skip a backend
16
+ * owes a declaration for (`check_declared_skips`). `test_if` registers its
17
+ * skipped cases through it.
18
+ *
19
+ * @param name - the test name
20
+ * @param fn - the test body, never run
21
+ */
22
+ export declare const test_skip_gated: (name: string, fn: () => void | Promise<void>) => void;
23
+ /**
24
+ * Whether `task` was registered by `test_skip_gated`.
25
+ *
26
+ * @param task - a collected task
27
+ */
28
+ export declare const is_gated_skip: (task: {
29
+ readonly meta?: object;
30
+ }) => boolean;
31
+ /** A collected test, by its name path, and whether it is a gated skip. */
32
+ export interface CollectedTest {
33
+ readonly path: string;
34
+ readonly gated_skip: boolean;
35
+ }
36
+ /**
37
+ * Hold the collected tests' gated skips to `expected` — the pure half of
38
+ * `check_declared_skips`.
39
+ *
40
+ * @param expected - test name path to the reason it skips
41
+ * @param tests - every collected test under the checked suite
42
+ * @returns one line per problem: an undeclared skip, a declared skip
43
+ * registered to run, or a declared path naming no test
44
+ */
45
+ export declare const find_declared_skip_problems: (expected: Readonly<Record<string, string>>, tests: Iterable<CollectedTest>) => Array<string>;
46
+ /**
47
+ * Validate `expected`'s reasons.
48
+ *
49
+ * @param expected - test name path to the reason it skips
50
+ * @param label - who passed it, for the error
51
+ * @throws Error - naming every entry with an empty reason
52
+ */
53
+ export declare const assert_declared_skip_reasons: (expected: Readonly<Record<string, string>>, label: string) => void;
54
+ /**
55
+ * Register a closing test that holds every gated skip under the current suite
56
+ * (the enclosing `describe`, or the file) to `expected` — see the module doc.
57
+ * A nested suite with a check of its own owns its subtree: this check
58
+ * neither collects nor needs declared what sits below it.
59
+ * The paths are read from the collected tree when the test runs, so tests
60
+ * registered after the call count, and a filtered run checks the same paths
61
+ * as a whole one.
62
+ *
63
+ * @param expected - test name path below the current suite to the reason it
64
+ * skips on this backend; `{}` when nothing may skip
65
+ * @throws Error - at collection, on an entry with no reason
66
+ */
67
+ export declare const check_declared_skips: (expected: Readonly<Record<string, string>>) => void;
68
+ //# sourceMappingURL=declared_skips.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declared_skips.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/declared_skips.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AA0B9B,OAAO,QAAQ,QAAQ,CAAC;IACvB,UAAU,QAAQ;QACjB;;;;WAIG;QACH,cAAc,CAAC,EAAE,IAAI,CAAC;KACtB;CACD;AAED,6DAA6D;AAC7D,eAAO,MAAM,yBAAyB,iCAAiC,CAAC;AAExE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,IAAI,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAG,IAE9E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KAAG,OACgB,CAAC;AAElF,0EAA0E;AAC1E,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GACvC,UAAU,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAC1C,OAAO,QAAQ,CAAC,aAAa,CAAC,KAC5B,KAAK,CAAC,MAAM,CAiBd,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GACxC,UAAU,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAC1C,OAAO,MAAM,KACX,IAOF,CAAC;AA4BF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,GAAI,UAAU,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,KAAG,IAUjF,CAAC"}