@feltdb/core 0.15.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 (247) hide show
  1. package/dist/agent-state.d.ts +20 -0
  2. package/dist/agent-state.d.ts.map +1 -1
  3. package/dist/agent-state.js +36 -0
  4. package/dist/build-identity.json +12 -4
  5. package/dist/cli/commands.js +187 -4
  6. package/dist/cli/publish-engine.js +116 -16
  7. package/dist/collection.d.ts.map +1 -1
  8. package/dist/collection.js +3 -0
  9. package/dist/create/build-identity.json +12 -4
  10. package/dist/create/managed-account.js +93 -35
  11. package/dist/create/package-versions.js +1 -1
  12. package/dist/create/server-source/Cargo.lock +6 -509
  13. package/dist/create/server-source/Cargo.toml +2 -13
  14. package/dist/create/server-source/crates/feltdb-client/Cargo.toml +1 -1
  15. package/dist/create/server-source/crates/feltdb-server/Cargo.toml +1 -1
  16. package/dist/create/server-source/crates/feltdb-server/src/main.rs +255 -12
  17. package/dist/create/server-source/crates/feltdb-wasm/Cargo.toml +1 -1
  18. package/dist/db.d.ts +11 -1
  19. package/dist/db.d.ts.map +1 -1
  20. package/dist/db.js +15 -2
  21. package/dist/error-codes.d.ts +5 -0
  22. package/dist/error-codes.d.ts.map +1 -1
  23. package/dist/error-codes.js +9 -1
  24. package/dist/http-db.d.ts +16 -0
  25. package/dist/http-db.d.ts.map +1 -1
  26. package/dist/http-db.js +36 -6
  27. package/dist/managed-recovery.d.ts +6 -0
  28. package/dist/managed-recovery.d.ts.map +1 -1
  29. package/dist/managed-recovery.js +9 -0
  30. package/dist/studio-app/assets/{feltdb_wasm-BjM1ylL3.js → feltdb_wasm-DtybUY0q.js} +1 -1
  31. package/dist/studio-app/assets/feltdb_wasm_bg-DsgIUwaB.wasm +0 -0
  32. package/dist/studio-app/assets/index-C4OffsZl.js +37 -0
  33. package/dist/studio-app/index.html +1 -1
  34. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  35. package/dist/wasm/package.json +1 -1
  36. package/dist/workload.d.ts +55 -3
  37. package/dist/workload.d.ts.map +1 -1
  38. package/dist/workload.js +23 -0
  39. package/dist/workspace/workspace-connection.d.ts.map +1 -1
  40. package/dist/workspace/workspace-connection.js +14 -3
  41. package/package.json +1 -1
  42. package/dist/create/server-source/crates/feltdb/Cargo.lock +0 -175
  43. package/dist/create/server-source/crates/feltdb/Cargo.toml +0 -102
  44. package/dist/create/server-source/crates/feltdb/LICENSE +0 -21
  45. package/dist/create/server-source/crates/feltdb/README.md +0 -75
  46. package/dist/create/server-source/crates/feltdb/benches/baselines/gate-13-redux.json +0 -370
  47. package/dist/create/server-source/crates/feltdb/benches/gate13_baseline.rs +0 -589
  48. package/dist/create/server-source/crates/feltdb/benches/gate13_phase_7_1_release_economics.rs +0 -247
  49. package/dist/create/server-source/crates/feltdb/benches/gate_13_redux.rs +0 -440
  50. package/dist/create/server-source/crates/feltdb/benches/gate_13_regression_runner.rs +0 -275
  51. package/dist/create/server-source/crates/feltdb/benches/gate_14a_concurrent_writer_scaling.rs +0 -381
  52. package/dist/create/server-source/crates/feltdb/benches/gate_14a_production_admission_revalidation.rs +0 -467
  53. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc2_admission_contract.rs +0 -489
  54. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc_root_cause.rs +0 -281
  55. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync1_queued_prototype.rs +0 -606
  56. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync_economics.rs +0 -531
  57. package/dist/create/server-source/crates/feltdb/benches/gate_14b_causal_backlog_scaling.rs +0 -462
  58. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_contract_test.rs +0 -505
  59. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_scaling.rs +0 -484
  60. package/dist/create/server-source/crates/feltdb/benches/gate_14d_combined_dimension_scaling.rs +0 -758
  61. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_2_optimization_benchmark.rs +0 -421
  62. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_3_crossover_analysis.rs +0 -329
  63. package/dist/create/server-source/crates/feltdb/src/acceptance_tests.rs +0 -1705
  64. package/dist/create/server-source/crates/feltdb/src/acquisition.rs +0 -286
  65. package/dist/create/server-source/crates/feltdb/src/admission.rs +0 -185
  66. package/dist/create/server-source/crates/feltdb/src/admission_contract_tests.rs +0 -507
  67. package/dist/create/server-source/crates/feltdb/src/adversarial_transport.rs +0 -539
  68. package/dist/create/server-source/crates/feltdb/src/agent_state.rs +0 -320
  69. package/dist/create/server-source/crates/feltdb/src/agent_transition_contract.rs +0 -1545
  70. package/dist/create/server-source/crates/feltdb/src/analytics.rs +0 -521
  71. package/dist/create/server-source/crates/feltdb/src/application.rs +0 -2674
  72. package/dist/create/server-source/crates/feltdb/src/application_runtime.rs +0 -1070
  73. package/dist/create/server-source/crates/feltdb/src/authority.rs +0 -479
  74. package/dist/create/server-source/crates/feltdb/src/authority_failover.rs +0 -847
  75. package/dist/create/server-source/crates/feltdb/src/authorization.rs +0 -1030
  76. package/dist/create/server-source/crates/feltdb/src/authorization_security_tests.rs +0 -1122
  77. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority-client.rs +0 -32
  78. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority.rs +0 -19
  79. package/dist/create/server-source/crates/feltdb/src/bin/feltdb_node.rs +0 -1474
  80. package/dist/create/server-source/crates/feltdb/src/capabilities/mod.rs +0 -8
  81. package/dist/create/server-source/crates/feltdb/src/capabilities/search.rs +0 -418
  82. package/dist/create/server-source/crates/feltdb/src/capabilities/vector.rs +0 -482
  83. package/dist/create/server-source/crates/feltdb/src/capability.rs +0 -903
  84. package/dist/create/server-source/crates/feltdb/src/cardinality_diagnostics.rs +0 -263
  85. package/dist/create/server-source/crates/feltdb/src/cardinality_endpoint.rs +0 -77
  86. package/dist/create/server-source/crates/feltdb/src/causal_backlog_bound.rs +0 -496
  87. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier.rs +0 -2574
  88. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier_phase_7_1.rs +0 -212
  89. package/dist/create/server-source/crates/feltdb/src/concurrency_fuzzing.rs +0 -422
  90. package/dist/create/server-source/crates/feltdb/src/consistency_contract.rs +0 -445
  91. package/dist/create/server-source/crates/feltdb/src/content_distribution.rs +0 -465
  92. package/dist/create/server-source/crates/feltdb/src/convergence.rs +0 -634
  93. package/dist/create/server-source/crates/feltdb/src/crash_atomic_boundary.rs +0 -427
  94. package/dist/create/server-source/crates/feltdb/src/crash_injection.rs +0 -376
  95. package/dist/create/server-source/crates/feltdb/src/crash_recovery_tests.rs +0 -365
  96. package/dist/create/server-source/crates/feltdb/src/cron.rs +0 -294
  97. package/dist/create/server-source/crates/feltdb/src/dedup_bound_investigation.rs +0 -483
  98. package/dist/create/server-source/crates/feltdb/src/distributed_indexing.rs +0 -477
  99. package/dist/create/server-source/crates/feltdb/src/distributed_tests.rs +0 -1003
  100. package/dist/create/server-source/crates/feltdb/src/distributed_transactions.rs +0 -1334
  101. package/dist/create/server-source/crates/feltdb/src/durability_guarantees.rs +0 -368
  102. package/dist/create/server-source/crates/feltdb/src/durable_dedup_set.rs +0 -231
  103. package/dist/create/server-source/crates/feltdb/src/durable_operation_identity.rs +0 -482
  104. package/dist/create/server-source/crates/feltdb/src/durable_operation_log.rs +0 -203
  105. package/dist/create/server-source/crates/feltdb/src/durable_sync.rs +0 -317
  106. package/dist/create/server-source/crates/feltdb/src/equality_index.rs +0 -595
  107. package/dist/create/server-source/crates/feltdb/src/execution.rs +0 -426
  108. package/dist/create/server-source/crates/feltdb/src/in_process_transport.rs +0 -214
  109. package/dist/create/server-source/crates/feltdb/src/indexing.rs +0 -776
  110. package/dist/create/server-source/crates/feltdb/src/lib.rs +0 -7365
  111. package/dist/create/server-source/crates/feltdb/src/managed_cas_tests.rs +0 -234
  112. package/dist/create/server-source/crates/feltdb/src/materialization.rs +0 -184
  113. package/dist/create/server-source/crates/feltdb/src/metrics.rs +0 -266
  114. package/dist/create/server-source/crates/feltdb/src/multi_node_convergence.rs +0 -310
  115. package/dist/create/server-source/crates/feltdb/src/multi_operation_transaction.rs +0 -736
  116. package/dist/create/server-source/crates/feltdb/src/observability.rs +0 -379
  117. package/dist/create/server-source/crates/feltdb/src/operation.rs +0 -290
  118. package/dist/create/server-source/crates/feltdb/src/operation_algebra.rs +0 -439
  119. package/dist/create/server-source/crates/feltdb/src/operation_log.rs +0 -349
  120. package/dist/create/server-source/crates/feltdb/src/p1_application_atomicity.rs +0 -332
  121. package/dist/create/server-source/crates/feltdb/src/p1_atomicity_acceptance.rs +0 -718
  122. package/dist/create/server-source/crates/feltdb/src/partition_reconciliation.rs +0 -487
  123. package/dist/create/server-source/crates/feltdb/src/peer_registry.rs +0 -166
  124. package/dist/create/server-source/crates/feltdb/src/permutation_scheduler.rs +0 -289
  125. package/dist/create/server-source/crates/feltdb/src/persistence_reality.rs +0 -566
  126. package/dist/create/server-source/crates/feltdb/src/phase1b_acceptance.rs +0 -3391
  127. package/dist/create/server-source/crates/feltdb/src/phase1c1_acceptance.rs +0 -203
  128. package/dist/create/server-source/crates/feltdb/src/phase1c2_acceptance.rs +0 -261
  129. package/dist/create/server-source/crates/feltdb/src/phase1c3_acceptance.rs +0 -502
  130. package/dist/create/server-source/crates/feltdb/src/phase1c_atomicity_proof.rs +0 -216
  131. package/dist/create/server-source/crates/feltdb/src/phase5_integration.rs +0 -303
  132. package/dist/create/server-source/crates/feltdb/src/phase5_scenarios.rs +0 -323
  133. package/dist/create/server-source/crates/feltdb/src/phase6_adversarial_scenarios.rs +0 -531
  134. package/dist/create/server-source/crates/feltdb/src/phase6_convergence_validator.rs +0 -406
  135. package/dist/create/server-source/crates/feltdb/src/phase6_persistence.rs +0 -436
  136. package/dist/create/server-source/crates/feltdb/src/phase_1c_real_tcp.rs +0 -387
  137. package/dist/create/server-source/crates/feltdb/src/phase_2a_failures.rs +0 -378
  138. package/dist/create/server-source/crates/feltdb/src/phase_2b_network.rs +0 -359
  139. package/dist/create/server-source/crates/feltdb/src/phase_2c_cascading.rs +0 -372
  140. package/dist/create/server-source/crates/feltdb/src/phase_3_durability.rs +0 -404
  141. package/dist/create/server-source/crates/feltdb/src/phase_4_baseline.rs +0 -376
  142. package/dist/create/server-source/crates/feltdb/src/phase_5_soak.rs +0 -461
  143. package/dist/create/server-source/crates/feltdb/src/policy_evaluation.rs +0 -2125
  144. package/dist/create/server-source/crates/feltdb/src/production_api.rs +0 -418
  145. package/dist/create/server-source/crates/feltdb/src/provenance.rs +0 -207
  146. package/dist/create/server-source/crates/feltdb/src/query_execution_diagnostics.rs +0 -126
  147. package/dist/create/server-source/crates/feltdb/src/query_performance.rs +0 -218
  148. package/dist/create/server-source/crates/feltdb/src/read_basis.rs +0 -257
  149. package/dist/create/server-source/crates/feltdb/src/references.rs +0 -404
  150. package/dist/create/server-source/crates/feltdb/src/replay_fuzzing.rs +0 -401
  151. package/dist/create/server-source/crates/feltdb/src/replica_acknowledgements.rs +0 -501
  152. package/dist/create/server-source/crates/feltdb/src/replica_membership.rs +0 -680
  153. package/dist/create/server-source/crates/feltdb/src/replication_manager.rs +0 -163
  154. package/dist/create/server-source/crates/feltdb/src/replication_protocol.rs +0 -133
  155. package/dist/create/server-source/crates/feltdb/src/routing.rs +0 -409
  156. package/dist/create/server-source/crates/feltdb/src/semantic_decision.rs +0 -2029
  157. package/dist/create/server-source/crates/feltdb/src/semantic_query.rs +0 -599
  158. package/dist/create/server-source/crates/feltdb/src/sharding.rs +0 -549
  159. package/dist/create/server-source/crates/feltdb/src/state_conflict_contract.rs +0 -516
  160. package/dist/create/server-source/crates/feltdb/src/state_contract.rs +0 -6003
  161. package/dist/create/server-source/crates/feltdb/src/state_diff_contract.rs +0 -222
  162. package/dist/create/server-source/crates/feltdb/src/state_facade.rs +0 -320
  163. package/dist/create/server-source/crates/feltdb/src/state_hash.rs +0 -291
  164. package/dist/create/server-source/crates/feltdb/src/state_model.rs +0 -4158
  165. package/dist/create/server-source/crates/feltdb/src/state_transition_store.rs +0 -379
  166. package/dist/create/server-source/crates/feltdb/src/state_trigger.rs +0 -673
  167. package/dist/create/server-source/crates/feltdb/src/storage.rs +0 -273
  168. package/dist/create/server-source/crates/feltdb/src/submission.rs +0 -471
  169. package/dist/create/server-source/crates/feltdb/src/sync.rs +0 -495
  170. package/dist/create/server-source/crates/feltdb/src/sync_contract.rs +0 -822
  171. package/dist/create/server-source/crates/feltdb/src/tcp_transport.rs +0 -433
  172. package/dist/create/server-source/crates/feltdb/src/transaction_api.rs +0 -462
  173. package/dist/create/server-source/crates/feltdb/src/transaction_invariants.rs +0 -965
  174. package/dist/create/server-source/crates/feltdb/src/transaction_preconditions.rs +0 -1120
  175. package/dist/create/server-source/crates/feltdb/src/transactions.rs +0 -643
  176. package/dist/create/server-source/crates/feltdb/src/trigger.rs +0 -390
  177. package/dist/create/server-source/crates/feltdb/src/trigger_contract.rs +0 -749
  178. package/dist/create/server-source/crates/feltdb/src/versioned_object_substrate.rs +0 -708
  179. package/dist/create/server-source/crates/feltdb/src/worker_mesh.rs +0 -1269
  180. package/dist/create/server-source/crates/feltdb/src/workflow.rs +0 -713
  181. package/dist/create/server-source/crates/feltdb/src/workflow_acceptance_tests.rs +0 -510
  182. package/dist/create/server-source/crates/feltdb/src/workflow_integration.rs +0 -354
  183. package/dist/create/server-source/crates/feltdb/src/workflow_runtime.rs +0 -594
  184. package/dist/create/server-source/crates/feltdb/src/workload.rs +0 -4222
  185. package/dist/create/server-source/crates/feltdb/src/workload_diagnostics.rs +0 -456
  186. package/dist/create/server-source/crates/feltdb/tests/agent_state_native.rs +0 -1188
  187. package/dist/create/server-source/crates/feltdb/tests/agent_transition_contract_conformance.rs +0 -2884
  188. package/dist/create/server-source/crates/feltdb/tests/authority_process.rs +0 -297
  189. package/dist/create/server-source/crates/feltdb/tests/authority_transaction_identity.rs +0 -534
  190. package/dist/create/server-source/crates/feltdb/tests/bounded_read_contract.rs +0 -132
  191. package/dist/create/server-source/crates/feltdb/tests/branching_evidence.rs +0 -299
  192. package/dist/create/server-source/crates/feltdb/tests/common/mod.rs +0 -96
  193. package/dist/create/server-source/crates/feltdb/tests/compaction_stall_contract.rs +0 -272
  194. package/dist/create/server-source/crates/feltdb/tests/crash_durability_contract.rs +0 -467
  195. package/dist/create/server-source/crates/feltdb/tests/current_revision_authority_evidence.rs +0 -309
  196. package/dist/create/server-source/crates/feltdb/tests/durable_backup_contract.rs +0 -445
  197. package/dist/create/server-source/crates/feltdb/tests/durable_corruption_contract.rs +0 -518
  198. package/dist/create/server-source/crates/feltdb/tests/durable_format_compatibility.rs +0 -392
  199. package/dist/create/server-source/crates/feltdb/tests/feltdb_state_boundary_tests.rs +0 -850
  200. package/dist/create/server-source/crates/feltdb/tests/fixtures/agent_transition_corpus.json +0 -23340
  201. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_conflict_contract_corpus.json +0 -1916
  202. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_diff_contract_corpus.json +0 -1878
  203. package/dist/create/server-source/crates/feltdb/tests/fixtures/trigger_contract_corpus.json +0 -1862
  204. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_evidence.rs +0 -123
  205. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_substrate_completion.rs +0 -299
  206. package/dist/create/server-source/crates/feltdb/tests/local_process_ownership.rs +0 -69
  207. package/dist/create/server-source/crates/feltdb/tests/managed_incident_regression.rs +0 -191
  208. package/dist/create/server-source/crates/feltdb/tests/operational_health_contract.rs +0 -278
  209. package/dist/create/server-source/crates/feltdb/tests/pr34_query_collection.rs +0 -234
  210. package/dist/create/server-source/crates/feltdb/tests/pr35_equality_index.rs +0 -947
  211. package/dist/create/server-source/crates/feltdb/tests/pr7_self_authorization_proof.rs +0 -404
  212. package/dist/create/server-source/crates/feltdb/tests/pr8_vocabulary_assessment.rs +0 -916
  213. package/dist/create/server-source/crates/feltdb/tests/pr9_phase2_boundary_tests.rs +0 -1045
  214. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3a_path_a_tests.rs +0 -347
  215. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_authorized_mutations.rs +0 -361
  216. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_role_based_authorization.rs +0 -330
  217. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_simple_auth_delete.rs +0 -93
  218. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_team_delete_role_authorization.rs +0 -622
  219. package/dist/create/server-source/crates/feltdb/tests/pr9_teams_role_based_access.rs +0 -517
  220. package/dist/create/server-source/crates/feltdb/tests/production_certification.rs +0 -1153
  221. package/dist/create/server-source/crates/feltdb/tests/production_contract.rs +0 -771
  222. package/dist/create/server-source/crates/feltdb/tests/production_readiness_contract.rs +0 -1383
  223. package/dist/create/server-source/crates/feltdb/tests/reconciliation_application.rs +0 -868
  224. package/dist/create/server-source/crates/feltdb/tests/reconciliation_wire_format_evidence.rs +0 -221
  225. package/dist/create/server-source/crates/feltdb/tests/replicated_history_contract.rs +0 -417
  226. package/dist/create/server-source/crates/feltdb/tests/resource_scoped_revisions.rs +0 -338
  227. package/dist/create/server-source/crates/feltdb/tests/revision_identity_contract.rs +0 -1039
  228. package/dist/create/server-source/crates/feltdb/tests/revision_model_decision.rs +0 -739
  229. package/dist/create/server-source/crates/feltdb/tests/revision_retention_boundary_evidence.rs +0 -452
  230. package/dist/create/server-source/crates/feltdb/tests/saas_authorization_integration.rs +0 -81
  231. package/dist/create/server-source/crates/feltdb/tests/saas_invitation_lifecycle.rs +0 -438
  232. package/dist/create/server-source/crates/feltdb/tests/semantic_decision.rs +0 -1165
  233. package/dist/create/server-source/crates/feltdb/tests/semantic_query.rs +0 -767
  234. package/dist/create/server-source/crates/feltdb/tests/semantic_query_contract.rs +0 -363
  235. package/dist/create/server-source/crates/feltdb/tests/state_conflict_contract_conformance.rs +0 -1799
  236. package/dist/create/server-source/crates/feltdb/tests/state_diff_contract_conformance.rs +0 -1316
  237. package/dist/create/server-source/crates/feltdb/tests/state_model_integration.rs +0 -358
  238. package/dist/create/server-source/crates/feltdb/tests/state_persistence_integration.rs +0 -365
  239. package/dist/create/server-source/crates/feltdb/tests/state_ref_authority.rs +0 -918
  240. package/dist/create/server-source/crates/feltdb/tests/state_store_boundary_evidence.rs +0 -299
  241. package/dist/create/server-source/crates/feltdb/tests/storage_independent_versioned_object_substrate.rs +0 -328
  242. package/dist/create/server-source/crates/feltdb/tests/sync_divergence_evidence.rs +0 -255
  243. package/dist/create/server-source/crates/feltdb/tests/three_way_input_boundary_evidence.rs +0 -249
  244. package/dist/create/server-source/crates/feltdb/tests/trigger_contract_conformance.rs +0 -994
  245. package/dist/create/server-source/crates/feltdb/tests/workload_envelope_contract.rs +0 -484
  246. package/dist/studio-app/assets/feltdb_wasm_bg-TseJn2Ax.wasm +0 -0
  247. package/dist/studio-app/assets/index-1wd0uKua.js +0 -30
