The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat(cli): show app install progress instead of the job id (#28100)
Weiko864336cb53d6
diff --git a/packages/twenty-cli/docs/commands.md b/packages/twenty-cli/docs/commands.mdindex 17ec7cad468..a39ce81ca51 100644--- a/packages/twenty-cli/docs/commands.md+++ b/packages/twenty-cli/docs/commands.md@@ -446,7 +446,7 @@ twenty app install --universal-identifier <id> --remote staging --jsonThe server selects the registered package and version. Local source changes are not uploaded. For a private package, run `app publish --private` first; publishing to npm alone does not create a server registration. Installation can run app hooks and update an existing installation. Use `app apply` to sync local source instead.-The command waits up to ten minutes for its server installation job to complete, then verifies that the app is installed. JSON returns `application`, `installed: true` and `jobId`. Failed jobs return `INSTALL_FAILED`; missing or mismatched job status is an error, not a successful installation.+The command waits up to ten minutes for its server installation job to complete, then verifies that the app is installed. While it waits, human output shows the job's progress as an updating percentage bar in an interactive terminal. Redirected output, CI and terminals with `TERM=dumb` print a plain progress line each time the percentage changes. JSON returns `application`, `installed: true` and `jobId`. Failed jobs return `INSTALL_FAILED`; missing or mismatched job status is an error, not a successful installation.Identifier resolution and installation errors include `details.phase`, `details.completedPhases` and `details.outcome`, plus the universal identifier and job identifier when available. Identifier resolution failures report `phase: "identity"` and `outcome: "not-started"`. Ctrl+C or a timeout stops waiting but does not cancel the server job. Run the same command again to retry or resume waiting for an installation that is still running. The command requires the server's `triggerInstallApplication` and `findInstallApplicationJobStatus` APIs, including lookup by `jobId`.diff --git a/packages/twenty-cli/src/app/deployment/install-registered-app.ts b/packages/twenty-cli/src/app/deployment/install-registered-app.tsindex 99af8de3f3c..f4d870ba9e0 100644--- a/packages/twenty-cli/src/app/deployment/install-registered-app.ts+++ b/packages/twenty-cli/src/app/deployment/install-registered-app.ts@@ -15,13 +15,13 @@ export const installRegisteredApp = async ({completedPhases,target,signal,- onQueued,+ onProgress,}: {universalIdentifier: string;completedPhases: AppInstallPhase[];target: ResolvedTarget;signal: AbortSignal;- onQueued: (jobId: string) => void;+ onProgress: (percentage: number) => void;}) => {const timeout = AbortSignal.timeout(APP_INSTALL.TIMEOUT_MILLISECONDS);const installSignal = AbortSignal.any([signal, timeout]);@@ -71,13 +71,13 @@ export const installRegisteredApp = async ({});completedPhases.push('start');- onQueued(jobId);await waitForAppInstall({universalIdentifier,jobId,target,signal: installSignal,+ onProgress,}).catch((error: unknown) => {throw fail(error, 'wait', jobId);});diff --git a/packages/twenty-cli/src/app/deployment/wait-for-app-install.ts b/packages/twenty-cli/src/app/deployment/wait-for-app-install.tsindex 1e4f2543c53..c57e16970e1 100644--- a/packages/twenty-cli/src/app/deployment/wait-for-app-install.ts+++ b/packages/twenty-cli/src/app/deployment/wait-for-app-install.ts@@ -1,10 +1,11 @@import { isNonEmptyString } from '@sniptt/guards';import { setTimeout as delay } from 'node:timers/promises';import { MetadataSchema } from 'twenty-client-sdk/metadata';-import { isPlainObject } from 'twenty-shared/utils';+import { isDefined, isPlainObject } from 'twenty-shared/utils';import { APP_INSTALL } from '@/app/deployment/constants/app-install.constant';import { CliError } from '@/output/cli-error';+import { isProgressPercentage } from '@/output/is-progress-percentage';import { type ResolvedTarget } from '@/target/types/resolved-target.type';import { createMetadataClient } from '@/transport/metadata/create-metadata-client';@@ -13,13 +14,16 @@ export const waitForAppInstall = async ({jobId,target,signal,+ onProgress,}: {universalIdentifier: string;jobId: string;target: ResolvedTarget;signal: AbortSignal;+ onProgress: (percentage: number) => void;}) => {const client = createMetadataClient({ target, signal });+ let reportedPercentage = 0;while (true) {signal.throwIfAborted();@@ -30,6 +34,7 @@ export const waitForAppInstall = async ({jobId: true,state: true,failedReason: true,+ progress: true,},});const status = data?.findInstallApplicationJobStatus;@@ -37,7 +42,8 @@ export const waitForAppInstall = async ({if (!isPlainObject(status) ||status.jobId !== jobId ||- !Object.values(MetadataSchema.enumJobState).includes(status.state)+ !Object.values(MetadataSchema.enumJobState).includes(status.state) ||+ (isDefined(status.progress) && !isProgressPercentage(status.progress))) {throw new CliError({code: 'INVALID_RESPONSE',@@ -55,6 +61,16 @@ export const waitForAppInstall = async ({});}+ const percentage =+ status.state === 'COMPLETED'+ ? 100+ : (status.progress ?? reportedPercentage);++ if (percentage !== reportedPercentage) {+ reportedPercentage = percentage;+ onProgress(percentage);+ }+if (status.state === 'COMPLETED') {break;}diff --git a/packages/twenty-cli/src/commands/app/__tests__/app-install.spec.ts b/packages/twenty-cli/src/commands/app/__tests__/app-install.spec.tsindex f04002524b8..0a0b6e22c51 100644--- a/packages/twenty-cli/src/commands/app/__tests__/app-install.spec.ts+++ b/packages/twenty-cli/src/commands/app/__tests__/app-install.spec.ts@@ -296,6 +296,7 @@ describe('app install', () => {null,{ jobId: 'another-job', state: 'COMPLETED' },{ jobId: JOB_ID, state: 'UNKNOWN' },+ { ...jobStatus('ACTIVE'), progress: 101 },])('never treats missing or unrelated job status as success (%j)',async (status) => {@@ -478,6 +479,33 @@ describe('app install', () => {});});+ it('reports job progress once per change instead of the job identifier', async () => {+ state.statuses = [+ jobStatus('WAITING'),+ { ...jobStatus('ACTIVE'), progress: 25 },+ { ...jobStatus('ACTIVE'), progress: 25 },+ { ...jobStatus('ACTIVE'), progress: 75 },+ { ...jobStatus('COMPLETED'), progress: 100 },+ ];+ const progressMessage = `Installing the registered app on ${server.url}…`;++ const { exitCode, stderr } = await run(+ '--universal-identifier',+ UNIVERSAL_IDENTIFIER,+ );++ expect(exitCode).toBe(0);+ expect(+ stderr.split('\n').filter((line) => line.startsWith(progressMessage)),+ ).toEqual([+ `${progressMessage} 0%`,+ `${progressMessage} 25%`,+ `${progressMessage} 75%`,+ `${progressMessage} 100%`,+ ]);+ expect(stderr).not.toContain(JOB_ID);+ });+it('prints success only after installation and appears as a target write command', async () => {const { exitCode, stdout } = await run('--universal-identifier',diff --git a/packages/twenty-cli/src/commands/app/install/run-app-install-command.ts b/packages/twenty-cli/src/commands/app/install/run-app-install-command.tsindex 9a49d5197cc..b19650a6a3c 100644--- a/packages/twenty-cli/src/commands/app/install/run-app-install-command.ts+++ b/packages/twenty-cli/src/commands/app/install/run-app-install-command.ts@@ -24,19 +24,17 @@ export const runAppInstallCommand: CommandRun<TargetCommandContext> = async (});});- output.progress({- message: `Installing the registered app on ${target.apiUrl}…`,- });+ const progressMessage = `Installing the registered app on ${target.apiUrl}…`;++ output.progress({ message: progressMessage, percentage: 0 });const result = await installRegisteredApp({universalIdentifier,completedPhases,target,signal,- onQueued: (jobId) =>- output.progress({- message: `Waiting for installation ${formatDataValue(jobId)}…`,- }),+ onProgress: (percentage) =>+ output.progress({ message: progressMessage, percentage }),});return {diff --git a/packages/twenty-cli/src/output/is-progress-percentage.ts b/packages/twenty-cli/src/output/is-progress-percentage.tsnew file mode 100644index 00000000000..c9729566ac9--- /dev/null+++ b/packages/twenty-cli/src/output/is-progress-percentage.ts@@ -0,0 +1,4 @@+import { isNumber } from '@sniptt/guards';++export const isProgressPercentage = (value: unknown): value is number =>+ isNumber(value) && Number.isInteger(value) && value >= 0 && value <= 100;