@@ -259,6 +259,49 @@ def record_mode(
259259 assert (run_dir / "manifest.json" ).is_file ()
260260
261261
262+ @pytest .mark .skipif (os .name != "posix" , reason = "POSIX directory-mode contract" )
263+ @pytest .mark .parametrize (
264+ ("raced_mode" , "expected_error" ),
265+ ((0o700 , None ), (0o755 , PermissionError )),
266+ )
267+ def test_missing_private_parent_validates_concurrent_creator (
268+ tmp_path : Path ,
269+ monkeypatch : pytest .MonkeyPatch ,
270+ raced_mode : int ,
271+ expected_error : type [Exception ] | None ,
272+ ) -> None :
273+ existing_parent = tmp_path / "existing"
274+ existing_parent .mkdir (mode = 0o700 )
275+ raced_parent = existing_parent / "runs"
276+ destination = raced_parent / "run"
277+ real_mkdir = Path .mkdir
278+ raced = False
279+
280+ def race_mkdir (
281+ path : Path ,
282+ mode : int = 0o777 ,
283+ parents : bool = False ,
284+ exist_ok : bool = False ,
285+ ) -> None :
286+ nonlocal raced
287+ if path == raced_parent and not raced :
288+ real_mkdir (path , mode = raced_mode )
289+ path .chmod (raced_mode )
290+ raced = True
291+ real_mkdir (path , mode = mode , parents = parents , exist_ok = exist_ok )
292+
293+ monkeypatch .setattr (Path , "mkdir" , race_mkdir )
294+
295+ if expected_error is None :
296+ workflow ._create_missing_private_parents (destination )
297+ else :
298+ with pytest .raises (expected_error , match = "not private" ):
299+ workflow ._create_missing_private_parents (destination )
300+
301+ assert raced is True
302+ assert stat .S_IMODE (raced_parent .stat ().st_mode ) == raced_mode
303+
304+
262305@pytest .mark .skipif (os .name != "posix" , reason = "POSIX directory-mode contract" )
263306@pytest .mark .parametrize ("mask" , (0o002 , 0o000 ))
264307def test_prepare_run_creates_missing_default_parent_privately (
0 commit comments