socketdev 3.0.14__tar.gz → 3.0.17__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. {socketdev-3.0.14 → socketdev-3.0.17}/PKG-INFO +1 -1
  2. {socketdev-3.0.14 → socketdev-3.0.17}/pyproject.toml +1 -1
  3. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/__init__.py +2 -0
  4. socketdev-3.0.17/socketdev/uploadmanifests/__init__.py +141 -0
  5. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/utils/__init__.py +57 -60
  6. socketdev-3.0.17/socketdev/version.py +1 -0
  7. socketdev-3.0.17/tests/unit/test_upload_manifests.py +179 -0
  8. socketdev-3.0.14/socketdev/version.py +0 -1
  9. {socketdev-3.0.14 → socketdev-3.0.17}/.github/CODEOWNERS +0 -0
  10. {socketdev-3.0.14 → socketdev-3.0.17}/.github/PULL_REQUEST_TEMPLATE/bug-fix.md +0 -0
  11. {socketdev-3.0.14 → socketdev-3.0.17}/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -0
  12. {socketdev-3.0.14 → socketdev-3.0.17}/.github/PULL_REQUEST_TEMPLATE/improvement.md +0 -0
  13. {socketdev-3.0.14 → socketdev-3.0.17}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  14. {socketdev-3.0.14 → socketdev-3.0.17}/.github/workflows/pr-preview.yml +0 -0
  15. {socketdev-3.0.14 → socketdev-3.0.17}/.github/workflows/release.yml +0 -0
  16. {socketdev-3.0.14 → socketdev-3.0.17}/.github/workflows/version-check.yml +0 -0
  17. {socketdev-3.0.14 → socketdev-3.0.17}/.gitignore +0 -0
  18. {socketdev-3.0.14 → socketdev-3.0.17}/.hooks/sync_version.py +0 -0
  19. {socketdev-3.0.14 → socketdev-3.0.17}/.python-version +0 -0
  20. {socketdev-3.0.14 → socketdev-3.0.17}/LICENSE +0 -0
  21. {socketdev-3.0.14 → socketdev-3.0.17}/README.rst +0 -0
  22. {socketdev-3.0.14 → socketdev-3.0.17}/scripts/build.sh +0 -0
  23. {socketdev-3.0.14 → socketdev-3.0.17}/scripts/deploy-test-pypi.sh +0 -0
  24. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/alerttypes/__init__.py +0 -0
  25. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/analytics/__init__.py +0 -0
  26. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/apitokens/__init__.py +0 -0
  27. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/auditlog/__init__.py +0 -0
  28. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/basics/__init__.py +0 -0
  29. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/core/api.py +0 -0
  30. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/core/classes.py +0 -0
  31. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/core/dedupe.py +0 -0
  32. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/core/issues.py +0 -0
  33. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/dependencies/__init__.py +0 -0
  34. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/diffscans/__init__.py +0 -0
  35. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/exceptions.py +0 -0
  36. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/export/__init__.py +0 -0
  37. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/fullscans/__init__.py +0 -0
  38. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/historical/__init__.py +0 -0
  39. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/labels/__init__.py +0 -0
  40. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/licensemetadata/__init__.py +0 -0
  41. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/log.py +0 -0
  42. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/npm/__init__.py +0 -0
  43. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/openapi/__init__.py +0 -0
  44. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/org/__init__.py +0 -0
  45. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/purl/__init__.py +0 -0
  46. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/quota/__init__.py +0 -0
  47. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/report/__init__.py +0 -0
  48. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/repos/__init__.py +0 -0
  49. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/repositories/__init__.py +0 -0
  50. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/sbom/__init__.py +0 -0
  51. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/settings/__init__.py +0 -0
  52. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/threatfeed/__init__.py +0 -0
  53. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/tools/__init__.py +0 -0
  54. {socketdev-3.0.14 → socketdev-3.0.17}/socketdev/triage/__init__.py +0 -0
  55. {socketdev-3.0.14 → socketdev-3.0.17}/tests/README.md +0 -0
  56. {socketdev-3.0.14 → socketdev-3.0.17}/tests/conftest.py +0 -0
  57. {socketdev-3.0.14 → socketdev-3.0.17}/tests/integration/test_all_endpoints.py +0 -0
  58. {socketdev-3.0.14 → socketdev-3.0.17}/tests/integration/test_comprehensive_integration.py +0 -0
  59. {socketdev-3.0.14 → socketdev-3.0.17}/tests/integration/test_diffscans_integration.py +0 -0
  60. {socketdev-3.0.14 → socketdev-3.0.17}/tests/integration/test_new_endpoints.py +0 -0
  61. {socketdev-3.0.14 → socketdev-3.0.17}/tests/run_tests.py +0 -0
  62. {socketdev-3.0.14 → socketdev-3.0.17}/tests/unit/__init__.py +0 -0
  63. {socketdev-3.0.14 → socketdev-3.0.17}/tests/unit/test_all_endpoints_unit.py +0 -0
  64. {socketdev-3.0.14 → socketdev-3.0.17}/tests/unit/test_dedupe.py +0 -0
  65. {socketdev-3.0.14 → socketdev-3.0.17}/tests/unit/test_socket_sdk_unit.py +0 -0
  66. {socketdev-3.0.14 → socketdev-3.0.17}/tests/unit/test_working_endpoints_unit.py +0 -0
  67. {socketdev-3.0.14 → socketdev-3.0.17}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: socketdev
