From 6f6e004f82ac779baa33b6dd0b2a0e9748580f91 Mon Sep 17 00:00:00 2001 From: Miguel Solorio Date: Mon, 29 Sep 2025 15:42:33 -0700 Subject: [PATCH] feat: Add red threshold for getStatusColor util (#9789) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Jacob Richman --- .../cli/src/ui/utils/displayUtils.test.ts | 63 +++++++++++++------ packages/cli/src/ui/utils/displayUtils.ts | 5 +- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/packages/cli/src/ui/utils/displayUtils.test.ts b/packages/cli/src/ui/utils/displayUtils.test.ts index 7dd9f0e831..962cb57c70 100644 --- a/packages/cli/src/ui/utils/displayUtils.test.ts +++ b/packages/cli/src/ui/utils/displayUtils.test.ts @@ -18,30 +18,55 @@ import { Colors } from '../colors.js'; describe('displayUtils', () => { describe('getStatusColor', () => { - const thresholds = { - green: 80, - yellow: 50, - }; + describe('with red threshold', () => { + const thresholds = { + green: 80, + yellow: 50, + red: 20, + }; - it('should return green for values >= green threshold', () => { - expect(getStatusColor(90, thresholds)).toBe(Colors.AccentGreen); - expect(getStatusColor(80, thresholds)).toBe(Colors.AccentGreen); + it('should return green for values >= green threshold', () => { + expect(getStatusColor(90, thresholds)).toBe(Colors.AccentGreen); + expect(getStatusColor(80, thresholds)).toBe(Colors.AccentGreen); + }); + + it('should return yellow for values < green and >= yellow threshold', () => { + expect(getStatusColor(79, thresholds)).toBe(Colors.AccentYellow); + expect(getStatusColor(50, thresholds)).toBe(Colors.AccentYellow); + }); + + it('should return red for values < yellow and >= red threshold', () => { + expect(getStatusColor(49, thresholds)).toBe(Colors.AccentRed); + expect(getStatusColor(20, thresholds)).toBe(Colors.AccentRed); + }); + + it('should return error for values < red threshold', () => { + expect(getStatusColor(19, thresholds)).toBe(Colors.AccentRed); + expect(getStatusColor(0, thresholds)).toBe(Colors.AccentRed); + }); + + it('should return defaultColor for values < red threshold when provided', () => { + expect( + getStatusColor(19, thresholds, { defaultColor: Colors.Foreground }), + ).toBe(Colors.Foreground); + }); }); - it('should return yellow for values < green and >= yellow threshold', () => { - expect(getStatusColor(79, thresholds)).toBe(Colors.AccentYellow); - expect(getStatusColor(50, thresholds)).toBe(Colors.AccentYellow); - }); + describe('when red threshold is not provided', () => { + const thresholds = { + green: 80, + yellow: 50, + }; - it('should return red for values < yellow threshold', () => { - expect(getStatusColor(49, thresholds)).toBe(Colors.AccentRed); - expect(getStatusColor(0, thresholds)).toBe(Colors.AccentRed); - }); + it('should return error color for values < yellow threshold', () => { + expect(getStatusColor(49, thresholds)).toBe(Colors.AccentRed); + }); - it('should return defaultColor for values < yellow threshold when provided', () => { - expect( - getStatusColor(49, thresholds, { defaultColor: Colors.Foreground }), - ).toBe(Colors.Foreground); + it('should return defaultColor for values < yellow threshold when provided', () => { + expect( + getStatusColor(49, thresholds, { defaultColor: Colors.Foreground }), + ).toBe(Colors.Foreground); + }); }); }); diff --git a/packages/cli/src/ui/utils/displayUtils.ts b/packages/cli/src/ui/utils/displayUtils.ts index 73018fd29f..b8f603170e 100644 --- a/packages/cli/src/ui/utils/displayUtils.ts +++ b/packages/cli/src/ui/utils/displayUtils.ts @@ -19,7 +19,7 @@ export const CACHE_EFFICIENCY_MEDIUM = 15; // --- Color Logic --- export const getStatusColor = ( value: number, - thresholds: { green: number; yellow: number }, + thresholds: { green: number; yellow: number; red?: number }, options: { defaultColor?: string } = {}, ) => { if (value >= thresholds.green) { @@ -28,5 +28,8 @@ export const getStatusColor = ( if (value >= thresholds.yellow) { return theme.status.warning; } + if (thresholds.red != null && value >= thresholds.red) { + return theme.status.error; + } return options.defaultColor ?? theme.status.error; };