-
Notifications
You must be signed in to change notification settings - Fork 731
feat: add workflow for blast radius api (CM-1328) #4372
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
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,99 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { | ||
| blastRadiusJobRequestSchema, | ||
| isSupportedBlastRadiusEcosystem, | ||
| toBlastRadiusJobEntry, | ||
| } from './blastRadius' | ||
|
|
||
| describe('blastRadiusJobRequestSchema', () => { | ||
| it('accepts a minimal advisory-wide request and defaults force to false', () => { | ||
| const result = blastRadiusJobRequestSchema.parse({ advisoryId: 'GHSA-jf85-cpcp-j695' }) | ||
| expect(result).toEqual({ | ||
| advisoryId: 'GHSA-jf85-cpcp-j695', | ||
| ecosystem: undefined, | ||
| package: undefined, | ||
| force: false, | ||
| }) | ||
| }) | ||
|
|
||
| it('accepts a request scoped to a package with ecosystem and force set', () => { | ||
| const result = blastRadiusJobRequestSchema.parse({ | ||
| advisoryId: 'GHSA-jf85-cpcp-j695', | ||
| ecosystem: 'npm', | ||
| package: 'pkg:npm/lodash', | ||
| force: true, | ||
| }) | ||
| expect(result).toEqual({ | ||
| advisoryId: 'GHSA-jf85-cpcp-j695', | ||
| ecosystem: 'npm', | ||
| package: 'pkg:npm/lodash', | ||
| force: true, | ||
| }) | ||
| }) | ||
|
|
||
| it('accepts explicit null for package/ecosystem (advisory-wide, explicit)', () => { | ||
| const result = blastRadiusJobRequestSchema.parse({ | ||
| advisoryId: 'GHSA-jf85-cpcp-j695', | ||
| ecosystem: null, | ||
| package: null, | ||
| }) | ||
| expect(result.ecosystem).toBeNull() | ||
| expect(result.package).toBeNull() | ||
| }) | ||
|
|
||
| it('rejects a missing advisoryId', () => { | ||
| const result = blastRadiusJobRequestSchema.safeParse({}) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
|
|
||
| it('rejects an empty advisoryId', () => { | ||
| const result = blastRadiusJobRequestSchema.safeParse({ advisoryId: ' ' }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('isSupportedBlastRadiusEcosystem', () => { | ||
| it('accepts npm', () => { | ||
| expect(isSupportedBlastRadiusEcosystem('npm')).toBe(true) | ||
| }) | ||
|
|
||
| it('rejects any other ecosystem', () => { | ||
| expect(isSupportedBlastRadiusEcosystem('pypi')).toBe(false) | ||
| }) | ||
|
|
||
| it('rejects null and undefined', () => { | ||
| expect(isSupportedBlastRadiusEcosystem(null)).toBe(false) | ||
| expect(isSupportedBlastRadiusEcosystem(undefined)).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('toBlastRadiusJobEntry', () => { | ||
| it('builds a pending job entry echoing the request fields', () => { | ||
| const entry = toBlastRadiusJobEntry({ | ||
| analysisId: 'br_01h', | ||
| advisoryId: 'GHSA-jf85-cpcp-j695', | ||
| package: 'pkg:npm/lodash', | ||
| ecosystem: 'npm', | ||
| }) | ||
| expect(entry).toEqual({ | ||
| analysisId: 'br_01h', | ||
| advisoryId: 'GHSA-jf85-cpcp-j695', | ||
| package: 'pkg:npm/lodash', | ||
| ecosystem: 'npm', | ||
| status: 'pending', | ||
| }) | ||
| }) | ||
|
|
||
| it('echoes null package/ecosystem for an advisory-wide job', () => { | ||
| const entry = toBlastRadiusJobEntry({ | ||
| analysisId: 'br_01h', | ||
| advisoryId: 'GHSA-jf85-cpcp-j695', | ||
| package: null, | ||
| ecosystem: null, | ||
| }) | ||
| expect(entry.package).toBeNull() | ||
| expect(entry.ecosystem).toBeNull() | ||
| expect(entry.status).toBe('pending') | ||
| }) | ||
| }) |
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,52 @@ | ||
| import { z } from 'zod' | ||
|
|
||
| // The reachability pipeline is npm-only for now — every other ecosystem (including | ||
| // missing/null) is rejected at the API layer before the Temporal workflow is triggered. | ||
| export const SUPPORTED_BLAST_RADIUS_ECOSYSTEMS = ['npm'] as const | ||
|
|
||
| export type SupportedBlastRadiusEcosystem = (typeof SUPPORTED_BLAST_RADIUS_ECOSYSTEMS)[number] | ||
|
|
||
| export function isSupportedBlastRadiusEcosystem( | ||
| ecosystem: string | null | undefined, | ||
| ): ecosystem is SupportedBlastRadiusEcosystem { | ||
| return (SUPPORTED_BLAST_RADIUS_ECOSYSTEMS as readonly string[]).includes(ecosystem ?? '') | ||
| } | ||
|
|
||
| // Always exactly one job per request — advisory-wide (package omitted) or narrowed | ||
| // to a single package. package accepts either a full purl or a bare package name, | ||
| // so it is NOT run through purlFieldSchema/normalizePurl like the other endpoints. | ||
| export const blastRadiusJobRequestSchema = z.object({ | ||
| advisoryId: z.string().trim().min(1, 'advisoryId is required'), | ||
|
ulemons marked this conversation as resolved.
Outdated
|
||
| ecosystem: z.string().trim().min(1).nullish(), | ||
| package: z.string().trim().min(1).nullish(), | ||
| force: z.boolean().default(false), | ||
| }) | ||
|
|
||
| export type BlastRadiusJobRequest = z.infer<typeof blastRadiusJobRequestSchema> | ||
|
|
||
| export type BlastRadiusJobStatus = 'pending' | 'running' | 'done' | 'failed' | ||
|
|
||
| export interface BlastRadiusJobEntry { | ||
| analysisId: string | ||
| advisoryId: string | ||
| package: string | null | ||
| ecosystem: string | null | ||
|
ulemons marked this conversation as resolved.
Outdated
|
||
| status: BlastRadiusJobStatus | ||
| } | ||
|
|
||
| // Builds the 2a response body. The pipeline isn't implemented yet, so every freshly | ||
| // submitted job comes back pending — see analyzeBlastRadius in packages_worker. | ||
| export function toBlastRadiusJobEntry(params: { | ||
| analysisId: string | ||
| advisoryId: string | ||
| package: string | null | ||
| ecosystem: string | null | ||
| }): BlastRadiusJobEntry { | ||
| return { | ||
| analysisId: params.analysisId, | ||
| advisoryId: params.advisoryId, | ||
| package: params.package, | ||
| ecosystem: params.ecosystem, | ||
| status: 'pending', | ||
| } | ||
| } | ||
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.