-
Notifications
You must be signed in to change notification settings - Fork 731
feat: implment bulk radius api (CM-1328) #4390
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
Open
ulemons
wants to merge
6
commits into
main
Choose a base branch
from
fix/add-bulk-to-blast-radius
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bc1a7fc
feat: implment bulk radius api
ulemons 8f41682
feat: add tests
ulemons aadcaaf
feat: high rate limit
ulemons a93f850
fix: test
ulemons b677219
fix: max concurrency for pg
ulemons d6a945d
fix: modify hearthbit test 20 adv
ulemons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
backend/src/api/public/v1/packages/blastRadiusBatch.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { | ||
| MAX_BLAST_RADIUS_JOBS_PER_BATCH, | ||
| MAX_BLAST_RADIUS_POLL_IDS_PER_BATCH, | ||
| blastRadiusJobBatchRequestSchema, | ||
| blastRadiusJobPollBatchRequestSchema, | ||
| paginateAnalysisIds, | ||
| } from './blastRadiusBatch' | ||
|
|
||
| describe('blastRadiusJobBatchRequestSchema', () => { | ||
| it('accepts a batch of valid job requests', () => { | ||
| const result = blastRadiusJobBatchRequestSchema.safeParse({ | ||
| jobs: [ | ||
| { advisoryId: 'GHSA-jf85-cpcp-j695', ecosystem: 'npm' }, | ||
| { advisoryId: 'CVE-2024-12345', ecosystem: 'npm', package: 'pkg:npm/lodash' }, | ||
| ], | ||
| }) | ||
| expect(result.success).toBe(true) | ||
| }) | ||
|
|
||
| it('rejects an empty jobs array', () => { | ||
| const result = blastRadiusJobBatchRequestSchema.safeParse({ jobs: [] }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
|
|
||
| it('rejects more than MAX_BLAST_RADIUS_JOBS_PER_BATCH jobs', () => { | ||
| const jobs = Array.from({ length: MAX_BLAST_RADIUS_JOBS_PER_BATCH + 1 }, () => ({ | ||
| advisoryId: 'GHSA-jf85-cpcp-j695', | ||
| ecosystem: 'npm', | ||
| })) | ||
| const result = blastRadiusJobBatchRequestSchema.safeParse({ jobs }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
|
|
||
| it('rejects a batch containing one invalid job', () => { | ||
| const result = blastRadiusJobBatchRequestSchema.safeParse({ | ||
| jobs: [ | ||
| { advisoryId: 'GHSA-jf85-cpcp-j695', ecosystem: 'npm' }, | ||
| { advisoryId: 'not-an-advisory-id', ecosystem: 'npm' }, | ||
| ], | ||
| }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('blastRadiusJobPollBatchRequestSchema', () => { | ||
| const validId = '3fa85f64-5717-4562-b3fc-2c963f66afa6' | ||
|
|
||
| it('accepts a batch of valid analysisIds and defaults page/pageSize', () => { | ||
| const result = blastRadiusJobPollBatchRequestSchema.parse({ analysisIds: [validId] }) | ||
| expect(result.page).toBe(1) | ||
| expect(result.pageSize).toBe(20) | ||
| }) | ||
|
|
||
| it('rejects an empty analysisIds array', () => { | ||
| const result = blastRadiusJobPollBatchRequestSchema.safeParse({ analysisIds: [] }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
|
|
||
| it('rejects a non-uuid analysisId', () => { | ||
| const result = blastRadiusJobPollBatchRequestSchema.safeParse({ analysisIds: ['not-a-uuid'] }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
|
|
||
| it('rejects more than MAX_BLAST_RADIUS_POLL_IDS_PER_BATCH analysisIds', () => { | ||
| const analysisIds = Array.from( | ||
| { length: MAX_BLAST_RADIUS_POLL_IDS_PER_BATCH + 1 }, | ||
| () => validId, | ||
| ) | ||
| const result = blastRadiusJobPollBatchRequestSchema.safeParse({ analysisIds }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('paginateAnalysisIds', () => { | ||
| it('slices the requested page out of the full analysisIds array', () => { | ||
| const analysisIds = ['a', 'b', 'c', 'd', 'e'] | ||
| const result = paginateAnalysisIds({ analysisIds, page: 2, pageSize: 2 }) | ||
| expect(result).toEqual({ | ||
| page: 2, | ||
| pageSize: 2, | ||
| total: 5, | ||
| pagedAnalysisIds: ['c', 'd'], | ||
| }) | ||
| }) | ||
|
|
||
| it('returns an empty page past the end of the array', () => { | ||
| const result = paginateAnalysisIds({ analysisIds: ['a'], page: 2, pageSize: 20 }) | ||
| expect(result.pagedAnalysisIds).toEqual([]) | ||
| expect(result.total).toBe(1) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.