-
Notifications
You must be signed in to change notification settings - Fork 0
Implement review feedback: concurrency limiting, semver coercion, logging improvements, and test coverage #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
04b8526
e103d8b
cb3f901
6ff1d10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,7 @@ beforeEach(() => { | |||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| afterEach(() => { | ||||||||||||
| jest.clearAllMocks() | ||||||||||||
| jest.restoreAllMocks() | ||||||||||||
| core.summary.emptyBuffer() | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
|
|
@@ -639,3 +639,184 @@ test('addChangeVulnerabilitiesToSummary() - handles RestSharp GHSA-4rr6-2v9v-wcp | |||||||||||
| ghsa_id: 'GHSA-4rr6-2v9v-wcpc' | ||||||||||||
| }) | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| test('addChangeVulnerabilitiesToSummary() - handles version coercion for non-strict semver versions', async () => { | ||||||||||||
| // Test that versions like "8.0" (without patch version) can be coerced to "8.0.0" | ||||||||||||
| // for successful range matching in fail-open mode (patch selection) | ||||||||||||
| const pkg = createTestChange({ | ||||||||||||
| ecosystem: 'npm', | ||||||||||||
| name: 'test-package', | ||||||||||||
| version: '8.0', // Non-strict semver version | ||||||||||||
| vulnerabilities: [ | ||||||||||||
| createTestVulnerability({ | ||||||||||||
| advisory_ghsa_id: 'GHSA-test-1234', | ||||||||||||
| advisory_summary: 'Test vulnerability', | ||||||||||||
| severity: 'high' | ||||||||||||
| }) | ||||||||||||
| ] | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| mockOctokitRequest.mockResolvedValueOnce({ | ||||||||||||
| data: { | ||||||||||||
| vulnerabilities: [ | ||||||||||||
| { | ||||||||||||
| package: { | ||||||||||||
| ecosystem: 'npm', | ||||||||||||
| name: 'test-package' | ||||||||||||
| }, | ||||||||||||
| vulnerable_version_range: '>= 8.0.0, < 9.0.0', | ||||||||||||
| first_patched_version: '9.0.0' | ||||||||||||
| } | ||||||||||||
| ] | ||||||||||||
| } | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| const changes = [pkg] | ||||||||||||
| await summary.addChangeVulnerabilitiesToSummary(changes, 'low') | ||||||||||||
|
|
||||||||||||
| const text = core.summary.stringify() | ||||||||||||
|
|
||||||||||||
| // Should coerce "8.0" to "8.0.0" and successfully match the range, | ||||||||||||
| // showing the patched version instead of N/A | ||||||||||||
| expect(text).toContain('9.0.0') | ||||||||||||
| expect(text).not.toContain('N/A') | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| test('addChangeVulnerabilitiesToSummary() - handles invalid versions in fail-open mode', async () => { | ||||||||||||
| // Test that completely invalid versions that can't be coerced | ||||||||||||
| // still return N/A gracefully in fail-open mode | ||||||||||||
| const pkg = createTestChange({ | ||||||||||||
| ecosystem: 'npm', | ||||||||||||
| name: 'test-package', | ||||||||||||
| version: 'invalid-version-string', | ||||||||||||
| vulnerabilities: [ | ||||||||||||
| createTestVulnerability({ | ||||||||||||
| advisory_ghsa_id: 'GHSA-test-5678', | ||||||||||||
| advisory_summary: 'Test vulnerability', | ||||||||||||
| severity: 'high' | ||||||||||||
| }) | ||||||||||||
| ] | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| mockOctokitRequest.mockResolvedValueOnce({ | ||||||||||||
| data: { | ||||||||||||
| vulnerabilities: [ | ||||||||||||
| { | ||||||||||||
| package: { | ||||||||||||
| ecosystem: 'npm', | ||||||||||||
| name: 'test-package' | ||||||||||||
| }, | ||||||||||||
| vulnerable_version_range: '>= 1.0.0, < 2.0.0', | ||||||||||||
| first_patched_version: '2.0.0' | ||||||||||||
| } | ||||||||||||
| ] | ||||||||||||
| } | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| const changes = [pkg] | ||||||||||||
| await summary.addChangeVulnerabilitiesToSummary(changes, 'low') | ||||||||||||
|
|
||||||||||||
| const text = core.summary.stringify() | ||||||||||||
|
|
||||||||||||
| // Should show N/A since version can't be coerced or matched | ||||||||||||
| expect(text).toContain('N/A') | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| test('addChangeVulnerabilitiesToSummary() - respects concurrency limit for API calls', async () => { | ||||||||||||
| // Create 15 packages with different vulnerabilities to test concurrency limiting | ||||||||||||
| const packages = Array.from({length: 15}, (_, i) => | ||||||||||||
| createTestChange({ | ||||||||||||
| ecosystem: 'npm', | ||||||||||||
| name: `package-${i}`, | ||||||||||||
| version: '1.0.0', | ||||||||||||
| vulnerabilities: [ | ||||||||||||
| createTestVulnerability({ | ||||||||||||
| advisory_ghsa_id: `GHSA-test-${i.toString().padStart(4, '0')}`, | ||||||||||||
| advisory_summary: `Vulnerability ${i}`, | ||||||||||||
| severity: 'high' | ||||||||||||
| }) | ||||||||||||
| ] | ||||||||||||
| }) | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| // Track concurrent calls | ||||||||||||
| let maxConcurrent = 0 | ||||||||||||
| let currentConcurrent = 0 | ||||||||||||
|
|
||||||||||||
| mockOctokitRequest.mockImplementation(async () => { | ||||||||||||
| currentConcurrent++ | ||||||||||||
| maxConcurrent = Math.max(maxConcurrent, currentConcurrent) | ||||||||||||
|
|
||||||||||||
| // Simulate async API call with variable delay | ||||||||||||
| await new Promise(resolve => setTimeout(resolve, Math.random() * 10)) | ||||||||||||
|
|
||||||||||||
| currentConcurrent-- | ||||||||||||
|
Comment on lines
+746
to
+753
|
||||||||||||
|
|
||||||||||||
| return { | ||||||||||||
| data: { | ||||||||||||
| vulnerabilities: [ | ||||||||||||
| { | ||||||||||||
| package: {ecosystem: 'npm', name: 'test'}, | ||||||||||||
| vulnerable_version_range: '>= 1.0.0, < 2.0.0', | ||||||||||||
| first_patched_version: '2.0.0' | ||||||||||||
| } | ||||||||||||
| ] | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| await summary.addChangeVulnerabilitiesToSummary(packages, 'low') | ||||||||||||
|
|
||||||||||||
| // Verify that concurrency limit (10) was respected | ||||||||||||
| expect(maxConcurrent).toBeLessThanOrEqual(10) | ||||||||||||
| // Verify all 15 unique advisories were fetched | ||||||||||||
| expect(mockOctokitRequest).toHaveBeenCalledTimes(15) | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| test('addChangeVulnerabilitiesToSummary() - completes all tasks even with varying durations', async () => { | ||||||||||||
| // Test that promise pool doesn't lose tasks when some complete faster than others | ||||||||||||
| const packages = Array.from({length: 20}, (_, i) => | ||||||||||||
| createTestChange({ | ||||||||||||
| ecosystem: 'npm', | ||||||||||||
| name: `package-${i}`, | ||||||||||||
| version: '1.0.0', | ||||||||||||
| vulnerabilities: [ | ||||||||||||
| createTestVulnerability({ | ||||||||||||
| advisory_ghsa_id: `GHSA-vary-${i.toString().padStart(4, '0')}`, | ||||||||||||
| advisory_summary: `Vulnerability ${i}`, | ||||||||||||
| severity: 'high' | ||||||||||||
| }) | ||||||||||||
| ] | ||||||||||||
| }) | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| const completedAdvisories = new Set<string>() | ||||||||||||
|
|
||||||||||||
| mockOctokitRequest.mockImplementation( | ||||||||||||
| async (path: string, params: {ghsa_id: string}) => { | ||||||||||||
| // Variable delay to simulate real-world API response times | ||||||||||||
| const delay = Math.random() * 50 | ||||||||||||
|
Comment on lines
+797
to
+798
|
||||||||||||
| // Variable delay to simulate real-world API response times | |
| const delay = Math.random() * 50 | |
| // Deterministic variable delay to simulate real-world API response times | |
| const idNumber = parseInt(params.ghsa_id.slice(-4), 10) | |
| const delay = (idNumber % 3) * 25 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jest.restoreAllMocks()restores spied-on originals, but it does not clear call history/state for plainjest.fn()mocks the wayjest.clearAllMocks()did. If any tests assert call counts/args without reinitializing those mocks inbeforeEach, this can cause cross-test leakage. Consider usingjest.restoreAllMocks(); jest.clearAllMocks();(orjest.resetAllMocks()if you also want implementations reset) to keep both “no spy stacking” and per-test isolation.