From 958078def8dd426a1770ea32a3b9b615eca86437 Mon Sep 17 00:00:00 2001 From: Linghong Date: Thu, 17 Sep 2026 09:52:40 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AD=96=E5=88=92panic?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=9A=84env=E5=8F=98=E9=87=8F=E6=B3=84?= =?UTF-8?q?=E6=BC=8F=20=E6=96=B0=E5=A2=9E=E9=9D=99=E6=80=81=E4=BA=92?= =?UTF-8?q?=E6=96=A5=E9=94=81=E4=B8=B2=E8=A1=8C=E5=8C=96=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E7=BA=A7debug=E5=BC=80=E5=85=B3=E4=BF=AE=E6=94=B9=20DesignDebu?= =?UTF-8?q?gEnvGuard=E5=9C=A8drop=E6=97=B6=E6=81=A2=E5=A4=8D=E5=8E=9F?= =?UTF-8?q?=E5=80=BC=EF=BC=8C=E8=A6=86=E7=9B=96=E6=96=AD=E8=A8=80=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E4=B8=8Epanic=E8=B7=AF=E5=BE=84=20=E9=94=81=E4=B8=AD?= =?UTF-8?q?=E6=AF=92=E6=97=B6=E5=8F=96=E5=86=85=E9=83=A8=E5=80=BC=E7=BB=A7?= =?UTF-8?q?=E7=BB=AD=EF=BC=8C=E9=81=BF=E5=85=8D=E5=A4=B1=E8=B4=A5=E6=94=BE?= =?UTF-8?q?=E5=A4=A7=E5=88=B0=E5=90=8E=E7=BB=AD=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src-tauri/src/agent/design_runtime.rs | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/design_runtime.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/design_runtime.rs index fbb42a22a..9e907c2c0 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/design_runtime.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/design_runtime.rs @@ -1696,10 +1696,40 @@ mod tests { .clone() } + // 进程级 env 在同一 binary 的并行用例间共享:持锁串行化修改,drop 时恢复原值, + // 避免 debug 开关泄漏给并发用例。锁中毒时取内部值继续,不让上游失败放大。 + static DESIGN_DEBUG_ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); + + struct DesignDebugEnvGuard { + previous: Option, + _lock: std::sync::MutexGuard<'static, ()>, + } + + impl Drop for DesignDebugEnvGuard { + fn drop(&mut self) { + match &self.previous { + Some(value) => std::env::set_var("GENARRATIVE_AGC_DESIGN_DEBUG", value), + None => std::env::remove_var("GENARRATIVE_AGC_DESIGN_DEBUG"), + } + } + } + + fn enable_design_debug_for_test() -> DesignDebugEnvGuard { + let lock = DESIGN_DEBUG_ENV_LOCK + .lock() + .unwrap_or_else(|poisoned| poisoned.into_inner()); + let previous = std::env::var("GENARRATIVE_AGC_DESIGN_DEBUG").ok(); + std::env::set_var("GENARRATIVE_AGC_DESIGN_DEBUG", "1"); + DesignDebugEnvGuard { + previous, + _lock: lock, + } + } + #[tokio::test(flavor = "current_thread")] async fn design_tool_panic_becomes_visible_retryable_error() { let (_temp, root, resources) = init_design_project(); - std::env::set_var("GENARRATIVE_AGC_DESIGN_DEBUG", "1"); + let _debug_env = enable_design_debug_for_test(); let panic_call = platform_llm::LlmToolCall { id: "call-panic".into(), name: "design_test__panic".into(),