T0022 — Conformance runner
Part of the roadmap. Phase 1 · wave 1 · size M.
Goal
Run the official HL7 FHIRPath test suite and report the results (design notes, ADR-0011).
Scope
tools/conformance(private):- vendored
tests-fhir-r5.xml(fromr5/fhirpath/) andtests-fhir-r4.xml(fromr4/fhirpath/), plus every input file they reference, from FHIR/fhir-test-cases at a pinned commit SOURCE.mdwith the commit SHA and the Apache-2.0 notice- an
update-fixturesscript
- vendored
- A test-file parser (a dev-only XML parser such as
fast-xml-parseris fine). - Typed comparison of expected outputs (
boolean,integer,decimal,string,date,dateTime,time,code,id,Quantity). - Support for
invalid,predicate,ordered,context/contextType,modeandversion. - Classification of each test as phase 1, STU or unsupported.
- An injectable evaluator: the runner calls a small adapter interface (adapter interface) rather than importing
@callis/coredirectly. A stub adapter in the runner is used until an engine exists. It answers "not implemented", so every test is reported as failing or skipped, not crashed.- T0008 wires the adapter to the engine's internal
compile()/evaluate(). - T0025 switches it to the public API.
- T0008 wires the adapter to the engine's internal
- A runner CLI and a Vitest project (
pnpm test:conformance). - Reports: Markdown to
docs/conformance/{r4,r5}.md(generated, never committed), a JSON summary (a CI artifact), and a CI job summary. The CI job is non-blocking until T0023. - A baseline ratchet (
tools/conformance/baseline/{r4,r5}.txt) and a CI check against it.
Design notes
- Source: the HL7 suite in FHIR/fhir-test-cases (Apache-2.0). That is
r5/fhirpath/tests-fhir-r5.xml(the source of truth, about 1,350 tests), the R4 copyr4/fhirpath/tests-fhir-r4.xml(about 1,190 tests), and the input files they reference fromr4/andr5/. - Fixtures are vendored into
tools/conformance/fixtures/{r4,r5}/at a pinned commit, with aSOURCE.mdrecording the commit SHA and license, and anupdate-fixturesscript. - Input conversion: most inputs are FHIR XML (
patient-example.xmlis used by roughly 1,000 tests). A model-driven XML → JSON converter (dev only; it uses the generated models and keeps decimal text) converts them once, and the JSON is committed. - Test semantics:
invalid="syntax"expectsFhirPathSyntaxError, andinvalid="execution"expectsFhirPathEvaluationError.invalid="semantic"expectsFhirPathSemanticError; an evaluation error also counts, but the report marks it "detected late", because N1 §11 leaves compile-time versus run-time checking to the implementation.invalid="true"accepts any error.- Labels the suite gets wrong for our scope are listed in
spec-notes.mdas exceptions. For example, the out-of-scopedocumentFunctionsgroup marks arity errors assyntax. <output type="…">values are compared using typed output; a test with no outputs expects an empty result.predicate="true"converts the result to a Boolean.contextandcontextTypeevaluate against a sub-node.mode(strict,lenient/polymorphics,element,html,tx,cda) maps to options or marks the test unsupported.versionmarks tests that need a newer FHIRPath version.
- Classification: each test is tagged phase 1, STU or unsupported from its group, its
testingattribute and itsversion. The report shows pass/fail/skip per group and per phase. - Outputs: the reports
docs/conformance/r4.mdandr5.md, a JSON summary uploaded with the CI results artifact, and a CI job summary. The reports are generated, never committed:pnpm conformance, the CI job and the site build write them, and the site publishes them at/conformance/r4and/conformance/r5. The first version of the runner committed them, and every PR that changed evaluation behaviour then conflicted on them (#187, 2026-11-09; ADR-0011 has the amendment). - Ratchet:
tools/conformance/baseline/r4.txtandr5.txtlist the passing tests, one test ID per line, sorted (the first version was onebaseline.json). CI fails if a test that used to pass now fails. A PR that makes more tests pass updates the baseline. - It also runs as a Vitest project (
pnpm test:conformance) to get per-test diffs.
Adapter interface
Defined in tools/conformance/src/adapter.ts and documented in tools/conformance/README.md. tools/conformance/src/engine-adapter.ts chooses the adapter; it is the only file T0008 and T0025 change to plug in the engine.
ts
interface EvaluatorAdapter {readonly name: string;parseInput?(text: string): unknown; // default JSON.parse; T0018's lossless parser goes hereevaluate(input: unknown, expression: string, options: EvaluationOptions): readonly unknown[] | PromiseLike<readonly unknown[]>;describeValue(value: unknown): ResultItem; // { type: 'System.Decimal', value: '1.50' }, …classifyError(error: unknown): ClassifiedError; // syntax | semantic | execution | not-implemented | other}
EvaluationOptions carries what the test asks for: the FHIR version, context and contextType, the raw mode, and strict, lenientChoiceSuffix and skipStaticCheck derived from it. describeValue keeps the typed comparison independent of the engine's value classes.
Decisions made while building the runner
- Converted inputs: an XML input
name.xmlis read fromname.jsonin the same fixture folder. T0023 writes those files; until then the tests are skipped as "fixture not converted". - Classification is per test, not per group: a test that calls an STU function is STU even in a phase-1 group (for example
testPeriodInvariantNewinperiod, and thetype()tests intestType). - Comparison follows the HL7 Java test runner (exact types, decimals with their precision, type-only checks for empty outputs); the details and the few differences are in spec notes.
- The ratchet also fails CI when the baseline is out of date: tests that pass but are not in it yet, or tests that must leave it (
pnpm conformance --check). While the reports were committed, an out-of-date report only warned, so parallel PRs did not serialize on the report files (owner decision in #65); now that they are generated, a report cannot be out of date. A baseline test that becomes an exception or unsupported is not a regression:--update-baselinedrops it, as it drops tests that left the suite. - Exceptions are listed in
tools/conformance/src/exceptions.ts, each with itsspec-notes.mdentry, and are skipped. - Report stability: the reports show failure kinds and error codes, not engine messages or file paths, so a report changes only when an outcome changes, not when an error message is reworded.
Acceptance criteria
- The runner runs end to end with its runner-local stub adapter. T0000's public API is still empty, so it does not depend on it. Every test is either run or skipped with a reason; nothing crashes the runner.
- The adapter interface is documented, so T0008 and T0025 can plug in the engine without changing the runner.
- Tests with JSON inputs run. Tests with XML inputs are skipped with the reason "fixture not converted" until T0023.
- The report shows pass/fail/skip per group and per phase, with links to the failing expressions.