From 691298864afc29be0ac95061e1f6c4e16ac64a1d Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 14 Nov 2026 13:34:44 +0530 Subject: [PATCH 1/2] chore(lint): make all-targets clippy pass Use shared test-only Clippy configuration, fix fixture and benchmark lints, and enforce all targets in the v3 lint workflow. Co-Authored-By: Codex (GPT-6) --- .github/workflows/lint.yml | 8 +- Cargo.toml | 2 + benches/helpers/shape.rs | 6 +- benches/minigraf_bench.rs | 13 ++- .../minigraf_bench/chunked_transactions.rs | 6 +- benches/minigraf_bench/fact_log.rs | 2 +- benches/minigraf_bench/history.rs | 3 +- benches/minigraf_bench/memory_meter.rs | 2 +- benches/minigraf_bench/pagination.rs | 4 +- benches/simd_helpers.rs | 31 ++++--- clippy.toml | 5 ++ examples/memory_profile.rs | 1 + examples/pid_ns_helper.rs | 1 + examples/tutorial_udfs.rs | 3 +- src/graph/storage.rs | 4 +- src/query/datalog/parser.rs | 9 +- src/query/engine/tests.rs | 12 +-- src/repl.rs | 3 +- src/storage/dict.rs | 4 +- src/storage/persistent_facts.rs | 18 ++-- tests/aggregate_value_handling_test.rs | 1 + tests/aggregate_window_rules_test.rs | 1 + tests/aggregation_test.rs | 1 + tests/allow_overrides_test.rs | 15 ++-- tests/answers/mod.rs | 2 +- tests/bitemporal_test.rs | 1 + tests/btree_v6_test.rs | 1 + tests/collect_set_test.rs | 6 +- tests/complex_queries_test.rs | 1 + tests/crash_kill_test.rs | 39 +++++---- tests/cursor_test.rs | 1 + tests/disjunction_test.rs | 1 + tests/distinct_test.rs | 6 +- tests/docker_lock_test.rs | 1 + tests/edge_cases_test.rs | 3 +- tests/error_codes_prs_test.rs | 1 + tests/error_codes_qry_test.rs | 1 + tests/error_codes_storage_test.rs | 1 + tests/error_handling_test.rs | 1 + tests/fact_log_test.rs | 43 +++++----- tests/golden_corpus_test.rs | 1 + tests/grammar_doc.rs | 4 +- tests/index_corruption_test.rs | 25 +++--- tests/index_test.rs | 1 + tests/input_order_test.rs | 1 + tests/integrity_test.rs | 25 ++++-- tests/join_rules_test.rs | 1 + tests/large_transaction_acceptance_test.rs | 9 +- tests/limit_acceptance_test.rs | 7 +- tests/limit_keywords_test.rs | 57 +++++++------ tests/limit_order_test.rs | 24 +++++- tests/live_reads_test.rs | 1 + tests/log_writer_test.rs | 13 ++- tests/magic_sets_test.rs | 1 + tests/memory_limit_acceptance_test.rs | 8 +- tests/memory_limit_test.rs | 1 + tests/migration_matrix_test.rs | 1 + tests/model_based_test.rs | 1 + tests/multi_value_test.rs | 1 + tests/negation_equality_test.rs | 1 + tests/negation_test.rs | 1 + tests/nfs_lock_test.rs | 1 + tests/nightly_candidates_acceptance_test.rs | 9 +- tests/not_join_test.rs | 1 + tests/or_equality_test.rs | 1 + tests/ordinary_avg_test.rs | 1 + tests/owned_tx_test.rs | 1 + tests/path_events_test.rs | 1 + tests/pid_namespace_test.rs | 1 + tests/plan_independence_test.rs | 1 + tests/point_query_history_test.rs | 1 + tests/predicate_expr_test.rs | 1 + tests/prepared_statements_test.rs | 1 + tests/production_patterns_test.rs | 1 + tests/property_test.rs | 1 + tests/pseudo_source_test.rs | 1 + tests/read_only_open_test.rs | 1 + tests/recursive_acceptance_test.rs | 7 +- tests/recursive_engine_test.rs | 1 + tests/recursive_rules_test.rs | 1 + tests/set_predicates_test.rs | 3 +- tests/set_values_test.rs | 1 + tests/smoke_test.rs | 2 +- tests/snapshot_atomicity_test.rs | 6 +- tests/soak_test.rs | 83 +++++++++++++------ tests/statement_order_test.rs | 1 + tests/temporal_metadata_test.rs | 1 + tests/udf_reentry_test.rs | 1 + tests/udf_test.rs | 1 + tests/valid_time_window_test.rs | 1 + tests/wal_test.rs | 1 + tests/window_functions_test.rs | 7 +- tests/write_tx_guard_test.rs | 1 + tests/xtdb_compat_test.rs | 1 + 94 files changed, 381 insertions(+), 210 deletions(-) create mode 100644 clippy.toml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 07eb2e467b..3877c13e1d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,9 +1,9 @@ name: Lint # rustfmt and clippy in one job: formatting takes a second once the toolchain -# is installed. Clippy lints the library and binary with every feature; tests, -# examples and benches are not linted (the panic-prevention lints in Cargo.toml -# would need thousands of changes there). wasm.yml lints the wasm targets. +# is installed. Clippy lints all targets with every feature. clippy.toml scopes +# panic and indexing exemptions to tests; Cargo.toml keeps production denies. +# wasm.yml lints the wasm targets. on: push: @@ -33,4 +33,4 @@ jobs: run: cargo fmt -- --check - name: Run clippy - run: cargo clippy --all-features -- -D warnings + run: cargo clippy --all-targets --all-features -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index b8bde9efad..fa64d37ab1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,6 +58,8 @@ web-sys = { version = "0.3", optional = true, features = [ ] } [dev-dependencies] +# Checked float-to-integer conversions in the soak harness (already transitive). +num-traits = "0.2" serde_json = "1.0" pest = "2" pest_derive = "2" diff --git a/benches/helpers/shape.rs b/benches/helpers/shape.rs index 620e555d35..de7b7c5977 100644 --- a/benches/helpers/shape.rs +++ b/benches/helpers/shape.rs @@ -136,7 +136,7 @@ impl Shape { /// Rows the answer has. pub fn rows(&self) -> usize { - self.oracle().rows as usize + usize::try_from(self.oracle().rows).expect("fixture value fits in usize") } /// The answer, computed without the database. @@ -215,13 +215,13 @@ impl Shape { self.records(|e, a, v| { command.push_str(&format!("[#uuid \"{e}\" {a} {}]", edn(&v))); count += 1; - if count % 1000 == 0 { + if count.is_multiple_of(1000) { command.push_str("])"); db.execute(&command).unwrap(); command = String::from("(transact ["); } }); - if count % 1000 != 0 { + if !count.is_multiple_of(1000) { command.push_str("])"); db.execute(&command).unwrap(); } diff --git a/benches/minigraf_bench.rs b/benches/minigraf_bench.rs index 0e3b06c9ac..99649c1b9f 100644 --- a/benches/minigraf_bench.rs +++ b/benches/minigraf_bench.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::expect_used, + clippy::indexing_slicing, + clippy::panic, + clippy::unwrap_used +)] // TODO (Phase 7.4): Add profiling integration before optimizing the query path. // // Integrate `pprof` as a Criterion profiler (via the `pprof` crate's Criterion @@ -61,8 +67,9 @@ mod chunked_transactions; #[cfg(not(target_arch = "wasm32"))] mod simd_helpers; -use criterion::{BenchmarkId, Criterion, Throughput, black_box, criterion_group}; +use criterion::{BenchmarkId, Criterion, Throughput, criterion_group}; use minigraf::OpenOptions; +use std::hint::black_box; // ── Task 3: insert/ ─────────────────────────────────────────────────────────── @@ -1853,7 +1860,7 @@ fn bench_prepared(c: &mut Criterion) { let pq = db .prepare("(query [:find ?e :where [?e :val ?v] [(< ?v $threshold)]])") .unwrap(); - let threshold = (n / 2) as i64; + let threshold = i64::try_from(n / 2).expect("fixture value fits in i64"); b.iter(|| { pq.execute(&[( "threshold", @@ -1980,7 +1987,7 @@ fn bench_predicate_pushdown(c: &mut Criterion) { for &(label, n) in SCALES { let db = helpers::populate_with_names(n); - let threshold = (n as i64) * 9 / 10; + let threshold = i64::try_from(n).expect("fixture value fits in i64") * 9 / 10; let query = format!( "(query [:find ?e ?n :where [?e :val ?v] [?e :name ?n] [(> ?v {})]])", threshold diff --git a/benches/minigraf_bench/chunked_transactions.rs b/benches/minigraf_bench/chunked_transactions.rs index d14d14a122..652ac1acc7 100644 --- a/benches/minigraf_bench/chunked_transactions.rs +++ b/benches/minigraf_bench/chunked_transactions.rs @@ -147,7 +147,8 @@ pub fn bench_chunked_transactions(c: &mut Criterion) { let mut tx = db.begin_write().unwrap(); black_box(tx.execute(black_box(first)).unwrap()); black_box(tx.execute(black_box(second)).unwrap()); - black_box(tx.commit().unwrap()); + tx.commit().unwrap(); + black_box(()); }; validated.get_or_init(|| { let check = fixture(None); @@ -184,7 +185,8 @@ pub fn bench_chunked_transactions(c: &mut Criterion) { assert_eq!(error.code(), "API-011"); black_box(error); black_box(tx.execute(black_box(AFTER)).unwrap()); - black_box(tx.commit().unwrap()); + tx.commit().unwrap(); + black_box(()); }; validated.get_or_init(|| { let check = fixture(None); diff --git a/benches/minigraf_bench/fact_log.rs b/benches/minigraf_bench/fact_log.rs index 72fc818c34..68f9b4d617 100644 --- a/benches/minigraf_bench/fact_log.rs +++ b/benches/minigraf_bench/fact_log.rs @@ -32,7 +32,7 @@ fn records(n: usize) -> Vec { }; FactRecord { entity: Uuid::from_u128(u128::try_from(entity).unwrap() + 1), - attribute: if entity % 2 == 0 { + attribute: if entity.is_multiple_of(2) { ":history/a" } else { ":history/b" diff --git a/benches/minigraf_bench/history.rs b/benches/minigraf_bench/history.rs index f8a2ad46c7..bbb9c12ad1 100644 --- a/benches/minigraf_bench/history.rs +++ b/benches/minigraf_bench/history.rs @@ -1,4 +1,5 @@ -use criterion::{BenchmarkId, Criterion, black_box}; +use criterion::{BenchmarkId, Criterion}; +use std::hint::black_box; // ── point_query_chain_depth (Issue #323) ───────────────────────────────────── // diff --git a/benches/minigraf_bench/memory_meter.rs b/benches/minigraf_bench/memory_meter.rs index e572e9096f..2f64708626 100644 --- a/benches/minigraf_bench/memory_meter.rs +++ b/benches/minigraf_bench/memory_meter.rs @@ -64,7 +64,7 @@ pub fn bench_memory_meter(c: &mut Criterion) { .path(&path) .open() .unwrap(); - let err = constrained.execute(query).err().expect("limit enforced"); + let err = constrained.execute(query).expect_err("limit enforced"); assert_eq!(err.code(), "QRY-012"); assert!( err.to_string().contains("Aggregate"), diff --git a/benches/minigraf_bench/pagination.rs b/benches/minigraf_bench/pagination.rs index 9f83d0b47c..7d7941d595 100644 --- a/benches/minigraf_bench/pagination.rs +++ b/benches/minigraf_bench/pagination.rs @@ -74,7 +74,7 @@ pub fn bench_pagination(c: &mut Criterion) { if descending { ":desc" } else { ":asc" } ); let expected: Vec<_> = (offset..offset + limit) - .map(|i| vec![Value::Integer(if descending { n - 1 - i } else { i } as i64)]) + .map(|i| vec![Value::Integer(i64::try_from(if descending { n - 1 - i } else { i }).expect("fixture value fits in i64"))]) .collect(); // Validate the entire page (including offset/order), not just // its size. Keep fixture and oracle work out of the measurement. @@ -94,7 +94,7 @@ pub fn bench_pagination(c: &mut Criterion) { oracle.sort_unstable_by(|a, b| b.0.cmp(&a.0).then(a.1.cmp(&b.1)).then(a.2.cmp(&b.2))); let expected: Vec<_> = oracle[137..147] .iter() - .map(|&(g, s, v)| vec![Value::Integer(g as i64), Value::Integer(s as i64), Value::Integer(v as i64)]) + .map(|&(g, s, v)| vec![Value::Integer(i64::try_from(g).expect("fixture value fits in i64")), Value::Integer(i64::try_from(s).expect("fixture value fits in i64")), Value::Integer(i64::try_from(v).expect("fixture value fits in i64"))]) .collect(); assert!(rows(&db, query) == expected, "complete tie order matches oracle"); b.iter(|| black_box(rows(&db, black_box(query)))); diff --git a/benches/simd_helpers.rs b/benches/simd_helpers.rs index ef87b8a9a0..7008aeca89 100644 --- a/benches/simd_helpers.rs +++ b/benches/simd_helpers.rs @@ -16,7 +16,7 @@ #![allow(clippy::cast_possible_truncation)] // synthetic bench data: N ≤ 1M fits in i64 #![allow(clippy::cast_sign_loss)] // tx_count cast: monotonic counter, always positive -use wide::{CmpGt, i64x4, u64x4}; +use wide::{i64x4, u64x4}; /// Count facts where `valid_from[i] <= ts && ts < valid_to[i]`. /// @@ -101,7 +101,7 @@ pub fn sum_simd_i64(values: &[i64]) -> i64 { for chunk in values.chunks_exact(4) { let [a, b, c, d] = *chunk else { unreachable!() }; - acc = acc + i64x4::new([a, b, c, d]); + acc += i64x4::new([a, b, c, d]); } let lanes: [i64; 4] = acc.to_array(); @@ -117,7 +117,6 @@ pub fn sum_simd_i64(values: &[i64]) -> i64 { #[cfg(test)] mod tests { - use super::*; // ── valid_time_filter_simd ──────────────────────────────────────────────── @@ -135,7 +134,10 @@ mod tests { .filter(|&(&vf, &vt)| vf <= ts && ts < vt) .count(); - assert_eq!(valid_time_filter_simd(&valid_from, &valid_to, ts), scalar); + assert_eq!( + super::valid_time_filter_simd(&valid_from, &valid_to, ts), + scalar + ); } #[test] @@ -151,12 +153,15 @@ mod tests { .filter(|&(&vf, &vt)| vf <= ts && ts < vt) .count(); - assert_eq!(valid_time_filter_simd(&valid_from, &valid_to, ts), scalar); + assert_eq!( + super::valid_time_filter_simd(&valid_from, &valid_to, ts), + scalar + ); } #[test] fn test_valid_time_filter_empty() { - assert_eq!(valid_time_filter_simd(&[], &[], 0), 0); + assert_eq!(super::valid_time_filter_simd(&[], &[], 0), 0); } // ── as_of_filter_simd ───────────────────────────────────────────────────── @@ -169,7 +174,7 @@ mod tests { let scalar = tx_counts.iter().filter(|&&tc| tc <= threshold).count(); - assert_eq!(as_of_filter_simd(&tx_counts, threshold), scalar); + assert_eq!(super::as_of_filter_simd(&tx_counts, threshold), scalar); } #[test] @@ -180,12 +185,12 @@ mod tests { let scalar = tx_counts.iter().filter(|&&tc| tc <= threshold).count(); - assert_eq!(as_of_filter_simd(&tx_counts, threshold), scalar); + assert_eq!(super::as_of_filter_simd(&tx_counts, threshold), scalar); } #[test] fn test_as_of_filter_empty() { - assert_eq!(as_of_filter_simd(&[], 100), 0); + assert_eq!(super::as_of_filter_simd(&[], 100), 0); } // ── sum_simd_i64 ────────────────────────────────────────────────────────── @@ -196,7 +201,7 @@ mod tests { let values: Vec = (1_i64..=9).collect(); let scalar: i64 = values.iter().sum(); - assert_eq!(sum_simd_i64(&values), scalar); + assert_eq!(super::sum_simd_i64(&values), scalar); } #[test] @@ -205,12 +210,12 @@ mod tests { let values: Vec = (1_i64..=8).collect(); let scalar: i64 = values.iter().sum(); - assert_eq!(sum_simd_i64(&values), scalar); + assert_eq!(super::sum_simd_i64(&values), scalar); } #[test] fn test_sum_simd_empty() { - assert_eq!(sum_simd_i64(&[]), 0); + assert_eq!(super::sum_simd_i64(&[]), 0); } #[test] @@ -218,6 +223,6 @@ mod tests { let values = vec![-3_i64, -2, -1, 0, 1, 2, 3]; let scalar: i64 = values.iter().sum(); - assert_eq!(sum_simd_i64(&values), scalar); + assert_eq!(super::sum_simd_i64(&values), scalar); } } diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000000..c3141ff402 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,5 @@ +# Assertions and fixture helpers may panic; production code keeps Cargo.toml's denies. +allow-unwrap-in-tests = true +allow-expect-in-tests = true +allow-panic-in-tests = true +allow-indexing-slicing-in-tests = true diff --git a/examples/memory_profile.rs b/examples/memory_profile.rs index 476060b9c4..593693a766 100644 --- a/examples/memory_profile.rs +++ b/examples/memory_profile.rs @@ -1,3 +1,4 @@ +#![allow(clippy::unwrap_used)] //! Memory profiling target for heaptrack. //! //! Usage: cargo run --example memory_profile --release -- diff --git a/examples/pid_ns_helper.rs b/examples/pid_ns_helper.rs index 95550023fa..9d65cdd166 100644 --- a/examples/pid_ns_helper.rs +++ b/examples/pid_ns_helper.rs @@ -1,3 +1,4 @@ +#![allow(clippy::indexing_slicing)] //! Helper for `tests/pid_namespace_test.rs`. Opens a database and either dies //! holding the lock, or reports whether the open succeeded. //! diff --git a/examples/tutorial_udfs.rs b/examples/tutorial_udfs.rs index 4d5a6f7f2d..8b746778c6 100644 --- a/examples/tutorial_udfs.rs +++ b/examples/tutorial_udfs.rs @@ -1,3 +1,4 @@ +#![allow(clippy::indexing_slicing)] //! Tutorial Section 10 — User-Defined Functions //! //! Demonstrates `register_predicate` and `register_aggregate` in the context @@ -195,7 +196,7 @@ fn main() -> anyhow::Result<()> { for row in &window_rows { let order = match &row[0] { Value::Keyword(k) => format!(":{}", k), - Value::Ref(u) => format!("{}", &u.to_string()[..8]), + Value::Ref(u) => u.to_string()[..8].to_string(), other => format!("{:?}", other), }; let score = match &row[1] { diff --git a/src/graph/storage.rs b/src/graph/storage.rs index b347ca5a8f..49c898951f 100644 --- a/src/graph/storage.rs +++ b/src/graph/storage.rs @@ -2502,7 +2502,7 @@ mod tests { entity, attribute: attr.to_string(), value, - tx_id: tx_count as u64, + tx_id: tx_count, tx_count, valid_from, valid_to, @@ -2516,7 +2516,7 @@ mod tests { entity, attribute: attr.to_string(), value, - tx_id: tx_count as u64, + tx_id: tx_count, tx_count, valid_from: 0, valid_to: VALID_TIME_FOREVER, diff --git a/src/query/datalog/parser.rs b/src/query/datalog/parser.rs index 8143691c0e..2c118b0f87 100644 --- a/src/query/datalog/parser.rs +++ b/src/query/datalog/parser.rs @@ -3246,7 +3246,9 @@ mod tests { } } - fn parse_order(input: &str) -> Result<(Vec<(FindSpec, Order)>, Option)> { + type ParsedOrder = (Vec<(FindSpec, Order)>, Option); + + fn parse_order(input: &str) -> Result { match parse_datalog_command(input)? { DatalogCommand::Query(q) => Ok((q.order_by, q.offset)), _ => panic!("expected Query"), @@ -4529,8 +4531,7 @@ mod window_parse_tests { parse_datalog_command(&query("(sum ?v :over (:order-by ?v :rows 1 preceding))")) .expect("matching frame"); let error = parse_datalog_command(&query("(sum ?v :over (:order-by ?v))")) - .err() - .expect("different frame"); + .expect_err("different frame"); assert_eq!(crate::MinigrafError::from(error).code(), "PRS-117"); } @@ -4679,7 +4680,7 @@ mod window_parse_tests { r#"(query [:find ?d (count ?e) (sum ?d :over (:partition-by ?v :order-by ?d)) :where [?e :x ?v] [?e :d ?d]])"#, r#"(query [:find ?d (count ?e) (sum ?v :over (:order-by ?d)) :with ?v :where [?e :x ?v] [?e :d ?d]])"#, ] { - let err = parse_datalog_command(q).err().expect("rejected"); + let err = parse_datalog_command(q).expect_err("rejected"); assert_eq!(crate::MinigrafError::from(err).code(), "PRS-082"); } parse_datalog_command( diff --git a/src/query/engine/tests.rs b/src/query/engine/tests.rs index f52071e451..cc642d2ff8 100644 --- a/src/query/engine/tests.rs +++ b/src/query/engine/tests.rs @@ -72,13 +72,13 @@ fn write_round(db: &Minigraf, round: u32) { [:p{p} :person/score {score}] [:p{p} :person/attr :person/age] [:p{p} :p{f} {p}]])", age = 20 + round % 4, bio = long(p % 2), - ok = (round + p) % 2 == 0, + ok = (round + p).is_multiple_of(2), boss = uuid_of(&format!(":p{f}")), alias = uuid_of(&format!(":p{}", (p + 1) % 6)), score = scores[((round + p) % 5) as usize], )) .unwrap(); - if (round + p) % 2 == 0 { + if (round + p).is_multiple_of(2) { db.execute(&format!( "(retract [[:p{p} :person/status :s{s}] [:p{p} :person/age {}] \ [:p{p} :person/score {}]])", @@ -87,7 +87,7 @@ fn write_round(db: &Minigraf, round: u32) { )) .unwrap(); } - if (round + p) % 3 == 0 { + if (round + p).is_multiple_of(3) { db.execute(&format!( "(transact {{:valid-from \"2023-01-01\" :valid-to \"2023-06-30\"}} \ [[:p{p} :person/name \"n{p}\"] [:p{p} :person/null nil]])" @@ -587,7 +587,7 @@ fn pseudo_attributes_without_a_source_are_prs_081() { :where [?e :db/tx-count ?t] [?e :person/age ?a]])", ] { let err = db.execute(q).unwrap_err(); - assert_eq!(crate::MinigrafError::from(err).code(), "PRS-081"); + assert_eq!(err.code(), "PRS-081"); } } @@ -610,7 +610,7 @@ fn engine_queries_raise_the_executor_errors() { ] { let before = runs(); let err = db.execute(q).unwrap_err(); - assert_eq!(crate::MinigrafError::from(err).code(), code); + assert_eq!(err.code(), code); assert_eq!(runs(), before, "no engine run"); } } @@ -4120,7 +4120,7 @@ fn top_k_memory_follows_k_not_the_input() { let e = db .execute("(query [:find ?e ?v :where [?e :a ?v] :order-by [?v :desc]])") .expect_err("a full sort over the limit"); - assert_eq!(crate::MinigrafError::from(e).code(), "QRY-012"); + assert_eq!(e.code(), "QRY-012"); } #[test] diff --git a/src/repl.rs b/src/repl.rs index 5f57fcc069..7826d816bf 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -543,7 +543,8 @@ mod tests { #[test] fn format_value_float() { use crate::graph::types::Value; - assert_eq!(Repl::format_value(&Value::Float(3.14)), "3.14"); + let two_decimal_pi = (std::f64::consts::PI * 100.0).trunc() / 100.0; + assert_eq!(Repl::format_value(&Value::Float(two_decimal_pi)), "3.14"); } #[test] diff --git a/src/storage/dict.rs b/src/storage/dict.rs index 282e4d0ef6..228755c966 100644 --- a/src/storage/dict.rs +++ b/src/storage/dict.rs @@ -948,7 +948,7 @@ mod tests { assert_eq!(long_entries, 1, "one stored copy within a checkpoint"); // Re-asserting in a later checkpoint writes no value page. - let again = vec![fact(3, ":bio", Value::String(long), 3)]; + let again = [fact(3, ":bio", Value::String(long), 3)]; let mut enc2 = Encoder::new(enc.next_eid, enc.next_iid); { let mut dict = DictReader::new(root, &backend, &cache); @@ -989,7 +989,7 @@ mod tests { .count(); assert_eq!(long_entries, 1, "one stored copy within a checkpoint"); - let again = vec![fact(3, ":s", long_set_value(), 2)]; + let again = [fact(3, ":s", long_set_value(), 2)]; let mut enc2 = Encoder::new(enc.next_eid, enc.next_iid); { let mut dict = DictReader::new(root, &backend, &cache); diff --git a/src/storage/persistent_facts.rs b/src/storage/persistent_facts.rs index ff0c5cd920..e20d905608 100644 --- a/src/storage/persistent_facts.rs +++ b/src/storage/persistent_facts.rs @@ -1022,7 +1022,8 @@ mod tests { fn assert_indexes_exact(meta: &MetaPage, backend: &dyn StorageBackend) { let cache = PageCache::new(0); let facts = |index, root| { - let mut v: Vec<(Uuid, String, Vec, u64, i64, i64, bool)> = + type IndexedFact = (Uuid, String, Vec, u64, i64, i64, bool); + let mut v: Vec = all_entries_as_facts(index, root, meta.dict_root, backend, &cache) .unwrap() .into_iter() @@ -1072,13 +1073,13 @@ mod tests { let mut batch = Vec::new(); for i in 0..n { let k = seed.wrapping_mul(31).wrapping_add(i as u64); - let e = if *next_entity == 0 || k % 3 == 0 { + let e = if *next_entity == 0 || k.is_multiple_of(3) { *next_entity += 1; entity(*next_entity) } else { entity(u128::from(k) % *next_entity + 1) }; - let value = if k % 4 == 0 { + let value = if k.is_multiple_of(4) { Value::Ref(entity(u128::from(k / 4) % *next_entity + 1)) } else { Value::String(format!("v{k}")) @@ -2329,7 +2330,9 @@ mod tests { /// Mixed facts: short and long strings (some repeated), keywords, refs, /// numbers, multi-valued attributes and retractions. - fn mixed_batch(round: u64, n: u64) -> (Vec<(Uuid, String, Value)>, Vec<(Uuid, String, Value)>) { + type FactBatch = Vec<(Uuid, String, Value)>; + + fn mixed_batch(round: u64, n: u64) -> (FactBatch, FactBatch) { let mut asserts = Vec::new(); let mut retracts = Vec::new(); for i in 0..n { @@ -2343,10 +2346,10 @@ mod tests { 3 => Value::Ref(entity(u128::from(k % 41))), 4 => Value::Integer(i64::try_from(k).unwrap() - 500), 5 => Value::Float(k as f64 / 7.0), - 6 => Value::Boolean(k % 2 == 0), + 6 => Value::Boolean(k.is_multiple_of(2)), _ => Value::String("x".repeat(65 + (k % 3) as usize)), }; - if k % 11 == 0 { + if k.is_multiple_of(11) { retracts.push((e, a, v)); } else { asserts.push((e, a, v)); @@ -2656,7 +2659,8 @@ mod tests { /// counter bound exactly when `tx_id` rises with `tx_count` over both. #[test] fn tx_bound_keeps_what_the_executor_filter_keeps() { - let cases: [(&[(u64, u64)], &[(u64, u64)], bool); 6] = [ + type TxBoundCase<'a> = (&'a [(u64, u64)], &'a [(u64, u64)], bool); + let cases: [TxBoundCase<'_>; 6] = [ (&[(1, 100), (2, 200), (4, 400)], &[(5, 500), (6, 600)], true), (&[(1, 100), (2, 200)], &[], true), (&[], &[(1, 100), (2, 200), (2, 200)], true), diff --git a/tests/aggregate_value_handling_test.rs b/tests/aggregate_value_handling_test.rs index ce09df2269..8171416dec 100644 --- a/tests/aggregate_value_handling_test.rs +++ b/tests/aggregate_value_handling_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! #789: ordinary and window aggregates share their argument domain. use minigraf::{BindValue, Minigraf, QueryResult, Value}; diff --git a/tests/aggregate_window_rules_test.rs b/tests/aggregate_window_rules_test.rs index 427e917c28..a34c78b7a8 100644 --- a/tests/aggregate_window_rules_test.rs +++ b/tests/aggregate_window_rules_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Aggregate and window answers that do not depend on the plan (#547, spec //! `docs/superpowers/specs/2026-10-20-aggregate-window-engine-design.md` §3.4). //! `plan_independence_test.rs` runs the same shapes with reordering on and diff --git a/tests/aggregation_test.rs b/tests/aggregation_test.rs index 84d5b10af1..e2c9487e34 100644 --- a/tests/aggregation_test.rs +++ b/tests/aggregation_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Integration tests for Phase 7.2a aggregation. //! Covers count, sum, min, max, :with, rules, negation, and temporal queries. diff --git a/tests/allow_overrides_test.rs b/tests/allow_overrides_test.rs index 22ea7ff751..db031a977e 100644 --- a/tests/allow_overrides_test.rs +++ b/tests/allow_overrides_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] #![cfg(not(target_arch = "wasm32"))] //! `OpenOptions::allow_overrides` (#869, spec #862 §1–§2): the embedder //! decides which query keywords may override its limits; a keyword the list @@ -44,11 +45,11 @@ fn defaults_allow_both_keywords() { fn empty_list_refuses_every_entry_point() { let db = setup(OpenOptions::new().allow_overrides([])); for (q, kw) in [(DERIVED, ":max-derived-facts"), (RESULTS, ":max-results")] { - refused(db.execute(q).err().expect("execute refused"), kw); - refused(db.query(q).err().expect("query refused"), kw); - refused(db.prepare(q).err().expect("prepare refused"), kw); + refused(db.execute(q).expect_err("execute refused"), kw); + refused(db.query(q).expect_err("query refused"), kw); + refused(db.prepare(q).expect_err("prepare refused"), kw); let mut tx = db.begin_write().expect("begin"); - refused(tx.execute(q).err().expect("tx refused"), kw); + refused(tx.execute(q).expect_err("tx refused"), kw); tx.rollback(); } assert_eq!(rows(db.execute(PLAIN).expect("plain")), 2); @@ -68,7 +69,7 @@ fn empty_list_refuses_every_entry_point() { fn list_replaces_defaults() { let db = setup(OpenOptions::new().allow_overrides([Overridable::MaxResults])); refused( - db.execute(DERIVED).err().expect("refused"), + db.execute(DERIVED).expect_err("refused"), ":max-derived-facts", ); assert_eq!(rows(db.execute(RESULTS).expect("allowed")), 2); @@ -79,7 +80,7 @@ fn refused_tx_execute_leaves_transaction_usable() { let db = setup(OpenOptions::new().allow_overrides([])); let mut tx = db.begin_write().expect("begin"); refused( - tx.execute(DERIVED).err().expect("refused"), + tx.execute(DERIVED).expect_err("refused"), ":max-derived-facts", ); tx.execute("(transact [[:c :edge :d]])").expect("transact"); @@ -127,7 +128,7 @@ fn file_database_option_not_persisted() { db.execute("(transact [[:a :edge :b]])").expect("transact"); db.execute(RULE).expect("rule"); refused( - db.execute(DERIVED).err().expect("refused"), + db.execute(DERIVED).expect_err("refused"), ":max-derived-facts", ); } diff --git a/tests/answers/mod.rs b/tests/answers/mod.rs index 44ce56428d..7761d0594e 100644 --- a/tests/answers/mod.rs +++ b/tests/answers/mod.rs @@ -43,7 +43,7 @@ const WEEK_MS: u64 = 7 * 86_400_000; fn now() -> i64 { std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) - .map(|d| d.as_millis() as i64) + .map(|d| i64::try_from(d.as_millis()).expect("fixture value fits in i64")) .unwrap_or(0) } diff --git a/tests/bitemporal_test.rs b/tests/bitemporal_test.rs index 22a137ee59..e2a28c64b3 100644 --- a/tests/bitemporal_test.rs +++ b/tests/bitemporal_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] use minigraf::{Minigraf, QueryResult, Value}; /// Helper: execute a Datalog command string via `Minigraf::execute`, panicking on error diff --git a/tests/btree_v6_test.rs b/tests/btree_v6_test.rs index 1ada2b5a22..e310e8bb12 100644 --- a/tests/btree_v6_test.rs +++ b/tests/btree_v6_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Integration tests for Phase 6.5: on-disk B+tree indexes (file format v6). #![cfg(not(target_arch = "wasm32"))] diff --git a/tests/collect_set_test.rs b/tests/collect_set_test.rs index 597b005017..957ccb1a54 100644 --- a/tests/collect_set_test.rs +++ b/tests/collect_set_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! `collect-set` (#316 spec §7): `[(collect-set ?e :a) ?s]` binds the set of //! the values of `[?e :a ?v]` under the query's view, `#{}` when there are //! none. @@ -28,7 +29,7 @@ fn one_set(db: &Minigraf, q: &str) -> Value { } fn code(db: &Minigraf, q: &str) -> String { - db.execute(q).err().expect("an error").code().to_string() + db.execute(q).expect_err("an error").code().to_string() } fn scopes() -> Minigraf { @@ -356,8 +357,7 @@ fn memory_limit_is_qry_012() { .unwrap(); let err = db .execute("(query [:find ?s :where [?e :name _] [(collect-set ?e :v) ?s]])") - .err() - .expect("over the limit"); + .expect_err("over the limit"); assert_eq!(err.code(), "QRY-012"); assert!( err.to_string().contains("CollectSet"), diff --git a/tests/complex_queries_test.rs b/tests/complex_queries_test.rs index 60621ba011..a752de87de 100644 --- a/tests/complex_queries_test.rs +++ b/tests/complex_queries_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] use minigraf::{Minigraf, QueryResult, Value}; use uuid::Uuid; diff --git a/tests/crash_kill_test.rs b/tests/crash_kill_test.rs index 33eaf6e299..5f250b8a70 100644 --- a/tests/crash_kill_test.rs +++ b/tests/crash_kill_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! A `SIGKILL` at any point while a child process writes must leave the //! database holding exactly the transactions the child had committed (#384). //! @@ -119,7 +120,7 @@ impl Rng { } fn below_u8(&mut self, n: u8) -> u8 { - self.below(u64::from(n)) as u8 + u8::try_from(self.below(u64::from(n))).expect("fixture value fits in u8") } } @@ -131,7 +132,10 @@ fn next_tx(rng: &mut Rng, live: &BTreeSet) -> (String, BTreeSet) let pool: Vec = live.iter().copied().collect(); let mut picked = BTreeSet::new(); for _ in 0..1 + rng.below(4) { - picked.insert(pool[rng.below(pool.len() as u64) as usize]); + picked.insert( + pool[usize::try_from(rng.below(pool.len() as u64)) + .expect("fixture value fits in usize")], + ); } let body: Vec = picked.iter().map(|t| triple_edn(*t)).collect(); for t in &picked { @@ -143,7 +147,7 @@ fn next_tx(rng: &mut Rng, live: &BTreeSet) -> (String, BTreeSet) // 0-3 other triples. Triples retracted earlier come back this way. A // triple is never repeated within one transaction. let e = rng.below_u8(ENTITIES); - let a = rng.below_u8(ATTRS.len() as u8); + let a = rng.below_u8(u8::try_from(ATTRS.len()).expect("fixture value fits in u8")); let mut picked = BTreeSet::new(); for _ in 0..1 + rng.below(3) { picked.insert((e, a, rng.below_u8(VALUES))); @@ -151,7 +155,7 @@ fn next_tx(rng: &mut Rng, live: &BTreeSet) -> (String, BTreeSet) for _ in 0..rng.below(4) { picked.insert(( rng.below_u8(ENTITIES), - rng.below_u8(ATTRS.len() as u8), + rng.below_u8(u8::try_from(ATTRS.len()).expect("fixture value fits in u8")), rng.below_u8(VALUES), )); } @@ -268,11 +272,11 @@ impl Variant { fn checkpoint_after(self, k: u64) -> bool { match self { Variant::CheckpointEach => true, - Variant::CheckpointEvery3 | Variant::NormalSync => k % 3 == 0, + Variant::CheckpointEvery3 | Variant::NormalSync => k.is_multiple_of(3), Variant::WalOnly | Variant::AutoCheckpoint => false, - Variant::PerTxSync => k % 5 == 0, + Variant::PerTxSync => k.is_multiple_of(5), #[cfg(feature = "test-hooks")] - Variant::Large => k % 5 == 0, + Variant::Large => k.is_multiple_of(5), } } } @@ -341,7 +345,7 @@ impl Checker { "{}: tx count {t} after {confirmed} confirmed transactions", self.ctx ); - let live = &history[t as usize]; + let live = &history[usize::try_from(t).expect("fixture value fits in usize")]; let full = |s: &BTreeSet| -> Vec { s.iter() .map(|&(e, a, v)| format!("r{e} {} {}", ATTRS[a as usize], value_render(v))) @@ -356,7 +360,7 @@ impl Checker { ); // AEVT: attribute scans; AVET: attribute and value bound. for (ai, attr) in ATTRS.iter().enumerate() { - let ai = ai as u8; + let ai = u8::try_from(ai).expect("fixture value fits in u8"); self.expect( db, &format!("(query [:find ?e ?v :where [?e {attr} ?v]])"), @@ -393,7 +397,8 @@ impl Checker { self.expect( db, &format!("(query [:find ?e ?a ?v :as-of {k} :where [?e ?a ?v]])"), - full(&history[k as usize]).into_iter(), + full(&history[usize::try_from(k).expect("fixture value fits in usize")]) + .into_iter(), ); } let report = db @@ -430,10 +435,14 @@ fn sigkill_keeps_exactly_the_committed_transactions() { .ok() .and_then(|s| s.parse().ok()) .unwrap_or_else(|| { - std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_nanos() as u64 + u64::try_from( + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos() + & u128::from(u64::MAX), + ) + .expect("low seed bits fit in u64") }); println!("crash-kill base seed {base_seed} (replay: MINIGRAF_CRASH_KILL_SEED={base_seed})"); let uuids: HashMap = (0..ENTITIES).map(|e| (entity_uuid(e), e)).collect(); @@ -540,7 +549,7 @@ fn crash_kill_child_entrypoint() { tx.commit().expect("child commit"); } else { #[cfg(feature = "test-hooks")] - if large && k % 3 == 0 { + if large && k.is_multiple_of(3) { in_write_tx(&db, &stmt); } else { db.execute(&stmt).expect("child transaction"); diff --git a/tests/cursor_test.rs b/tests/cursor_test.rs index b6cdbdea13..919e3a80a0 100644 --- a/tests/cursor_test.rs +++ b/tests/cursor_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! `Minigraf::query` and `PreparedQuery::query` return a `Cursor` that delivers //! the answer in batches (#432). These tests pin the public contract the //! streaming engine must keep: batches partition the `execute()` answer, the diff --git a/tests/disjunction_test.rs b/tests/disjunction_test.rs index 1b37340b44..09e1c1c743 100644 --- a/tests/disjunction_test.rs +++ b/tests/disjunction_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Integration tests for Phase 7.3: or / or-join disjunction. use minigraf::{Minigraf, OpenOptions, QueryResult, Value}; diff --git a/tests/distinct_test.rs b/tests/distinct_test.rs index ee72434dff..9f9ed859aa 100644 --- a/tests/distinct_test.rs +++ b/tests/distinct_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Optional distinct output (#493). Default queries still return bags. #![cfg(not(target_arch = "wasm32"))] @@ -68,7 +69,7 @@ fn distinct_is_a_bare_non_repeating_section() { (":distinct ?e", "PRS-061"), ] { let q = format!("(query [:find ?e :where [?e :c ?v] {extra}])"); - assert_eq!(db.prepare(&q).err().expect("rejected").code(), code); + assert_eq!(db.prepare(&q).expect_err("rejected").code(), code); } } @@ -488,8 +489,7 @@ fn retained_set_payloads_count_toward_the_memory_limit() { ] { let e = db .execute(q) - .err() - .expect("retained set payloads must exceed the bound"); + .expect_err("retained set payloads must exceed the bound"); assert_eq!(e.code(), "QRY-012"); } } diff --git a/tests/docker_lock_test.rs b/tests/docker_lock_test.rs index 7c15b55378..6890eec0a1 100644 --- a/tests/docker_lock_test.rs +++ b/tests/docker_lock_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! #324: kernel file locking, tier 3 — two containers sharing a Docker //! volume, matching the deployment shape in the #317 report literally. //! diff --git a/tests/edge_cases_test.rs b/tests/edge_cases_test.rs index db12345223..e622992fa9 100644 --- a/tests/edge_cases_test.rs +++ b/tests/edge_cases_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Edge case integration tests for Phase 6.4a. //! //! Covers: @@ -233,7 +234,7 @@ fn test_sub_page_file_refused_unless_torn_first_write() { } let saved = std::fs::read(&path).unwrap(); std::fs::remove_file(&path).unwrap(); - let foreign = vec![0x5Au8; 100]; + let foreign = [0x5Au8; 100]; for bytes in [&saved[..2222], &saved[..20], &foreign[..]] { std::fs::write(&path, bytes).unwrap(); assert_eq!(open_code(&path), "STG-045"); diff --git a/tests/error_codes_prs_test.rs b/tests/error_codes_prs_test.rs index 1fb5fa18a2..0fc132d107 100644 --- a/tests/error_codes_prs_test.rs +++ b/tests/error_codes_prs_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Regression tests for issue #358 (#277 2/6): PRS-0xx parser error codes. //! //! `src/query/datalog/parser.rs` now carries a real, documented `PRS-0xx` diff --git a/tests/error_codes_qry_test.rs b/tests/error_codes_qry_test.rs index f4ff8cb151..05f11694d8 100644 --- a/tests/error_codes_qry_test.rs +++ b/tests/error_codes_qry_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Regression tests for issue #361 (part of #277): QRY-0xx error codes. //! //! Drives the full public `Minigraf::execute()` API and asserts the specific diff --git a/tests/error_codes_storage_test.rs b/tests/error_codes_storage_test.rs index ec361b0a2f..7f72de602b 100644 --- a/tests/error_codes_storage_test.rs +++ b/tests/error_codes_storage_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Regression tests for #359 (STG-0xx storage error codes, part of the #277 //! structured error codes rollout): asserts that specific `STG-NNN` codes //! come back through the public `Minigraf::open()` API for corrupt/invalid diff --git a/tests/error_handling_test.rs b/tests/error_handling_test.rs index 801cfe295b..b9563252ba 100644 --- a/tests/error_handling_test.rs +++ b/tests/error_handling_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Integration-level error paths and aggregate type-boundary regressions. //! Invalid programs still propagate errors; aggregate values follow #789. diff --git a/tests/fact_log_test.rs b/tests/fact_log_test.rs index 7fdffed5ba..df2dc215b9 100644 --- a/tests/fact_log_test.rs +++ b/tests/fact_log_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! `Minigraf::fact_log` streams every fact record with its transaction and //! valid-time bounds (#430). These tests check the records against a model of //! the writes, in every split between checkpointed and pending facts, both @@ -50,7 +51,9 @@ fn tx_id_of(result: QueryResult) -> u64 { /// The writes, one transaction per step: `(command, records)` where each record /// is `(entity, attribute, value as Debug, asserted)`. -fn steps() -> Vec<(String, Vec<(usize, &'static str, String, bool)>)> { +type Step = (String, Vec<(usize, &'static str, String, bool)>); + +fn steps() -> Vec { let e = |i: usize| format!("#uuid \"{}\"", uuid(i)); let s = |v: &str| format!("String({v:?})"); let mut steps = vec![ @@ -243,23 +246,24 @@ fn records_are_identical_across_layouts() { let dir = tempfile::tempdir().unwrap(); let mut all = Vec::new(); for (_name, db, _) in layouts(dir.path()) { - let mut recs: Vec<(u64, String, String, String, bool, Option, i64)> = - read(&db, &FactFilter::new(), 1000) - .iter() - .map(|r| { - ( - r.tx_count, - name_of(&r.entity).to_string(), - r.attribute.clone(), - format!("{:?}", r.value), - r.asserted, - // `None` for the transaction time, so layouts written - // at different times compare equal. - (r.valid_from != r.tx_id as i64).then_some(r.valid_from), - r.valid_to, - ) - }) - .collect(); + type NormalizedRecord = (u64, String, String, String, bool, Option, i64); + let mut recs: Vec = read(&db, &FactFilter::new(), 1000) + .iter() + .map(|r| { + ( + r.tx_count, + name_of(&r.entity).to_string(), + r.attribute.clone(), + format!("{:?}", r.value), + r.asserted, + // `None` for the transaction time, so layouts written + // at different times compare equal. + (r.valid_from != i64::try_from(r.tx_id).expect("fixture value fits in i64")) + .then_some(r.valid_from), + r.valid_to, + ) + }) + .collect(); recs.sort(); all.push(recs); } @@ -282,7 +286,8 @@ fn valid_time_and_long_values_round_trip() { .find(|r| r.attribute == ":person/name") .expect("name record"); assert_eq!( - name.valid_from, name.tx_id as i64, + name.valid_from, + i64::try_from(name.tx_id).expect("fixture value fits in i64"), "default valid_from is tx time" ); assert_eq!(name.valid_to, i64::MAX, "default valid_to is forever"); diff --git a/tests/golden_corpus_test.rs b/tests/golden_corpus_test.rs index cdc89ca2d9..ca0620fbd7 100644 --- a/tests/golden_corpus_test.rs +++ b/tests/golden_corpus_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Golden-file compatibility corpus (#391). //! //! Every `tests/golden/*.json` manifest names a committed `.graph` file (and diff --git a/tests/grammar_doc.rs b/tests/grammar_doc.rs index bd9f3d2676..db2f70bb08 100644 --- a/tests/grammar_doc.rs +++ b/tests/grammar_doc.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! `docs/GRAMMAR.md` is rendered from `tests/grammar/grammar.pest` (#643). //! //! `grammar_doc_is_current` renders the grammar as EBNF and fails when the file differs. @@ -285,7 +286,8 @@ fn render(src: &str) -> String { // Rules grouped into sections; names are aligned within a section. let mut note = None; let mut comment = None; - let mut sections: Vec<(Option, Vec<(String, Node, bool)>)> = Vec::new(); + type Section = (Option, Vec<(String, Node, bool)>); + let mut sections: Vec
= Vec::new(); for rule in &rules { if rule.name == "WHITESPACE" { note = Some(whitespace_note(&rule.expr)); diff --git a/tests/index_corruption_test.rs b/tests/index_corruption_test.rs index cbc7c0b161..0f2818fdc5 100644 --- a/tests/index_corruption_test.rs +++ b/tests/index_corruption_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Index corruption recovery tests (#216). #![cfg(not(target_arch = "wasm32"))] @@ -110,18 +111,15 @@ fn query_results_after_non_critical_corruption_match_original() { db.checkpoint().unwrap(); } corrupt_bytes_at(&path, 84, 16); - match Minigraf::open(&path) { - Ok(db) => { - let n = count_results( - db.execute("(query [:find ?n :where [?e :name ?n]])") - .unwrap(), - ); - assert_eq!( - n, 2, - "both facts must be visible after non-critical corruption" - ); - } - Err(_) => {} + if let Ok(db) = Minigraf::open(&path) { + let n = count_results( + db.execute("(query [:find ?n :where [?e :name ?n]])") + .unwrap(), + ); + assert_eq!( + n, 2, + "both facts must be visible after non-critical corruption" + ); } } @@ -148,8 +146,7 @@ fn query_over_damaged_leaves_fails_with_stg_029() { ] { let err = db .execute(q) - .err() - .expect("a query over damaged pages must fail"); + .expect_err("a query over damaged pages must fail"); assert_eq!(err.code(), "STG-029", "query fails with the checksum code"); } } diff --git a/tests/index_test.rs b/tests/index_test.rs index 0ae3966a3b..f40f84f8dd 100644 --- a/tests/index_test.rs +++ b/tests/index_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Integration tests for Phase 6.1 covering indexes. //! //! These tests verify that: diff --git a/tests/input_order_test.rs b/tests/input_order_test.rs index 9901fa82ec..37e011f3ea 100644 --- a/tests/input_order_test.rs +++ b/tests/input_order_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Differential oracle: identical ordered lists with input-order strategies //! enabled and disabled, across the existing plan switches and snapshots. #![cfg(all(feature = "test-hooks", not(target_arch = "wasm32")))] diff --git a/tests/integrity_test.rs b/tests/integrity_test.rs index 72a4cf999b..5ab5eaf407 100644 --- a/tests/integrity_test.rs +++ b/tests/integrity_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! `Minigraf::verify` and `Minigraf::rebuild_indexes` through the public API (#373). #![cfg(not(target_arch = "wasm32"))] @@ -91,7 +92,10 @@ fn damaged_leaves_are_reported_and_index_damage_is_repaired() { } let bytes = std::fs::read(&clean).unwrap(); let leaves: Vec = (2..bytes.len() as u64 / PAGE_SIZE) - .filter(|&p| bytes[(p * PAGE_SIZE) as usize] == PAGE_TYPE_LEAF) + .filter(|&p| { + bytes[usize::try_from(p * PAGE_SIZE).expect("fixture value fits in usize")] + == PAGE_TYPE_LEAF + }) .collect(); assert!(leaves.len() > 4, "fixture spans several leaves"); @@ -99,7 +103,8 @@ fn damaged_leaves_are_reported_and_index_damage_is_repaired() { for (i, &leaf) in leaves.iter().enumerate() { let path = dir.path().join(format!("damaged{i}.graph")); let mut damaged = bytes.clone(); - damaged[(leaf * PAGE_SIZE + 2000) as usize] ^= 0x5A; + damaged[usize::try_from(leaf * PAGE_SIZE + 2000).expect("fixture value fits in usize")] ^= + 0x5A; std::fs::write(&path, &damaged).unwrap(); let db = Minigraf::open(&path).unwrap(); @@ -144,13 +149,18 @@ fn internal_node_pointing_at_itself_fails_the_scan_instead_of_looping() { } let bytes = std::fs::read(&clean).unwrap(); let internals: Vec = (2..bytes.len() as u64 / PAGE_SIZE) - .filter(|&p| bytes[(p * PAGE_SIZE) as usize] == PAGE_TYPE_INTERNAL) + .filter(|&p| { + bytes[usize::try_from(p * PAGE_SIZE).expect("fixture value fits in usize")] + == PAGE_TYPE_INTERNAL + }) .collect(); assert!(!internals.is_empty(), "fixture has internal nodes"); let mut refused = 0; for (i, &node) in internals.iter().enumerate() { let mut damaged = bytes.clone(); - let page = &mut damaged[(node * PAGE_SIZE) as usize..((node + 1) * PAGE_SIZE) as usize]; + let page = &mut damaged[usize::try_from(node * PAGE_SIZE) + .expect("fixture value fits in usize") + ..usize::try_from((node + 1) * PAGE_SIZE).expect("fixture value fits in usize")]; page[RIGHTMOST_CHILD..RIGHTMOST_CHILD + 8].copy_from_slice(&node.to_le_bytes()); page[4..8].fill(0); let crc = crc32fast::hash(page); @@ -251,7 +261,7 @@ fn sub_page_file_is_refused_unless_a_torn_first_write() { } let template = std::fs::read(&path).unwrap(); std::fs::remove_file(&path).unwrap(); - let foreign = vec![0x5Au8; 100]; + let foreign = [0x5Au8; 100]; for bytes in [&template[..2222], &template[..20], &foreign[..]] { std::fs::write(&path, bytes).unwrap(); assert_eq!(open_code(&path, false), "STG-045"); @@ -289,11 +299,12 @@ fn meta_page_count_past_end_is_refused_and_file_never_grows() { let (path, len) = checkpointed_file(dir.path(), "forged.graph"); let mut bytes = std::fs::read(&path).unwrap(); let generation = |page: usize| -> u64 { - let off = page * PAGE_SIZE as usize; + let off = page * usize::try_from(PAGE_SIZE).expect("fixture value fits in usize"); u64::from_le_bytes(bytes[off + 16..off + 24].try_into().unwrap()) }; let active = if generation(0) >= generation(1) { 0 } else { 1 }; - let meta = &mut bytes[active * PAGE_SIZE as usize..(active + 1) * PAGE_SIZE as usize]; + let meta = &mut bytes[active * usize::try_from(PAGE_SIZE).expect("fixture value fits in usize") + ..(active + 1) * usize::try_from(PAGE_SIZE).expect("fixture value fits in usize")]; meta[24..32].copy_from_slice(&(1u64 << 50).to_le_bytes()); meta[12..16].fill(0); let crc = crc32fast::hash(meta); diff --git a/tests/join_rules_test.rs b/tests/join_rules_test.rs index d10185171a..2574667c99 100644 --- a/tests/join_rules_test.rs +++ b/tests/join_rules_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Join rules that do not depend on the query plan (#545, #473 spec §5.4): //! bound floats are equal by IEEE `==`, and a variable bound to both a //! keyword and a ref returns the kind from the first pattern, in `:where` diff --git a/tests/large_transaction_acceptance_test.rs b/tests/large_transaction_acceptance_test.rs index 0a5cee64e6..a8110a0c4d 100644 --- a/tests/large_transaction_acceptance_test.rs +++ b/tests/large_transaction_acceptance_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Acceptance test for large transactions (#550 spec §8.1, #473 spec §8): a //! 1M-fact `transact` on a file database holds at most `TX_CHUNK_FACTS` //! materialised facts at any time, and commits as a checkpoint. A statement @@ -156,7 +157,7 @@ fn custom_chunk_bounds() { }; assert_eq!(results.len(), 1); assert!( - matches!(results[0][0], minigraf::Value::Integer(n) if n == facts as i64), + matches!(results[0][0], minigraf::Value::Integer(n) if n == i64::try_from(facts).expect("fixture value fits in i64")), "all facts survive reopen" ); assert_eq!(db.current_tx_count(), 1); @@ -191,12 +192,12 @@ fn check_heavy_entry(db: &Minigraf, ctx: &str) { ); assert_eq!( count_value(db, "(query [:find (count ?e) :where [?e :n ?v]])"), - (FACTS / 2) as i64, + i64::try_from(FACTS / 2).expect("fixture value fits in i64"), "{ctx}: AEVT :n" ); assert_eq!( count_value(db, "(query [:find (count ?v) :where [?e :m ?v]])"), - (FACTS / 2) as i64, + i64::try_from(FACTS / 2).expect("fixture value fits in i64"), "{ctx}: AEVT :m" ); assert_eq!( @@ -231,7 +232,7 @@ fn check_heavy_entry(db: &Minigraf, ctx: &str) { ); assert_eq!( count_value(db, "(query [:find (count ?e) :as-of 1 :where [?e :n ?v]])"), - (FACTS / 2) as i64, + i64::try_from(FACTS / 2).expect("fixture value fits in i64"), "{ctx}: first entry is whole at tx 1" ); } diff --git a/tests/limit_acceptance_test.rs b/tests/limit_acceptance_test.rs index 4675c1823f..293e43d674 100644 --- a/tests/limit_acceptance_test.rs +++ b/tests/limit_acceptance_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Acceptance test for `:limit` and top-k (#306 spec §5, moved from #473): //! over 10M facts, `:limit 10` stops the query once it has its rows, so its //! time and memory do not grow with the facts; `:order-by [?v :desc] :limit @@ -92,10 +93,10 @@ fn limit_and_top_k_over_10m_facts() { w.append(&FactRecord { entity: uuid::Uuid::from_u128(i as u128 + 1), attribute: ":a".to_string(), - value: Value::Integer(i as i64), + value: Value::Integer(i64::try_from(i).expect("fixture value fits in i64")), tx_count: tx, tx_id: 1_700_000_000_000 + tx, - valid_from: (1_700_000_000_000 + tx) as i64, + valid_from: i64::try_from(1_700_000_000_000 + tx).expect("fixture value fits in i64"), valid_to: i64::MAX, asserted: true, }) @@ -125,7 +126,7 @@ fn limit_and_top_k_over_10m_facts() { _ => panic!("an integer"), }) .collect(); - let n = FACTS as i64; + let n = i64::try_from(FACTS).expect("fixture value fits in i64"); assert_eq!( top, ((n - 10)..n).rev().collect::>(), diff --git a/tests/limit_keywords_test.rs b/tests/limit_keywords_test.rs index 01a9d7ad4f..d2e47e0df4 100644 --- a/tests/limit_keywords_test.rs +++ b/tests/limit_keywords_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] #![cfg(not(target_arch = "wasm32"))] //! `:query-memory-limit`, bind slots on the limit keywords and the //! `PreparedQuery` limit setters (#870, spec #862 §3–§5). @@ -51,7 +52,7 @@ fn rows(r: QueryResult) -> usize { } fn code(r: Result) -> &'static str { - r.err().expect("an error").code() + r.expect_err("an error").code() } fn with(query: &str, opt: &str) -> String { @@ -128,16 +129,15 @@ fn memory_keyword_is_refused_by_default() { "names the variant" ); }; - refused(db.execute(&q).err().expect("execute")); - refused(db.query(&q).err().expect("query")); - refused(db.prepare(&q).err().expect("prepare")); + refused(db.execute(&q).expect_err("execute")); + refused(db.query(&q).expect_err("query")); + refused(db.prepare(&q).expect_err("prepare")); refused( db.prepare(&with(VALUES, ":query-memory-limit $m")) - .err() - .expect("slot"), + .expect_err("slot"), ); let mut tx = db.begin_write().expect("begin"); - refused(tx.execute(&q).err().expect("tx")); + refused(tx.execute(&q).expect_err("tx")); tx.rollback(); } @@ -268,11 +268,7 @@ fn unbound_limit_slots_are_refused_by_execute() { ] { let q = with(REACH, opt); assert_eq!(code(db.execute(&q)), "API-010", "{opt}"); - assert_eq!( - db.query(&q).err().expect("query").code(), - "API-010", - "{opt}" - ); + assert_eq!(db.query(&q).expect_err("query").code(), "API-010", "{opt}"); } } @@ -280,7 +276,7 @@ fn unbound_limit_slots_are_refused_by_execute() { fn empty_list_refuses_slots_at_prepare() { let db = setup(OpenOptions::new().allow_overrides([])); for opt in [":max-derived-facts $n", ":max-results $n"] { - let err = db.prepare(&with(REACH, opt)).err().expect("refused"); + let err = db.prepare(&with(REACH, opt)).expect_err("refused"); assert_eq!(err.code(), "API-025", "{opt}"); } } @@ -295,7 +291,7 @@ fn derived_facts_setter_replaces_the_database_value() { .expect("prepare") .with_max_derived_facts(1); assert_eq!(code(low.execute(&[])), "INT-020"); - assert_eq!(low.query(&[]).err().expect("cursor").code(), "INT-020"); + assert_eq!(low.query(&[]).expect_err("cursor").code(), "INT-020"); let db = setup(OpenOptions::new().max_derived_facts(1)); assert_eq!(code(db.execute(REACH)), "INT-020"); @@ -381,8 +377,11 @@ fn default_round_limit_allows_long_chains() { #[test] fn open_option_sets_the_round_limit() { - let db = setup(OpenOptions::new().max_iterations(REACH_ROUNDS as usize - 1)); - let err = db.execute(REACH).err().expect("over the limit"); + let db = + setup(OpenOptions::new().max_iterations( + usize::try_from(REACH_ROUNDS).expect("fixture value fits in usize") - 1, + )); + let err = db.execute(REACH).expect_err("over the limit"); assert_eq!(err.code(), "INT-020"); let text = err.to_string(); assert!(text.contains(":max-iterations"), "says how to raise it"); @@ -390,7 +389,10 @@ fn open_option_sets_the_round_limit() { text.contains("OpenOptions::max_iterations"), "names the option" ); - let db = setup(OpenOptions::new().max_iterations(REACH_ROUNDS as usize)); + let db = setup( + OpenOptions::new() + .max_iterations(usize::try_from(REACH_ROUNDS).expect("fixture value fits in usize")), + ); assert_eq!(rows(db.execute(REACH).expect("at the limit")), 10); let db = setup(OpenOptions::new().max_iterations(0)); assert_eq!(code(db.execute(REACH)), "INT-020"); @@ -454,9 +456,9 @@ fn iterations_keyword_is_in_the_defaults_and_gated() { let db = setup(OpenOptions::new().allow_overrides([])); let q = with_iterations(REACH, 10); assert_eq!(code(db.execute(&q)), "API-025"); - assert_eq!(db.query(&q).err().expect("query").code(), "API-025"); - assert_eq!(db.prepare(&q).err().expect("prepare").code(), "API-025"); - let err = db.execute(&q).err().expect("refused").to_string(); + assert_eq!(db.query(&q).expect_err("query").code(), "API-025"); + assert_eq!(db.prepare(&q).expect_err("prepare").code(), "API-025"); + let err = db.execute(&q).expect_err("refused").to_string(); assert!( err.contains("Overridable::MaxIterations"), "names the variant" @@ -509,18 +511,17 @@ fn iterations_slot_changes_per_execution() { #[test] fn iterations_setter_replaces_the_database_value() { let db = setup(OpenOptions::new()); - let low = db - .prepare(REACH) - .expect("prepare") - .with_max_iterations(REACH_ROUNDS as usize - 1); + let low = db.prepare(REACH).expect("prepare").with_max_iterations( + usize::try_from(REACH_ROUNDS).expect("fixture value fits in usize") - 1, + ); assert_eq!(code(low.execute(&[])), "INT-020"); - assert_eq!(low.query(&[]).err().expect("cursor").code(), "INT-020"); + assert_eq!(low.query(&[]).expect_err("cursor").code(), "INT-020"); let db = setup(OpenOptions::new().allow_overrides([]).max_iterations(1)); let high = db .prepare(REACH) .expect("prepare") - .with_max_iterations(REACH_ROUNDS as usize); + .with_max_iterations(usize::try_from(REACH_ROUNDS).expect("fixture value fits in usize")); assert_eq!(rows(high.execute(&[]).expect("ungated")), 10); let db = setup(OpenOptions::new()); @@ -542,7 +543,9 @@ fn prepared_query_clone_is_independent() { assert_eq!(rows(pq.execute(&[]).expect("source unchanged")), 10); let low = db.prepare(REACH).expect("prepare").with_max_iterations(1); - let high = low.clone().with_max_iterations(REACH_ROUNDS as usize); + let high = low + .clone() + .with_max_iterations(usize::try_from(REACH_ROUNDS).expect("fixture value fits in usize")); assert_eq!(rows(high.execute(&[]).expect("copy raised")), 10); assert_eq!(code(low.execute(&[])), "INT-020"); diff --git a/tests/limit_order_test.rs b/tests/limit_order_test.rs index ec5ebfcdaf..4e279929c8 100644 --- a/tests/limit_order_test.rs +++ b/tests/limit_order_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! `:limit`, `:offset` and `:order-by` (#306, spec `docs/superpowers/specs/2026-10-24-limit-order-by-design.md`). //! //! Without `:order-by`, `:limit n` returns `min(n, |answer|)` rows, and @@ -123,7 +124,12 @@ fn check(db: &Minigraf) { pulled.extend(keys(batch.rows())); } - let bind = [("n", BindValue::Val(Value::Integer(n as i64)))]; + let bind = [( + "n", + BindValue::Val(Value::Integer( + i64::try_from(n).expect("fixture value fits in i64"), + )), + )]; let from_prepared = results(prepared.execute(&bind).expect(&q)); let mut cursor = prepared.query(&bind).expect(&q); let mut prepared_pulled = Vec::new(); @@ -279,7 +285,9 @@ fn values(r: QueryResult) -> Vec> { /// Ordered shapes: a body, its `:order-by` vector, and the keys as /// `(column, descending)`. -const ORDERED: &[(&str, &str, &[(usize, bool)])] = &[ +type OrderedCase = (&'static str, &'static str, &'static [(usize, bool)]); + +const ORDERED: &[OrderedCase] = &[ ( ":find ?e ?a :where [?e :age ?a]", "[?a :desc]", @@ -390,9 +398,17 @@ fn check_ordered(db: &Minigraf) { let bind = [ ( "o", - BindValue::Val(Value::Integer(offset.unwrap_or(0) as i64)), + BindValue::Val(Value::Integer( + i64::try_from(offset.unwrap_or(0)) + .expect("fixture value fits in i64"), + )), + ), + ( + "n", + BindValue::Val(Value::Integer( + i64::try_from(n).expect("fixture value fits in i64"), + )), ), - ("n", BindValue::Val(Value::Integer(n as i64))), ]; let got = keys(&values(prepared.execute(&bind).expect(&q))); assert_eq!(got, want, "{q} via prepared, reorder {reorder}"); diff --git a/tests/live_reads_test.rs b/tests/live_reads_test.rs index ab9c500132..ae956993d9 100644 --- a/tests/live_reads_test.rs +++ b/tests/live_reads_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Query results over committed history equal those over the same history held //! in memory (#379). The file-backed database checkpoints between batches, so //! its committed facts go through the key-level net-assert walk; the in-memory diff --git a/tests/log_writer_test.rs b/tests/log_writer_test.rs index 0cade36687..b6679621fc 100644 --- a/tests/log_writer_test.rs +++ b/tests/log_writer_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! `LogWriter` builds a new database from explicit fact records (#431). These //! tests copy a source's fact log through it and check that the result answers //! every query, `:as-of` and fact-log read as the source does, survives a @@ -246,10 +247,13 @@ fn many_batches_give_the_same_file_contents() { let rec = FactRecord { entity: Uuid::from_u128(u128::from(i % 1000) + 1), attribute: format!(":n/a{}", i % 7), - value: Value::Integer((tx * per_tx + i) as i64), + value: Value::Integer( + i64::try_from(tx * per_tx + i).expect("fixture value fits in i64"), + ), tx_count: tx * 2, tx_id: 1_700_000_000_000 + tx, - valid_from: 1_700_000_000_000 + tx as i64, + valid_from: 1_700_000_000_000 + + i64::try_from(tx).expect("fixture value fits in i64"), valid_to: i64::MAX, asserted: true, }; @@ -272,7 +276,8 @@ fn many_batches_give_the_same_file_contents() { }, _ => panic!("results"), }; - let a3_per_tx = (0..per_tx).filter(|i| i % 7 == 3).count() as i64; + let a3_per_tx = i64::try_from((0..per_tx).filter(|i| i % 7 == 3).count()) + .expect("fixture value fits in i64"); assert_eq!( count("(query [:find (count ?v) :where [?e :n/a3 ?v]])"), 9 * a3_per_tx @@ -352,7 +357,7 @@ fn rec(tx_count: u64, tx_id: u64, attr: &str, value: i64) -> FactRecord { value: Value::Integer(value), tx_count, tx_id, - valid_from: tx_id as i64, + valid_from: i64::try_from(tx_id).expect("fixture value fits in i64"), valid_to: i64::MAX, asserted: true, } diff --git a/tests/magic_sets_test.rs b/tests/magic_sets_test.rs index d4f90fb351..dfdd8c623a 100644 --- a/tests/magic_sets_test.rs +++ b/tests/magic_sets_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Integration tests for magic sets rewriting (#289). //! //! Asserts result *correctness* only — magic sets must never change query results. diff --git a/tests/memory_limit_acceptance_test.rs b/tests/memory_limit_acceptance_test.rs index 77c50fbc5e..aab42956b5 100644 --- a/tests/memory_limit_acceptance_test.rs +++ b/tests/memory_limit_acceptance_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Acceptance tests for query memory accounting (#549 spec §6.2, and #575): //! a query whose state is large either completes or fails with `QRY-012` //! under `OpenOptions::query_memory_limit`, a cartesian product streams @@ -129,8 +130,7 @@ fn grouped_count_1m_groups() { &db, "(query [:find ?g (sum-distinct ?v) :where [?e :g ?g] [(+ ?g 0.5) ?v]])", ) - .err() - .expect("over the limit"); + .expect_err("over the limit"); assert_eq!(err.code(), "QRY-012", "stopped by the limit"); assert!(err.to_string().contains("Aggregate"), "names Aggregate"); // The database answers other queries. @@ -176,7 +176,7 @@ fn cartesian_k13_streams() { .path(dir.path().join("cartesian.graph")) .open() .unwrap(); - let err = drain(&db, &query).err().expect("over the limit"); + let err = drain(&db, &query).expect_err("over the limit"); assert_eq!(err.code(), "QRY-012", "stopped by the limit"); assert!(err.to_string().contains("HashJoin"), "names HashJoin"); } @@ -213,7 +213,7 @@ fn count_holds_no_rows() { }; assert_eq!(results.len(), 1, "one row"); assert!( - matches!(results[0][0], minigraf::Value::Integer(n) if n == GROUPS as i64), + matches!(results[0][0], minigraf::Value::Integer(n) if n == i64::try_from(GROUPS).expect("fixture value fits in i64")), "counts every fact" ); acceptance::check_rss( diff --git a/tests/memory_limit_test.rs b/tests/memory_limit_test.rs index a43db36375..8b92c4d686 100644 --- a/tests/memory_limit_test.rs +++ b/tests/memory_limit_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! `OpenOptions::query_memory_limit` and `QRY-012` through the public API //! (#549): the default, the builder, and every way a query runs. diff --git a/tests/migration_matrix_test.rs b/tests/migration_matrix_test.rs index ed40b4534f..8db7053f01 100644 --- a/tests/migration_matrix_test.rs +++ b/tests/migration_matrix_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Migration matrix tests (#215). #![cfg(not(target_arch = "wasm32"))] diff --git a/tests/model_based_test.rs b/tests/model_based_test.rs index b3fa571458..94245b66c1 100644 --- a/tests/model_based_test.rs +++ b/tests/model_based_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Model-based (stateful) test of the file-backed database (#385). //! //! Random sequences of transact, retract, write transactions, checkpoints and diff --git a/tests/multi_value_test.rs b/tests/multi_value_test.rs index 8dbff76974..239711cf6b 100644 --- a/tests/multi_value_test.rs +++ b/tests/multi_value_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Same-transaction multi-valued facts (#371, #287): every query path must //! return every value, before checkpoint, after WAL replay, and after //! checkpoint + reopen. diff --git a/tests/negation_equality_test.rs b/tests/negation_equality_test.rs index 95b41681c4..e2841f9945 100644 --- a/tests/negation_equality_test.rs +++ b/tests/negation_equality_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! A value a `not` / `not-join` body takes from the outer row compares as a //! join compares it (#546, design //! `docs/superpowers/specs/2026-10-16-negation-disjunction-engine-design.md` diff --git a/tests/negation_test.rs b/tests/negation_test.rs index 8093cba67a..9feaa96dcf 100644 --- a/tests/negation_test.rs +++ b/tests/negation_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Integration tests for stratified negation (Phase 7.1a). //! Covers the 10 scenarios from the spec testing plan. diff --git a/tests/nfs_lock_test.rs b/tests/nfs_lock_test.rs index ebc0ae3a09..6558258c2d 100644 --- a/tests/nfs_lock_test.rs +++ b/tests/nfs_lock_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! #324: kernel file locking must behave correctly on network filesystems. //! //! `flock` over NFS is emulated by `fcntl` on Linux since 2.6.37, which works diff --git a/tests/nightly_candidates_acceptance_test.rs b/tests/nightly_candidates_acceptance_test.rs index d9140dc00b..0d1e70ef93 100644 --- a/tests/nightly_candidates_acceptance_test.rs +++ b/tests/nightly_candidates_acceptance_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Nightly acceptance for the #841 shape-sweep candidates qualified by #863: //! each test pins one candidate's answer and the path it guards (operator //! names from the cursor's `Debug` view, `minigraf::__path_events`) and, @@ -239,7 +240,7 @@ fn n6_held_cursor_quarantine_and_reuse() { .append(&minigraf::FactRecord { entity: entity(i), attribute: ":pin/value".into(), - value: Value::Integer(i as i64), + value: Value::Integer(i64::try_from(i).expect("fixture value fits in i64")), tx_count: (i / 1000 + 1) as u64, tx_id: 1_700_000_000_000 + (i / 1000) as u64, valid_from: 0, @@ -273,7 +274,11 @@ fn n6_held_cursor_quarantine_and_reuse() { panic!("entity and value expected"); }; let i = (e.as_u128() - entity(0).as_u128()) as usize; - assert_eq!(*v as usize, expected[i], "held cursor reads its state"); + assert_eq!( + usize::try_from(*v).expect("fixture value fits in usize"), + expected[i], + "held cursor reads its state" + ); assert!(!seen[i], "one row per entity"); seen[i] = true; } diff --git a/tests/not_join_test.rs b/tests/not_join_test.rs index e23b4268e4..45294e9959 100644 --- a/tests/not_join_test.rs +++ b/tests/not_join_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Integration tests for Phase 7.1b: not-join (existential negation). use minigraf::{Minigraf, OpenOptions, QueryResult}; diff --git a/tests/or_equality_test.rs b/tests/or_equality_test.rs index 902d494648..93ed85bc30 100644 --- a/tests/or_equality_test.rs +++ b/tests/or_equality_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! An `or` / `or-join` branch row meets the outer row by join equality (#546, //! design `docs/superpowers/specs/2026-10-16-negation-disjunction-engine-design.md` //! §3.5, §3.6 item 3, §5.3): a keyword equal to a ref to the entity it names, diff --git a/tests/ordinary_avg_test.rs b/tests/ordinary_avg_test.rs index cf2a9c6cb4..fc5a28f0e6 100644 --- a/tests/ordinary_avg_test.rs +++ b/tests/ordinary_avg_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Ordinary avg shares window avg's numeric population and arithmetic (#777). use minigraf::{BindValue, Minigraf, QueryResult, Value}; diff --git a/tests/owned_tx_test.rs b/tests/owned_tx_test.rs index dcc473e896..0b194e7517 100644 --- a/tests/owned_tx_test.rs +++ b/tests/owned_tx_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] // File-backed (Minigraf::open, tempfile): native only, like the other file tests. #![cfg(not(target_arch = "wasm32"))] //! `OwnedWriteTransaction` (#824): a write transaction that owns its diff --git a/tests/path_events_test.rs b/tests/path_events_test.rs index 09e045e61b..7d8299cf32 100644 --- a/tests/path_events_test.rs +++ b/tests/path_events_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! The `test-hooks` path events and memory peaks the nightly acceptance tests //! read (#863): `minigraf::__path_events` and `Cursor::__memory_peak`. #![cfg(all(feature = "test-hooks", not(target_arch = "wasm32")))] diff --git a/tests/pid_namespace_test.rs b/tests/pid_namespace_test.rs index 192b9dbb87..a020a8e286 100644 --- a/tests/pid_namespace_test.rs +++ b/tests/pid_namespace_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! #317: a `.graph` file must stay openable after its holder dies in another //! PID namespace. //! diff --git a/tests/plan_independence_test.rs b/tests/plan_independence_test.rs index 5d3ffe33ff..ef24771f02 100644 --- a/tests/plan_independence_test.rs +++ b/tests/plan_independence_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Every plan returns the same rows the same number of times (#596, design //! `docs/superpowers/specs/2026-10-15-plan-independent-answers-design.md`). //! diff --git a/tests/point_query_history_test.rs b/tests/point_query_history_test.rs index 68d9ff3bc1..4287b6225a 100644 --- a/tests/point_query_history_test.rs +++ b/tests/point_query_history_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! #323 — bound-entity point queries must return exactly what a full scan returns, //! while only reading the queried attributes' history. //! diff --git a/tests/predicate_expr_test.rs b/tests/predicate_expr_test.rs index 2321985694..d481a80e9b 100644 --- a/tests/predicate_expr_test.rs +++ b/tests/predicate_expr_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Integration tests for Phase 7.2b: arithmetic and predicate expression clauses. use minigraf::{Minigraf, QueryResult, Value as MgValue}; diff --git a/tests/prepared_statements_test.rs b/tests/prepared_statements_test.rs index 72e17bb605..1567935ebd 100644 --- a/tests/prepared_statements_test.rs +++ b/tests/prepared_statements_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] use minigraf::db::Minigraf; use minigraf::{BindValue, QueryResult, Value}; use uuid::Uuid; diff --git a/tests/production_patterns_test.rs b/tests/production_patterns_test.rs index a46f19749f..d2b0b487ee 100644 --- a/tests/production_patterns_test.rs +++ b/tests/production_patterns_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Cross-feature integration tests for Phase 7.5. //! Each test models a realistic embedder workload combining 2–3 Datalog features. diff --git a/tests/property_test.rs b/tests/property_test.rs index 68055146a1..55fe8db992 100644 --- a/tests/property_test.rs +++ b/tests/property_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Cross-feature property tests (#221, #386). //! //! Compares Minigraf query results against a deliberately simple reference diff --git a/tests/pseudo_source_test.rs b/tests/pseudo_source_test.rs index 162dab6a52..400444eeda 100644 --- a/tests/pseudo_source_test.rs +++ b/tests/pseudo_source_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Pseudo-attribute sources (#594, design //! `docs/superpowers/specs/2026-10-15-plan-independent-answers-design.md` //! §3.1–3.3): a per-fact pseudo-attribute (`:db/valid-from`, `:db/valid-to`, diff --git a/tests/read_only_open_test.rs b/tests/read_only_open_test.rs index 6642be11fb..9aa6da5f10 100644 --- a/tests/read_only_open_test.rs +++ b/tests/read_only_open_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! `OpenOptions::read_only` (#429): a handle that shows the same data as a //! read-write open, writes nothing to the `.graph` file or its WAL, refuses //! writes with API-014, and shares the file with other read-only handles. diff --git a/tests/recursive_acceptance_test.rs b/tests/recursive_acceptance_test.rs index 258252c2c9..f39230e5ea 100644 --- a/tests/recursive_acceptance_test.rs +++ b/tests/recursive_acceptance_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Acceptance tests for recursive rules on the streaming engine (#473, #548 //! spec §7): a rule deriving about 5M facts completes, and its peak memory //! follows the derived relation; the default `max_derived_facts` stops the @@ -108,8 +109,7 @@ fn reach_5m() { let db = layered(&dir, OpenOptions::new()); let err = db .execute("(query [:find ?x ?y :where (reach ?x ?y)])") - .err() - .expect("over the default max_derived_facts"); + .expect_err("over the default max_derived_facts"); assert_eq!(err.code().to_string(), "INT-020", "stopped by the limit"); } @@ -221,8 +221,7 @@ fn closure_scaling(multistratum: bool) { } let err = db .execute(query) - .err() - .expect("derived relation exceeds the cap"); + .expect_err("derived relation exceeds the cap"); assert_eq!(err.code(), "INT-020"); eprintln!("{label}: derived_cap=1000 error=INT-020"); } diff --git a/tests/recursive_engine_test.rs b/tests/recursive_engine_test.rs index b99cf572be..f172589576 100644 --- a/tests/recursive_engine_test.rs +++ b/tests/recursive_engine_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Rule queries on the streaming engine (#548 spec §7). Each query runs on //! an in-memory database, on a file with its facts pending, and on the same //! file after a checkpoint, and its answer must be the one recorded while the diff --git a/tests/recursive_rules_test.rs b/tests/recursive_rules_test.rs index 3890ad5369..25d18d2a28 100644 --- a/tests/recursive_rules_test.rs +++ b/tests/recursive_rules_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] use minigraf::{Minigraf, QueryResult, Value}; use uuid::Uuid; diff --git a/tests/set_predicates_test.rs b/tests/set_predicates_test.rs index 589a22522b..8a28511062 100644 --- a/tests/set_predicates_test.rs +++ b/tests/set_predicates_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Set-membership predicates (#316): `in?`, `not-in?`, `any-in?`, `all-in?`, //! `none-in?` as filters and as Boolean bindings, over literal, stored and //! bind-slot operands. @@ -299,7 +300,7 @@ fn wrong_arity_is_prs_065() { for op in ["in?", "not-in?", "any-in?", "all-in?", "none-in?"] { for args in ["1", "1 #{1} #{2}"] { let q = format!("(query [:find ?x :where [?x :t/k _] [({op} {args})]])"); - let err = db.execute(&q).err().expect("arity error"); + let err = db.execute(&q).expect_err("arity error"); assert_eq!(err.code(), "PRS-065", "{op} with {args}"); } } diff --git a/tests/set_values_test.rs b/tests/set_values_test.rs index 6960acf858..978d7c842a 100644 --- a/tests/set_values_test.rs +++ b/tests/set_values_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Set values (#316): transact, query, retract and persist `#{...}`, through //! the pending store, a checkpoint, a reopen, WAL replay, the fact log and //! the log writer. diff --git a/tests/smoke_test.rs b/tests/smoke_test.rs index 56d38ca55f..2c961ef7a7 100644 --- a/tests/smoke_test.rs +++ b/tests/smoke_test.rs @@ -114,7 +114,7 @@ fn smoke_large_graph_10_cycles() { ); // 500 entities, active if i % 3 != 0. Inactive: i=0,3,6,...,498 → 167 entities. // ceil(NUM_ENTITIES / 3) = number of multiples of 3 in [0, NUM_ENTITIES). - let n_inactive = (NUM_ENTITIES + 2) / 3; + let n_inactive = NUM_ENTITIES.div_ceil(3); let expected_active = NUM_ENTITIES - n_inactive; assert_eq!( n_active, expected_active, diff --git a/tests/snapshot_atomicity_test.rs b/tests/snapshot_atomicity_test.rs index bbc17e9d1e..e8c534f230 100644 --- a/tests/snapshot_atomicity_test.rs +++ b/tests/snapshot_atomicity_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Reproducers: a query must see each transaction whole, and each fact once, //! while other threads commit and checkpoint (#473 spec §2 and §4.1). //! @@ -77,7 +78,7 @@ fn batch(i: u64) -> String { fn commit_is_seen_whole(db: Minigraf, write: impl FnMut(&Minigraf, u64) + Send + 'static) { let found = race(Arc::new(db), write, |db| { let n = rows(db, "(query [:find ?e :where [?e :batch/id ?b]])").len() as u64; - (n % N != 0).then(|| format!("saw {n} facts, not a multiple of {N}")) + (!n.is_multiple_of(N)).then(|| format!("saw {n} facts, not a multiple of {N}")) }); if let Some(msg) = found { panic!("partial transaction visible: {msg}"); @@ -224,7 +225,8 @@ fn checkpoint_never_hides_committed_facts() { db.checkpoint().unwrap(); }, |db| { - let before = committed.load(Ordering::SeqCst) as usize; + let before = usize::try_from(committed.load(Ordering::SeqCst)) + .expect("fixture value fits in usize"); let half = rows( db, "(query [:find ?e :where [?e :pair/y ?v] (not [?e :pair/x ?v])])", diff --git a/tests/soak_test.rs b/tests/soak_test.rs index 9acd134789..03d07cf903 100644 --- a/tests/soak_test.rs +++ b/tests/soak_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Long-running soak test at scale (#392). //! //! Grows a file-backed database to millions of facts in batches of mixed @@ -22,6 +23,7 @@ use minigraf::db::{Minigraf, OpenOptions}; use minigraf::{QueryResult, Value}; +use num_traits::ToPrimitive; use std::collections::{HashMap, HashSet}; use std::fs::File; use std::io::Write; @@ -68,7 +70,11 @@ impl Rng { /// Log-uniform in `lo..=hi`: small batches are common, large ones occur. fn log_uniform(&mut self, lo: u64, hi: u64) -> u64 { let (l, h) = ((lo as f64).ln(), ((hi + 1) as f64).ln()); - ((l + (h - l) * self.unit()).exp() as u64).clamp(lo, hi) + (l + (h - l) * self.unit()) + .exp() + .to_u64() + .expect("log-uniform sample fits in u64") + .clamp(lo, hi) } } @@ -157,9 +163,18 @@ fn content(seed: u64, n: u64) -> Vec<(String, Val)> { let h = mix(seed ^ n.wrapping_mul(0x2545_F491_4F6C_DD1D)); let mut facts = vec![ (":p/name".to_string(), Val::Str(format!("name-{n}"))), - (":p/score".to_string(), Val::Int((h % 1000) as i64)), - (format!(":p/shard{}", n % SHARDS), Val::Int(n as i64)), - (format!(":p/shard{}", n % SHARDS), Val::Int(-(n as i64) - 1)), + ( + ":p/score".to_string(), + Val::Int(i64::try_from(h % 1000).expect("fixture value fits in i64")), + ), + ( + format!(":p/shard{}", n % SHARDS), + Val::Int(i64::try_from(n).expect("fixture value fits in i64")), + ), + ( + format!(":p/shard{}", n % SHARDS), + Val::Int(-i64::try_from(n).expect("fixture value fits in i64") - 1), + ), ]; let start = (h >> 10) % 16; for i in 0..1 + (h >> 20) % 4 { @@ -169,13 +184,13 @@ fn content(seed: u64, n: u64) -> Vec<(String, Val)> { Val::Kw(format!(":t{}", (start + i * 5) % 16)), )); } - if n % 50 == 0 { + if n.is_multiple_of(50) { facts.push(( ":p/bio".to_string(), Val::Str(format!("bio-{n}-{}", "b".repeat(80))), )); } - if n % 10 == 0 && n > 0 { + if n.is_multiple_of(10) && n > 0 { facts.push((":p/ref".to_string(), Val::Ref((h >> 30) % n))); } facts @@ -264,7 +279,9 @@ impl Reference { let mut rows: Vec = content(self.seed, n) .into_iter() .enumerate() - .filter(|(slot, _)| !self.is_flipped(n, *slot as u8)) + .filter(|(slot, _)| { + !self.is_flipped(n, u8::try_from(*slot).expect("fixture value fits in u8")) + }) .map(|(_, (a, v))| format!("k{a} {}", v.render())) .collect(); rows.sort(); @@ -302,12 +319,15 @@ impl Reference { /// `[entity value]` rows of attribute `:p/shard{k}`, sorted. fn shard_rows(&self, k: u64) -> Vec { let mut rows: Vec = (k..self.next_entity) - .step_by(SHARDS as usize) + .step_by(usize::try_from(SHARDS).expect("fixture value fits in usize")) .flat_map(|n| { - [(2, n as i64), (3, -(n as i64) - 1)] - .into_iter() - .filter(move |(slot, _)| !self.is_flipped(n, *slot)) - .map(move |(_, v)| format!(":e{n} i{v}")) + [ + (2, i64::try_from(n).expect("fixture value fits in i64")), + (3, -i64::try_from(n).expect("fixture value fits in i64") - 1), + ] + .into_iter() + .filter(move |(slot, _)| !self.is_flipped(n, *slot)) + .map(move |(_, v)| format!(":e{n} i{v}")) }) .collect(); rows.sort(); @@ -381,7 +401,10 @@ impl Config { "MINIGRAF_SOAK_SEED", std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) - .map_or(0, |d| d.as_nanos() as u64), + .map_or(0, |d| { + u64::try_from(d.as_nanos() & u128::from(u64::MAX)) + .expect("low seed bits fit in u64") + }), ); let minute = 60_000; Config { @@ -434,7 +457,10 @@ fn percentile(sorted: &[u64], p: f64) -> u64 { if sorted.is_empty() { return 0; } - sorted[((sorted.len() - 1) as f64 * p).round() as usize] + sorted[((sorted.len() - 1) as f64 * p) + .round() + .to_usize() + .expect("percentile index fits in usize")] } /// `(VmRSS, VmHWM)` in bytes; `None` where `/proc` is not available. @@ -542,7 +568,7 @@ impl Soak { if self.cfg.step_clock { self.steps } else { - self.start.elapsed().as_millis() as u64 + u64::try_from(self.start.elapsed().as_millis()).expect("fixture value fits in u64") } } @@ -665,7 +691,7 @@ impl Soak { } self.metrics .checkpoint_ms - .push(t.elapsed().as_millis() as u64); + .push(u64::try_from(t.elapsed().as_millis()).expect("fixture value fits in u64")); self.metrics.checkpoints += 1; self.since_checkpoint = 0; self.checkpoint_due = self @@ -708,19 +734,21 @@ impl Soak { } fn flip_ordinary(&mut self) { - let k = self.rng.log_uniform(1, 50) as usize; + let k = usize::try_from(self.rng.log_uniform(1, 50)).expect("fixture value fits in usize"); let reassert = !self.rf.flipped.is_empty() && (self.rf.flipped.len() >= FLIP_CAP || self.rng.chance(0.5)); let mut chosen: HashSet<(u64, u8)> = HashSet::new(); if reassert { for _ in 0..k { - let i = self.rng.below(self.rf.flipped.len() as u64) as usize; + let i = usize::try_from(self.rng.below(self.rf.flipped.len() as u64)) + .expect("fixture value fits in usize"); chosen.insert(self.rf.flipped[i]); } } else { for _ in 0..k * 2 { let n = self.rng.below(self.rf.next_entity); - let slot = self.rng.below(content(self.cfg.seed, n).len() as u64) as u8; + let slot = u8::try_from(self.rng.below(content(self.cfg.seed, n).len() as u64)) + .expect("fixture value fits in u8"); if !self.rf.is_flipped(n, slot) { chosen.insert((n, slot)); } @@ -758,11 +786,13 @@ impl Soak { fn churn_hot(&mut self) { let live = self.rf.live_hot(); let assert = live == 0 || (live < (HOT * HOT_SLOTS) as u64 && self.rng.chance(0.5)); - let k = self.rng.range(1, 8) as usize; + let k = usize::try_from(self.rng.range(1, 8)).expect("fixture value fits in usize"); let mut chosen: Vec<(usize, usize)> = Vec::new(); for _ in 0..k * 4 { - let h = self.rng.below(HOT as u64) as usize; - let s = self.rng.below(HOT_SLOTS as u64) as usize; + let h = + usize::try_from(self.rng.below(HOT as u64)).expect("fixture value fits in usize"); + let s = usize::try_from(self.rng.below(HOT_SLOTS as u64)) + .expect("fixture value fits in usize"); if self.rf.hot_live[h][s] != assert && !chosen.contains(&(h, s)) { chosen.push((h, s)); } @@ -796,7 +826,7 @@ impl Soak { ) -> Vec { let t = Instant::now(); let result = self.db().execute(query); - let us = t.elapsed().as_micros() as u64; + let us = u64::try_from(t.elapsed().as_micros()).expect("fixture value fits in u64"); self.metrics.latency.entry(path).or_default().push(us); match result { Ok(QueryResult::QueryResults { results, .. }) => { @@ -881,7 +911,7 @@ impl Soak { fn check_shard(&mut self, k: u64) { let names: HashMap = (k..self.rf.next_entity) - .step_by(SHARDS as usize) + .step_by(usize::try_from(SHARDS).expect("fixture value fits in usize")) .map(|n| (entity_uuid(&format!(":e{n}")), format!(":e{n}"))) .collect(); let got = self.rows( @@ -945,7 +975,8 @@ impl Soak { self.check_hot(h, None); } for _ in 0..self.cfg.sample_as_of { - let h = self.read_rng.below(HOT as u64) as usize; + let h = usize::try_from(self.read_rng.below(HOT as u64)) + .expect("fixture value fits in usize"); for _ in 0..3 { let t = self.read_rng.range(1, self.rf.tx.max(1)); self.check_hot(h, Some(t)); @@ -963,7 +994,7 @@ impl Soak { } let t = Instant::now(); self.db = Some(open(&self.path)); - let ms = t.elapsed().as_millis() as u64; + let ms = u64::try_from(t.elapsed().as_millis()).expect("fixture value fits in u64"); self.metrics.reopens += 1; if after_checkpoint { self.metrics.open_ms_file = Some(ms); diff --git a/tests/statement_order_test.rs b/tests/statement_order_test.rs index 76ca5dacd8..ac732f0561 100644 --- a/tests/statement_order_test.rs +++ b/tests/statement_order_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Several writes to one `(e, a, v)` in one `WriteTransaction` (#477). //! //! The last statement that writes a triple decides it, in any mix of diff --git a/tests/temporal_metadata_test.rs b/tests/temporal_metadata_test.rs index efa4880fa0..d5d016b692 100644 --- a/tests/temporal_metadata_test.rs +++ b/tests/temporal_metadata_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Phase 7.6 integration tests — temporal metadata pseudo-attribute bindings. use minigraf::{Minigraf, OpenOptions, QueryResult, Value}; diff --git a/tests/udf_reentry_test.rs b/tests/udf_reentry_test.rs index 9ef807fe62..e6c56a295a 100644 --- a/tests/udf_reentry_test.rs +++ b/tests/udf_reentry_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] // File-backed (Minigraf::open, tempfile): native only, like the other file tests. #![cfg(not(target_arch = "wasm32"))] //! A query reads its functions from a snapshot of the registry taken when it diff --git a/tests/udf_test.rs b/tests/udf_test.rs index 46ec51be8c..225b7df1fa 100644 --- a/tests/udf_test.rs +++ b/tests/udf_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Integration tests for Phase 7.7b — User-Defined Functions (UDFs). //! //! Testing conventions: no `{:?}` of Result/Value/Fact in assert messages. diff --git a/tests/valid_time_window_test.rs b/tests/valid_time_window_test.rs index 875c85d13b..0477b32a7a 100644 --- a/tests/valid_time_window_test.rs +++ b/tests/valid_time_window_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! One current valid-time window per `(e, a, v)` (#435). //! //! At transaction time N a triple has exactly one current window: the one of diff --git a/tests/wal_test.rs b/tests/wal_test.rs index a6a8db509f..31ee5cdbe0 100644 --- a/tests/wal_test.rs +++ b/tests/wal_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! Integration tests for WAL-backed crash safety, recovery, and checkpoint. //! //! These tests exercise the file-backed `Minigraf` API end-to-end, verifying: diff --git a/tests/window_functions_test.rs b/tests/window_functions_test.rs index 3bf7b8a4f8..af1edc5ff4 100644 --- a/tests/window_functions_test.rs +++ b/tests/window_functions_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] use minigraf::db::Minigraf; use minigraf::{QueryResult, Value}; @@ -563,8 +564,7 @@ fn window_in_aggregate_query_reading_a_non_grouping_variable_is_rejected() { :where [?e :employee/dept ?dept] [?e :employee/salary ?salary]])"#, ) - .err() - .expect("rejected"); + .expect_err("rejected"); assert_eq!(err.code(), "PRS-082"); let err = db .execute( @@ -572,8 +572,7 @@ fn window_in_aggregate_query_reading_a_non_grouping_variable_is_rejected() { :where [?e :employee/dept ?dept] [?e :employee/salary ?salary]])"#, ) - .err() - .expect("lag on non-grouping variable rejected"); + .expect_err("lag on non-grouping variable rejected"); assert_eq!(err.code(), "PRS-082"); } diff --git a/tests/write_tx_guard_test.rs b/tests/write_tx_guard_test.rs index 9d05594df3..b10559addb 100644 --- a/tests/write_tx_guard_test.rs +++ b/tests/write_tx_guard_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] // File-backed (Minigraf::open, tempfile): native only, like the other file tests. #![cfg(not(target_arch = "wasm32"))] //! A database call on a thread that holds a `WriteTransaction` returns diff --git a/tests/xtdb_compat_test.rs b/tests/xtdb_compat_test.rs index ac2eeeac64..dd63190760 100644 --- a/tests/xtdb_compat_test.rs +++ b/tests/xtdb_compat_test.rs @@ -1,3 +1,4 @@ +#![cfg(test)] //! XTDB compatibility tests (#221). //! //! License: XTDB is Apache 2.0. These tests are semantic ports of query From f50807ee5079875babf2d5292b31fa7aad79d248 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 14 Nov 2026 13:52:32 +0530 Subject: [PATCH 2/2] chore(lint): fix lints flagged by the current stable clippy CI's stable clippy is newer than the toolchain the cleanup was checked with and flags constant-size chunks_exact (as_chunks instead) and a reversed sort_by comparator (sort_by_key with Reverse). Same iteration and order. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01H2a7QjCHpikfsg5qwAV1p9 --- benches/minigraf_bench/storage_v3.rs | 4 +++- benches/simd_helpers.rs | 21 ++++++++++----------- src/graph/storage.rs | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/benches/minigraf_bench/storage_v3.rs b/benches/minigraf_bench/storage_v3.rs index b53691edfb..8934a9f36c 100644 --- a/benches/minigraf_bench/storage_v3.rs +++ b/benches/minigraf_bench/storage_v3.rs @@ -127,7 +127,9 @@ fn check_golden(db: &Minigraf) { /// the golden/integrity tests; no checksum is recomputed on the damaged page. fn newest_meta(bytes: &[u8]) -> &[u8] { bytes - .chunks_exact(4096) + .as_chunks::<4096>() + .0 + .iter() .take(2) .filter(|page| &page[..4] == b"MGRF" && &page[8..12] == b"META") .max_by_key(|page| u64::from_le_bytes(page[16..24].try_into().unwrap())) diff --git a/benches/simd_helpers.rs b/benches/simd_helpers.rs index 7008aeca89..7100f68d8d 100644 --- a/benches/simd_helpers.rs +++ b/benches/simd_helpers.rs @@ -26,13 +26,14 @@ pub fn valid_time_filter_simd(valid_from: &[i64], valid_to: &[i64], ts: i64) -> let ts_v = i64x4::splat(ts); let mut count = 0usize; - for (vf_chunk, vt_chunk) in valid_from.chunks_exact(4).zip(valid_to.chunks_exact(4)) { - let [vf0, vf1, vf2, vf3] = *vf_chunk else { - unreachable!() - }; - let [vt0, vt1, vt2, vt3] = *vt_chunk else { - unreachable!() - }; + for (vf_chunk, vt_chunk) in valid_from + .as_chunks::<4>() + .0 + .iter() + .zip(valid_to.as_chunks::<4>().0) + { + let [vf0, vf1, vf2, vf3] = *vf_chunk; + let [vt0, vt1, vt2, vt3] = *vt_chunk; let vf = i64x4::new([vf0, vf1, vf2, vf3]); let vt = i64x4::new([vt0, vt1, vt2, vt3]); @@ -70,8 +71,7 @@ pub fn as_of_filter_simd(tx_counts: &[u64], threshold: u64) -> usize { let thr_v = u64x4::splat(threshold); let mut count = 0usize; - for chunk in tx_counts.chunks_exact(4) { - let [a, b, c, d] = *chunk else { unreachable!() }; + for &[a, b, c, d] in tx_counts.as_chunks::<4>().0 { let v = u64x4::new([a, b, c, d]); // tc <= threshold ≡ NOT (tc > threshold) @@ -99,8 +99,7 @@ pub fn as_of_filter_simd(tx_counts: &[u64], threshold: u64) -> usize { pub fn sum_simd_i64(values: &[i64]) -> i64 { let mut acc = i64x4::splat(0_i64); - for chunk in values.chunks_exact(4) { - let [a, b, c, d] = *chunk else { unreachable!() }; + for &[a, b, c, d] in values.as_chunks::<4>().0 { acc += i64x4::new([a, b, c, d]); } diff --git a/src/graph/storage.rs b/src/graph/storage.rs index 49c898951f..94dff76b5d 100644 --- a/src/graph/storage.rs +++ b/src/graph/storage.rs @@ -1426,7 +1426,7 @@ impl FactStorage { ) -> Result> { let relevant_facts = self.get_facts_by_entity_attribute(entity_id, attribute)?; let mut net = net_asserted_facts(relevant_facts); - net.sort_by(|a, b| b.tx_count.cmp(&a.tx_count)); + net.sort_by_key(|f| std::cmp::Reverse(f.tx_count)); Ok(net.first().map(|f| f.value.clone())) }