einvoice-validatorDocs

Build and test

For contributors, and for anyone who wants to check the claims: everything on this page runs in a clone of the repository. To validate invoices with the released version, 0.4.0 on crates.io, see Use it; the commands below build the workspace and check the engine, the library and the command-line tool against Saxon-HE on the corpus of every rule set.

Requirements

Build and install from source

The released command-line tool installs from crates.io without a clone, with Rust 1.99 or later; the library is the crate einvoice-validator, documented on docs.rs:

cargo install --locked einvoice-cli
# in Cargo.toml: einvoice-validator = "0.4"

From a clone, for the current main:

git clone https://github.com/einvoice-validator/einvoice-validator.git
cd einvoice-validator
# install the pinned toolchain if needed
scripts/check.sh toolchain
cargo build --workspace --locked
# install the command-line tool, einvoice-validate
cargo install --locked --path crates/einvoice-cli

Cargo.lock is committed; every cargo command in the checks uses --locked.

Checks

CI and a local run execute the same script, with the same flags. Every warning is an error.

# every job
scripts/check.sh
# selected jobs
scripts/check.sh clippy test
# only install the pinned toolchain
scripts/check.sh toolchain
JobWhat it runs
fmtcargo fmt --all --check
clippycargo clippy --workspace --all-targets --all-features --locked -- -D warnings
doccargo doc --workspace --no-deps --all-features --locked
testUnit and integration tests, then the doctests
featuresClippy and the tests of einvoice-validator with --no-default-features (no built-in rule set)
wasmeinvoice-validator, einvoice-pdf and einvoice-xml built for wasm32-unknown-unknown, then their examples built for that target (the evaluator, the built-in rule set on two corpus documents, two PDF files built in memory, the XML reader): each must import nothing and return 0 under wasmtime
npmThe npm package built (wasm-bindgen, wasm-opt), its Node.js tests (the API, the CEN UBL and CII corpora against the Saxon-HE results), a strict TypeScript check of its declarations, the browser test in headless Chrome and Firefox, then npm pack --dry-run
packageThe publishable crates packaged as crates.io would receive them and built from their packages; each term of a crate's licence expression must have its text in the package
denycargo deny --all-features check: licences, advisories, bans, sources
actionlintLints the GitHub Actions workflows
zizmorSecurity audit of the workflows and the Dependabot configuration, pedantic persona
pinsEvery pin of upstream.toml matches the files that record it (offline), and the tests of the freshness script
guardsShellCheck on the scripts and git hooks, then the tests of the privacy guard and of the release scripts
oracleThe CEN corpus, the xmllint oracle and the Saxon-HE reference oracle (below)
peppolThe Peppol corpus built in target/peppol/, its Saxon-HE results, then the engine and einvoice-validate with the Peppol bundle against them, and the Schematron compiled in Rust against ph-schematron (below)
facturx, xrechnung, fr-ctcThe corpus of each family of fetched rule sets built in target/, its Saxon-HE results and cross-checks, then the engine against them, and xmllint and einvoice-xsd on its CII documents (below)
rulesThe rule sets fetched on demand: the pins embedded in the crate are the fetch scripts' pins, rules fetch assembles from the scripts' downloads, byte for byte, the bundles the scripts wrote, and einvoice-validate --rules NAME gives the Saxon-HE results and the reference validators' verdicts on every corpus of the four jobs above
privacyThe repository's content guard on staged changes; does nothing when nothing is staged

Tests

# everything
cargo test --workspace --all-features --locked
# one crate
cargo test -p einvoice-xdm --locked
# the tests of a crate whose path contains a name
cargo test -p einvoice-xdm --locked every_case
# corpus checks, no Java needed
cargo test -p xtask --locked

Besides unit tests: golden tests against results produced by the reference engines, and property-based tests with proptest. None of the CEN tests, UBL or CII, needs Java or xmllint: the expected results are committed.

