Skip to content

The open alternative to Salesforce, designed for AI.

improve dry run logs: show entity names and changed fields (#22299)

Marie3031891491a4
diff --git a/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/__tests__/format-sync-actions-summary.spec.ts b/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/__tests__/format-sync-actions-summary.spec.ts
index c4faf2b77f2..a309ba1d7ea 100644
--- a/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/__tests__/format-sync-actions-summary.spec.ts
+++ b/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/__tests__/format-sync-actions-summary.spec.ts
@@ -58,6 +58,67 @@ describe('formatSyncActionsSummary', () => {
]);
});
+ it('shows the name and uuid for updated/deleted entities when flatEntity is present', () => {
+ const events = formatSyncActionsSummary([
+ {
+ type: 'update',
+ metadataName: 'fieldMetadata',
+ universalIdentifier: '94265b02-25b4-4bd3-9dae-669f9e983c0f',
+ flatEntity: { name: 'myField' },
+ },
+ {
+ type: 'delete',
+ metadataName: 'objectMetadata',
+ universalIdentifier: 'c1a2b3c4-d5e6-4f78-9a01-234567890abc',
+ flatEntity: { nameSingular: 'rocket' },
+ },
+ ]);
+
+ expect(events).toEqual([
+ {
+ message: 'Metadata changes: 1 updated, 1 deleted',
+ status: 'info',
+ },
+ {
+ message:
+ ' updated fieldMetadata myField (94265b02-25b4-4bd3-9dae-669f9e983c0f)',
+ status: 'info',
+ },
+ {
+ message:
+ ' deleted objectMetadata rocket (c1a2b3c4-d5e6-4f78-9a01-234567890abc)',
+ status: 'info',
+ },
+ ]);
+ });
+
+ it('shows changed fields in brackets for update actions with diff', () => {
+ const events = formatSyncActionsSummary([
+ {
+ type: 'update',
+ metadataName: 'fieldMetadata',
+ universalIdentifier: '94265b02-25b4-4bd3-9dae-669f9e983c0f',
+ flatEntity: { name: 'myField' },
+ diff: {
+ label: { before: 'Old Label', after: 'New Label' },
+ description: { before: null, after: 'A description' },
+ },
+ },
+ ]);
+
+ expect(events).toEqual([
+ {
+ message: 'Metadata changes: 1 updated',
+ status: 'info',
+ },
+ {
+ message:
+ ' updated fieldMetadata myField (94265b02-25b4-4bd3-9dae-669f9e983c0f) [label, description] changed',
+ status: 'info',
+ },
+ ]);
+ });
+
it('falls back to the universal identifier when a created entity has no name', () => {
const events = formatSyncActionsSummary([
{
diff --git a/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/format-sync-actions-summary.ts b/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/format-sync-actions-summary.ts
index 4b9ab96930c..fa1352bd7e4 100644
--- a/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/format-sync-actions-summary.ts
+++ b/packages/twenty-sdk/src/cli/utilities/dev/orchestrator/steps/format-sync-actions-summary.ts
@@ -10,19 +10,46 @@ const VERB_BY_TYPE = {
delete: 'deleted',
} as const;
-const getActionLabel = (action: SyncAction): string => {
+const getFlatEntityName = (
+ flatEntity: SyncAction['flatEntity'],
+): string | null => {
+ const universalIdentifier = flatEntity?.universalIdentifier;
+
+ return (
+ flatEntity?.name ??
+ flatEntity?.nameSingular ??
+ (typeof universalIdentifier === 'string' ? universalIdentifier : null)
+ );
+};
+
+const getEntityLabel = (action: SyncAction): string => {
if (action.type === 'create') {
- return (
- action.flatEntity?.name ??
- action.flatEntity?.nameSingular ??
- action.flatEntity?.universalIdentifier ??
- 'unknown'
- );
+ return getFlatEntityName(action.flatEntity) ?? 'unknown';
+ }
+
+ const nameLabel = getFlatEntityName(action.flatEntity);
+
+ if (nameLabel && nameLabel !== action.universalIdentifier) {
+ return `${nameLabel} (${action.universalIdentifier})`;
}
return action.universalIdentifier;
};
+const getChangedFieldsNote = (action: SyncAction): string => {
+ if (action.type !== 'update' || !isDefined(action.diff)) {
+ return '';
+ }
+
+ const changedFields = Object.keys(action.diff);
+
+ if (changedFields.length === 0) {
+ return '';
+ }
+
+ return ` [${changedFields.join(', ')}] changed`;
+};
+
export const formatSyncActionsSummary = (
actions: SyncAction[] | undefined,
): OrchestratorStateStepEvent[] => {
@@ -51,8 +78,11 @@ export const formatSyncActionsSummary = (
const visibleActions = definedActions.slice(0, MAX_DETAIL_LINES);
for (const action of visibleActions) {
+ const label = getEntityLabel(action);
+ const changedFieldsNote = getChangedFieldsNote(action);
+
events.push({
- message: ` ${VERB_BY_TYPE[action.type]} ${action.metadataName} ${getActionLabel(action)}`,
+ message: ` ${VERB_BY_TYPE[action.type]} ${action.metadataName} ${label}${changedFieldsNote}`,
status: 'info',
});
}
diff --git a/packages/twenty-shared/src/metadata/types/sync-action.type.ts b/packages/twenty-shared/src/metadata/types/sync-action.type.ts
index da365f5d3fe..2e808eafe60 100644
--- a/packages/twenty-shared/src/metadata/types/sync-action.type.ts
+++ b/packages/twenty-shared/src/metadata/types/sync-action.type.ts
@@ -1,26 +1,31 @@
import { type AllMetadataName } from '@/metadata/types/all-metadata-name.type';
+type SyncActionFlatEntity = {
+ name?: string | null;
+ nameSingular?: string | null;
+ universalIdentifier?: string | null;
+ [key: string]: unknown;
+};
+
type SyncCreateAction = {
type: 'create';
metadataName: AllMetadataName;
- flatEntity?: {
- name?: string | null;
- nameSingular?: string | null;
- universalIdentifier?: string | null;
- [key: string]: unknown;
- };
+ flatEntity?: SyncActionFlatEntity;
};
type SyncUpdateAction = {
type: 'update';
metadataName: AllMetadataName;
universalIdentifier: string;
+ flatEntity?: SyncActionFlatEntity;
+ diff?: Record<string, { before: unknown; after: unknown }>;
};
type SyncDeleteAction = {
type: 'delete';
metadataName: AllMetadataName;
universalIdentifier: string;
+ flatEntity?: SyncActionFlatEntity;
};
export type SyncAction = SyncCreateAction | SyncUpdateAction | SyncDeleteAction;