Conformance runner

Runs the official HL7 FHIRPath test suite against Callis and reports the results (T0022, ADR-0011). This package is private and never published.

The reports are published on the documentation site: R4 and R5. They are generated, never committed: pnpm conformance and the site build write them to docs/conformance/, which git ignores, so parallel PRs have no report to conflict on. CI writes them too and uploads them with a JSON summary and every test result as the conformance-results artifact of each run. There is no official R6 FHIRPath suite, so there is no R6 report; the engine's tests against the R6 provider are not conformance results (FHIR versions).

Commands

Run them from the repository root.

CommandWhat it does
pnpm conformanceRun both suites, write the reports to docs/conformance/, and compare with the baseline. Fails if a test in the baseline no longer passes.
pnpm conformance --update-baselineThe same, and record the passing tests in baseline/. Refuses if a baseline test regressed.
pnpm conformance --checkWhat CI runs. Fails on a regression or on a baseline that is out of date.
pnpm conformance --reports-onlyWrite the reports and nothing else: no baseline is read, and the exit code ignores test results. The site build runs it.
pnpm test:conformanceThe suite as Vitest tests, one per suite test, with diffs for wrong results. Filter with -t, for example pnpm test:conformance -t testLiterals. Not part of pnpm test.
pnpm --filter @callis/conformance update-fixtures --ref <commit>Vendor the suite at another upstream commit. Do it in its own PR, and convert the XML inputs again.
pnpm --filter @callis/conformance convert-fixturesConvert the suite's XML inputs to JSON (converted inputs). No network needed.
pnpm --filter @callis/conformance update-official-examplesVendor the official JSON examples that the converted inputs are compared with.

Every mode of pnpm conformance writes the Markdown reports, to docs/conformance/ or to the directory of --reports <dir>. --results <file> also writes every test result as JSON, and --summary <file> the counts per suite, phase and group.

When evaluation behaviour changes: run pnpm conformance --update-baseline and commit baseline/. Do not commit reports: there is nothing in docs/conformance/ to commit. The PR's validation comment shows the change in passing tests per phase (CONTRIBUTING).

Layout

PathWhat
fixtures/r4/, fixtures/r5/The vendored suite files and the input files they use, unchanged (SOURCE.md), and the JSON converted from each XML input (name.json next to name.xml).
fixtures/source.jsonThe pinned commit and the SHA-256 of every vendored file. A unit test checks them.
official-examples/Official FHIR JSON examples the converted inputs are compared with (SOURCE.md).
baseline/The tests that pass: r4.txt and r5.txt, one test ID per line, sorted (below). Written by --update-baseline.
src/adapter.tsThe evaluator adapter interface.
src/engine-adapter.tsThe adapter the commands use: the engine's internal API (T0008), with the UCUM unit system.
src/core-source.tsResolves @callis/core to core's source for pnpm conformance, so @callis/ucum shares the engine's copy of core.
src/parse-suite.ts, src/suite.tsThe test-file parser and model.
src/classify.tsPhase 1, STU or unsupported.
src/compare.tsTyped comparison of results with expected outputs.
src/run-suite.tsRuns and judges tests.
src/report.ts, src/summary.ts, src/baseline.ts, src/baseline-files.ts, src/cli.tsReports, counts, the ratchet, the baseline files and the command line.
src/xml-reader.ts, src/fhir-xml.ts, src/json-text.tsThe XML reader, the FHIR XML → JSON converter and the JSON writer that keeps numbers as written.
src/fixture-conversion.ts, src/official-examples.tsWhich inputs are converted, and the comparison with the official examples.
suite/The Vitest project behind pnpm test:conformance.

Plugging in an evaluator

The runner never imports @callis/core. It calls an EvaluatorAdapter (src/adapter.ts), and src/engine-adapter.ts chooses which one; it is the only file of the runner that imports the engine. Since T0008 that is an adapter over the engine's internal compile()/evaluateAsync(); since T0018 it evaluates each suite file with the generated model of its FHIR version (@callis/fhir-r4 for r4, @callis/fhir-r5 for r5), with the choice-type suffix only for mode="lenient/polymorphics" (ADR-0012), and parses the inputs with the engine's lossless parseJson(), so the decimals keep the precision of the converted fixtures. It compiles with the full UCUM unit system of @callis/ucum (T0006), also from source: pnpm conformance preloads src/core-source.ts and the Vitest configs have an alias, so the @callis/core that @callis/ucum imports is the engine's own source and no build is needed. It reports spec functions, FHIR variables and operators that a later task adds as "not implemented", so a test that expects an error never passes because a feature is missing (spec notes). It passes the fake conformsTo and htmlChecks hooks of src/fake-hooks.ts to every evaluation (T0021), so the hook-backed functions are measured like the others: conformsTo() knows the base profiles of the suite model's resource types and raises an execution error for any other profile, as testConformsTo3 expects, and htmlChecks() checks the element names against FHIR's narrative rules. No suite test needs a terminology provider, so memberOf(), subsumes() and subsumedBy() stay empty. The stub adapter in src/stub-adapter.ts, which throws "not implemented" for every evaluation, remains for the runner's own tests. The minimal T0025 public facade deliberately leaves this adapter on the internal API: conformance needs typed values and capabilities deferred from that facade. The expanded API task will switch it when those contracts are public.

