feat(h4-2): exportador CSV/JSON del log de eventos (RF-11)#26
Merged
Conversation
Nuevo adapter `adapters/exportador.py` con dos funciones puras:
- `exportar_a_csv(eventos, path)`: flatten del `payload` anidado a
columnas `payload_*` (e.g. `payload_costo_total`); listas serializadas
como JSON string; encoding `utf-8-sig` con BOM para Excel ES; unión
de columnas para payloads heterogéneos (saturación vs óptimo).
- `exportar_a_json(eventos, path)`: array indentado sin BOM, formato
apto para herramientas tabulares (`jq`) y auditoría humana.
Nuevo subcomando CLI `sentinel export --formato {csv,json} --in --out`
con enum `FormatoExport`. Exit 2 si la entrada no existe o es JSONL
corrupto (propagado desde `JsonlRepositorioEventos.__init__`).
El log canónico (`eventos.jsonl`) NO se modifica — el export es un
archivo derivado. RN-03 preservado: este subcomando solo lee.
Tests: 14 nuevos verdes (Normal/Borde + CLI end-to-end con archivo
inexistente y corrupto). Suite total 249/249, cov 92.66 %.
Trazabilidad: RF-11 ✅ apuntando a `adapters/exportador.py` + `interfaces/cli/export_cmd.py`. Descripción del schema CSV (flatten con prefijo `payload_`, encoding utf-8-sig BOM) y JSON (array indentado). CHANGELOG: entrada "H4 fase 2" bajo [Unreleased] con resumen del exportador, decisiones de encoding y cobertura del test suite.
Jacket-69
added a commit
that referenced
this pull request
May 29, 2026
feat(h4-2): exportador CSV/JSON del log de eventos (RF-11)
Jacket-69
added a commit
that referenced
this pull request
May 29, 2026
feat(h4-2): exportador CSV/JSON del log de eventos (RF-11)
Jacket-69
added a commit
that referenced
this pull request
May 29, 2026
feat(h4-2): exportador CSV/JSON del log de eventos (RF-11)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resumen
Segunda fase de H4: subcomando
sentinel exportque produce CSV (Excel-ready) y JSON (auditoría humana) a partir del log canónicoeventos.jsonlgenerado en H4-1. Cierra RF-11.Cambios
Adapter
adapters/exportador.py:exportar_a_csv(eventos, path) -> int: flatten delpayloadanidado a columnaspayload_*; listas serializadas a JSON string; encodingutf-8-sig(BOM). Unión de columnas para payloads heterogéneos (saturación tiene menos campos que óptimo).exportar_a_json(eventos, path) -> int: array indentado sin BOM, formato apto parajqy revisión humana._aplanar_dict(d, prefijo)recursivo.CLI
interfaces/cli/export_cmd.py:sentinel export --formato {csv,json} --in eventos.jsonl --out reporte.{csv,json}.FormatoExportpara validación.--inno existe o el JSONL es corrupto (propagado desdeJsonlRepositorioEventos.__init__→pydantic.ValidationError).Decisiones intencionales
payload_. Razonable para auditoría manual; un consumidor programático debería usar JSON.utf-8-sigcon BOM en CSV: regla pragmática para Excel español sin reconfigurar locales. JSON queda sin BOM (estándar IETF).Validación local
ruff check+ruff format --check: ✓ (68 archivos).mypy src/sentinel_dispatch: ✓ (36 archivos).pytest tests/unit tests/integration --no-cov: 249 passed in 3.61s (235 baseline + 14 nuevos).DoD
comparedebe seguir 12/12 OK bit-exacto (este PR no toca RT-02).Commits
633d992feat(h4-2): exportador CSV/JSON del log de eventos (RF-11)af41878docs(quality): RF-11 ✅ + entrada H4-2 en CHANGELOGPróxima fase
H4-3:
application/simulacion.py(RF-12). Fase 5 del plan H4.