@feltdb/core 0.13.0 → 0.16.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 (300) hide show
  1. package/dist/agent-runtime.d.ts +64 -2
  2. package/dist/agent-runtime.d.ts.map +1 -1
  3. package/dist/agent-runtime.js +121 -11
  4. package/dist/agent-state.d.ts +68 -0
  5. package/dist/agent-state.d.ts.map +1 -1
  6. package/dist/agent-state.js +210 -12
  7. package/dist/agent.d.ts +10 -1
  8. package/dist/agent.d.ts.map +1 -1
  9. package/dist/agent.js +10 -1
  10. package/dist/build-identity.json +12 -4
  11. package/dist/cli/commands.js +214 -10
  12. package/dist/cli/publish-engine.js +116 -16
  13. package/dist/collection.d.ts +3 -1
  14. package/dist/collection.d.ts.map +1 -1
  15. package/dist/collection.js +33 -8
  16. package/dist/create/build-identity.json +12 -4
  17. package/dist/create/cli.js +1 -1
  18. package/dist/create/create.js +4 -6
  19. package/dist/create/managed-account.js +93 -35
  20. package/dist/create/package-versions.js +1 -1
  21. package/dist/create/server-source/Cargo.lock +8 -511
  22. package/dist/create/server-source/Cargo.toml +2 -13
  23. package/dist/create/server-source/crates/feltdb-client/Cargo.toml +1 -1
  24. package/dist/create/server-source/crates/feltdb-server/Cargo.toml +1 -1
  25. package/dist/create/server-source/crates/feltdb-server/README.md +6 -1
  26. package/dist/create/server-source/crates/feltdb-server/src/app_state.rs +9 -1
  27. package/dist/create/server-source/crates/feltdb-server/src/auth.rs +85 -25
  28. package/dist/create/server-source/crates/feltdb-server/src/backup.rs +4 -0
  29. package/dist/create/server-source/crates/feltdb-server/src/console_accounts.rs +1009 -0
  30. package/dist/create/server-source/crates/feltdb-server/src/control_authorization.rs +441 -0
  31. package/dist/create/server-source/crates/feltdb-server/src/identity.rs +68 -6
  32. package/dist/create/server-source/crates/feltdb-server/src/key_management.rs +355 -23
  33. package/dist/create/server-source/crates/feltdb-server/src/lib.rs +3 -0
  34. package/dist/create/server-source/crates/feltdb-server/src/main.rs +1134 -96
  35. package/dist/create/server-source/crates/feltdb-server/src/redaction.rs +208 -0
  36. package/dist/create/server-source/crates/feltdb-server/src/tenancy.rs +198 -19
  37. package/dist/create/server-source/crates/feltdb-server/tests/transaction_precondition_contract.rs +403 -0
  38. package/dist/create/server-source/crates/feltdb-wasm/Cargo.toml +1 -1
  39. package/dist/db.d.ts +75 -10
  40. package/dist/db.d.ts.map +1 -1
  41. package/dist/db.js +168 -29
  42. package/dist/deployment.d.ts +19 -0
  43. package/dist/deployment.d.ts.map +1 -1
  44. package/dist/deployment.js +38 -2
  45. package/dist/embedded-query.d.ts.map +1 -1
  46. package/dist/embedded-query.js +5 -4
  47. package/dist/embedded-transaction.d.ts +8 -4
  48. package/dist/embedded-transaction.d.ts.map +1 -1
  49. package/dist/embedded-transaction.js +55 -19
  50. package/dist/error-codes.d.ts +36 -2
  51. package/dist/error-codes.d.ts.map +1 -1
  52. package/dist/error-codes.js +50 -3
  53. package/dist/feltdb.d.ts +7 -0
  54. package/dist/feltdb.d.ts.map +1 -1
  55. package/dist/file-db.d.ts +27 -0
  56. package/dist/file-db.d.ts.map +1 -1
  57. package/dist/file-db.js +145 -7
  58. package/dist/http-client.d.ts +11 -3
  59. package/dist/http-client.d.ts.map +1 -1
  60. package/dist/http-client.js +27 -14
  61. package/dist/http-db.d.ts +43 -1
  62. package/dist/http-db.d.ts.map +1 -1
  63. package/dist/http-db.js +287 -59
  64. package/dist/index.js +1 -1
  65. package/dist/local-state-lock.d.ts +34 -0
  66. package/dist/local-state-lock.d.ts.map +1 -0
  67. package/dist/local-state-lock.js +225 -0
  68. package/dist/managed-recovery.d.ts +6 -0
  69. package/dist/managed-recovery.d.ts.map +1 -1
  70. package/dist/managed-recovery.js +9 -0
  71. package/dist/reactive-graph.d.ts +0 -3
  72. package/dist/reactive-graph.d.ts.map +1 -1
  73. package/dist/reactive-graph.js +11 -1
  74. package/dist/runtime-registry.d.ts +7 -2
  75. package/dist/runtime-registry.d.ts.map +1 -1
  76. package/dist/runtime-registry.js +2 -2
  77. package/dist/studio/components/index.js +1 -1
  78. package/dist/studio/{components-BSGmHfif.js → components-CJmzntBi.js} +2 -1
  79. package/dist/studio/index.js +1 -1
  80. package/dist/studio-app/assets/{feltdb_wasm-3hDngl1h.js → feltdb_wasm-DtybUY0q.js} +1 -1
  81. package/dist/studio-app/assets/feltdb_wasm_bg-DsgIUwaB.wasm +0 -0
  82. package/dist/studio-app/assets/index-C4OffsZl.js +37 -0
  83. package/dist/studio-app/index.html +1 -1
  84. package/dist/transaction.d.ts +27 -11
  85. package/dist/transaction.d.ts.map +1 -1
  86. package/dist/transaction.js +20 -14
  87. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  88. package/dist/wasm/package.json +1 -1
  89. package/dist/workload.d.ts +86 -6
  90. package/dist/workload.d.ts.map +1 -1
  91. package/dist/workload.js +51 -3
  92. package/dist/workspace/workspace-connection.d.ts.map +1 -1
  93. package/dist/workspace/workspace-connection.js +14 -3
  94. package/package.json +1 -1
  95. package/dist/create/server-source/crates/feltdb/Cargo.lock +0 -175
  96. package/dist/create/server-source/crates/feltdb/Cargo.toml +0 -102
  97. package/dist/create/server-source/crates/feltdb/LICENSE +0 -21
  98. package/dist/create/server-source/crates/feltdb/README.md +0 -75
  99. package/dist/create/server-source/crates/feltdb/benches/baselines/gate-13-redux.json +0 -370
  100. package/dist/create/server-source/crates/feltdb/benches/gate13_baseline.rs +0 -589
  101. package/dist/create/server-source/crates/feltdb/benches/gate13_phase_7_1_release_economics.rs +0 -247
  102. package/dist/create/server-source/crates/feltdb/benches/gate_13_redux.rs +0 -440
  103. package/dist/create/server-source/crates/feltdb/benches/gate_13_regression_runner.rs +0 -275
  104. package/dist/create/server-source/crates/feltdb/benches/gate_14a_concurrent_writer_scaling.rs +0 -381
  105. package/dist/create/server-source/crates/feltdb/benches/gate_14a_production_admission_revalidation.rs +0 -467
  106. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc2_admission_contract.rs +0 -489
  107. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc_root_cause.rs +0 -281
  108. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync1_queued_prototype.rs +0 -606
  109. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync_economics.rs +0 -531
  110. package/dist/create/server-source/crates/feltdb/benches/gate_14b_causal_backlog_scaling.rs +0 -462
  111. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_contract_test.rs +0 -505
  112. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_scaling.rs +0 -484
  113. package/dist/create/server-source/crates/feltdb/benches/gate_14d_combined_dimension_scaling.rs +0 -758
  114. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_2_optimization_benchmark.rs +0 -421
  115. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_3_crossover_analysis.rs +0 -329
  116. package/dist/create/server-source/crates/feltdb/src/acceptance_tests.rs +0 -1705
  117. package/dist/create/server-source/crates/feltdb/src/acquisition.rs +0 -286
  118. package/dist/create/server-source/crates/feltdb/src/admission.rs +0 -185
  119. package/dist/create/server-source/crates/feltdb/src/admission_contract_tests.rs +0 -507
  120. package/dist/create/server-source/crates/feltdb/src/adversarial_transport.rs +0 -539
  121. package/dist/create/server-source/crates/feltdb/src/agent_state.rs +0 -320
  122. package/dist/create/server-source/crates/feltdb/src/agent_transition_contract.rs +0 -1545
  123. package/dist/create/server-source/crates/feltdb/src/analytics.rs +0 -521
  124. package/dist/create/server-source/crates/feltdb/src/application.rs +0 -2674
  125. package/dist/create/server-source/crates/feltdb/src/application_runtime.rs +0 -1070
  126. package/dist/create/server-source/crates/feltdb/src/authority.rs +0 -479
  127. package/dist/create/server-source/crates/feltdb/src/authority_failover.rs +0 -847
  128. package/dist/create/server-source/crates/feltdb/src/authorization.rs +0 -1030
  129. package/dist/create/server-source/crates/feltdb/src/authorization_security_tests.rs +0 -1122
  130. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority-client.rs +0 -32
  131. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority.rs +0 -19
  132. package/dist/create/server-source/crates/feltdb/src/bin/feltdb_node.rs +0 -1474
  133. package/dist/create/server-source/crates/feltdb/src/capabilities/mod.rs +0 -8
  134. package/dist/create/server-source/crates/feltdb/src/capabilities/search.rs +0 -418
  135. package/dist/create/server-source/crates/feltdb/src/capabilities/vector.rs +0 -482
  136. package/dist/create/server-source/crates/feltdb/src/capability.rs +0 -903
  137. package/dist/create/server-source/crates/feltdb/src/cardinality_diagnostics.rs +0 -263
  138. package/dist/create/server-source/crates/feltdb/src/cardinality_endpoint.rs +0 -77
  139. package/dist/create/server-source/crates/feltdb/src/causal_backlog_bound.rs +0 -496
  140. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier.rs +0 -2574
  141. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier_phase_7_1.rs +0 -212
  142. package/dist/create/server-source/crates/feltdb/src/concurrency_fuzzing.rs +0 -422
  143. package/dist/create/server-source/crates/feltdb/src/consistency_contract.rs +0 -445
  144. package/dist/create/server-source/crates/feltdb/src/content_distribution.rs +0 -465
  145. package/dist/create/server-source/crates/feltdb/src/convergence.rs +0 -634
  146. package/dist/create/server-source/crates/feltdb/src/crash_atomic_boundary.rs +0 -427
  147. package/dist/create/server-source/crates/feltdb/src/crash_injection.rs +0 -376
  148. package/dist/create/server-source/crates/feltdb/src/crash_recovery_tests.rs +0 -365
  149. package/dist/create/server-source/crates/feltdb/src/cron.rs +0 -294
  150. package/dist/create/server-source/crates/feltdb/src/dedup_bound_investigation.rs +0 -483
  151. package/dist/create/server-source/crates/feltdb/src/distributed_indexing.rs +0 -477
  152. package/dist/create/server-source/crates/feltdb/src/distributed_tests.rs +0 -1003
  153. package/dist/create/server-source/crates/feltdb/src/distributed_transactions.rs +0 -1334
  154. package/dist/create/server-source/crates/feltdb/src/durability_guarantees.rs +0 -368
  155. package/dist/create/server-source/crates/feltdb/src/durable_dedup_set.rs +0 -231
  156. package/dist/create/server-source/crates/feltdb/src/durable_operation_identity.rs +0 -482
  157. package/dist/create/server-source/crates/feltdb/src/durable_operation_log.rs +0 -203
  158. package/dist/create/server-source/crates/feltdb/src/durable_sync.rs +0 -317
  159. package/dist/create/server-source/crates/feltdb/src/equality_index.rs +0 -595
  160. package/dist/create/server-source/crates/feltdb/src/execution.rs +0 -426
  161. package/dist/create/server-source/crates/feltdb/src/in_process_transport.rs +0 -214
  162. package/dist/create/server-source/crates/feltdb/src/indexing.rs +0 -776
  163. package/dist/create/server-source/crates/feltdb/src/lib.rs +0 -7274
  164. package/dist/create/server-source/crates/feltdb/src/managed_cas_tests.rs +0 -234
  165. package/dist/create/server-source/crates/feltdb/src/materialization.rs +0 -184
  166. package/dist/create/server-source/crates/feltdb/src/metrics.rs +0 -266
  167. package/dist/create/server-source/crates/feltdb/src/multi_node_convergence.rs +0 -310
  168. package/dist/create/server-source/crates/feltdb/src/multi_operation_transaction.rs +0 -736
  169. package/dist/create/server-source/crates/feltdb/src/observability.rs +0 -379
  170. package/dist/create/server-source/crates/feltdb/src/operation.rs +0 -290
  171. package/dist/create/server-source/crates/feltdb/src/operation_algebra.rs +0 -439
  172. package/dist/create/server-source/crates/feltdb/src/operation_log.rs +0 -349
  173. package/dist/create/server-source/crates/feltdb/src/p1_application_atomicity.rs +0 -332
  174. package/dist/create/server-source/crates/feltdb/src/p1_atomicity_acceptance.rs +0 -718
  175. package/dist/create/server-source/crates/feltdb/src/partition_reconciliation.rs +0 -487
  176. package/dist/create/server-source/crates/feltdb/src/peer_registry.rs +0 -166
  177. package/dist/create/server-source/crates/feltdb/src/permutation_scheduler.rs +0 -289
  178. package/dist/create/server-source/crates/feltdb/src/persistence_reality.rs +0 -566
  179. package/dist/create/server-source/crates/feltdb/src/phase1b_acceptance.rs +0 -3391
  180. package/dist/create/server-source/crates/feltdb/src/phase1c1_acceptance.rs +0 -203
  181. package/dist/create/server-source/crates/feltdb/src/phase1c2_acceptance.rs +0 -261
  182. package/dist/create/server-source/crates/feltdb/src/phase1c3_acceptance.rs +0 -502
  183. package/dist/create/server-source/crates/feltdb/src/phase1c_atomicity_proof.rs +0 -216
  184. package/dist/create/server-source/crates/feltdb/src/phase5_integration.rs +0 -303
  185. package/dist/create/server-source/crates/feltdb/src/phase5_scenarios.rs +0 -323
  186. package/dist/create/server-source/crates/feltdb/src/phase6_adversarial_scenarios.rs +0 -531
  187. package/dist/create/server-source/crates/feltdb/src/phase6_convergence_validator.rs +0 -406
  188. package/dist/create/server-source/crates/feltdb/src/phase6_persistence.rs +0 -436
  189. package/dist/create/server-source/crates/feltdb/src/phase_1c_real_tcp.rs +0 -387
  190. package/dist/create/server-source/crates/feltdb/src/phase_2a_failures.rs +0 -378
  191. package/dist/create/server-source/crates/feltdb/src/phase_2b_network.rs +0 -359
  192. package/dist/create/server-source/crates/feltdb/src/phase_2c_cascading.rs +0 -372
  193. package/dist/create/server-source/crates/feltdb/src/phase_3_durability.rs +0 -404
  194. package/dist/create/server-source/crates/feltdb/src/phase_4_baseline.rs +0 -376
  195. package/dist/create/server-source/crates/feltdb/src/phase_5_soak.rs +0 -461
  196. package/dist/create/server-source/crates/feltdb/src/policy_evaluation.rs +0 -2125
  197. package/dist/create/server-source/crates/feltdb/src/production_api.rs +0 -418
  198. package/dist/create/server-source/crates/feltdb/src/provenance.rs +0 -207
  199. package/dist/create/server-source/crates/feltdb/src/query_execution_diagnostics.rs +0 -126
  200. package/dist/create/server-source/crates/feltdb/src/query_performance.rs +0 -218
  201. package/dist/create/server-source/crates/feltdb/src/read_basis.rs +0 -257
  202. package/dist/create/server-source/crates/feltdb/src/references.rs +0 -404
  203. package/dist/create/server-source/crates/feltdb/src/replay_fuzzing.rs +0 -401
  204. package/dist/create/server-source/crates/feltdb/src/replica_acknowledgements.rs +0 -501
  205. package/dist/create/server-source/crates/feltdb/src/replica_membership.rs +0 -680
  206. package/dist/create/server-source/crates/feltdb/src/replication_manager.rs +0 -163
  207. package/dist/create/server-source/crates/feltdb/src/replication_protocol.rs +0 -133
  208. package/dist/create/server-source/crates/feltdb/src/routing.rs +0 -409
  209. package/dist/create/server-source/crates/feltdb/src/semantic_decision.rs +0 -2029
  210. package/dist/create/server-source/crates/feltdb/src/semantic_query.rs +0 -599
  211. package/dist/create/server-source/crates/feltdb/src/sharding.rs +0 -549
  212. package/dist/create/server-source/crates/feltdb/src/state_conflict_contract.rs +0 -516
  213. package/dist/create/server-source/crates/feltdb/src/state_contract.rs +0 -5894
  214. package/dist/create/server-source/crates/feltdb/src/state_diff_contract.rs +0 -222
  215. package/dist/create/server-source/crates/feltdb/src/state_facade.rs +0 -320
  216. package/dist/create/server-source/crates/feltdb/src/state_hash.rs +0 -291
  217. package/dist/create/server-source/crates/feltdb/src/state_model.rs +0 -4158
  218. package/dist/create/server-source/crates/feltdb/src/state_transition_store.rs +0 -379
  219. package/dist/create/server-source/crates/feltdb/src/state_trigger.rs +0 -673
  220. package/dist/create/server-source/crates/feltdb/src/storage.rs +0 -273
  221. package/dist/create/server-source/crates/feltdb/src/submission.rs +0 -471
  222. package/dist/create/server-source/crates/feltdb/src/sync.rs +0 -495
  223. package/dist/create/server-source/crates/feltdb/src/sync_contract.rs +0 -822
  224. package/dist/create/server-source/crates/feltdb/src/tcp_transport.rs +0 -433
  225. package/dist/create/server-source/crates/feltdb/src/transaction_api.rs +0 -462
  226. package/dist/create/server-source/crates/feltdb/src/transaction_invariants.rs +0 -965
  227. package/dist/create/server-source/crates/feltdb/src/transaction_preconditions.rs +0 -1120
  228. package/dist/create/server-source/crates/feltdb/src/transactions.rs +0 -643
  229. package/dist/create/server-source/crates/feltdb/src/trigger.rs +0 -390
  230. package/dist/create/server-source/crates/feltdb/src/trigger_contract.rs +0 -749
  231. package/dist/create/server-source/crates/feltdb/src/versioned_object_substrate.rs +0 -708
  232. package/dist/create/server-source/crates/feltdb/src/worker_mesh.rs +0 -1133
  233. package/dist/create/server-source/crates/feltdb/src/workflow.rs +0 -713
  234. package/dist/create/server-source/crates/feltdb/src/workflow_acceptance_tests.rs +0 -510
  235. package/dist/create/server-source/crates/feltdb/src/workflow_integration.rs +0 -354
  236. package/dist/create/server-source/crates/feltdb/src/workflow_runtime.rs +0 -594
  237. package/dist/create/server-source/crates/feltdb/src/workload.rs +0 -2886
  238. package/dist/create/server-source/crates/feltdb/src/workload_diagnostics.rs +0 -456
  239. package/dist/create/server-source/crates/feltdb/tests/agent_state_native.rs +0 -1188
  240. package/dist/create/server-source/crates/feltdb/tests/agent_transition_contract_conformance.rs +0 -2884
  241. package/dist/create/server-source/crates/feltdb/tests/authority_process.rs +0 -297
  242. package/dist/create/server-source/crates/feltdb/tests/authority_transaction_identity.rs +0 -534
  243. package/dist/create/server-source/crates/feltdb/tests/bounded_read_contract.rs +0 -132
  244. package/dist/create/server-source/crates/feltdb/tests/branching_evidence.rs +0 -299
  245. package/dist/create/server-source/crates/feltdb/tests/common/mod.rs +0 -96
  246. package/dist/create/server-source/crates/feltdb/tests/compaction_stall_contract.rs +0 -272
  247. package/dist/create/server-source/crates/feltdb/tests/crash_durability_contract.rs +0 -467
  248. package/dist/create/server-source/crates/feltdb/tests/current_revision_authority_evidence.rs +0 -309
  249. package/dist/create/server-source/crates/feltdb/tests/durable_backup_contract.rs +0 -445
  250. package/dist/create/server-source/crates/feltdb/tests/durable_corruption_contract.rs +0 -518
  251. package/dist/create/server-source/crates/feltdb/tests/durable_format_compatibility.rs +0 -392
  252. package/dist/create/server-source/crates/feltdb/tests/feltdb_state_boundary_tests.rs +0 -850
  253. package/dist/create/server-source/crates/feltdb/tests/fixtures/agent_transition_corpus.json +0 -23340
  254. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_conflict_contract_corpus.json +0 -1916
  255. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_diff_contract_corpus.json +0 -1878
  256. package/dist/create/server-source/crates/feltdb/tests/fixtures/trigger_contract_corpus.json +0 -1862
  257. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_evidence.rs +0 -123
  258. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_substrate_completion.rs +0 -299
  259. package/dist/create/server-source/crates/feltdb/tests/local_process_ownership.rs +0 -69
  260. package/dist/create/server-source/crates/feltdb/tests/managed_incident_regression.rs +0 -191
  261. package/dist/create/server-source/crates/feltdb/tests/operational_health_contract.rs +0 -278
  262. package/dist/create/server-source/crates/feltdb/tests/pr34_query_collection.rs +0 -234
  263. package/dist/create/server-source/crates/feltdb/tests/pr35_equality_index.rs +0 -947
  264. package/dist/create/server-source/crates/feltdb/tests/pr7_self_authorization_proof.rs +0 -404
  265. package/dist/create/server-source/crates/feltdb/tests/pr8_vocabulary_assessment.rs +0 -916
  266. package/dist/create/server-source/crates/feltdb/tests/pr9_phase2_boundary_tests.rs +0 -1045
  267. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3a_path_a_tests.rs +0 -347
  268. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_authorized_mutations.rs +0 -361
  269. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_role_based_authorization.rs +0 -330
  270. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_simple_auth_delete.rs +0 -93
  271. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_team_delete_role_authorization.rs +0 -622
  272. package/dist/create/server-source/crates/feltdb/tests/pr9_teams_role_based_access.rs +0 -517
  273. package/dist/create/server-source/crates/feltdb/tests/production_certification.rs +0 -1153
  274. package/dist/create/server-source/crates/feltdb/tests/production_contract.rs +0 -771
  275. package/dist/create/server-source/crates/feltdb/tests/production_readiness_contract.rs +0 -1383
  276. package/dist/create/server-source/crates/feltdb/tests/reconciliation_application.rs +0 -868
  277. package/dist/create/server-source/crates/feltdb/tests/reconciliation_wire_format_evidence.rs +0 -221
  278. package/dist/create/server-source/crates/feltdb/tests/replicated_history_contract.rs +0 -417
  279. package/dist/create/server-source/crates/feltdb/tests/resource_scoped_revisions.rs +0 -338
  280. package/dist/create/server-source/crates/feltdb/tests/revision_identity_contract.rs +0 -1039
  281. package/dist/create/server-source/crates/feltdb/tests/revision_model_decision.rs +0 -739
  282. package/dist/create/server-source/crates/feltdb/tests/revision_retention_boundary_evidence.rs +0 -452
  283. package/dist/create/server-source/crates/feltdb/tests/saas_authorization_integration.rs +0 -81
  284. package/dist/create/server-source/crates/feltdb/tests/saas_invitation_lifecycle.rs +0 -438
  285. package/dist/create/server-source/crates/feltdb/tests/semantic_decision.rs +0 -1165
  286. package/dist/create/server-source/crates/feltdb/tests/semantic_query.rs +0 -767
  287. package/dist/create/server-source/crates/feltdb/tests/semantic_query_contract.rs +0 -363
  288. package/dist/create/server-source/crates/feltdb/tests/state_conflict_contract_conformance.rs +0 -1799
  289. package/dist/create/server-source/crates/feltdb/tests/state_diff_contract_conformance.rs +0 -1316
  290. package/dist/create/server-source/crates/feltdb/tests/state_model_integration.rs +0 -358
  291. package/dist/create/server-source/crates/feltdb/tests/state_persistence_integration.rs +0 -365
  292. package/dist/create/server-source/crates/feltdb/tests/state_ref_authority.rs +0 -918
  293. package/dist/create/server-source/crates/feltdb/tests/state_store_boundary_evidence.rs +0 -299
  294. package/dist/create/server-source/crates/feltdb/tests/storage_independent_versioned_object_substrate.rs +0 -328
  295. package/dist/create/server-source/crates/feltdb/tests/sync_divergence_evidence.rs +0 -255
  296. package/dist/create/server-source/crates/feltdb/tests/three_way_input_boundary_evidence.rs +0 -249
  297. package/dist/create/server-source/crates/feltdb/tests/trigger_contract_conformance.rs +0 -994
  298. package/dist/create/server-source/crates/feltdb/tests/workload_envelope_contract.rs +0 -484
  299. package/dist/studio-app/assets/feltdb_wasm_bg-CFQT4gCy.wasm +0 -0
  300. package/dist/studio-app/assets/index-Dql1hS5m.js +0 -30