ts
interface EvaluatorAdapter {
readonly name: string; // shown in the reports
parseInput?(text: string): unknown; // default JSON.parse; the engine adapter passes parseJson()
evaluate(input: unknown, expression: string, options: EvaluationOptions):
readonly unknown[] | PromiseLike<readonly unknown[]>; // the result collection, or throw
describeValue(value: unknown): ResultItem; // one result item, for comparison
classifyError(error: unknown): ClassifiedError; // what evaluate() threw
}
  • evaluate gets the parsed input file (undefined when the test has none), the expression, and EvaluationOptions built from the test's attributes:

    OptionFromMeaning
    fhirVersionthe suite filer4 or r5; selects the FHIR model.
    context, contextTypescontext, contextTypeEvaluate context on the input first; it selects exactly one node, and the expression is evaluated with that node as its focus. %resource and %rootResource stay the whole input. contextTypes are the declared types of the focus for static analysis.
    modemode of the test, its expression or its groupThe raw mode, for example element or html.
    strictmode="strict"N1 §11 strict evaluation.
    lenientChoiceSuffixmode="lenient" or lenient/polymorphicsAccept Observation.valueQuantity (ADR-0012).
    skipStaticCheckskipStaticCheckEvaluate without static analysis.

    It may return a promise. Inputs are parsed once per file and shared, so evaluation must not mutate them.

  • describeValue turns one result item into { type, value?, unit? }: the qualified type name (System.Decimal, FHIR.code, FHIR.HumanName), and for primitives and quantities the value as text with its precision (1.50, 2014-01-01, 10:30:00.000) and the unit (cm, days).

  • classifyError maps the engine's errors to syntax (FhirPathSyntaxError), semantic (FhirPathSemanticError), execution (FhirPathEvaluationError), not-implemented or other, with the error code and message.

How tests are run

Each test is classified first:

PhaseWhich testsRun?
Phase 1N1 normative content, Math and the FHIR additions (ADR-0001)yes
STUtests with version newer than 2.0.0, mode="tx", a call to an STU function (sort, aggregate, lowBoundary, type, …) or STU syntax ($total, 1L), and the STU-only groups. The report names the task (T0026–T0032) that implements them.yes
Unsupportedthe cdaTests and documentFunctions groups, mode="cda", mode="custom" and unknown modesskipped

A test is skipped, with the reason, when it is unsupported, when it is an exception (below), or when its input is missing. XML inputs are read from the JSON converted from them (name.json next to name.xml, below); a test whose XML input has no converted JSON is skipped as "fixture not converted", which no phase-1 or STU test is.

A test that runs passes when:

  • invalid="syntax" or "execution": evaluation throws an error of that class.
  • invalid="semantic": evaluation throws a semantic error, or an evaluation error, which the report counts as "detected late" (spec notes).
  • invalid="true": evaluation throws any FHIRPath error.
  • otherwise: the result matches the outputs, item by item and in order (as a multiset when ordered="false"). No outputs means an empty result. With predicate="true" the result is first converted to a Boolean.

"Not implemented" and non-FHIRPath errors (other) never pass.

Comparing values. An output's type must be the result item's type: System.Decimal counts as decimal, FHIR.code as code, and types the suite does not name (FHIR.uri, FHIR.HumanName) never match. Values are compared exactly: decimals must have the same value and the same number of decimal places (1.50 is not 1.5), dates and times as text without @, and quantities by value and unit. An output with empty text checks only the type. R4 has outputs without a type; their text is a FHIRPath literal and is compared by kind. The rules follow the HL7 Java test runner; the details and differences are in spec notes.

Test IDs are the test names, made unique per file with a #2, #3 suffix (the R4 file has two testEquivalent23).

Exceptions. A test whose expectation is wrong for Callis is listed in src/exceptions.ts with a link to its entry in docs/spec-notes.md, and skipped.

Reports name each failing test with its expression and a one-line problem: the failure kind and the engine's error code, never the engine's message text or a file path. A report therefore only changes when an outcome changes. The full message is in pnpm test:conformance and in the CI results artifact.

Baseline and CI

