From 5f38ac74beb67f9a2a9f958473db4b1b40de9642 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 10 Oct 2026 19:19:14 +0200 Subject: [PATCH] mind-body forge probe: a root from the environment, and the test seam in the library build Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/control.rs | 13 ++++++++ crates/mind-body/tests/forge.rs | 59 ++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/crates/mind-body/src/control.rs b/crates/mind-body/src/control.rs index 77c4a5b..0febc8e 100644 --- a/crates/mind-body/src/control.rs +++ b/crates/mind-body/src/control.rs @@ -263,6 +263,19 @@ pub fn load_state(source: &impl ControlSource) -> Result { /// let _ = mind_body::control::Grant::for_test; /// ``` /// +/// ```compile_fail +/// // the test seam that moves the root is not in the library build, public or not +/// use mind_body::control::with_root; +/// ``` +/// +/// ```compile_fail +/// use mind_body::control::TEST_ROOT; +/// ``` +/// +/// ```compile_fail +/// use mind_body::control::control_root; +/// ``` +/// /// The same preamble with the real call compiles: /// /// ``` diff --git a/crates/mind-body/tests/forge.rs b/crates/mind-body/tests/forge.rs index ba7f92b..d2ff7d4 100644 --- a/crates/mind-body/tests/forge.rs +++ b/crates/mind-body/tests/forge.rs @@ -1,7 +1,8 @@ //! The brake-grant rule seen from outside the crate: the only reader takes the //! instance, so whatever a caller builds elsewhere (a store in a temporary //! directory, a symlink to another instance's directory, a copy of another -//! instance's store, the relative root `.`) is never what a Grant is made from. +//! instance's store, the relative root `.`, a tree that every environment +//! variable points at) is never what a Grant is made from. //! The signature half of the rule (no root argument, no source reader, no //! struct literal, no test constructor) is the `compile_fail` examples on //! `read_effective`; this is the behavioural half, committed because it is the @@ -63,4 +64,60 @@ fn no_forged_store_yields_a_grant() { let relative = reads(FORGED); std::env::set_current_dir(before).unwrap(); assert!(matches!(relative, Effective::Held { .. }), "relative root"); + + // A root named by the environment. The forged tree is laid out for a value + // used as the root itself and for one with `minds` joined on, and every + // variable the process has, with the names an implementation would likely + // read, is pointed at it. A variable of a name neither list holds is not + // reached; the library build having no `std::env` reader is the rest of it. + let environed = tempfile::tempdir().unwrap(); + release(environed.path(), FORGED); + std::fs::create_dir_all(environed.path().join("minds")).unwrap(); + release(&environed.path().join("minds"), FORGED); + let value = environed.path().as_os_str().to_owned(); + let mut names: Vec = std::env::vars_os().map(|(name, _)| name).collect(); + names.extend(GUESSED_ROOT_VARIABLES.iter().map(Into::into)); + let saved: Vec<_> = names.iter().map(|name| (name.clone(), std::env::var_os(name))).collect(); + // SAFETY: this file's one test is the only thread touching the environment. + unsafe { + for name in &names { + std::env::set_var(name, &value); + } + } + let through_environment = reads(FORGED); + unsafe { + for (name, before) in saved { + match before { + Some(before) => std::env::set_var(name, before), + None => std::env::remove_var(name), + } + } + } + assert!(matches!(through_environment, Effective::Held { .. }), "root from an environment variable"); } + +/// Names a caller-chosen root would plausibly be read from. +const GUESSED_ROOT_VARIABLES: [&str; 22] = [ + "MIND_CONTROL_ROOT", + "MIND_BODY_ROOT", + "MIND_ROOT", + "MINDS_ROOT", + "MINDS_DIR", + "CONTROL_ROOT", + "CONTROL_DIR", + "GAMECULT_MINDS", + "GAMECULT_ROOT", + "HUGINN_ROOT", + "HUGINN_HOME", + "EUREKA_ROOT", + "EUREKA_HOME", + "EUREKA_INSTANCE_ROOT", + "STATE_DIRECTORY", + "CONFIGURATION_DIRECTORY", + "RUNTIME_DIRECTORY", + "XDG_CONFIG_HOME", + "XDG_STATE_HOME", + "XDG_DATA_HOME", + "HOME", + "TMPDIR", +];