Skip to content

fix(test-suite): make Tier 2 schema mapper UNTP 0.7.0-aware#713

Open
halleluiaman-ux wants to merge 2 commits into
uncefact:nextfrom
halleluiaman-ux:fix/tier2-mapper-untp-070
Open

fix(test-suite): make Tier 2 schema mapper UNTP 0.7.0-aware#713
halleluiaman-ux wants to merge 2 commits into
uncefact:nextfrom
halleluiaman-ux:fix/tier2-mapper-untp-070

Conversation

@halleluiaman-ux

Copy link
Copy Markdown

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.

  • 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.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.

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

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, so getSchemaUrlForCredential returned null and 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:

  1. schema-mapper/loader.tsgetSchemaUrlFromMappings now 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 its versionRegex does not match. This also fixes the selection bug that blocked the obvious workaround of adding a second (0.7.0) mapping for the same credentialType.
  2. schema-mapper/default-mappings.json — adds 0.7.0 entries (unified context → untp.unece.org/artefacts schemas) alongside the existing 0.6.x entries. Note: the v0.7.0 DCC artefact is published as dcc/ConformityCredential.json (no Digital prefix), unlike the other four types, so it needs an explicit pattern — a uniform Digital<Type>.json template would 404.
  3. test-utils.tsextractUNTPVersion now 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?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help

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.mjs in this package is an inactive stub with testMatch: [], and jest is not a devDependency here). A minimal, generic UNTP 0.7.0 DPP fixture (test-fixtures/untp-0.7.0/, no third-party @context dependency) 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 introducing jest/ts-jest to 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 build for this package exits non-zero on a pre-existing, unrelated error (TS7016: Could not find a declaration file for module 'jsonld' in n3-utils.ts) that is present on next before this PR; tsc still emits dist/ and the CLI runs. This PR does not touch n3-utils.ts and does not introduce the error.

Added to documentation?

API Documentation Updated?

  • 📚 Updated Swagger schemas in schemas.ts
  • ✅ Verified Zod schemas match Prisma database schema
  • 🙅 No API changes in this PR

[optional] Are there any post-deployment tasks we need to perform?

None.

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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/untp-test-suite/src/untp-test/schema-mapper/loader.ts Outdated
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tier 2 schema mapper is not UNTP 0.7.0-aware: every 0.7.0 credential fails with "expected null to be a string"

1 participant