@feltdb/core 0.8.4 → 0.8.6
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/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/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 +1648 -46
- 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.rs +39 -0
- 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 +79 -70
- 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_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 +13 -4
- 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 +1565 -536
- 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/storage.rs +9 -3
- package/dist/create/server-source/crates/feltdb/src/submission.rs +5 -11
- 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 +3 -4
- package/dist/create/server-source/crates/feltdb/tests/bounded_read_contract.rs +132 -0
- package/dist/create/server-source/crates/feltdb/tests/branching_evidence.rs +299 -0
- package/dist/create/server-source/crates/feltdb/tests/compaction_stall_contract.rs +272 -0
- package/dist/create/server-source/crates/feltdb/tests/crash_durability_contract.rs +467 -0
- package/dist/create/server-source/crates/feltdb/tests/current_revision_authority_evidence.rs +309 -0
- package/dist/create/server-source/crates/feltdb/tests/durable_backup_contract.rs +445 -0
- package/dist/create/server-source/crates/feltdb/tests/durable_corruption_contract.rs +518 -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/operational_health_contract.rs +278 -0
- package/dist/create/server-source/crates/feltdb/tests/pr34_query_collection.rs +2 -1
- package/dist/create/server-source/crates/feltdb/tests/pr35_equality_index.rs +80 -25
- 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 +1365 -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/replicated_history_contract.rs +417 -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/tests/workload_envelope_contract.rs +442 -0
- package/dist/create/server-source/crates/feltdb-server/src/app_state.rs +16 -1
- package/dist/create/server-source/crates/feltdb-server/src/auth.rs +164 -13
- package/dist/create/server-source/crates/feltdb-server/src/main.rs +695 -47
- package/dist/create/server-source/crates/feltdb-server/src/metrics.rs +21 -0
- package/dist/studio-app/assets/{feltdb_wasm-CVQWgXO-.js → feltdb_wasm-C1VhI-U5.js} +1 -1
- package/dist/studio-app/assets/feltdb_wasm_bg-C8HXbAXb.wasm +0 -0
- package/dist/studio-app/assets/{index-DwgNAIIX.js → index-Bbos1m2U.js} +1 -1
- package/dist/studio-app/index.html +1 -1
- 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-CNVpvaZV.wasm +0 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
//! Scoped reads must not materialize a collection.
|
|
2
|
+
//!
|
|
3
|
+
//! The managed incident's amplifier: `list_collection` takes the one lock that
|
|
4
|
+
//! serializes every read and write, and **clones every row in the collection**.
|
|
5
|
+
//! A keyed lookup implemented that way, or a search that filters after the
|
|
6
|
+
//! clone, extends the window in which nothing else in the database can proceed.
|
|
7
|
+
//!
|
|
8
|
+
//! The code's own comment already recorded this pathology being seen before:
|
|
9
|
+
//!
|
|
10
|
+
//! > *a query holding the lock while it cloned a collection inflated the cost
|
|
11
|
+
//! > of unrelated writes*
|
|
12
|
+
//!
|
|
13
|
+
//! The bounded APIs already existed. These tests pin the properties the server
|
|
14
|
+
//! now depends on, so a future handler cannot quietly go back to the scanning
|
|
15
|
+
//! form.
|
|
16
|
+
|
|
17
|
+
use feltdb::FeltDb;
|
|
18
|
+
use serde_json::json;
|
|
19
|
+
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
20
|
+
use tempfile::TempDir;
|
|
21
|
+
|
|
22
|
+
fn populated(rows: usize) -> (TempDir, FeltDb) {
|
|
23
|
+
let directory = TempDir::new().unwrap();
|
|
24
|
+
let db = FeltDb::open(directory.path().join("reads.log")).unwrap();
|
|
25
|
+
for index in 0..rows {
|
|
26
|
+
db.insert(
|
|
27
|
+
&format!("docs:{index:05}"),
|
|
28
|
+
json!({ "n": index, "body": "x".repeat(200) }),
|
|
29
|
+
)
|
|
30
|
+
.unwrap();
|
|
31
|
+
}
|
|
32
|
+
(directory, db)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// **A keyed lookup reads one record.**
|
|
36
|
+
///
|
|
37
|
+
/// `get_provenance` used to call `list_collection` and `find` the key, cloning
|
|
38
|
+
/// the entire collection to return one row.
|
|
39
|
+
#[test]
|
|
40
|
+
fn a_keyed_lookup_does_not_materialize_the_collection() {
|
|
41
|
+
let (_directory, db) = populated(500);
|
|
42
|
+
|
|
43
|
+
let row = db
|
|
44
|
+
.get_collection_record("docs", "docs:00042")
|
|
45
|
+
.unwrap()
|
|
46
|
+
.expect("the record is found");
|
|
47
|
+
assert_eq!(row.value["n"], json!(42));
|
|
48
|
+
|
|
49
|
+
assert!(db
|
|
50
|
+
.get_collection_record("docs", "docs:99999")
|
|
51
|
+
.unwrap()
|
|
52
|
+
.is_none());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// **A bounded search stops at its limit.**
|
|
56
|
+
///
|
|
57
|
+
/// The predicate is the observable proof: it runs once per row *visited*, so a
|
|
58
|
+
/// limited search over a large collection visits far fewer rows than the
|
|
59
|
+
/// collection holds. The scanning form evaluated every row, every time.
|
|
60
|
+
#[test]
|
|
61
|
+
fn a_bounded_search_stops_at_the_limit_instead_of_scanning() {
|
|
62
|
+
let (_directory, db) = populated(500);
|
|
63
|
+
let visited = AtomicUsize::new(0);
|
|
64
|
+
|
|
65
|
+
// Every row matches, so the only thing that can stop the traversal is the
|
|
66
|
+
// limit.
|
|
67
|
+
let matched = db
|
|
68
|
+
.query_collection("docs", Some(10), |row| {
|
|
69
|
+
visited.fetch_add(1, Ordering::Relaxed);
|
|
70
|
+
row.value["body"].is_string()
|
|
71
|
+
})
|
|
72
|
+
.unwrap();
|
|
73
|
+
|
|
74
|
+
assert_eq!(matched.len(), 10, "the limit is honoured");
|
|
75
|
+
assert_eq!(
|
|
76
|
+
visited.load(Ordering::Relaxed),
|
|
77
|
+
10,
|
|
78
|
+
"and the traversal stopped there rather than visiting all 500"
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// Only matching rows are cloned; rejected rows are borrowed and dropped.
|
|
83
|
+
#[test]
|
|
84
|
+
fn a_search_clones_only_what_it_returns() {
|
|
85
|
+
let (_directory, db) = populated(300);
|
|
86
|
+
let visited = AtomicUsize::new(0);
|
|
87
|
+
|
|
88
|
+
let matched = db
|
|
89
|
+
.query_collection("docs", None, |row| {
|
|
90
|
+
visited.fetch_add(1, Ordering::Relaxed);
|
|
91
|
+
row.value["n"].as_u64() == Some(7)
|
|
92
|
+
})
|
|
93
|
+
.unwrap();
|
|
94
|
+
|
|
95
|
+
assert_eq!(matched.len(), 1);
|
|
96
|
+
assert_eq!(
|
|
97
|
+
visited.load(Ordering::Relaxed),
|
|
98
|
+
300,
|
|
99
|
+
"an unlimited search still visits every row — the saving is in cloning"
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// Paging traverses in key order and is bounded, so a large collection is
|
|
104
|
+
/// readable without a single unbounded materialization.
|
|
105
|
+
#[test]
|
|
106
|
+
fn paging_is_bounded_and_ordered() {
|
|
107
|
+
let (_directory, db) = populated(120);
|
|
108
|
+
|
|
109
|
+
let first = db.list_collection_page("docs", None, 25).unwrap();
|
|
110
|
+
assert_eq!(first.len(), 25);
|
|
111
|
+
assert_eq!(first[0].key, "docs:00000");
|
|
112
|
+
|
|
113
|
+
let after = first.last().unwrap().key.clone();
|
|
114
|
+
let second = db.list_collection_page("docs", Some(&after), 25).unwrap();
|
|
115
|
+
assert_eq!(second.len(), 25);
|
|
116
|
+
assert!(second[0].key > after, "paging advances");
|
|
117
|
+
|
|
118
|
+
// The whole collection is reachable in bounded steps.
|
|
119
|
+
let mut seen = 0;
|
|
120
|
+
let mut cursor: Option<String> = None;
|
|
121
|
+
loop {
|
|
122
|
+
let page = db
|
|
123
|
+
.list_collection_page("docs", cursor.as_deref(), 25)
|
|
124
|
+
.unwrap();
|
|
125
|
+
if page.is_empty() {
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
seen += page.len();
|
|
129
|
+
cursor = Some(page.last().unwrap().key.clone());
|
|
130
|
+
}
|
|
131
|
+
assert_eq!(seen, 120);
|
|
132
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
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
|
+
}
|