# the engine on all 1179 CEN cases: its canonical SVRL must equal the Saxon-HE golden
cargo test -p einvoice-xslt-exec --release --locked --test cen_equivalence -- --nocapture
# the engine on the mutation cases (CEN; Peppol too when its corpus is built)
cargo test -p einvoice-xslt-exec --release --locked --test mutation_equivalence -- --nocapture
# the library's verdicts and findings on all 1179 CEN cases
cargo test -p einvoice-validator --release --locked --test cen_corpus -- --nocapture
# the engine on the 24 CEN CII cases and its 808 mutation cases
cargo test -p einvoice-xslt-exec --release --locked --test cii_equivalence -- --nocapture
# the library's verdicts and findings on the CII cases and mutation cases
cargo test -p einvoice-validator --release --locked --test cii_corpus -- --nocapture
# einvoice-validate on the CII corpus, the rule set picked from the root element or named
cargo test -p einvoice-cli --release --locked --test cii
# the depth, nesting and stack limits
cargo test -p einvoice-validator --locked --test depth
cargo test -p einvoice-xslt-exec --locked --test limits
# the executor on synthetic probe stylesheets, against Saxon-HE results
cargo test -p einvoice-xslt-exec --locked --test probes
# the evaluator against Saxon-HE on every distinct expression of the CEN stylesheet
cargo test -p einvoice-xpath-eval --locked --test oracle
# the atomic values against Saxon-HE results
cargo test -p einvoice-xdm --locked --test oracle
# schema validation against the xmllint results
cargo test -p einvoice-xsd --locked --test oracle

The equivalence test prints 1179 cases: 1179 equal, 0 different, 0 failed, and the mutation test CEN: 508 mutation cases: 508 equal, 0 different; for CII, 24 CII cases: 24 equal, 0 not and CII: 808 mutation cases: 808 equal, 0 different; any difference is shown with the first line where the two reports diverge. A mutation case on which Saxon-HE stops with a dynamic error must stop the engine with the same error code; the cases where the message differs are listed, not failed.

Test corpus and reference oracle

artefacts/ holds unmodified copies of the official validation artefacts, corpus/ the test cases derived from them and, for each case, the SVRL report Saxon-HE 12.10 produces (or the error that stops it), in the canonical form of corpus/SVRL-CANONICAL.md. Besides the official examples, test files and unit tests, the corpus has mutation cases: the edits of corpus/mutations.toml (UBL) and corpus/mutations-cii.toml (CII) applied to official examples. The CEN UBL corpus has 1179 cases and 508 mutation cases, the CEN CII corpus 24 cases (the 15 examples and the 9 VEFA tests of the release) and 808 mutation cases. The format is described in corpus/README.md.

# vendored files match artefacts/*/SHA256SUMS
cargo xtask manifest
# the corpus re-derived from artefacts/, mutation cases included, matches the committed one
cargo xtask corpus
# Saxon results vs the expectations of the official unit tests
cargo xtask crosscheck
# Saxon-HE 12.10 and the XML Resolver 5.3.3 from Maven Central,
# checksums verified, into target/oracle/saxon/
scripts/fetch-saxon.sh
# Saxon-HE on every CEN UBL and CII case and mutation case: results must equal the committed ones
cargo xtask oracle
# all of the above, then the xmllint oracle and the Saxon-HE oracles of
# einvoice-xdm, einvoice-xpath-eval and einvoice-xslt-exec
scripts/check.sh oracle

--write regenerates instead of checking (manifest, corpus, oracle). cargo xtask oracle also takes --java JAVA and --saxon JAR; scripts/check.sh oracle reads them from the JAVA and SAXON_JAR environment variables. Without Java, scripts/check.sh oracle runs the manifest, corpus and cross-check and skips the Saxon runs (in CI it fails instead). cargo test covers the manifest, extraction and cross-check without Java.

Schema validation has its own oracle, xmllint (libxml2): for UBL 2.1, the corpus documents, synthetic documents and mutations of them; for CII D16B, the 24 cases and 808 mutation cases of the CEN CII corpus, and in the facturx, xrechnung and fr-ctc jobs the CII corpora of those rule sets. A second, synthetic suite (180 document cases and 69 schema mutations) covers the XML Schema constructs the CII-family schemas add: fixed and default values, anonymous complex types in local element declarations, length facets on the string types. Every difference from xmllint is listed with its cause in crates/einvoice-xsd/tests/oracle/.

# run xmllint on every case of both suites, check the committed results, compare
cargo run --release --locked -p einvoice-xsd --example xmllint-oracle

Peppol corpus and bundle

The Peppol BIS Billing 3.0 files carry no licence, so neither they nor anything derived from them is committed: the corpus is built locally in target/peppol/. scripts/fetch-peppol.sh downloads the pinned 3.0.22 release and compiles its Peppol and CEN Schematron to XSLT with ph-schematron 10.3.1 itself (the reference), every input and output checked against a pinned checksum, and writes the bundle.toml that makes the directory a rule-set bundle. einvoice-validate rules fetch peppol builds the same bundle, byte for byte, with the Schematron compiled in Rust (einvoice-schematron), and a test checks each step of that compilation against ph-schematron. CI builds the corpus and runs these checks whenever the engine or the tooling changes.

