From b241dc7e1c3b18c91f7171c6c3efd9c6f6fb19d2 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Wed, 1 Oct 2025 14:19:46 +0000 Subject: [PATCH] feat: no security issues should show up as green progress bar --- __tests__/summary-component.test.ts | 27 +++++++++++++++++++++++++++ src/components/summary.ts | 15 ++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/__tests__/summary-component.test.ts b/__tests__/summary-component.test.ts index 34ef809..2c99d0f 100644 --- a/__tests__/summary-component.test.ts +++ b/__tests__/summary-component.test.ts @@ -87,4 +87,31 @@ describe('SummaryComponent', () => { assert.ok(lines[3].includes('2 / 5 Implicit Latest')) assert.ok(lines[4].includes('stdio: 4 | SSE: 1 | HTTP: 0')) }) + + it('should show green progress bars when security and version issues are zero', () => { + const stats = { + totalServers: 5, + runningServers: 3, + highRiskCredentials: 0, + implicitLatestVersions: 0, + transportBreakdown: { + stdio: 4, + sse: 1, + http: 0 + } + } + + const output = SummaryComponent(stats) + const lines = output.split('\n') + + assert.strictEqual(lines.length, 5) + assert.ok(lines[1].includes('3 / 5 Running')) + assert.ok(lines[2].includes('0 / 5 High Risk Credentials')) + assert.ok(lines[3].includes('0 / 5 Implicit Latest')) + assert.ok(lines[4].includes('stdio: 4 | SSE: 1 | HTTP: 0')) + + // When count is 0 for security and version bars, they should use green styling + // (We can't easily test the actual color codes, but we can verify the logic works) + // The key change is in the createProgressBar function with emptyIsGood=true parameter + }) }) diff --git a/src/components/summary.ts b/src/components/summary.ts index 9642a9b..39ed743 100644 --- a/src/components/summary.ts +++ b/src/components/summary.ts @@ -16,9 +16,9 @@ export default function SummaryComponent (stats: SummaryStats): string { const { totalServers, runningServers, highRiskCredentials, implicitLatestVersions, transportBreakdown } = stats // Create progress bars (20 characters wide, following existing convention) - const runningBar = createProgressBar(runningServers, totalServers, 20, 'green') - const securityBar = createProgressBar(highRiskCredentials, totalServers, 20, 'red') - const versionBar = createProgressBar(implicitLatestVersions, totalServers, 20, 'red') + const runningBar = createProgressBar(runningServers, totalServers, 20, 'green', false) + const securityBar = createProgressBar(highRiskCredentials, totalServers, 20, 'red', true) + const versionBar = createProgressBar(implicitLatestVersions, totalServers, 20, 'red', true) // Format transport breakdown const transportText = `stdio: ${transportBreakdown.stdio} | SSE: ${transportBreakdown.sse} | HTTP: ${transportBreakdown.http}` @@ -35,7 +35,7 @@ export default function SummaryComponent (stats: SummaryStats): string { return lines.join('\n') } -function createProgressBar (count: number, total: number, width: number, color: 'green' | 'red'): string { +function createProgressBar (count: number, total: number, width: number, color: 'green' | 'red', emptyIsGood: boolean = false): string { if (total === 0) { const emptyBar = '░'.repeat(width) return emptyBar @@ -53,7 +53,12 @@ function createProgressBar (count: number, total: number, width: number, color: empty = styleText(['green'], '░'.repeat(emptyWidth)) } else { // red filled = styleText(['redBright'], '█'.repeat(filledWidth)) - empty = styleText(['red'], '░'.repeat(emptyWidth)) + // If count is 0 and emptyIsGood is true, use green for empty sections (0 issues is good) + if (count === 0 && emptyIsGood) { + empty = styleText(['green'], '░'.repeat(emptyWidth)) + } else { + empty = styleText(['red'], '░'.repeat(emptyWidth)) + } } return `${filled}${empty}`