Skip to content

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

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

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

Conversation

@cs-raj

Copy link
Copy Markdown
Contributor

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

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

Edge Cases Handled

CaseHandling
reference_to undefined/nullSkip check (no restriction)
reference_to stringNormalize to [reference_to]
reference_to empty arrayNo refs allowed; invalid if ref present
refCtUid undefinedSkip 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 attrsUse 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

Comment threadpackages/contentstack-audit/src/modules/entries.ts
@aman19K
aman19K self-requested a review February 24, 2026 05:54
@cs-raj
cs-raj merged commit aa08882 into developmentFeb 24, 2026
10 checks passed
@cs-raj
cs-raj deleted the feat/DX-3800 branch February 24, 2026 06:13
Sign up for freeto 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

@cs-raj@aman19K