# the release and its two compiled stylesheets, checksums verified,
# into target/peppol/peppol-bis-billing-ubl-3.0.22/, with its bundle.toml
scripts/fetch-peppol.sh
# 707 cases and 509 mutation cases, the Saxon-HE results of both
# stylesheets, and the cross-check with the official unit tests
cargo xtask peppol
# the engine on all 707 cases, with each stylesheet
cargo test -p einvoice-xslt-exec --release --locked --test peppol_equivalence -- --nocapture
# einvoice-validate with the Peppol bundle, against the same results
cargo test -p einvoice-cli --release --locked --test peppol_bundle -- --nocapture
# the Schematron compiled in Rust, byte for byte the stylesheets of ph-schematron
cargo test -p einvoice-schematron --locked --test peppol -- --nocapture
# all of the above, and the Peppol mutation cases
scripts/check.sh peppol

The equivalence test prints PEPPOL-EN16931-UBL: 707 cases: 707 equal, 0 different, 0 failed and the same for CEN-EN16931-UBL, the CEN rules the Peppol release embeds (the bundle.toml gives them the CEN version their Schematron states, 1.3.16), and the mutation test PEPPOL-EN16931-UBL: 509 mutation cases: 509 equal, 0 different; the cross-check reports 678 unit-test cases out of 678 in agreement with Saxon-HE.

Factur-X, XRechnung and the French rules

Their files may not be redistributed either, and their corpora are built locally the same way, each by a fetch script (every input checked against a pinned digest) and a cargo xtask command that extracts the cases, runs Saxon-HE with every stylesheet, writes the acceptance table (each document as the reference validator reads its findings) and cross-checks the results with the expectations: the XML Mutate expectations of the XRechnung unit tests, and the published examples, which must be accepted. The corpora: Factur-X 1.09.2, 42 cases and 808 mutation cases, five stylesheets; XRechnung 3.0.2, 1196 UBL and 686 CII cases and 508 + 808 mutation cases, two stylesheets per syntax, the scenarios of the KoSIT configuration and the verdict of its XML schema (xmllint); French rules 1.4.0.04, 53 CII, 75 UBL and 70 CDAR cases and 808 + 508 mutation cases, seven, four and two stylesheets.

# one family: fetch, corpus, Saxon-HE results, cross-checks, then the engine
scripts/check.sh facturx
scripts/check.sh xrechnung
scripts/check.sh fr-ctc
# or step by step
scripts/fetch-xrechnung.sh                # into target/xrechnung/
cargo xtask xrechnung                     # the corpora and their Saxon-HE results
cargo test -p einvoice-xslt-exec --release --locked --test xrechnung_equivalence -- --nocapture
# einvoice-validate --rules NAME on every fetched corpus: Saxon-HE results and verdicts
scripts/check.sh rules

The equivalence tests print one line per stylesheet, for instance xrechnung-ubl-3.0.2 XRechnung-UBL: 1704 cases (508 mutation cases): 1704 equal, 0 not. On the corpora as built for 0.4.0, every stylesheet gives the Saxon-HE result on every case: 4250 runs for Factur-X, 6396 for XRechnung, 8499 for the French rules.

Performance

