5454 LogContent ,
5555)
5656from openjd .sessions import _path_mapping as path_mapping_impl_mod
57+ from openjd .sessions import _session as session_module
5758from openjd .sessions ._action_filter import ActionMessageKind
5859from openjd .sessions ._os_checker import is_posix , is_windows
5960from openjd .sessions ._logging import LoggerAdapter , LogExtraInfo
@@ -564,6 +565,12 @@ class TestSessionWorkingDirectoryName:
564565 DEADLINE_SHAPED_ID = f"session-{ uuid .uuid4 ().hex } "
565566
566567 def test_working_directory_name_length_is_bounded (self ) -> None :
568+ # A ceiling, not an equality: the exact count is mkdtemp()'s to choose
569+ # (CPython currently yields 8 characters, hence the constant) and a stdlib
570+ # change to a *shorter* name would not be a regression. What must not
571+ # regress is the budget -- passing the 40-character session id as a prefix
572+ # cost 48.
573+
567574 # GIVEN
568575 job_params = dict [str , ParameterValue ]()
569576
@@ -572,28 +579,29 @@ def test_working_directory_name_length_is_bounded(self) -> None:
572579 session_id = self .DEADLINE_SHAPED_ID , job_parameter_values = job_params
573580 ) as session :
574581 # THEN
575- assert len (session .working_directory .name ) == SESSION_DIR_NAME_LENGTH
576- # Guard on the budget itself, independent of the constant: this cost 48.
577- assert len (session .working_directory .name ) <= 8
582+ assert len (session .working_directory .name ) <= SESSION_DIR_NAME_LENGTH
578583
579- def test_working_directory_name_carries_no_part_of_the_session_id (self ) -> None :
580- # prefix="" rather than None: None would restore mkdtemp()'s "tmp" template,
581- # so guard the distinction and not just the absence of the id.
584+ def test_working_directory_is_created_with_an_empty_prefix (self ) -> None :
585+ # prefix="" rather than None is the load-bearing choice: None restores
586+ # mkdtemp()'s "tmp" template (3 characters) and the session id (48) is what
587+ # we removed. Assert the argument we pass, not a sample of the random name:
588+ # inspecting the name for the *absence* of a prefix is probabilistic -- a
589+ # random [a-z0-9_] name can happen to begin "tmp" -- while the call is exact.
582590
583591 # GIVEN
584592 job_params = dict [str , ParameterValue ]()
585593
586594 # WHEN
587- with Session (
588- session_id = self . DEADLINE_SHAPED_ID , job_parameter_values = job_params
589- ) as session :
590- # THEN
591- name = session . working_directory . name
592- assert not name . startswith ( "tmp" )
593- assert "session" not in name
594- assert not any (
595- self . DEADLINE_SHAPED_ID [ - n :] in name for n in range ( 4 , len ( self . DEADLINE_SHAPED_ID ))
596- )
595+ with patch . object ( session_module , "TempDir" , wraps = session_module . TempDir ) as mock_tempdir :
596+ with Session (
597+ session_id = self . DEADLINE_SHAPED_ID , job_parameter_values = job_params
598+ ) as session :
599+ # THEN
600+ # The first TempDir call is the working directory; the second is
601+ # the nested embedded_files directory.
602+ assert mock_tempdir . call_args_list [ 0 ]. kwargs [ "prefix" ] == ""
603+ # ... and nothing of the session id survived into the name.
604+ assert self . DEADLINE_SHAPED_ID not in session . working_directory . name
597605
598606 @pytest .mark .usefixtures ("caplog" ) # built-in fixture
599607 def test_full_session_id_remains_in_the_log (self , caplog : pytest .LogCaptureFixture ) -> None :
@@ -617,9 +625,15 @@ def test_full_session_id_remains_in_the_log(self, caplog: pytest.LogCaptureFixtu
617625 m == f"Session Working Directory: { str (session .working_directory )} "
618626 for m in caplog .messages
619627 )
628+ # caplog.records collects from every logger propagating to root, so
629+ # filter to this library's before asserting the extra is present --
630+ # and default to None, not the expected id, so a record that is
631+ # *missing* the extra fails rather than passing vacuously (which is
632+ # precisely the regression -- a dropped LoggerAdapter -- this guards).
633+ session_records = [r for r in caplog .records if r .name .startswith ("openjd.sessions" )]
634+ assert session_records
620635 assert all (
621- getattr (r , "session_id" , self .DEADLINE_SHAPED_ID ) == self .DEADLINE_SHAPED_ID
622- for r in caplog .records
636+ getattr (r , "session_id" , None ) == self .DEADLINE_SHAPED_ID for r in session_records
623637 )
624638
625639 @pytest .mark .usefixtures ("tmp_path" ) # built-in fixture
@@ -662,7 +676,7 @@ def test_concurrent_sessions_in_one_root_get_distinct_directories(self, tmp_path
662676 job_params = dict [str , ParameterValue ]()
663677 sessions : list [Session ] = []
664678 lock = threading .Lock ()
665- errors : list [BaseException ] = []
679+ errors : list [Exception ] = []
666680
667681 def make_session () -> None :
668682 try :
@@ -671,7 +685,7 @@ def make_session() -> None:
671685 job_parameter_values = job_params ,
672686 session_root_directory = tmp_path ,
673687 )
674- except BaseException as err : # pragma: nocover - only on a failure
688+ except Exception as err : # pragma: nocover - only on a failure
675689 with lock :
676690 errors .append (err )
677691 return
0 commit comments