From 17def3be0918c9eea0684939bf5ddc0019b0c364 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 16 Nov 2026 18:17:31 +0530 Subject: [PATCH 1/2] fix(branches): label content type option changes in branch diff (DX-30314) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cm:branches:diff --format detailed-text reported content type option changes (e.g. options.is_page) as "Unknown Field" with Field Path "N/A". The compare API returns these as { path: "options.", value } with no uid or display_name; only title, description and options.singleton were special-cased, so every other option fell through to the schema-field path. The CSV writer also hard-coded Field Path to "N/A" for every row. - Handle any options.* difference as its own entry, labelled "Options → ", with its path and old/new values (modified, added and deleted cases) - Write the real diff path to the CSV Field Path column instead of "N/A" - Show actual old/new values for content type level changes (options, title, description) instead of the item's uid - getFieldDisplayName falls back to the path before "Unknown Field" - Add unit tests for option changes, field paths and singleton values Co-Authored-By: Claude Opus 5.5 --- .../src/interfaces/index.ts | 1 + .../src/utils/branch-diff-utility.ts | 29 ++++- .../src/utils/csv-utility.ts | 63 ++++++++-- .../test/unit/utils/csv-utility.test.ts | 113 ++++++++++++++++++ 4 files changed, 197 insertions(+), 9 deletions(-) diff --git a/packages/contentstack-branches/src/interfaces/index.ts b/packages/contentstack-branches/src/interfaces/index.ts index 29eba9801..71e9b9397 100644 --- a/packages/contentstack-branches/src/interfaces/index.ts +++ b/packages/contentstack-branches/src/interfaces/index.ts @@ -92,6 +92,7 @@ export interface CSVRow { export interface AddCSVRowParams { contentTypeName: string; fieldName: string; + fieldPath?: string; fieldType: string; sourceValue: string; srNo: number; diff --git a/packages/contentstack-branches/src/utils/branch-diff-utility.ts b/packages/contentstack-branches/src/utils/branch-diff-utility.ts index 7085735f2..c27a13a55 100644 --- a/packages/contentstack-branches/src/utils/branch-diff-utility.ts +++ b/packages/contentstack-branches/src/utils/branch-diff-utility.ts @@ -19,7 +19,13 @@ import { ModifiedFieldsInput, ModifiedFieldsType, } from '../interfaces/index'; -import { extractValueFromPath, generateCSVDataFromVerbose, getFieldDisplayName } from './csv-utility'; +import { + extractValueFromPath, + generateCSVDataFromVerbose, + getFieldDisplayName, + getOptionDisplayName, + isContentTypeOptionPath, +} from './csv-utility'; /** * Fetch differences between two branches @@ -320,6 +326,9 @@ async function baseAndCompareBranchDiff(params: { displayName = 'Description'; path = baseBranchFieldExists?.path; field = 'metadata'; + } else if (isContentTypeOptionPath(baseBranchFieldExists.path)) { + displayName = getOptionDisplayName(baseBranchFieldExists.path); + field = 'option'; } params.listOfDeletedFields.push({ displayName: displayName, @@ -335,6 +344,9 @@ async function baseAndCompareBranchDiff(params: { displayName = 'Description'; path = compareBranchFieldExists?.path; field = 'metadata'; + } else if (isContentTypeOptionPath(compareBranchFieldExists.path)) { + displayName = getOptionDisplayName(compareBranchFieldExists.path); + field = 'option'; } params.listOfAddedFields.push({ displayName: displayName, @@ -388,6 +400,21 @@ async function prepareModifiedDiff(params: { path: '', uid: baseBranchFieldExists.path, }); + } else if (isContentTypeOptionPath(compareBranchFieldExists.path)) { + // Other content type options (is_page, title, url_pattern, url_prefix, ...) carry { path, value } + // and no uid/display_name, so they must not go through the schema field deep diff. + const optionPath: string = compareBranchFieldExists.path; + const oldValue = baseBranchFieldExists?.value; + const newValue = compareBranchFieldExists.value; + params.listOfModifiedFields.push({ + changeDetails: `Changed from "${oldValue}" to "${newValue}"`, + displayName: getOptionDisplayName(optionPath), + field: 'option', + newValue, + oldValue, + path: optionPath, + uid: optionPath, + }); } else { const fieldDisplayName = getFieldDisplayName(compareBranchFieldExists); diff --git a/packages/contentstack-branches/src/utils/csv-utility.ts b/packages/contentstack-branches/src/utils/csv-utility.ts index 0d5d7e513..95de276ac 100644 --- a/packages/contentstack-branches/src/utils/csv-utility.ts +++ b/packages/contentstack-branches/src/utils/csv-utility.ts @@ -11,17 +11,39 @@ import { AddCSVRowParams, BranchDiffVerboseRes, CSV_HEADER, CSVRow, ContentTypeI */ export function getFieldDisplayName(field: Record): string { let fieldName = field?.displayName || field?.display_name || field?.title || field?.uid; - - // Special handling for field_rules - if (!fieldName && field?.path === 'field_rules') { - fieldName = 'Field Rules'; - } else if (!fieldName) { - fieldName = 'Unknown Field'; + + if (!fieldName) { + const path = typeof field?.path === 'string' ? field.path : ''; + if (path === 'field_rules') { + fieldName = 'Field Rules'; + } else if (isContentTypeOptionPath(path)) { + fieldName = getOptionDisplayName(path); + } else { + fieldName = path || 'Unknown Field'; + } } - + return fieldName as string; } +/** + * Whether a diff path points at a content type option (e.g. "options.is_page") + * @param path - The diff item path + * @returns {boolean} + */ +export function isContentTypeOptionPath(path: unknown): path is string { + return typeof path === 'string' && path.startsWith('options.') && path.length > 'options.'.length; +} + +/** + * Readable label for a content type option path, e.g. "options.is_page" -> "Options → is_page" + * @param path - The option path + * @returns {string} + */ +export function getOptionDisplayName(path: string): string { + return `Options → ${path.slice('options.'.length).split('.').join(' → ')}`; +} + /** * Format values for CSV display * @param value - The value to format @@ -230,7 +252,7 @@ function addCSVRow(csvRows: CSVRow[], params: AddCSVRowParams): void { csvRows.push({ contentTypeName: params.contentTypeName, fieldName: params.fieldName, - fieldPath: 'N/A', + fieldPath: params.fieldPath || 'N/A', operation: params.fieldType, sourceBranchValue: params.sourceValue, srNo: params.srNo, @@ -258,22 +280,36 @@ function addFieldChangesToCSV(csvRows: CSVRow[], params: { fields.forEach(field => { const fieldName = getFieldDisplayName(field); + const fieldPath = getCSVFieldPath(field); if (field.propertyChanges?.length > 0) { field.propertyChanges.forEach(propertyChange => { addCSVRow(csvRows, { contentTypeName: params.contentTypeName, fieldName, + fieldPath, fieldType, sourceValue: formatValue(propertyChange.newValue), srNo: srNo++, targetValue: formatValue(propertyChange.oldValue) }); }); + } else if (fieldType === 'modified' && ('newValue' in field || 'oldValue' in field)) { + // Content type level changes (options, title, description) carry their values directly + addCSVRow(csvRows, { + contentTypeName: params.contentTypeName, + fieldName, + fieldPath, + fieldType, + sourceValue: formatValue(field.newValue), + srNo: srNo++, + targetValue: formatValue(field.oldValue) + }); } else { addCSVRow(csvRows, { contentTypeName: params.contentTypeName, fieldName, + fieldPath, fieldType, sourceValue: fieldType === 'added' ? 'N/A' : formatValue(field), srNo: srNo++, @@ -284,6 +320,17 @@ function addFieldChangesToCSV(csvRows: CSVRow[], params: { }); } +/** + * Field path shown in the CSV: the diff path (e.g. "group.title", "options.is_page"), + * falling back to the uid for content type level changes that carry an empty path. + * @param field - The diff item + * @returns {string} Field path, or 'N/A' when none is known + */ +function getCSVFieldPath(field: Record): string { + const path = typeof field?.path === 'string' && field.path && field.path !== 'undefined' ? field.path : ''; + return path || (typeof field?.uid === 'string' && field.uid) || 'N/A'; +} + /** * Get total field count for serial number calculation * @param modifiedFields - Field changes data diff --git a/packages/contentstack-branches/test/unit/utils/csv-utility.test.ts b/packages/contentstack-branches/test/unit/utils/csv-utility.test.ts index 442749105..245149c25 100644 --- a/packages/contentstack-branches/test/unit/utils/csv-utility.test.ts +++ b/packages/contentstack-branches/test/unit/utils/csv-utility.test.ts @@ -4,6 +4,7 @@ import { stub } from 'sinon'; import { join } from 'path'; import { cliux } from '@contentstack/cli-utilities'; import * as csvUtility from '../../../src/utils/csv-utility'; +import * as branchDiffUtility from '../../../src/utils/branch-diff-utility'; import { BranchDiffVerboseRes } from '../../../src/interfaces'; describe('CSV Utility Testcases', () => { @@ -130,6 +131,118 @@ describe('CSV Utility Testcases', () => { expect(deletedCTRow?.targetBranchValue).to.equal('N/A'); }); + it('should fill Field Path from the diff path instead of always N/A', () => { + const result = csvUtility.generateCSVDataFromVerbose({ + modified: [ + { + moduleDetails: { title: 'Blog', uid: 'blog', status: 'modified', type: 'content_type' }, + modifiedFields: { + modified: [ + { + path: 'seo.meta_title', + displayName: 'Meta Title', + uid: 'meta_title', + field: 'text field', + propertyChanges: [{ property: 'mandatory', changeType: 'modified', oldValue: false, newValue: true }], + }, + ], + }, + }, + ], + added: [], + deleted: [], + }); + + expect(result).to.have.length(1); + expect(result[0].fieldPath).to.equal('seo.meta_title'); + }); + + it('DX-30314: should label content type option changes and use their path', async () => { + const branchDiff = { + diff: { + status: 'modified', + base_branch: { + differences: [ + { path: 'options.is_page', value: false }, + { path: 'options.url_prefix', value: '/' }, + ], + }, + compare_branch: { + differences: [ + { path: 'options.is_page', value: true }, + { path: 'options.url_prefix', value: '/jobs/' }, + { path: 'options.url_pattern', value: '/:title' }, + ], + }, + }, + }; + + const { listOfAddedFields, listOfDeletedFields, listOfModifiedFields } = + await branchDiffUtility.prepareBranchVerboseRes(branchDiff); + + expect(listOfModifiedFields.map((f) => f.displayName)).to.deep.equal([ + 'Options → is_page', + 'Options → url_prefix', + ]); + expect(listOfAddedFields).to.have.length(1); + expect(listOfAddedFields[0].displayName).to.equal('Options → url_pattern'); + expect(listOfAddedFields[0].path).to.equal('options.url_pattern'); + expect(listOfDeletedFields).to.have.length(0); + + const result = csvUtility.generateCSVDataFromVerbose({ + modified: [ + { + moduleDetails: { title: 'Page - Employer', uid: 'page_employer', status: 'modified', type: 'content_type' }, + modifiedFields: { added: listOfAddedFields, deleted: listOfDeletedFields, modified: listOfModifiedFields }, + }, + ], + added: [], + deleted: [], + }); + + const isPageRow = result.find((row) => row.fieldPath === 'options.is_page'); + expect(isPageRow).to.exist; + expect(isPageRow?.fieldName).to.equal('Options → is_page'); + expect(isPageRow?.operation).to.equal('modified'); + expect(isPageRow?.sourceBranchValue).to.equal('true'); + expect(isPageRow?.targetBranchValue).to.equal('false'); + + const urlPrefixRow = result.find((row) => row.fieldPath === 'options.url_prefix'); + expect(urlPrefixRow?.sourceBranchValue).to.equal('/jobs/'); + expect(urlPrefixRow?.targetBranchValue).to.equal('/'); + + expect(result.some((row) => row.fieldName === 'Unknown Field')).to.be.false; + }); + + it('should show values, not the uid, for content type level changes like singleton', () => { + const result = csvUtility.generateCSVDataFromVerbose({ + modified: [ + { + moduleDetails: { title: 'Home', uid: 'home', status: 'modified', type: 'content_type' }, + modifiedFields: { + modified: [ + { + changeDetails: 'Changed from Multiple to Single', + displayName: 'Single', + field: 'changed', + newValue: true, + oldValue: false, + path: '', + uid: 'options.singleton', + }, + ], + }, + }, + ], + added: [], + deleted: [], + }); + + expect(result[0].fieldPath).to.equal('options.singleton'); + expect(result[0].sourceBranchValue).to.equal('true'); + expect(result[0].targetBranchValue).to.equal('false'); + }); + it('should handle empty verbose results gracefully', () => { const emptyVerboseRes: BranchDiffVerboseRes = { modified: [], From 78d2102683addb8310bc9bcd9fc120cee74bc423 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 16 Nov 2026 18:38:53 +0530 Subject: [PATCH 2/2] fix(branches): label singleton like other content type options (DX-30314) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit options.singleton had its own special case that labelled the change "Single"/"Multiple" with an empty path. Route it through the generic options.* handling so it is reported as "Options → singleton" with path options.singleton and its old/new values, like every other option. - Remove options.singleton from the title/description special case - Replace the synthetic singleton test with one driven by the API shape - Add a test for content type rename values (the remaining special case) Co-Authored-By: Claude Opus 5.5 --- .../src/utils/branch-diff-utility.ts | 18 ++----- .../test/unit/utils/csv-utility.test.ts | 52 ++++++++++++++----- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/packages/contentstack-branches/src/utils/branch-diff-utility.ts b/packages/contentstack-branches/src/utils/branch-diff-utility.ts index c27a13a55..6a0f6b527 100644 --- a/packages/contentstack-branches/src/utils/branch-diff-utility.ts +++ b/packages/contentstack-branches/src/utils/branch-diff-utility.ts @@ -365,22 +365,10 @@ async function prepareModifiedDiff(params: { listOfModifiedFields: any[]; }) { const { baseBranchFieldExists, compareBranchFieldExists } = params; - if ( - compareBranchFieldExists.path === 'description' || - compareBranchFieldExists.path === 'title' || - compareBranchFieldExists.path === 'options.singleton' - ) { + if (compareBranchFieldExists.path === 'description' || compareBranchFieldExists.path === 'title') { let displayName: string; let changeDetails = ''; - if (baseBranchFieldExists.path === 'options.singleton') { - if (compareBranchFieldExists.value) { - displayName = 'Single'; - changeDetails = `Changed from Multiple to Single`; - } else { - displayName = 'Multiple'; - changeDetails = `Changed from Single to Multiple`; - } - } else if (baseBranchFieldExists.path === 'description') { + if (baseBranchFieldExists.path === 'description') { displayName = 'Description'; const oldDesc = baseBranchFieldExists.value || 'undefined'; const newDesc = compareBranchFieldExists.value || 'undefined'; @@ -401,7 +389,7 @@ async function prepareModifiedDiff(params: { uid: baseBranchFieldExists.path, }); } else if (isContentTypeOptionPath(compareBranchFieldExists.path)) { - // Other content type options (is_page, title, url_pattern, url_prefix, ...) carry { path, value } + // Content type options (is_page, singleton, title, url_pattern, url_prefix, ...) carry { path, value } // and no uid/display_name, so they must not go through the schema field deep diff. const optionPath: string = compareBranchFieldExists.path; const oldValue = baseBranchFieldExists?.value; diff --git a/packages/contentstack-branches/test/unit/utils/csv-utility.test.ts b/packages/contentstack-branches/test/unit/utils/csv-utility.test.ts index 245149c25..7b66014ee 100644 --- a/packages/contentstack-branches/test/unit/utils/csv-utility.test.ts +++ b/packages/contentstack-branches/test/unit/utils/csv-utility.test.ts @@ -214,35 +214,59 @@ describe('CSV Utility Testcases', () => { expect(result.some((row) => row.fieldName === 'Unknown Field')).to.be.false; }); - it('should show values, not the uid, for content type level changes like singleton', () => { + it('DX-30314: should label singleton like the other content type options', async () => { + const { listOfModifiedFields } = await branchDiffUtility.prepareBranchVerboseRes({ + diff: { + status: 'modified', + base_branch: { differences: [{ path: 'options.singleton', value: false }] }, + compare_branch: { differences: [{ path: 'options.singleton', value: true }] }, + }, + }); + const result = csvUtility.generateCSVDataFromVerbose({ modified: [ { moduleDetails: { title: 'Home', uid: 'home', status: 'modified', type: 'content_type' }, - modifiedFields: { - modified: [ - { - changeDetails: 'Changed from Multiple to Single', - displayName: 'Single', - field: 'changed', - newValue: true, - oldValue: false, - path: '', - uid: 'options.singleton', - }, - ], - }, + modifiedFields: { modified: listOfModifiedFields }, }, ], added: [], deleted: [], }); + expect(result).to.have.length(1); + expect(result[0].fieldName).to.equal('Options → singleton'); expect(result[0].fieldPath).to.equal('options.singleton'); expect(result[0].sourceBranchValue).to.equal('true'); expect(result[0].targetBranchValue).to.equal('false'); }); + it('should show values, not the uid, for a content type rename', async () => { + const { listOfModifiedFields } = await branchDiffUtility.prepareBranchVerboseRes({ + diff: { + status: 'modified', + base_branch: { differences: [{ path: 'title', value: 'Home' }] }, + compare_branch: { differences: [{ path: 'title', value: 'Home Page' }] }, + }, + }); + + const result = csvUtility.generateCSVDataFromVerbose({ + modified: [ + { + moduleDetails: { title: 'Home', uid: 'home', status: 'modified', type: 'content_type' }, + modifiedFields: { modified: listOfModifiedFields }, + }, + ], + added: [], + deleted: [], + }); + + expect(result[0].fieldName).to.equal('Display Name'); + expect(result[0].fieldPath).to.equal('title'); + expect(result[0].sourceBranchValue).to.equal('Home Page'); + expect(result[0].targetBranchValue).to.equal('Home'); + }); + it('should handle empty verbose results gracefully', () => { const emptyVerboseRes: BranchDiffVerboseRes = { modified: [],