@feltdb/core 0.8.3 → 0.8.5
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.
- package/dist/cli/commands.js +4 -1
- package/dist/cli/provisioning-neutrality.js +79 -0
- package/dist/collection.d.ts +43 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +192 -22
- package/dist/create/create.js +25 -21
- package/dist/create/managed-account.js +11 -0
- package/dist/create/package-versions.js +1 -1
- package/dist/create/server-source/Cargo.lock +165 -0
- package/dist/create/server-source/Cargo.toml +9 -0
- package/dist/create/server-source/crates/feltdb/Cargo.toml +3 -0
- package/dist/create/server-source/crates/feltdb/benches/gate13_baseline.rs +44 -44
- package/dist/create/server-source/crates/feltdb/benches/gate13_phase_7_1_release_economics.rs +12 -24
- package/dist/create/server-source/crates/feltdb/benches/gate_13_redux.rs +7 -13
- package/dist/create/server-source/crates/feltdb/benches/gate_13_regression_runner.rs +13 -10
- package/dist/create/server-source/crates/feltdb/benches/gate_14a_concurrent_writer_scaling.rs +12 -9
- package/dist/create/server-source/crates/feltdb/benches/gate_14a_production_admission_revalidation.rs +78 -25
- package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc2_admission_contract.rs +16 -13
- package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc_root_cause.rs +13 -5
- package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync1_queued_prototype.rs +41 -22
- package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync_economics.rs +33 -15
- package/dist/create/server-source/crates/feltdb/benches/gate_14b_causal_backlog_scaling.rs +100 -33
- package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_contract_test.rs +56 -20
- package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_scaling.rs +116 -41
- package/dist/create/server-source/crates/feltdb/benches/gate_14d_combined_dimension_scaling.rs +186 -55
- package/dist/create/server-source/crates/feltdb/benches/phase_7_1_2_optimization_benchmark.rs +64 -26
- package/dist/create/server-source/crates/feltdb/benches/phase_7_1_3_crossover_analysis.rs +46 -15
- package/dist/create/server-source/crates/feltdb/src/admission.rs +8 -15
- package/dist/create/server-source/crates/feltdb/src/admission_contract_tests.rs +43 -13
- package/dist/create/server-source/crates/feltdb/src/adversarial_transport.rs +15 -42
- package/dist/create/server-source/crates/feltdb/src/analytics.rs +65 -19
- package/dist/create/server-source/crates/feltdb/src/application.rs +113 -30
- package/dist/create/server-source/crates/feltdb/src/authorization_security_tests.rs +475 -140
- package/dist/create/server-source/crates/feltdb/src/cardinality_diagnostics.rs +17 -15
- package/dist/create/server-source/crates/feltdb/src/cardinality_endpoint.rs +0 -1
- package/dist/create/server-source/crates/feltdb/src/causal_backlog_bound.rs +59 -15
- package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier.rs +266 -114
- package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier_phase_7_1.rs +25 -7
- package/dist/create/server-source/crates/feltdb/src/concurrency_fuzzing.rs +10 -15
- package/dist/create/server-source/crates/feltdb/src/consistency_contract.rs +3 -11
- package/dist/create/server-source/crates/feltdb/src/crash_atomic_boundary.rs +14 -5
- package/dist/create/server-source/crates/feltdb/src/crash_injection.rs +21 -25
- package/dist/create/server-source/crates/feltdb/src/crash_recovery_tests.rs +14 -11
- package/dist/create/server-source/crates/feltdb/src/dedup_bound_investigation.rs +103 -22
- package/dist/create/server-source/crates/feltdb/src/distributed_indexing.rs +18 -15
- package/dist/create/server-source/crates/feltdb/src/durability_guarantees.rs +12 -8
- package/dist/create/server-source/crates/feltdb/src/durable_dedup_set.rs +1 -5
- package/dist/create/server-source/crates/feltdb/src/durable_operation_identity.rs +87 -23
- package/dist/create/server-source/crates/feltdb/src/durable_operation_log.rs +3 -7
- package/dist/create/server-source/crates/feltdb/src/durable_sync.rs +10 -9
- package/dist/create/server-source/crates/feltdb/src/equality_index.rs +595 -0
- package/dist/create/server-source/crates/feltdb/src/in_process_transport.rs +1 -6
- package/dist/create/server-source/crates/feltdb/src/indexing.rs +35 -38
- package/dist/create/server-source/crates/feltdb/src/lib.rs +1050 -117
- package/dist/create/server-source/crates/feltdb/src/managed_cas_tests.rs +4 -1
- package/dist/create/server-source/crates/feltdb/src/metrics.rs +0 -1
- package/dist/create/server-source/crates/feltdb/src/multi_node_convergence.rs +1 -2
- package/dist/create/server-source/crates/feltdb/src/multi_operation_transaction.rs +107 -30
- package/dist/create/server-source/crates/feltdb/src/observability.rs +19 -6
- package/dist/create/server-source/crates/feltdb/src/operation_algebra.rs +12 -11
- package/dist/create/server-source/crates/feltdb/src/operation_log.rs +9 -4
- package/dist/create/server-source/crates/feltdb/src/p1_application_atomicity.rs +65 -18
- package/dist/create/server-source/crates/feltdb/src/p1_atomicity_acceptance.rs +193 -57
- package/dist/create/server-source/crates/feltdb/src/partition_reconciliation.rs +37 -27
- package/dist/create/server-source/crates/feltdb/src/permutation_scheduler.rs +38 -10
- package/dist/create/server-source/crates/feltdb/src/persistence_reality.rs +20 -14
- package/dist/create/server-source/crates/feltdb/src/phase1b_acceptance.rs +394 -229
- package/dist/create/server-source/crates/feltdb/src/phase1c1_acceptance.rs +8 -6
- package/dist/create/server-source/crates/feltdb/src/phase1c2_acceptance.rs +11 -13
- package/dist/create/server-source/crates/feltdb/src/phase1c3_acceptance.rs +90 -72
- package/dist/create/server-source/crates/feltdb/src/phase1c_atomicity_proof.rs +3 -3
- package/dist/create/server-source/crates/feltdb/src/phase5_integration.rs +33 -11
- package/dist/create/server-source/crates/feltdb/src/phase5_scenarios.rs +6 -6
- package/dist/create/server-source/crates/feltdb/src/phase6_adversarial_scenarios.rs +14 -56
- package/dist/create/server-source/crates/feltdb/src/phase6_convergence_validator.rs +29 -27
- package/dist/create/server-source/crates/feltdb/src/phase6_persistence.rs +35 -17
- package/dist/create/server-source/crates/feltdb/src/phase_1c_real_tcp.rs +8 -2
- package/dist/create/server-source/crates/feltdb/src/phase_2a_failures.rs +59 -15
- package/dist/create/server-source/crates/feltdb/src/phase_2b_network.rs +70 -17
- package/dist/create/server-source/crates/feltdb/src/phase_2c_cascading.rs +23 -6
- package/dist/create/server-source/crates/feltdb/src/phase_3_durability.rs +12 -3
- package/dist/create/server-source/crates/feltdb/src/phase_4_baseline.rs +41 -11
- package/dist/create/server-source/crates/feltdb/src/phase_5_soak.rs +56 -25
- package/dist/create/server-source/crates/feltdb/src/policy_evaluation.rs +701 -245
- package/dist/create/server-source/crates/feltdb/src/production_api.rs +31 -13
- package/dist/create/server-source/crates/feltdb/src/query_execution_diagnostics.rs +126 -0
- package/dist/create/server-source/crates/feltdb/src/query_performance.rs +6 -8
- package/dist/create/server-source/crates/feltdb/src/replay_fuzzing.rs +5 -5
- package/dist/create/server-source/crates/feltdb/src/replica_acknowledgements.rs +48 -18
- package/dist/create/server-source/crates/feltdb/src/replica_membership.rs +30 -11
- package/dist/create/server-source/crates/feltdb/src/replication_manager.rs +6 -3
- package/dist/create/server-source/crates/feltdb/src/replication_protocol.rs +4 -3
- package/dist/create/server-source/crates/feltdb/src/sharding.rs +36 -10
- package/dist/create/server-source/crates/feltdb/src/state_conflict_contract.rs +516 -0
- package/dist/create/server-source/crates/feltdb/src/state_contract.rs +305 -6
- package/dist/create/server-source/crates/feltdb/src/state_diff_contract.rs +222 -0
- package/dist/create/server-source/crates/feltdb/src/state_facade.rs +82 -54
- package/dist/create/server-source/crates/feltdb/src/state_hash.rs +2 -2
- package/dist/create/server-source/crates/feltdb/src/state_model.rs +1514 -537
- package/dist/create/server-source/crates/feltdb/src/state_transition_store.rs +6 -3
- package/dist/create/server-source/crates/feltdb/src/state_trigger.rs +672 -0
- package/dist/create/server-source/crates/feltdb/src/submission.rs +5 -11
- package/dist/create/server-source/crates/feltdb/src/sync.rs +12 -0
- package/dist/create/server-source/crates/feltdb/src/tcp_transport.rs +6 -8
- package/dist/create/server-source/crates/feltdb/src/transaction_api.rs +24 -35
- package/dist/create/server-source/crates/feltdb/src/transaction_invariants.rs +24 -8
- package/dist/create/server-source/crates/feltdb/src/transaction_preconditions.rs +248 -59
- package/dist/create/server-source/crates/feltdb/src/transactions.rs +17 -20
- package/dist/create/server-source/crates/feltdb/src/trigger_contract.rs +749 -0
- package/dist/create/server-source/crates/feltdb/src/worker_mesh.rs +1 -0
- package/dist/create/server-source/crates/feltdb/src/workload.rs +512 -4
- package/dist/create/server-source/crates/feltdb/src/workload_diagnostics.rs +442 -0
- package/dist/create/server-source/crates/feltdb/tests/branching_evidence.rs +299 -0
- package/dist/create/server-source/crates/feltdb/tests/current_revision_authority_evidence.rs +288 -0
- package/dist/create/server-source/crates/feltdb/tests/durable_format_compatibility.rs +392 -0
- package/dist/create/server-source/crates/feltdb/tests/feltdb_state_boundary_tests.rs +436 -220
- package/dist/create/server-source/crates/feltdb/tests/fixtures/state_conflict_contract_corpus.json +1916 -0
- package/dist/create/server-source/crates/feltdb/tests/fixtures/state_diff_contract_corpus.json +1878 -0
- package/dist/create/server-source/crates/feltdb/tests/fixtures/trigger_contract_corpus.json +1862 -0
- package/dist/create/server-source/crates/feltdb/tests/pr34_query_collection.rs +234 -0
- package/dist/create/server-source/crates/feltdb/tests/pr35_equality_index.rs +947 -0
- package/dist/create/server-source/crates/feltdb/tests/pr7_self_authorization_proof.rs +5 -8
- package/dist/create/server-source/crates/feltdb/tests/pr8_vocabulary_assessment.rs +52 -44
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase2_boundary_tests.rs +33 -16
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase3a_path_a_tests.rs +22 -7
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_authorized_mutations.rs +41 -22
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_role_based_authorization.rs +25 -8
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_simple_auth_delete.rs +9 -6
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_team_delete_role_authorization.rs +120 -69
- package/dist/create/server-source/crates/feltdb/tests/pr9_teams_role_based_access.rs +21 -10
- package/dist/create/server-source/crates/feltdb/tests/production_readiness_contract.rs +1032 -0
- package/dist/create/server-source/crates/feltdb/tests/reconciliation_application.rs +868 -0
- package/dist/create/server-source/crates/feltdb/tests/reconciliation_wire_format_evidence.rs +221 -0
- package/dist/create/server-source/crates/feltdb/tests/resource_scoped_revisions.rs +338 -0
- package/dist/create/server-source/crates/feltdb/tests/revision_identity_contract.rs +1039 -0
- package/dist/create/server-source/crates/feltdb/tests/revision_model_decision.rs +739 -0
- package/dist/create/server-source/crates/feltdb/tests/revision_retention_boundary_evidence.rs +427 -0
- package/dist/create/server-source/crates/feltdb/tests/saas_authorization_integration.rs +3 -3
- package/dist/create/server-source/crates/feltdb/tests/saas_invitation_lifecycle.rs +25 -22
- package/dist/create/server-source/crates/feltdb/tests/state_conflict_contract_conformance.rs +1799 -0
- package/dist/create/server-source/crates/feltdb/tests/state_diff_contract_conformance.rs +1316 -0
- package/dist/create/server-source/crates/feltdb/tests/state_model_integration.rs +53 -61
- package/dist/create/server-source/crates/feltdb/tests/state_persistence_integration.rs +156 -61
- package/dist/create/server-source/crates/feltdb/tests/state_store_boundary_evidence.rs +299 -0
- package/dist/create/server-source/crates/feltdb/tests/sync_divergence_evidence.rs +255 -0
- package/dist/create/server-source/crates/feltdb/tests/three_way_input_boundary_evidence.rs +249 -0
- package/dist/create/server-source/crates/feltdb/tests/trigger_contract_conformance.rs +994 -0
- package/dist/create/server-source/crates/feltdb-server/src/app_state.rs +2 -1
- package/dist/create/server-source/crates/feltdb-server/src/audit.rs +1137 -29
- package/dist/create/server-source/crates/feltdb-server/src/auth.rs +164 -13
- package/dist/create/server-source/crates/feltdb-server/src/main.rs +800 -34
- package/dist/db.d.ts +33 -34
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +74 -20
- package/dist/deployment.d.ts +30 -0
- package/dist/deployment.d.ts.map +1 -0
- package/dist/deployment.js +130 -0
- package/dist/embedded-transaction.d.ts +22 -4
- package/dist/embedded-transaction.d.ts.map +1 -1
- package/dist/embedded-transaction.js +51 -5
- package/dist/feltdb.d.ts +14 -2
- package/dist/feltdb.d.ts.map +1 -1
- package/dist/file-db.js +1 -1
- package/dist/http-client.d.ts +14 -0
- package/dist/http-client.d.ts.map +1 -1
- package/dist/http-client.js +23 -5
- package/dist/http-db.d.ts +119 -1
- package/dist/http-db.d.ts.map +1 -1
- package/dist/http-db.js +346 -31
- package/dist/index-core.d.ts +2 -0
- package/dist/index-core.d.ts.map +1 -1
- package/dist/index-core.js +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/indexeddb-db.d.ts.map +1 -1
- package/dist/indexeddb-db.js +35 -21
- package/dist/managed-recovery.d.ts +192 -0
- package/dist/managed-recovery.d.ts.map +1 -0
- package/dist/managed-recovery.js +242 -0
- package/dist/memory-db.js +1 -1
- package/dist/studio-app/assets/{feltdb_wasm-DB8cX151.js → feltdb_wasm-DaNwCLRX.js} +1 -1
- package/dist/studio-app/assets/feltdb_wasm_bg-DnsHNv6g.wasm +0 -0
- package/dist/studio-app/assets/index-j8IlhNqJ.js +29 -0
- package/dist/studio-app/index.html +1 -1
- package/dist/transaction.d.ts +30 -0
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +41 -0
- package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
- package/dist/workload.d.ts +2 -1
- package/dist/workload.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/studio-app/assets/feltdb_wasm_bg-ClhDHp0S.wasm +0 -0
- package/dist/studio-app/assets/index-B0k4UAlI.js +0 -29
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
//! Evidence for the StateStore boundary audit
|
|
2
|
+
//! (`docs/audits/STATESTORE-BOUNDARY-AUDIT.md`).
|
|
3
|
+
//!
|
|
4
|
+
//! These tests add **no capability and no product surface**. They answer one
|
|
5
|
+
//! adversarial question with runs rather than readings:
|
|
6
|
+
//!
|
|
7
|
+
//! > Can FeltDB expose immutable state history through the existing server
|
|
8
|
+
//! > authority with fewer primitives than a conventional database or branch
|
|
9
|
+
//! > system requires?
|
|
10
|
+
//!
|
|
11
|
+
//! The answer is yes, and the margin is large. `MinimalStore` below is written
|
|
12
|
+
//! in this test file deliberately: demonstrating that a shape is sufficient is
|
|
13
|
+
//! not the same as committing the product to it, and this PR adds no API.
|
|
14
|
+
|
|
15
|
+
use feltdb::state_model::{
|
|
16
|
+
apply_reconciliation_plan, ConflictClass, ConflictClassification, ReconciliationPlan, StateId,
|
|
17
|
+
StateRevision, StateStore,
|
|
18
|
+
};
|
|
19
|
+
use feltdb::FeltDb;
|
|
20
|
+
use std::collections::HashMap;
|
|
21
|
+
use std::sync::Arc;
|
|
22
|
+
use tempfile::TempDir;
|
|
23
|
+
|
|
24
|
+
fn revision(content: &str) -> StateRevision {
|
|
25
|
+
StateRevision {
|
|
26
|
+
id: StateId::compute(content),
|
|
27
|
+
resource: "docs:1".into(),
|
|
28
|
+
content: content.to_string(),
|
|
29
|
+
content_id: StateId::compute(content),
|
|
30
|
+
sequence: 0,
|
|
31
|
+
parent_id: None,
|
|
32
|
+
authority: "test".into(),
|
|
33
|
+
timestamp_ms: 0,
|
|
34
|
+
metadata: Default::default(),
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
// A store built from two operations
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
/// A read-through revision store built from nothing but `FeltDb::insert` and
|
|
43
|
+
/// `FeltDb::get`.
|
|
44
|
+
///
|
|
45
|
+
/// No in-memory index, no `current` pointer, no branches, and — because every
|
|
46
|
+
/// record is keyed by the hash of its own content — no recovery path.
|
|
47
|
+
struct MinimalStore {
|
|
48
|
+
db: Arc<FeltDb>,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
impl MinimalStore {
|
|
52
|
+
fn key(id: &StateId) -> String {
|
|
53
|
+
format!("state:revision:{}", id.as_hex())
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fn put(&self, revision: &StateRevision) -> Result<(), String> {
|
|
57
|
+
if !revision.verify_integrity() {
|
|
58
|
+
return Err("integrity check failed".into());
|
|
59
|
+
}
|
|
60
|
+
self.db
|
|
61
|
+
.insert(&Self::key(&revision.id), revision.clone())
|
|
62
|
+
.map_err(|error| error.to_string())
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fn get(&self, id: &StateId) -> Option<StateRevision> {
|
|
66
|
+
self.db.get::<StateRevision>(&Self::key(id)).ok().flatten()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/// Ancestry is not a third operation. It is `get` and `parent_id`.
|
|
70
|
+
fn ancestors(&self, id: &StateId) -> Vec<StateId> {
|
|
71
|
+
let mut out = vec![];
|
|
72
|
+
let mut cursor = self.get(id).and_then(|revision| revision.parent_id);
|
|
73
|
+
while let Some(parent) = cursor {
|
|
74
|
+
out.push(parent.clone());
|
|
75
|
+
cursor = self.get(&parent).and_then(|revision| revision.parent_id);
|
|
76
|
+
}
|
|
77
|
+
out
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// Two operations carry the whole chain, across a real restart, with no
|
|
82
|
+
/// recovery step and no mutable pointer.
|
|
83
|
+
///
|
|
84
|
+
/// This is the audit's central result. The store is opened, written, dropped,
|
|
85
|
+
/// and reopened over the same log by a *different* `FeltDb` instance; nothing
|
|
86
|
+
/// reconstructs an index, and the three revisions reconciliation needs are read
|
|
87
|
+
/// back by identity alone.
|
|
88
|
+
#[test]
|
|
89
|
+
fn two_operations_carry_the_whole_chain_across_a_restart() {
|
|
90
|
+
let directory = TempDir::new().unwrap();
|
|
91
|
+
let path = directory.path().join("minimal.log");
|
|
92
|
+
|
|
93
|
+
let (base_id, left_id, right_id) = {
|
|
94
|
+
let store = MinimalStore {
|
|
95
|
+
db: Arc::new(FeltDb::open(&path).unwrap()),
|
|
96
|
+
};
|
|
97
|
+
let base = StateRevision::initial(
|
|
98
|
+
"docs:1".to_string(),
|
|
99
|
+
r#"{"shared":1,"only_left":1}"#.into(),
|
|
100
|
+
"a".into(),
|
|
101
|
+
);
|
|
102
|
+
let left = StateRevision::child(
|
|
103
|
+
r#"{"shared":10,"only_left":2}"#.into(),
|
|
104
|
+
&base,
|
|
105
|
+
"alice".into(),
|
|
106
|
+
);
|
|
107
|
+
let right =
|
|
108
|
+
StateRevision::child(r#"{"shared":20,"only_left":1}"#.into(), &base, "bob".into());
|
|
109
|
+
|
|
110
|
+
store.put(&base).unwrap();
|
|
111
|
+
store.put(&left).unwrap();
|
|
112
|
+
store.put(&right).unwrap();
|
|
113
|
+
(base.id.clone(), left.id.clone(), right.id.clone())
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// A different FeltDb instance over the same log. No recovery is run.
|
|
117
|
+
let store = MinimalStore {
|
|
118
|
+
db: Arc::new(FeltDb::open(&path).unwrap()),
|
|
119
|
+
};
|
|
120
|
+
let base = store.get(&base_id).expect("base survives");
|
|
121
|
+
let left = store.get(&left_id).expect("left survives");
|
|
122
|
+
let right = store.get(&right_id).expect("right survives");
|
|
123
|
+
assert!(base.verify_integrity() && left.verify_integrity() && right.verify_integrity());
|
|
124
|
+
|
|
125
|
+
// The full chain runs against what was read back.
|
|
126
|
+
let classification = ConflictClassification::classify(&base, &left, &right);
|
|
127
|
+
assert_eq!(classification.overall, ConflictClass::Conflict);
|
|
128
|
+
|
|
129
|
+
let plan = ReconciliationPlan::new(left.id.clone(), right.id.clone(), base.id.clone(), true);
|
|
130
|
+
let content = apply_reconciliation_plan(&base, &left, &right, &plan).expect("applies");
|
|
131
|
+
assert_eq!(content, r#"{"only_left":2,"shared":10}"#);
|
|
132
|
+
|
|
133
|
+
let result = StateRevision::child(content, &left, "reconciler".into());
|
|
134
|
+
store.put(&result).expect("the result persists");
|
|
135
|
+
assert_eq!(
|
|
136
|
+
store.ancestors(&result.id),
|
|
137
|
+
vec![left_id, base_id],
|
|
138
|
+
"ancestry needs no primitive beyond get and parent_id"
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// And no shared mutable record was ever written.
|
|
142
|
+
let current = store
|
|
143
|
+
.db
|
|
144
|
+
.get::<(String, HashMap<String, String>)>("state:current")
|
|
145
|
+
.unwrap();
|
|
146
|
+
assert!(
|
|
147
|
+
current.is_none(),
|
|
148
|
+
"a content-addressed history needs no current pointer"
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
// What the chain actually requires
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
/// Application reads exactly one content, and three identities.
|
|
157
|
+
///
|
|
158
|
+
/// The base and the branch that was *not* selected contribute nothing but their
|
|
159
|
+
/// ids — both may be unparseable and application still succeeds. This bounds
|
|
160
|
+
/// what a store must be able to serve at the moment a plan is applied: one full
|
|
161
|
+
/// state, not three.
|
|
162
|
+
///
|
|
163
|
+
/// Classification is the step that reads all three, so the chain as a whole
|
|
164
|
+
/// still needs all three. The distinction matters for a durable design, because
|
|
165
|
+
/// the two steps could be served differently.
|
|
166
|
+
#[test]
|
|
167
|
+
fn application_reads_one_content_and_three_identities() {
|
|
168
|
+
let base = revision("this is not json at all");
|
|
169
|
+
let left = revision(r#"{"a":1}"#);
|
|
170
|
+
let right = revision("also not json");
|
|
171
|
+
|
|
172
|
+
let plan = ReconciliationPlan::new(left.id.clone(), right.id.clone(), base.id.clone(), true);
|
|
173
|
+
assert_eq!(
|
|
174
|
+
apply_reconciliation_plan(&base, &left, &right, &plan).expect("applies"),
|
|
175
|
+
r#"{"a":1}"#,
|
|
176
|
+
"only the selected parent's content is read"
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/// The chain from three revisions to a reconciled one names no branch.
|
|
181
|
+
#[test]
|
|
182
|
+
fn the_chain_needs_no_branch() {
|
|
183
|
+
let store = StateStore::new_volatile();
|
|
184
|
+
let base = store
|
|
185
|
+
.create("docs:1", r#"{"v":1}"#.into(), "a".into())
|
|
186
|
+
.unwrap();
|
|
187
|
+
let left = store
|
|
188
|
+
.commit(r#"{"v":2}"#.into(), &base, "alice".into())
|
|
189
|
+
.unwrap();
|
|
190
|
+
let right = store
|
|
191
|
+
.commit(r#"{"v":3}"#.into(), &base, "bob".into())
|
|
192
|
+
.unwrap();
|
|
193
|
+
|
|
194
|
+
let plan = ReconciliationPlan::new(left.id.clone(), right.id.clone(), base.id.clone(), true);
|
|
195
|
+
assert!(apply_reconciliation_plan(&base, &left, &right, &plan).is_ok());
|
|
196
|
+
assert!(
|
|
197
|
+
store.get(&base.id).is_some() && store.get(&left.id).is_some(),
|
|
198
|
+
"the chain named no branch, and every revision stayed addressable"
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ---------------------------------------------------------------------------
|
|
203
|
+
// What the existing store costs
|
|
204
|
+
// ---------------------------------------------------------------------------
|
|
205
|
+
|
|
206
|
+
/// No commit writes a shared mutable record. **Regression.**
|
|
207
|
+
///
|
|
208
|
+
/// This test previously asserted the opposite, as a finding: `state:current`
|
|
209
|
+
/// carried the global current pointer *and* the whole branch map in one
|
|
210
|
+
/// replicated record — the record behind both defects the branching audit
|
|
211
|
+
/// reported — and `commit_revision` wrote it unconditionally, so a caller that
|
|
212
|
+
/// never created a branch did not avoid it.
|
|
213
|
+
///
|
|
214
|
+
/// That record no longer exists. The store's entire durable schema is
|
|
215
|
+
/// `state:revision:{hex}`, one record per revision, and nothing else is
|
|
216
|
+
/// written. The two defects were removed with it rather than repaired.
|
|
217
|
+
#[test]
|
|
218
|
+
fn no_commit_writes_a_shared_mutable_record() {
|
|
219
|
+
let directory = TempDir::new().unwrap();
|
|
220
|
+
let db = Arc::new(FeltDb::open(directory.path().join("shared.log")).unwrap());
|
|
221
|
+
let store = StateStore::with_feltdb(db.clone()).unwrap();
|
|
222
|
+
|
|
223
|
+
let base = store
|
|
224
|
+
.create("docs:1", r#"{"v":1}"#.into(), "a".into())
|
|
225
|
+
.unwrap();
|
|
226
|
+
let child = store
|
|
227
|
+
.commit(r#"{"v":2}"#.into(), &base, "a".into())
|
|
228
|
+
.unwrap();
|
|
229
|
+
|
|
230
|
+
assert!(
|
|
231
|
+
db.get::<(String, HashMap<String, String>)>("state:current")
|
|
232
|
+
.unwrap()
|
|
233
|
+
.is_none(),
|
|
234
|
+
"the record that carried the global pointer and the branch map is gone"
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
// What *is* written is one record per revision, and nothing else.
|
|
238
|
+
for revision in [&base, &child] {
|
|
239
|
+
assert_eq!(
|
|
240
|
+
store
|
|
241
|
+
.get(&revision.id)
|
|
242
|
+
.expect("revision is durable")
|
|
243
|
+
.content,
|
|
244
|
+
revision.content
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/// One damaged record no longer refuses the whole store. **Regression.**
|
|
250
|
+
///
|
|
251
|
+
/// This test previously asserted the opposite, as a finding: `with_feltdb`
|
|
252
|
+
/// eagerly loaded every revision, re-verified every content hash, and validated
|
|
253
|
+
/// every parent reference before returning, so a single orphaned record that no
|
|
254
|
+
/// caller would ever request refused the entire store.
|
|
255
|
+
///
|
|
256
|
+
/// There is no recovery step now. Reads are keyed and independent, so a damaged
|
|
257
|
+
/// or unrelated record is simply a record nobody asked for. This is the
|
|
258
|
+
/// operational difference between an index that must be rebuilt and records
|
|
259
|
+
/// addressed by content.
|
|
260
|
+
#[test]
|
|
261
|
+
fn one_damaged_record_does_not_refuse_the_whole_store() {
|
|
262
|
+
let directory = TempDir::new().unwrap();
|
|
263
|
+
let path = directory.path().join("domain.log");
|
|
264
|
+
|
|
265
|
+
let good_id = {
|
|
266
|
+
let db = Arc::new(FeltDb::open(&path).unwrap());
|
|
267
|
+
let store = StateStore::with_feltdb(db.clone()).unwrap();
|
|
268
|
+
let good = store
|
|
269
|
+
.create("docs:1", r#"{"v":1}"#.into(), "a".into())
|
|
270
|
+
.unwrap();
|
|
271
|
+
|
|
272
|
+
// An unrelated revision whose parent was never stored. Nothing the
|
|
273
|
+
// caller will ever ask for.
|
|
274
|
+
let orphan = StateRevision {
|
|
275
|
+
id: StateId::compute(r#"{"orphan":true}"#),
|
|
276
|
+
resource: "docs:1".into(),
|
|
277
|
+
content: r#"{"orphan":true}"#.into(),
|
|
278
|
+
content_id: StateId::compute(r#"{"orphan":true}"#),
|
|
279
|
+
sequence: 0,
|
|
280
|
+
parent_id: Some(StateId::compute("a parent that was never stored")),
|
|
281
|
+
authority: "x".into(),
|
|
282
|
+
timestamp_ms: 0,
|
|
283
|
+
metadata: Default::default(),
|
|
284
|
+
};
|
|
285
|
+
db.insert(&format!("state:revision:{}", orphan.id.as_hex()), orphan)
|
|
286
|
+
.unwrap();
|
|
287
|
+
good.id
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
let db = Arc::new(FeltDb::open(&path).unwrap());
|
|
291
|
+
let store = StateStore::with_feltdb(db).expect("the store opens despite the orphan");
|
|
292
|
+
|
|
293
|
+
// The intact revision is readable by identity, unaffected by its neighbour.
|
|
294
|
+
let good = store
|
|
295
|
+
.get(&good_id)
|
|
296
|
+
.expect("the intact revision is readable");
|
|
297
|
+
assert!(good.verify_integrity());
|
|
298
|
+
assert_eq!(good.content, r#"{"v":1}"#);
|
|
299
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
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
|
+
}
|