Skip to main content

surrealdb_cnf/
lib.rs

1//! # Surrealdb Config
2//!
3//! Server-wide configuration constants, environment-variable defaults, and the
4//! [`Config`]/[`ConfigMap`] mechanism each layer uses to declare and load its
5//! own settings.
6//!
7//! <section class="warning">
8//! <h3>Unstable!</h3>
9//! This crate is <b>SurrealDB internal API</b>. It does not adhere to SemVer and its API is
10//! free to change and break code even between patch versions. If you are looking for a stable
11//! interface to the SurrealDB library please have a look at
12//! <a href="https://crates.io/crates/surrealdb">the Rust SDK</a>.
13//! </section>
14
15#[macro_use]
16extern crate tracing;
17#[macro_use]
18extern crate common;
19
20pub mod config;
21pub mod dynamic;
22
23use std::fs;
24use std::path::PathBuf;
25use std::sync::LazyLock;
26use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
27
28use common::str::ParseBytes;
29pub use config::{Config, ConfigMap, format_duration, parse_duration};
30pub use dynamic::DynamicConfiguration;
31use path_clean::PathClean;
32
33/// The publicly visible name of the server
34pub const SERVER_NAME: &str = "SurrealDB";
35
36/// The characters which are supported in server record IDs
37pub const ID_CHARS: [char; 36] = [
38	'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
39	'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
40];
41
42/// Specifies the names of parameters which can not be specified in a query
43pub const PROTECTED_PARAM_NAMES: &[&str] = &["access", "auth", "token", "session"];
44
45/// Specifies the names the system binds itself in the frame of a clause, a field, an event or a
46/// function body: the value a clause or an element filter reads (`this`, `self`, `parent`), and
47/// the values an event or a field definition reads (`value`, `input`, `before`, `after`,
48/// `event`). They are not in [`PROTECTED_PARAM_NAMES`]: that list names the values read from the
49/// session, and the planner folds, captures and scopes by it, which these names are not.
50///
51/// A name here is bound per frame, so it is the frame's to bind and a binding made outside one is
52/// shadowed by it. A client may bind any of these as a request or session variable, and a `LET`
53/// that is a whole statement of a request — which binds the same request variable by another
54/// route — may bind one too. Only a `LET` written *inside* a frame may not
55/// ([`is_refused_local_let_name`]), because the plan reads the name from the frame rather than
56/// from the `LET`.
57pub const SYSTEM_BOUND_PARAM_NAMES: &[&str] =
58	&["this", "self", "parent", "value", "input", "before", "after", "event"];
59
60/// Whether a `LET` written inside a frame — a block, a clause, a field, an event, a function body,
61/// stored code — may not bind `name`: a protected parameter name, and a name the system binds in
62/// that frame. A `LET` the planner writes to bind a system name into a frame is exempt, see
63/// [`SYSTEM_BOUND_PARAM_NAMES`].
64///
65/// This is not the question asked of a variable a client binds, or of a `LET` that is a whole
66/// statement of a request: those refuse [`PROTECTED_PARAM_NAMES`] alone.
67pub fn is_refused_local_let_name(name: &str) -> bool {
68	SYSTEM_BOUND_PARAM_NAMES.contains(&name) || PROTECTED_PARAM_NAMES.contains(&name)
69}
70
71/// Default capacity for the bounded channel used to deliver live-query
72/// notifications from the datastore to subscribers.
73pub const NOTIFICATIONS_CHANNEL_SIZE: usize = 15_000;
74
75/// Parse an allowlist configuration string into a list of paths.
76///
77/// The string is split on the platform path delimiter (`:` on Unix, `;` on
78/// Windows), each entry is cleaned, and (when `canonicalize` is set) resolved
79/// to its canonical form; entries that fail to canonicalize are dropped with a
80/// warning. `subject` names the allowlist for log messages (e.g. `"file"`).
81/// Enforcement of a resolved path against the allowlist lives in
82/// `surrealdb_idx::file::check_is_path_allowed`.
83pub fn extract_allowed_paths(input: &str, canonicalize: bool, subject: &str) -> Vec<PathBuf> {
84	let delimiter = if cfg!(target_os = "windows") {
85		";"
86	} else {
87		":"
88	};
89	// Split the allowlist string, canonicalize each path, and collect valid paths.
90	input
91		.split(delimiter)
92		.filter_map(|s| {
93			if s.trim().is_empty() {
94				None
95			} else {
96				let path = PathBuf::from(s).clean();
97				let path = if canonicalize {
98					let Ok(path) = fs::canonicalize(&path) else {
99						warn!("Failed to canonicalize {subject} path: {}", path.to_string_lossy());
100						return None;
101					};
102
103					path
104				} else {
105					path
106				};
107
108				debug!("Allowed {subject} path: {}", path.to_string_lossy());
109				Some(path)
110			}
111		})
112		.collect()
113}
114
115//FIXME: These configuration values should be removed.
116// We advertise that we are embeddable, but configuring solely through environment variables is not
117// acceptable for an embeddable database.
118// Currently these cannot be removed without a major restructure.
119
120// Used in the memory allocator global, so hard to remove.
121
122/// The tracked-memory ceiling, in bytes, above which queries are refused
123/// (`SURREAL_MEMORY_THRESHOLD`). `0` — the default — disables the guard
124/// entirely; any other value is floored to 1 MiB.
125///
126/// # What the threshold is compared against
127///
128/// The guard compares this value against *tracked* bytes, not process RSS: for
129/// each live Rust-heap allocation the size class the allocator reserved for it,
130/// plus every registered external memory reporter (memory held outside Rust's
131/// global allocator). Tracked bytes are a lower bound on the process's real footprint. Not
132/// counted, and therefore requiring headroom below a container memory limit:
133///
134/// - allocator arena metadata, slab-level fragmentation, and pages the allocator retains rather
135///   than returning to the operating system
136/// - storage-engine memory outside the registered reporters, such as compaction and flush buffers
137///   and an open transaction's pending writes
138/// - WebAssembly linear memory, which is mapped rather than heap-allocated (bound it with
139///   `SURREAL_SURREALISM_MAX_MEMORY`)
140/// - thread stacks and the binary's own text
141///
142/// Because the heap term is the reserved size class rather than the requested
143/// size, it exceeds the sum of the requests — by more, proportionally, the
144/// smaller the allocations are. A value carried over from a release that
145/// compared requested bytes therefore refuses queries at a lighter workload
146/// than it used to, and wants raising to match.
147///
148/// Set this *below* the container's memory limit so the guard sheds load before
149/// the kernel's OOM killer intervenes, and *above* the combined capacity of any
150/// registered external reporter that holds memory indefinitely (such as a warm
151/// block cache): a threshold at or below that size refuses every query once the
152/// cache fills and does not recover without a restart.
153///
154/// # When the guard is inert
155///
156/// Enforcement needs the `allocation-tracking` feature, which the server
157/// enables by default. A build without it reports no tracked memory and never
158/// refuses a query, whatever this is set to.
159///
160/// # Lifetime
161///
162/// Read once, on first use. Changing the environment variable takes effect only
163/// in a fresh process.
164pub static MEMORY_THRESHOLD: LazyLock<usize> = LazyLock::new(|| {
165	let raw = match std::env::var("SURREAL_MEMORY_THRESHOLD") {
166		Ok(raw) => raw,
167		// Absent is the documented default: the guard is off.
168		Err(std::env::VarError::NotPresent) => return 0,
169		// Set to something that is not UTF-8. Reported rather than treated as
170		// absent, because the operator did configure it and it will not apply.
171		Err(std::env::VarError::NotUnicode(_)) => {
172			warn!(
173				"Ignoring SURREAL_MEMORY_THRESHOLD: the value is not valid UTF-8. The memory \
174				 threshold is DISABLED: queries will not be refused on memory pressure."
175			);
176			return 0;
177		}
178	};
179	// An empty value is how a deployment spells "leave this unset", so it takes
180	// the default without being reported as a mistake.
181	if raw.trim().is_empty() {
182		return 0;
183	}
184	match parse_memory_threshold(&raw) {
185		Some(v) => v,
186		None => {
187			warn!(
188				"Ignoring invalid SURREAL_MEMORY_THRESHOLD value `{raw}`; expected a byte count \
189				 with an optional k/kb/kib/m/mb/mib/g/gb/gib suffix (Kubernetes-style `Gi`/`Mi` \
190				 quantities are not accepted). The memory threshold is DISABLED: queries will \
191				 not be refused on memory pressure."
192			);
193			0
194		}
195	}
196});
197
198/// Parse a `SURREAL_MEMORY_THRESHOLD` value into a byte count. Accepts a plain
199/// byte count or a human-readable size suffix (`b`, `k`/`kb`/`kib`,
200/// `m`/`mb`/`mib`, `g`/`gb`/`gib`, case-insensitive; all multipliers are
201/// binary). Returns `None` for unparseable values — note that
202/// Kubernetes-style `Gi`/`Mi` suffixes are *not* accepted, so a resource
203/// quantity cannot be passed through verbatim. Returns `Some(0)` for `"0"`
204/// (disables the threshold); otherwise `Some(n)` floored to 1 MiB.
205fn parse_memory_threshold(value: &str) -> Option<usize> {
206	value.parse_bytes::<usize>().ok().map(|x| match x {
207		0 => 0,
208		x => x.max(1024 * 1024),
209	})
210}
211
212/// `SURREAL_HNSW_BUILD_SEED`, read once at first use. A value that is set but not
213/// a valid `u64` is reported via `tracing::warn!` and ignored, rather than
214/// silently falling back to entropy — a typo'd seed would otherwise look like a
215/// pinned build while producing a different graph on every run.
216static HNSW_BUILD_SEED_ENV: LazyLock<Option<u64>> =
217	LazyLock::new(|| match std::env::var("SURREAL_HNSW_BUILD_SEED") {
218		Ok(v) => match v.parse::<u64>() {
219			Ok(seed) => Some(seed),
220			Err(_) => {
221				warn!("Ignoring invalid SURREAL_HNSW_BUILD_SEED value `{v}`; expected a u64");
222				None
223			}
224		},
225		Err(_) => None,
226	});
227
228/// In-process fallback seed, installed by [`set_default_hnsw_build_seed`]. Read
229/// only when [`HNSW_BUILD_SEED_ENV`] is absent.
230static HNSW_BUILD_SEED_DEFAULT: AtomicU64 = AtomicU64::new(0);
231
232/// Whether [`HNSW_BUILD_SEED_DEFAULT`] holds an installed seed. Separate from the
233/// seed itself so every `u64` remains a usable seed value.
234static HNSW_BUILD_SEED_DEFAULT_SET: AtomicBool = AtomicBool::new(false);
235
236/// The seed for the HNSW level-assignment RNG, or `None` to seed from entropy.
237///
238/// Resolution order, highest priority first:
239///
240/// 1. `SURREAL_HNSW_BUILD_SEED=<u64>`.
241/// 2. An in-process default installed by [`set_default_hnsw_build_seed`].
242/// 3. Neither: entropy, so every index build produces a different graph.
243///
244/// A fixed seed builds a *deterministic* graph — its structure then depends only
245/// on insertion order and the vectors — which makes HNSW build and search
246/// benchmarks reproducible across runs. Without one, graph-construction variance
247/// alone moves an HNSW search benchmark by far more than any regression worth
248/// catching, so a fixed seed is a prerequisite for a clean before/after
249/// comparison. The seed only affects graph construction, never search behaviour,
250/// results, or recall.
251pub fn hnsw_build_seed() -> Option<u64> {
252	if let Some(seed) = *HNSW_BUILD_SEED_ENV {
253		return Some(seed);
254	}
255	// `Acquire` pairs with the `Release` store in the setter, so the seed written
256	// before the flag is visible to any thread that observes the flag.
257	HNSW_BUILD_SEED_DEFAULT_SET
258		.load(Ordering::Acquire)
259		.then(|| HNSW_BUILD_SEED_DEFAULT.load(Ordering::Relaxed))
260}
261
262/// Install the process-wide fallback HNSW build seed used when
263/// `SURREAL_HNSW_BUILD_SEED` is unset, so a caller that wants reproducible graphs
264/// gets them without depending on its launcher exporting the variable. The
265/// environment variable still wins, which is what lets a single run be re-seeded
266/// from outside the process.
267///
268/// Only takes effect for indexes built after the call, and only affects graph
269/// construction. BENCHMARK AND TEST USE ONLY — the benchmark harness calls this
270/// at startup; a server has no reason to pin the seed.
271pub fn set_default_hnsw_build_seed(seed: u64) {
272	HNSW_BUILD_SEED_DEFAULT.store(seed, Ordering::Relaxed);
273	HNSW_BUILD_SEED_DEFAULT_SET.store(true, Ordering::Release);
274}
275
276/// Optional fixed seed for the deterministic data-generation RNG (see
277/// `surrealdb_expr::val::rnd`).
278///
279/// Unset (the default) leaves `rand::*` and generated record ids drawing from
280/// the per-thread RNG, exactly as in production. Set `SURREAL_RAND_SEED=<u64>`
281/// to route them through a single seeded RNG so benchmark datasets are identical
282/// across runs. TEST AND BENCHMARK USE ONLY — never set it on a shared or
283/// multi-tenant deployment, where it makes record ids and `rand::*` values
284/// predictable process-wide.
285///
286/// Read once at first use, like the other knobs here. A value that is set but
287/// not a valid `u64` is reported via `tracing::warn!` and ignored, rather than
288/// silently falling back to the default.
289pub static RAND_SEED: LazyLock<Option<u64>> =
290	LazyLock::new(|| match std::env::var("SURREAL_RAND_SEED") {
291		Ok(v) => match v.parse::<u64>() {
292			Ok(seed) => Some(seed),
293			Err(_) => {
294				warn!("Ignoring invalid SURREAL_RAND_SEED value `{v}`; expected a u64");
295				None
296			}
297		},
298		Err(_) => None,
299	});
300
301/// Initial (and minimum) window size for the DiskANN filtered-KNN record
302/// prefetch. The committed-graph search prefetches candidate records in
303/// distance-ascending windows that grow geometrically (doubling, capped by
304/// [`DISKANN_FILTER_PREFETCH_MAX_CHUNK`]); this is the first window's size and
305/// the floor. A smaller value bounds the over-fetch tighter when the result
306/// builder fills early (non-selective filters); a larger value amortises each
307/// window's multi-get over more candidates. Read once at first use.
308pub static DISKANN_FILTER_PREFETCH_MIN_CHUNK: LazyLock<usize> = LazyLock::new(|| {
309	std::env::var("SURREAL_DISKANN_FILTER_PREFETCH_MIN_CHUNK")
310		.ok()
311		.and_then(|s| s.parse::<usize>().ok())
312		.filter(|n| *n > 0)
313		.unwrap_or(64)
314});
315
316/// Upper bound on the DiskANN filtered-KNN record-prefetch window (the geometric
317/// growth is capped here). Read once at first use.
318pub static DISKANN_FILTER_PREFETCH_MAX_CHUNK: LazyLock<usize> = LazyLock::new(|| {
319	std::env::var("SURREAL_DISKANN_FILTER_PREFETCH_MAX_CHUNK")
320		.ok()
321		.and_then(|s| s.parse::<usize>().ok())
322		.filter(|n| *n > 0)
323		.unwrap_or(4096)
324});
325
326// Used in a lot of surrealql functions which randomly access this limit as well as casting
327// functions Both of which cannot be changed without massive restructuring.
328
329/// Used to limit allocation for builtin functions. Default: 2^20 (1 MiB),
330/// can be as large as 28 (2^28, 256 MiB)
331pub static GENERATION_ALLOCATION_LIMIT: LazyLock<usize> = LazyLock::new(|| {
332	let n = std::env::var("SURREAL_GENERATION_ALLOCATION_LIMIT")
333		.map(|s| s.parse::<u32>().unwrap_or(20))
334		.unwrap_or(20);
335	2usize.pow(n.min(28))
336});
337
338// Used in a lot of surrealql functions which randomly access this limit.
339// Which cannot be changed without massive restructuring the planner.
340
341/// The maximum input string length for similarity/distance functions (default:
342/// 16384 bytes)
343pub static STRING_SIMILARITY_LIMIT: LazyLock<usize> =
344	lazy_env_parse!("SURREAL_STRING_SIMILARITY_LIMIT", usize, 16384);
345
346// Used in global regex cache, we would first need to make that cache non-global.
347
348/// The maximum size of a compiled regular expression (default: 10 MiB)
349pub static REGEX_SIZE_LIMIT: LazyLock<usize> =
350	lazy_env_parse!("SURREAL_REGEX_SIZE_LIMIT", usize, 10 * 1024 * 1024);
351
352/// Specifies the number of computed regexes which can be cached in the engine
353/// (default: 1000)
354pub static REGEX_CACHE_SIZE: LazyLock<usize> =
355	lazy_env_parse!("SURREAL_REGEX_CACHE_SIZE", usize, 1_000);
356
357/// Drained-entry budget for one range branch of a bitmap candidate plan
358/// (default: 250000). A non-anchor range branch that drains more index
359/// entries than this is abandoned — its predicate is instead enforced by the
360/// residual WHERE filter — so an unselective range cannot make the bitmap
361/// plan slower than the streaming plan it replaced. `0` disables the budget.
362pub static BITMAP_BRANCH_BUDGET: LazyLock<usize> =
363	lazy_env_parse!("SURREAL_BITMAP_BRANCH_BUDGET", usize, 250_000);
364
365/// Master switch for pre-filtered vector search (#548, default: true).
366/// When `false`, KNN queries keep evaluating their WHERE residual inside the
367/// ANN traversal via per-candidate record fetches, exactly as before the
368/// allow-list bitmap prefilter existed.
369pub static KNN_PREFILTER_ENABLED: LazyLock<bool> =
370	lazy_env_parse!("SURREAL_KNN_PREFILTER_ENABLED", bool, true);
371
372/// Allow-list size at or below which a pre-filtered KNN search skips the
373/// graph entirely and scores the members exactly (default: 2000). Below this
374/// cardinality a bounded fetch-and-score over the bitmap is cheaper than a
375/// graph traversal and — unlike filtered ANN search under a highly selective
376/// filter — guaranteed to find the true top-K. Above it, an HNSW search that
377/// can score the members from the vectors the index stores still takes the
378/// exact tier wherever [`KNN_PREFILTER_EXACT_COST`] estimates it cheaper than
379/// the gated traversal.
380pub static KNN_PREFILTER_EXACT_THRESHOLD: LazyLock<u64> =
381	lazy_env_parse!("SURREAL_KNN_PREFILTER_EXACT_THRESHOLD", u64, 2_000);
382
383/// The cost of scoring one allow-list member exactly from the vectors an HNSW
384/// index stores, in distance computations of the gated graph traversal
385/// (default: 5). The traversal admits about one candidate in `1 / s` for an
386/// allow-list holding a share `s = members / nodes` of the graph's nodes, so
387/// it computes about `ef × degree / s` distances, while the exact tier scores
388/// every member; the exact tier is taken wherever `members × cost` is at most
389/// that, which is `members² × cost ≤ ef × degree × nodes` (with `s` capped at
390/// one). A larger cost keeps more searches on the graph.
391pub static KNN_PREFILTER_EXACT_COST: LazyLock<u32> =
392	lazy_env_parse!("SURREAL_KNN_PREFILTER_EXACT_COST", u32, 5);
393
394/// Allow-list size above which the gated ANN traversal stops boosting `ef`
395/// (default: 100000). Large allow-lists barely reject candidates on typical
396/// tables, so widening the search buys no recall; admission stays gated on
397/// bitmap membership at every size — an absolute cardinality says nothing
398/// about how near-universe the predicate really is, and an unrestricted
399/// search with a post-check would truncate results whenever the nearest
400/// overall neighbours are excluded.
401pub static KNN_PREFILTER_EF_BOOST_THRESHOLD: LazyLock<u64> =
402	lazy_env_parse!("SURREAL_KNN_PREFILTER_EF_BOOST_THRESHOLD", u64, 100_000);
403
404/// `ef` multiplier for an allow-list-gated DiskANN search (default: 4). With
405/// an allow-list alone, DiskANN searches its top `l` candidates and admits the
406/// members among them, so a selective allow-list leaves few admissible ones in
407/// that list; widening the search counteracts the loss. Applied as
408/// `max(ef, ef * boost)` capped by [`KNN_PREFILTER_EF_MAX`]. An HNSW search is
409/// widened by [`KNN_PREFILTER_HNSW_EF_BOOST`] instead.
410pub static KNN_PREFILTER_EF_BOOST: LazyLock<u32> =
411	lazy_env_parse!("SURREAL_KNN_PREFILTER_EF_BOOST", u32, 4);
412
413/// `ef` multiplier for an allow-list-gated HNSW traversal (default: 1, no
414/// widening). The gated traversal walks on past the candidates the allow-list
415/// rejects, so its recall at the requested `ef` holds up without widening. A
416/// wider search costs time in proportion and buys little recall, and none
417/// where the filter is selective enough that the traversal ends before it
418/// holds `ef` admitted candidates, since that end does not depend on `ef`;
419/// the exact tier serves such filters. Applied as `max(ef, ef * boost)`
420/// capped by [`KNN_PREFILTER_EF_MAX`].
421pub static KNN_PREFILTER_HNSW_EF_BOOST: LazyLock<u32> =
422	lazy_env_parse!("SURREAL_KNN_PREFILTER_HNSW_EF_BOOST", u32, 1);
423
424/// Ceiling for the boosted `ef` of an allow-list-gated ANN traversal
425/// (default: 1024). Never clamps below the user-requested `ef`.
426pub static KNN_PREFILTER_EF_MAX: LazyLock<u32> =
427	lazy_env_parse!("SURREAL_KNN_PREFILTER_EF_MAX", u32, 1_024);
428
429// A limit belongs on the owning layer's config struct rather than in a static
430// here whenever its readers already hold a configuration in hand: that keeps it
431// per-datastore and settable programmatically, not only through an env var. The
432// statics above are the cases where no such handle reaches the reader.
433
434#[cfg(test)]
435mod tests {
436	use super::*;
437
438	/// `SURREAL_MEMORY_THRESHOLD` must accept human-readable byte suffixes
439	/// (regression for #6860, which dropped suffix parsing and silently
440	/// disabled the guard for values like `1792mb`).
441	#[test]
442	fn memory_threshold_parses_byte_suffixes() {
443		// Human-readable suffix is honoured (the regressed case).
444		assert_eq!(parse_memory_threshold("1792mb"), Some(1792 * 1024 * 1024));
445		assert_eq!(parse_memory_threshold("1g"), Some(1024 * 1024 * 1024));
446		// A plain byte count still works.
447		assert_eq!(parse_memory_threshold("1879048192"), Some(1792 * 1024 * 1024));
448		// `0` disables the threshold.
449		assert_eq!(parse_memory_threshold("0"), Some(0));
450		// Any non-zero value is floored to at least 1 MiB.
451		assert_eq!(parse_memory_threshold("10"), Some(1024 * 1024));
452		// An unparseable value returns None; callers map that to disabled (0).
453		assert_eq!(parse_memory_threshold("garbage"), None);
454	}
455
456	/// Kubernetes resource quantities are not accepted. A deployment that
457	/// templates a container memory limit straight into the environment
458	/// variable disables the guard rather than setting it, so these forms must
459	/// keep returning `None` and be reported to the operator.
460	#[test]
461	fn memory_threshold_rejects_kubernetes_quantities() {
462		// Binary IEC suffixes as Kubernetes spells them.
463		assert_eq!(parse_memory_threshold("8Gi"), None);
464		assert_eq!(parse_memory_threshold("8192Mi"), None);
465		// Decimal fractions and percentages are not a supported spelling.
466		assert_eq!(parse_memory_threshold("1.5g"), None);
467		assert_eq!(parse_memory_threshold("85%"), None);
468		// Terabyte suffixes are outside the accepted set.
469		assert_eq!(parse_memory_threshold("1tb"), None);
470	}
471
472	/// The in-process HNSW seed default is off until installed, then answers every
473	/// later resolution. This is the only test that touches that process-global
474	/// state, so it can assert the uninstalled state without synchronising.
475	#[test]
476	fn hnsw_build_seed_honours_installed_default() {
477		// `SURREAL_HNSW_BUILD_SEED` outranks the default by design, so with it set
478		// there is nothing here for the default to answer.
479		if std::env::var_os("SURREAL_HNSW_BUILD_SEED").is_some() {
480			return;
481		}
482
483		assert_eq!(hnsw_build_seed(), None, "no seed until one is installed");
484
485		set_default_hnsw_build_seed(0);
486		assert_eq!(hnsw_build_seed(), Some(0), "zero is a seed, not 'unset'");
487
488		set_default_hnsw_build_seed(u64::MAX);
489		assert_eq!(hnsw_build_seed(), Some(u64::MAX), "a later install replaces the default");
490	}
491
492	/// `extract_allowed_paths` must preserve leading and trailing spaces in
493	/// directory names while ignoring empty or whitespace-only segments.
494	#[test]
495	fn extract_allowed_paths_preserves_significant_whitespace() {
496		let delim = if cfg!(target_os = "windows") {
497			";"
498		} else {
499			":"
500		};
501		let input = format!("/tmp/ leading{delim}  {delim}/tmp/trailing {delim}");
502		let paths = extract_allowed_paths(&input, false, "bucket");
503		assert_eq!(paths, vec![PathBuf::from("/tmp/ leading"), PathBuf::from("/tmp/trailing ")]);
504	}
505}