@feltdb/core 0.8.4 → 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/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 +507 -6
- 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 +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 +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/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/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 +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 +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/auth.rs +164 -13
- package/dist/create/server-source/crates/feltdb-server/src/main.rs +326 -6
- package/dist/studio-app/assets/{feltdb_wasm-CVQWgXO-.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-DwgNAIIX.js → index-j8IlhNqJ.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,249 @@
|
|
|
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
|
+
}
|