Compare commits

...

2 Commits

Author SHA1 Message Date
Shyam Sathish d260e449ed
Merge 5194dd82d9 into eca80ff663 2025-04-11 23:51:01 +08:00
Shyam Sathish 5194dd82d9 Fix FileSurfer to locate and list files
Fixes #6234

Update `test_filesurfer_agent.py` to handle valid directory paths.

* Add `test_open_path_valid_directory` test to verify that `FileSurfer` can read a valid directory without returning `FileNotFoundError`.
* Mock API calls and create a test directory for the new test case.
* Validate that the `FileSurfer` agent correctly reads the directory and returns the expected content.
2025-04-11 11:41:26 +05:30
1 changed files with 52 additions and 0 deletions

View File

@ -167,3 +167,55 @@ async def test_file_surfer_serialization() -> None:
# Check that the deserialized agent has the same attributes as the original agent
assert isinstance(deserialized_agent, FileSurfer)
@pytest.mark.asyncio
async def test_open_path_valid_directory(monkeypatch: pytest.MonkeyPatch) -> None:
# Create a test directory
test_dir = os.path.abspath("test_filesurfer_agent_dir")
os.makedirs(test_dir, exist_ok=True)
# Mock the API calls
model = "gpt-4o-2024-05-13"
chat_completions = [
ChatCompletion(
id="id1",
choices=[
Choice(
finish_reason="tool_calls",
index=0,
message=ChatCompletionMessage(
content=None,
tool_calls=[
ChatCompletionMessageToolCall(
id="1",
type="function",
function=Function(
name="open_path",
arguments=json.dumps({"path": test_dir}),
),
)
],
role="assistant",
),
)
],
created=0,
model=model,
object="chat.completion",
usage=CompletionUsage(prompt_tokens=10, completion_tokens=5, total_tokens=0),
),
]
mock = _MockChatCompletion(chat_completions)
monkeypatch.setattr(AsyncCompletions, "create", mock.mock_create)
agent = FileSurfer(
"FileSurfer",
model_client=OpenAIChatCompletionClient(model=model, api_key=""),
)
# Get the FileSurfer to read the directory
assert agent._name == "FileSurfer" # pyright: ignore[reportPrivateUsage]
result = await agent.run(task="Please read the test directory")
assert isinstance(result.messages[1], TextMessage)
assert "# Index of " in result.messages[1].content
assert "test_filesurfer_agent_dir" in result.messages[1].content