Skip to content

Comments

feat(audit): validate referenced entry content types in entries audit#2423

Merged
cs-raj merged 2 commits intodevelopmentfrom
feat/DX-3800
Feb 24, 2026
Merged

feat(audit): validate referenced entry content types in entries audit#2423
cs-raj merged 2 commits intodevelopmentfrom
feat/DX-3800

Conversation

@cs-raj
Copy link
Contributor

@cs-raj cs-raj commented Feb 23, 2026

feat(audit): Validate reference content types against schema in entries audit

Problem

The entries audit only verified that referenced entry UIDs exist in the export. It did not validate that the referenced entry's content type matched the schema's reference_to. This allowed invalid references to pass audit, e.g.:

  • Reference fields: A field with reference_to: ["ct1"] could reference ct2 entries and pass
  • JSON RTE: A field with reference_to: ["ct1", "sys_assets"] could embed ct2 entries and pass

These invalid references could cause import failures.

Solution

Add content-type validation so that when a reference exists in entryMetaData, the audit also checks that the referenced entry's content type is allowed by reference_to. Invalid references are now reported and can be fixed.

Changes

Area Change
Helper Added isRefContentTypeAllowed(refCtUid, referenceTo, config?) to centralize the content-type check
Audit – reference fields In validateReferenceValues, when ref exists, validate content type and report if invalid
Audit – JSON RTE In jsonRefCheck, when ref exists, validate content type and report if invalid
Fix – reference fields In fixMissingReferences, filter out refs with invalid content type and record in missingRefs
Fix – JSON RTE In jsonRefCheck, return null when CT invalid in fix mode so fix path removes the embed

Edge Cases Handled

Case Handling
reference_to undefined/null Skip check (no restriction)
reference_to string Normalize to [reference_to]
reference_to empty array No refs allowed; invalid if ref present
refCtUid undefined Skip check (cannot determine)
refCtUid in skipRefs (e.g. sys_assets) Allow
Reference as string "blt..." Use refExist.ctUid from metadata
Reference as { uid, _content_type_uid } Prefer _content_type_uid, fallback refExist.ctUid
JSON RTE attrs Use content-type-uid (kebab-case)

Testing

  • Unit tests: 7 for isRefContentTypeAllowed, 3 for validateReferenceValues, 1 for JSON RTE audit, 1 for fixMissingReferences, 1 for jsonRefCheck fix mode
  • TDD: Tests written first, then implementation
  • All 140 unit tests pass

Files Changed

  • packages/contentstack-audit/src/modules/entries.ts – implementation
  • packages/contentstack-audit/test/unit/modules/entries.test.ts – unit tests

@aman19K aman19K self-requested a review February 24, 2026 05:54
@cs-raj cs-raj merged commit aa08882 into development Feb 24, 2026
10 checks passed
@cs-raj cs-raj deleted the feat/DX-3800 branch February 24, 2026 06:13
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.

2 participants