Skip to content

Commit d6becd8

Browse files
author
Taniya Mathur
committed
fix: correct path parsing in test_set_file_copier for nested directory structures
- Fix path_parts[2] bug in _copy_baseline_from_testset function - Fix same bug in handler baseline validation logic - Use '/'.join(path_parts[2:]) to preserve full nested paths - Add unit test for baseline path extraction logic - Resolves performance issues with testset baseline copying
1 parent 402a99b commit d6becd8

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/idp_common_pkg/tests/unit/test_test_set_file_copier.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,35 @@ def test_path_extraction_logic():
2525
assert dest_key == expected
2626

2727

28+
@pytest.mark.unit
29+
def test_baseline_path_extraction_logic():
30+
"""Test the path extraction logic for baseline files from testset bucket"""
31+
# Simulate the path extraction logic from _copy_baseline_from_testset
32+
file_key = "fcc_benchmark/input/fcc_benchmark/033f718b16cb597c065930410752c294.pdf"
33+
test_set_id = "demo_test_set"
34+
35+
# Extract test set name and file name from path (format: test_set_name/input/file_name)
36+
path_parts = file_key.split("/")
37+
if len(path_parts) >= 3 and path_parts[1] == "input":
38+
source_test_set_name = path_parts[0]
39+
file_name = "/".join(path_parts[2:]) # Get full path after 'input/'
40+
41+
# Source baseline path in testset bucket
42+
source_baseline_prefix = f"{source_test_set_name}/baseline/{file_name}/"
43+
# Destination baseline path
44+
dest_baseline_prefix = f"{test_set_id}/baseline/{file_name}/"
45+
46+
expected_source = (
47+
"fcc_benchmark/baseline/fcc_benchmark/033f718b16cb597c065930410752c294.pdf/"
48+
)
49+
expected_dest = (
50+
"demo_test_set/baseline/fcc_benchmark/033f718b16cb597c065930410752c294.pdf/"
51+
)
52+
53+
assert source_baseline_prefix == expected_source
54+
assert dest_baseline_prefix == expected_dest
55+
56+
2857
@pytest.mark.unit
2958
def test_path_extraction_edge_cases():
3059
"""Test edge cases for path extraction"""

src/lambda/test_set_file_copier/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def handler(event, context):
6060
path_parts = file_key.split('/')
6161
if len(path_parts) >= 3 and path_parts[1] == 'input':
6262
test_set_name = path_parts[0]
63-
file_name = path_parts[2]
63+
file_name = '/'.join(path_parts[2:]) # Get full path after 'input/'
6464
baseline_prefix = f"{test_set_name}/baseline/{file_name}/"
6565
baseline_check_bucket = source_bucket
6666
else:
@@ -185,7 +185,7 @@ def _copy_baseline_from_testset(test_set_id, files):
185185
path_parts = file_key.split('/')
186186
if len(path_parts) >= 3 and path_parts[1] == 'input':
187187
source_test_set_name = path_parts[0]
188-
file_name = path_parts[2]
188+
file_name = '/'.join(path_parts[2:]) # Get full path after 'input/'
189189

190190
# Source baseline path in testset bucket
191191
source_baseline_prefix = f"{source_test_set_name}/baseline/{file_name}/"

0 commit comments

Comments
 (0)