Read-only mirror of github.com/ondeinference/ed.
Mirrored from https://github.com/ondeinference/ed.git
Synced Nov 23, 01:00 UTC
Serialize the ed-claude tests that touch the environment
The no-key test set and removed process variables while the tool-call turn test ran the agent on another thread, so a set_var could overlap a getenv. Both now hold one lock. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.6 <noreply@sigit.si>
Seto Elkahfi committed
Nov 1, 2026 at 19:48 UTC
735869428c916c8efbaa5eeef32ba44e3f87d0aa
1 file changed
+8
-2
crates/ed-claude/tests/turn.rs
+8
-2
@@ -13,10 +13,15 @@ use ed_acp_testkit::{MockStats, Script, Step, TEST_KEY, start_mock_llm, temp_dir
13
use ed_claude::{Claude, ClaudeAuth, DEFAULT_MODEL, MODELS, credentials};
14
use serde_json::json;
15
16
+/// Held by every test that changes the process environment or runs the agent, which reads it,
17
+/// so a `set_var` never overlaps another thread's `getenv`.
18
+static ENV: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
19
+
20
#[test]
21
fn no_key_means_no_llm_config_even_with_provider_env_set() {
22
+ let _env = ENV.blocking_lock();
23
let dir = temp_dir("ed-claude-nokey");
19
- // SAFETY: only this test touches these variables, and nothing reads them concurrently.
24
+ // SAFETY: ENV is held, and the other test that reads the environment waits for it.
25
unsafe {
26
std::env::set_var("OPENAI_API_KEY", "sk-from-env");
27
std::env::set_var("ED_CLAUDE_API_KEY", "sk-from-env");
@@ -49,11 +54,12 @@ fn llm_config_uses_the_stored_key_and_model() {
54
55
#[tokio::test]
56
async fn a_streamed_tool_call_turn_round_trips() {
57
+ let _env = ENV.lock().await;
58
let data = temp_dir("ed-claude-data");
59
let key_dir = temp_dir("ed-claude-keys");
60
let work = temp_dir("ed-claude-work");
61
std::fs::write(work.join("hello.txt"), "hi").unwrap();
56
- // SAFETY: set before the agent starts; only the data dir, no credentials.
62
+ // SAFETY: ENV is held for the whole turn; only the data dir, no credentials.
63
unsafe { std::env::set_var("ED_CLAUDE_DATA_DIR", &data) };
64
credentials::store_in_for_tests(&key_dir, TEST_KEY, None);
65