File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7212,6 +7212,15 @@ mod tests {
72127212 . unwrap_or_else ( |err| err. into_inner ( ) )
72137213 }
72147214
7215+ #[ cfg( target_family = "unix" ) ]
7216+ fn worker_process_test_temp_parent ( label : & str ) -> PathBuf {
7217+ let root = std:: env:: temp_dir ( )
7218+ . join ( "mcp-repl-test-scratch" )
7219+ . join ( label) ;
7220+ std:: fs:: create_dir_all ( & root) . expect ( "create worker process test temp parent" ) ;
7221+ root
7222+ }
7223+
72157224 #[ test]
72167225 fn python_backend_prepares_windows_sandbox_launch ( ) {
72177226 assert ! (
@@ -9829,7 +9838,7 @@ mod tests {
98299838 let _guard = cwd_test_mutex ( ) . lock ( ) . expect ( "cwd mutex" ) ;
98309839 let temp = tempfile:: Builder :: new ( )
98319840 . prefix ( ".tmp-interrupt-tail-current-sandbox-" )
9832- . tempdir_in ( env ! ( "CARGO_MANIFEST_DIR ") )
9841+ . tempdir_in ( worker_process_test_temp_parent ( "worker-process ") )
98339842 . expect ( "tempdir" ) ;
98349843 let sandbox_cwd = temp. path ( ) . to_path_buf ( ) ;
98359844 let plan = SandboxCliPlan {
Original file line number Diff line number Diff line change @@ -36,6 +36,15 @@ const WINDOWS_TEST_TIMEOUT_CAP_SECS: f64 = 60.0;
3636#[ cfg( windows) ]
3737const WINDOWS_TEST_SERVER_MUTEX_NAME : & str = "Local\\ mcp_repl_test_server_mutex" ;
3838
39+ pub ( crate ) fn checkout_test_temp_parent ( label : & str ) -> TestResult < PathBuf > {
40+ let root = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) )
41+ . join ( "target" )
42+ . join ( "test-scratch" )
43+ . join ( label) ;
44+ std:: fs:: create_dir_all ( & root) ?;
45+ Ok ( root)
46+ }
47+
3948#[ cfg( windows) ]
4049struct WindowsSuiteServerMutexOwner {
4150 release_tx : std:: sync:: mpsc:: Sender < ( ) > ,
Original file line number Diff line number Diff line change @@ -200,7 +200,28 @@ fn home_scratch_dir(label: &str) -> TestResult<TempDir> {
200200fn repo_scratch_dir ( label : & str ) -> TestResult < TempDir > {
201201 Ok ( Builder :: new ( )
202202 . prefix ( & format ! ( ".tmp-{label}-" ) )
203- . tempdir_in ( env ! ( "CARGO_MANIFEST_DIR" ) ) ?)
203+ . tempdir_in ( common:: checkout_test_temp_parent ( "sandbox-state-updates" ) ?) ?)
204+ }
205+
206+ #[ test]
207+ fn repo_scratch_dir_uses_non_temp_checkout_scratch_parent ( ) -> TestResult < ( ) > {
208+ let scratch = repo_scratch_dir ( "parent" ) ?;
209+ assert_ne ! (
210+ scratch. path( ) . parent( ) ,
211+ Some ( Path :: new( env!( "CARGO_MANIFEST_DIR" ) ) ) ,
212+ "test scratch dirs must not be created directly in the repo root"
213+ ) ;
214+ assert ! (
215+ scratch
216+ . path( )
217+ . starts_with( common:: checkout_test_temp_parent( "sandbox-state-updates" ) ?) ,
218+ "sandbox cwd scratch dirs should stay under target/test-scratch"
219+ ) ;
220+ assert ! (
221+ !scratch. path( ) . starts_with( std:: env:: temp_dir( ) ) ,
222+ "sandbox cwd scratch dirs must stay outside OS temp so read-only sandbox tests can observe blocked cwd writes"
223+ ) ;
224+ Ok ( ( ) )
204225}
205226
206227fn write_file_code ( path : & Path ) -> TestResult < String > {
Original file line number Diff line number Diff line change @@ -96,7 +96,27 @@ fn r_path_literal(path: &Path) -> TestResult<String> {
9696fn workspace_tempdir ( ) -> TestResult < tempfile:: TempDir > {
9797 Ok ( tempfile:: Builder :: new ( )
9898 . prefix ( "mcp-repl-write-stdin-" )
99- . tempdir_in ( env ! ( "CARGO_MANIFEST_DIR" ) ) ?)
99+ . tempdir_in ( common:: checkout_test_temp_parent ( "write-stdin" ) ?) ?)
100+ }
101+
102+ #[ test]
103+ fn workspace_tempdir_uses_non_temp_checkout_scratch_parent ( ) -> TestResult < ( ) > {
104+ let temp = workspace_tempdir ( ) ?;
105+ assert_ne ! (
106+ temp. path( ) . parent( ) ,
107+ Some ( Path :: new( env!( "CARGO_MANIFEST_DIR" ) ) ) ,
108+ "test scratch dirs must not be created directly in the repo root"
109+ ) ;
110+ assert ! (
111+ temp. path( )
112+ . starts_with( common:: checkout_test_temp_parent( "write-stdin" ) ?) ,
113+ "workspace scratch dirs should stay under target/test-scratch"
114+ ) ;
115+ assert ! (
116+ !temp. path( ) . starts_with( std:: env:: temp_dir( ) ) ,
117+ "workspace scratch dirs must stay outside OS temp because some tests remove or override worker temp env"
118+ ) ;
119+ Ok ( ( ) )
100120}
101121
102122async fn wait_until_path_exists ( path : & Path , label : & str ) -> TestResult < ( ) > {
You can’t perform that action at this time.
0 commit comments