Skip to content

Commit 79d247d

Browse files
committed
Fixed test cases and minor issues in logic
1 parent 415560e commit 79d247d

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/sentry/integrations/utils/code_mapping.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ def __init__(self, frame_file_path: str) -> None:
8686
# Remove drive letter if it exists
8787
if is_windows_path and frame_file_path[1] == ":":
8888
frame_file_path = frame_file_path[2:]
89+
# windows drive letters can be like C:\ or C:
90+
# so we need to remove the slash if it exists
91+
if frame_file_path[0] == "/":
92+
frame_file_path = frame_file_path[1:]
8993

9094
start_at_index = get_straight_path_prefix_end_index(frame_file_path)
9195
self.straight_path_prefix = frame_file_path[:start_at_index]
@@ -157,7 +161,7 @@ def list_file_matches(self, frame_filename: FrameFilename) -> list[dict[str, str
157161
)
158162
continue
159163

160-
if stack_path.replace(stack_root, source_root, 1) != source_path:
164+
if stack_path.replace(stack_root, source_root, 1).replace("\\", "/") != source_path:
161165
logger.info(
162166
"Unexpected stack_path/source_path found. A code mapping was not generated.",
163167
extra={
@@ -271,7 +275,7 @@ def _generate_code_mapping_from_tree(
271275
)
272276
return []
273277

274-
if stack_path.replace(stack_root, source_root, 1) != source_path:
278+
if stack_path.replace(stack_root, source_root, 1).replace("\\", "/") != source_path:
275279
logger.info(
276280
"Unexpected stack_path/source_path found. A code mapping was not generated.",
277281
extra={
@@ -521,8 +525,8 @@ def find_roots(stack_path: str, source_path: str) -> tuple[str, str]:
521525
If there is no overlap, raise an exception since this should not happen
522526
"""
523527
stack_root = ""
524-
if stack_path[0] == "/":
525-
stack_root += "/"
528+
if stack_path[0] == "/" or stack_path[0] == "\\":
529+
stack_root += stack_path[0]
526530
stack_path = stack_path[1:]
527531

528532
if stack_path == source_path:
@@ -550,7 +554,7 @@ def find_roots(stack_path: str, source_path: str) -> tuple[str, str]:
550554
source_root = source_path.rpartition(overlap)[0]
551555
stack_root += stack_path_delim.join(stack_root_items)
552556

553-
if stack_root and stack_root[-1] != SLASH: # append trailing slash
557+
if stack_root and stack_root[-1] != stack_path_delim: # append trailing slash
554558
stack_root = f"{stack_root}{stack_path_delim}"
555559
if source_root and source_root[-1] != SLASH:
556560
source_root = f"{source_root}{SLASH}"

tests/sentry/integrations/utils/test_code_mapping.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"README", # no extension
4949
"ssl.py",
5050
# XXX: The following will need to be supported
51-
"C:\\Users\\Donia\\AppData\\Roaming\\Adobe\\UXP\\Plugins\\External\\452f92d2_0.13.0\\main.js",
5251
"initialization.dart",
5352
"backburner.js",
5453
]

tests/sentry/tasks/test_derive_code_mappings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def setUp(self):
105105
[
106106
{"in_app": True, "filename": "\\sentry\\mouse.py"},
107107
{"in_app": True, "filename": "\\sentry\\dog\\cat\\parrot.py"},
108-
{"in_app": True, "filename": "C:\\sentry\\tasks.py"},
108+
{"in_app": True, "filename": "C:sentry\\tasks.py"},
109109
{"in_app": True, "filename": "D:\\Users\\code\\sentry\\models\\release.py"},
110110
]
111111
)
@@ -136,8 +136,8 @@ def test_backslash_drive_letter_filename_simple(self):
136136
}
137137
derive_code_mappings(self.project.id, self.event_data)
138138
code_mapping = RepositoryProjectPathConfig.objects.all()[0]
139-
assert code_mapping.stack_root == "C:\\"
140-
assert code_mapping.source_root == ""
139+
assert code_mapping.stack_root == "C:sentry\\"
140+
assert code_mapping.source_root == "sentry/"
141141
assert code_mapping.repository.name == repo_name
142142

143143
@responses.activate
@@ -151,8 +151,8 @@ def test_backslash_drive_letter_filename_monorepo(self):
151151
}
152152
derive_code_mappings(self.project.id, self.event_data)
153153
code_mapping = RepositoryProjectPathConfig.objects.all()[0]
154-
assert code_mapping.stack_root == "C:\\sentry\\"
155-
assert code_mapping.source_root == "src/"
154+
assert code_mapping.stack_root == "C:sentry\\"
155+
assert code_mapping.source_root == "src/sentry/"
156156
assert code_mapping.repository.name == repo_name
157157

158158
@responses.activate

0 commit comments

Comments
 (0)