fix(runtime): stop CI-built binaries reading test state paths; clippy needless_return

Linux hosted CI (Test ubuntu-latest, `cargo nextest run --workspace
--all-features`) had 11 failures from 4cf2d2cfff (coordinator diagnosis,
CW/artifacts/linux-ci-regressions-20261027/RESULT.md group A). The move
of settings, paths, catalog cache and credential lookup into
codewhale-runtime gates its test redirect on a feature that
`--workspace --all-features` turns on, so the shipped-shape binary and
the cli tests read `/tmp/codewhale-tui-test-state-*` instead of
HOME/CODEWHALE_HOME. `codewhale_runtime::resolve_state_from_environment()`
(a no-op without `test-support`) is called by the binary's main and the
cli test env_lock, so state comes from the real environment again.
Release artifacts build `-p codewhale-cli --profile dist` without
`--all-features`, so they never had the redirect (resolver 2; the
features are dev-dependency only).

Also: c21e0b1e14 left a `return` in provider_lake.rs that clippy's
needless_return flags when the cfg(not(test…)) block after it is
compiled out (CI's all-features debug build). The second known() check
now guards the model load directly; shipped behavior is unchanged.

Patch by the coordinator session (fix.patch); provider_lake by the
release manager. Verified:
- Linux (coordinator, Boat VM): cli lib 501, cucumber 54,
  diagnostic_read_only 12 passing (2 group-C tests remain, routed).
- macOS, export of 39c446a164 + this change, under the build lock:
  `cargo clippy --workspace --all-targets --all-features --locked --
  -D warnings` (CI Lint allowances) exit 0, 0 errors, 1288 s;
  `cargo test -p codewhale-cli --all-features --locked` (hermetic home)
  exit 0: lib 501/0 and every integration binary 0 failed.
- rustfmt --check clean on all six files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
CodeWhale BotandClaude Opus 5.5 committed 2026-10-27 21:04:43 -07:00
1 parent c8e68b9afb
commit 0d0b2f46af
6 files changed
+39 -15

No files matched your search

+1
View File
@@ -6795,6 +6795,7 @@ mod tests {
}
pub(crate) fn env_lock() -> std::sync::MutexGuard<'static, ()> {
codewhale_runtime::resolve_state_from_environment();
static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
LOCK.get_or_init(|| Mutex::new(()))
.lock()
+2
View File
@@ -55,6 +55,8 @@ fn main() -> std::process::ExitCode {
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
}
codewhale_runtime::resolve_state_from_environment();
// Published codew/codewhale-tui compatibility names are copies or links
// to this executable and use the same CLI parser and Engine entrypoint.
codewhale_cli::run_cli()
+5 -3
View File
@@ -10913,7 +10913,8 @@ pub fn credential_secret_store() -> Option<codewhale_secrets::Secrets> {
let explicit_backend = std::env::var_os("CODEWHALE_SECRET_BACKEND")
.or_else(|| std::env::var_os("DEEPSEEK_SECRET_BACKEND"))
.is_some_and(|value| !value.is_empty());
(isolated_home && explicit_backend).then(codewhale_secrets::Secrets::auto_detect)
(crate::test_support::state_from_environment() || (isolated_home && explicit_backend))
.then(codewhale_secrets::Secrets::auto_detect)
}
fn save_root_api_key_metadata_without_plaintext(config_path: &Path, table: &str) -> Result<()> {
@@ -11949,8 +11950,9 @@ fn provider_secret_store_api_key_with_mode(
// Secret-store regressions opt in with an isolated CODEWHALE_HOME and an
// explicit backend, matching the secrets crate's own test discipline.
#[cfg(any(test, all(feature = "test-thread-scoped-state", debug_assertions)))]
if !codewhale_paths::codewhale_home_is_explicit()
|| std::env::var_os("CODEWHALE_SECRET_BACKEND").is_none()
if !crate::test_support::state_from_environment()
&& (!codewhale_paths::codewhale_home_is_explicit()
|| std::env::var_os("CODEWHALE_SECRET_BACKEND").is_none())
{
return None;
}
+5
View File
@@ -53,6 +53,11 @@ pub mod workspace_discovery;
pub const CODEWHALE_MAIN_STACK_BYTES: usize = 32 * 1024 * 1024;
pub fn resolve_state_from_environment() {
#[cfg(any(test, feature = "test-support"))]
test_support::resolve_state_from_environment();
}
pub mod catalog_cache;
pub mod codex_model_roster;
+20
View File
@@ -2,6 +2,7 @@
use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Mutex, OnceLock};
use std::time::{SystemTime, UNIX_EPOCH};
@@ -228,8 +229,21 @@ fn unregister_guarded_env_key(key: &'static str) {
}
}
static STATE_FROM_ENVIRONMENT: AtomicBool = AtomicBool::new(false);
pub fn resolve_state_from_environment() {
STATE_FROM_ENVIRONMENT.store(true, Ordering::SeqCst);
}
pub fn state_from_environment() -> bool {
STATE_FROM_ENVIRONMENT.load(Ordering::SeqCst)
}
/// Whether some live [`EnvVarGuard`] currently covers `key`.
pub fn env_var_currently_guarded(key: &str) -> bool {
if state_from_environment() {
return true;
}
match guarded_env_keys().lock() {
Ok(keys) => keys.contains_key(key),
Err(poisoned) => poisoned.into_inner().contains_key(key),
@@ -248,6 +262,9 @@ pub fn env_var_currently_guarded(key: &str) -> bool {
/// override variables or redirecting `HOME`/`USERPROFILE` through
/// [`EnvVarGuard`].
pub fn guarded_environment_provides_state_paths() -> bool {
if state_from_environment() {
return true;
}
if !current_thread_holds_test_env_lock() {
return false;
}
@@ -283,6 +300,9 @@ pub fn guarded_environment_provides_state_paths() -> bool {
/// is set, so a guarded `HOME` seals nothing while an unguarded
/// `CODEWHALE_HOME` is in the ambient environment.
pub fn home_is_sealed() -> bool {
if state_from_environment() {
return true;
}
if !current_thread_holds_test_env_lock() {
return false;
}
+6 -12
View File
@@ -1994,10 +1994,6 @@ pub(crate) async fn refresh_local_ollama_catalog(config: &Config, identity: &Pro
}
}
#[cfg_attr(
any(test, all(feature = "test-thread-scoped-state", debug_assertions)),
allow(clippy::needless_return)
)]
pub(crate) async fn refresh_unverified_local_context(
config: &Config,
identity: &ProviderIdentity,
@@ -2033,15 +2029,13 @@ pub(crate) async fn refresh_unverified_local_context(
return;
}
let _ = refresh().await;
if known().await {
return;
}
#[cfg(not(any(test, all(feature = "test-thread-scoped-state", debug_assertions))))]
if crate::client::ollama_catalog::load_model(
&crate::client::ollama_catalog::ollama_native_origin(&base_url),
model,
)
.await
if !known().await
&& crate::client::ollama_catalog::load_model(
&crate::client::ollama_catalog::ollama_native_origin(&base_url),
model,
)
.await
{
let _ = refresh().await;
}