mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
1ef24d3e91
* add initial backend service code for devui * add tests * add frontendcode * ui updates * update readme * ui updates and tweaks * update ui bundle * improve ui, add react flow base * add react flow ui, fix background * update ui, fix introspection bug * update readme * update ui build * add support for multimodal input - both backend and frontend * update ui build * refactor as main framework package * backend and tests refactor * ui build update * ui build update and refactor * update pyproject.toml, update uv.lock * update ui build * ui update to fit oai responses types * add backend updat and readme update * mypy and other fixes * add intial dev guide * update ui and fix workflow bug * update ui build, add thread support * type fixes * update workflow view * update uv.lock * fix workflow iport errors * lint and other fixes * mypy fixes * minor update * update ui build * refactor to use oai dependencies directly, update examples to samples, improve typing * readme update * update ui and ui build * fix workflow pyright error * update ui, fix issues with run workflow placement, miniamp menu, etc * make samples integrate serve --------- Co-authored-by: Chris <66376200+crickman@users.noreply.github.com> Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
102 lines
3.2 KiB
Python
102 lines
3.2 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
"""Focused tests for entity discovery functionality."""
|
|
|
|
import asyncio
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from agent_framework_devui._discovery import EntityDiscovery
|
|
|
|
|
|
@pytest.fixture
|
|
def test_entities_dir():
|
|
"""Use the samples directory which has proper entity structure."""
|
|
# Get the samples directory relative to the current test file
|
|
current_dir = Path(__file__).parent
|
|
samples_dir = current_dir.parent / "samples"
|
|
return str(samples_dir.resolve())
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_discover_agents(test_entities_dir):
|
|
"""Test that agent discovery works and returns valid agent entities."""
|
|
discovery = EntityDiscovery(test_entities_dir)
|
|
entities = await discovery.discover_entities()
|
|
|
|
agents = [e for e in entities if e.type == "agent"]
|
|
|
|
# Test that we can discover agents (not specific count)
|
|
assert len(agents) > 0, "Should discover at least one agent"
|
|
|
|
# Test agent structure/properties
|
|
for agent in agents:
|
|
assert agent.id, "Agent should have an ID"
|
|
assert agent.name, "Agent should have a name"
|
|
assert agent.type == "agent", "Should be identified as agent type"
|
|
assert hasattr(agent, "description"), "Agent should have description attribute"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_discover_workflows(test_entities_dir):
|
|
"""Test that workflow discovery works and returns valid workflow entities."""
|
|
discovery = EntityDiscovery(test_entities_dir)
|
|
entities = await discovery.discover_entities()
|
|
|
|
workflows = [e for e in entities if e.type == "workflow"]
|
|
|
|
# Test that we can discover workflows (not specific count)
|
|
assert len(workflows) > 0, "Should discover at least one workflow"
|
|
|
|
# Test workflow structure/properties
|
|
for workflow in workflows:
|
|
assert workflow.id, "Workflow should have an ID"
|
|
assert workflow.name, "Workflow should have a name"
|
|
assert workflow.type == "workflow", "Should be identified as workflow type"
|
|
assert hasattr(workflow, "description"), "Workflow should have description attribute"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_empty_directory():
|
|
"""Test discovery with empty directory."""
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
discovery = EntityDiscovery(temp_dir)
|
|
entities = await discovery.discover_entities()
|
|
|
|
assert len(entities) == 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Simple test runner
|
|
async def run_tests():
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
temp_path = Path(temp_dir)
|
|
|
|
# Create test files
|
|
agent_file = temp_path / "test_agent.py"
|
|
agent_file.write_text("""
|
|
class WeatherAgent:
|
|
name = "Weather Agent"
|
|
description = "Gets weather information"
|
|
|
|
def run_stream(self, input_str):
|
|
return f"Weather in {input_str}"
|
|
""")
|
|
|
|
workflow_file = temp_path / "test_workflow.py"
|
|
workflow_file.write_text("""
|
|
class DataWorkflow:
|
|
name = "Data Processing Workflow"
|
|
description = "Processes data"
|
|
|
|
def run(self, data):
|
|
return f"Processed {data}"
|
|
""")
|
|
|
|
discovery = EntityDiscovery(str(temp_path))
|
|
await discovery.discover_entities()
|
|
|
|
asyncio.run(run_tests())
|