verifactu-lint 0.1.0a2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- verifactu_lint-0.1.0a2/.github/ISSUE_TEMPLATE/config.yml +13 -0
- verifactu_lint-0.1.0a2/.github/ISSUE_TEMPLATE/falso-positivo.yml +49 -0
- verifactu_lint-0.1.0a2/.github/ISSUE_TEMPLATE/incumplimiento-no-detectado.yml +45 -0
- verifactu_lint-0.1.0a2/.github/workflows/ci.yml +59 -0
- verifactu_lint-0.1.0a2/.github/workflows/codeql.yml +41 -0
- verifactu_lint-0.1.0a2/.github/workflows/release.yml +131 -0
- verifactu_lint-0.1.0a2/.github/workflows/scorecard.yml +47 -0
- verifactu_lint-0.1.0a2/.gitignore +9 -0
- verifactu_lint-0.1.0a2/CONTRIBUTING.md +75 -0
- verifactu_lint-0.1.0a2/LICENSE +202 -0
- verifactu_lint-0.1.0a2/PKG-INFO +202 -0
- verifactu_lint-0.1.0a2/README.md +173 -0
- verifactu_lint-0.1.0a2/SECURITY.md +42 -0
- verifactu_lint-0.1.0a2/ejemplos/cadena-conforme.xml +78 -0
- verifactu_lint-0.1.0a2/ejemplos/cadena-rota.xml +78 -0
- verifactu_lint-0.1.0a2/pyproject.toml +82 -0
- verifactu_lint-0.1.0a2/src/verifactu_lint/__init__.py +1 -0
- verifactu_lint-0.1.0a2/src/verifactu_lint/cli.py +109 -0
- verifactu_lint-0.1.0a2/src/verifactu_lint/hallazgos.py +85 -0
- verifactu_lint-0.1.0a2/src/verifactu_lint/huella.py +232 -0
- verifactu_lint-0.1.0a2/src/verifactu_lint/registros.py +263 -0
- verifactu_lint-0.1.0a2/src/verifactu_lint/reglas/__init__.py +46 -0
- verifactu_lint-0.1.0a2/src/verifactu_lint/reglas/encadenamiento.py +334 -0
- verifactu_lint-0.1.0a2/src/verifactu_lint/reglas/identificacion.py +219 -0
- verifactu_lint-0.1.0a2/src/verifactu_lint/salida.py +145 -0
- verifactu_lint-0.1.0a2/tests/test_huella.py +269 -0
- verifactu_lint-0.1.0a2/tests/test_reglas.py +298 -0
- verifactu_lint-0.1.0a2/tests/test_workflows.py +78 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
blank_issues_enabled: true
|
|
2
|
+
contact_links:
|
|
3
|
+
- name: Vulnerabilidad de seguridad
|
|
4
|
+
url: https://github.com/easybytehub/verifactu-lint/security/advisories/new
|
|
5
|
+
about: >
|
|
6
|
+
Por el canal privado, no como issue público. Interesan especialmente el
|
|
7
|
+
agotamiento de recursos con un XML manipulado y cualquier lectura de fichero o
|
|
8
|
+
red provocada por su contenido.
|
|
9
|
+
- name: Dudas sobre la norma, no sobre la herramienta
|
|
10
|
+
url: https://sede.agenciatributaria.gob.es/Sede/iva/sistemas-informaticos-facturacion-verifactu.html
|
|
11
|
+
about: >
|
|
12
|
+
Este repositorio no interpreta el reglamento por nadie. Para dudas sobre qué
|
|
13
|
+
exige la norma, la AEAT publica su FAQ de desarrolladores y atiende un buzón.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
name: Falso positivo
|
|
2
|
+
description: verifactu-lint marca como incumplimiento algo que en realidad cumple
|
|
3
|
+
labels: ["falso-positivo"]
|
|
4
|
+
body:
|
|
5
|
+
- type: markdown
|
|
6
|
+
attributes:
|
|
7
|
+
value: |
|
|
8
|
+
Este es el defecto más grave que puede tener esta herramienta: si marca como
|
|
9
|
+
incumplimiento algo correcto, alguien cambia código que estaba bien y deja de
|
|
10
|
+
creerse el resto del informe. Se tratan con prioridad sobre todo lo demás.
|
|
11
|
+
|
|
12
|
+
**Anonimiza el caso**: NIF y números de factura ficticios sirven igual. No
|
|
13
|
+
hace falta —ni queremos— tus registros reales.
|
|
14
|
+
|
|
15
|
+
- type: input
|
|
16
|
+
id: regla
|
|
17
|
+
attributes:
|
|
18
|
+
label: Regla
|
|
19
|
+
placeholder: RRSIF001
|
|
20
|
+
validations:
|
|
21
|
+
required: true
|
|
22
|
+
|
|
23
|
+
- type: textarea
|
|
24
|
+
id: registro
|
|
25
|
+
attributes:
|
|
26
|
+
label: Registro mínimo que lo reproduce
|
|
27
|
+
description: El XML más pequeño con el que ocurre, ya anonimizado.
|
|
28
|
+
render: xml
|
|
29
|
+
validations:
|
|
30
|
+
required: true
|
|
31
|
+
|
|
32
|
+
- type: textarea
|
|
33
|
+
id: por_que_cumple
|
|
34
|
+
attributes:
|
|
35
|
+
label: Por qué este caso sí cumple
|
|
36
|
+
description: >
|
|
37
|
+
Lo más útil aquí es la cita: artículo de la orden, apartado del FAQ de
|
|
38
|
+
desarrolladores, o la respuesta de la AEAT si la tienes. Si la norma y la
|
|
39
|
+
regla discrepan, la norma tiene razón.
|
|
40
|
+
validations:
|
|
41
|
+
required: true
|
|
42
|
+
|
|
43
|
+
- type: input
|
|
44
|
+
id: version
|
|
45
|
+
attributes:
|
|
46
|
+
label: Versión
|
|
47
|
+
description: "`verifactu-lint --version`"
|
|
48
|
+
validations:
|
|
49
|
+
required: true
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: Incumplimiento no detectado
|
|
2
|
+
description: Un registro que incumple y verifactu-lint deja pasar
|
|
3
|
+
labels: ["regla-nueva"]
|
|
4
|
+
body:
|
|
5
|
+
- type: markdown
|
|
6
|
+
attributes:
|
|
7
|
+
value: |
|
|
8
|
+
**Anonimiza el caso**: NIF y números de factura ficticios sirven igual.
|
|
9
|
+
|
|
10
|
+
Si lo que falta es una familia entera de comprobaciones (eventos,
|
|
11
|
+
rectificativas, NO VERI\*FACTU), mira antes los issues abiertos: es probable
|
|
12
|
+
que ya esté registrado y prefieras comentar allí.
|
|
13
|
+
|
|
14
|
+
- type: textarea
|
|
15
|
+
id: registro
|
|
16
|
+
attributes:
|
|
17
|
+
label: Registro que debería dar hallazgo
|
|
18
|
+
render: xml
|
|
19
|
+
validations:
|
|
20
|
+
required: true
|
|
21
|
+
|
|
22
|
+
- type: textarea
|
|
23
|
+
id: que_incumple
|
|
24
|
+
attributes:
|
|
25
|
+
label: Qué incumple, y dónde lo dice la norma
|
|
26
|
+
description: >
|
|
27
|
+
Artículo del RD 1007/2023, de la Orden HAC/1177/2024, o apartado del FAQ de
|
|
28
|
+
desarrolladores. Sin la cita concreta no se puede escribir la regla, porque
|
|
29
|
+
el campo `norma` del hallazgo es lo que permite contrastarlo.
|
|
30
|
+
validations:
|
|
31
|
+
required: true
|
|
32
|
+
|
|
33
|
+
- type: dropdown
|
|
34
|
+
id: severidad
|
|
35
|
+
attributes:
|
|
36
|
+
label: Severidad que le corresponde
|
|
37
|
+
description: >
|
|
38
|
+
`error` sólo si se puede demostrar con el fichero delante. Si hace falta ver
|
|
39
|
+
el sistema o algo que no está en el XML, es `incompleto`.
|
|
40
|
+
options:
|
|
41
|
+
- error
|
|
42
|
+
- aviso
|
|
43
|
+
- incompleto
|
|
44
|
+
validations:
|
|
45
|
+
required: true
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Los tres gates que corren antes de que nada entre en `main`.
|
|
2
|
+
#
|
|
3
|
+
# **Y una cuarta comprobación que no es sobre este código**: los vectores oficiales de
|
|
4
|
+
# la AEAT se ejecutan como parte de `pytest`. Son la definición de correcto para el
|
|
5
|
+
# cálculo de la huella, así que si un cambio los rompe, el cambio está mal — no
|
|
6
|
+
# ellos. Eso es lo que hace que esta herramienta pueda afirmar algo sobre el
|
|
7
|
+
# cumplimiento de otros.
|
|
8
|
+
name: ci
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [main]
|
|
13
|
+
pull_request:
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
gates:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
strategy:
|
|
22
|
+
fail-fast: false
|
|
23
|
+
# **Se prueba cada versión que `requires-python` permite.** Una versión
|
|
24
|
+
# declarada y no ejecutada es una promesa que nadie ha comprobado — y como
|
|
25
|
+
# aquí no hay techo, eso incluye 3.14: es lo que `python3` resuelve hoy en un
|
|
26
|
+
# Mac actualizado, o sea lo que le toca a quien escriba lo obvio.
|
|
27
|
+
matrix:
|
|
28
|
+
python: ["3.11", "3.12", "3.13", "3.14"]
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
31
|
+
with:
|
|
32
|
+
persist-credentials: false
|
|
33
|
+
|
|
34
|
+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
|
|
35
|
+
with:
|
|
36
|
+
python-version: ${{ matrix.python }}
|
|
37
|
+
|
|
38
|
+
- name: Instalar
|
|
39
|
+
run: python -m pip install --disable-pip-version-check -e ".[dev]"
|
|
40
|
+
|
|
41
|
+
- name: ruff
|
|
42
|
+
run: python -m ruff check .
|
|
43
|
+
|
|
44
|
+
- name: mypy
|
|
45
|
+
run: python -m mypy
|
|
46
|
+
|
|
47
|
+
- name: pytest
|
|
48
|
+
run: python -m pytest -q
|
|
49
|
+
|
|
50
|
+
# La herramienta corriendo sobre sus propios ejemplos: el conforme no debe dar
|
|
51
|
+
# errores y el roto debe darlos. Un `--help` que no falla no prueba que la CLI
|
|
52
|
+
# haga su trabajo; esto sí.
|
|
53
|
+
- name: La CLI sobre los ejemplos
|
|
54
|
+
run: |
|
|
55
|
+
python -m verifactu_lint.cli ejemplos/cadena-conforme.xml
|
|
56
|
+
if python -m verifactu_lint.cli ejemplos/cadena-rota.xml; then
|
|
57
|
+
echo "::error::la cadena rota debería haber salido con código 1"
|
|
58
|
+
exit 1
|
|
59
|
+
fi
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Análisis estático de una herramienta que no hemos escrito nosotros.
|
|
2
|
+
#
|
|
3
|
+
# **Qué añade sobre `ruff`, que ya ejecuta las reglas de bandit.** Un linter razona
|
|
4
|
+
# línea a línea; CodeQL sigue un valor desde donde entra hasta donde se usa. Aquí eso
|
|
5
|
+
# importa porque el dato de entrada es un XML ajeno: llega de un fichero que el
|
|
6
|
+
# usuario no siempre ha mirado y atraviesa parser, reglas y salida. *Hasta dónde
|
|
7
|
+
# llega un valor no confiable* es exactamente la pregunta que un linter no responde.
|
|
8
|
+
name: codeql
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [main]
|
|
13
|
+
pull_request:
|
|
14
|
+
schedule:
|
|
15
|
+
# Semanal, porque las consultas de CodeQL mejoran sin que este repositorio
|
|
16
|
+
# cambie: puede aparecer un hallazgo en código que nadie ha tocado.
|
|
17
|
+
- cron: "23 4 * * 2"
|
|
18
|
+
|
|
19
|
+
permissions:
|
|
20
|
+
contents: read
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
analyse:
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
permissions:
|
|
26
|
+
contents: read
|
|
27
|
+
security-events: write # el único write, y escribe hallazgos, no código
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
30
|
+
with:
|
|
31
|
+
persist-credentials: false
|
|
32
|
+
|
|
33
|
+
- uses: github/codeql-action/init@c4dd10e44af883a891fe31ced449bcb4a6728b9b # v3
|
|
34
|
+
with:
|
|
35
|
+
languages: python
|
|
36
|
+
# `security-and-quality` en lugar del conjunto de seguridad a secas: este
|
|
37
|
+
# código lo leen desconocidos decidiendo si fiarse de él, así que un aviso
|
|
38
|
+
# sobre un `except` demasiado ancho compensa el ruido que añade.
|
|
39
|
+
queries: security-and-quality
|
|
40
|
+
|
|
41
|
+
- uses: github/codeql-action/analyze@c4dd10e44af883a891fe31ced449bcb4a6728b9b # v3
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Lo que produce una etiqueta: un wheel publicado y su procedencia comprobable.
|
|
2
|
+
#
|
|
3
|
+
# **Por qué la procedencia importa especialmente en esta herramienta.** Se instala
|
|
4
|
+
# para responder a «¿cumplo?» en un sistema cuyo titular responde de su facturación.
|
|
5
|
+
# Pedirle que confíe a ciegas en un paquete descargado sería ampliarle la superficie
|
|
6
|
+
# de riesgo justo donde vino a reducirla. `gh attestation verify` le deja comprobar
|
|
7
|
+
# qué commit, qué workflow y qué runner produjeron exactamente el artefacto que se
|
|
8
|
+
# está instalando.
|
|
9
|
+
#
|
|
10
|
+
# **Ninguna clave nuestra interviene.** GitHub emite un token OIDC efímero para esta
|
|
11
|
+
# ejecución, se firma con él y la atestación queda registrada públicamente. No hay
|
|
12
|
+
# nada que custodiar, rotar ni filtrar. Lo mismo para PyPI: publicación por Trusted
|
|
13
|
+
# Publishing, sin token de API almacenado en ningún secreto.
|
|
14
|
+
name: release
|
|
15
|
+
|
|
16
|
+
on:
|
|
17
|
+
push:
|
|
18
|
+
tags: ["v*"]
|
|
19
|
+
|
|
20
|
+
# **Lectura arriba, escritura sólo en el job que la necesita.** Un permiso de
|
|
21
|
+
# escritura declarado al principio del fichero se concede a *todos* los jobs,
|
|
22
|
+
# incluido cualquiera que se añada después y sólo necesite leer.
|
|
23
|
+
permissions:
|
|
24
|
+
contents: read
|
|
25
|
+
|
|
26
|
+
jobs:
|
|
27
|
+
publish:
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
environment: release
|
|
30
|
+
permissions:
|
|
31
|
+
contents: write # crear la release y adjuntar el wheel con su procedencia
|
|
32
|
+
id-token: write # OIDC: firma de la atestación y Trusted Publishing en PyPI
|
|
33
|
+
attestations: write # registrar la atestación
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
36
|
+
with:
|
|
37
|
+
persist-credentials: false
|
|
38
|
+
|
|
39
|
+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
|
|
40
|
+
with:
|
|
41
|
+
python-version: "3.12"
|
|
42
|
+
|
|
43
|
+
# **La etiqueta y `__version__` tienen que coincidir.** Publicar un wheel que
|
|
44
|
+
# dice 0.1.0 bajo una etiqueta v0.2.0 es inutilizable para quien fije
|
|
45
|
+
# cualquiera de las dos, y el fallo aparece meses después en un informe que
|
|
46
|
+
# nadie puede reproducir. Se comprueba antes de construir nada.
|
|
47
|
+
- name: La etiqueta y `__version__` deben coincidir
|
|
48
|
+
run: |
|
|
49
|
+
etiquetada="${GITHUB_REF_NAME#v}"
|
|
50
|
+
declarada=$(python -c 'import sys; sys.path.insert(0, "src"); import verifactu_lint; print(verifactu_lint.__version__)')
|
|
51
|
+
if [ "$etiquetada" != "$declarada" ]; then
|
|
52
|
+
echo "::error::la etiqueta es v$etiquetada y __version__ es $declarada."
|
|
53
|
+
echo "Corrige el paquete o mueve la etiqueta; publicarlos separados es peor que no publicar."
|
|
54
|
+
exit 1
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
- name: Construir el wheel
|
|
58
|
+
run: |
|
|
59
|
+
python -m pip install --disable-pip-version-check build==1.2.2.post1
|
|
60
|
+
python -m build
|
|
61
|
+
|
|
62
|
+
# La atestación se genera sobre el artefacto ya construido y antes de
|
|
63
|
+
# publicarlo: una procedencia que llegue después de la publicación es una que
|
|
64
|
+
# alguien pudo descargarse sin ella.
|
|
65
|
+
- name: Atestiguar la procedencia
|
|
66
|
+
id: provenance
|
|
67
|
+
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2
|
|
68
|
+
with:
|
|
69
|
+
subject-path: dist/*
|
|
70
|
+
|
|
71
|
+
# **El bundle se adjunta a la release, y no es redundante.** GitHub guarda las
|
|
72
|
+
# atestaciones fuera de banda, donde una herramienta que mira los *assets* de
|
|
73
|
+
# una release no las ve. Adjuntarlo las deja comprobables también como fichero,
|
|
74
|
+
# sin necesidad de confiar en la API de este repositorio.
|
|
75
|
+
#
|
|
76
|
+
# Se copia FUERA de `dist/` a propósito: ese directorio se sube íntegro a PyPI,
|
|
77
|
+
# que rechaza cualquier fichero que no sea un artefacto instalable.
|
|
78
|
+
- name: Publicar la release con el wheel y su procedencia
|
|
79
|
+
env:
|
|
80
|
+
GH_TOKEN: ${{ github.token }}
|
|
81
|
+
PROVENANCE: ${{ steps.provenance.outputs.bundle-path }}
|
|
82
|
+
run: |
|
|
83
|
+
mkdir -p release
|
|
84
|
+
cp dist/* release/
|
|
85
|
+
cp "$PROVENANCE" release/provenance.intoto.jsonl
|
|
86
|
+
notas="Verificar la procedencia del wheel:
|
|
87
|
+
|
|
88
|
+
\`\`\`bash
|
|
89
|
+
gh attestation verify --owner ${{ github.repository_owner }} verifactu_lint-*.whl
|
|
90
|
+
\`\`\`"
|
|
91
|
+
prerelease=""
|
|
92
|
+
case "${GITHUB_REF_NAME#v}" in
|
|
93
|
+
*a*|*b*|*rc*) prerelease="--prerelease" ;;
|
|
94
|
+
esac
|
|
95
|
+
gh release create "$GITHUB_REF_NAME" release/* \
|
|
96
|
+
--title "$GITHUB_REF_NAME" --notes "$notas" $prerelease
|
|
97
|
+
|
|
98
|
+
# **Por qué este paso está condicionado.** Trusted Publishing exige registrar
|
|
99
|
+
# antes un *pending publisher* en pypi.org, y eso sólo puede hacerlo una
|
|
100
|
+
# persona con sesión allí. Hasta que exista, este paso fallaría y dejaría en
|
|
101
|
+
# rojo una release cuyo wheel y cuya procedencia son perfectamente válidos.
|
|
102
|
+
#
|
|
103
|
+
# La alternativa —`continue-on-error`— esconde el fallo: la release saldría
|
|
104
|
+
# verde sin haber publicado nada, que es peor. Una variable de repositorio hace
|
|
105
|
+
# explícito el estado: mientras no esté, el resumen dice que no se publicó y
|
|
106
|
+
# por qué.
|
|
107
|
+
#
|
|
108
|
+
# Para activarlo: en pypi.org → Publishing → Add a pending publisher, con
|
|
109
|
+
# owner `easybytehub`, repositorio `verifactu-lint`, workflow `release.yml` y
|
|
110
|
+
# environment `release`. Después, definir la variable de repositorio
|
|
111
|
+
# `PYPI_TRUSTED_PUBLISHER` con valor `listo`.
|
|
112
|
+
- name: Publicar en PyPI
|
|
113
|
+
if: vars.PYPI_TRUSTED_PUBLISHER == 'listo'
|
|
114
|
+
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # release/v1
|
|
115
|
+
with:
|
|
116
|
+
packages-dir: dist
|
|
117
|
+
skip-existing: true
|
|
118
|
+
|
|
119
|
+
- name: Avisar de que PyPI está pendiente
|
|
120
|
+
if: vars.PYPI_TRUSTED_PUBLISHER != 'listo'
|
|
121
|
+
run: |
|
|
122
|
+
echo "::notice::Release publicada en GitHub con procedencia verificable, pero NO en PyPI."
|
|
123
|
+
{
|
|
124
|
+
echo "### PyPI: no publicado"
|
|
125
|
+
echo
|
|
126
|
+
echo 'La variable de repositorio `PYPI_TRUSTED_PUBLISHER` no vale `listo`.'
|
|
127
|
+
echo 'Registra el pending publisher en pypi.org (owner `easybytehub`,'
|
|
128
|
+
echo 'repo `verifactu-lint`, workflow `release.yml`, environment `release`)'
|
|
129
|
+
echo 'y define la variable. El wheel de esta release es válido y'
|
|
130
|
+
echo 'se puede instalar desde la propia release.'
|
|
131
|
+
} >> "$GITHUB_STEP_SUMMARY"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# La puntuación de seguridad de la cadena de suministro, calculada por alguien que
|
|
2
|
+
# no somos nosotros.
|
|
3
|
+
#
|
|
4
|
+
# **Por qué se publica.** Una herramienta que le pide a su usuario que compruebe la
|
|
5
|
+
# procedencia de lo que instala no puede pedirle a la vez que se crea nuestra propia
|
|
6
|
+
# valoración de nuestras prácticas. `publish_results` envía el resultado a la API
|
|
7
|
+
# pública de la OpenSSF, donde cualquiera puede consultarlo sin pasar por aquí.
|
|
8
|
+
#
|
|
9
|
+
# **No sube sus hallazgos a code scanning, y es deliberado.** Los checks de Scorecard
|
|
10
|
+
# son puntuaciones de política del repositorio —edad del proyecto, decisiones sobre
|
|
11
|
+
# revisión de código—, no defectos del programa. Mezclarlos con los de CodeQL llena
|
|
12
|
+
# la pestaña Security de entradas que nadie puede cerrar, y una pestaña que no se
|
|
13
|
+
# puede vaciar es una pestaña que nadie mira. El SARIF queda como artefacto de la
|
|
14
|
+
# ejecución, legible cuando alguien quiera el detalle.
|
|
15
|
+
name: scorecard
|
|
16
|
+
|
|
17
|
+
on:
|
|
18
|
+
push:
|
|
19
|
+
branches: [main]
|
|
20
|
+
schedule:
|
|
21
|
+
- cron: "41 5 * * 2"
|
|
22
|
+
|
|
23
|
+
permissions:
|
|
24
|
+
contents: read
|
|
25
|
+
|
|
26
|
+
jobs:
|
|
27
|
+
analyse:
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
permissions:
|
|
30
|
+
contents: read
|
|
31
|
+
id-token: write # con lo que firma `publish_results`; no es una clave nuestra
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
34
|
+
with:
|
|
35
|
+
persist-credentials: false
|
|
36
|
+
|
|
37
|
+
- uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4
|
|
38
|
+
with:
|
|
39
|
+
results_file: results.sarif
|
|
40
|
+
results_format: sarif
|
|
41
|
+
publish_results: true
|
|
42
|
+
|
|
43
|
+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
|
|
44
|
+
with:
|
|
45
|
+
name: scorecard-results
|
|
46
|
+
path: results.sarif
|
|
47
|
+
retention-days: 30
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Contribuir
|
|
2
|
+
|
|
3
|
+
## Lo más útil que puedes aportar
|
|
4
|
+
|
|
5
|
+
**Un registro real que esta herramienta juzga mal.** Un falso positivo —algo marcado
|
|
6
|
+
como `error` que la AEAT acepta— es el defecto más grave que puede tener un linter de
|
|
7
|
+
cumplimiento, porque hace que alguien cambie código correcto y deje de creerse el
|
|
8
|
+
resto del informe. Si te encuentras uno, ábrelo como issue con el caso mínimo que lo
|
|
9
|
+
reproduce (anonimizado: NIF y números de factura ficticios bastan).
|
|
10
|
+
|
|
11
|
+
Lo segundo más útil: **un incumplimiento real que no detecta**.
|
|
12
|
+
|
|
13
|
+
## Entorno
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/easybytehub/verifactu-lint
|
|
17
|
+
cd verifactu-lint
|
|
18
|
+
python -m venv .venv
|
|
19
|
+
.venv/bin/pip install -e ".[dev]"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Los tres gates, que son los mismos que corren en CI:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
.venv/bin/python -m ruff check .
|
|
26
|
+
.venv/bin/python -m mypy
|
|
27
|
+
.venv/bin/python -m pytest
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Escribir una regla
|
|
31
|
+
|
|
32
|
+
Una regla es una función `list[Registro] -> list[Hallazgo]`. No hay clase base, ni
|
|
33
|
+
registro por decorador, ni sistema de plugins: escribes la función, la añades a la
|
|
34
|
+
tupla `REGLAS` de su familia en `src/verifactu_lint/reglas/`, y le pones un test.
|
|
35
|
+
|
|
36
|
+
Recibe la lista completa y no un registro suelto porque casi todo lo que importa aquí
|
|
37
|
+
es relacional —el encadenamiento, la numeración duplicada, cuántas cadenas hay
|
|
38
|
+
mezcladas— y una interfaz de uno en uno obligaría a las reglas interesantes a
|
|
39
|
+
mantener estado por su cuenta.
|
|
40
|
+
|
|
41
|
+
Toda regla necesita:
|
|
42
|
+
|
|
43
|
+
1. **La cita normativa concreta** en el campo `norma`. Sin ella el hallazgo no se
|
|
44
|
+
puede contrastar, y un informe que hay que creerse a ciegas no sirve de nada.
|
|
45
|
+
2. **Una severidad justificada.** Si no puedes demostrar el incumplimiento con lo que
|
|
46
|
+
hay en el fichero, es `AVISO` o `INCOMPLETO`, no `ERROR`.
|
|
47
|
+
3. **Dos tests como mínimo**: uno con un caso que la dispare y otro con uno que no.
|
|
48
|
+
4. **Agregación si puede repetirse.** Una regla que emita un hallazgo por registro
|
|
49
|
+
produce miles de líneas idénticas en un fichero real y hace ilegible el informe.
|
|
50
|
+
Emite uno por campo o por causa, y di cuántos registros afecta.
|
|
51
|
+
|
|
52
|
+
Los identificadores de regla (`RRSIF0NN`) son estables: no se reutilizan ni se
|
|
53
|
+
renumeran, porque la gente los mete en configuraciones y filtros.
|
|
54
|
+
|
|
55
|
+
## Los vectores oficiales
|
|
56
|
+
|
|
57
|
+
`tests/test_huella.py` contiene los tres ejemplos del apartado 6 del documento de la
|
|
58
|
+
AEAT *Detalle de las especificaciones técnicas para generación de la huella o hash de
|
|
59
|
+
los registros de facturación*.
|
|
60
|
+
|
|
61
|
+
**Esos tests no se tocan.** Si un cambio los rompe, es el cambio el que está mal. Son
|
|
62
|
+
lo único que permite a esta herramienta afirmar algo sobre el cumplimiento de otros.
|
|
63
|
+
|
|
64
|
+
## Workflows
|
|
65
|
+
|
|
66
|
+
Las acciones se fijan al SHA completo del commit, nunca a una etiqueta: una etiqueta
|
|
67
|
+
la puede mover su autor, y el workflow de release sostiene un token capaz de publicar
|
|
68
|
+
paquetes. Hay un test que lo comprueba (`tests/test_workflows.py`), así que no hace
|
|
69
|
+
falta acordarse.
|
|
70
|
+
|
|
71
|
+
## Estilo
|
|
72
|
+
|
|
73
|
+
Los comentarios explican **por qué**, no qué. El qué ya está en el código. Si un
|
|
74
|
+
fragmento existe porque una alternativa evidente no funciona, escribe cuál y por qué:
|
|
75
|
+
eso es lo que evita que alguien lo «simplifique» dentro de seis meses.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|