feat(registry): añade FileSystemPolicyStore con carga YAML versionada

Incluye 'yaml' en los overrides de mypy (PyYAML no trae type stubs).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Juan
2026-05-10 10:37:53 +02:00
co-authored by Claude Opus 4.7
parent 2fffecb988
commit 85906de832
5 changed files with 122 additions and 1 deletions
+8
View File
@@ -0,0 +1,8 @@
name: test_policy
versions:
- id: v1
hash: deadbeef
author: pytest
message: fixture inicial
created_at: 2026-01-01T00:00:00Z
active_version: v1
+13
View File
@@ -0,0 +1,13 @@
name: test_policy
version: v1
description: Política de prueba
input_validators:
- type: detect_pii
config:
entities: [PERSON, EMAIL]
severity_on_match: block
output_validators:
- type: schema_match
config:
severity_on_mismatch: block
on_validator_error: fail_closed
+36
View File
@@ -0,0 +1,36 @@
"""Tests del PolicyStore."""
from pathlib import Path
import pytest
from agentforge_core.registry.policy_store import FileSystemPolicyStore
FIXTURES = Path(__file__).parent.parent / "fixtures" / "policies"
def test_list_policies() -> None:
store = FileSystemPolicyStore(FIXTURES)
names = [p.name for p in store.list_policies()]
assert "test_policy" in names
def test_get_policy_devuelve_version_activa() -> None:
store = FileSystemPolicyStore(FIXTURES)
p = store.get_policy("test_policy")
assert p.version == "v1"
assert len(p.input_validators) == 1
assert p.input_validators[0].type == "detect_pii"
def test_get_policy_inexistente_lanza_error() -> None:
store = FileSystemPolicyStore(FIXTURES)
with pytest.raises(FileNotFoundError):
store.get_policy("inexistente")
def test_list_versions() -> None:
store = FileSystemPolicyStore(FIXTURES)
metas = store.list_versions("test_policy")
assert metas[0].id == "v1"
assert metas[0].author == "pytest"