Skip to content

Añadir fixtures de facturas anonimizadas (PDF/JPG/PNG) y casos de pipeline#52

Merged
erseco merged 2 commits into
mainfrom
test/add-anonymized-invoice-fixtures
May 31, 2026
Merged

Añadir fixtures de facturas anonimizadas (PDF/JPG/PNG) y casos de pipeline#52
erseco merged 2 commits into
mainfrom
test/add-anonymized-invoice-fixtures

Conversation

@erseco
Copy link
Copy Markdown
Owner

@erseco erseco commented May 31, 2026

Añade más fixtures de facturas de proveedor para los tests, en varios formatos (PDF, JPG y PNG).

Qué incluye

Cuatro facturas sintéticas y anonimizadas, modeladas a partir de la estructura de facturas reales de Canarias pero con nombres de empresa y CIF/NIF ficticios (no contienen ningún dato real):

Fixture Formato Caso
F-2025-004 PDF Servicios profesionales, retención IRPF 15%, exento de IVA/IGIC
F-2025-005 PDF Servicios jurídicos, IGIC 7%
F-2025-006 PDF Logística, mixto: 7% IGIC + línea de suplido no sujeto (art. 22.3C Ley 20/1991)
F-2025-007 JPG + PNG Tienda de piensos, una línea, 0% IGIC

Cómo pasan por los tests

Cada fixture incluye su respuesta de IA grabada en Test/fixtures/responses/*.json y queda registrada en el data provider de InvoicePipelineTest, por lo que se ejecutan contra todas las comprobaciones del pipeline: normalización, validación, consistencia aritmética (subtotal + IVA − retención = total, suma de líneas = base, desglose de impuestos = cuota), formato de CIF/NIF, fechas y confianzas.

Esto amplía la cobertura con casos antes no cubiertos (retención IRPF con exención de IVA, línea de suplido no sujeto, importe muy pequeño) y añade los formatos de imagen JPG y PNG junto a los PDF existentes.

Notas

  • Los ficheros se generan sintéticamente (reportlab con fuente Bitstream Vera embebida, para que el texto siempre se renderice) y se rasterizan a JPG/PNG. Sin trazas de datos reales (verificado).
  • De paso, se estabiliza testResolveMimeType…: usaba random_bytes(), que finfo podía detectar como un tipo concreto (p. ej. application/x-dosexec) y hacía fallar el fallback de extensión de forma intermitente; ahora usa contenido de texto determinista.
  • Test/ ya está marcado como export-ignore, así que estas fixtures no se incluyen en el ZIP de release.

Verificado en CI (lint + suite PHPUnit) en PHP 8.1–8.5.

Add four synthetic, anonymized supplier-invoice fixtures modelled on real
Canary-Islands invoices (fictitious company names and tax IDs, no real data):

- F-2025-004 (PDF): professional services, IRPF 15% retention, VAT-exempt
- F-2025-005 (PDF): legal services, 7% IGIC
- F-2025-006 (PDF): logistics, mixed 7% IGIC + non-subject 'suplido' line
- F-2025-007 (JPG + PNG): feed store, single line, 0% IGIC

Each ships a recorded AI-response JSON under fixtures/responses and is wired
into InvoicePipelineTest's data provider, so they run through the full
normalize/validate/arithmetic/tax-breakdown/supplier-data assertions. Adds
JPG and PNG sample formats alongside the existing PDF fixtures.
@github-actions
Copy link
Copy Markdown

FacturaScripts Playground Preview

Open this PR in FacturaScripts Playground
Try this PR in your browser

This preview is generated automatically for the test/add-anonymized-invoice-fixtures branch and loads the plugin directly from the PR branch ZIP in FacturaScripts Playground.

- The reportlab fixtures used the non-embedded Helvetica base-14 font, so
  the text was invisible when rasterized/viewed (only rules showed). Embed
  Bitstream Vera (bundled with reportlab) so the invoice text always renders.
  Regenerate F-2025-004/005/006 (PDF) and F-2025-007 (JPG+PNG).
- Stabilize testResolveMimeType* : use deterministic plain-text content
  instead of random_bytes(), which finfo could detect as a concrete type
  (application/x-dosexec) and intermittently fail the extension fallback.
@erseco erseco self-assigned this May 31, 2026
@erseco erseco merged commit 6fccbd6 into main May 31, 2026
8 checks passed
@erseco erseco deleted the test/add-anonymized-invoice-fixtures branch May 31, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant