fix: retain complete histories with bounded journal capacity and native recovery
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-13 19:11:45 +01:00
parent da7eb8109c
commit c512bd6fb2
36 changed files with 2556 additions and 38 deletions
+51
View File
@@ -85,6 +85,57 @@ fn directory() -> std::path::PathBuf {
path
}
#[test]
fn journal_capacity_is_finite_and_retains_original_consumption_on_reopen() {
let dir = directory();
let uid = unsafe { libc::geteuid() };
let mut db = open_ledger(&dir, uid).unwrap();
let (binding, request, _, now) = fixture();
let (_, permit) = binding.verify(&request, now).unwrap();
consume(&mut db, &permit).unwrap();
save_start(&db, &permit, &request).unwrap();
let original: Vec<u8> = db
.query_row("SELECT start FROM execution_evidence", [], |r| r.get(0))
.unwrap();
db.execute_batch("PRAGMA max_page_count=16384").unwrap();
drop(db);
let mut db = open_ledger(&dir, uid).unwrap();
assert_eq!(
db.query_row("PRAGMA page_size", [], |r| r.get::<_, u32>(0))
.unwrap(),
4096
);
assert_eq!(
db.query_row("PRAGMA max_page_count", [], |r| r.get::<_, u32>(0))
.unwrap(),
65536
);
let preserved: (String, Option<Vec<u8>>, Vec<u8>) = db.query_row("SELECT c.grant_id,c.result,e.start FROM consumed c JOIN execution_evidence e USING(grant_id)", [], |r|Ok((r.get(0)?,r.get(1)?,r.get(2)?))).unwrap();
assert_eq!(preserved, (permit.grant_id.to_string(), None, original));
assert!(consume(&mut db, &permit).is_err());
drop(db);
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn journal_capacity_rejects_unexpected_page_size_without_rewriting_history() {
let dir = directory();
let db = rusqlite::Connection::open(dir.join("odd.sqlite")).unwrap();
db.execute_batch("PRAGMA page_size=8192;CREATE TABLE witness(value TEXT);INSERT INTO witness VALUES('retained');").unwrap();
assert!(bounded_journal_capacity(&db).is_err());
assert_eq!(
db.query_row("PRAGMA page_size", [], |r| r.get::<_, u32>(0))
.unwrap(),
8192
);
assert_eq!(
db.query_row("SELECT value FROM witness", [], |r| r.get::<_, String>(0))
.unwrap(),
"retained"
);
drop(db);
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn exact_signature_and_every_permit_binding() {
let (binding, request, key, now) = fixture();
assert!(binding.verify(&request, now).is_ok());