Skip to content

Fix mdoc fallback field assembly in openId4VCI Utils - #2397

Open
dhruv1955 wants to merge 4 commits into
inji:masterfrom
dhruv1955:fix/mdoc-fields-concat-utils
Open

Fix mdoc fallback field assembly in openId4VCI Utils#2397
dhruv1955 wants to merge 4 commits into
inji:masterfrom
dhruv1955:fix/mdoc-fields-concat-utils

Conversation

@dhruv1955

@dhruv1955 dhruv1955 commented Apr 21, 2026

Copy link
Copy Markdown

What and Why

Array.concat() returns a new array - the result wasn't being stored, so derived mdoc fallback fields were silently dropped before reaching the UI. This broke the detail view for mdoc credentials missing issuer-defined ordering.

Changes

  • Utils.ts - store the result of fields.concat(...) back into fields
  • Utils.test.ts - regression test for the mdoc fallback path

Validation

  • npx tsc --noEmit
  • npx eslint on both files - warnings only, no errors
  • Direct Node execution confirmed fallback fields are now returned correctly

Full Jest is blocked by a pre-existing @mosip/tuvali issue in jest-init.js, unrelated to this change.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed field path accumulation for mdoc credential configurations to ensure proper handling of credential fields during issuer configuration parsing.
  • Tests

    • Added comprehensive test coverage for credential issuer configuration handling with enhanced validation scenarios.

Signed-off-by: Chandra Keshav Mishra <chandrakeshavmishra@gmail.com>
@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@dhruv1955 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 54 minutes and 18 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 54 minutes and 18 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ba56dd6-3a5a-4ffc-a870-1c3059f17b83

📥 Commits

Reviewing files that changed from the base of the PR and between 9a0a47e and 65b33fd.

📒 Files selected for processing (2)
  • shared/openId4VCI/Utils.test.ts
  • shared/openId4VCI/Utils.ts

Walkthrough

Bug fix in credential issuer utilities where field accumulation logic was corrected from a no-op fields.concat() statement to proper reassignment fields = fields.concat(). Removed unused imports and cleaned up formatting. Added test coverage for the getCredentialIssuersWellKnownConfig function with validation of field path generation for MSO mdoc credentials.

Changes

Cohort / File(s) Summary
Implementation
shared/openId4VCI/Utils.ts
Removed unused imports (getCredentialTypeFromWellKnown, getVerifiableCredential). Fixed field accumulation in getCredentialIssuersWellKnownConfig by reassigning fields = fields.concat(...) instead of leaving it as a no-op. Applied minor formatting adjustments to conditional statements and type signatures (e.g., time: number | string).
Tests
shared/openId4VCI/Utils.test.ts
Added test imports and Jest mock for ../api. Introduced new test suite for getCredentialIssuersWellKnownConfig with stubs for fetchIssuerWellknownConfig, validating that MSO mdoc claim-derived field keys are correctly extracted and returned in result.fields.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • swatigoel

Poem

🐰 A field path that didn't accumulate so well,
Now gathers credentials with a reassignment spell,
Tests hop along to verify the gain,
MSO mdocs flow through our refactored domain! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: storing the result of Array.concat() when assembling mdoc fallback fields in openId4VCI Utils.
Description check ✅ Passed The description covers the bug fix (Array.concat() result not stored), changes made (Utils.ts and Utils.test.ts), and validation steps, but is missing the repository's required template sections (Issue ticket number/link and Screenshots).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dhruv1955
dhruv1955 force-pushed the fix/mdoc-fields-concat-utils branch from 654c8c2 to f391f10 Compare April 21, 2026 11:21

@abhip2565 abhip2565 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we remove unrelated formatiing changes?

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shared/openId4VCI/Utils.ts (1)

162-170: ⚠️ Potential issue | 🟠 Major

Build mdoc fallback fields locally before replacing defaults.

Line 163 clears fields before claim parsing succeeds, so a missing/malformed claims object makes the catch return [] instead of the promised default fields. This branch also leaves wellknownFieldsFlag false even when fields are derived from well-known metadata.

