@@ -39,7 +39,8 @@ def test_pip_docker_container_detection(self, request: pytest.FixtureRequest) ->
3939 executor = DockerExecutor (container_id )
4040 orchestrator = Orchestrator (debug = False , skip_system_scope = True )
4141
42- result = orchestrator .resolve_dependencies (executor )
42+ # Set working directory to where the venv was created to help detection
43+ result = orchestrator .resolve_dependencies (executor , working_dir = "/opt" )
4344
4445 if verbose_output :
4546 self .print_verbose_results ("DEPENDENCY RESOLVER OUTPUT:" , result )
@@ -50,15 +51,45 @@ def test_pip_docker_container_detection(self, request: pytest.FixtureRequest) ->
5051 if container_id :
5152 self .cleanup_container (container_id )
5253
54+ @pytest .mark .skipif (docker is None , reason = "Docker not available" )
55+ def test_pip_system_scope_with_location_and_hash (self , request : pytest .FixtureRequest ) -> None :
56+ """Test that system scope pip packages have actual locations and hashes."""
57+
58+ verbose_output = self .setup_verbose_output (request )
59+ container_id = None
60+
61+ try :
62+ container_id = self .start_container (self .PYTHON_DOCKER_IMAGE )
63+ self .wait_for_container_ready (container_id , "pip --version" , max_wait = 60 )
64+
65+ executor = DockerExecutor (container_id )
66+ orchestrator = Orchestrator (debug = False , skip_system_scope = False ) # Include system scope
67+
68+ result = orchestrator .resolve_dependencies (executor )
69+
70+ if verbose_output :
71+ self .print_verbose_results ("DEPENDENCY RESOLVER OUTPUT:" , result )
72+
73+ self ._validate_system_pip_dependencies (result )
74+
75+ finally :
76+ if container_id :
77+ self .cleanup_container (container_id )
78+
5379 def _setup_pip_packages (self , container_id : str ) -> None :
54- """Install some test pip packages in the container."""
80+ """Install some test pip packages in the container using a virtual environment ."""
5581 executor = DockerExecutor (container_id )
5682
57- # Install some common packages for testing
83+ # Create a virtual environment
84+ _ , stderr , exit_code = executor .execute_command ("python3 -m venv /opt/test_venv" )
85+ if exit_code != 0 :
86+ pytest .fail (f"Failed to create virtual environment: { stderr } " )
87+
88+ # Install some common packages for testing in the virtual environment
5889 packages = ["requests==2.31.0" , "numpy==1.24.3" , "click==8.1.7" ]
5990
6091 for package in packages :
61- _ , stderr , exit_code = executor .execute_command (f"pip install { package } " )
92+ _ , stderr , exit_code = executor .execute_command (f"/opt/test_venv/bin/ pip install { package } " )
6293 if exit_code != 0 :
6394 pytest .fail (f"Failed to install { package } : { stderr } " )
6495
@@ -98,6 +129,49 @@ def _validate_pip_dependencies(self, result: Dict[str, Any]) -> None:
98129 print (f"✓ Total dependencies found: { len (pip_packages )} " )
99130 print ("✓ Scope: project" )
100131
132+ def _validate_system_pip_dependencies (self , result : Dict [str , Any ]) -> None :
133+ """Validate that system scope pip dependencies have actual locations and hashes."""
134+ # Check for system scope packages
135+ assert "system" in result , "Expected 'system' scope in result"
136+ system_result = result ["system" ]
137+ assert "packages" in system_result , "System scope should contain 'packages'"
138+
139+ # Check for package management metadata
140+ if "package-management" in system_result :
141+ package_mgmt = system_result ["package-management" ]
142+ if "pip" in package_mgmt :
143+ pip_metadata = package_mgmt ["pip" ]
144+
145+ # Validate that location is an actual path, not just "system"
146+ assert "location" in pip_metadata , "System pip should have location metadata"
147+ location = pip_metadata ["location" ]
148+ assert location != "system" , f"Location should be actual path, not 'system', got: { location } "
149+ assert "/" in location , f"Location should be an absolute path, got: { location } "
150+
151+ # Check if hash is present (it should be for system packages now)
152+ if "hash" in pip_metadata :
153+ hash_value = pip_metadata ["hash" ]
154+ assert len (hash_value ) == 64 , f"Hash should be 64 characters (SHA256), got: { len (hash_value )} "
155+ assert hash_value .isalnum (), f"Hash should be alphanumeric, got: { hash_value } "
156+
157+ print (f"✓ System pip location: { location } " )
158+ print (f"✓ System pip hash: { 'present' if 'hash' in pip_metadata else 'not present' } " )
159+
160+ # Validate system pip packages exist
161+ packages = system_result ["packages" ]
162+ pip_packages = [pkg for pkg in packages if pkg .get ("type" ) == "pip" ]
163+
164+ if len (pip_packages ) > 0 :
165+ print (f"✓ Found { len (pip_packages )} system pip packages" )
166+ # Check structure of system pip packages
167+ for pkg in pip_packages [:3 ]: # Check first few packages
168+ assert "name" in pkg , "Package should have name"
169+ assert "version" in pkg , "Package should have version"
170+ assert "type" in pkg , "Package should have type"
171+ assert pkg ["type" ] == "pip" , f"Package type should be 'pip', got: { pkg ['type' ]} "
172+ else :
173+ print ("✓ No system pip packages found (this is acceptable)" )
174+
101175
102176if __name__ == "__main__" :
103177 pytest .main ([__file__ , "-v" ])
0 commit comments