Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

test(tokenizer): hold the env lock in the invalid-repo Hub error test (#4151)

Kenneth Wong1bbc0ea89e80
diff --git a/crates/headroom-core/src/tokenizer/hf_impl.rs b/crates/headroom-core/src/tokenizer/hf_impl.rs
index efb58c5d9..7b5fc8067 100644
--- a/crates/headroom-core/src/tokenizer/hf_impl.rs
+++ b/crates/headroom-core/src/tokenizer/hf_impl.rs
@@ -510,7 +510,17 @@ mod tests {
// request. Locks in that we propagate Hub errors as `Hub`, not
// `Load`, so callers can distinguish "couldn't fetch" from
// "fetched but malformed".
+ //
+ // Runs online: hold the env lock so a parallel test's
+ // `HEADROOM_OFFLINE=1` can't turn this into `Offline`, and clear an
+ // inherited value for the same reason.
+ let _guard = crate::test_support::env_lock();
+ let inherited = std::env::var_os(crate::offline::OFFLINE_ENV);
+ std::env::remove_var(crate::offline::OFFLINE_ENV);
let r = HfTokenizer::from_pretrained("");
+ if let Some(value) = inherited {
+ std::env::set_var(crate::offline::OFFLINE_ENV, value);
+ }
assert!(
matches!(r, Err(HfTokenizerError::Hub { .. })),
"expected HfTokenizerError::Hub, got {r:?}"