The baseline is the ratchet, and it is committed and reviewed. baseline/r4.txt and baseline/r5.txt list every passing test of a suite, one test ID per line, sorted. A baseline test that stops passing is a regression, which always fails. A baseline test can leave the baseline in only two ways: it is no longer in the suite (after a fixture update), or it is skipped on purpose because it became an exception or unsupported. pnpm conformance --update-baseline drops those tests and records new passes, and refuses to run when there is a regression. Do not edit the files by hand.

  • Only additions go without review. A PR that removes a line from a baseline file is labelled risk:high by scripts/review-areas.ts (CONTRIBUTING). Sorting a file again, which removes and adds the same lines, is not a removal. A test ID that moves from one suite to the other counts as removed from the first.
  • Parallel PRs do not conflict. .gitattributes merges the files with merge=union: when two PRs record different new passes, git keeps the lines of both, even next to each other. The runner reads the file as a set, so the order, a repeated line and a blank line do not matter, and the next --update-baseline sorts the file again. Merge main and run pnpm conformance --check: it tells you if anything is missing. A removal next to a change from the other side can come back from the merge; CI then says that the test is no longer in the suite or is skipped on purpose, and --update-baseline drops it again.
  • Not in the baseline file: the reports. They are generated from the vendored suites and the engine (below), so they never conflict and never go out of date.

CI runs pnpm conformance --check. It fails on a regression or on a baseline that is out of date (tests to drop or new passes to record): the PR that changes a test's outcome records it. The check adds a job summary, and uploads the reports, the JSON summary and every test result as the conformance-results artifact of the run, so a reviewer can read the numbers of a PR. Locally, pnpm conformance fails only on a regression and lists the rest as hints. The decision is ratchetFails() in src/baseline.ts. The job is blocking: it fails the required CI result check.

The site publishes the reports of main. Its build (apps/site/scripts/collect.ts) runs pnpm conformance --reports-only before it collects docs/, so /conformance/r4 and /conformance/r5 show the engine of the commit that is built, and pnpm site:dev and pnpm site:build work in a fresh clone. The progress page reads the numbers of each commit from the baseline at that commit: its entries are the passing tests, and the run of the build says which of them are Phase 1 (apps/site/progress/conformance.ts). Commits from before the reports stopped being committed still have theirs, and the page reads those as they are.

Converted XML inputs

Most inputs are FHIR XML, and the engine reads JSON. pnpm --filter @callis/conformance convert-fixtures converts each XML input name.xml that a suite references to name.json next to it, once, and the JSON is committed (T0023, ADR-0011). The converted files are generated: change the converter and run the script again, never edit them by hand. A unit test fails while a committed file is not what the script writes.

The converter (src/fhir-xml.ts) is driven by the generated FHIR model of the suite's version (@callis/fhir-r4 for R4, @callis/fhir-r5 for R5), so the JSON follows the FHIR JSON format:

  • Elements that repeat in the model are arrays, even with one item; properties follow the model's element order, after resourceType.
  • boolean values are JSON booleans. integer, its subtypes and decimal are JSON numbers written with the exact text of the XML value, so 1.50 and 9.5e2 stay as they are. Other primitives, including R5 integer64, are strings.
  • The id and extensions of a primitive go to _name, aligned with nulls when the element repeats. Element.id and Extension.url are XML attributes and ordinary JSON properties.
  • The narrative div is a string, copied from the XML as written.
  • Contained and nested resources lose their XML wrapper; choice elements keep their typed name (valueQuantity).
  • XML comments are dropped. Anything the model does not define, or XML the reader does not accept (a DTD, an undefined entity), is an error, not a guess. The details are in spec notes.

Not converted: r5/ccda.xml, a CDA document rather than FHIR. Only the out-of-scope cdaTests group uses it. The list is UNCONVERTED_INPUTS in src/fixture-conversion.ts; a unit test checks that only unsupported tests use those inputs.

Checked against the official examples. Ten converted inputs are copies of examples in the FHIR specification. A unit test compares each with the official JSON example from the hl7.fhir.r4.examples and hl7.fhir.r5.examples packages, vendored in official-examples/. The differences must be exactly the ones listed with their reason in src/official-examples.ts: the suite edited its copy of the example, the examples package added metadata, or the official JSON writes the same narrative XHTML differently. There are no differences in names, cardinality, types or numbers.

Decimal precision. The runner parses an input with the adapter's parseInput, and with JSON.parse when the adapter has none. JSON.parse loses what the converted JSON keeps: 1.50 becomes 1.5 and 9.5e2 becomes 950. Since T0018, the engine adapter sets parseInput to the engine's lossless parseJson, so tests that observe the precision of a decimal from an input see it as written. An adapter without the hook can fail such tests for that reason alone; the baseline records only tests that really pass.