The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Keep undeclared application references on additive apply (#25335)
Weikoe2dd1dc9c92b
diff --git a/packages/twenty-docs/developers/extend/apps/operations/sync-and-recovery.mdx b/packages/twenty-docs/developers/extend/apps/operations/sync-and-recovery.mdxindex 5abda50f810..7e35bad1cfb 100644--- a/packages/twenty-docs/developers/extend/apps/operations/sync-and-recovery.mdx+++ b/packages/twenty-docs/developers/extend/apps/operations/sync-and-recovery.mdx@@ -54,7 +54,7 @@ This is your first diagnostic: it tells you exactly which objects, fields, and lDestructive changes (`to destroy`) are listed with what they drop (e.g. `objectMetadata "auditNote" — drops the table and all its rows`) and require interactive confirmation, or `--force` in scripts.-A sync deletes every entity your app owns that your source no longer declares. When a plan contains destroys it says so and points at `--no-delete`, which makes the sync additive: creates and updates are applied, nothing missing from your source is deleted. Use it when your source is intentionally partial, for example while adopting an app that was built in the UI.+A sync deletes every entity your app owns that your source no longer declares. When a plan contains destroys it says so and points at `--no-delete`, which makes the sync additive: creates and updates are applied, nothing missing from your source is deleted, and the settings component and uninstall hook bindings of the app stay as they are when your source does not declare them. Use it when your source is intentionally partial, for example while adopting an app that was built in the UI.When a sync fails on a single entity, the error names the offending entity and its `universalIdentifier`, for example:diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.tsindex 5a96ccafe7a..5f8f941f977 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.ts@@ -268,6 +268,7 @@ export class ApplicationManifestMigrationService {manifest,workspaceId,ownerFlatApplication,+ inferDeletionFromMissingEntities,});}@@ -281,10 +282,12 @@ export class ApplicationManifestMigrationService {manifest,workspaceId,ownerFlatApplication,+ inferDeletionFromMissingEntities,}: {manifest: Manifest;workspaceId: string;ownerFlatApplication: FlatApplication;+ inferDeletionFromMissingEntities: boolean;}) {const {flatRoleMaps: refreshedFlatRoleMaps,@@ -345,8 +348,14 @@ export class ApplicationManifestMigrationService {await this.applicationService.update(ownerFlatApplication.id, {workspaceId,- settingsCustomTabFrontComponentId,- uninstallLogicFunctionId,+ ...(isDefined(settingsCustomTabFrontComponentId) ||+ inferDeletionFromMissingEntities+ ? { settingsCustomTabFrontComponentId }+ : {}),+ ...(isDefined(uninstallLogicFunctionId) ||+ inferDeletionFromMissingEntities+ ? { uninstallLogicFunctionId }+ : {}),...(isDefined(defaultRoleId) ? { defaultRoleId } : {}),});}diff --git a/packages/twenty-server/test/integration/metadata/suites/application/successful-sync-application-additive-mode.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/successful-sync-application-additive-mode.integration-spec.tsindex fc2d7a19457..d63170b4ded 100644--- a/packages/twenty-server/test/integration/metadata/suites/application/successful-sync-application-additive-mode.integration-spec.ts+++ b/packages/twenty-server/test/integration/metadata/suites/application/successful-sync-application-additive-mode.integration-spec.ts@@ -3,6 +3,7 @@ import { buildDefaultObjectManifest } from 'test/integration/metadata/suites/appimport { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';import { setupApplicationForSync } from 'test/integration/metadata/suites/application/utils/setup-application-for-sync.util';import { syncApplication } from 'test/integration/metadata/suites/application/utils/sync-application.util';+import { uploadApplicationFile } from 'test/integration/metadata/suites/application/utils/upload-application-file.util';import { findManyObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/find-many-object-metadata.util';import { deactivateSkill } from 'test/integration/metadata/suites/skill/utils/deactivate-skill.util';import { findSkills } from 'test/integration/metadata/suites/skill/utils/find-skills.util';@@ -13,6 +14,9 @@ import { v4 as uuidv4 } from 'uuid';const TEST_APP_ID = uuidv4();const TEST_ROLE_ID = uuidv4();const SKILL_NAME = 'additiveModeSkill';+const CLEANUP_LOGIC_FUNCTION_ID = uuidv4();+const SETTINGS_FRONT_COMPONENT_ID = uuidv4();+const BUILT_SETTINGS_COMPONENT_PATH = 'src/front-components/settings.mjs';const skill: SkillManifest = {universalIdentifier: uuidv4(),@@ -48,6 +52,67 @@ const buildManifest = (overrides: { skills: [skill], ...overrides },});+const buildManifestWithApplicationReferences = (): Manifest => {+ const baseManifest = buildManifest({+ objects: [ticketObject, invoiceObject],+ });++ return {+ ...baseManifest,+ application: {+ ...baseManifest.application,+ settingsFrontComponent: {+ universalIdentifier: SETTINGS_FRONT_COMPONENT_ID,+ },+ uninstallLogicFunction: {+ universalIdentifier: CLEANUP_LOGIC_FUNCTION_ID,+ },+ },+ logicFunctions: [+ {+ universalIdentifier: CLEANUP_LOGIC_FUNCTION_ID,+ name: 'Cleanup',+ description: 'Uninstall cleanup logic function',+ handlerName: 'handler',+ sourceHandlerPath: 'src/cleanup.ts',+ builtHandlerPath: 'dist/cleanup.mjs',+ builtHandlerChecksum: 'checksum-cleanup',+ httpRouteTriggerSettings: {+ path: '/cleanup',+ httpMethod: 'POST',+ isAuthRequired: true,+ },+ },+ ],+ frontComponents: [+ {+ universalIdentifier: SETTINGS_FRONT_COMPONENT_ID,+ name: 'SettingsComponent',+ description: 'The settings tab of the application',+ sourceComponentPath: 'src/front-components/settings.tsx',+ builtComponentPath: BUILT_SETTINGS_COMPONENT_PATH,+ builtComponentChecksum: 'settings-checksum',+ componentName: 'SettingsComponent',+ isHeadless: false,+ },+ ],+ };+};++const findApplicationReferences = async (): Promise<{+ settingsCustomTabFrontComponentId: string | null;+ uninstallLogicFunctionId: string | null;+}> => {+ const [application] = await globalThis.testDataSource.query(+ `SELECT "settingsCustomTabFrontComponentId", "uninstallLogicFunctionId"+ FROM core."application"+ WHERE "universalIdentifier" = $1 AND "deletedAt" IS NULL`,+ [TEST_APP_ID],+ );++ return application;+};+const findObjectNames = async (): Promise<string[]> => {const { objects } = await findManyObjectMetadata({input: { filter: {}, paging: { first: 100 } },@@ -138,6 +203,55 @@ describe('Manifest sync - additive mode', () => {expect(objectNames).toContain('additiveInvoice');}, 60000);+ it('keeps the settings component and uninstall hook bindings when the source stops declaring them and deletions are turned off', async () => {+ jest.useRealTimers();++ await uploadApplicationFile({+ applicationUniversalIdentifier: TEST_APP_ID,+ fileFolder: 'BuiltFrontComponent',+ filePath: BUILT_SETTINGS_COMPONENT_PATH,+ fileBuffer: Buffer.from('dummy built component content'),+ filename: 'settings.mjs',+ contentType: 'application/javascript',+ expectToFail: false,+ });++ jest.useFakeTimers();++ await syncApplication({+ manifest: buildManifestWithApplicationReferences(),+ expectToFail: false,+ });++ const declaredReferences = await findApplicationReferences();++ expect(declaredReferences.settingsCustomTabFrontComponentId).not.toBeNull();+ expect(declaredReferences.uninstallLogicFunctionId).not.toBeNull();++ const manifestWithoutReferences = buildManifest({+ objects: [ticketObject, invoiceObject],+ });++ const additiveSync = await syncApplication({+ manifest: manifestWithoutReferences,+ inferDeletionFromMissingEntities: false,+ expectToFail: false,+ });++ expect(additiveSync.errors).toBeUndefined();+ expect(await findApplicationReferences()).toEqual(declaredReferences);++ await syncApplication({+ manifest: manifestWithoutReferences,+ expectToFail: false,+ });++ expect(await findApplicationReferences()).toEqual({+ settingsCustomTabFrontComponentId: null,+ uninstallLogicFunctionId: null,+ });+ }, 60000);+it('keeps a skill deactivated by the workspace across a sync', async () => {const skillBefore = await findTestSkill();