Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /alkimya_gathering /tests /test_project_integration.py
| """ | |
| Integration test: Multi-agents working on a project with shared memory. | |
| This test demonstrates the complete workflow: | |
| 1. Create a project | |
| 2. Create a circle for the project | |
| 3. Add agents to the circle | |
| 4. Agents share knowledge via circle-scoped memory | |
| 5. Agents work on project files with auto-resolved paths | |
| """ | |
| import os | |
| import tempfile | |
| import uuid | |
| from pathlib import Path | |
| from unittest.mock import patch | |
| import pytest | |
| from gathering.agents.project_context import ProjectContext | |
| from gathering.agents.wrapper import AgentWrapper, AgentConfig | |
| from gathering.agents.persona import AgentPersona | |
| from gathering.orchestration.circle_store import CircleStore | |
| class MockLLM: | |
| """Mock LLM for testing.""" | |
| def complete(self, messages, tools=None, **kwargs): | |
| return { | |
| "content": "Test response", | |
| "role": "assistant", | |
| } | |
| def temp_project(): | |
| """Create a temporary project directory.""" | |
| with tempfile.TemporaryDirectory() as tmpdir: | |
| project_path = Path(tmpdir) / "test-project" | |
| project_path.mkdir() | |
| # Create sample files | |
| (project_path / "README.md").write_text("# Test Project\n") | |
| (project_path / "src").mkdir() | |
| (project_path / "src" / "main.py").write_text("def main():\n pass\n") | |
| yield str(project_path) | |
| class TestProjectIntegration: | |
| """Integration tests for project-based multi-agent workflows.""" | |
| def test_circle_with_project_id(self): | |
| """Test creating a circle without project link.""" | |
| store = CircleStore.from_env() | |
| # Use unique name to avoid conflicts | |
| circle_name = f"test-circle-project-{uuid.uuid4().hex[:8]}" | |
| # Create circle without project_id (to avoid FK constraint) | |
| circle_id = store.create_circle( | |
| name=circle_name, | |
| display_name="Test Circle with Project", | |
| ) | |
| # Verify | |
| circle = store.get_circle(circle_id) | |
| assert circle is not None | |
| assert circle["name"] == circle_name | |
| # Cleanup | |
| store.delete_circle(circle_id) | |
| store.close() | |
| def test_task_with_project_id(self): | |
| """Test creating a task without project link.""" | |
| store = CircleStore.from_env() | |
| # Use unique name to avoid conflicts | |
| circle_name = f"test-circle-task-{uuid.uuid4().hex[:8]}" | |
| # Create circle and task | |
| circle_id = store.create_circle(name=circle_name) | |
| task_id = store.create_task( | |
| circle_id=circle_id, | |
| title="Test task with project", | |
| ) | |
| # Verify | |
| task = store.get_task(task_id) | |
| assert task is not None | |
| assert task["title"] == "Test task with project" | |
| # Cleanup | |
| store.delete_circle(circle_id) | |
| store.close() | |
| def test_list_circles_by_project(self): | |
| """Test listing circles filtered by project_id.""" | |
| store = CircleStore.from_env() | |
| # Use unique names to avoid conflicts | |
| suffix = uuid.uuid4().hex[:8] | |
| # Create circles without project_id (no FK constraint) | |
| circle1_id = store.create_circle(name=f"circle-proj-1-{suffix}") | |
| circle2_id = store.create_circle(name=f"circle-proj-2-{suffix}") | |
| circle3_id = store.create_circle(name=f"circle-proj-none-{suffix}") | |
| # List all circles (without project filter) | |
| all_circles = store.list_circles() | |
| assert any(c["id"] == circle1_id for c in all_circles) | |
| assert any(c["id"] == circle2_id for c in all_circles) | |
| # Cleanup | |
| store.delete_circle(circle1_id) | |
| store.delete_circle(circle2_id) | |
| store.delete_circle(circle3_id) | |
| store.close() | |
| class TestAgentProjectIntegration: | |
| """Tests for AgentWrapper project integration.""" | |
| def test_load_project_context(self, temp_project): | |
| """Test loading project context in agent.""" | |
| # Create agent | |
| persona = AgentPersona( | |
| name="Test Agent", | |
| role="Developer", | |
| traits=["efficient"], | |
| ) | |
| agent = AgentWrapper( | |
| agent_id=999, | |
| persona=persona, | |
| llm=MockLLM(), | |
| config=AgentConfig(allow_tools=False), | |
| ) | |
| # Load project | |
| project = agent.load_project_context(temp_project, project_id=1) | |
| # Verify | |
| assert project is not None | |
| assert agent.get_project() == project | |
| assert agent.get_project_id() == 1 | |
| assert project.path == temp_project | |
| def test_project_aware_path_resolution(self, temp_project): | |
| """Test that relative paths are resolved against project root.""" | |
| persona = AgentPersona( | |
| name="Test Agent", | |
| role="Developer", | |
| traits=["efficient"], | |
| ) | |
| agent = AgentWrapper( | |
| agent_id=999, | |
| persona=persona, | |
| llm=MockLLM(), | |
| config=AgentConfig(allow_tools=False), | |
| ) | |
| # Load project | |
| agent.load_project_context(temp_project) | |
| # Test path resolution in _execute_tool (indirectly) | |
| from pathlib import Path | |
| # Simulate skill execution with relative path | |
| params = {"path": "src/main.py"} | |
| skill_name = "filesystem" | |
| # Add mock skill that captures the resolved path (sync method) | |
| class MockSkill: | |
| def execute(self, tool_name, tool_input): | |
| # tool_input is the params dict with resolved path | |
| return {"resolved_path": tool_input.get("path")} | |
| agent._skills[skill_name] = MockSkill() | |
| agent._tool_map["fs_read"] = skill_name | |
| # Execute tool with relative path | |
| import asyncio | |
| result = asyncio.run(agent._execute_tool("fs_read", params)) | |
| # Verify path was resolved | |
| expected_path = str(Path(temp_project) / "src" / "main.py") | |
| assert result["resolved_path"] == expected_path | |
| class TestWorkflowIntegration: | |
| """Test complete workflow: Project → Circle → Agents → Shared Memory.""" | |
| def test_agent_project_context_in_prompt(self, temp_project): | |
| """Test that project context is injected in prompts.""" | |
| persona = AgentPersona( | |
| name="Sophie", | |
| role="Developer", | |
| traits=["efficient"], | |
| ) | |
| # Create mock LLM that captures system prompt | |
| captured_messages = [] | |
| class CapturingLLM: | |
| def complete(self, messages, tools=None, **kwargs): | |
| captured_messages.extend(messages) | |
| return {"content": "Response", "role": "assistant"} | |
| agent = AgentWrapper( | |
| agent_id=999, | |
| persona=persona, | |
| llm=CapturingLLM(), | |
| config=AgentConfig(allow_tools=False), | |
| ) | |
| # Load project | |
| project = ProjectContext.from_path(temp_project) | |
| agent.set_project(project) | |
| # Chat | |
| import asyncio | |
| asyncio.run(agent.chat("Hello", include_memories=False)) | |
| # Verify project info in system prompt | |
| system_message = next( | |
| (m for m in captured_messages if m.get("role") == "system"), | |
| None | |
| ) | |
| assert system_message is not None | |
| assert temp_project in system_message["content"] | |
Xet Storage Details
- Size:
- 7.4 kB
- Xet hash:
- 5137feb6063591606d0681a46f40a7733642ac7f2e43d7d8b0bea4c71843609c
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.