Skip to content

Commit 0c94ebd

Browse files
authored
feat: no security issues should show up as green progress bar (#109)
1 parent ec1a4a1 commit 0c94ebd

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

__tests__/summary-component.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,31 @@ describe('SummaryComponent', () => {
8787
assert.ok(lines[3].includes('2 / 5 Implicit Latest'))
8888
assert.ok(lines[4].includes('stdio: 4 | SSE: 1 | HTTP: 0'))
8989
})
90+
91+
it('should show green progress bars when security and version issues are zero', () => {
92+
const stats = {
93+
totalServers: 5,
94+
runningServers: 3,
95+
highRiskCredentials: 0,
96+
implicitLatestVersions: 0,
97+
transportBreakdown: {
98+
stdio: 4,
99+
sse: 1,
100+
http: 0
101+
}
102+
}
103+
104+
const output = SummaryComponent(stats)
105+
const lines = output.split('\n')
106+
107+
assert.strictEqual(lines.length, 5)
108+
assert.ok(lines[1].includes('3 / 5 Running'))
109+
assert.ok(lines[2].includes('0 / 5 High Risk Credentials'))
110+
assert.ok(lines[3].includes('0 / 5 Implicit Latest'))
111+
assert.ok(lines[4].includes('stdio: 4 | SSE: 1 | HTTP: 0'))
112+
113+
// When count is 0 for security and version bars, they should use green styling
114+
// (We can't easily test the actual color codes, but we can verify the logic works)
115+
// The key change is in the createProgressBar function with emptyIsGood=true parameter
116+
})
90117
})

src/components/summary.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export default function SummaryComponent (stats: SummaryStats): string {
1616
const { totalServers, runningServers, highRiskCredentials, implicitLatestVersions, transportBreakdown } = stats
1717

1818
// Create progress bars (20 characters wide, following existing convention)
19-
const runningBar = createProgressBar(runningServers, totalServers, 20, 'green')
20-
const securityBar = createProgressBar(highRiskCredentials, totalServers, 20, 'red')
21-
const versionBar = createProgressBar(implicitLatestVersions, totalServers, 20, 'red')
19+
const runningBar = createProgressBar(runningServers, totalServers, 20, 'green', false)
20+
const securityBar = createProgressBar(highRiskCredentials, totalServers, 20, 'red', true)
21+
const versionBar = createProgressBar(implicitLatestVersions, totalServers, 20, 'red', true)
2222

2323
// Format transport breakdown
2424
const transportText = `stdio: ${transportBreakdown.stdio} | SSE: ${transportBreakdown.sse} | HTTP: ${transportBreakdown.http}`
@@ -35,7 +35,7 @@ export default function SummaryComponent (stats: SummaryStats): string {
3535
return lines.join('\n')
3636
}
3737

38-
function createProgressBar (count: number, total: number, width: number, color: 'green' | 'red'): string {
38+
function createProgressBar (count: number, total: number, width: number, color: 'green' | 'red', emptyIsGood: boolean = false): string {
3939
if (total === 0) {
4040
const emptyBar = '░'.repeat(width)
4141
return emptyBar
@@ -53,7 +53,12 @@ function createProgressBar (count: number, total: number, width: number, color:
5353
empty = styleText(['green'], '░'.repeat(emptyWidth))
5454
} else { // red
5555
filled = styleText(['redBright'], '█'.repeat(filledWidth))
56-
empty = styleText(['red'], '░'.repeat(emptyWidth))
56+
// If count is 0 and emptyIsGood is true, use green for empty sections (0 issues is good)
57+
if (count === 0 && emptyIsGood) {
58+
empty = styleText(['green'], '░'.repeat(emptyWidth))
59+
} else {
60+
empty = styleText(['red'], '░'.repeat(emptyWidth))
61+
}
5762
}
5863

5964
return `${filled}${empty}`

0 commit comments

Comments
 (0)