// SPDX-License-Identifier: MIT OR Apache-2.0
//! The checked-in `matrix/sqlx-sqlite.tsv` parses and records every certified leaf on, except rel.row_lock (SQLite has no row locks).
#![cfg(feature = "core")]
use persistant::capability::{Config, Lookup, Matrix};
#[test]
fn the_recorded_sqlite_rows_are_all_on_and_read_by_the_gate() {
let m = Matrix::parse(include_str!("../matrix/sqlx-sqlite.tsv"))
.expect("the checked-in matrix parses");
// Rows are recorded per bundled SQLite version and the older ones stay (a lockfile that still
// resolves 3.51.3 is served); every version carries the same set.
// 3.54.1 also records `kv.in_relational_transaction` on `sqlite` and `sqlite-full`.
const VERSIONS: [(&str, usize); 2] = [("3.51.3", 97), ("3.54.1", 99)];
for (v, per_os) in VERSIONS {
let n = m.rows().iter().filter(|r| r.version.ends_with(v)).count();
assert_eq!(n, 3 * per_os, "rows recorded for SQLite {v}");
}
assert_eq!(
m.rows().len(),
3 * (97 + 99),
"no other SQLite version is recorded"
);
// Each operating system recorded its own share of every version: a file whose rows were all
// attributed to one OS would pass the totals above.
for (v, per_os) in VERSIONS {
for os in ["linux", "windows", "macos"] {
let n = m
.rows()
.iter()
.filter(|r| r.version.ends_with(v) && r.metadata.get("os") == Some(os))
.count();
assert_eq!(n, per_os, "rows recorded for SQLite {v} on {os}");
}
}
// Composition of one version's 291 rows: per SQLite version, three operating systems (linux, windows, macos) each recording: twenty-four kv/lock leaves on each of sqlite and sqlite-full (plus kv.bounded_call set on each), and nineteen relational leaves (thirteen contract, six migration) on each of them are certified, and storage.secure_delete once on the opt-in secure profile, and text.index once on each of them, and kv.delete_erased and text.index.erased once on each of them (off, wrong: stale in-page fragments of earlier writes stay) and once on the opt-in secure profile (on)
for r in m.rows() {
// kv.bounded_call is recorded per call bound: off with none configured (`call_bound=unset`),
// on when the backend was certified through `Bounded` (`call_bound=set`).
let bound_row = r.subject.as_str() == "kv.bounded_call";
if bound_row {
assert_eq!(
r.enabled,
r.config.get("call_bound") == Some("set"),
"{}",
r.note
);
continue;
}
// `kv.delete_erased` and `text.index.erased` are recorded off (wrong) on the plain and the
// durable profile, where stale in-page fragments of earlier writes survive the erase, and on
// the secure profile, where `secure_delete` is on for every connection.
if matches!(r.subject.as_str(), "kv.delete_erased" | "text.index.erased") {
assert_eq!(
r.enabled,
r.config.get("secure_delete") == Some("on"),
"{} on {} {:?}: {}",
r.subject,
r.backend,
r.config,
r.note
);
continue;
}
// SQLite has no row locks and holds the write lock from `begin`: those leaves are recorded off.
assert_eq!(
r.enabled,
!matches!(
r.subject.as_str(),
"rel.row_lock"
| "rel.advisory_lock"
| "rel.error.deadlock"
| "rel.isolation.repeatable_read"
| "rel.isolation.serializable"
),
"{}: {}",
r.subject,
r.note
);
// kv rows are keyed by the adapter (plain and the durable `open_durable` profile), relational
// rows by the server itself.
if r.subject.as_str().starts_with("rel.") {
assert!(
["sqlite", "sqlite-full"].contains(&r.backend.as_str()),
"{}",
r.backend
);
} else {
assert!(
["kv-on-relational:sqlite", "kv-on-relational:sqlite-full"]
.contains(&r.backend.as_str()),
"{}",
r.backend
);
}
assert_eq!(r.config.get("dialect"), Some("sqlite"));
assert!(r.metadata.get("test").is_some());
}
let first = &m.rows()[0];
let actual = Config::new().with("dialect", "sqlite");
assert_eq!(
m.lookup(&first.subject, &first.backend, &first.version, &actual),
Lookup::On
);
assert_eq!(
m.lookup(&first.subject, &first.backend, "0.0-not-certified", &actual),
Lookup::NoRow
);
}