Skip to content

The open alternative to Salesforce, designed for AI.

Refuse to pull an application into a project that already defines another (#25750)

Weiko0a0836208a6e
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.mdx
index b24c7b9b761..df199352e23 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
@@ -107,7 +107,7 @@ A plan only previews **metadata** changes. It also works for an app that was nev
yarn twenty pull -u <universalIdentifier>
```
-Pull needs an existing project — scaffold one with `npx create-twenty-app@latest` first, then pull into it. Without `-u`, pull targets the application your local `defineApplication()` file declares. Add `-v` to expand the coverage sections of the report, which then name up to 20 identifiers per metadata type instead of only the totals.
+Pull needs an existing project — scaffold one with `npx create-twenty-app@latest` first, then pull into it. Without `-u`, pull targets the application your local `defineApplication()` file declares. If `-u` names a different application than the one your project declares, pull refuses rather than leaving two applications in one tree: pull that one into its own directory. If the project has an application file whose identifier cannot be read, usually because dependencies are not installed, pull refuses too and asks you to run `yarn install` first. Add `-v` to expand the coverage sections of the report, which then name up to 20 identifiers per metadata type instead of only the totals.
**What it writes:**
diff --git a/packages/twenty-sdk/src/cli/operations/pull.ts b/packages/twenty-sdk/src/cli/operations/pull.ts
index 4f1980f7479..4be1d035233 100644
--- a/packages/twenty-sdk/src/cli/operations/pull.ts
+++ b/packages/twenty-sdk/src/cli/operations/pull.ts
@@ -21,6 +21,7 @@ import {
readPullBaseManifest,
writePullBaseManifest,
} from '@/cli/utilities/pull/pull-base-file';
+import { getApplicationMismatchMessage } from '@/cli/utilities/pull/get-application-mismatch-message';
import { scanProjectSourceFiles } from '@/cli/utilities/pull/scan-project-source-files';
import { runSafe } from '@/cli/utilities/run-safe';
import { join } from 'node:path';
@@ -110,9 +111,11 @@ const innerAppPull = async (
onProgress?.('Reading local source files...');
const scannedFiles = await scanProjectSourceFiles(appPath);
- const localApplicationUniversalIdentifier = scannedFiles.find(
+ const localApplicationFile = scannedFiles.find(
(scannedFile) => scannedFile.entityKey === ManifestEntityKey.Application,
- )?.universalIdentifier;
+ );
+ const localApplicationUniversalIdentifier =
+ localApplicationFile?.universalIdentifier;
const universalIdentifier =
options.universalIdentifier ?? localApplicationUniversalIdentifier;
@@ -130,6 +133,22 @@ const innerAppPull = async (
};
}
+ const applicationMismatchMessage = getApplicationMismatchMessage({
+ requestedUniversalIdentifier: options.universalIdentifier,
+ localApplicationUniversalIdentifier,
+ hasLocalApplicationFile: isDefined(localApplicationFile),
+ });
+
+ if (isDefined(applicationMismatchMessage)) {
+ return {
+ success: false,
+ error: {
+ code: APP_ERROR_CODES.PULL_FAILED,
+ message: applicationMismatchMessage,
+ },
+ };
+ }
+
onProgress?.(`Exporting application ${universalIdentifier}...`);
const exportResult = await apiService.exportApplication(universalIdentifier);
diff --git a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/get-application-mismatch-message.spec.ts b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/get-application-mismatch-message.spec.ts
new file mode 100644
index 00000000000..66d4e968db6
--- /dev/null
+++ b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/get-application-mismatch-message.spec.ts
@@ -0,0 +1,58 @@
+import { getApplicationMismatchMessage } from '@/cli/utilities/pull/get-application-mismatch-message';
+
+const LOCAL_UID = 'b30a4560-fedb-4ccd-904a-3788762c7d33';
+const OTHER_UID = '5b1e7c2a-3d4f-4e5a-9b6c-7d8e9f0a1b2c';
+
+describe('getApplicationMismatchMessage', () => {
+ it('should refuse a pull that would bring another application into the tree', () => {
+ const message = getApplicationMismatchMessage({
+ requestedUniversalIdentifier: OTHER_UID,
+ localApplicationUniversalIdentifier: LOCAL_UID,
+ hasLocalApplicationFile: true,
+ });
+
+ expect(message).toContain(LOCAL_UID);
+ expect(message).toContain(OTHER_UID);
+ });
+
+ it('should refuse a pull when the declaration exists but could not be read', () => {
+ const message = getApplicationMismatchMessage({
+ requestedUniversalIdentifier: OTHER_UID,
+ localApplicationUniversalIdentifier: null,
+ hasLocalApplicationFile: true,
+ });
+
+ expect(message).toContain('could not be read');
+ expect(message).toContain(OTHER_UID);
+ });
+
+ it('should allow a pull of the application the tree already defines', () => {
+ expect(
+ getApplicationMismatchMessage({
+ requestedUniversalIdentifier: LOCAL_UID,
+ localApplicationUniversalIdentifier: LOCAL_UID,
+ hasLocalApplicationFile: true,
+ }),
+ ).toBeUndefined();
+ });
+
+ it('should allow a pull into a tree that defines no application yet', () => {
+ expect(
+ getApplicationMismatchMessage({
+ requestedUniversalIdentifier: OTHER_UID,
+ localApplicationUniversalIdentifier: null,
+ hasLocalApplicationFile: false,
+ }),
+ ).toBeUndefined();
+ });
+
+ it('should allow a pull that names no application, so the tree decides', () => {
+ expect(
+ getApplicationMismatchMessage({
+ requestedUniversalIdentifier: undefined,
+ localApplicationUniversalIdentifier: LOCAL_UID,
+ hasLocalApplicationFile: true,
+ }),
+ ).toBeUndefined();
+ });
+});
diff --git a/packages/twenty-sdk/src/cli/utilities/pull/get-application-mismatch-message.ts b/packages/twenty-sdk/src/cli/utilities/pull/get-application-mismatch-message.ts
new file mode 100644
index 00000000000..6da70493ed1
--- /dev/null
+++ b/packages/twenty-sdk/src/cli/utilities/pull/get-application-mismatch-message.ts
@@ -0,0 +1,33 @@
+import { isDefined } from 'twenty-shared/utils';
+
+export const getApplicationMismatchMessage = ({
+ requestedUniversalIdentifier,
+ localApplicationUniversalIdentifier,
+ hasLocalApplicationFile,
+}: {
+ requestedUniversalIdentifier: string | undefined;
+ localApplicationUniversalIdentifier: string | null | undefined;
+ hasLocalApplicationFile: boolean;
+}): string | undefined => {
+ if (!isDefined(requestedUniversalIdentifier) || !hasLocalApplicationFile) {
+ return undefined;
+ }
+
+ if (!isDefined(localApplicationUniversalIdentifier)) {
+ return (
+ 'This project declares an application, but its identifier could not be read.\n\n' +
+ ` Pulling ${requestedUniversalIdentifier} here could overwrite that declaration.\n` +
+ ' Run `yarn install` so the file can be evaluated, then pull again.'
+ );
+ }
+
+ if (requestedUniversalIdentifier === localApplicationUniversalIdentifier) {
+ return undefined;
+ }
+
+ return (
+ `This project already defines application ${localApplicationUniversalIdentifier}.\n\n` +
+ ` Pulling ${requestedUniversalIdentifier} here would leave two applications in one tree.\n` +
+ ' Pull it into a different directory instead.'
+ );
+};