Items completed: 1. Merged PR #2 (starlette/httpx deps) 2. Fixed async race condition in multimodal_ui.py 3. Wired TTSAdapter (ElevenLabs, Azure) in API routes 4. Moved super_big_brain.py from core/ to reasoning/ (backward compat shim) 5. Added API authentication middleware (Bearer token via FUSIONAGI_API_KEY) 6. Added async adapter interface (acomplete/acomplete_structured) 7. Migrated FastAPI on_event to lifespan (fixes 20 deprecation warnings) 8. Liquid Neural Networks (continuous-time adaptive weights) 9. Quantum-AI Hybrid compute backend (simulator + optimization) 10. Embodied Intelligence / Robotics bridge (actuator + sensor protocols) 11. Consciousness Engineering (formal self-model with introspection) 12. ASI Scoring Rubric (C/A/L/N/R self-assessment harness) 13. GPU integration tests for TensorFlow backend 14. Multi-stage production Dockerfile 15. Gitea CI/CD pipeline (lint, test matrix, Docker build) 16. API rate limiting middleware (per-IP sliding window) 17. OpenAPI docs cleanup (auth + rate limiting descriptions) 18. Benchmarking suite (decomposition, multi-path, recomposition, e2e) 19. Plugin system (head registry for custom heads) 427 tests passing, 0 ruff errors, 0 mypy errors. Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
113 lines
4.1 KiB
Python
113 lines
4.1 KiB
Python
"""MAA tests: Gate blocks manufacturing tools without MPC; allows with valid MPC."""
|
|
|
|
import pytest
|
|
|
|
from fusionagi.agents import ExecutorAgent
|
|
from fusionagi.core import StateManager
|
|
from fusionagi.governance import Guardrails
|
|
from fusionagi.maa import MAAGate
|
|
from fusionagi.maa.gap_detection import GapClass, check_gaps
|
|
from fusionagi.maa.layers import MPCAuthority
|
|
from fusionagi.maa.tools import cnc_emit_tool
|
|
from fusionagi.tools import ToolRegistry
|
|
|
|
|
|
def test_maa_gate_blocks_manufacturing_without_mpc() -> None:
|
|
mpc = MPCAuthority()
|
|
gate = MAAGate(mpc_authority=mpc)
|
|
allowed, result = gate.check("cnc_emit", {"machine_id": "m1", "toolpath_ref": "t1"})
|
|
assert allowed is False
|
|
assert "mpc_id" in str(result)
|
|
|
|
|
|
def test_maa_gate_allows_manufacturing_with_valid_mpc() -> None:
|
|
mpc = MPCAuthority()
|
|
cert = mpc.issue("design-001", metadata={})
|
|
gate = MAAGate(mpc_authority=mpc)
|
|
allowed, result = gate.check("cnc_emit", {"mpc_id": cert.mpc_id.value, "machine_id": "m1", "toolpath_ref": "t1"})
|
|
assert allowed is True
|
|
assert isinstance(result, dict)
|
|
assert result.get("mpc_id") == cert.mpc_id.value
|
|
|
|
|
|
def test_maa_gate_non_manufacturing_passes() -> None:
|
|
mpc = MPCAuthority()
|
|
gate = MAAGate(mpc_authority=mpc)
|
|
allowed, result = gate.check("file_read", {"path": "/tmp/foo"})
|
|
assert allowed is True
|
|
assert result == {"path": "/tmp/foo"}
|
|
|
|
|
|
def test_gap_detection_returns_gaps() -> None:
|
|
gaps = check_gaps({"require_numeric_bounds": True})
|
|
assert len(gaps) >= 1
|
|
assert gaps[0].gap_class == GapClass.MISSING_NUMERIC_BOUNDS
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"context,expected_gap_class",
|
|
[
|
|
({"require_numeric_bounds": True}, GapClass.MISSING_NUMERIC_BOUNDS),
|
|
({"require_explicit_tolerances": True}, GapClass.IMPLICIT_TOLERANCES),
|
|
({"require_datums": True}, GapClass.UNDEFINED_DATUMS),
|
|
({"require_process_type": True}, GapClass.ASSUMED_PROCESSES),
|
|
],
|
|
)
|
|
def test_gap_detection_parametrized(context: dict, expected_gap_class: GapClass) -> None:
|
|
"""Parametrized gap detection tests."""
|
|
gaps = check_gaps(context)
|
|
assert len(gaps) >= 1
|
|
assert gaps[0].gap_class == expected_gap_class
|
|
|
|
|
|
def test_gap_detection_no_gaps() -> None:
|
|
gaps = check_gaps({"numeric_bounds": {"x": [0, 1]}})
|
|
assert len(gaps) == 0
|
|
|
|
|
|
def test_gap_detection_no_gaps_empty_context() -> None:
|
|
gaps = check_gaps({})
|
|
assert len(gaps) == 0
|
|
|
|
|
|
def test_executor_with_guardrails_blocks_manufacturing_without_mpc() -> None:
|
|
guardrails = Guardrails()
|
|
mpc = MPCAuthority()
|
|
gate = MAAGate(mpc_authority=mpc)
|
|
guardrails.add_check(gate.check)
|
|
reg = ToolRegistry()
|
|
reg.register(cnc_emit_tool())
|
|
state = StateManager()
|
|
executor = ExecutorAgent(registry=reg, state_manager=state, guardrails=guardrails)
|
|
from fusionagi.schemas.messages import AgentMessage, AgentMessageEnvelope
|
|
env = AgentMessageEnvelope(
|
|
message=AgentMessage(
|
|
sender="orch",
|
|
recipient="executor",
|
|
intent="execute_step",
|
|
payload={
|
|
"step_id": "s1",
|
|
"plan": {"steps": [{"id": "s1", "description": "CNC", "dependencies": [], "tool_name": "cnc_emit", "tool_args": {"machine_id": "m1", "toolpath_ref": "t1"}}], "fallback_paths": []},
|
|
"tool_name": "cnc_emit",
|
|
"tool_args": {"machine_id": "m1", "toolpath_ref": "t1"},
|
|
},
|
|
),
|
|
task_id="t1",
|
|
)
|
|
out = executor.handle_message(env)
|
|
assert out is not None
|
|
assert out.message.intent == "step_failed"
|
|
assert "mpc_id" in out.message.payload.get("error", "")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_maa_gate_blocks_manufacturing_without_mpc()
|
|
test_maa_gate_allows_manufacturing_with_valid_mpc()
|
|
test_maa_gate_non_manufacturing_passes()
|
|
test_gap_detection_returns_gaps()
|
|
test_gap_detection_parametrized({"require_numeric_bounds": True}, GapClass.MISSING_NUMERIC_BOUNDS)
|
|
test_gap_detection_no_gaps()
|
|
test_gap_detection_no_gaps_empty_context()
|
|
test_executor_with_guardrails_blocks_manufacturing_without_mpc()
|
|
print("MAA tests OK")
|