🐛 Proposed fix
         if (format === VCFormat.mso_mdoc) {
-          fields = [];
-          Object.keys(matchingWellknownDetails.claims).forEach(namespace => {
-            Object.keys(matchingWellknownDetails.claims[namespace]).forEach(
-              claim => {
-                fields = fields.concat(`${namespace}~${claim}`);
-              },
-            );
-          });
+          const claims = matchingWellknownDetails.claims ?? {};
+          const mdocFields = Object.keys(claims).flatMap(namespace =>
+            Object.keys(claims[namespace] ?? {}).map(
+              claim => `${namespace}~${claim}`,
+            ),
+          );
+
+          if (mdocFields.length > 0) {
+            fields = mdocFields;
+            wellknownFieldsFlag = true;
+          }
         } else if (format === VCFormat.ldp_vc) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shared/openId4VCI/Utils.ts` around lines 162 - 170, The code clears the
shared variable fields at the start of the VCFormat.mso_mdoc branch which causes
an empty array to be returned if matchingWellknownDetails.claims is
missing/malformed and also never sets wellknownFieldsFlag when fields are
successfully derived; fix by building a local fallback array (e.g.,
localMdocFields) from matchingWellknownDetails.claims inside a try block
(iterating namespace and claim as currently done), only assign it to the outer
fields when parsing succeeds, and set wellknownFieldsFlag = true when you assign
those derived values; ensure you do not mutate fields until parsing completes
and handle missing/malformed matchingWellknownDetails.claims by leaving the
default fields intact.
🧹 Nitpick comments (1)
shared/openId4VCI/Utils.test.ts (1)

265-272: Assert the well-known flag in the mdoc fallback regression.

This test now protects the field list, but it should also lock down that callers can recognize these fields as well-known-derived.

🧪 Proposed test assertion
       expect(result.fields).toEqual(
         expect.arrayContaining([
           'org.iso.18013.5.1~family_name',
           'org.iso.18013.5.1~given_name',
         ]),
       );
       expect(result.fields).toHaveLength(2);
+      expect(result.wellknownFieldsFlag).toBe(true);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shared/openId4VCI/Utils.test.ts` around lines 265 - 272, The test currently
locks the field list via result.fields but doesn't assert that those fields are
marked as well-known; add an assertion that the same field identifiers are
present in the well-known flag collection (e.g.
expect(result.wellKnown).toEqual(expect.arrayContaining(['org.iso.18013.5.1~family_name','org.iso.18013.5.1~given_name']))
and also assert its length (e.g. expect(result.wellKnown).toHaveLength(2)) so
callers can detect these as well-known-derived fields alongside the existing
result.fields checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@shared/openId4VCI/Utils.ts`:
- Around line 162-170: The code clears the shared variable fields at the start
of the VCFormat.mso_mdoc branch which causes an empty array to be returned if
matchingWellknownDetails.claims is missing/malformed and also never sets
wellknownFieldsFlag when fields are successfully derived; fix by building a
local fallback array (e.g., localMdocFields) from
matchingWellknownDetails.claims inside a try block (iterating namespace and
claim as currently done), only assign it to the outer fields when parsing
succeeds, and set wellknownFieldsFlag = true when you assign those derived
values; ensure you do not mutate fields until parsing completes and handle
missing/malformed matchingWellknownDetails.claims by leaving the default fields
intact.

---

Nitpick comments:
In `@shared/openId4VCI/Utils.test.ts`:
- Around line 265-272: The test currently locks the field list via result.fields
but doesn't assert that those fields are marked as well-known; add an assertion
that the same field identifiers are present in the well-known flag collection
(e.g.
expect(result.wellKnown).toEqual(expect.arrayContaining(['org.iso.18013.5.1~family_name','org.iso.18013.5.1~given_name']))
and also assert its length (e.g. expect(result.wellKnown).toHaveLength(2)) so
callers can detect these as well-known-derived fields alongside the existing
result.fields checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e8aaf672-3064-4440-8574-ce195fb5d5c1

📥 Commits

Reviewing files that changed from the base of the PR and between 21743f7 and 9a0a47e.

📒 Files selected for processing (2)
  • shared/openId4VCI/Utils.test.ts
  • shared/openId4VCI/Utils.ts

Signed-off-by: dhruv1955 <dhruvyadav042905@gmail.com>
Signed-off-by: dhruv1955 <dhruvyadav042905@gmail.com>
Signed-off-by: dhruv1955 <dhruvyadav042905@gmail.com>
@dhruv1955
dhruv1955 force-pushed the fix/mdoc-fields-concat-utils branch from 91efcca to 65b33fd Compare April 22, 2026 06:48
@dhruv1955

Copy link
Copy Markdown
Author

Thanks for the review @abhip2565! Removed all unrelated formatting changes - the PR now contains only:

  • Remove unused import getCredentialTypeFromWellKnown
  • Remove unused import getVerifiableCredential
  • Fix fields = fields.concat(...) - the actual bug
  • Regression test in Utils.test.ts

@abhip2565

Copy link
Copy Markdown
Contributor

Thanks for the review @abhip2565! Removed all unrelated formatting changes - the PR now contains only:

  • Remove unused import getCredentialTypeFromWellKnown
  • Remove unused import getVerifiableCredential
  • Fix fields = fields.concat(...) - the actual bug
  • Regression test in Utils.test.ts

Thanks. Did we do any dev testing to verify the scenario? If yes can we attach relevant video(s)?

@dhruv1955

Copy link
Copy Markdown
Author

@abhip2565 Here's a screenshot demonstrating the bug and fix.

Before the fix - fields.concat(...) result was not stored, so fields stays empty [].

After the fix - fields = fields.concat(...) correctly populates the derived mdoc field paths.

Screenshot 2026-04-22 123140

@abhip2565 abhip2565 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. @sanchi-singh24 @swatigoel Thinking should we verify once, the scenario (wellknown w/o order), in vc detail view... to catch any other errors upstream which can be fixed together for this edge case scenario,

@swatigoel

Copy link
Copy Markdown
Contributor

@dhruv1955 can you raise this PR for develop branch?

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.

4 participants