fix: image not been sent on ChatInputComponent during runtime of building a flow (#3862)

* refactor: Refactor file path rewriting logic

This commit refactors the logic for rewriting file paths in the `rewrite_file_path` function. The function now splits the file path by "/" and checks if it has at least two parts. If it does, it creates a consistent file path by concatenating the last two parts. If not, it returns the original file path. This change improves the consistency of file paths in the codebase.

Refactor the file path rewriting logic in the `rewrite_file_path` function.

* refactor: Refactor file path rewriting logic and treat file paths in InterfaceVertex

* Refactor file path rewriting logic and treat file paths in InterfaceVertex

* Refactor file path rewriting logic and treat file paths in InterfaceVertex

* Refactor file path rewriting logic and treat file paths in InterfaceVertex

* ✨ (general-bugs-shard-3836.spec.ts): update test description to be more specific about the tool used for sending images on chat
📝 (general-bugs-shard-3836.spec.ts): remove unused import of readFileSync from fs module

* ✅ (test_rewrite_file_path.py): add unit tests for the rewrite_file_path function to ensure correct behavior with various file path scenarios

* ♻️ (utils.py): refactor file_path function to handle both forward and backward slashes and extract file path after drive letter if present

* style: fix single quotes, commas, and spaces

---------

Co-authored-by: italojohnny <italojohnnydosanjos@gmail.com>
This commit is contained in:
Cristhian Zanforlin Lousa 2024-09-23 12:19:09 -03:00 • committed by GitHub
commit ad97ee9830
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 192 additions and 2 deletions

View file

@ -0,0 +1,43 @@
from langflow.graph.utils import rewrite_file_path
import pytest
@pytest.mark.parametrize(
"file_path, expected",
[
# Test case 1: Standard path with multiple directories
("/home/user/documents/file.txt", ["documents/file.txt"]),
# Test case 2: Path with only one directory
("/documents/file.txt", ["documents/file.txt"]),
# Test case 3: Path with no directories (just filename)
("file.txt", ["file.txt"]),
# Test case 4: Path with multiple levels and special characters
("/home/user/my-docs/special_file!.pdf", ["my-docs/special_file!.pdf"]),
# Test case 5: Path with trailing slash
("/home/user/documents/", ["user/documents"]),
# Test case 6: Empty path
("", [""]),
# Test case 7: Path with only slashes
("///", [""]),
# Test case 8: Path with dots
("/home/user/../documents/./file.txt", ["./file.txt"]),
# Test case 9: Windows-style path
("C:\\Users\\Documents\\file.txt", ["Documents/file.txt"]),
# Test case 10: Windows path with trailing backslash
("C:\\Users\\Documents\\", ["Users/Documents"]),
# Test case 11: Mixed separators
("C:/Users\\Documents/file.txt", ["Documents/file.txt"]),
# Test case 12: Network path (UNC)
("\\\\server\\share\\file.txt", ["share/file.txt"]),
],
)
def test_rewrite_file_path(file_path, expected):
result = rewrite_file_path(file_path)
assert result == expected
# Additional test for type checking
def test_rewrite_file_path_type():
result = rewrite_file_path("/home/user/file.txt")
assert isinstance(result, list)
assert all(isinstance(item, str) for item in result)