Skip to content

Commit e092cbb

Browse files
author
Dev Optimizer Bot
committed
fix: Make suggestedFix optional in Finding type
- suggestedFix can be undefined for security findings without autoFix - Added test for suggestedFix handling (3 tests) - All 72 tests passing
1 parent d4d2f6a commit e092cbb

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface Finding {
4242
severity: Severity;
4343
confidence: Confidence;
4444
impact: Impact;
45-
suggestedFix: SuggestedFix;
45+
suggestedFix?: SuggestedFix;
4646
autoFixSafe: boolean;
4747
}
4848

tests/unit/suggestedFix.test.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { describe, it, expect } from '@jest/globals';
2+
import { Finding } from '../../src/types';
3+
4+
describe('Finding suggestedFix handling', () => {
5+
it('should handle findings without suggestedFix', () => {
6+
const finding: Finding = {
7+
id: 'test-001',
8+
domain: 'deps',
9+
title: 'Test finding',
10+
description: 'Test description',
11+
evidence: { file: 'test.js', snippet: 'test' },
12+
severity: 'high',
13+
confidence: 'high',
14+
impact: { type: 'security', estimate: 'test', confidence: 'high' },
15+
autoFixSafe: false
16+
};
17+
18+
const hasAutoFix = finding.suggestedFix?.autoFixable ?? false;
19+
expect(hasAutoFix).toBe(false);
20+
21+
// Use !! to convert to boolean
22+
const canAutoFix = !!(finding.autoFixSafe || finding.suggestedFix?.autoFixable);
23+
expect(canAutoFix).toBe(false);
24+
});
25+
26+
it('should handle findings with suggestedFix but no autoFixable', () => {
27+
const finding: Finding = {
28+
id: 'test-002',
29+
domain: 'deps',
30+
title: 'Test finding',
31+
description: 'Test description',
32+
evidence: { file: 'test.js', snippet: 'test' },
33+
severity: 'medium',
34+
confidence: 'high',
35+
impact: { type: 'time', estimate: 'test', confidence: 'medium' },
36+
suggestedFix: {
37+
type: 'modify',
38+
file: 'test.js',
39+
description: 'Fix description',
40+
autoFixable: false
41+
},
42+
autoFixSafe: false
43+
};
44+
45+
const hasAutoFix = finding.suggestedFix?.autoFixable ?? false;
46+
expect(hasAutoFix).toBe(false);
47+
});
48+
49+
it('should handle findings with autoFixable', () => {
50+
const finding: Finding = {
51+
id: 'test-003',
52+
domain: 'deps',
53+
title: 'Test finding',
54+
description: 'Test description',
55+
evidence: { file: 'test.js', snippet: 'test' },
56+
severity: 'low',
57+
confidence: 'high',
58+
impact: { type: 'size', estimate: '100KB', confidence: 'high' },
59+
suggestedFix: {
60+
type: 'modify',
61+
file: 'test.js',
62+
description: 'Fix description',
63+
autoFixable: true
64+
},
65+
autoFixSafe: true
66+
};
67+
68+
const hasAutoFix = finding.suggestedFix?.autoFixable ?? false;
69+
expect(hasAutoFix).toBe(true);
70+
71+
// When both autoFixSafe and autoFixable are true, it's auto-fixable
72+
const canAutoFix = finding.autoFixSafe && finding.suggestedFix?.autoFixable;
73+
expect(canAutoFix).toBe(true);
74+
});
75+
});

0 commit comments

Comments
 (0)