Skip to content

Commit c856f1e

Browse files
committed
fix a bug
1 parent 81f96ed commit c856f1e

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

codeflash/context/code_context_extractor.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,14 @@ def extract_code_markdown_context_from_files(
322322
continue
323323
if code_context.strip():
324324
if code_context_type != CodeContextType.HASHING:
325-
code_context = (
326-
add_needed_imports_from_module(
327-
src_module_code=original_code,
328-
dst_module_code=code_context,
329-
src_path=file_path,
330-
dst_path=file_path,
331-
project_root=project_root_path,
332-
helper_functions=list(
333-
helpers_of_fto.get(file_path, set()) | helpers_of_helpers.get(file_path, set())
334-
),
325+
code_context = add_needed_imports_from_module(
326+
src_module_code=original_code,
327+
dst_module_code=code_context,
328+
src_path=file_path,
329+
dst_path=file_path,
330+
project_root=project_root_path,
331+
helper_functions=list(
332+
helpers_of_fto.get(file_path, set()) | helpers_of_helpers.get(file_path, set())
335333
),
336334
)
337335
code_string_context = CodeString(code=code_context, file_path=file_path.relative_to(project_root_path))
@@ -357,15 +355,13 @@ def extract_code_markdown_context_from_files(
357355

358356
if code_context.strip():
359357
if code_context_type != CodeContextType.HASHING:
360-
code_context = (
361-
add_needed_imports_from_module(
362-
src_module_code=original_code,
363-
dst_module_code=code_context,
364-
src_path=file_path,
365-
dst_path=file_path,
366-
project_root=project_root_path,
367-
helper_functions=list(helpers_of_helpers_no_overlap.get(file_path, set())),
368-
),
358+
code_context = add_needed_imports_from_module(
359+
src_module_code=original_code,
360+
dst_module_code=code_context,
361+
src_path=file_path,
362+
dst_path=file_path,
363+
project_root=project_root_path,
364+
helper_functions=list(helpers_of_helpers_no_overlap.get(file_path, set())),
369365
)
370366
code_string_context = CodeString(code=code_context, file_path=file_path.relative_to(project_root_path))
371367
code_context_markdown.code_strings.append(code_string_context)

tests/test_git_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,35 @@ class TestGitUtils(unittest.TestCase):
1111
def test_test_get_repo_owner_and_name(self, mock_get_remote_url):
1212
# Test with a standard GitHub HTTPS URL
1313
mock_get_remote_url.return_value = "https://github.com/owner/repo.git"
14+
get_repo_owner_and_name.cache_clear()
1415
owner, repo_name = get_repo_owner_and_name()
1516
assert owner == "owner"
1617
assert repo_name == "repo"
1718

1819
# Test with a GitHub SSH URL
1920
mock_get_remote_url.return_value = "[email protected]:owner/repo.git"
21+
get_repo_owner_and_name.cache_clear()
2022
owner, repo_name = get_repo_owner_and_name()
2123
assert owner == "owner"
2224
assert repo_name == "repo"
2325

2426
# Test with another GitHub SSH URL
2527
mock_get_remote_url.return_value = "[email protected]:codeflash-ai/posthog.git"
28+
get_repo_owner_and_name.cache_clear()
2629
owner, repo_name = get_repo_owner_and_name()
2730
assert owner == "codeflash-ai"
2831
assert repo_name == "posthog"
2932

3033
# Test with a URL without the .git suffix
3134
mock_get_remote_url.return_value = "https://github.com/owner/repo"
35+
get_repo_owner_and_name.cache_clear()
3236
owner, repo_name = get_repo_owner_and_name()
3337
assert owner == "owner"
3438
assert repo_name == "repo"
3539

3640
# Test with another GitHub SSH URL
3741
mock_get_remote_url.return_value = "[email protected]:codeflash-ai/posthog/"
42+
get_repo_owner_and_name.cache_clear()
3843
owner, repo_name = get_repo_owner_and_name()
3944
assert owner == "codeflash-ai"
4045
assert repo_name == "posthog"

0 commit comments

Comments
 (0)