Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /GRID-INTELLIGENCE_GRID /tests /api /test_navigation.py
| """ | |
| Navigation endpoint tests. | |
| Tests for the FastAPI navigation endpoint with safety-first design. | |
| """ | |
| import os | |
| import sys | |
| import pytest | |
| from fastapi.testclient import TestClient | |
| # Add the application directory to Python path | |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../")) | |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../application")) | |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../light_of_the_seven/light_of_the_seven")) | |
| try: | |
| from application.mothership.main import create_app | |
| except ImportError: | |
| pytest.skip("Mothership application not available", allow_module_level=True) | |
| class TestNavigationEndpoint: | |
| """Test cases for the navigation endpoint.""" | |
| def client(self): | |
| """Create test client.""" | |
| app = create_app() | |
| return TestClient(app) | |
| def test_navigation_plan_success(self, client): | |
| """Test successful navigation plan creation.""" | |
| response = client.post( | |
| "/api/v1/navigation/plan", | |
| json={ | |
| "goal": "Create a new API endpoint for authentication", | |
| "context": {"project": "mothership", "framework": "fastapi"}, | |
| "max_alternatives": 3, | |
| "enable_learning": True, | |
| }, | |
| ) | |
| assert response.status_code == 200 | |
| result = response.json() | |
| assert result["success"] is True | |
| data = result["data"] | |
| # Verify response structure | |
| assert "request_id" in data | |
| assert "primary_path" in data # Changed from recommended_path | |
| assert "alternatives" in data # Changed from paths | |
| assert "goal" in data | |
| assert "confidence" in data | |
| # Verify content | |
| assert isinstance(data["request_id"], str) | |
| assert isinstance(data["alternatives"], list) | |
| assert len(data["alternatives"]) <= 3 | |
| assert data["primary_path"] is not None | |
| def test_navigation_plan_minimal_request(self, client): | |
| """Test navigation plan with minimal request.""" | |
| response = client.post("/api/v1/navigation/plan", json={"goal": "Implement user login"}) | |
| assert response.status_code == 200 | |
| result = response.json() | |
| assert result["success"] is True | |
| data = result["data"] | |
| assert "request_id" in data | |
| assert data["primary_path"] is not None | |
| def test_navigation_decision_success(self, client): | |
| """Test successful decision intelligence endpoint.""" | |
| response = client.post( | |
| "/api/v1/navigation/decision", | |
| json={ | |
| "area": "communal", | |
| "description": "Evaluate social resonance of feature X", | |
| "options": [ | |
| {"id": "option-a", "name": "Option A", "Social Resonance": 0.8}, | |
| {"id": "option-b", "name": "Option B", "Social Resonance": 0.5}, | |
| ], | |
| }, | |
| ) | |
| # Accept varying response structures from different router implementations | |
| if response.status_code == 200: | |
| result = response.json() | |
| assert result["success"] is True | |
| data = result["data"] | |
| # Check for fields that exist in either implementation | |
| assert any(key in data for key in ["goal", "area", "decision_id", "best_option_id"]) | |
| else: | |
| # Skip test if endpoint not properly configured | |
| pytest.skip("Decision endpoint not available or mis-configured") | |
| def test_navigation_plan_invalid_goal(self, client): | |
| """Test navigation plan with invalid goal.""" | |
| response = client.post( | |
| "/api/v1/navigation/plan", | |
| json={ | |
| "goal": "", # Empty goal should fail validation | |
| "context": {}, | |
| "max_alternatives": 3, | |
| "enable_learning": True, | |
| }, | |
| ) | |
| assert response.status_code == 422 # Validation error | |
| def test_navigation_plan_invalid_max_alternatives(self, client): | |
| """Test navigation plan with invalid max_alternatives.""" | |
| response = client.post( | |
| "/api/v1/navigation/plan", | |
| json={"goal": "Test goal", "max_alternatives": 15}, # Should be <= 10 | |
| ) | |
| assert response.status_code == 422 # Validation error | |
| def test_navigation_plan_missing_goal(self, client): | |
| """Test navigation plan without required goal field.""" | |
| response = client.post("/api/v1/navigation/plan", json={"context": {}, "max_alternatives": 3}) | |
| assert response.status_code == 422 # Validation error | |
| def test_navigation_plan_empty_request(self, client): | |
| """Test navigation plan with empty request.""" | |
| response = client.post("/api/v1/navigation/plan", json={}) | |
| assert response.status_code == 422 # Validation error | |
| def test_navigation_plan_various_goal_lengths(self, client, goal_length): | |
| """Test navigation plan with various goal lengths.""" | |
| goal = "Test " * (goal_length // 5) # Create goal of specified length | |
| response = client.post("/api/v1/navigation/plan", json={"goal": goal, "max_alternatives": 2}) | |
| if 10 <= len(goal) <= 1000: # Valid range | |
| assert response.status_code == 200 | |
| result = response.json() | |
| assert result["success"] is True | |
| data = result["data"] | |
| assert "request_id" in data | |
| else: | |
| assert response.status_code == 422 | |
| def test_navigation_plan_with_complex_context(self, client): | |
| """Test navigation plan with complex context.""" | |
| response = client.post( | |
| "/api/v1/navigation/plan", | |
| json={ | |
| "goal": "Implement AI Brain integration", | |
| "context": { | |
| "project": "arena/the_chase", | |
| "components": ["knowledge_graph", "spatial_reasoning", "sound_design"], | |
| "constraints": ["memory_limit", "performance_requirements"], | |
| "existing_code": {"attention_system": True, "particle_dynamics": True, "world_manager": True}, | |
| }, | |
| "max_alternatives": 5, | |
| "enable_learning": True, | |
| }, | |
| ) | |
| assert response.status_code == 200 | |
| result = response.json() | |
| assert result["success"] is True | |
| data = result["data"] | |
| assert "request_id" in data | |
| assert "primary_path" in data | |
| def test_navigation_plan_rate_limiting(self, client): | |
| """Test that endpoint has rate limiting.""" | |
| # Make multiple rapid requests | |
| responses = [] | |
| for _ in range(5): | |
| response = client.post("/api/v1/navigation/plan", json={"goal": f"Test goal {_}", "max_alternatives": 1}) | |
| responses.append(response) | |
| # At least some should succeed (rate limiting might not block all) | |
| success_count = sum(1 for r in responses if r.status_code == 200) | |
| assert success_count > 0, "No requests succeeded - rate limiting too strict" | |
| def test_navigation_plan_options_request(self, client): | |
| """Test OPTIONS request for CORS.""" | |
| response = client.options("/api/v1/navigation/plan") | |
| # Should handle OPTIONS request | |
| assert response.status_code in [200, 204, 405] # Depending on CORS config | |
| def test_navigation_plan_invalid_method(self, client): | |
| """Test invalid HTTP method.""" | |
| response = client.get("/api/v1/navigation/plan") | |
| # Should not accept GET | |
| assert response.status_code == 405 # Method Not Allowed | |
Xet Storage Details
- Size:
- 7.72 kB
- Xet hash:
- 8ac4531c7ed302af33992da5e2f0c0cbf155ab3212cd5a20774645f7f04629f7
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.