Repository navigation
test(manifest): run cdxgen help checks offline #1807
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
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { mkdtemp, rm, symlink, writeFile } from 'node:fs/promises' | ||
| import os from 'node:os' | ||
| import path from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
|
|
@@ -6,8 +7,6 @@ import { it } from 'vitest' | |
|
|
||
| import constants, { | ||
| COANA_CLI_VERSION, | ||
| FLAG_HELP, | ||
| FLAG_VERSION, | ||
| SOCKET_CLI_API_TOKEN_VARIABLES, | ||
| } from '../src/constants.mts' | ||
| import { type SpawnOptions, spawn } from '../src/utils/spawn.mts' | ||
|
|
@@ -143,35 +142,27 @@ export function cleanOutput(output: string): string { | |
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Check if output contains cdxgen help content. | ||
| * Used to verify cdxgen command executed with help flag. | ||
| */ | ||
| export function hasCdxgenHelpContent(output: string): boolean { | ||
| // Check for various cdxgen help indicators. | ||
| // Must have cdxgen or CycloneDX AND at least one help flag indicator. | ||
| const hasCdxgenMention = | ||
| output.includes('CycloneDX') || output.includes('cdxgen') | ||
| const hasHelpFlags = | ||
| output.includes(FLAG_HELP) || | ||
| output.includes(FLAG_VERSION) || | ||
| // cdxgen-specific flags. | ||
| output.includes('--output') || | ||
| output.includes('--type') | ||
|
|
||
| return hasCdxgenMention && hasHelpFlags | ||
| } | ||
|
|
||
| /** | ||
| * Check if output contains the Socket CLI banner. | ||
| * The banner appears as ASCII art in the stderr output. | ||
| * Note: The banner contains either '*' (when --config is used) or '.' (when no config is used). | ||
| */ | ||
| export function hasSocketBanner(output: string): boolean { | ||
| // Check for Socket banner ASCII art lines. | ||
| // The banner is always printed as a complete block, never partial. | ||
| // Just check for the most distinctive first line. | ||
| return output.includes('_____ _ _') | ||
| export async function spawnCdxgenHelp(args: string[]) { | ||
| const cwd = await mkdtemp(path.join(os.tmpdir(), 'socket-cdxgen-help-')) | ||
| try { | ||
| // Outside the pnpm workspace, npx can run the pinned devDependency locally. | ||
| await writeFile(path.join(cwd, 'package.json'), '{"private":true}') | ||
| await symlink( | ||
| path.resolve(testPath, '../node_modules'), | ||
| path.join(cwd, 'node_modules'), | ||
| 'junction', | ||
| ) | ||
| return await spawnSocketCli(constants.binCliPath, args, { | ||
| cwd, | ||
| env: { | ||
| SOCKET_CLI_CONFIG: '{}', | ||
| npm_config_offline: 'true', | ||
| npm_config_cache: path.join(cwd, '.npm-cache'), | ||
| }, | ||
| }) | ||
| } finally { | ||
| await rm(cwd, { recursive: true, force: true }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Temp cleanup can wipe node_modulesHigh Severity
Reviewed by Cursor Bugbot for commit b152fa4. Configure here. |
||
| } | ||
| } | ||
|
|
||
| export type TestCollectorOptions = Exclude<Parameters<typeof it>[1], undefined> | ||
|
|
||


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.
Offline npx may skip local cdxgen
Medium Severity
The temp project’s
package.jsonis only{"private":true}, whilenpxis invoked as@cyclonedx/cdxgen@<pinned version>withnpm_config_offline=trueandnpm_config_cachepointed at a fresh empty directory. If npm exec does not treat the symlinked install as satisfying that spec (common when the package is not a declared dependency, or when a versioned spec still loads a packument), the fetch fails immediately withENOTCACHEDinstead of printing help, so the newcode === 0/CycloneDX Generatorassertions fail.Reviewed by Cursor Bugbot for commit b152fa4. Configure here.