Skip to content

The open alternative to Salesforce, designed for AI.

fix(cli): color doctor status labels (#27411)

Weiko0490f475e2fe
diff --git a/packages/twenty-cli/src/commands/doctor/__tests__/doctor.spec.ts b/packages/twenty-cli/src/commands/doctor/__tests__/doctor.spec.ts
index 45109bfe0d0..09c7d9591a1 100644
--- a/packages/twenty-cli/src/commands/doctor/__tests__/doctor.spec.ts
+++ b/packages/twenty-cli/src/commands/doctor/__tests__/doctor.spec.ts
@@ -492,6 +492,45 @@ describe('doctor', () => {
expect(result.stdout).not.toContain(API_KEY);
});
+ it.each([false, true])(
+ 'colors human diagnostics on the output stream, failures: %s',
+ async (hasFailures) => {
+ vi.stubEnv('NO_COLOR', undefined);
+ vi.stubEnv('FORCE_COLOR', '1');
+ await saveConfig({ version: 1, remotes: {} });
+ await chmod(configPath, 0o644);
+
+ const result = await runCliForTest([
+ 'doctor',
+ '--offline',
+ ...(hasFailures ? ['--remote', 'missing'] : []),
+ ]);
+ const output = hasFailures ? result.stderr : result.stdout;
+
+ expect(output).toContain('\u001b[32m[PASS]\u001b[39m');
+ expect(output).toContain('\u001b[33m[SKIPPED]\u001b[39m');
+ expect(output).toContain('\u001b[33m[WARNING]\u001b[39m');
+
+ if (hasFailures) {
+ expect(output).toContain('\u001b[31m[FAIL]\u001b[39m');
+ expect(result.stdout).toBe('');
+ } else {
+ expect(result.stderr).toBe('');
+ }
+ },
+ );
+
+ it('respects NO_COLOR for human diagnostics', async () => {
+ vi.stubEnv('FORCE_COLOR', undefined);
+ vi.stubEnv('NO_COLOR', '1');
+
+ const result = await runCliForTest(['doctor', '--offline']);
+
+ expect(result.stdout).toContain('[PASS] node:');
+ expect(result.stdout).toContain('[SKIPPED] project:');
+ expect(result.stdout).not.toContain('\u001b[');
+ });
+
it('keeps failed JSON diagnostics free of ANSI even when color is forced', async () => {
vi.stubEnv('FORCE_COLOR', '1');
const result = await runJson(['--remote', 'missing']);
diff --git a/packages/twenty-cli/src/commands/doctor/run-doctor-command.ts b/packages/twenty-cli/src/commands/doctor/run-doctor-command.ts
index 28a93cbe76e..ca9632e792c 100644
--- a/packages/twenty-cli/src/commands/doctor/run-doctor-command.ts
+++ b/packages/twenty-cli/src/commands/doctor/run-doctor-command.ts
@@ -57,7 +57,10 @@ export const runDoctorCommand: CommandRun = async ({
signal.throwIfAborted();
const failedChecks = checks.filter((check) => check.status === 'fail');
- const human = formatDoctorChecks(checks);
+ const human = formatDoctorChecks(
+ checks,
+ isNonEmptyArray(failedChecks) ? process.stderr : process.stdout,
+ );
if (isNonEmptyArray(failedChecks)) {
throw new CliError({
diff --git a/packages/twenty-cli/src/doctor/format-doctor-checks.ts b/packages/twenty-cli/src/doctor/format-doctor-checks.ts
index bbbc0b16908..32c1f79a3c7 100644
--- a/packages/twenty-cli/src/doctor/format-doctor-checks.ts
+++ b/packages/twenty-cli/src/doctor/format-doctor-checks.ts
@@ -1,12 +1,29 @@
import { isDefined } from 'twenty-shared/utils';
import { type DoctorCheck } from '@/doctor/types/doctor-check.type';
+import { colorText } from '@/output/style';
-export const formatDoctorChecks = (checks: DoctorCheck[]) =>
+const COLOR_BY_STATUS = {
+ pass: 'green',
+ warning: 'yellow',
+ fail: 'red',
+ skipped: 'yellow',
+} as const;
+
+export const formatDoctorChecks = (
+ checks: DoctorCheck[],
+ stream: NodeJS.WriteStream = process.stdout,
+) =>
checks
.map((check) => {
const hint = isDefined(check.hint) ? `\n ${check.hint}` : '';
- return `[${check.status.toUpperCase()}] ${check.id}: ${check.message}${hint}`;
+ const status = colorText(
+ COLOR_BY_STATUS[check.status],
+ `[${check.status.toUpperCase()}]`,
+ stream,
+ );
+
+ return `${status} ${check.id}: ${check.message}${hint}`;
})
.join('\n');