@@ -1,255 +0,0 @@
1
- //! Evidence for the sync divergence boundary audit
2
- //! (`docs/audits/SYNC-DIVERGENCE-AUDIT.md`).
3
- //!
4
- //! Adds **no capability and no product surface**. It tests one question:
5
- //!
6
- //! > Is there a concrete transition where two independently valid states need
7
- //! > to coexist durably — and does a durable representation for the second one
8
- //! > already exist?
9
- //!
10
- //! Both answers are yes, and the second is the surprising one: `SyncStore`
11
- //! already accepts `ReconciliationOutcome::Conflict` and persists the operation
12
- //! with its complete proposed value. The representation is not missing. The
13
- //! server reaches the conflict, declines to record it, and `continue`s.
14
-
15
- use feltdb::authorization::{
16
- AuthorizationContext, Grant, GrantConstraints, GrantSigner, GrantStatus, Resource,
17
- ResourceScope, ResourceScopeKind, Subject,
18
- };
19
- use feltdb::state_contract::{TransactionOperation, TransactionOperationKind};
20
- use feltdb::sync_contract::{ReconciliationOutcome, SyncOperation, SyncStore};
21
- use serde_json::json;
22
- use std::collections::BTreeMap;
23
- use tempfile::TempDir;
24
-
25
- /// A pushed operation for `flow://a/tasks/1` carrying `value` as its proposed
26
- /// state, descending from server position `causal_parent`.
27
- fn operation(id: &str, value: serde_json::Value, causal_parent: Option<u64>) -> SyncOperation {
28
- let signer = GrantSigner::new("k", vec![9; 32]).unwrap();
29
- let grant = Grant {
30
- contract_version: 1,
31
- id: "g".into(),
32
- issuer: Subject::Human("h".into()),
33
- subject: Subject::Human("u".into()),
34
- tenant_id: "t".into(),
35
- application_id: "a".into(),
36
- capabilities: ["state:write".into(), "state:read".into()].into(),
37
- resources: vec![ResourceScope {
38
- kind: ResourceScopeKind::ResourcePrefix,
39
- uri: "flow://a/tasks/*".into(),
40
- }],
41
- constraints: GrantConstraints::default(),
42
- issued_at: 1,
43
- expires_at: 999,
44
- parent_grant: None,
45
- revision: 1,
46
- status: GrantStatus::Active,
47
- };
48
- let signed = signer.sign(grant).unwrap();
49
-
50
- let mut causal_context = BTreeMap::new();
51
- if let Some(position) = causal_parent {
52
- causal_context.insert("server".to_string(), position);
53
- }
54
-
55
- SyncOperation {
56
- contract_version: 1,
57
- operation_id: id.into(),
58
- tenant_id: "t".into(),
59
- application_id: "a".into(),
60
- subject: Subject::Human("u".into()),
61
- device_id: "d".into(),
62
- resource: Resource {
63
- uri: "flow://a/tasks/1".into(),
64
- attributes: BTreeMap::new(),
65
- },
66
- operation: TransactionOperation {
67
- kind: TransactionOperationKind::Update,
68
- collection: "tasks".into(),
69
- id: "1".into(),
70
- value,
71
- if_version: None,
72
- },
73
- causal_context,
74
- schema_version: 1,
75
- authorization_context: AuthorizationContext {
76
- timestamp: 10,
77
- ..Default::default()
78
- },
79
- offline_grant: signed,
80
- application_revision: "r1".into(),
81
- created_at: 10,
82
- }
83
- }
84
-
85
- // ---------------------------------------------------------------------------
86
- // What arrives at the boundary
87
- // ---------------------------------------------------------------------------
88
-
89
- /// A pushed operation carries a **complete proposed state**, not a delta.
90
- ///
91
- /// This is the first half of what reconciliation needs. `TransactionOperation`
92
- /// is `{kind, collection, id, value, if_version}` and `value` is a whole
93
- /// `serde_json::Value` — the same shape `/v1/data` accepts. So the remote side
94
- /// of a divergence arrives at the server fully formed, and is present in memory
95
- /// at the exact moment the conflict is detected.
96
- #[test]
97
- fn a_pushed_operation_carries_a_complete_proposed_state() {
98
- let remote = operation("op-remote", json!({"title": "written offline"}), Some(1));
99
-
100
- assert_eq!(
101
- remote.operation.value,
102
- json!({"title": "written offline"}),
103
- "the proposed state is carried whole, not as a change description"
104
- );
105
- assert_eq!(
106
- remote.causal_context.get("server"),
107
- Some(&1),
108
- "and it names the server position it descended from"
109
- );
110
- }
111
-
112
- // ---------------------------------------------------------------------------
113
- // The durable representation already exists
114
- // ---------------------------------------------------------------------------
115
-
116
- /// `SyncStore` can already record a conflicting operation, durably, with its
117
- /// full proposed state.
118
- ///
119
- /// This is the audit's central result. `record` takes a
120
- /// `ReconciliationOutcome`, and `Conflict` is one of its variants. Recording a
121
- /// losing operation persists it at its own position, retains its complete
122
- /// value, and it survives reload — so the "losing state is annihilated" problem
123
- /// the current-revision audit found in the CAS path **does not apply here for
124
- /// want of a place to put it**. The place exists.
125
- ///
126
- /// The server does not use it: at the conflict site it pushes a `SyncConflict`
127
- /// and `continue`s, skipping both `record` and the transaction.
128
- #[test]
129
- fn the_sync_store_can_already_record_a_conflicting_operation_durably() {
130
- let directory = TempDir::new().unwrap();
131
- let path = directory.path().join("sync.json");
132
-
133
- let accepted_position;
134
- let conflicting_position;
135
- {
136
- let mut store = SyncStore::load(&path).unwrap();
137
-
138
- accepted_position = store
139
- .record(
140
- operation("op-local", json!({"title": "written on server"}), None),
141
- ReconciliationOutcome::Accept,
142
- None,
143
- 100,
144
- )
145
- .expect("the winning operation records");
146
-
147
- // The losing side, recorded rather than discarded.
148
- conflicting_position = store
149
- .record(
150
- operation("op-remote", json!({"title": "written offline"}), Some(1)),
151
- ReconciliationOutcome::Conflict,
152
- None,
153
- 101,
154
- )
155
- .expect("a conflicting operation records just as well");
156
- }
157
-
158
- // Both survive a reload, with their full states intact.
159
- let reloaded = SyncStore::load(&path).unwrap();
160
- let accepted = reloaded
161
- .operations
162
- .iter()
163
- .find(|stored| stored.position == accepted_position)
164
- .expect("the accepted operation is durable");
165
- let conflicting = reloaded
166
- .operations
167
- .iter()
168
- .find(|stored| stored.position == conflicting_position)
169
- .expect("the conflicting operation is durable too");
170
-
171
- assert!(matches!(accepted.outcome, ReconciliationOutcome::Accept));
172
- assert!(matches!(
173
- conflicting.outcome,
174
- ReconciliationOutcome::Conflict
175
- ));
176
- assert_eq!(
177
- conflicting.operation.operation.value,
178
- json!({"title": "written offline"}),
179
- "the losing side's complete proposed state is retained"
180
- );
181
- assert_eq!(
182
- conflicting.operation.causal_context.get("server"),
183
- Some(&1),
184
- "along with the position it claimed to descend from"
185
- );
186
- }
187
-
188
- /// Retained operations reconstruct the state a resource held at a position.
189
- ///
190
- /// This is where `base` would come from. Operations are appended with a
191
- /// monotonic `position` and never pruned, and each carries the whole value that
192
- /// was applied, so "what did this resource look like at server position N" is
193
- /// answerable by lookup — **for the part of its history that arrived through
194
- /// sync**. See the audit for why that qualifier is the load-bearing one.
195
- #[test]
196
- fn retained_operations_reconstruct_the_state_at_a_position() {
197
- let directory = TempDir::new().unwrap();
198
- let mut store = SyncStore::load(directory.path().join("history.json")).unwrap();
199
-
200
- let first = store
201
- .record(
202
- operation("op-1", json!({"title": "v1"}), None),
203
- ReconciliationOutcome::Accept,
204
- None,
205
- 10,
206
- )
207
- .unwrap();
208
- let second = store
209
- .record(
210
- operation("op-2", json!({"title": "v2"}), Some(first)),
211
- ReconciliationOutcome::Accept,
212
- None,
213
- 11,
214
- )
215
- .unwrap();
216
-
217
- let at = |position: u64| {
218
- store
219
- .operations
220
- .iter()
221
- .find(|stored| {
222
- stored.position == position && stored.operation.resource.uri == "flow://a/tasks/1"
223
- })
224
- .map(|stored| stored.operation.operation.value.clone())
225
- };
226
-
227
- assert_eq!(at(first), Some(json!({"title": "v1"})));
228
- assert_eq!(at(second), Some(json!({"title": "v2"})));
229
- assert!(second > first, "positions are monotonic");
230
-
231
- // Nothing prunes: the earlier state is still there after the later one.
232
- assert_eq!(store.operations.len(), 2);
233
- }
234
-
235
- /// The outcome vocabulary already distinguishes the cases a reconciler needs.
236
- ///
237
- /// Recorded because it bounds how much vocabulary a future change would have to
238
- /// invent: none. What is missing is a *decision procedure*, not a way to say
239
- /// what was decided.
240
- #[test]
241
- fn the_outcome_vocabulary_already_names_a_conflict() {
242
- let outcomes = [
243
- ReconciliationOutcome::Accept,
244
- ReconciliationOutcome::Conflict,
245
- ReconciliationOutcome::Reject,
246
- ReconciliationOutcome::Stale,
247
- ReconciliationOutcome::AlreadyCommitted,
248
- ];
249
- // Each is representable and round-trips, so a stored decision is durable.
250
- for outcome in outcomes {
251
- let text = serde_json::to_string(&outcome).unwrap();
252
- let back: ReconciliationOutcome = serde_json::from_str(&text).unwrap();
253
- assert_eq!(format!("{outcome:?}"), format!("{back:?}"));
254
- }
255
- }
@@ -1,249 +0,0 @@
1
- //! Evidence for the three-way reconciliation input boundary audit
2
- //! (`docs/audits/THREE-WAY-INPUT-BOUNDARY-AUDIT.md`).
3
- //!
4
- //! Adds **no capability and no product surface**. It tests one question:
5
- //!
6
- //! > When a resource has mixed local and sync-originated history, what is the
7
- //! > authoritative source of `base`, `left` and `right`?
8
- //!
9
- //! The decisive result is negative and it kills a tempting shortcut: the
10
- //! operation log cannot serve as the ancestry source, because compaction — a
11
- //! routine, correct replication maintenance step — deletes the history while
12
- //! deliberately preserving current state.
13
-
14
- use feltdb::state_model::StateId;
15
- use feltdb::{FeltDb, JsonCasResult};
16
- use serde_json::{json, Value};
17
- use std::collections::HashMap;
18
- use tempfile::TempDir;
19
-
20
- /// The canonical content string for a stored value, as a `StateRevision` would
21
- /// hold it.
22
- fn canonical(value: &Value) -> String {
23
- value.to_string()
24
- }
25
-
26
- // ---------------------------------------------------------------------------
27
- // What a locally committed state can already produce
28
- // ---------------------------------------------------------------------------
29
-
30
- /// A stored value canonicalizes deterministically, so it can become revision
31
- /// content without replaying anything.
32
- ///
33
- /// `serde_json` is compiled without `preserve_order`, so `Map` is a `BTreeMap`
34
- /// and `to_string` emits keys in sorted order. Two documents that differ only
35
- /// in the order their keys were written produce the same string and therefore
36
- /// the same `StateId`. This is what makes candidate B representationally sound:
37
- /// the artifact that already holds a resource's authoritative state can be
38
- /// turned into a revision by reading it, not by reconstructing it.
39
- #[test]
40
- fn a_stored_value_canonicalizes_deterministically() {
41
- let directory = TempDir::new().unwrap();
42
- let db = FeltDb::open(directory.path().join("canon.log")).unwrap();
43
-
44
- db.insert("tasks:1", json!({"title": "A", "__version": 1}))
45
- .unwrap();
46
- let stored: Value = db.get("tasks:1").unwrap().unwrap();
47
- let content = canonical(&stored);
48
- assert_eq!(content, r#"{"__version":1,"title":"A"}"#);
49
-
50
- // Key order in the source text does not change the canonical form.
51
- let one: Value = serde_json::from_str(r#"{"a":1,"b":2}"#).unwrap();
52
- let other: Value = serde_json::from_str(r#"{"b":2,"a":1}"#).unwrap();
53
- assert_eq!(canonical(&one), canonical(&other));
54
- assert_eq!(
55
- StateId::compute(&canonical(&one)).as_hex(),
56
- StateId::compute(&canonical(&other)).as_hex(),
57
- "the same state has one identity regardless of how it was written"
58
- );
59
- }
60
-
61
- /// The prior document is in hand at the mutation boundary.
62
- ///
63
- /// The fence reads the existing row before deciding, and it reads *inside* it:
64
- /// the authority epoch lives at `/authority/epoch`, a nested field of the
65
- /// stored document, and a stale epoch is refused on its basis. That is
66
- /// behavioural proof that the whole previous state — not merely a version
67
- /// counter — is available under the same lock that performs the write.
68
- ///
69
- /// So the parent of a revision minted at this boundary is computable at that
70
- /// instant: it is `StateId::compute` over the canonical form of the document
71
- /// the fence just read.
72
- #[test]
73
- fn the_prior_document_is_read_at_the_mutation_boundary() {
74
- let directory = TempDir::new().unwrap();
75
- let db = FeltDb::open(directory.path().join("prior.log")).unwrap();
76
-
77
- db.insert(
78
- "tasks:2",
79
- json!({"title": "A", "__version": 1, "authority": {"epoch": 7}}),
80
- )
81
- .unwrap();
82
-
83
- // A nested field of the *previous* document decides this write.
84
- let refused = db
85
- .compare_and_set_json("tasks:2", 1, Some(6), None, false, json!({"title": "B"}))
86
- .unwrap();
87
- assert!(
88
- matches!(
89
- refused,
90
- JsonCasResult::AuthorityConflict {
91
- current_epoch: 7,
92
- ..
93
- }
94
- ),
95
- "the fence read into the prior document to refuse this: {refused:?}"
96
- );
97
-
98
- // And the prior document is still intact, so it could have been hashed.
99
- let prior: Value = db.get("tasks:2").unwrap().unwrap();
100
- assert_eq!(prior["authority"]["epoch"], json!(7));
101
- assert!(!StateId::compute(&canonical(&prior)).as_hex().is_empty());
102
- }
103
-
104
- // ---------------------------------------------------------------------------
105
- // The shortcut, and why it fails
106
- // ---------------------------------------------------------------------------
107
-
108
- /// **Compaction destroys ancestry while preserving current state.**
109
- ///
110
- /// This is the audit's decisive negative result, and it disqualifies
111
- /// reconstructing `base` from the operation log.
112
- ///
113
- /// `compact_operation_log` prunes operations every active peer has
114
- /// acknowledged, then rewrites the log as a header, the still-pending
115
- /// operations, and a snapshot of the *current rows* — with `operation` set to
116
- /// `None` on each snapshot row, so even the linkage back to a mutation is
117
- /// stripped. It is correct, it is routine, and its entire purpose is to stop
118
- /// the log growing without bound once replication no longer needs it.
119
- ///
120
- /// The consequence for reconciliation is exact: after compaction the resource's
121
- /// **current** state is intact and its **previous** state is gone. That is
122
- /// precisely the wrong half to preserve. A `base` derived from the log is not
123
- /// merely awkward to compute — it is destroyed by normal operation.
124
- #[test]
125
- fn log_compaction_destroys_ancestry_while_preserving_current_state() {
126
- let directory = TempDir::new().unwrap();
127
- let path = directory.path().join("compact.log");
128
- let db = FeltDb::open(&path).unwrap();
129
-
130
- // local A, then local B fenced on A.
131
- db.insert("tasks:3", json!({"title": "A", "__version": 1}))
132
- .unwrap();
133
- db.compare_and_set_json("tasks:3", 1, None, None, false, json!({"title": "B"}))
134
- .unwrap();
135
-
136
- // Before compaction both states are in the log.
137
- let before = db.operations_since(&HashMap::new()).unwrap();
138
- let for_resource: Vec<_> = before.iter().filter(|op| op.key == "tasks:3").collect();
139
- assert_eq!(
140
- for_resource.len(),
141
- 2,
142
- "insert A and update B are both present"
143
- );
144
- assert!(
145
- for_resource
146
- .iter()
147
- .any(|op| op.value.as_ref().unwrap()["title"] == json!("A")),
148
- "state A is recoverable from the log at this point"
149
- );
150
-
151
- // A peer acknowledges everything, and the log is compacted.
152
- let versions = db.operation_versions().unwrap();
153
- db.acknowledge_peer_versions("peer-1".to_string(), versions)
154
- .unwrap();
155
- let removed = db.compact_operation_log(&["peer-1".to_string()]).unwrap();
156
- assert!(removed > 0, "compaction pruned acknowledged operations");
157
-
158
- // Reopen from the compacted log.
159
- drop(db);
160
- let reopened = FeltDb::open(&path).unwrap();
161
-
162
- // Current state survived.
163
- let current: Value = reopened.get("tasks:3").unwrap().unwrap();
164
- assert_eq!(current["title"], json!("B"), "the current state is intact");
165
-
166
- // Ancestry did not.
167
- let after = reopened.operations_since(&HashMap::new()).unwrap();
168
- assert!(
169
- !after
170
- .iter()
171
- .any(|op| op.value.as_ref().is_some_and(|v| v["title"] == json!("A"))),
172
- "state A is no longer recoverable from anywhere in the log"
173
- );
174
- }
175
-
176
- // ---------------------------------------------------------------------------
177
- // The mixed-history case
178
- // ---------------------------------------------------------------------------
179
-
180
- /// **`base` cannot be produced for a locally written resource.**
181
- ///
182
- /// The scenario the audit was asked to settle:
183
- ///
184
- /// ```text
185
- /// local A → local B → remote proposal C, descended from A
186
- /// ```
187
- ///
188
- /// At the moment of conflict:
189
- ///
190
- /// | input | source | available |
191
- /// | --- | --- | --- |
192
- /// | `right` = C | the pushed operation's `value` | yes |
193
- /// | `left` = B | the current row, canonicalized | yes |
194
- /// | `base` = A | — | **no** |
195
- ///
196
- /// A is gone from the row, which was overwritten in place; it was never written
197
- /// to `SyncStore`, which only records sync-originated operations; and it does
198
- /// not survive compaction of the operation log. Nothing durable holds it.
199
- ///
200
- /// This is the missing invariant, stated exactly: **no durable artifact
201
- /// preserves a resource's prior state once it has been overwritten.**
202
- #[test]
203
- fn the_prior_state_is_unrecoverable_after_a_second_local_write() {
204
- let directory = TempDir::new().unwrap();
205
- let db = FeltDb::open(directory.path().join("mixed.log")).unwrap();
206
-
207
- // local A
208
- db.insert("tasks:4", json!({"title": "A", "__version": 1}))
209
- .unwrap();
210
- let a_id = StateId::compute(&canonical(&db.get::<Value>("tasks:4").unwrap().unwrap()));
211
-
212
- // local B, fenced on A
213
- db.compare_and_set_json("tasks:4", 1, None, None, false, json!({"title": "B"}))
214
- .unwrap();
215
-
216
- // `left` is available and identifiable.
217
- let left: Value = db.get("tasks:4").unwrap().unwrap();
218
- let left_id = StateId::compute(&canonical(&left));
219
- assert_eq!(left["title"], json!("B"));
220
- assert_ne!(left_id.as_hex(), a_id.as_hex());
221
-
222
- // The row no longer holds A: it was overwritten in place.
223
- assert_ne!(
224
- StateId::compute(&canonical(&left)).as_hex(),
225
- a_id.as_hex(),
226
- "the authoritative row holds B, and nothing holds A beside it"
227
- );
228
-
229
- // A is present in the log only for as long as the log is uncompacted,
230
- // which the previous test shows is not a durability guarantee.
231
- let operations = db.operations_since(&HashMap::new()).unwrap();
232
- let a_in_log = operations
233
- .iter()
234
- .filter(|op| op.key == "tasks:4")
235
- .any(|op| op.value.as_ref().unwrap()["title"] == json!("A"));
236
- assert!(
237
- a_in_log,
238
- "A is in the log now — but only until acknowledged operations are pruned"
239
- );
240
-
241
- // And there is no revision for it: nothing in this path mints one.
242
- // `a_id` was computed by this test, not by FeltDB; no durable record
243
- // anywhere associates it with the resource.
244
- assert_eq!(
245
- a_id.as_hex().len(),
246
- 64,
247
- "an identity for A is computable, but it is computed here and stored nowhere"
248
- );
249
- }