diff --git a/.changeset/README.md b/.changeset/README.md index 0432bb3..e1f7a06 100644 --- a/.changeset/README.md +++ b/.changeset/README.md @@ -24,6 +24,7 @@ A change to `docs-content/`, tests, CI, or scripts gets none, and never an empty (`changeset add --empty`): only a changeset starts a release, and one that bumps nothing sends a release through approval that publishes nothing. -While the version is below 1.0, every release is a **patch**, including a breaking change (a renamed or removed command, -flag, output field, exit code or diagnostic code) and new capability. Call a break out in the -changeset: say what changed and what a caller must do. +While the version is below 1.0, a release is a **patch** unless a minor has been approved for that +release by name, and a breaking change (a renamed or removed command, flag, output field, exit code +or diagnostic code) can ship in either. Call a break out in the changeset: say what changed and +what a caller must do. diff --git a/.changeset/parsers-0-2.md b/.changeset/parsers-0-2.md new file mode 100644 index 0000000..baf77f6 --- /dev/null +++ b/.changeset/parsers-0-2.md @@ -0,0 +1,27 @@ +--- +"@cosyte/cli": minor +--- + +`cosyte` now runs on the 0.2 lines of `@cosyte/hl7`, `@cosyte/fhir` and `@cosyte/ccda`, with `@cosyte/transform` 0.3 and the `@cosyte/deid` and `@cosyte/mllp` releases that accept them, so a FHIR parse warning is now `{ code, position: { expression } }` with no severity, and every code those libraries pass through carries their prefix. + +What a caller must change: read each row of the table below against the scripts, `jq` filters and programs that consume `cosyte` output, the `cosyte-mcp` tool results, or `parseFormat` and `validateFormat` from the programmatic API. HL7 v2, X12, ASTM, NCPDP, DICOM and C-CDA output keeps its shape; only the codes named in the second table change. + +| What changes | Before | After | How to find it | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | +| Each entry of `warnings` in `cosyte parse` output for a FHIR resource, in a `parse --ndjson` record, in the MCP `parse` result, and from `parseFormat("fhir", ...)` | `{ "code", "severity", "expression" }` | `{ "code", "position": { "expression" } }`, the shape every other format's warnings have | a `jq` filter or a program reading `.warnings[].severity` or `.warnings[].expression` on FHIR input | +| The `severity` of a `cosyte validate` finding that comes from reading a FHIR resource (not from `validateResource`), in the stderr line, in `--json`, in the MCP `validate` result, and from `validateFormat` | `information` for some codes, such as the decimal precision warning | always `warning`; the verdict and the exit code are unchanged, since neither severity fails it | `grep -rn 'information'` near a check on `validate` output, or `jq '.findings[] \| select(.severity == "information")'` | +| A code passed through from `@cosyte/hl7`, in `warnings[].code`, `findings[].code`, the parenthesized code after `CLI_PARSE_FAILED`, and a failed record's `error` | an unprefixed name, such as `NO_MSH_SEGMENT` | the same name with `HL7_` in front: `HL7_NO_MSH_SEGMENT` | `grep -rnE '"[A-Z][A-Z0-9]*(_[A-Z0-9]+)+"'` in the code that reads HL7 v2 output | +| A code passed through from `@cosyte/fhir`, in the same places | `MALFORMED_JSON`, `CODE_INVALID`, `INVARIANT_VIOLATED`, `DECIMAL_PRECISION_AT_RISK` | `FHIR_MALFORMED_JSON`, `FHIR_CODE_INVALID`, `FHIR_INVARIANT_VIOLATED`, `FHIR_DECIMAL_PRECISION_AT_RISK` | the same `grep`, in the code that reads FHIR output | +| A code passed through from `@cosyte/ccda`, in the same places | an unprefixed name, such as `NOT_WELL_FORMED_XML` | the same name with `CCDA_` in front: `CCDA_NOT_WELL_FORMED_XML` | the same `grep`, in the code that reads C-CDA output | +| An MLLP stream with a start byte (`VT`) inside a frame, read by `cosyte parse` or `cosyte inspect` | exit `0`: the bytes before the second `VT` dropped with an `MLLP_TRAILING_BYTES` framing warning, and the message after it read | exit `65`, `CLI_PARSE_FAILED` with `(MLLP_PAYLOAD_CONTAINS_VT)`: the frame is refused whole and nothing in it is read | a script that expects exit `0` or a nonzero `warningCount` from `inspect` on such a stream | + +Each library's own changelog lists every renamed code. The ones the `cosyte` docs and examples use: + +| Library | Before | After | +| -------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `@cosyte/hl7` | `NO_MSH_SEGMENT`, `MSH_TOO_SHORT`, `INVALID_ENCODING_CHARACTERS`, `EMPTY_INPUT` | `HL7_NO_MSH_SEGMENT`, `HL7_MSH_TOO_SHORT`, `HL7_INVALID_ENCODING_CHARACTERS`, `HL7_EMPTY_INPUT` | +| `@cosyte/fhir` | `MALFORMED_JSON`, `CODE_INVALID`, `INVARIANT_VIOLATED`, `DECIMAL_PRECISION_AT_RISK`, `UNKNOWN_ELEMENT`, `CARDINALITY_MIN` | `FHIR_MALFORMED_JSON`, `FHIR_CODE_INVALID`, `FHIR_INVARIANT_VIOLATED`, `FHIR_DECIMAL_PRECISION_AT_RISK`, `FHIR_UNKNOWN_ELEMENT`, `FHIR_CARDINALITY_MIN` | +| `@cosyte/ccda` | `NOT_WELL_FORMED_XML`, `MISSING_DOSE_QUANTITY` | `CCDA_NOT_WELL_FORMED_XML`, `CCDA_MISSING_DOSE_QUANTITY` | +| `@cosyte/mllp` | `MLLP_TRAILING_BYTES` on a `VT` inside a frame | `MLLP_PAYLOAD_CONTAINS_VT` | + +The `CLI_*` codes, the exit codes, the commands and their flags are unchanged. An install of this release takes the 0.2 lines of `@cosyte/hl7`, `@cosyte/fhir` and `@cosyte/ccda` and nothing older, so a project that also depends on one of them directly moves it to 0.2 in the same change. diff --git a/AGENTS.md b/AGENTS.md index d7a8fe5..0143daa 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -85,8 +85,8 @@ pnpm check:no-internal-refs - A floor in `quality-floor.json` only rises. Raise it with `pnpm quality:raise` after a full mutation run (`pnpm mutate:full`), in a pull request of its own. - A change to anything in the npm tarball (`src/`, `README.md`, or a `package.json` field npm - shows) adds a changeset (`pnpm changeset`), always a patch. A change to `docs-content/`, tests, - CI, or scripts adds none. + shows) adds a changeset (`pnpm changeset`), a patch unless a minor has been approved for that + release by name. A change to `docs-content/`, tests, CI, or scripts adds none. ## Contributing diff --git a/README.md b/README.md index 5516166..e1aadc6 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ diagnostic** posture. ## Status -The 0.1 line. While the package is below 1.0, a breaking change can ship in a patch -version and is called out in the changelog. The `cosyte` command wraps **all eight +The 0.2 line. While the package is below 1.0, a breaking change can ship in a patch or a +minor version and is called out in the changelog. The `cosyte` command wraps **all eight Cosyte formats** (**HL7 v2**, **FHIR R4**, **X12**, **ASTM**, **NCPDP SCRIPT and Telecom**, **C-CDA**, **DICOM**, and **MLLP**) plus the `@cosyte/transform` and `@cosyte/terminology` higher-layer libraries, with conservative content-format autodetection and a documented exit-code contract: @@ -78,9 +78,9 @@ npm install -g @cosyte/cli # put `cosyte` on your PATH Requires Node.js 22 or later, tested on 22, 24, and 26. Versions `0.0.1` and `0.0.2` are on npm but cannot be installed, because of a packaging defect in -those releases. Install the 0.1 line. +those releases. Install the 0.2 line. -Below 1.0 a break can ship in a patch release, so a caret range such as `^0.1.0` does not protect a +Below 1.0 a break can ship in a patch release, so a caret range such as `^0.2.0` does not protect a consumer. Pin the exact version: ```bash no-run it installs the package from npm diff --git a/docs-content/api/src.md b/docs-content/api/src.md index f668e6d..2ce773d 100644 --- a/docs-content/api/src.md +++ b/docs-content/api/src.md @@ -253,7 +253,8 @@ A value-free positional locator: a FHIRPath expression, or an HL7 segment/field > `readonly` **severity**: `string` -The R4-style severity (`fatal` | `error` | `warning` | `information`), or `warning` for HL7. +The R4-style severity (`fatal` | `error` | `warning` | `information`) of a FHIR validation or a +conversion finding, or `warning` for a parse warning, which carries no severity of its own. *** @@ -1658,7 +1659,7 @@ extractPhiPosture(["parse", "x.hl7", "--unsafe-show-values"]).argv; // => ["pars > **extractStableCode**(`e`): `string` \| `null` Pull a `code` off a thrown value **only** when it is a PHI-free constant token -(`^[A-Z][A-Z0-9_]*$`: a letter-led UPPER_SNAKE code like `MALFORMED_JSON`), e.g. a wrapped +(`^[A-Z][A-Z0-9_]*$`: a letter-led UPPER_SNAKE code like `FHIR_MALFORMED_JSON`), e.g. a wrapped parser's stable fatal code. Anything else (no `code`, a non-string, a non-token, or a **pure-digit** value that could be a raw identifier) yields `null`, so a parser exception that embedded input bytes in a `code`-shaped field can never reach a diagnostic. @@ -1682,7 +1683,7 @@ The stable code token, or `null`. ```ts import { extractStableCode } from "@cosyte/cli"; -extractStableCode({ code: "MALFORMED_JSON" }); // => "MALFORMED_JSON" +extractStableCode({ code: "FHIR_MALFORMED_JSON" }); // => "FHIR_MALFORMED_JSON" extractStableCode(new Error("boom")); // => null ``` @@ -2563,7 +2564,7 @@ A value-free `CLI_PARSE_FAILED` / exit-`65` [RunResult](#runresult). import { parseFailureResult, VALUE_FREE } from "@cosyte/cli"; const bytes = new TextEncoder().encode("not hl7"); -parseFailureResult("hl7", bytes, VALUE_FREE, { code: "MISSING_MSH" }).exit; // => 65 +parseFailureResult("hl7", bytes, VALUE_FREE, { code: "HL7_NO_MSH_SEGMENT" }).exit; // => 65 ``` *** diff --git a/docs-content/check-messages-in-ci.md b/docs-content/check-messages-in-ci.md index a8b2428..1c200e5 100644 --- a/docs-content/check-messages-in-ci.md +++ b/docs-content/check-messages-in-ci.md @@ -101,7 +101,7 @@ cosyte validate messages/result.json; echo "exit $?" ``` ```text -cosyte: validate: error CODE_INVALID at Observation.status +cosyte: validate: error FHIR_CODE_INVALID at Observation.status cosyte: validate: fhir is INVALID (1 error(s), 0 other finding(s)) exit 1 ``` diff --git a/docs-content/debug-a-rejected-message.md b/docs-content/debug-a-rejected-message.md index b2054c6..dd9e4c2 100644 --- a/docs-content/debug-a-rejected-message.md +++ b/docs-content/debug-a-rejected-message.md @@ -17,13 +17,13 @@ cosyte parse broken.json; echo "exit $?" ``` ```text -cosyte: CLI_PARSE_FAILED: the fhir parser rejected the input (MALFORMED_JSON) +cosyte: CLI_PARSE_FAILED: the fhir parser rejected the input (FHIR_MALFORMED_JSON) exit 65 ``` ## 1. Read the code -The code in parentheses is the parser library's own, here `@cosyte/fhir`'s `MALFORMED_JSON`. The +The code in parentheses is the parser library's own, here `@cosyte/fhir`'s `FHIR_MALFORMED_JSON`. The library's documentation on [docs.cosyte.com](https://docs.cosyte.com) lists its codes and what each means. The diagnostic carries no value from the message, so it is safe to paste into an issue. diff --git a/docs-content/installation.md b/docs-content/installation.md index 1490808..1aaa57e 100644 --- a/docs-content/installation.md +++ b/docs-content/installation.md @@ -42,7 +42,7 @@ npm install --save-dev --save-exact @cosyte/cli npx cosyte --version ``` -Below 1.0 a break can ship in a patch release, so a caret range such as `^0.1.0` does not protect +Below 1.0 a break can ship in a patch release, so a caret range such as `^0.2.0` does not protect you. `--save-exact` writes the exact version into `package.json`; raise it yourself after reading the changelog. diff --git a/docs-content/intro.md b/docs-content/intro.md index 849e3f5..d724c4d 100644 --- a/docs-content/intro.md +++ b/docs-content/intro.md @@ -50,7 +50,7 @@ Not every command supports every format; [Format support](./format-support.md) h ## Status -The 0.1 line is published to npm. Below 1.0, a breaking change can ship in a patch version and is +The 0.2 line is published to npm. Below 1.0, a breaking change can ship in a patch or a minor version and is called out in the changelog. Two early versions cannot be installed at all: see [If you are on 0.0.1 or 0.0.2](./installation.md#if-you-are-on-001-or-002). diff --git a/docs-content/mcp-tools.md b/docs-content/mcp-tools.md index 1009fde..f398e52 100644 --- a/docs-content/mcp-tools.md +++ b/docs-content/mcp-tools.md @@ -70,7 +70,7 @@ A `validate` call on a Patient whose `gender` is not in its value set: "data": { "format": "fhir", "valid": false, - "findings": [{ "code": "CODE_INVALID", "severity": "error", "location": "Patient.gender" }] + "findings": [{ "code": "FHIR_CODE_INVALID", "severity": "error", "location": "Patient.gender" }] } } ``` diff --git a/docs-content/parse-messages-in-a-pipeline.md b/docs-content/parse-messages-in-a-pipeline.md index 6746c8f..6d7b793 100644 --- a/docs-content/parse-messages-in-a-pipeline.md +++ b/docs-content/parse-messages-in-a-pipeline.md @@ -65,7 +65,7 @@ cosyte parse --format fhir message.hl7; echo "exit $?" ``` ```text -cosyte: CLI_PARSE_FAILED: the fhir parser rejected the input (MALFORMED_JSON) +cosyte: CLI_PARSE_FAILED: the fhir parser rejected the input (FHIR_MALFORMED_JSON) exit 65 ``` @@ -96,7 +96,7 @@ echo "exit ${PIPESTATUS[0]}" ```text {"record":0,"error":null,"resourceType":"Patient"} -{"record":1,"error":"MALFORMED_JSON","resourceType":null} +{"record":1,"error":"FHIR_MALFORMED_JSON","resourceType":null} {"record":2,"error":null,"resourceType":"Observation"} exit 65 ``` diff --git a/docs-content/quickstart.md b/docs-content/quickstart.md index 22d10c8..a8ba256 100644 --- a/docs-content/quickstart.md +++ b/docs-content/quickstart.md @@ -100,7 +100,7 @@ cosyte validate patient.json; echo "exit $?" ``` ```text -cosyte: validate: error CODE_INVALID at Patient.gender +cosyte: validate: error FHIR_CODE_INVALID at Patient.gender cosyte: validate: fhir is INVALID (1 error(s), 0 other finding(s)) exit 1 ``` diff --git a/docs-content/use-the-programmatic-api.md b/docs-content/use-the-programmatic-api.md index 3510752..dc455f2 100644 --- a/docs-content/use-the-programmatic-api.md +++ b/docs-content/use-the-programmatic-api.md @@ -46,7 +46,7 @@ const deps = { const result = await run(["validate", "patient.json"], deps); result.exit === EXIT.INVALID; // => true result.stdout; // => "" -result.stderr.split("\n")[0]; // => "cosyte: validate: error CODE_INVALID at Patient.gender" +result.stderr.split("\n")[0]; // => "cosyte: validate: error FHIR_CODE_INVALID at Patient.gender" ``` To read real files, pass `readFileBytes` as `readFile`: it applies the same size limit as the diff --git a/examples/exit-codes.ts b/examples/exit-codes.ts index e2dc618..a2cdb03 100644 --- a/examples/exit-codes.ts +++ b/examples/exit-codes.ts @@ -33,7 +33,7 @@ for (const [name, run] of Object.entries(results)) { assert.equal(valid.status, 0); assert.equal(invalid.status, 1); -assert.match(invalid.stderr, /CODE_INVALID at Patient\.gender/); +assert.match(invalid.stderr, /FHIR_CODE_INVALID at Patient\.gender/); assert.equal(usage.status, 2); assert.equal(unparseable.status, 65); assert.match(unparseable.stderr, /CLI_FORMAT_UNDETECTED/); diff --git a/package.json b/package.json index 60d5728..ceae7c1 100644 --- a/package.json +++ b/package.json @@ -149,7 +149,7 @@ "@cosyte/prettier-config": "^0.1.2", "@cosyte/process": "^0.1.10", "@cosyte/script-utils": "^0.1.17", - "@cosyte/synth": "^0.1.5", + "@cosyte/synth": "^0.1.16", "@cosyte/test-utils": "^0.1.4", "@cosyte/tsconfig": "^0.1.2", "@cosyte/tsup-config": "^0.1.3", @@ -165,18 +165,18 @@ "vitest": "5.1.0" }, "dependencies": { - "@cosyte/hl7": "^0.1.10", + "@cosyte/hl7": "^0.2.0", "@cosyte/terminology": "^0.2.0" }, "optionalDependencies": { "@cosyte/astm": "^0.2.0", - "@cosyte/ccda": "^0.1.6", - "@cosyte/deid": "^0.2.4", + "@cosyte/ccda": "^0.2.0", + "@cosyte/deid": "^0.2.20", "@cosyte/dicom": "^0.2.0", - "@cosyte/fhir": "^0.1.11", - "@cosyte/mllp": "^0.1.9", + "@cosyte/fhir": "^0.2.0", + "@cosyte/mllp": "^0.1.17", "@cosyte/ncpdp": "^0.2.0", - "@cosyte/transform": "^0.2.2", + "@cosyte/transform": "^0.3.0", "@cosyte/x12": "^0.2.0", "@modelcontextprotocol/sdk": "^1.32.2" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 38e1641..eac006f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,8 +16,8 @@ importers: .: dependencies: '@cosyte/hl7': - specifier: ^0.1.10 - version: 0.1.10(fast-check@4.10.2) + specifier: ^0.2.0 + version: 0.2.0(fast-check@4.10.2) '@cosyte/terminology': specifier: ^0.2.0 version: 0.2.0 @@ -44,8 +44,8 @@ importers: specifier: ^0.1.17 version: 0.1.17 '@cosyte/synth': - specifier: ^0.1.5 - version: 0.1.5(@cosyte/astm@0.2.0)(@cosyte/ccda@0.1.6)(@cosyte/deid@0.2.4(@cosyte/ccda@0.1.6)(@cosyte/dicom@0.2.0(fast-check@4.10.2))(@cosyte/fhir@0.1.11(fast-check@4.10.2))(@cosyte/hl7@0.1.10(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2)))(@cosyte/fhir@0.1.11(fast-check@4.10.2))(@cosyte/hl7@0.1.10(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2)) + specifier: ^0.1.16 + version: 0.1.16(@cosyte/astm@0.2.0)(@cosyte/ccda@0.2.0(fast-check@4.10.2))(@cosyte/deid@0.2.20(@cosyte/ccda@0.2.0(fast-check@4.10.2))(@cosyte/dicom@0.2.0(fast-check@4.10.2))(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2)))(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2)) '@cosyte/test-utils': specifier: ^0.1.4 version: 0.1.4(fast-check@4.10.2) @@ -90,26 +90,26 @@ importers: specifier: ^0.2.0 version: 0.2.0 '@cosyte/ccda': - specifier: ^0.1.6 - version: 0.1.6 + specifier: ^0.2.0 + version: 0.2.0(fast-check@4.10.2) '@cosyte/deid': - specifier: ^0.2.4 - version: 0.2.4(@cosyte/ccda@0.1.6)(@cosyte/dicom@0.2.0(fast-check@4.10.2))(@cosyte/fhir@0.1.11(fast-check@4.10.2))(@cosyte/hl7@0.1.10(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2)) + specifier: ^0.2.20 + version: 0.2.20(@cosyte/ccda@0.2.0(fast-check@4.10.2))(@cosyte/dicom@0.2.0(fast-check@4.10.2))(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2)) '@cosyte/dicom': specifier: ^0.2.0 version: 0.2.0(fast-check@4.10.2) '@cosyte/fhir': - specifier: ^0.1.11 - version: 0.1.11(fast-check@4.10.2) + specifier: ^0.2.0 + version: 0.2.0(fast-check@4.10.2) '@cosyte/mllp': - specifier: ^0.1.9 - version: 0.1.9(@cosyte/hl7@0.1.10(fast-check@4.10.2))(fast-check@4.10.2) + specifier: ^0.1.17 + version: 0.1.17(@cosyte/hl7@0.2.0(fast-check@4.10.2))(fast-check@4.10.2) '@cosyte/ncpdp': specifier: ^0.2.0 version: 0.2.0(fast-check@4.10.2) '@cosyte/transform': - specifier: ^0.2.2 - version: 0.2.2(@cosyte/fhir@0.1.11(fast-check@4.10.2))(@cosyte/hl7@0.1.10(fast-check@4.10.2)) + specifier: ^0.3.0 + version: 0.3.0(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2)) '@cosyte/x12': specifier: ^0.2.0 version: 0.2.0(fast-check@4.10.2) @@ -431,20 +431,25 @@ packages: engines: {node: '>=22.15.0'} hasBin: true - '@cosyte/ccda@0.1.6': - resolution: {integrity: sha512-3ZheOAuUufIVWo5oTdLayb6ClJYV72lWcmg865cPD2IQyh/CtFVcKsb7s3jfbEVxOX7xMCp9DOv7g470vhkMRg==} + '@cosyte/ccda@0.2.0': + resolution: {integrity: sha512-a/UUCrY6feVhszxgoIO0LoaPeZG1tvWSNyfom9drOPDiBCW6kxqd3TgBlyHben0HqrQGIBEVrlKd265tHBMbRw==} engines: {node: '>=22.0.0'} + peerDependencies: + fast-check: ^4.0.0 + peerDependenciesMeta: + fast-check: + optional: true - '@cosyte/deid@0.2.4': - resolution: {integrity: sha512-wXmdk2E7dcMAPsfttVvrp25KBqhDdrxwexO0fe400u4h3bfcxmh4hmVCe72PmV6rocFSKg24O3F5VEK8eOdlJg==} + '@cosyte/deid@0.2.20': + resolution: {integrity: sha512-abIOEsIT4S5iTglrvBqD/DLa40lfBa/Hq9s5aGqHRfCr210aon+AGzUtUJ6gIkEL5UIf7HdaYciclgU+EeQPZA==} engines: {node: '>=22.0.0'} peerDependencies: - '@cosyte/ccda': ^0.1.0 - '@cosyte/dicom': ^0.1.0 - '@cosyte/fhir': ^0.1.0 - '@cosyte/hl7': ^0.1.0 - '@cosyte/ncpdp': ^0.1.0 - '@cosyte/x12': ^0.1.0 + '@cosyte/ccda': ^0.1.6 || ^0.2.0 + '@cosyte/dicom': ^0.1.11 || ^0.2.0 + '@cosyte/fhir': ^0.1.8 || ^0.2.0 + '@cosyte/hl7': ^0.1.8 || ^0.2.0 + '@cosyte/ncpdp': ^0.1.6 || ^0.2.0 + '@cosyte/x12': ^0.1.10 || ^0.2.0 peerDependenciesMeta: '@cosyte/ccda': optional: true @@ -475,8 +480,8 @@ packages: eslint: ^9.0.0 || ^10.0.0 typescript: '>=5.0.0' - '@cosyte/fhir@0.1.11': - resolution: {integrity: sha512-K0xpMyV6I32mClmP28vSafAOIJTCqKFJgbIzcF2GfiKJbNznjJ2Y1hFKQpK2K9G9L67QduBmZtsKJMi9v0da/Q==} + '@cosyte/fhir@0.2.0': + resolution: {integrity: sha512-OuVgo307h2zg+xY3hqU87PMTattsE2AEfY/MG5op0Co/5Q5RdxM7Opr3I++WJsP90piGNGAY3LcOXspZVXppQg==} engines: {node: '>=22.0.0'} peerDependencies: fast-check: ^4.0.0 @@ -484,8 +489,8 @@ packages: fast-check: optional: true - '@cosyte/hl7@0.1.10': - resolution: {integrity: sha512-AlC9ZzTnFzapMHUUfn9LcNlyw3w23tAY7szokl6tT0vukByZigQoXCj4hBqKrpS53FxTcF6oohaBJZkyTQpJ0w==} + '@cosyte/hl7@0.2.0': + resolution: {integrity: sha512-KVvLj8EthFE7m4mVkw3ER+TiNGzDJEUzGFG57SDvGQpOkYoqIUh8wHtmexYlLQxLMY1pUPHTQ6d1N0ocEFTQQQ==} engines: {node: '>=22.0.0'} peerDependencies: fast-check: ^4.0.0 @@ -493,11 +498,11 @@ packages: fast-check: optional: true - '@cosyte/mllp@0.1.9': - resolution: {integrity: sha512-LcXA2UHFu0OqbxQubMbz04SrcNVvMI7vEKQSgUlwa/O5wX7CicK9oRdD1OY4kQtQ2pizpFJ++re2UjAbsSszYQ==} + '@cosyte/mllp@0.1.17': + resolution: {integrity: sha512-/2bzuQ3HAgCzZtxcPqy3LLvn+veQwzdI1d4CHZ9OrHJXMpm4w1XykhW7Lu0XWlpIauBd89Gd23NG47WIiFzU/g==} engines: {node: '>=22.0.0'} peerDependencies: - '@cosyte/hl7': '>=0.0.0' + '@cosyte/hl7': ^0.1.5 || ^0.2.0 fast-check: ^4.0.0 peerDependenciesMeta: '@cosyte/hl7': @@ -527,17 +532,17 @@ packages: engines: {node: '>=22.14'} hasBin: true - '@cosyte/synth@0.1.5': - resolution: {integrity: sha512-TukqcmkF8nYsAKkM7oTYy44t3/UdIujnyPlev8eZARXaEENB75y2lfWINquft5YzW4OBFvdapJTaMVABSRqCgA==} - engines: {node: '>=22.0.0'} + '@cosyte/synth@0.1.16': + resolution: {integrity: sha512-oBM/ZttlrB/KHSXi46PuA2nVKdOI8Y5kQnjVbkmDdDMYGSVmg1uO0jX46VbMhpqBPAvWLpQnS/cazh1BaV6KHg==} + engines: {node: '>=22.12.0'} peerDependencies: - '@cosyte/astm': ^0.1.0 - '@cosyte/ccda': ^0.1.0 - '@cosyte/deid': ^0.1.0 - '@cosyte/fhir': ^0.1.0 - '@cosyte/hl7': ^0.1.0 - '@cosyte/ncpdp': ^0.1.0 - '@cosyte/x12': ^0.1.0 + '@cosyte/astm': ^0.1.6 || ^0.2.0 + '@cosyte/ccda': ^0.1.6 || ^0.2.0 + '@cosyte/deid': ^0.1.5 || ^0.2.0 + '@cosyte/fhir': ^0.1.8 || ^0.2.0 + '@cosyte/hl7': ^0.1.8 || ^0.2.0 + '@cosyte/ncpdp': ^0.1.6 || ^0.2.0 + '@cosyte/x12': ^0.1.10 || ^0.2.0 peerDependenciesMeta: '@cosyte/astm': optional: true @@ -564,12 +569,12 @@ packages: peerDependencies: fast-check: ^3.0.0 || ^4.0.0 - '@cosyte/transform@0.2.2': - resolution: {integrity: sha512-GbASCWPbDeTXIslG+sPqegLrWVm6giG9FvPZbFlz9qH7tBwy+V+0CbxEqrOiiUDmMsmRm8GgUs2P0eAl1WLBQg==} + '@cosyte/transform@0.3.0': + resolution: {integrity: sha512-PpbBL29TVWFtNAaCeNKTyFWwPnQXqth88HqiOZhCd7sTe8FsatJs43lfVwRlJpT1McwTzcbO1PyuLtj2k9zFPQ==} engines: {node: '>=22.0.0'} peerDependencies: - '@cosyte/fhir': ^0.1.8 - '@cosyte/hl7': ^0.1.8 + '@cosyte/fhir': ^0.2.0 + '@cosyte/hl7': ^0.2.0 '@cosyte/tsconfig@0.1.2': resolution: {integrity: sha512-ZTWC9cgdccJwL+EWTEWCtJr/a87TTZWlegTZWHpN7LGW3rALE1glnffOFMVraj4XSUam+DuHVOdGmKF8BhJPlA==} @@ -3645,17 +3650,19 @@ snapshots: '@cosyte/bench@0.1.1': {} - '@cosyte/ccda@0.1.6': + '@cosyte/ccda@0.2.0(fast-check@4.10.2)': dependencies: '@xmldom/xmldom': 0.9.12 + optionalDependencies: + fast-check: 4.10.2 optional: true - '@cosyte/deid@0.2.4(@cosyte/ccda@0.1.6)(@cosyte/dicom@0.2.0(fast-check@4.10.2))(@cosyte/fhir@0.1.11(fast-check@4.10.2))(@cosyte/hl7@0.1.10(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2))': + '@cosyte/deid@0.2.20(@cosyte/ccda@0.2.0(fast-check@4.10.2))(@cosyte/dicom@0.2.0(fast-check@4.10.2))(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2))': optionalDependencies: - '@cosyte/ccda': 0.1.6 + '@cosyte/ccda': 0.2.0(fast-check@4.10.2) '@cosyte/dicom': 0.2.0(fast-check@4.10.2) - '@cosyte/fhir': 0.1.11(fast-check@4.10.2) - '@cosyte/hl7': 0.1.10(fast-check@4.10.2) + '@cosyte/fhir': 0.2.0(fast-check@4.10.2) + '@cosyte/hl7': 0.2.0(fast-check@4.10.2) '@cosyte/ncpdp': 0.2.0(fast-check@4.10.2) '@cosyte/x12': 0.2.0(fast-check@4.10.2) optional: true @@ -3676,18 +3683,18 @@ snapshots: transitivePeerDependencies: - supports-color - '@cosyte/fhir@0.1.11(fast-check@4.10.2)': + '@cosyte/fhir@0.2.0(fast-check@4.10.2)': optionalDependencies: fast-check: 4.10.2 optional: true - '@cosyte/hl7@0.1.10(fast-check@4.10.2)': + '@cosyte/hl7@0.2.0(fast-check@4.10.2)': optionalDependencies: fast-check: 4.10.2 - '@cosyte/mllp@0.1.9(@cosyte/hl7@0.1.10(fast-check@4.10.2))(fast-check@4.10.2)': + '@cosyte/mllp@0.1.17(@cosyte/hl7@0.2.0(fast-check@4.10.2))(fast-check@4.10.2)': optionalDependencies: - '@cosyte/hl7': 0.1.10(fast-check@4.10.2) + '@cosyte/hl7': 0.2.0(fast-check@4.10.2) fast-check: 4.10.2 optional: true @@ -3732,13 +3739,13 @@ snapshots: '@cosyte/script-utils@0.1.17': {} - '@cosyte/synth@0.1.5(@cosyte/astm@0.2.0)(@cosyte/ccda@0.1.6)(@cosyte/deid@0.2.4(@cosyte/ccda@0.1.6)(@cosyte/dicom@0.2.0(fast-check@4.10.2))(@cosyte/fhir@0.1.11(fast-check@4.10.2))(@cosyte/hl7@0.1.10(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2)))(@cosyte/fhir@0.1.11(fast-check@4.10.2))(@cosyte/hl7@0.1.10(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2))': + '@cosyte/synth@0.1.16(@cosyte/astm@0.2.0)(@cosyte/ccda@0.2.0(fast-check@4.10.2))(@cosyte/deid@0.2.20(@cosyte/ccda@0.2.0(fast-check@4.10.2))(@cosyte/dicom@0.2.0(fast-check@4.10.2))(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2)))(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2))': optionalDependencies: '@cosyte/astm': 0.2.0 - '@cosyte/ccda': 0.1.6 - '@cosyte/deid': 0.2.4(@cosyte/ccda@0.1.6)(@cosyte/dicom@0.2.0(fast-check@4.10.2))(@cosyte/fhir@0.1.11(fast-check@4.10.2))(@cosyte/hl7@0.1.10(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2)) - '@cosyte/fhir': 0.1.11(fast-check@4.10.2) - '@cosyte/hl7': 0.1.10(fast-check@4.10.2) + '@cosyte/ccda': 0.2.0(fast-check@4.10.2) + '@cosyte/deid': 0.2.20(@cosyte/ccda@0.2.0(fast-check@4.10.2))(@cosyte/dicom@0.2.0(fast-check@4.10.2))(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2))(@cosyte/ncpdp@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2)) + '@cosyte/fhir': 0.2.0(fast-check@4.10.2) + '@cosyte/hl7': 0.2.0(fast-check@4.10.2) '@cosyte/ncpdp': 0.2.0(fast-check@4.10.2) '@cosyte/x12': 0.2.0(fast-check@4.10.2) @@ -3748,10 +3755,10 @@ snapshots: dependencies: fast-check: 4.10.2 - '@cosyte/transform@0.2.2(@cosyte/fhir@0.1.11(fast-check@4.10.2))(@cosyte/hl7@0.1.10(fast-check@4.10.2))': + '@cosyte/transform@0.3.0(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2))': dependencies: - '@cosyte/fhir': 0.1.11(fast-check@4.10.2) - '@cosyte/hl7': 0.1.10(fast-check@4.10.2) + '@cosyte/fhir': 0.2.0(fast-check@4.10.2) + '@cosyte/hl7': 0.2.0(fast-check@4.10.2) optional: true '@cosyte/tsconfig@0.1.2': {} diff --git a/src/commands/validate.ts b/src/commands/validate.ts index ffed00a..c809869 100644 --- a/src/commands/validate.ts +++ b/src/commands/validate.ts @@ -9,9 +9,10 @@ * Findings are **value-free**: a stable code, a severity, and a positional locator (a FHIRPath, or an * HL7 segment/field index), never a field value. By default they render on **stderr**; `--json` * emits the same value-free verdict + findings as machine JSON on stdout. The CLI invents **no** - * verdict of its own: FHIR validity is `@cosyte/fhir`'s `validateResource().valid` (plus any - * error-severity read issue); HL7 validity is "parseable": its parser is Postel's-Law lenient and its - * warnings are, by the library's design, non-fatal deviations (surfaced, never failing). + * verdict of its own: FHIR validity is `@cosyte/fhir`'s `validateResource().valid`, and the read's own + * warnings are reported as `warning` findings that never fail it; HL7 validity is "parseable": its + * parser is Postel's-Law lenient and its warnings are, by the library's design, non-fatal deviations + * (surfaced, never failing). * * @packageDocumentation */ diff --git a/src/core/deid.ts b/src/core/deid.ts index 0dcd2e8..9378642 100644 --- a/src/core/deid.ts +++ b/src/core/deid.ts @@ -349,7 +349,7 @@ export async function loadDeidDelegate( adapterUnavailable("fhir"), () => import("@cosyte/deid/fhir"), ); - const resource = parseOrFail("fhir", () => parseResource(decode(bytes)).resource); + const resource = parseOrFail("fhir", () => parseResource(decode(bytes))); return deidentifyOrFail(() => { const { document, manifest } = deidentifyFhir(resource, { context }); return { output: serializeResource(document), manifest: toRecords(manifest) }; diff --git a/src/core/findings.ts b/src/core/findings.ts index 07cd9ae..6906fee 100644 --- a/src/core/findings.ts +++ b/src/core/findings.ts @@ -14,7 +14,10 @@ export interface Finding { /** The stable diagnostic/warning code (the wrapped library's or the CLI's). */ readonly code: string; - /** The R4-style severity (`fatal` | `error` | `warning` | `information`), or `warning` for HL7. */ + /** + * The R4-style severity (`fatal` | `error` | `warning` | `information`) of a FHIR validation or a + * conversion finding, or `warning` for a parse warning, which carries no severity of its own. + */ readonly severity: string; /** A value-free positional locator: a FHIRPath expression, or an HL7 segment/field index path. */ readonly location: string; diff --git a/src/core/parsers.ts b/src/core/parsers.ts index 31a8bbe..89a91fe 100644 --- a/src/core/parsers.ts +++ b/src/core/parsers.ts @@ -412,15 +412,13 @@ export async function parseFormat(format: CosyteFormat, bytes: Uint8Array): Prom } case "fhir": { const { parseResource, serializeResource } = await loadFhir(); - const text = decode(bytes); - const { resource, issues } = parseResource(text); + const resource = parseResource(decode(bytes)); const model: unknown = JSON.parse(serializeResource(resource)); return { model, - warnings: issues.map((i) => ({ - code: i.code, - severity: i.severity, - expression: i.expression, + warnings: resource.warnings.map((w) => ({ + code: w.code, + position: { expression: w.position.expression }, })), }; } @@ -502,7 +500,7 @@ export async function inspectFormat( } case "fhir": { const { parseResource, resourceType, readBundle } = await loadFhir(); - const { resource, issues } = parseResource(decode(bytes)); + const resource = parseResource(decode(bytes)); const rt = resourceType(resource) ?? null; if (rt === "Bundle") { const bundle = readBundle(resource); @@ -517,10 +515,10 @@ export async function inspectFormat( bundleType: bundle.type ?? null, entryCount: bundle.entries.length, entryResourceTypes, - issueCount: issues.length, + issueCount: resource.warnings.length, }; } - return { format: "fhir", resourceType: rt, issueCount: issues.length }; + return { format: "fhir", resourceType: rt, issueCount: resource.warnings.length }; } case "x12": { const { parseX12 } = await loadOptional("x12", () => import("@cosyte/x12")); @@ -660,8 +658,8 @@ export async function fmtFormat(format: CosyteFormat, bytes: Uint8Array): Promis } case "fhir": { const { parseResource, serializeResource } = await loadFhir(); - const { resource, issues } = parseResource(decode(bytes)); - return { output: serializeResource(resource), warningCount: issues.length }; + const resource = parseResource(decode(bytes)); + return { output: serializeResource(resource), warningCount: resource.warnings.length }; } case "x12": { const { parseX12, serializeX12 } = await loadOptional("x12", () => import("@cosyte/x12")); @@ -733,10 +731,11 @@ export async function validateFormat(format: CosyteFormat, bytes: Uint8Array): P switch (format) { case "fhir": { const { parseResource, validateResource } = await loadFhir(); - const { resource, issues } = parseResource(decode(bytes)); + const resource = parseResource(decode(bytes)); const validation = validateResource(resource); + // A parse warning carries no severity: like every other format's, it is a `warning`. const findings: Finding[] = [ - ...issues.map((i) => finding(i.code, i.severity, i.expression)), + ...resource.warnings.map((w) => finding(w.code, "warning", w.position.expression)), ...validation.issues.map((i) => finding(i.code, i.severity, i.expression, i.constraint)), ]; return { findings, valid: !anyError(findings) }; diff --git a/src/core/wrap.ts b/src/core/wrap.ts index a86313c..e8e5951 100644 --- a/src/core/wrap.ts +++ b/src/core/wrap.ts @@ -22,7 +22,7 @@ import type { RunResult } from "./result.js"; /** * Pull a `code` off a thrown value **only** when it is a PHI-free constant token - * (`^[A-Z][A-Z0-9_]*$`: a letter-led UPPER_SNAKE code like `MALFORMED_JSON`), e.g. a wrapped + * (`^[A-Z][A-Z0-9_]*$`: a letter-led UPPER_SNAKE code like `FHIR_MALFORMED_JSON`), e.g. a wrapped * parser's stable fatal code. Anything else (no `code`, a non-string, a non-token, or a **pure-digit** * value that could be a raw identifier) yields `null`, so a parser exception that embedded input bytes * in a `code`-shaped field can never reach a diagnostic. @@ -33,7 +33,7 @@ import type { RunResult } from "./result.js"; * ```ts * import { extractStableCode } from "@cosyte/cli"; * - * extractStableCode({ code: "MALFORMED_JSON" }); // => "MALFORMED_JSON" + * extractStableCode({ code: "FHIR_MALFORMED_JSON" }); // => "FHIR_MALFORMED_JSON" * extractStableCode(new Error("boom")); // => null * ``` */ @@ -62,7 +62,7 @@ export function extractStableCode(e: unknown): string | null { * import { parseFailureResult, VALUE_FREE } from "@cosyte/cli"; * * const bytes = new TextEncoder().encode("not hl7"); - * parseFailureResult("hl7", bytes, VALUE_FREE, { code: "MISSING_MSH" }).exit; // => 65 + * parseFailureResult("hl7", bytes, VALUE_FREE, { code: "HL7_NO_MSH_SEGMENT" }).exit; // => 65 * ``` */ export function parseFailureResult( diff --git a/test/fmt.test.ts b/test/fmt.test.ts index 3dabe2c..5bd5364 100644 --- a/test/fmt.test.ts +++ b/test/fmt.test.ts @@ -30,7 +30,7 @@ describe("fmt: canonical re-serialization via the wrapped serializer", () => { const { parseResource, serializeResource } = await import("@cosyte/fhir"); const r = await fmtCommand(["p.json"], deps(FHIR)); expect(r.exit).toBe(EXIT.OK); - const { resource } = parseResource(new TextDecoder().decode(FHIR)); + const resource = parseResource(new TextDecoder().decode(FHIR)); expect(r.stdout).toBe(`${serializeResource(resource)}\n`); }); @@ -38,8 +38,8 @@ describe("fmt: canonical re-serialization via the wrapped serializer", () => { const { parseResource, serializeResource } = await import("@cosyte/fhir"); const messy = new TextEncoder().encode('{ "resourceType" : "Patient" , "id":"x" }'); const r = await fmtCommand(["p.json", "--format", "fhir"], deps(messy)); - const reparsed = parseResource(r.stdout.trimEnd()).resource; - const original = parseResource(new TextDecoder().decode(messy)).resource; + const reparsed = parseResource(r.stdout.trimEnd()); + const original = parseResource(new TextDecoder().decode(messy)); expect(serializeResource(reparsed)).toBe(serializeResource(original)); }); diff --git a/test/parse.test.ts b/test/parse.test.ts index 507a20d..73e5c86 100644 --- a/test/parse.test.ts +++ b/test/parse.test.ts @@ -54,7 +54,7 @@ describe("parse: command contract", () => { const { parseResource, serializeResource } = await import("@cosyte/fhir"); const r = await parseCommand(["p.json"], deps(FHIR)); const env = JSON.parse(r.stdout) as { model: unknown }; - const { resource } = parseResource(new TextDecoder().decode(FHIR)); + const resource = parseResource(new TextDecoder().decode(FHIR)); expect(env.model).toStrictEqual(JSON.parse(serializeResource(resource))); }); @@ -152,16 +152,21 @@ describe("parse: fail-safe exit-code contract", () => { }); describe("parse: pass-through of the wrapped library's warnings", () => { - it("surfaces FHIR issues as value-free envelope warnings (code + severity + expression)", async () => { - // A high-precision decimal raises a read-time DECIMAL_PRECISION_AT_RISK issue (value-free). + it("surfaces FHIR warnings as value-free envelope warnings (code + position)", async () => { + // A high-precision decimal raises a read-time FHIR_DECIMAL_PRECISION_AT_RISK (value-free). The + // warning has the shape every other format's has: a code and a position, with no severity. const withIssue = new TextEncoder().encode( '{"resourceType":"Observation","valueDecimal":1.00000000000000000001}', ); const r = await parseCommand(["p.json", "--format", "fhir"], deps(withIssue)); expect(r.exit).toBe(EXIT.OK); - const env = JSON.parse(r.stdout) as { warnings: { code: string; expression?: string }[] }; - expect(env.warnings.length).toBeGreaterThan(0); - for (const w of env.warnings) expect(typeof w.code).toBe("string"); + const env = JSON.parse(r.stdout) as { warnings: unknown[] }; + expect(env.warnings).toStrictEqual([ + { + code: "FHIR_DECIMAL_PRECISION_AT_RISK", + position: { expression: "Observation.valueDecimal" }, + }, + ]); }); it("surfaces HL7 warnings (e.g. MLLP framing stripped) as value-free envelope warnings", async () => { @@ -190,7 +195,7 @@ describe("parse: value-free warning note", () => { describe("extractStableCode: only bare uppercase code tokens pass, never input bytes", () => { it("returns a stable code token from an error-shaped value", () => { - expect(extractStableCode({ code: "MALFORMED_JSON" })).toBe("MALFORMED_JSON"); + expect(extractStableCode({ code: "FHIR_MALFORMED_JSON" })).toBe("FHIR_MALFORMED_JSON"); expect(extractStableCode({ code: "MISSING_MSH_1" })).toBe("MISSING_MSH_1"); }); diff --git a/test/parser-edges.test.ts b/test/parser-edges.test.ts index 3976e24..7178ef3 100644 --- a/test/parser-edges.test.ts +++ b/test/parser-edges.test.ts @@ -232,7 +232,7 @@ describe("fhir: an invariant failure names its constraint in the location", () = expect(exit).toBe(EXIT.INVALID); expect(body.valid).toBe(false); expect(body.findings).toContainEqual({ - code: "INVARIANT_VIOLATED", + code: "FHIR_INVARIANT_VIOLATED", severity: "error", location: "Patient.contact[0] (pat-1)", }); @@ -240,30 +240,34 @@ describe("fhir: an invariant failure names its constraint in the location", () = }); describe("mllp: a frame restarted part way through", () => { - // VT, one payload byte, then a second VT before any FS: the reader warns, discards the partial - // payload, and reads the frame that the second VT opens. + // VT, one payload byte, then a second VT before any FS: a VT inside a frame. The reader refuses + // the whole frame with MLLP_PAYLOAD_CONTAINS_VT, so neither the fragment nor the message after it + // is read, and the command names the code and nothing from the input. const HL7 = "MSH|^~\\&|A|B|C|D|20240101||ADT^A01|1|P|2.5\rPID|1\r"; const RESTARTED = new Uint8Array([0x0b, 0x41, 0x0b, ...enc.encode(HL7), 0x1c, 0x0d]); - it("inspect counts one frame and one framing warning", async () => { + it("inspect still counts a framing warning the reader raises: an empty frame", async () => { + // VT, FS, CR with nothing between: the reader delivers an empty payload with one + // MLLP_EMPTY_PAYLOAD warning, then reads the frame after it. + const withEmpty = new Uint8Array([0x0b, 0x1c, 0x0d, 0x0b, ...enc.encode(HL7), 0x1c, 0x0d]); const { exit, body } = await json<{ frameCount: number; warningCount: number }>( ["inspect", "s.mllp"], - RESTARTED, + withEmpty, ); expect(exit).toBe(EXIT.OK); - expect(body).toMatchObject({ frameCount: 1, warningCount: 1 }); + expect(body).toMatchObject({ frameCount: 2, warningCount: 1 }); }); - it("parse emits the one complete message, not the discarded fragment", async () => { - const r = await run(["parse", "s.mllp"], deps(RESTARTED)); - expect(r.exit).toBe(EXIT.OK); - const lines = r.stdout.trim().split("\n"); - expect(lines).toHaveLength(1); - expect(JSON.parse(lines[0] ?? "") as { record: number; format: string }).toMatchObject({ - record: 0, - format: "hl7", + for (const command of ["inspect", "parse"]) { + it(`${command} refuses the stream as a data error that names the framing code`, async () => { + const r = await run([command, "s.mllp"], deps(RESTARTED)); + expect(r.exit).toBe(EXIT.DATAERR); + expect(r.stdout).toBe(""); + expect(r.stderr).toBe( + "cosyte: CLI_PARSE_FAILED: the mllp parser rejected the input (MLLP_PAYLOAD_CONTAINS_VT)\n", + ); }); - }); + } }); describe("loadOptional: only a module-not-found failure means unavailable", () => { diff --git a/test/redact-blocked.test.ts b/test/redact-blocked.test.ts index 8061680..81e01bc 100644 --- a/test/redact-blocked.test.ts +++ b/test/redact-blocked.test.ts @@ -216,6 +216,15 @@ describe("the two failure boundaries: a rejected input and a fatal the library r expect(err.message).not.toContain("ZZSENTINELLAST"); // the library's message is discarded }); + it("the delegate's FHIR branch names the fhir parser and its prefixed code, and no input", async () => { + const delegate = await loadDeidDelegate(); + const bad = new TextEncoder().encode("{ not json ZZSENTINELFIRST"); + const err = (await delegate.redact("fhir", bad).catch((e: unknown) => e)) as CliError; + expect(err).toBeInstanceOf(CliError); + expect(err.code).toBe("CLI_PARSE_FAILED"); + expect(err.message).toBe("the fhir parser rejected the input (FHIR_MALFORMED_JSON)"); + }); + // AC-14 it("a parser rejection with no stable code still says nothing about the input", () => { try { diff --git a/test/sibling-releases.test.ts b/test/sibling-releases.test.ts index 81da43f..20e380a 100644 --- a/test/sibling-releases.test.ts +++ b/test/sibling-releases.test.ts @@ -10,19 +10,22 @@ import { describe, expect, it } from "vitest"; * a character at a time, and parsing a FHIR Binary held 33 to 40 times the input in memory. Before * 0.2.0, `@cosyte/transform` dropped six valued PID fields (race, primary language, SSN, ethnic * group, death date and time, death indicator) with no issue, so `convert` could not report them. + * The 0.2 lines of `@cosyte/hl7`, `@cosyte/fhir` and `@cosyte/ccda` move together with + * `@cosyte/transform` 0.3, whose peer range admits only those lines, and with the `@cosyte/deid`, + * `@cosyte/mllp` and `@cosyte/synth` releases that accept them, so an install holds one copy of each. */ const FLOORS: Readonly> = { - "@cosyte/hl7": "0.1.10", + "@cosyte/hl7": "0.2.0", "@cosyte/terminology": "0.2.0", "@cosyte/astm": "0.2.0", - "@cosyte/ccda": "0.1.6", + "@cosyte/ccda": "0.2.0", "@cosyte/dicom": "0.2.0", - "@cosyte/fhir": "0.1.11", - "@cosyte/mllp": "0.1.9", + "@cosyte/fhir": "0.2.0", + "@cosyte/mllp": "0.1.17", "@cosyte/ncpdp": "0.2.0", "@cosyte/x12": "0.2.0", - "@cosyte/transform": "0.2.2", - "@cosyte/deid": "0.2.4", + "@cosyte/transform": "0.3.0", + "@cosyte/deid": "0.2.20", }; interface Manifest { diff --git a/test/validate.test.ts b/test/validate.test.ts index cecba28..ff3f846 100644 --- a/test/validate.test.ts +++ b/test/validate.test.ts @@ -69,15 +69,20 @@ describe("validate: verdict in the exit code", () => { expect(invalid.stderr).toBe(""); }); - it("a value-free read-time issue is surfaced as a finding but does not fail a clean resource", async () => { - // A high-precision decimal raises a read-time DECIMAL_PRECISION_AT_RISK (warning, value-free). + it("a value-free read-time warning is surfaced as a finding of severity warning", async () => { + // A high-precision decimal raises a read-time FHIR_DECIMAL_PRECISION_AT_RISK (value-free). A + // parse warning carries no severity of its own, so the finding is a `warning`, never a failure. const withIssue = new TextEncoder().encode( '{"resourceType":"Observation","valueDecimal":1.00000000000000000001}', ); const r = await validateCommand(["o.json", "--format", "fhir", "--json"], deps(withIssue)); const body = JSON.parse(r.stdout) as { findings: { code: string; severity: string }[] }; expect(body.findings.length).toBeGreaterThan(0); - expect(body.findings.some((f) => f.code === "DECIMAL_PRECISION_AT_RISK")).toBe(true); + expect(body.findings).toContainEqual({ + code: "FHIR_DECIMAL_PRECISION_AT_RISK", + severity: "warning", + location: "Observation.valueDecimal", + }); }); it("HL7 warnings are surfaced as findings but do not fail the verdict (parseable ⇒ valid)", async () => { @@ -93,7 +98,7 @@ describe("validate: the verdict matches the library, never invented", () => { it("`validate`'s exit 0/1 equals @cosyte/fhir validateResource().valid", async () => { const { parseResource, validateResource } = await import("@cosyte/fhir"); for (const bytes of [FHIR, INVALID_FHIR]) { - const { resource } = parseResource(new TextDecoder().decode(bytes)); + const resource = parseResource(new TextDecoder().decode(bytes)); const libValid = validateResource(resource).valid; const r = await validateCommand(["p.json", "--format", "fhir"], deps(bytes)); expect(r.exit === EXIT.OK).toBe(libValid);