metrale_bench/gate/
hermetic.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! 2026-09-26: The serve keys `met serve --hermetic` closes, as one table that the
4//! bench and server crates both read.
5//!
6//! Owner: bench gate.
7//! Invariants: none beyond the types.
8//!
9//! `metrale-server`'s `cli::hermetic` re-exports `CLOSED_KEYS` and expands a requested
10//! `hermetic=true` into these keys. `gate::bench` refuses a BENCH.toml entry that pins
11//! `hermetic=true` without them, because `scoring::check_record` also fails a record
12//! whose serve overrides hold a key the baseline does not pin.
13
14/// 2026-09-26: The serve keys `--hermetic` forces, and the values it forces them to.
15pub const CLOSED_KEYS: &[(&str, &str)] =
16    &[("enable_prefix_caching", "false"), ("mtp_gate", "force")];
17
18/// 2026-09-26: Whether this override map requests the hermetic regime: only the exact
19/// string `"true"` does. Any other value, including `"TRUE"` and `"1"`, reads as not
20/// requested.
21pub fn is_requested(overrides: &std::collections::BTreeMap<String, String>) -> bool {
22    overrides.get("hermetic").map(String::as_str) == Some("true")
23}
24
25/// 2026-09-26: The `CLOSED_KEYS` entries that `overrides` lacks or holds at another
26/// value. Empty means every closed key is pinned at its closed value.
27pub fn missing_pins(
28    overrides: &std::collections::BTreeMap<String, String>,
29) -> Vec<(&'static str, &'static str)> {
30    CLOSED_KEYS
31        .iter()
32        .filter(|(k, v)| overrides.get(*k).map(String::as_str) != Some(*v))
33        .map(|(k, v)| (*k, *v))
34        .collect()
35}
36
37#[cfg(test)]
38#[path = "hermetic_tests.rs"]
39mod hermetic_tests;