fix(test-suite): make Tier 2 schema mapper UNTP 0.7.0-aware#713
fix(test-suite): make Tier 2 schema mapper UNTP 0.7.0-aware#713halleluiaman-ux wants to merge 2 commits into
Conversation
The Tier 2 schema mapper derived the schema URL only from the 0.6.x per-type
context scheme (test.uncefact.org/vocabulary/untp/<abbr>/<version>/). UNTP 0.7.0
uses a single unified context (vocabulary.uncefact.org/untp/<version>/context/),
which never matched, so getSchemaUrlForCredential returned null and every 0.7.0
credential failed at the guard assertion ("expected null to be a string") before
schema validation.
- loader.ts: getSchemaUrlFromMappings now tries every mapping for the credential
type and returns the first that resolves, instead of giving up on the first
entry whose versionRegex does not match (this also unblocks adding a parallel
0.7.0 mapping for the same type).
- default-mappings.json: add 0.7.0 entries (unified context -> untp.unece.org
artefacts schemas) alongside the existing 0.6.x entries. Note the DCC artefact
is published as dcc/ConformityCredential.json (no Digital prefix), so it needs
an explicit pattern; a uniform Digital<Type>.json template would 404.
- test-utils.ts: extractUNTPVersion also recognises the unified 0.7.0 context.
The 0.6.x path is untouched (version-aware, parallel mappings). Adds a minimal,
generic 0.7.0 DPP fixture (no third-party context dependency) that passes Tier 1,
Tier 2 schema and Tier 3 RDF.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request adds support for the UNTP 0.7.0+ unified context scheme. It updates default schema mappings, refactors the schema loader to support multiple mappings per credential type, updates version extraction utility functions to handle both legacy (0.6.x) and unified (0.7.0+) context schemes, and adds a new test fixture. Feedback points out a potential correctness issue in the schema loader where matching the version regex against the entire stringified credential could lead to false matches if other fields contain matching URLs. It is recommended to match the regex specifically against the @context array elements instead.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…SON.stringify Addresses Gemini Code Assist review on the Tier 2 mapper PR: resolve the schema version by testing each mapping's versionRegex against the credential's @context URL strings (handling a non-array @context), instead of matching against a JSON.stringify of the whole credential. The stringify approach was inherited from the original getSchemaUrlFromMappings; it is corrected here since the function is being rewritten anyway, and it avoids matching a version-like substring elsewhere in the credential body. Verified: 0.7.0 fixture passes Tier 2; 0.6.x example credentials unchanged (23 passing / 1 failing).
The Tier 2 schema mapper derived the schema URL only from the 0.6.x per-type context scheme (test.uncefact.org/vocabulary/untp///). UNTP 0.7.0 uses a single unified context (vocabulary.uncefact.org/untp//context/), which never matched, so getSchemaUrlForCredential returned null and every 0.7.0 credential failed at the guard assertion ("expected null to be a string") before schema validation.
The 0.6.x path is untouched (version-aware, parallel mappings). Adds a minimal, generic 0.7.0 DPP fixture (no third-party context dependency) that passes Tier 1, Tier 2 schema and Tier 3 RDF.
What type of PR is this? (check all applicable)
Description
The Tier 2 schema mapper derived the UNTP schema URL only from the 0.6.x per-type context scheme (
https://test.uncefact.org/vocabulary/untp/<abbr>/<version>/). UNTP 0.7.0 uses a single unified context (https://vocabulary.uncefact.org/untp/<version>/context/), which never matched, sogetSchemaUrlForCredentialreturnednulland every 0.7.0 credential failed at the guard assertion (expected null to be a string) before schema validation ever ran.This PR makes the mapper version-aware, leaving the 0.6.x path untouched:
schema-mapper/loader.ts—getSchemaUrlFromMappingsnow iterates over every mapping for the credential type and returns the first that resolves a URL, instead of selecting the first entry and giving up when itsversionRegexdoes not match. This also fixes the selection bug that blocked the obvious workaround of adding a second (0.7.0) mapping for the samecredentialType.schema-mapper/default-mappings.json— adds 0.7.0 entries (unified context →untp.unece.org/artefactsschemas) alongside the existing 0.6.x entries. Note: the v0.7.0 DCC artefact is published asdcc/ConformityCredential.json(noDigitalprefix), unlike the other four types, so it needs an explicit pattern — a uniformDigital<Type>.jsontemplate would 404.test-utils.ts—extractUNTPVersionnow also recognises the unified 0.7.0 context.All five published v0.7.0 artefact paths were verified to return HTTP 200:
dpp/DigitalProductPassport.json,dcc/ConformityCredential.json,dfr/DigitalFacilityRecord.json,dia/DigitalIdentityAnchor.json,dte/DigitalTraceabilityEvent.json.Related Tickets & Documents
Fixes #711
Mobile & Desktop Screenshots/Recordings
Not applicable — no visual changes (test-suite code only).
Added tests?
Added as an integration test, consistent with this package's existing self-test mechanism (the suite runs its own conformance tiers over credential fixtures rather than a separate unit-test runner —
jest.config.mjsin this package is an inactive stub withtestMatch: [], andjestis not a devDependency here). A minimal, generic UNTP 0.7.0 DPP fixture (test-fixtures/untp-0.7.0/, no third-party@contextdependency) is added: with this fix it now resolves the schema URL and passes Tier 2 (and Tier 1 + Tier 3 RDF). The bundled 0.6.x example credentials are unchanged (still 23 passing / 1 failing — the pre-existing trust-anchor example failure). A jest-based unit test for the loader fall-through can be added if preferred, but would require introducingjest/ts-jestto this package (touching the lockfile), so it is left out to keep the change focused — happy to add it on request.Note for the reviewer:
pnpm buildfor this package exits non-zero on a pre-existing, unrelated error (TS7016: Could not find a declaration file for module 'jsonld'inn3-utils.ts) that is present onnextbefore this PR;tscstill emitsdist/and the CLI runs. This PR does not touchn3-utils.tsand does not introduce the error.Added to documentation?
API Documentation Updated?
schemas.ts[optional] Are there any post-deployment tasks we need to perform?
None.