cargo xtask bench measures the wall time, CPU time and peak memory of einvoice-validate and of Saxon-HE 12.10 on the whole corpus of each rule set (every document, mutation cases included), at the given thread counts: 23 jobs, one per rule set as einvoice-validate --rules NAME runs it, from the cache rules fetch fills, with its XML schema step, scenarios and verdicts, which must be the reference verdicts on every document and every run (#41); a run of einvoice-validate doing exactly Saxon-HE's work (each stylesheet alone, on every document, no schema), Saxon-HE's time without the JVM start, and the latency of one document in a new process. Each command runs once to warm up, then the given number of times, the tools taking turns; each run is measured by a helper process (getrusage of its only child). The results, the method and the machine are in docs/benchmarks.md, every run in docs/benchmarks.json; a summary is on the home page.

cargo build --release --locked -p einvoice-cli
scripts/fetch-saxon.sh
# the fetched corpora (Java, xmllint, network the first time)
scripts/check.sh peppol facturx xrechnung fr-ctc
# every rule set, 1 and 8 threads; --write updates docs/benchmarks.md and .json
cargo xtask bench --runs 5 --threads 1,8
# some rule sets only: all, the groups cen, peppol, facturx, xrechnung,
# fr-ctc, fr-ctc-cii, fr-ctc-ubl, or rule sets by their --rules names
# (cen-ubl, factur-x-en16931, fr-ctc-cdar, ...)
cargo xtask bench --families cen --runs 3

Memory of one validation, measured by a counting allocator, and its budget:

# peak heap and time of a validation and of its stages, on the largest CEN corpus
# document and on a synthetic invoice of 5000 lines
cargo run --release --locked -p einvoice-validator --example footprint
# the budget: fails when a validation peaks above it
cargo test -p einvoice-validator --release --locked --test footprint
# the heap of the UBL 2.1 and CII D16B schemas and of validating the CEN corpora
cargo run --release --locked -p einvoice-xsd --example heap

Repository layout

crates/einvoice-bigint
Arbitrary-precision signed integers in safe Rust, without dependencies and without assembly, behind xs:integer and xs:decimal; no division panics.
crates/einvoice-xml
A streaming (pull) XML 1.0 parser with namespaces that builds no tree; every document the validator checks, validates against a schema or gives the stylesheets is read with it.
crates/einvoice-xpath
Parser and syntax tree for the XPath 2.0 subset of the official stylesheets, XSLT match patterns, sequence types and attribute value templates.
crates/einvoice-xdm
Atomic values of the XPath 2.0 data model: exact xs:decimal, xs:integer, xs:double, dates, casts, comparisons, regular expressions, with the behaviour of Saxon-HE 12.10.
crates/einvoice-xpath-eval
Node model and evaluator of the XPath 2.0 subset, with the behaviour of Saxon-HE 12.10; unknown functions and variables are refused when an expression is compiled. The clock is an input, so it runs on wasm32-unknown-unknown.
crates/einvoice-xslt
Loader for the XSLT 2.0 subset emitted by the Schematron compilers: templates, modes, priorities, imports, functions, variables and instructions; anything outside the subset is a load error.
crates/einvoice-xslt-exec
Executor of that subset: a stylesheet is prepared once and run on any number of documents, writing the result (SVRL for the rule sets) compactly, read as it is written. Constructs whose result would differ from Saxon's are refused when the stylesheet is prepared.
crates/einvoice-schematron
Schematron compiled to XSLT as ph-schematron 10.3.1 compiles it, byte for byte: the ISO Schematron skeleton run by the engine.
crates/einvoice-svrl
The canonical, line-oriented form of SVRL reports, shared by the oracle and the equivalence tests.
crates/einvoice-xsd
XML Schema validation against the official OASIS UBL 2.1 and UN/CEFACT CII D16B schemas, which it embeds; exactly the XML Schema 1.0 constructs those schemas and the CII-family schemas use, any other refused at load.
crates/einvoice-pdf
Extracts the embedded invoice XML and the XMP metadata of a Factur-X, ZUGFeRD or Order-X PDF/A-3 file, reading only the part of PDF on the path to embedded files; bounded against hostile input.
crates/einvoice-validator
The public crate: rule-set bundles (a bundle.toml manifest with the SHA-256 of each stylesheet and of each file it reads, severities and scenarios; CEN EN 16931 UBL and CII 1.3.17 built in), the rule sets fetched on demand (feature fetch), the Validator, the Report and Syntax (UBL or CII, from the root element).
crates/einvoice-cli
The einvoice-validate command-line tool: XML and PDF files and standard input, built-in rule sets (chosen from each document's root element by default), fetched rule sets or bundle directories, several threads, text, JSON or SVRL output, documented exit codes.
crates/einvoice-wasm
The JavaScript and TypeScript bindings and the build of the npm package einvoice-validator; not published on crates.io.
crates/einvoice-testkit
Helpers of the tests, not published: synthetic PDF files and invoices, the supply-chain audit, the third-party notices.
xtask
Repository tooling behind cargo xtask: manifest, corpora and mutation cases, oracle, cross-checks, the corpora of the fetched rule sets, the benchmark.
artefacts
Official validation artefacts, unmodified, with their licence and SHA256SUMS.
corpus
Test cases and their Saxon-HE results, one directory per rule set (only the README and the records of comparisons for the fetched ones), and the mutation catalogues (UBL and CII).
docs
The benchmarks (benchmarks.md, benchmarks.json) and the dependency audit (dependencies.md).
scripts
check.sh, fetch-saxon.sh, the fetch scripts of the rule sets, freshness.sh, the release scripts and the other repository scripts.
upstream.toml
Every pinned upstream version (rule sets, Saxon-HE, toolchain, CI tools) and the files that record it; a weekly workflow reports newer releases.
RELEASING.md
The release process and the versioning policy.