feat(registry): añade FileSystemAgentRegistry con versionado tipo Git y diff

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Juan
2026-05-10 10:39:50 +02:00
co-authored by Claude Opus 4.7
parent 85906de832
commit 5cbec0d5d8
5 changed files with 256 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
name: test_agent
versions:
- id: v1
hash: feedface
author: pytest
message: fixture inicial
created_at: 2026-01-01T00:00:00Z
active_version: v1
+18
View File
@@ -0,0 +1,18 @@
name: test_agent
version: v1
owner: Juan
purpose: Test fixture
state: active
guardrails: [test_policy]
llm:
provider: mock
model: gpt-4o
temperature: 0.2
max_tokens: 2000
system_prompt: |
Eres un agente de prueba.
output_schema:
type: object
required: [severity]
risk_threshold_for_hitl: 4
updated_at: 2026-01-01T00:00:00Z
+70
View File
@@ -0,0 +1,70 @@
"""Tests del AgentRegistry."""
import shutil
from datetime import UTC, datetime
from pathlib import Path
from agentforge_core.domain.agent import AgentDefinition, LLMConfig
from agentforge_core.registry.repository import FileSystemAgentRegistry
FIXTURES = Path(__file__).parent.parent / "fixtures" / "agents"
def test_get_agent_carga_version_activa() -> None:
r = FileSystemAgentRegistry(FIXTURES)
a = r.get_agent("test_agent")
assert a.name == "test_agent"
assert a.version == "v1"
def test_list_versions_devuelve_metadata() -> None:
r = FileSystemAgentRegistry(FIXTURES)
metas = r.list_versions("test_agent")
assert len(metas) == 1
assert metas[0].id == "v1"
def test_upsert_crea_nueva_version_y_actualiza_index(tmp_path: Path) -> None:
# Copiamos el fixture a tmp para no contaminar el repo
shutil.copytree(FIXTURES / "test_agent", tmp_path / "test_agent")
r = FileSystemAgentRegistry(tmp_path)
new_def = AgentDefinition(
name="test_agent",
version="v2",
owner="Juan",
purpose="añade lógica",
state="active",
guardrails=["test_policy"],
llm=LLMConfig(temperature=0.3),
system_prompt="Eres un agente actualizado.",
output_schema={"type": "object"},
updated_at=datetime.now(UTC),
)
meta = r.upsert_version("test_agent", new_def, message="bump temp", author="Juan")
assert meta.id == "v2"
assert (tmp_path / "test_agent" / "versions" / "v2.yaml").exists()
# active_version debe haber cambiado
a = r.get_agent("test_agent")
assert a.version == "v2"
def test_diff_versions_retorna_unified_diff(tmp_path: Path) -> None:
shutil.copytree(FIXTURES / "test_agent", tmp_path / "test_agent")
r = FileSystemAgentRegistry(tmp_path)
new_def = AgentDefinition(
name="test_agent",
version="v2",
owner="Juan",
purpose="distinto",
state="active",
guardrails=["test_policy"],
llm=LLMConfig(),
system_prompt="otro prompt",
output_schema={"type": "object"},
updated_at=datetime.now(UTC),
)
r.upsert_version("test_agent", new_def, message="change", author="Juan")
diff = r.diff_versions("test_agent", "v1", "v2")
assert "purpose" in diff.unified_diff
assert diff.from_version == "v1"
assert diff.to_version == "v2"