@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,309 @@
|
|
|
1
|
+
//! Evidence for the current-revision authority audit
|
|
2
|
+
//! (`docs/audits/CURRENT-REVISION-AUTHORITY-AUDIT.md`).
|
|
3
|
+
//!
|
|
4
|
+
//! Adds **no capability and no product surface**. It answers one question with
|
|
5
|
+
//! runs rather than readings:
|
|
6
|
+
//!
|
|
7
|
+
//! > Can the existing resource/application authority legitimately own
|
|
8
|
+
//! > `currentRevisionId`, advanced atomically with the resource's durable
|
|
9
|
+
//! > mutation?
|
|
10
|
+
//!
|
|
11
|
+
//! The short answer is that the *mechanism* already exists and does exactly
|
|
12
|
+
//! this for `__version`, but the *place* it keeps it — a field inside the
|
|
13
|
+
//! document — is erasable by the unconditional write path. That is the finding
|
|
14
|
+
//! the audit turns on, and `an_unconditional_write_erases_a_document_maintained_field`
|
|
15
|
+
//! is what pins it.
|
|
16
|
+
|
|
17
|
+
use feltdb::{FeltDb, JsonCasResult};
|
|
18
|
+
use serde_json::{json, Value};
|
|
19
|
+
use std::collections::HashMap;
|
|
20
|
+
use tempfile::TempDir;
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// The resource already owns durable currentness
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
/// A resource's current state is already durable and already survives restart.
|
|
27
|
+
///
|
|
28
|
+
/// This is the load-bearing precondition for the audit's hypothesis. Nothing
|
|
29
|
+
/// needs to be invented for a resource to *have* a current state that outlives
|
|
30
|
+
/// the process: the row at `capability:key` is that state, the version fence
|
|
31
|
+
/// advances it atomically, and reopening the log returns exactly what the last
|
|
32
|
+
/// successful mutation left.
|
|
33
|
+
#[test]
|
|
34
|
+
fn a_resource_already_owns_its_current_state_across_restart() {
|
|
35
|
+
let directory = TempDir::new().unwrap();
|
|
36
|
+
let path = directory.path().join("resource.log");
|
|
37
|
+
|
|
38
|
+
{
|
|
39
|
+
let db = FeltDb::open(&path).unwrap();
|
|
40
|
+
db.insert("accounts:1", json!({"balance": 100, "__version": 1}))
|
|
41
|
+
.unwrap();
|
|
42
|
+
|
|
43
|
+
let result = db
|
|
44
|
+
.compare_and_set_json("accounts:1", 1, None, None, false, json!({"balance": 150}))
|
|
45
|
+
.unwrap();
|
|
46
|
+
assert!(
|
|
47
|
+
matches!(
|
|
48
|
+
result,
|
|
49
|
+
JsonCasResult::Updated {
|
|
50
|
+
current_version: 2,
|
|
51
|
+
..
|
|
52
|
+
}
|
|
53
|
+
),
|
|
54
|
+
"the fence advanced the resource's version inside the mutation"
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let db = FeltDb::open(&path).unwrap();
|
|
59
|
+
let recovered: Option<Value> = db.get("accounts:1").unwrap();
|
|
60
|
+
assert_eq!(
|
|
61
|
+
recovered,
|
|
62
|
+
Some(json!({"balance": 150, "__version": 2})),
|
|
63
|
+
"the resource's current state survives restart without any recovery step"
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// Advancement is already gated, by three independent fences.
|
|
68
|
+
///
|
|
69
|
+
/// `compare_and_set_json` checks the record version, the authority epoch at
|
|
70
|
+
/// `/authority/epoch`, and an optional lease id — all under the store lock,
|
|
71
|
+
/// before any durable write. "Who is entitled to advance this resource" is a
|
|
72
|
+
/// question the existing authority already answers.
|
|
73
|
+
#[test]
|
|
74
|
+
fn the_existing_authority_already_gates_who_may_advance_a_resource() {
|
|
75
|
+
let directory = TempDir::new().unwrap();
|
|
76
|
+
let db = FeltDb::open(directory.path().join("epoch.log")).unwrap();
|
|
77
|
+
db.insert(
|
|
78
|
+
"accounts:4",
|
|
79
|
+
json!({"balance": 10, "__version": 1, "authority": {"epoch": 5}}),
|
|
80
|
+
)
|
|
81
|
+
.unwrap();
|
|
82
|
+
|
|
83
|
+
// A writer carrying a stale epoch is refused, even with the right version.
|
|
84
|
+
let stale = db
|
|
85
|
+
.compare_and_set_json(
|
|
86
|
+
"accounts:4",
|
|
87
|
+
1,
|
|
88
|
+
Some(4),
|
|
89
|
+
None,
|
|
90
|
+
false,
|
|
91
|
+
json!({"balance": 20}),
|
|
92
|
+
)
|
|
93
|
+
.unwrap();
|
|
94
|
+
assert!(
|
|
95
|
+
matches!(
|
|
96
|
+
stale,
|
|
97
|
+
JsonCasResult::AuthorityConflict {
|
|
98
|
+
current_epoch: 5,
|
|
99
|
+
..
|
|
100
|
+
}
|
|
101
|
+
),
|
|
102
|
+
"a stale authority epoch is refused: {stale:?}"
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// The holder of the current epoch may advance it.
|
|
106
|
+
let allowed = db
|
|
107
|
+
.compare_and_set_json(
|
|
108
|
+
"accounts:4",
|
|
109
|
+
1,
|
|
110
|
+
Some(5),
|
|
111
|
+
None,
|
|
112
|
+
false,
|
|
113
|
+
json!({"balance": 30}),
|
|
114
|
+
)
|
|
115
|
+
.unwrap();
|
|
116
|
+
assert!(
|
|
117
|
+
matches!(
|
|
118
|
+
allowed,
|
|
119
|
+
JsonCasResult::Updated {
|
|
120
|
+
current_version: 2,
|
|
121
|
+
current_epoch: 5,
|
|
122
|
+
..
|
|
123
|
+
}
|
|
124
|
+
),
|
|
125
|
+
"the current epoch holder advances the resource: {allowed:?}"
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
// What a race actually produces
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
|
|
133
|
+
/// The version fence **annihilates** the losing writer rather than recording it.
|
|
134
|
+
///
|
|
135
|
+
/// This is the audit's central negative result. Two writers start from the same
|
|
136
|
+
/// parent version. One wins. The loser is told a number — `current_version` —
|
|
137
|
+
/// and its proposed state is never stored, never logged, and never given an
|
|
138
|
+
/// identity. Nothing anywhere records that two states were proposed from one
|
|
139
|
+
/// parent.
|
|
140
|
+
///
|
|
141
|
+
/// So on a single node the existing mechanism does not *detect* divergence, it
|
|
142
|
+
/// *prevents* it. There is no `left` and `right` to reconcile, because `right`
|
|
143
|
+
/// never came into existence. Reconciliation's three inputs cannot be sourced
|
|
144
|
+
/// from this path no matter how it is wired.
|
|
145
|
+
#[test]
|
|
146
|
+
fn the_version_fence_annihilates_the_losing_writer() {
|
|
147
|
+
let directory = TempDir::new().unwrap();
|
|
148
|
+
let db = FeltDb::open(directory.path().join("race.log")).unwrap();
|
|
149
|
+
db.insert("accounts:2", json!({"balance": 100, "__version": 1}))
|
|
150
|
+
.unwrap();
|
|
151
|
+
|
|
152
|
+
// Both writers fence on the same parent version.
|
|
153
|
+
let winner = db
|
|
154
|
+
.compare_and_set_json("accounts:2", 1, None, None, false, json!({"balance": 200}))
|
|
155
|
+
.unwrap();
|
|
156
|
+
let loser = db
|
|
157
|
+
.compare_and_set_json("accounts:2", 1, None, None, false, json!({"balance": 300}))
|
|
158
|
+
.unwrap();
|
|
159
|
+
|
|
160
|
+
assert!(matches!(winner, JsonCasResult::Updated { .. }));
|
|
161
|
+
assert!(
|
|
162
|
+
matches!(
|
|
163
|
+
loser,
|
|
164
|
+
JsonCasResult::VersionConflict {
|
|
165
|
+
current_version: 2,
|
|
166
|
+
..
|
|
167
|
+
}
|
|
168
|
+
),
|
|
169
|
+
"the loser learns only a version number: {loser:?}"
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
// The stored state is the winner's, and the loser's is nowhere.
|
|
173
|
+
let stored: Option<Value> = db.get("accounts:2").unwrap();
|
|
174
|
+
assert_eq!(stored, Some(json!({"balance": 200, "__version": 2})));
|
|
175
|
+
|
|
176
|
+
let operations = db.operations_since(&HashMap::new()).unwrap();
|
|
177
|
+
let for_resource: Vec<_> = operations
|
|
178
|
+
.iter()
|
|
179
|
+
.filter(|op| op.key == "accounts:2")
|
|
180
|
+
.collect();
|
|
181
|
+
assert_eq!(
|
|
182
|
+
for_resource.len(),
|
|
183
|
+
2,
|
|
184
|
+
"only the insert and the winning update are durable"
|
|
185
|
+
);
|
|
186
|
+
for operation in &for_resource {
|
|
187
|
+
let rendered = operation.value.as_ref().unwrap().to_string();
|
|
188
|
+
assert!(
|
|
189
|
+
!rendered.contains("300"),
|
|
190
|
+
"the losing writer's proposed state appears nowhere: {rendered}"
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/// The operation log **does** retain an ordered per-resource history.
|
|
196
|
+
///
|
|
197
|
+
/// Worth recording as a positive: the ancestry a revision chain would need is
|
|
198
|
+
/// not absent from the substrate. Every mutation is appended in order, per key,
|
|
199
|
+
/// with a per-origin vector clock. What is missing is not the history — it is
|
|
200
|
+
/// an identity for each resulting *state* and an explicit parent link between
|
|
201
|
+
/// them. The log records operations, not revisions.
|
|
202
|
+
#[test]
|
|
203
|
+
fn the_operation_log_retains_an_ordered_per_resource_history() {
|
|
204
|
+
let directory = TempDir::new().unwrap();
|
|
205
|
+
let db = FeltDb::open(directory.path().join("history.log")).unwrap();
|
|
206
|
+
|
|
207
|
+
db.insert("accounts:3", json!({"balance": 100, "__version": 1}))
|
|
208
|
+
.unwrap();
|
|
209
|
+
db.update("accounts:3", json!({"balance": 200})).unwrap();
|
|
210
|
+
db.update("accounts:3", json!({"balance": 300})).unwrap();
|
|
211
|
+
|
|
212
|
+
let operations = db.operations_since(&HashMap::new()).unwrap();
|
|
213
|
+
let history: Vec<_> = operations
|
|
214
|
+
.iter()
|
|
215
|
+
.filter(|op| op.key == "accounts:3")
|
|
216
|
+
.collect();
|
|
217
|
+
assert_eq!(history.len(), 3, "every mutation is retained, in order");
|
|
218
|
+
|
|
219
|
+
// Each carries a per-origin causal position, which is a sequence rather
|
|
220
|
+
// than a statement about state.
|
|
221
|
+
for operation in &history {
|
|
222
|
+
assert!(
|
|
223
|
+
operation
|
|
224
|
+
.vector_clock
|
|
225
|
+
.as_ref()
|
|
226
|
+
.is_some_and(|c| !c.is_empty()),
|
|
227
|
+
"each operation carries causal evidence"
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// **Superseded.** This assertion read, as a finding of this audit:
|
|
232
|
+
//
|
|
233
|
+
// no operation names the state it descended from
|
|
234
|
+
//
|
|
235
|
+
// That was true when the audit ran, and it is the reason a replica could
|
|
236
|
+
// reproduce current state and no history at all. Replicated revision
|
|
237
|
+
// history closed it: an operation now carries the revision it produced —
|
|
238
|
+
// resource, identity, parent, sequence, content identity and authority — so
|
|
239
|
+
// a peer can rebuild that revision rather than mint a local substitute.
|
|
240
|
+
//
|
|
241
|
+
// The finding is kept here inverted rather than deleted, because it is the
|
|
242
|
+
// exact thing that changed.
|
|
243
|
+
for operation in &history {
|
|
244
|
+
let provenance = operation
|
|
245
|
+
.revision
|
|
246
|
+
.as_ref()
|
|
247
|
+
.expect("an operation now names the revision it produced");
|
|
248
|
+
assert_eq!(provenance.resource, "accounts:3");
|
|
249
|
+
}
|
|
250
|
+
let first = history[0].revision.as_ref().unwrap();
|
|
251
|
+
let second = history[1].revision.as_ref().unwrap();
|
|
252
|
+
assert_eq!(first.parent_id, None, "the first began the history");
|
|
253
|
+
assert_eq!(
|
|
254
|
+
second.parent_id.as_deref(),
|
|
255
|
+
Some(first.id.as_str()),
|
|
256
|
+
"and each names the state it descended from"
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// ---------------------------------------------------------------------------
|
|
261
|
+
// Why a document field cannot hold the reference
|
|
262
|
+
// ---------------------------------------------------------------------------
|
|
263
|
+
|
|
264
|
+
/// An unconditional write erases a field the authority maintains by convention.
|
|
265
|
+
///
|
|
266
|
+
/// This is the finding that decides the shape of any future `currentRevisionId`.
|
|
267
|
+
///
|
|
268
|
+
/// `__version` is, by the repository's own transaction-version contract, *"a
|
|
269
|
+
/// document field maintained by convention, not a storage-level attribute"*.
|
|
270
|
+
/// Unconditional writes are documented to remain verbatim — so writing a value
|
|
271
|
+
/// that omits the field stores it omitted. That is correct behaviour for
|
|
272
|
+
/// `update`, and it is exactly why it is not a safe home for a reference the
|
|
273
|
+
/// state model would depend on: one ordinary unconditional write silently
|
|
274
|
+
/// removes the resource's fence.
|
|
275
|
+
///
|
|
276
|
+
/// A `currentRevisionId` kept the same way would inherit the same weakness, and
|
|
277
|
+
/// losing it would sever a resource from its history rather than merely dropping
|
|
278
|
+
/// an optimistic-concurrency check.
|
|
279
|
+
#[test]
|
|
280
|
+
fn an_unconditional_write_erases_a_document_maintained_field() {
|
|
281
|
+
let directory = TempDir::new().unwrap();
|
|
282
|
+
let db = FeltDb::open(directory.path().join("erase.log")).unwrap();
|
|
283
|
+
|
|
284
|
+
db.insert("accounts:5", json!({"balance": 100, "__version": 1}))
|
|
285
|
+
.unwrap();
|
|
286
|
+
// Stand in for a revision pointer kept the same way the version is.
|
|
287
|
+
db.insert(
|
|
288
|
+
"accounts:6",
|
|
289
|
+
json!({"balance": 100, "__version": 1, "__currentRevision": "abc123"}),
|
|
290
|
+
)
|
|
291
|
+
.unwrap();
|
|
292
|
+
|
|
293
|
+
db.update("accounts:5", json!({"balance": 200})).unwrap();
|
|
294
|
+
db.update("accounts:6", json!({"balance": 200})).unwrap();
|
|
295
|
+
|
|
296
|
+
let versioned: Option<Value> = db.get("accounts:5").unwrap();
|
|
297
|
+
assert_eq!(
|
|
298
|
+
versioned,
|
|
299
|
+
Some(json!({"balance": 200})),
|
|
300
|
+
"the version field is gone after one unconditional write"
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
let referenced: Option<Value> = db.get("accounts:6").unwrap();
|
|
304
|
+
assert_eq!(
|
|
305
|
+
referenced,
|
|
306
|
+
Some(json!({"balance": 200})),
|
|
307
|
+
"a revision reference kept the same way is erased identically"
|
|
308
|
+
);
|
|
309
|
+
}
|