@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,427 @@
|
|
|
1
|
+
//! Evidence for the revision retention and identity boundary audit
|
|
2
|
+
//! (`docs/audits/REVISION-RETENTION-BOUNDARY-AUDIT.md`).
|
|
3
|
+
//!
|
|
4
|
+
//! Adds **no capability and no product surface**. It tests one question:
|
|
5
|
+
//!
|
|
6
|
+
//! > The [three-way input boundary audit](../../../docs/audits/THREE-WAY-INPUT-BOUNDARY-AUDIT.md)
|
|
7
|
+
//! > proved that minting a `StateRevision` at the authoritative mutation is the
|
|
8
|
+
//! > only candidate that can supply `base`. What does doing so *cost*, and what
|
|
9
|
+
//! > bounds it?
|
|
10
|
+
//!
|
|
11
|
+
//! Two results decide it. The cost is measurable and linear, with a fixed
|
|
12
|
+
//! per-revision overhead of roughly half a kilobyte that nothing collects. And
|
|
13
|
+
//! content-only identity does not survive per-mutation minting: a resource that
|
|
14
|
+
//! returns to a previous value silently rewrites the ancestry of the revision it
|
|
15
|
+
//! returns to, producing a cycle in the durable parent chain.
|
|
16
|
+
//!
|
|
17
|
+
//! # Superseded in part
|
|
18
|
+
//!
|
|
19
|
+
//! The identity findings here caused the resource-scoped model to be adopted,
|
|
20
|
+
//! and are **fixed**: the tests that recorded them now record the fix instead,
|
|
21
|
+
//! and say so individually. Two consequences of that change are recorded here
|
|
22
|
+
//! rather than argued:
|
|
23
|
+
//!
|
|
24
|
+
//! - **Content addressing no longer bounds anything.** Identity includes the
|
|
25
|
+
//! resource and a sequence, so repeated state does not collapse. The bound
|
|
26
|
+
//! this audit found is gone, replaced by an explicit retention policy.
|
|
27
|
+
//! - **The cost constants changed.** A revision now carries a resource, a
|
|
28
|
+
//! second identity and a sequence. The shape is still linear; the constants
|
|
29
|
+
//! are not the ones measured here.
|
|
30
|
+
//!
|
|
31
|
+
//! Re-measuring the economics against the adopted model is deliberately *not*
|
|
32
|
+
//! done here — it is the next step, and doing it inside the implementation
|
|
33
|
+
//! would mix a measurement with the change being measured.
|
|
34
|
+
|
|
35
|
+
use feltdb::state_model::{ParentLookup, RetentionPolicy, StateStore};
|
|
36
|
+
use feltdb::{FeltDb, JsonCasResult};
|
|
37
|
+
use serde_json::json;
|
|
38
|
+
use std::sync::Arc;
|
|
39
|
+
use tempfile::TempDir;
|
|
40
|
+
|
|
41
|
+
/// Build a durable store, commit `count` revisions of a state padded to a known
|
|
42
|
+
/// size, then acknowledge and compact. Returns the compacted log's contents.
|
|
43
|
+
fn compacted_log_after_revisions(count: usize, pad: usize) -> String {
|
|
44
|
+
let directory = TempDir::new().unwrap();
|
|
45
|
+
let path = directory.path().join("revisions.log");
|
|
46
|
+
let db = Arc::new(FeltDb::open(&path).unwrap());
|
|
47
|
+
let store = StateStore::with_feltdb(db.clone()).unwrap();
|
|
48
|
+
|
|
49
|
+
let filler = "x".repeat(pad);
|
|
50
|
+
let mut revision = store
|
|
51
|
+
.create(
|
|
52
|
+
"docs:1",
|
|
53
|
+
format!(r#"{{"n":0,"pad":"{filler}"}}"#),
|
|
54
|
+
"authority".into(),
|
|
55
|
+
)
|
|
56
|
+
.unwrap();
|
|
57
|
+
for n in 1..count {
|
|
58
|
+
revision = store
|
|
59
|
+
.commit(
|
|
60
|
+
format!(r#"{{"n":{n},"pad":"{filler}"}}"#),
|
|
61
|
+
&revision,
|
|
62
|
+
"authority".into(),
|
|
63
|
+
)
|
|
64
|
+
.unwrap();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let versions = db.operation_versions().unwrap();
|
|
68
|
+
db.acknowledge_peer_versions("peer-1".to_string(), versions)
|
|
69
|
+
.unwrap();
|
|
70
|
+
db.compact_operation_log(&["peer-1".to_string()]).unwrap();
|
|
71
|
+
|
|
72
|
+
std::fs::read_to_string(&path).unwrap()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fn revision_lines(log: &str) -> usize {
|
|
76
|
+
log.lines()
|
|
77
|
+
.filter(|line| line.contains("state:revision:"))
|
|
78
|
+
.count()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
// Retention: what bounds the revision store
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
|
|
85
|
+
/// **Nothing collects revisions — least of all the operation that collects.**
|
|
86
|
+
///
|
|
87
|
+
/// The three-way input boundary audit showed `compact_operation_log` deleting
|
|
88
|
+
/// ancestry: acknowledged operations are pruned, and the log is rewritten as a
|
|
89
|
+
/// snapshot of the *current rows*. That is exactly why it cannot supply `base`.
|
|
90
|
+
///
|
|
91
|
+
/// The same mechanism has the opposite effect on revisions, and for the same
|
|
92
|
+
/// reason. A revision is a current row — one per `state:revision:{hex}` key — so
|
|
93
|
+
/// the snapshot pass preserves every one of them. Compaction is the only
|
|
94
|
+
/// operation in the system that removes durable history, and it is structurally
|
|
95
|
+
/// incapable of removing a revision.
|
|
96
|
+
///
|
|
97
|
+
/// `StateStore` exposes no deletion of its own: `create`, `commit`, `get`,
|
|
98
|
+
/// `exists`, `metadata` and `parent`, and nothing else. So under candidate B the
|
|
99
|
+
/// revision store grows monotonically with the number of authoritative
|
|
100
|
+
/// mutations, with no mechanism — existing or exposed — that can shrink it.
|
|
101
|
+
#[test]
|
|
102
|
+
fn compaction_preserves_every_revision_it_finds() {
|
|
103
|
+
let directory = TempDir::new().unwrap();
|
|
104
|
+
let path = directory.path().join("survive.log");
|
|
105
|
+
let db = Arc::new(FeltDb::open(&path).unwrap());
|
|
106
|
+
let store = StateStore::with_feltdb(db.clone()).unwrap();
|
|
107
|
+
|
|
108
|
+
let mut ids = Vec::new();
|
|
109
|
+
let mut revision = store
|
|
110
|
+
.create("docs:1", r#"{"n":0}"#.into(), "authority".into())
|
|
111
|
+
.unwrap();
|
|
112
|
+
ids.push(revision.id.clone());
|
|
113
|
+
for n in 1..25 {
|
|
114
|
+
revision = store
|
|
115
|
+
.commit(format!(r#"{{"n":{n}}}"#), &revision, "authority".into())
|
|
116
|
+
.unwrap();
|
|
117
|
+
ids.push(revision.id.clone());
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let versions = db.operation_versions().unwrap();
|
|
121
|
+
db.acknowledge_peer_versions("peer-1".to_string(), versions)
|
|
122
|
+
.unwrap();
|
|
123
|
+
let removed = db.compact_operation_log(&["peer-1".to_string()]).unwrap();
|
|
124
|
+
assert!(removed > 0, "compaction pruned acknowledged operations");
|
|
125
|
+
|
|
126
|
+
drop(store);
|
|
127
|
+
drop(db);
|
|
128
|
+
let reopened = Arc::new(FeltDb::open(&path).unwrap());
|
|
129
|
+
let store = StateStore::with_feltdb(reopened).unwrap();
|
|
130
|
+
|
|
131
|
+
let surviving = ids.iter().filter(|id| store.exists(id)).count();
|
|
132
|
+
assert_eq!(
|
|
133
|
+
surviving,
|
|
134
|
+
ids.len(),
|
|
135
|
+
"every revision survived the one operation that deletes history"
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/// **Each compaction rewrites the entire revision history.**
|
|
140
|
+
///
|
|
141
|
+
/// The snapshot pass writes one line per current row, so the cost of a
|
|
142
|
+
/// compaction is proportional to the number of revisions ever minted — a number
|
|
143
|
+
/// that only grows. The operation that exists to stop the log growing without
|
|
144
|
+
/// bound therefore becomes more expensive with every mutation the system has
|
|
145
|
+
/// ever performed, and never cheaper.
|
|
146
|
+
#[test]
|
|
147
|
+
fn each_compaction_rewrites_the_whole_revision_history() {
|
|
148
|
+
let directory = TempDir::new().unwrap();
|
|
149
|
+
let path = directory.path().join("rewrite.log");
|
|
150
|
+
let db = Arc::new(FeltDb::open(&path).unwrap());
|
|
151
|
+
let store = StateStore::with_feltdb(db.clone()).unwrap();
|
|
152
|
+
|
|
153
|
+
let mut revision = store
|
|
154
|
+
.create("docs:1", r#"{"n":0}"#.into(), "authority".into())
|
|
155
|
+
.unwrap();
|
|
156
|
+
for n in 1..10 {
|
|
157
|
+
revision = store
|
|
158
|
+
.commit(format!(r#"{{"n":{n}}}"#), &revision, "authority".into())
|
|
159
|
+
.unwrap();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let versions = db.operation_versions().unwrap();
|
|
163
|
+
db.acknowledge_peer_versions("peer-1".to_string(), versions)
|
|
164
|
+
.unwrap();
|
|
165
|
+
db.compact_operation_log(&["peer-1".to_string()]).unwrap();
|
|
166
|
+
let first = std::fs::read_to_string(&path).unwrap();
|
|
167
|
+
assert_eq!(revision_lines(&first), 10);
|
|
168
|
+
|
|
169
|
+
// One unrelated write on another resource, acknowledged and compacted
|
|
170
|
+
// again. It mints a revision of its own, and the ten existing ones are
|
|
171
|
+
// written out in full a second time regardless.
|
|
172
|
+
db.insert("tasks:1", json!({"unrelated": true})).unwrap();
|
|
173
|
+
let versions = db.operation_versions().unwrap();
|
|
174
|
+
db.acknowledge_peer_versions("peer-1".to_string(), versions)
|
|
175
|
+
.unwrap();
|
|
176
|
+
db.compact_operation_log(&["peer-1".to_string()]).unwrap();
|
|
177
|
+
let second = std::fs::read_to_string(&path).unwrap();
|
|
178
|
+
|
|
179
|
+
assert_eq!(
|
|
180
|
+
revision_lines(&second),
|
|
181
|
+
11,
|
|
182
|
+
"the second compaction rewrote all ten revisions, plus the one the \
|
|
183
|
+
unrelated write minted, to serve that single write"
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
// Cost: what a revision is worth in bytes
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
/// **A revision costs a fixed overhead of roughly half a kilobyte, plus one
|
|
192
|
+
/// copy of its own state.**
|
|
193
|
+
///
|
|
194
|
+
/// The compacted log is linear in both the revision count and the state size:
|
|
195
|
+
///
|
|
196
|
+
/// ```text
|
|
197
|
+
/// bytes = header + count × (fixed_overhead + |content|)
|
|
198
|
+
/// ```
|
|
199
|
+
///
|
|
200
|
+
/// The fixed part is not incidental — it is a 64-character hex identity, a
|
|
201
|
+
/// 64-character parent identity, an authority, a timestamp, a metadata map, and
|
|
202
|
+
/// the `StoredRow` wrapper carrying the capability, the `state:revision:{hex}`
|
|
203
|
+
/// key and the fully-qualified Rust type name. It dominates until the state
|
|
204
|
+
/// being versioned is itself several hundred bytes.
|
|
205
|
+
///
|
|
206
|
+
/// The state is stored exactly once per revision, not twice. But it is stored
|
|
207
|
+
/// *escaped*, inside a JSON string field of the record — so every quote in the
|
|
208
|
+
/// versioned document costs a second byte.
|
|
209
|
+
#[test]
|
|
210
|
+
fn a_revision_costs_a_fixed_overhead_plus_one_copy_of_its_state() {
|
|
211
|
+
let small_ten = compacted_log_after_revisions(10, 0).len();
|
|
212
|
+
let small_twenty = compacted_log_after_revisions(20, 0).len();
|
|
213
|
+
let padded_hundred = compacted_log_after_revisions(10, 100).len();
|
|
214
|
+
let padded_thousand = compacted_log_after_revisions(10, 1000).len();
|
|
215
|
+
|
|
216
|
+
// Ten more revisions of a 16-byte state cost ten more per-revision records.
|
|
217
|
+
// Indices 10..19 are one digit wider than 0..9, hence the ten-byte term.
|
|
218
|
+
let ten_more = small_twenty - small_ten - 10;
|
|
219
|
+
let per_revision = ten_more / 10;
|
|
220
|
+
// The shape is unchanged by the resource-scoped model; the constant is
|
|
221
|
+
// not. A revision now also carries its resource, a second identity and a
|
|
222
|
+
// sequence, so the floor is higher than the 492 bytes measured before the
|
|
223
|
+
// model was adopted. Re-measuring the economics properly is a separate
|
|
224
|
+
// step; this assertion exists to catch the shape changing, not to be the
|
|
225
|
+
// measurement.
|
|
226
|
+
assert!(
|
|
227
|
+
(550..=750).contains(&per_revision),
|
|
228
|
+
"a revision of a 16-byte state costs {per_revision} bytes; \
|
|
229
|
+
the overhead is the record, not the state"
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
// Content is stored exactly once: growing each state by N bytes grows the
|
|
233
|
+
// log by exactly count × N.
|
|
234
|
+
assert_eq!(
|
|
235
|
+
padded_hundred - small_ten,
|
|
236
|
+
10 * 100,
|
|
237
|
+
"a hundred more bytes of state costs a hundred more bytes per revision"
|
|
238
|
+
);
|
|
239
|
+
assert_eq!(
|
|
240
|
+
padded_thousand - small_ten,
|
|
241
|
+
10 * 1000,
|
|
242
|
+
"the relationship stays exactly linear at a kilobyte of state"
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/// **Content addressing was the only bound, and adopting model C removed it.**
|
|
247
|
+
///
|
|
248
|
+
/// This test recorded the opposite: three commits of two distinct states were
|
|
249
|
+
/// stored as two records, because identity was content and repeated content
|
|
250
|
+
/// collapsed. That deduplication was the only thing bounding storage growth.
|
|
251
|
+
///
|
|
252
|
+
/// Under the resource-scoped model it is gone. A resource that returns to a
|
|
253
|
+
/// value it previously held records a new revision, because identity includes
|
|
254
|
+
/// the resource and the position in its history. Three commits are three
|
|
255
|
+
/// records.
|
|
256
|
+
///
|
|
257
|
+
/// The bound did not disappear — it moved, from an accident of hashing to an
|
|
258
|
+
/// explicit retention policy, which the next test exercises.
|
|
259
|
+
#[test]
|
|
260
|
+
fn repeated_state_no_longer_deduplicates() {
|
|
261
|
+
let directory = TempDir::new().unwrap();
|
|
262
|
+
let path = directory.path().join("dedupe.log");
|
|
263
|
+
let db = Arc::new(FeltDb::open(&path).unwrap());
|
|
264
|
+
let store = StateStore::with_feltdb(db.clone()).unwrap();
|
|
265
|
+
|
|
266
|
+
let first = store
|
|
267
|
+
.create("docs:1", r#"{"title":"A"}"#.into(), "authority".into())
|
|
268
|
+
.unwrap();
|
|
269
|
+
let second = store
|
|
270
|
+
.commit(r#"{"title":"B"}"#.into(), &first, "authority".into())
|
|
271
|
+
.unwrap();
|
|
272
|
+
let third = store
|
|
273
|
+
.commit(r#"{"title":"A"}"#.into(), &second, "authority".into())
|
|
274
|
+
.unwrap();
|
|
275
|
+
|
|
276
|
+
assert_ne!(third.id, first.id, "returning to A is a new revision");
|
|
277
|
+
assert_eq!(
|
|
278
|
+
third.content_id, first.content_id,
|
|
279
|
+
"and it is still the same state"
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
let versions = db.operation_versions().unwrap();
|
|
283
|
+
db.acknowledge_peer_versions("peer-1".to_string(), versions)
|
|
284
|
+
.unwrap();
|
|
285
|
+
db.compact_operation_log(&["peer-1".to_string()]).unwrap();
|
|
286
|
+
let log = std::fs::read_to_string(&path).unwrap();
|
|
287
|
+
|
|
288
|
+
assert_eq!(
|
|
289
|
+
revision_lines(&log),
|
|
290
|
+
3,
|
|
291
|
+
"three commits are three records; nothing collapses any more"
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/// **The bound that replaced deduplication.**
|
|
296
|
+
///
|
|
297
|
+
/// Retention is per-resource, count-based, and applied at the moment history is
|
|
298
|
+
/// created rather than at a maintenance pass that may never run. The current
|
|
299
|
+
/// revision always survives, and what remains is a suffix of the timeline.
|
|
300
|
+
#[test]
|
|
301
|
+
fn revision_retention_bounds_a_resources_history() {
|
|
302
|
+
let directory = TempDir::new().unwrap();
|
|
303
|
+
let db = Arc::new(FeltDb::open(directory.path().join("retain.log")).unwrap());
|
|
304
|
+
let store = StateStore::with_feltdb(db.clone()).unwrap();
|
|
305
|
+
|
|
306
|
+
store
|
|
307
|
+
.set_retention_policy("docs:1", RetentionPolicy::keep_last(3))
|
|
308
|
+
.unwrap();
|
|
309
|
+
|
|
310
|
+
db.insert("docs:1", json!({"n": 0})).unwrap();
|
|
311
|
+
for n in 1..40 {
|
|
312
|
+
db.update("docs:1", json!({ "n": n })).unwrap();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let history = store.history_of("docs:1");
|
|
316
|
+
assert_eq!(history.len(), 3, "forty writes, three retained revisions");
|
|
317
|
+
assert!(
|
|
318
|
+
history[2].content.contains(r#""n":39"#),
|
|
319
|
+
"the current revision survives"
|
|
320
|
+
);
|
|
321
|
+
assert!(
|
|
322
|
+
history[0].sequence < history[1].sequence && history[1].sequence < history[2].sequence,
|
|
323
|
+
"what remains is a suffix of the timeline, in order"
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/// **An expired ancestor is not a dangling one.**
|
|
328
|
+
///
|
|
329
|
+
/// The hazard in bounding history is recreating the dangling-parent defect at
|
|
330
|
+
/// the other end of the system: expire an ancestor, and its child names a parent
|
|
331
|
+
/// that is not there.
|
|
332
|
+
///
|
|
333
|
+
/// The child's `parent_id` is *not* rewritten — that would violate the
|
|
334
|
+
/// immutability the model is built on. Instead the resource records a horizon,
|
|
335
|
+
/// and the oldest survivor reports an **expired** parent rather than a missing
|
|
336
|
+
/// one. They are different facts, and the store says which.
|
|
337
|
+
#[test]
|
|
338
|
+
fn an_expired_ancestor_is_distinguishable_from_a_missing_one() {
|
|
339
|
+
let directory = TempDir::new().unwrap();
|
|
340
|
+
let db = Arc::new(FeltDb::open(directory.path().join("horizon.log")).unwrap());
|
|
341
|
+
let store = StateStore::with_feltdb(db.clone()).unwrap();
|
|
342
|
+
|
|
343
|
+
store
|
|
344
|
+
.set_retention_policy("docs:1", RetentionPolicy::keep_last(2))
|
|
345
|
+
.unwrap();
|
|
346
|
+
db.insert("docs:1", json!({"n": 0})).unwrap();
|
|
347
|
+
for n in 1..6 {
|
|
348
|
+
db.update("docs:1", json!({ "n": n })).unwrap();
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
let history = store.history_of("docs:1");
|
|
352
|
+
assert_eq!(history.len(), 2);
|
|
353
|
+
let oldest = &history[0];
|
|
354
|
+
|
|
355
|
+
assert!(
|
|
356
|
+
oldest.parent_id.is_some(),
|
|
357
|
+
"the oldest survivor still names the parent it was committed with"
|
|
358
|
+
);
|
|
359
|
+
assert!(
|
|
360
|
+
matches!(store.parent_of(&oldest.id), Some(ParentLookup::Expired(_))),
|
|
361
|
+
"and the store reports that parent as expired, not missing"
|
|
362
|
+
);
|
|
363
|
+
assert!(
|
|
364
|
+
store.retention_horizon("docs:1") > 0,
|
|
365
|
+
"the horizon records where history was deliberately cut"
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
assert!(
|
|
369
|
+
matches!(
|
|
370
|
+
store.parent_of(&history[1].id),
|
|
371
|
+
Some(ParentLookup::Revision(_))
|
|
372
|
+
),
|
|
373
|
+
"the newer revision's parent is still there and resolves"
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// ---------------------------------------------------------------------------
|
|
378
|
+
// Which mutations could mint
|
|
379
|
+
// ---------------------------------------------------------------------------
|
|
380
|
+
|
|
381
|
+
/// **The unconditional write paths consult nothing in the prior document.**
|
|
382
|
+
///
|
|
383
|
+
/// The fenced path refuses a write on the basis of a nested field of the
|
|
384
|
+
/// previous document — `/authority/epoch` — which is how the three-way input
|
|
385
|
+
/// boundary audit established that the whole prior state is in hand there.
|
|
386
|
+
///
|
|
387
|
+
/// The unconditional path has no such behaviour to exhibit: `update` replaces a
|
|
388
|
+
/// document that the equivalent fenced write would have refused, and replaces it
|
|
389
|
+
/// with one that drops the fence fields entirely. It needs nothing from what was
|
|
390
|
+
/// there. `insert_internal` and `update_internal`
|
|
391
|
+
/// (`crates/feltdb/src/lib.rs:1758` and `:1827`) confirm it — both construct a
|
|
392
|
+
/// fresh `StoredRow` and call `put_row` without reading the existing one.
|
|
393
|
+
///
|
|
394
|
+
/// So the two paths do not have the same cost under candidate B. A revision
|
|
395
|
+
/// minted at the fence has its parent for free. A revision minted on `insert` or
|
|
396
|
+
/// `update` has no parent at all unless a read is added — and a parentless
|
|
397
|
+
/// revision is indistinguishable from an initial one, which is the same as
|
|
398
|
+
/// having no `base`.
|
|
399
|
+
#[test]
|
|
400
|
+
fn the_unconditional_path_needs_nothing_from_the_prior_document() {
|
|
401
|
+
let directory = TempDir::new().unwrap();
|
|
402
|
+
let db = FeltDb::open(directory.path().join("blind.log")).unwrap();
|
|
403
|
+
|
|
404
|
+
db.insert(
|
|
405
|
+
"tasks:1",
|
|
406
|
+
json!({"title": "A", "__version": 1, "authority": {"epoch": 7}}),
|
|
407
|
+
)
|
|
408
|
+
.unwrap();
|
|
409
|
+
|
|
410
|
+
// The fence reads into the prior document and refuses on what it finds.
|
|
411
|
+
let refused = db
|
|
412
|
+
.compare_and_set_json("tasks:1", 1, Some(6), None, false, json!({"title": "B"}))
|
|
413
|
+
.unwrap();
|
|
414
|
+
assert!(
|
|
415
|
+
matches!(refused, JsonCasResult::AuthorityConflict { .. }),
|
|
416
|
+
"the fenced write consulted the prior document: {refused:?}"
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
// The unconditional write does not, and succeeds on the same document.
|
|
420
|
+
db.update("tasks:1", json!({"title": "B"})).unwrap();
|
|
421
|
+
let now: serde_json::Value = db.get("tasks:1").unwrap().unwrap();
|
|
422
|
+
assert_eq!(now["title"], json!("B"));
|
|
423
|
+
assert!(
|
|
424
|
+
now.get("authority").is_none() && now.get("__version").is_none(),
|
|
425
|
+
"it replaced the document wholesale, including the fields the fence reads"
|
|
426
|
+
);
|
|
427
|
+
}
|
|
@@ -20,14 +20,14 @@ fn saas_authorization_fixture_compiles() {
|
|
|
20
20
|
// This test verifies the SaaS fixture schema is valid.
|
|
21
21
|
// In Phase 2, this will be replaced with real authorization tests
|
|
22
22
|
// that go through the actual FeltDB query/mutation API.
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
// Fixture schema (valid FlowSpec):
|
|
25
25
|
// - User collection
|
|
26
26
|
// - Organization collection with policy { read: member, write: owner }
|
|
27
27
|
// - Membership collection with user/org references
|
|
28
28
|
// - Project collection with org/owner references
|
|
29
29
|
// policy { read: member, write: member }
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
// This test passes if compilation succeeds.
|
|
32
32
|
assert!(true, "SaaS fixture schema is valid");
|
|
33
33
|
}
|
|
@@ -75,7 +75,7 @@ fn saas_authorization_phase_2_integration_planned() {
|
|
|
75
75
|
// 10. SaaS template integration
|
|
76
76
|
// Verify the actual SaaSExample template doesn't
|
|
77
77
|
// reimplement authorization in TypeScript
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
// This test passes once Phase 2 implements the above.
|
|
80
80
|
assert!(true, "Phase 2 integration tests are planned");
|
|
81
81
|
}
|
|
@@ -12,9 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
use feltdb::{
|
|
14
14
|
state_contract::{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
QueryFilter,
|
|
15
|
+
begin_read, execute_query, AuthorizationContext, CanonicalQuery, CollectionSchema,
|
|
16
|
+
FieldSchema, FieldType, PrimitiveType, QueryFilter, StateSchema,
|
|
18
17
|
},
|
|
19
18
|
FeltDb,
|
|
20
19
|
};
|
|
@@ -60,7 +59,10 @@ fn saas_invitation_architecture_test() {
|
|
|
60
59
|
// Full integration tests will exercise the actual FeltDB APIs
|
|
61
60
|
// with realistic query/mutation payloads once this pattern is validated.
|
|
62
61
|
|
|
63
|
-
assert!(
|
|
62
|
+
assert!(
|
|
63
|
+
true,
|
|
64
|
+
"Invitation → Membership → Access pattern is architecturally valid"
|
|
65
|
+
);
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
#[test]
|
|
@@ -99,11 +101,15 @@ fn saas_invitation_lifecycle_phase_2_state_transition_proves_generalization() {
|
|
|
99
101
|
// 2. Workflows are ordinary state transitions
|
|
100
102
|
// 3. Access changes via state, not authorization code
|
|
101
103
|
|
|
102
|
-
assert!(
|
|
104
|
+
assert!(
|
|
105
|
+
true,
|
|
106
|
+
"State transitions create authorization changes without code changes"
|
|
107
|
+
);
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
#[test]
|
|
106
|
-
fn saas_invitation_lifecycle_phase_3_capability_gap_detection(
|
|
111
|
+
fn saas_invitation_lifecycle_phase_3_capability_gap_detection(
|
|
112
|
+
) -> Result<(), Box<dyn std::error::Error>> {
|
|
107
113
|
// Phase 3: Capability probe - can invited users see their invitations?
|
|
108
114
|
//
|
|
109
115
|
// The member policy requires Membership(user, org) to read Invitation.
|
|
@@ -167,19 +173,17 @@ fn saas_invitation_lifecycle_phase_3_capability_gap_detection() -> Result<(), Bo
|
|
|
167
173
|
CollectionSchema {
|
|
168
174
|
name: "Organization".to_string(),
|
|
169
175
|
version: 1,
|
|
170
|
-
fields: vec![
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
primitive: PrimitiveType::String,
|
|
175
|
-
},
|
|
176
|
-
nullable: false,
|
|
177
|
-
required: true,
|
|
178
|
-
default: None,
|
|
179
|
-
constraints: Default::default(),
|
|
180
|
-
computed: None,
|
|
176
|
+
fields: vec![FieldSchema {
|
|
177
|
+
name: "_id".to_string(),
|
|
178
|
+
field_type: FieldType::Primitive {
|
|
179
|
+
primitive: PrimitiveType::String,
|
|
181
180
|
},
|
|
182
|
-
|
|
181
|
+
nullable: false,
|
|
182
|
+
required: true,
|
|
183
|
+
default: None,
|
|
184
|
+
constraints: Default::default(),
|
|
185
|
+
computed: None,
|
|
186
|
+
}],
|
|
183
187
|
indexes: vec![],
|
|
184
188
|
},
|
|
185
189
|
// Membership collection (establishes access)
|
|
@@ -340,8 +344,7 @@ fn saas_invitation_lifecycle_phase_3_capability_gap_detection() -> Result<(), Bo
|
|
|
340
344
|
field_projections: Default::default(),
|
|
341
345
|
};
|
|
342
346
|
|
|
343
|
-
let bob_context = begin_read(&db, &schema, "app", bob_auth)
|
|
344
|
-
.map_err(|e| format!("{:?}", e))?;
|
|
347
|
+
let bob_context = begin_read(&db, &schema, "app", bob_auth).map_err(|e| format!("{:?}", e))?;
|
|
345
348
|
|
|
346
349
|
// Bob queries Invitations with filter on his email
|
|
347
350
|
let query = CanonicalQuery {
|
|
@@ -360,8 +363,8 @@ fn saas_invitation_lifecycle_phase_3_capability_gap_detection() -> Result<(), Bo
|
|
|
360
363
|
references: vec![],
|
|
361
364
|
};
|
|
362
365
|
|
|
363
|
-
let result =
|
|
364
|
-
.map_err(|e| format!("{:?}", e))?;
|
|
366
|
+
let result =
|
|
367
|
+
execute_query(&db, &schema, &bob_context, &query, None).map_err(|e| format!("{:?}", e))?;
|
|
365
368
|
|
|
366
369
|
// CRITICAL FINDING:
|
|
367
370
|
// If result.records.len() > 0: Bob CAN see his invitation
|