@@ -8,10 +8,12 @@ mod support;
88
99#[ cfg( feature = "libsql" ) ]
1010mod attachment_tests {
11- use std:: path:: { Path , PathBuf } ;
12- use std:: sync:: { Mutex , OnceLock } ;
11+ use std:: path:: PathBuf ;
12+ use std:: sync:: OnceLock ;
1313 use std:: time:: Duration ;
1414
15+ use tokio:: sync:: Mutex ;
16+
1517 use crate :: support:: test_rig:: TestRigBuilder ;
1618 use crate :: support:: trace_llm:: LlmTrace ;
1719
@@ -24,34 +26,14 @@ mod attachment_tests {
2426 ) ;
2527 const TIMEOUT : Duration = Duration :: from_secs ( 15 ) ;
2628
27- fn cwd_lock ( ) -> & ' static Mutex < ( ) > {
29+ fn engine_v2_attachment_root_lock ( ) -> & ' static Mutex < ( ) > {
2830 static LOCK : OnceLock < Mutex < ( ) > > = OnceLock :: new ( ) ;
2931 LOCK . get_or_init ( || Mutex :: new ( ( ) ) )
3032 }
3133
32- struct WorkingDirGuard {
33- original : PathBuf ,
34- _guard : std:: sync:: MutexGuard < ' static , ( ) > ,
35- }
36-
37- impl WorkingDirGuard {
38- fn enter ( path : & Path ) -> Self {
39- let guard = cwd_lock ( )
40- . lock ( )
41- . unwrap_or_else ( |poison| poison. into_inner ( ) ) ;
42- let original = std:: env:: current_dir ( ) . expect ( "current dir" ) ;
43- std:: env:: set_current_dir ( path) . expect ( "set current dir" ) ;
44- Self {
45- original,
46- _guard : guard,
47- }
48- }
49- }
50-
51- impl Drop for WorkingDirGuard {
52- fn drop ( & mut self ) {
53- std:: env:: set_current_dir ( & self . original ) . expect ( "restore current dir" ) ;
54- }
34+ fn engine_v2_project_root ( ) -> PathBuf {
35+ let base_dir = ironclaw:: bootstrap:: ironclaw_base_dir ( ) ;
36+ base_dir. parent ( ) . map ( PathBuf :: from) . unwrap_or ( base_dir)
5537 }
5638
5739 fn make_attachment ( kind : AttachmentKind ) -> IncomingAttachment {
@@ -243,10 +225,10 @@ mod attachment_tests {
243225
244226 #[ tokio:: test]
245227 async fn engine_v2_channel_attachments_persist_for_telegram_and_whatsapp ( ) {
246- for channel in [ "telegram" , "whatsapp" ] {
247- let cwd = tempfile:: tempdir ( ) . expect ( "temp cwd" ) ;
248- let _cwd = WorkingDirGuard :: enter ( cwd. path ( ) ) ;
228+ let _guard = engine_v2_attachment_root_lock ( ) . lock ( ) . await ;
229+ let project_root = engine_v2_project_root ( ) ;
249230
231+ for channel in [ "telegram" , "whatsapp" ] {
250232 let rig = TestRigBuilder :: new ( ) . with_engine_v2 ( ) . build ( ) . await ;
251233
252234 let attachment_bytes = format ! ( "Attachment from {channel}" ) . into_bytes ( ) ;
@@ -302,7 +284,7 @@ mod attachment_tests {
302284 "unexpected persisted path for {channel}: {project_path}"
303285 ) ;
304286
305- let saved_path = cwd . path ( ) . join ( project_path) ;
287+ let saved_path = project_root . join ( project_path) ;
306288 assert ! (
307289 saved_path. exists( ) ,
308290 "saved attachment missing: {}" ,
0 commit comments