3
- Version: 3.0.14
3
+ Version: 3.0.17
4
4
  Summary: Socket Security Python SDK
5
5
  Project-URL: Homepage, https://github.com/socketdev/socketdev
6
6
  Author-email: Douglas Coburn <douglas@socket.dev>
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "socketdev"
7
- version = "3.0.14"
7
+ version = "3.0.17"
8
8
  requires-python = ">= 3.9"
9
9
  dependencies = [
10
10
  'requests',
@@ -25,6 +25,7 @@ from socketdev.auditlog import AuditLog
25
25
  from socketdev.analytics import Analytics
26
26
  from socketdev.alerttypes import AlertTypes
27
27
  from socketdev.basics import Basics
28
+ from socketdev.uploadmanifests import UploadManifests
28
29
  from socketdev.log import log
29
30
 
30
31
  __author__ = "socket.dev"
@@ -74,6 +75,7 @@ class socketdev:
74
75
  self.analytics = Analytics(self.api)
75
76
  self.alerttypes = AlertTypes(self.api)
76
77
  self.basics = Basics(self.api)
78
+ self.uploadmanifests = UploadManifests(self.api)
77
79
 
78
80
  @staticmethod
79
81
  def set_timeout(timeout: int):
@@ -0,0 +1,141 @@
1
+ import os
2
+ import logging
3
+ from typing import List, Optional, Union
4
+ from ..utils import Utils
5
+
6
+ log = logging.getLogger("socketdev")
7
+
8
+
9
+ class UploadManifests:
10
+ def __init__(self, api):
11
+ self.api = api
12
+
13
+ def _calculate_key_name(self, file_path: str, workspace: Optional[str] = None, base_path: Optional[str] = None, base_paths: Optional[List[str]] = None) -> str:
14
+ """
15
+ Calculate the key name for a file using the same logic as load_files_for_sending_lazy.
16
+ This ensures consistency between lazy and non-lazy loading modes.
17
+ """
18
+ # Normalize file path
19
+ if "\\" in file_path:
20
+ file_path = file_path.replace("\\", "/")
21
+
22
+ # Normalize paths
23
+ if workspace and "\\" in workspace:
24
+ workspace = workspace.replace("\\", "/")
25
+ if base_path and "\\" in base_path:
26
+ base_path = base_path.replace("\\", "/")
27
+ if base_paths:
28
+ base_paths = [bp.replace("\\", "/") if "\\" in bp else bp for bp in base_paths]
29
+
30
+ # Calculate the key name for the form data
31
+ key = file_path
32
+ path_stripped = False
33
+
34
+ # If base_paths is provided, try to strip one of the paths from the file path
35
+ if base_paths:
36
+ for bp in base_paths:
37
+ normalized_base_path = bp.rstrip("/") + "/" if not bp.endswith("/") else bp
38
+ if key.startswith(normalized_base_path):
39
+ key = key[len(normalized_base_path):]
40
+ path_stripped = True
41
+ break
42
+ elif key.startswith(bp.rstrip("/")):
43
+ stripped_base = bp.rstrip("/")
44
+ if key.startswith(stripped_base + "/") or key == stripped_base:
45
+ key = key[len(stripped_base):]
46
+ key = key.lstrip("/")
47
+ path_stripped = True
48
+ break
49
+ elif base_path:
50
+ normalized_base_path = base_path.rstrip("/") + "/" if not base_path.endswith("/") else base_path
51
+ if key.startswith(normalized_base_path):
52
+ key = key[len(normalized_base_path):]
53
+ path_stripped = True
54
+ elif key.startswith(base_path.rstrip("/")):
55
+ stripped_base = base_path.rstrip("/")
56
+ if key.startswith(stripped_base + "/") or key == stripped_base:
57
+ key = key[len(stripped_base):]
58
+ key = key.lstrip("/")
59
+ path_stripped = True
60
+
61
+ # If workspace is provided and no base paths matched, fall back to workspace logic
62
+ if not path_stripped and workspace and file_path.startswith(workspace):
63
+ key = file_path[len(workspace):]
64
+ # Remove all leading slashes (for absolute paths)
65
+ while key.startswith("/"):
66
+ key = key[1:]
67
+ path_stripped = True
68
+
69
+ # Clean up relative path prefixes, but preserve filename dots
70
+ while key.startswith("./"):
71
+ key = key[2:]
72
+ while key.startswith("../"):
73
+ key = key[3:]
74
+ # Remove any remaining leading slashes (for absolute paths)
75
+ while key.startswith("/"):
76
+ key = key[1:]
77
+
78
+ # Remove Windows drive letter if present (C:/...)
79
+ if len(key) > 2 and key[1] == ':' and (key[2] == '/' or key[2] == '\\'):
80
+ key = key[2:]
81
+ while key.startswith("/"):
82
+ key = key[1:]
83
+
84
+ return key
85
+
86
+ def upload_manifest_files(self, org_slug: str, file_paths: List[str], workspace: Optional[str] = None, base_path: Optional[str] = None, base_paths: Optional[List[str]] = None, use_lazy_loading: bool = True) -> str:
87
+ """
88
+ Upload manifest files to Socket API and return tarHash.
89
+
90
+ Args:
91
+ org_slug: Organization slug
92
+ file_paths: List of manifest file paths to upload
93
+ workspace: Base directory path to make paths relative to
94
+ base_path: Optional base path to strip from key names for cleaner file organization
95
+ base_paths: Optional list of base paths to strip from key names (takes precedence over base_path)
96
+ use_lazy_loading: Whether to use lazy file loading (default: True)
97
+
98
+ Returns:
99
+ str: The tarHash from the upload response
100
+
101
+ Raises:
102
+ Exception: If upload fails
103
+ """
104
+ # Filter to only existing files
105
+ valid_files = [f for f in file_paths if os.path.exists(f) and os.path.isfile(f)]
106
+
107
+ if not valid_files:
108
+ raise Exception("No valid manifest files found to upload")
109
+
110
+ # Prepare files for upload using the utility function
111
+ if use_lazy_loading:
112
+ loaded_files = Utils.load_files_for_sending_lazy(
113
+ valid_files,
114
+ workspace=workspace,
115
+ base_path=base_path,
116
+ base_paths=base_paths
117
+ )
118
+ else:
119
+ # Fallback to basic file loading if needed
120
+ loaded_files = []
121
+ for file_path in valid_files:
122
+ # Use the same key generation logic as lazy loading for consistency
123
+ key = self._calculate_key_name(file_path, workspace, base_path, base_paths)
124
+ with open(file_path, 'rb') as f:
125
+ loaded_files.append((key, (key, f.read())))
126
+
127
+ # Make the upload request
128
+ path = f"orgs/{org_slug}/upload-manifest-files"
129
+ response = self.api.do_request(path=path, files=loaded_files, method="POST")
130
+
131
+ if response.status_code != 200:
132
+ raise Exception(f"Upload failed with status {response.status_code}: {response.text}")
133
+
134
+ result = response.json()
135
+ tar_hash = result.get('tarHash')
136
+
137
+ if not tar_hash:
138
+ raise Exception("Server did not return a tarHash")
139
+
140
+ log.info(f"Successfully uploaded {len(valid_files)} manifest files, tarHash: {tar_hash}")
141
+ return tar_hash
@@ -1,4 +1,4 @@
1
- from typing import Literal, List, Tuple
1
+ from typing import Literal, List, Tuple, Optional
2
2
  import logging
3
3
  import os
4
4
  import weakref
@@ -233,7 +233,7 @@ class Utils:
233
233
  return integration_type # type: ignore
234
234
 
235
235
  @staticmethod
236
- def load_files_for_sending_lazy(files: List[str], workspace: str = None, max_open_files: int = 100, base_path: str = None, base_paths: List[str] = None) -> List[Tuple[str, Tuple[str, LazyFileLoader]]]:
236
+ def load_files_for_sending_lazy(files: List[str], workspace: Optional[str] = None, max_open_files: int = 100, base_path: Optional[str] = None, base_paths: Optional[List[str]] = None) -> List[Tuple[str, Tuple[str, LazyFileLoader]]]:
237
237
  """
238
238
  Prepares files for sending to the Socket API using lazy loading.
239
239
 
@@ -268,78 +268,75 @@ class Utils:
268
268
  # Normalize file path
269
269
  if "\\" in file_path:
270
270
  file_path = file_path.replace("\\", "/")
271
-
272
- for file_path in files:
273
- # Normalize file path
274
- if "\\" in file_path:
275
- file_path = file_path.replace("\\", "/")
276
271
 
277
- # Skip directories
278
- if os.path.isdir(file_path):
279
- continue
272
+ # Skip directories
273
+ if os.path.isdir(file_path):
274
+ continue
280
275
 
281
- # Handle file path splitting safely
282
- if "/" in file_path:
283
- _, name = file_path.rsplit("/", 1)
284
- else:
285
- name = file_path
276
+ # Handle file path splitting safely
277
+ if "/" in file_path:
278
+ _, name = file_path.rsplit("/", 1)
279
+ else:
280
+ name = file_path
286
281
 
287
- # Calculate the key name for the form data
288
- key = file_path
289
- path_stripped = False
282
+ # Calculate the key name for the form data
283
+ key = file_path
284
+ path_stripped = False
290
285
 
291
- # If base_paths is provided, try to strip one of the paths from the file path
292
- if base_paths:
293
- for bp in base_paths:
294
- normalized_base_path = bp.rstrip("/") + "/" if not bp.endswith("/") else bp
295
- if key.startswith(normalized_base_path):
296
- key = key[len(normalized_base_path):]
297
- path_stripped = True
298
- break
299
- elif key.startswith(bp.rstrip("/")):
300
- stripped_base = bp.rstrip("/")
301
- if key.startswith(stripped_base + "/") or key == stripped_base:
302
- key = key[len(stripped_base):]
303
- key = key.lstrip("/")
304
- path_stripped = True
305
- break
306
- elif base_path:
307
- normalized_base_path = base_path.rstrip("/") + "/" if not base_path.endswith("/") else base_path
286
+ # If base_paths is provided, try to strip one of the paths from the file path
287
+ if base_paths:
288
+ for bp in base_paths:
289
+ normalized_base_path = bp.rstrip("/") + "/" if not bp.endswith("/") else bp
308
290
  if key.startswith(normalized_base_path):
309
291
  key = key[len(normalized_base_path):]
310
292
  path_stripped = True
311
- elif key.startswith(base_path.rstrip("/")):
312
- stripped_base = base_path.rstrip("/")
293
+ break
294
+ elif key.startswith(bp.rstrip("/")):
295
+ stripped_base = bp.rstrip("/")
313
296
  if key.startswith(stripped_base + "/") or key == stripped_base:
314
297
  key = key[len(stripped_base):]
315
298
  key = key.lstrip("/")
316
299
  path_stripped = True
317
-
318
- # If workspace is provided and no base paths matched, fall back to workspace logic
319
- if not path_stripped and workspace and file_path.startswith(workspace):
320
- key = file_path[len(workspace):]
321
- # Remove all leading slashes (for absolute paths)
322
- while key.startswith("/"):
323
- key = key[1:]
300
+ break
301
+ elif base_path:
302
+ normalized_base_path = base_path.rstrip("/") + "/" if not base_path.endswith("/") else base_path
303
+ if key.startswith(normalized_base_path):
304
+ key = key[len(normalized_base_path):]
324
305
  path_stripped = True
306
+ elif key.startswith(base_path.rstrip("/")):
307
+ stripped_base = base_path.rstrip("/")
308
+ if key.startswith(stripped_base + "/") or key == stripped_base:
309
+ key = key[len(stripped_base):]
310
+ key = key.lstrip("/")
311
+ path_stripped = True
312
+
313
+ # If workspace is provided and no base paths matched, fall back to workspace logic
314
+ if not path_stripped and workspace and file_path.startswith(workspace):
315
+ key = file_path[len(workspace):]
316
+ # Remove all leading slashes (for absolute paths)
317
+ while key.startswith("/"):
318
+ key = key[1:]
319
+ path_stripped = True
320
+
321
+ # Clean up relative path prefixes, but preserve filename dots
322
+ while key.startswith("./"):
323
+ key = key[2:]
324
+ while key.startswith("../"):
325
+ key = key[3:]
326
+ # Remove any remaining leading slashes (for absolute paths)
327
+ while key.startswith("/"):
328
+ key = key[1:]
325
329
 
326
- # Clean up relative path prefixes, but preserve filename dots
327
- while key.startswith("./"):
328
- key = key[2:]
329
- while key.startswith("../"):
330
- key = key[3:]
331
- # Remove any remaining leading slashes (for absolute paths)
330
+ # Remove Windows drive letter if present (C:/...)
331
+ if len(key) > 2 and key[1] == ':' and (key[2] == '/' or key[2] == '\\'):
332
+ key = key[2:]
332
333
  while key.startswith("/"):
333
334
  key = key[1:]
334
335
 
335
- # Remove Windows drive letter if present (C:/...)
336
- if len(key) > 2 and key[1] == ':' and (key[2] == '/' or key[2] == '\\'):
337
- key = key[2:]
338
- while key.startswith("/"):
339
- key = key[1:]
336
+ # Create lazy file loader instead of opening file immediately
337
+ lazy_file = LazyFileLoader(file_path, key)
338
+ payload = (key, (key, lazy_file))
339
+ send_files.append(payload)
340
340
 
341
- # Create lazy file loader instead of opening file immediately
342
- lazy_file = LazyFileLoader(file_path, key)
343
- payload = (key, (key, lazy_file))
344
- send_files.append(payload)
345
- return send_files
341
+ log.debug(f"Prepared {len(send_files)} files for lazy loading")
342
+ return send_files
@@ -0,0 +1 @@
1
+ __version__ = "3.0.17"
@@ -0,0 +1,179 @@
1
+ import os
2
+ import tempfile
3
+ import unittest
4
+ from unittest.mock import Mock, patch, mock_open
5
+ from socketdev.uploadmanifests import UploadManifests
6
+
7
+
8
+ class TestUploadManifests(unittest.TestCase):
9
+ def setUp(self):
10
+ self.mock_api = Mock()
11
+ self.upload_manifests = UploadManifests(self.mock_api)
12
+
13
+ def test_calculate_key_name_with_base_path(self):
14
+ """Test that key names are calculated correctly with base_path."""
15
+ # Test with base_path
16
+ key = self.upload_manifests._calculate_key_name(
17
+ "/project/frontend/package.json",
18
+ base_path="/project"
19
+ )
20
+ self.assertEqual(key, "frontend/package.json")
21
+
22
+ def test_calculate_key_name_with_workspace(self):
23
+ """Test that key names are calculated correctly with workspace."""
24
+ # Test with workspace
25
+ key = self.upload_manifests._calculate_key_name(
26
+ "/project/frontend/package.json",
27
+ workspace="/project/"
28
+ )
29
+ self.assertEqual(key, "frontend/package.json")
30
+
31
+ def test_calculate_key_name_with_base_paths(self):
32
+ """Test that key names are calculated correctly with base_paths."""
33
+ # Test with base_paths (takes precedence over base_path)
34
+ key = self.upload_manifests._calculate_key_name(
35
+ "/project/frontend/package.json",
36
+ base_path="/project",
37
+ base_paths=["/different", "/project"]
38
+ )
39
+ self.assertEqual(key, "frontend/package.json")
40
+
41
+ def test_calculate_key_name_no_stripping(self):
42
+ """Test that key names default to basename when no stripping options provided."""
43
+ # Test without any path stripping - should preserve relative path structure
44
+ key = self.upload_manifests._calculate_key_name(
45
+ "frontend/package.json"
46
+ )
47
+ self.assertEqual(key, "frontend/package.json")
48
+
49
+ def test_calculate_key_name_absolute_path_no_stripping(self):
50
+ """Test that absolute paths get cleaned up when no stripping options provided."""
51
+ key = self.upload_manifests._calculate_key_name(
52
+ "/absolute/path/frontend/package.json"
53
+ )
54
+ self.assertEqual(key, "absolute/path/frontend/package.json")
55
+
56
+ def test_calculate_key_name_windows_paths(self):
57
+ """Test that Windows paths are handled correctly."""
58
+ key = self.upload_manifests._calculate_key_name(
59
+ "C:\\project\\frontend\\package.json",
60
+ base_path="C:\\project"
61
+ )
62
+ self.assertEqual(key, "frontend/package.json")
63
+
64
+ @patch('socketdev.uploadmanifests.Utils.load_files_for_sending_lazy')
65
+ @patch('os.path.exists')
66
+ @patch('os.path.isfile')
67
+ def test_upload_manifest_files_lazy_loading(self, mock_isfile, mock_exists, mock_lazy_load):
68
+ """Test that lazy loading preserves key names correctly."""
69
+ # Setup mocks
70
+ mock_exists.return_value = True
71
+ mock_isfile.return_value = True
72
+ mock_lazy_load.return_value = [
73
+ ('frontend/package.json', ('frontend/package.json', Mock()))
74
+ ]
75
+ mock_response = Mock()
76
+ mock_response.status_code = 200
77
+ mock_response.json.return_value = {'tarHash': 'test_hash'}
78
+ self.mock_api.do_request.return_value = mock_response
79
+
80
+ # Test lazy loading
81
+ result = self.upload_manifests.upload_manifest_files(
82
+ "test_org",
83
+ ["/project/frontend/package.json"],
84
+ workspace="/project",
85
+ use_lazy_loading=True
86
+ )
87
+
88
+ self.assertEqual(result, 'test_hash')
89
+ mock_lazy_load.assert_called_once_with(
90
+ ["/project/frontend/package.json"],
91
+ workspace="/project",
92
+ base_path=None,
93
+ base_paths=None
94
+ )
95
+
96
+ @patch('builtins.open', new_callable=mock_open, read_data=b'{"name": "test"}')
97
+ @patch('os.path.exists')
98
+ @patch('os.path.isfile')
99
+ def test_upload_manifest_files_non_lazy_loading(self, mock_isfile, mock_exists, mock_file):
100
+ """Test that non-lazy loading produces same key names as lazy loading."""
101
+ # Setup mocks
102
+ mock_exists.return_value = True
103
+ mock_isfile.return_value = True
104
+ mock_response = Mock()
105
+ mock_response.status_code = 200
106
+ mock_response.json.return_value = {'tarHash': 'test_hash'}
107
+ self.mock_api.do_request.return_value = mock_response
108
+
109
+ # Test non-lazy loading with workspace
110
+ result = self.upload_manifests.upload_manifest_files(
111
+ "test_org",
112
+ ["frontend/package.json"],
113
+ workspace="/project",
114
+ use_lazy_loading=False
115
+ )
116
+
117
+ self.assertEqual(result, 'test_hash')
118
+
119
+ # Verify the API was called with the correct file structure
120
+ call_args = self.mock_api.do_request.call_args
121
+ files_arg = call_args[1]['files']
122
+ self.assertEqual(len(files_arg), 1)
123
+
124
+ # The key should be 'frontend/package.json' not just 'package.json'
125
+ key, (filename, content) = files_arg[0]
126
+ self.assertEqual(key, "frontend/package.json")
127
+ self.assertEqual(filename, "frontend/package.json")
128
+
129
+ @patch('builtins.open', new_callable=mock_open, read_data=b'{"name": "test"}')
130
+ @patch('os.path.exists')
131
+ @patch('os.path.isfile')
132
+ def test_upload_manifest_files_consistency_between_modes(self, mock_isfile, mock_exists, mock_file):
133
+ """Test that lazy and non-lazy loading produce identical key names."""
134
+ # Setup mocks
135
+ mock_exists.return_value = True
136
+ mock_isfile.return_value = True
137
+ mock_response = Mock()
138
+ mock_response.status_code = 200
139
+ mock_response.json.return_value = {'tarHash': 'test_hash'}
140
+ self.mock_api.do_request.return_value = mock_response
141
+
142
+ test_files = ["frontend/package.json", "backend/package.json"]
143
+
144
+ # Test non-lazy loading
145
+ with patch('socketdev.uploadmanifests.Utils.load_files_for_sending_lazy') as mock_lazy_load:
146
+ mock_lazy_load.return_value = [
147
+ ('frontend/package.json', ('frontend/package.json', Mock())),
148
+ ('backend/package.json', ('backend/package.json', Mock()))
149
+ ]
150
+
151
+ # Get lazy loading result
152
+ self.upload_manifests.upload_manifest_files(
153
+ "test_org",
154
+ test_files,
155
+ use_lazy_loading=True
156
+ )
157
+ lazy_call_args = self.mock_api.do_request.call_args[1]['files']
158
+
159
+ # Reset mock
160
+ self.mock_api.reset_mock()
161
+
162
+ # Get non-lazy loading result
163
+ self.upload_manifests.upload_manifest_files(
164
+ "test_org",
165
+ test_files,
166
+ use_lazy_loading=False
167
+ )
168
+ non_lazy_call_args = self.mock_api.do_request.call_args[1]['files']
169
+
170
+ # Compare key names - they should be identical
171
+ lazy_keys = [item[0] for item in lazy_call_args]
172
+ non_lazy_keys = [item[0] for item in non_lazy_call_args]
173
+
174
+ self.assertEqual(lazy_keys, non_lazy_keys)
175
+ self.assertEqual(non_lazy_keys, ['frontend/package.json', 'backend/package.json'])
176
+
177
+
178
+ if __name__ == '__main__':
179
+ unittest.main()
@@ -1 +0,0 @@
1
- __version__ = "3.0.14"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes