feat(maf): Phase 5 - action coordinator, approval flow, frontend MAF roundtable pages
- Backend: action_coordinator, capability_snapshot, event_normalizer, tool_executor updates - Backend: approved_tool_executor with write guard, action leases, migration script - Frontend: maf-roundtable module (API client, event timeline, approval cards, fact flow panel) - Frontend: MafRoutes, MafSessionsPage, MafRunDetailPage - Tests: action_leases, migration_phase5, phase5_entry_e2e, real_write_e2e/http_e2e - Docs: update implementation plan Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
21c4c898e7
commit
f82363d81f
55 files changed
+6304
-167
No files matched your search
+77
@@ -0,0 +1,77 @@
|
||||
"""Test-only real external-write tool for MAF approval E2E tests.
|
||||
|
||||
This module is deliberately not registered in ``config.yaml``. Tests add the
|
||||
tool to an isolated ``AppConfig`` and set ``MAF_E2E_OUTBOX_DIR`` to a temporary
|
||||
directory. It is a real LangChain ``StructuredTool`` and therefore exercises
|
||||
the same LangGraph ``ToolNode`` path as a configured production tool without
|
||||
touching a business system.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
from langchain.tools import tool
|
||||
|
||||
_OPERATION_ID = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_.-]{0,95}$")
|
||||
_TEST_BLOCK_STARTED: threading.Event | None = None
|
||||
_TEST_BLOCK_RELEASE: threading.Event | None = None
|
||||
|
||||
|
||||
def configure_test_block(
|
||||
*, started: threading.Event | None = None, release: threading.Event | None = None
|
||||
) -> None:
|
||||
"""Install a test-only barrier for lease contention tests.
|
||||
|
||||
The hook is inert unless a test explicitly supplies both events. It keeps
|
||||
the write inside the real synchronous ToolNode call while allowing the
|
||||
second MAF run to observe the first target lease as ``running``.
|
||||
"""
|
||||
|
||||
global _TEST_BLOCK_STARTED, _TEST_BLOCK_RELEASE
|
||||
_TEST_BLOCK_STARTED = started
|
||||
_TEST_BLOCK_RELEASE = release
|
||||
|
||||
|
||||
def clear_test_block() -> None:
|
||||
configure_test_block()
|
||||
|
||||
|
||||
@tool("maf_test_outbox_write", parse_docstring=True)
|
||||
def maf_test_outbox_write(operation_id: str, value: str) -> dict[str, object]:
|
||||
"""Append one controlled write record to the test outbox.
|
||||
|
||||
Args:
|
||||
operation_id: Stable idempotency identifier for the test action.
|
||||
value: Test payload written only to the temporary outbox.
|
||||
"""
|
||||
outbox_dir = (os.getenv("MAF_E2E_OUTBOX_DIR") or "").strip()
|
||||
if not outbox_dir:
|
||||
raise RuntimeError("MAF_E2E_OUTBOX_DIR is not configured")
|
||||
if not _OPERATION_ID.fullmatch(operation_id):
|
||||
raise ValueError("invalid test outbox operation id")
|
||||
|
||||
if _TEST_BLOCK_STARTED is not None and _TEST_BLOCK_RELEASE is not None:
|
||||
_TEST_BLOCK_STARTED.set()
|
||||
_TEST_BLOCK_RELEASE.wait()
|
||||
|
||||
directory = Path(outbox_dir).resolve()
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
record_path = directory / f"{operation_id}.jsonl"
|
||||
with record_path.open("a", encoding="utf-8", newline="") as record_file:
|
||||
record_file.write(
|
||||
json.dumps({"operation_id": operation_id, "value": value}, ensure_ascii=False)
|
||||
+ "\n"
|
||||
)
|
||||
return {
|
||||
"executed": True,
|
||||
"external_object_id": operation_id,
|
||||
"safe_summary": "test outbox write completed",
|
||||
}
|
||||
|
||||
|
||||
__all__ = ["clear_test_block", "configure_test_block", "maf_test_outbox_write"]
|
||||
Reference in new issue
Block a user