@@ -1,299 +0,0 @@
1
- //! Executable evidence for the Live State Branching audit
2
- //! (`docs/audits/BRANCHING-AUDIT.md`).
3
- //!
4
- //! These tests add no capability. Every one of them only *observes* what
5
- //! `feltdb::state_model` already does, so that the audit's branching claims
6
- //! rest on a run rather than on a reading. Where a test asserts an absence, the
7
- //! absence is the finding: it is what separates "FeltDB has branching" from
8
- //! "FeltDB has the durable lineage half of branching".
9
-
10
- use feltdb::state_model::StateStore;
11
- use feltdb::{
12
- reconcile, ConflictClass, ConflictClassification, ReconciliationPlan, Relationship,
13
- SemanticDiff, StateTopology,
14
- };
15
- use serde_json::json;
16
- use std::sync::Arc;
17
- use tempfile::TempDir;
18
-
19
- fn durable_store(directory: &TempDir, name: &str) -> StateStore {
20
- let db = feltdb::FeltDb::open(directory.path().join(name)).expect("open");
21
- StateStore::with_feltdb(Arc::new(db)).expect("store")
22
- }
23
-
24
- /// Q2 — **superseded.** Named branches no longer exist; a revision *is* the
25
- /// durable reference.
26
- ///
27
- /// This test previously asserted that a branch is a durable named pointer at a
28
- /// `StateId` and survives a restart. Named branches were removed from
29
- /// `StateStore` because the record that held them, `state:current`, was the
30
- /// same record that held the global current pointer, and it carried both of the
31
- /// defects Q9 and Q11 recorded.
32
- ///
33
- /// What survives is the load-bearing part: a revision is durable, and it is
34
- /// addressed by an identity derived from its own content — which is exactly
35
- /// what a branch name pointed at. The name was an alias for a value the caller
36
- /// already had.
37
- #[test]
38
- fn a_revision_is_its_own_durable_reference_across_restart() {
39
- let directory = TempDir::new().unwrap();
40
- let base = {
41
- let store = durable_store(&directory, "state.log");
42
- store
43
- .create(
44
- "docs:1",
45
- json!({"balance": 100}).to_string(),
46
- "authority".into(),
47
- )
48
- .expect("create")
49
- };
50
-
51
- let reopened = durable_store(&directory, "state.log");
52
- let recovered = reopened
53
- .get(&base.id)
54
- .expect("a revision must survive a restart under its own identity");
55
- assert_eq!(recovered.content, base.content);
56
- assert!(
57
- recovered.verify_integrity(),
58
- "and still hash to the identity it was addressed by"
59
- );
60
- }
61
-
62
- /// Q3/Q4 — mutation is **not** copy-on-write, and revisions share nothing.
63
- ///
64
- /// Each revision carries the entire canonical state as its own `content`
65
- /// string. Two revisions that differ in one field still hold two full copies,
66
- /// so a "clone" costs the whole state. This is the storage half of branching
67
- /// FeltDB does not have.
68
- #[test]
69
- fn every_revision_holds_a_full_copy_of_state_rather_than_a_delta() {
70
- let store = StateStore::new_volatile();
71
- let filler = "x".repeat(4096);
72
- let base = store
73
- .create(
74
- "docs:1",
75
- json!({"blob": filler, "counter": 0}).to_string(),
76
- "a".into(),
77
- )
78
- .expect("create");
79
- let child = store
80
- .commit(
81
- json!({"blob": filler, "counter": 1}).to_string(),
82
- &base,
83
- "a".into(),
84
- )
85
- .expect("commit");
86
-
87
- // One field changed; both revisions are still full-size.
88
- assert!(base.content.len() > 4096);
89
- assert!(child.content.len() > 4096);
90
- assert_eq!(
91
- base.content.len(),
92
- child.content.len(),
93
- "a one-field change produced two same-sized full copies, not a delta"
94
- );
95
- // And the parent link is the only thing they share: no structural sharing.
96
- assert_eq!(child.parent_id.as_ref(), Some(&base.id));
97
- assert_ne!(base.content, child.content);
98
- }
99
-
100
- /// Q5/Q6/Q7 — divergence, deterministic diff and conflict classification all
101
- /// work, but the topology is a structure the *caller* has to assemble.
102
- ///
103
- /// `StateStore` exposes no topology of its own, so ancestry questions are only
104
- /// answerable by a caller that has already collected the revisions.
105
- #[test]
106
- fn divergence_diff_and_conflict_classification_work_over_a_caller_built_topology() {
107
- let store = StateStore::new_volatile();
108
- let base = store
109
- .create(
110
- "docs:1",
111
- json!({"alice": 100, "bob": 50}).to_string(),
112
- "a".into(),
113
- )
114
- .expect("create");
115
- let left = store
116
- .commit(
117
- json!({"alice": 150, "bob": 50}).to_string(),
118
- &base,
119
- "a".into(),
120
- )
121
- .expect("left");
122
- let right = store
123
- .commit(
124
- json!({"alice": 100, "bob": 150}).to_string(),
125
- &base,
126
- "a".into(),
127
- )
128
- .expect("right");
129
-
130
- let mut topology = StateTopology::new();
131
- for revision in [&base, &left, &right] {
132
- topology.add_revision(revision.clone());
133
- }
134
- assert!(matches!(
135
- topology.relationship(&left.id, &right.id),
136
- Relationship::Diverged
137
- ));
138
- assert_eq!(
139
- topology.common_ancestor(&left.id, &right.id),
140
- Some(base.id.clone())
141
- );
142
-
143
- let base_value = serde_json::from_str(&base.content).unwrap();
144
- let left_value = serde_json::from_str(&left.content).unwrap();
145
- let diff = SemanticDiff::compute(&base_value, &left_value);
146
- assert_eq!(diff.changes.len(), 1, "diff is deterministic and minimal");
147
-
148
- let classification = ConflictClassification::classify(&base, &left, &right);
149
- assert_eq!(classification.overall, ConflictClass::Independent);
150
- }
151
-
152
- /// Q8 — a plan can now be **applied**, but a branch still cannot be
153
- /// **reconciled**.
154
- ///
155
- /// `apply_reconciliation_plan` turns an explicitly chosen plan into canonical
156
- /// content, and `reconcile` materializes that content as a `StateRevision`
157
- /// through the ordinary revision model. That is the half this evidence used to
158
- /// record as missing entirely.
159
- ///
160
- /// What is still missing is the other half, and it is the half that would make
161
- /// this "branch reconciliation": nothing *chooses* a plan, and applying one
162
- /// moves no branch head. The caller supplies the parent choice and every
163
- /// override, and the branch points exactly where it did afterwards. FeltDB
164
- /// materializes the decision; it does not make it, and it does not record it as
165
- /// the branch's new position.
166
- #[test]
167
- fn a_plan_can_be_applied_but_applying_one_reconciles_no_branch() {
168
- let store = StateStore::new_volatile();
169
- let base = store
170
- .create(
171
- "docs:1",
172
- json!({"alice": 100, "bob": 50}).to_string(),
173
- "a".into(),
174
- )
175
- .expect("create");
176
- let left = store
177
- .commit(
178
- json!({"alice": 150, "bob": 50}).to_string(),
179
- &base,
180
- "a".into(),
181
- )
182
- .expect("left");
183
- let right = store
184
- .commit(
185
- json!({"alice": 100, "bob": 150}).to_string(),
186
- &base,
187
- "a".into(),
188
- )
189
- .expect("right");
190
- let plan = ReconciliationPlan::new(left.id.clone(), right.id.clone(), base.id.clone(), true)
191
- .with_override(vec![], json!({"alice": 150, "bob": 150}));
192
- assert!(plan.validate(), "the plan validates structurally");
193
-
194
- // The override is now read, and the plan is now applied.
195
- let result =
196
- reconcile(&base, &left, &right, &plan, "reconciler".into()).expect("the plan applies");
197
- assert_eq!(
198
- result.materialized_state.content,
199
- r#"{"alice":150,"bob":150}"#
200
- );
201
- assert_eq!(
202
- result.materialized_state.parent_id.as_ref(),
203
- Some(&left.id),
204
- "the chosen parent is the revision's parent"
205
- );
206
-
207
- // And nothing the plan started from changed. There is no branch head to
208
- // advance — the store keeps none — and both source revisions are exactly
209
- // as retrievable as before.
210
- assert_eq!(store.get(&left.id).unwrap().content, left.content);
211
- assert_eq!(store.get(&right.id).unwrap().content, right.content);
212
-
213
- // And nothing chose this plan. Classification reports the conflict; the
214
- // decision of what to do about it came from the caller.
215
- let classification = ConflictClassification::classify(&base, &left, &right);
216
- assert_eq!(classification.overall, ConflictClass::Independent);
217
- assert!(
218
- plan.unresolved_conflicts(&classification).is_empty(),
219
- "the plan covers what the classifier reported, because the caller made it so"
220
- );
221
- }
222
-
223
- /// Q9 — **the defect was removed rather than fixed.**
224
- ///
225
- /// The original finding: `create_branch` recorded one `StateId` and never
226
- /// moved, while *any* commit moved the store's single global `current` pointer,
227
- /// so "which revision is this branch on now" was a question the store could not
228
- /// answer after the first commit. Both halves of that — the frozen branch
229
- /// pointer and the promiscuous global `current` — lived in one record.
230
- ///
231
- /// Neither exists now. The store keeps no pointer, so there is none to be
232
- /// stale, and no commit can displace anything. Two siblings committed onto the
233
- /// same parent are simply two revisions, each addressed by its own identity,
234
- /// and the parent is untouched by either.
235
- ///
236
- /// What this deliberately does *not* claim is that "which revision is current"
237
- /// has been answered. It has been **removed from this layer**, and no owner for
238
- /// it has been introduced.
239
- #[test]
240
- fn no_commit_can_displace_another_revision_because_there_is_no_pointer() {
241
- let store = StateStore::new_volatile();
242
- let base = store
243
- .create("docs:1", json!({"v": 1}).to_string(), "a".into())
244
- .expect("create");
245
-
246
- let one = store
247
- .commit(
248
- json!({"v": 2, "side": "one"}).to_string(),
249
- &base,
250
- "a".into(),
251
- )
252
- .expect("commit one");
253
- let two = store
254
- .commit(
255
- json!({"v": 2, "side": "two"}).to_string(),
256
- &base,
257
- "a".into(),
258
- )
259
- .expect("commit two");
260
-
261
- // All three coexist, and neither sibling is privileged over the other.
262
- for revision in [&base, &one, &two] {
263
- assert_eq!(
264
- store.get(&revision.id).expect("still present").content,
265
- revision.content
266
- );
267
- }
268
- assert_eq!(store.parent(&one.id).unwrap().id, base.id);
269
- assert_eq!(store.parent(&two.id).unwrap().id, base.id);
270
- assert_ne!(one.id, two.id, "the siblings are distinct revisions");
271
- }
272
-
273
- /// Q12 — nothing collects an abandoned revision, and nothing can.
274
- ///
275
- /// Unchanged by the removal of branches, and worth re-recording because it is
276
- /// now the *only* remaining retention finding. Every revision ever committed
277
- /// stays in the store and on disk. There is no refcount, no unreachability
278
- /// sweep, and no delete.
279
- #[test]
280
- fn abandoned_revisions_are_retained_with_no_way_to_drop_them() {
281
- let directory = TempDir::new().unwrap();
282
- let abandoned = {
283
- let store = durable_store(&directory, "state.log");
284
- let base = store
285
- .create("docs:1", json!({"v": 1}).to_string(), "a".into())
286
- .expect("create");
287
- // Nobody will ever ask for this revision again, and there is no way to
288
- // tell the store that.
289
- store
290
- .commit(json!({"v": 2}).to_string(), &base, "a".into())
291
- .expect("commit")
292
- };
293
-
294
- let reopened = durable_store(&directory, "state.log");
295
- assert!(
296
- reopened.exists(&abandoned.id),
297
- "an abandoned revision is still durable after restart"
298
- );
299
- }
@@ -1,96 +0,0 @@
1
- //! Shared rules for reading the certification and contract documents.
2
- //!
3
- //! Both `production_certification.rs` and `production_contract.rs` check
4
- //! published prose against an executable table, and both need the same answer
5
- //! to one awkward question: when does a document *assert* a guarantee, as
6
- //! opposed to naming one it is withholding? Defining that twice would be the
7
- //! same mistake the certification exists to prevent — two files quietly
8
- //! disagreeing — so it is defined once, here.
9
-
10
- #![allow(dead_code)]
11
-
12
- /// Split a markdown table row into its trimmed cells.
13
- ///
14
- /// Emphasis and code delimiters are stripped, so `**Proven**` and `` `E6` ``
15
- /// compare equal to the plain text they render.
16
- pub fn table_cells(line: &str) -> Option<Vec<String>> {
17
- let line = line.trim();
18
- if !line.starts_with('|') {
19
- return None;
20
- }
21
- Some(
22
- line.trim_matches('|')
23
- .split('|')
24
- .map(|cell| {
25
- cell.trim()
26
- .trim_matches('*')
27
- .trim()
28
- .trim_matches('`')
29
- .to_string()
30
- })
31
- .collect(),
32
- )
33
- }
34
-
35
- /// Does `text` *assert* `phrase`, as opposed to naming it?
36
- ///
37
- /// The distinction matters because the honest way to record a withheld
38
- /// guarantee is to quote it: `workload-envelope.md` says a test asserts no
39
- /// durability mode's wording contains "power-loss safe". A tripwire that
40
- /// flagged any occurrence would punish the document for being precise, and the
41
- /// cheapest way to satisfy it would be to stop naming the phrase at all — which
42
- /// is the opposite of what the tripwire is for.
43
- ///
44
- /// So an occurrence inside a quotation (`"..."`) or a code span (`` `...` ``)
45
- /// is a mention. Every other occurrence is an assertion. Quoting is judged per
46
- /// line, because a stray delimiter must not silence the rest of the file.
47
- pub fn asserts_phrase(text: &str, phrase: &str) -> bool {
48
- text.lines().any(|line| {
49
- if !line.contains(phrase) {
50
- return false;
51
- }
52
- let mut unquoted = String::new();
53
- let mut segment = String::new();
54
- let mut quoted = false;
55
- for character in line.chars() {
56
- if character == '"' || character == '`' {
57
- if !quoted {
58
- // A quotation opens here, so the text before it is asserted.
59
- unquoted.push_str(&segment);
60
- unquoted.push('\u{0}');
61
- }
62
- segment.clear();
63
- quoted = !quoted;
64
- } else {
65
- segment.push(character);
66
- }
67
- }
68
- // A delimiter that is never closed quotes nothing.
69
- unquoted.push_str(&segment);
70
- unquoted.contains(phrase)
71
- })
72
- }
73
-
74
- /// The document's prose, with rows that record a withheld verdict removed.
75
- ///
76
- /// A table row that names something next to a label withholding it — `Unproven`,
77
- /// `Not certified` — is recording a gap, not asserting a guarantee. Without
78
- /// this, a matrix would fail its own tripwire the moment it published a gap
79
- /// precisely, and the cheapest way to pass would be to stop naming the gap.
80
- ///
81
- /// Rows whose verdict cell *grants* the thing are deliberately not exempt: if
82
- /// one ever carried a forbidden phrase, the table and the phrase list would be
83
- /// in genuine contradiction and the tripwire should say so.
84
- pub fn prose_excluding_withheld_rows(document: &str, withheld: &[&str]) -> String {
85
- document
86
- .lines()
87
- .filter(|line| match table_cells(line) {
88
- None => true,
89
- Some(cells) => !cells
90
- .iter()
91
- .any(|cell| withheld.iter().any(|label| cell == label)),
92
- })
93
- .collect::<Vec<_>>()
94
- .join("\n")
95
- .to_lowercase()
96
- }
@@ -1,272 +0,0 @@
1
- //! Compaction must not stop the world on a timer.
2
- //!
3
- //! An incident on the managed deployment showed `/health` returning `200` while
4
- //! every application-scoped operation timed out or returned `502`, across
5
- //! several minutes, on four unrelated collections at once.
6
- //!
7
- //! Four collections failing together is the signature of a **global stall**,
8
- //! not of four collection-specific faults. The mechanism was here:
9
- //!
10
- //! > `compact_operation_log` takes the one lock that serializes every read and
11
- //! > every write, then serializes **every row in the database** to a temp file
12
- //! > and `fsync`s it — and a background task called it **every two seconds**.
13
- //!
14
- //! Pruning acknowledged operations from memory is cheap. Rewriting the log is
15
- //! not. This file holds them apart: pruning still happens whenever it can, and
16
- //! the rewrite waits until enough has accumulated to be worth the stall.
17
- //!
18
- //! See `docs/architecture/compaction-stall.md`.
19
-
20
- use feltdb::state_model::StateStore;
21
- use feltdb::{CompactionOutcome, CompactionPolicy, FeltDb};
22
- use serde_json::json;
23
- use std::sync::Arc;
24
- use std::time::Instant;
25
- use tempfile::TempDir;
26
-
27
- /// Acknowledge everything a database has produced, so a compaction has work.
28
- fn acknowledge_all(db: &Arc<FeltDb>) {
29
- let versions = db.operation_versions().unwrap();
30
- db.acknowledge_peer_versions("peer-1".to_string(), versions)
31
- .unwrap();
32
- }
33
-
34
- fn write_n(db: &Arc<FeltDb>, n: usize) {
35
- for index in 0..n {
36
- db.insert(&format!("tasks:{index}"), json!({ "n": index }))
37
- .unwrap();
38
- }
39
- }
40
-
41
- // ---------------------------------------------------------------------------
42
- // The fix
43
- // ---------------------------------------------------------------------------
44
-
45
- /// **A timer-driven compaction prunes without rewriting the log.**
46
- ///
47
- /// This is the change that stops the stall. The in-memory operation log still
48
- /// shrinks on every tick; the durable rewrite — the expensive half — waits.
49
- #[test]
50
- fn a_policy_driven_compaction_defers_the_rewrite() {
51
- let directory = TempDir::new().unwrap();
52
- let path = directory.path().join("defer.log");
53
- let db = Arc::new(FeltDb::open(&path).unwrap());
54
- db.set_compaction_policy(CompactionPolicy {
55
- rewrite_after_pruned: 1000,
56
- });
57
-
58
- write_n(&db, 20);
59
- acknowledge_all(&db);
60
- let before = std::fs::metadata(&path).unwrap().len();
61
-
62
- let outcome = db
63
- .maybe_compact_operation_log(&["peer-1".to_string()])
64
- .unwrap();
65
-
66
- match outcome {
67
- CompactionOutcome::Deferred {
68
- pruned,
69
- pending_since_rewrite,
70
- } => {
71
- assert!(pruned > 0, "the cheap half still happened");
72
- assert_eq!(pending_since_rewrite, pruned);
73
- }
74
- other => panic!("expected the rewrite to be deferred, got {other:?}"),
75
- }
76
- assert_eq!(
77
- std::fs::metadata(&path).unwrap().len(),
78
- before,
79
- "the durable log was not rewritten"
80
- );
81
-
82
- // And the database is entirely usable.
83
- let value: serde_json::Value = db.get("tasks:0").unwrap().unwrap();
84
- assert_eq!(value["n"], json!(0));
85
- }
86
-
87
- /// **The rewrite happens once the accumulated gain earns it**, and the log
88
- /// actually shrinks when it does.
89
- #[test]
90
- fn the_rewrite_happens_once_the_threshold_is_reached() {
91
- let directory = TempDir::new().unwrap();
92
- let path = directory.path().join("threshold.log");
93
- let db = Arc::new(FeltDb::open(&path).unwrap());
94
- db.set_compaction_policy(CompactionPolicy {
95
- rewrite_after_pruned: 25,
96
- });
97
-
98
- let mut rewrites = 0;
99
- let mut defers = 0;
100
- for round in 0..6 {
101
- for index in 0..10 {
102
- db.update(
103
- &format!("tasks:{}", round * 10 + index),
104
- json!({ "n": index }),
105
- )
106
- .unwrap();
107
- }
108
- acknowledge_all(&db);
109
- match db
110
- .maybe_compact_operation_log(&["peer-1".to_string()])
111
- .unwrap()
112
- {
113
- CompactionOutcome::Rewritten { .. } => rewrites += 1,
114
- CompactionOutcome::Deferred { .. } => defers += 1,
115
- CompactionOutcome::Idle => {}
116
- }
117
- }
118
-
119
- assert!(defers > 0, "most ticks defer");
120
- assert!(rewrites > 0, "and the rewrite still happens");
121
- assert!(
122
- defers > rewrites,
123
- "the point is that deferring is the common case: {defers} deferred, {rewrites} rewritten"
124
- );
125
- }
126
-
127
- /// **An explicit compaction still rewrites immediately.**
128
- ///
129
- /// The policy governs the timer, not a caller who is asking for a rewrite now.
130
- /// Every existing caller of `compact_operation_log` keeps its behaviour.
131
- #[test]
132
- fn an_explicit_compaction_still_rewrites_now() {
133
- let directory = TempDir::new().unwrap();
134
- let path = directory.path().join("explicit.log");
135
- let db = Arc::new(FeltDb::open(&path).unwrap());
136
- db.set_compaction_policy(CompactionPolicy {
137
- rewrite_after_pruned: usize::MAX,
138
- });
139
-
140
- write_n(&db, 20);
141
- for index in 0..20 {
142
- db.update(&format!("tasks:{index}"), json!({"n": "updated"}))
143
- .unwrap();
144
- }
145
- acknowledge_all(&db);
146
- let before = std::fs::metadata(&path).unwrap().len();
147
-
148
- let pruned = db.compact_operation_log(&["peer-1".to_string()]).unwrap();
149
- assert!(pruned > 0);
150
- assert!(
151
- std::fs::metadata(&path).unwrap().len() < before,
152
- "an explicit compaction rewrote and shrank the log"
153
- );
154
- }
155
-
156
- /// **The deferred rewrite costs nothing in correctness.**
157
- ///
158
- /// Pruning without rewriting leaves the durable log longer than it needs to be,
159
- /// and nothing else: the database reopens to the same state and the same
160
- /// history.
161
- #[test]
162
- fn deferring_the_rewrite_preserves_state_and_history() {
163
- let directory = TempDir::new().unwrap();
164
- let path = directory.path().join("preserve.log");
165
- let db = Arc::new(FeltDb::open(&path).unwrap());
166
- db.set_compaction_policy(CompactionPolicy {
167
- rewrite_after_pruned: usize::MAX,
168
- });
169
-
170
- db.insert("tasks:1", json!({"n": 0})).unwrap();
171
- for n in 1..10 {
172
- db.update("tasks:1", json!({ "n": n })).unwrap();
173
- }
174
- acknowledge_all(&db);
175
- assert!(matches!(
176
- db.maybe_compact_operation_log(&["peer-1".to_string()])
177
- .unwrap(),
178
- CompactionOutcome::Deferred { .. }
179
- ));
180
-
181
- let store = StateStore::with_feltdb(db.clone()).unwrap();
182
- let history_before = store.history_digest();
183
- let state_before = db.state_digest().unwrap();
184
- drop(store);
185
- drop(db);
186
-
187
- let reopened = Arc::new(FeltDb::open(&path).unwrap());
188
- let store = StateStore::with_feltdb(reopened.clone()).unwrap();
189
- assert_eq!(reopened.state_digest().unwrap(), state_before);
190
- assert_eq!(store.history_digest(), history_before);
191
- }
192
-
193
- /// Nothing to prune is not a rewrite either — the pre-existing early return.
194
- #[test]
195
- fn an_idle_compaction_does_no_work() {
196
- let directory = TempDir::new().unwrap();
197
- let path = directory.path().join("idle.log");
198
- let db = Arc::new(FeltDb::open(&path).unwrap());
199
- write_n(&db, 5);
200
- let before = std::fs::read(&path).unwrap();
201
-
202
- // No peer has acknowledged anything.
203
- let outcome = db.maybe_compact_operation_log(&[]).unwrap();
204
- assert_eq!(outcome, CompactionOutcome::Idle);
205
- assert_eq!(outcome.pruned(), 0);
206
- assert!(!outcome.rewrote_log());
207
- assert_eq!(std::fs::read(&path).unwrap(), before);
208
- }
209
-
210
- // ---------------------------------------------------------------------------
211
- // The stall itself
212
- // ---------------------------------------------------------------------------
213
-
214
- /// **The rewrite is what stalls, and it grows with the database.**
215
- ///
216
- /// Measured as an ordering rather than a number: a rewrite over a larger
217
- /// database holds the lock longer. That is why running it on a two-second timer
218
- /// degraded as the deployment grew, and why the default policy now waits.
219
- #[test]
220
- fn the_rewrite_cost_grows_with_the_database() {
221
- let cost = |rows: usize| {
222
- let directory = TempDir::new().unwrap();
223
- let path = directory.path().join("cost.log");
224
- let db = Arc::new(FeltDb::open(&path).unwrap());
225
- write_n(&db, rows);
226
- for index in 0..rows {
227
- db.update(&format!("tasks:{index}"), json!({"n": "updated"}))
228
- .unwrap();
229
- }
230
- acknowledge_all(&db);
231
- let started = Instant::now();
232
- db.compact_operation_log(&["peer-1".to_string()]).unwrap();
233
- started.elapsed()
234
- };
235
-
236
- let small = cost(20);
237
- let large = cost(400);
238
- assert!(
239
- large > small,
240
- "a rewrite over more rows holds the lock longer: {large:?} vs {small:?}"
241
- );
242
- }
243
-
244
- /// **The default policy does not rewrite on every tick.**
245
- ///
246
- /// The regression this whole file exists to prevent. With the shipped default,
247
- /// a handful of acknowledged operations must not trigger a full log rewrite.
248
- #[test]
249
- fn the_default_policy_does_not_rewrite_on_a_handful_of_operations() {
250
- assert_eq!(CompactionPolicy::default().rewrite_after_pruned, 1000);
251
-
252
- let directory = TempDir::new().unwrap();
253
- let path = directory.path().join("default.log");
254
- let db = Arc::new(FeltDb::open(&path).unwrap());
255
- assert_eq!(db.compaction_policy(), CompactionPolicy::default());
256
-
257
- write_n(&db, 30);
258
- acknowledge_all(&db);
259
- let before = std::fs::metadata(&path).unwrap().len();
260
-
261
- // Ten ticks of the timer.
262
- for _ in 0..10 {
263
- db.maybe_compact_operation_log(&["peer-1".to_string()])
264
- .unwrap();
265
- }
266
-
267
- assert_eq!(
268
- std::fs::metadata(&path).unwrap().len(),
269
- before,
270
- "ten timer ticks over a small database rewrote the log zero times"
271
- );
272
- }