Testing and quality
This page describes how we test @cosyte/ccda, what each technique catches, and what it cannot.
The shared rules every Cosyte package follows (the coverage and mutation floors, the property-based
runners, what a pull request must prove) are written down in the testing standard in
cosyte/config's decision records.
The numbers for the current release are in Current numbers below.
The failure we test hardest against is the quiet one. A coded value read wrong but plausible, an allergy that reads as absent, or a planned procedure that reads as performed travels downstream and nothing flags it. So most of what follows checks values, not only that the parser did not throw.
What we run, and what each technique catches
| Technique | What it catches | What it cannot catch |
|---|---|---|
| Unit tests | each documented behavior and each failure path of every module, run against the source: the warning and fatal codes, the entry families, the builder and the editor | an input nobody thought to write down |
| Conformance run | a document buildCcda emits that breaks the CDA R2 XML schema or the error-severity phase of the C-CDA R2.1 Schematron, and a public sample whose Schematron errors change when it is parsed and written back | the nine document types the builder does not emit; the Schematron's warning phase; value-set membership beyond the Schematron's own vocabulary file. It is an assessment against published artifacts, not a certification |
| Property-based tests | a whole class of input breaking a stated rule: a spec-clean document survives toString() and parsing again, normalizing twice changes nothing a first pass did not, lenient mode never throws except on the fatal codes and every warning it raises carries a registered code, and a parsed document cannot be changed by accident | a rule nobody stated; a case outside the cases run; a gap in what the generators produce |
| Fuzzing | a crash or an unexpected throw on hostile input: arbitrary strings, a document cut off at a random point and a document with a short random string inserted at a random point, alongside fixed attack inputs (an external entity, an entity-expansion bomb, deep nesting) | a wrong but plausible result, unless a property states what right is |
| Coverage gate | code no test runs: lines, branches, functions and statements, held at a floor of 100% for the whole package | a test that runs code without checking what it returns |
| Mutation testing | a test that runs code but would not notice it changing | a mutant StrykerJS does not make (it changes operators, conditions and literals, not whole designs); mutants in code that runs once, when a module loads, which are not scored |
| Doc samples | a documentation sample that no longer matches the code: every TypeScript and JavaScript sample on these pages runs against the built package and its // => values are checked, and each TypeScript one also compiles against the package's types. A sample that cannot run says why in its fence and is neither run nor compiled: today, the samples that import @cosyte/hl7 and the CommonJS require sample | prose that is wrong beside a sample that is right |
| PHI scan | a realistic patient identifier in any tracked file: a C-CDA-aware scan of every C-CDA document in the repository, and a scan for dashed Social Security numbers and email addresses in every other file | anything outside the fields and formats it knows; it detects after a write, it does not prevent one |
How each one runs
- Unit tests, properties, fuzzing and doc samples run in one Vitest suite on every pull request,
on
mainand nightly, on Node.js 22, 24 and 26, each on Linux, Windows and macOS. The same suite also runs under Bun and under Deno on every pull request. A few tests skip where they cannot run, each with its reason beside the skip: on Windows, the tests of our own PHI scanner and of the example-import check, the doc samples, one compile check of the builder's types and the conformance cache; under Bun, the checks of V8's heap and the samples of one doc page; under Deno, the checks of V8's heap, a probe started with Node's own flags and the conformance cache. Each of them runs on Node.js on Linux and macOS. - The properties run through the shared runners of
@cosyte/test-utils. The three properties every Cosyte parser proves (round trip, idempotent normalize, and never throws in lenient mode) run on the generators we publish at@cosyte/ccda/arbitraries, beside the immutability property of a parsed document. On a pull request each property runs 100 cases (the archetype round trip intest/property/round-trip.property.test.tsruns 80); every nightpnpm test:propertyruns every property undertest/property/at 10,000 cases. Each property prints its seed before it runs, so the nightly log records every seed it ran, and a failure prints the seed and path that replay it: setCOSYTE_PROPERTY_SEEDandCOSYTE_PROPERTY_PATHto them and runpnpm test:propertyto get the same case, already shrunk. Property-test your code shows those generators on code of your own. - The coverage gate runs with the suite. A floor that is not met fails the pull request. The
coverage ratchet (
cosyte-ratchet) then holds the coverage to the floor inquality-floor.json, fails a pull request whose changed lines a test never runs, and fails one that lowers or removes a floor. - Mutation testing runs StrykerJS on the shared configuration. On a pull request it mutates the
source files the pull request changed, and every mutant in the changed lines must be killed. Twice
a week a full run mutates every source file, shared out across 16 parallel jobs, and holds the
whole score to the mutation floor in
quality-floor.json. The floor only rises. - The conformance run fetches the C-CDA R2.1 Schematron, its vocabulary file and the CDA R2 XML
schema from pinned, digest-checked references, and runs on every pull request in a job of its
own, named
conformance. It writes a report and fails when the committed report differs from what the run produced. The fetched artifacts are cached between runs, and every cached file is checked against its pin again before it is used, so a run with a warm cache needs no network and a cached file that fails the check is fetched again. See When an upstream artifact is unreachable. - The PHI scan runs on every commit (a pre-commit hook) and in CI.
Run them yourself
pnpm install --frozen-lockfile
pnpm test # unit tests, properties, fuzzing and doc samples
pnpm test:coverage # the same suite with the coverage gate
pnpm conformance # the conformance run; it needs the network
pnpm phi-scan # the PHI scan over the repository
pnpm test:property # every property; COSYTE_PROPERTY_RUNS=10000 for the nightly depth
pnpm quality:check # coverage against quality-floor.json, after pnpm test:coverage
pnpm mutate changed --base origin/main # mutate the files a change touched
pnpm mutate:full # the full mutation run; it takes hours on one machine
When an upstream artifact is unreachable
The conformance run reaches the network by design, and an artifact it cannot fetch fails the run
rather than passing it: an artifact nobody could fetch is one nothing was validated against. It
reaches the network only when its cache does not hold an artifact as pinned: the first run after a
pin moves, or after the cache is evicted. When that fetch fails, the run stops with
CONFORMANCE_ARTIFACT_UNREACHABLE and names the URL. Then:
- Check that the host in the URL is up. Every pinned artifact comes from GitHub
(
raw.githubusercontent.comorcodeload.github.com). - Re-run the failed job once the host answers. A re-run fetches only what the cache lacks.
- If your change moved a pin, the new artifact has to come from upstream once. Wait for the host; do not move the pin back to get a green.
- Do not skip the run or let it pass on failure to get past an outage.
CONFORMANCE_ARTIFACT_DIGEST_MISMATCH is a different fault: the host served bytes other than the
pinned commit's, and a re-run does not fix it. Read the diff between the two commits before moving
a pin in scripts/conformance/artifacts.json.
Current numbers
Measured for version 0.1.13 at commit 38408f3 on 2026-11-29, in the release run that published it, on a GitHub-hosted runner: Linux X64, image ubuntu26 20261122.9.1, AMD EPYC 7763 64-Core Processor with 4 logical CPUs, Node.js v22.23.5.
Coverage
The package's own test suite with v8 coverage over src/, run once in the release run by pnpm run test:coverage. The floor is the lowest coverage the package's checks accept, read from quality-floor.json at the same commit.
| Measure | Covered | Total | Coverage | Floor |
|---|---|---|---|---|
| Lines | 4,499 | 4,499 | 100.00% | 100% |
| Branches | 3,283 | 3,283 | 100.00% | 100% |
| Functions | 823 | 823 | 100.00% | 100% |
| Statements | 5,295 | 5,295 | 100.00% | 100% |
Mutation score
No mutation run is part of a release: a full run takes hours, so it runs on a schedule instead, and the weekly run fails when the score falls below its floor. The floor in quality-floor.json at this commit is 74.94%. Before it published, the release read the latest weekly mutation run, which finished on 2026-11-29 and concluded success.